001 /*
002 Licensed to the Apache Software Foundation (ASF) under one
003 or more contributor license agreements. See the NOTICE file
004 distributed with this work for additional information
005 regarding copyright ownership. The ASF licenses this file
006 to you under the Apache License, Version 2.0 (the
007 "License"); you may not use this file except in compliance
008 with the License. You may obtain a copy of the License at
009
010 http://www.apache.org/licenses/LICENSE-2.0
011
012 Unless required by applicable law or agreed to in writing,
013 software distributed under the License is distributed on an
014 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 KIND, either express or implied. See the License for the
016 specific language governing permissions and limitations
017 under the License.
018 */
019 package org.apache.wiki.tags;
020
021 import java.io.IOException;
022
023 import org.apache.wiki.WikiEngine;
024 import org.apache.wiki.WikiPage;
025 import org.apache.wiki.i18n.InternationalizationManager;
026 import org.apache.wiki.parser.MarkupParser;
027 import org.apache.wiki.parser.WikiDocument;
028 import org.apache.wiki.preferences.Preferences;
029 import org.apache.wiki.render.RenderingManager;
030 import org.apache.wiki.util.TextUtil;
031
032 /**
033 * Writes the author name of the current page, including a link to that page,
034 * if that page exists.
035 *
036 * @since 2.0
037 */
038 public class AuthorTag
039 extends WikiTagBase
040 {
041 private static final long serialVersionUID = 0L;
042
043 /**
044 * {@inheritDoc}
045 */
046 @Override
047 public final int doWikiStartTag()
048 throws IOException
049 {
050 WikiEngine engine = m_wikiContext.getEngine();
051 WikiPage page = m_wikiContext.getPage();
052
053 String author = page.getAuthor();
054
055 if( author != null && author.length() > 0 )
056 {
057 author = TextUtil.replaceEntities(author);
058 if( engine.pageExists(author) )
059 {
060 // FIXME: It's very boring to have to do this.
061 // Slow, too.
062
063 RenderingManager mgr = engine.getRenderingManager();
064
065 MarkupParser p = mgr.getParser( m_wikiContext, "["+author+"|"+author+"]" );
066
067 WikiDocument d = p.parse();
068
069 author = mgr.getHTML( m_wikiContext, d );
070 }
071
072 pageContext.getOut().print( author );
073 }
074 else
075 {
076 pageContext.getOut().print( Preferences.getBundle( m_wikiContext, InternationalizationManager.CORE_BUNDLE )
077 .getString( "common.unknownauthor" ) );
078 }
079
080 return SKIP_BODY;
081 }
082 }