for( Iterator itr = baseElement.getChildren().iterator(); itr.hasNext(); )
{
Object childElement = itr.next();
if( childElement instanceof Element )
{
Element element = (Element)childElement;
String elementName = element.getName().toLowerCase();
Attribute classAttr = element.getAttribute( CLASS_ATTRIBUTE );
if( elementName.equals( A_ELEMENT ) )
{
if( classAttr != null )
{
String classValue = classAttr.getValue();
Attribute hrefAttr = element.getAttribute( HREF_ATTRIBUTE );
XHtmlToWikiConfig wikiConfig = new XHtmlToWikiConfig( m_context );
// Get the url for wiki page link - it's typically "Wiki.jsp?page=MyPage"
// or when using the ShortURLConstructor option, it's "wiki/MyPage" .
String wikiPageLinkUrl = wikiConfig.getWikiJspPage();
String editPageLinkUrl = wikiConfig.getEditJspPage();
if( classValue.equals( WIKIPAGE )
|| ( hrefAttr != null && hrefAttr.getValue().startsWith( wikiPageLinkUrl ) ) )
{
// Remove the leading url string so that users will only see the
// wikipage's name when editing an existing wiki link.
// For example, change "Wiki.jsp?page=MyPage" to just "MyPage".
String newHref = hrefAttr.getValue().substring( wikiPageLinkUrl.length() );
// Convert "This%20Pagename%20Has%20Spaces" to "This Pagename Has Spaces"
newHref = m_context.getEngine().decodeName( newHref );
// Handle links with section anchors.
// For example, we need to translate the html string "TargetPage#section-TargetPage-Heading2"
// to this wiki string: "TargetPage#Heading2".
hrefAttr.setValue( newHref.replaceFirst( LINKS_SOURCE, LINKS_TRANSLATION ) );
}
else if( hrefAttr != null && (classValue.equals( EDITPAGE ) ||
hrefAttr.getValue().startsWith( editPageLinkUrl ) ) )
{
Attribute titleAttr = element.getAttribute( TITLE_ATTRIBUTE );
if( titleAttr != null )
{
// remove the title since we don't want to eventually save the default undefined page title.
titleAttr.detach();
}