From: <jbo...@li...> - 2005-08-23 18:21:22
|
Author: ral...@jb... Date: 2005-08-23 14:21:14 -0400 (Tue, 23 Aug 2005) New Revision: 928 Modified: trunk/forge/portal-extensions/forge-wiki/src/etc/org/jboss/wiki/wikiPlugins.properties trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/HTMLTranslator.java Log: images and footnotes updated in links parsing Modified: trunk/forge/portal-extensions/forge-wiki/src/etc/org/jboss/wiki/wikiPlugins.properties =================================================================== --- trunk/forge/portal-extensions/forge-wiki/src/etc/org/jboss/wiki/wikiPlugins.properties 2005-08-23 17:18:42 UTC (rev 927) +++ trunk/forge/portal-extensions/forge-wiki/src/etc/org/jboss/wiki/wikiPlugins.properties 2005-08-23 18:21:14 UTC (rev 928) @@ -1,6 +1,6 @@ # WikiPlugin properties. Use it wise. #specifies base URL for the portal -htmlTranslatorURL = http://forge.sicore.org:8080/portal/ -#htmlTranslatorURL = http://localhost:8080/portal/ +htmlTranslatorURL = http://forge.sicore.org:8080/ +#htmlTranslatorURL = http://localhost:8080/ #extensions for images to be inlined, coma-separated -imagePatterns = .png , .jpeg , .gif , .bmp \ No newline at end of file +imagePatterns = .png , .jpeg , .gif , .bmp Modified: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/HTMLTranslator.java =================================================================== --- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/HTMLTranslator.java 2005-08-23 17:18:42 UTC (rev 927) +++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/HTMLTranslator.java 2005-08-23 18:21:14 UTC (rev 928) @@ -37,6 +37,7 @@ private String page = "&page="; private String mediaPatterns; + private String imagePath; private String[] mediaFormats = { "*.png", "*.jpeg", "*.gif" }; /* formatting variables */ @@ -73,6 +74,9 @@ private static final String WORD_SEPARATORS = ",.|:;+=&"; private PushbackReader m_in; + + //stores the name of the wiki page we are currently processing + private String pageName = ""; public HTMLTranslator() { @@ -760,61 +764,87 @@ */ private String handleHyperlinks(String link) { String result = ""; - String pageName = ""; + String text = ""; + String wikiPage = ""; + if(isPluginLink(link)) { - return null; //we do not include plugin links - } + return null; //we do not include plugin links for now + } int border = link.indexOf('|'); - if (border != -1) { - if (isExternalLink(link.substring(border + 1)))//case - // [...|externallink] - opens in new window + if (border != -1) //[text|link] case + { + text = link.substring(0, border); + link = link.substring(border + 1); + + + } + else //[link] case + { + text = link; + + + } + + //external link + if (isExternalLink(link)) { - //if(checkImageLink(link.substring(border + 1)) - //{result = "<img src=\""+link.substring(border + - // 1)+"\"alt=\"link.substring(0, border)\"";} - result = "<a href=\"" + link.substring(border + 1) + "\"target=\"_blank\">" - + link.substring(0, border) + "</a><img src=\"/file-access/default/members/jbosswiki/images/out.png\"/>"; - } //case [...|wikipagelink] + if(checkImageLink(link)) + { + result = "<img src=\""+link +"\"alt=\"" + text+"\">";//external + // image + } + else result = "<a href=\"" + link + "\"target=\"_blank\">" + + text + "</a><img src=\"/file-access/default/members/jbosswiki/images/out.png\"/>"; + } + //internal link else { - pageName = cleanLink(link.substring(border + 1)); - if(wikiEngine.pageExists(pageName)) + //check if a footnote + if(link.startsWith("#"))//footnote reference { - result = "<a href=\"" + portalHome + wikiHome + actionType + //http://labs.jboss.com/JSPWiki/Wiki.jsp?page=TextFormattingRules#ref-TextFormattingRules-1 + result = "<a name=\"" + portalHome + wikiHome + actionType + + "action" + page + pageName+"ref-" + pageName+"-"+link.substring(1)+"\">["+text+"]</A>"; + + } + else if (isNumber(link))//defines footnote + { + result = "<a href=\""+portalHome + wikiHome + actionType + + "action" + page + pageName+"#ref-"+ + pageName+"-"+ + link+"\">["+text+"]</A>"; + } + + //check if not an image link as well + else if(checkImageLink(link)) + { + result = "<img src=\""+ imagePath+"/" + pageName+"/" + link +"\" alt=\""+ text +"\">"; + + } + //check for attachments later on + else + { + wikiPage = cleanLink(link); + if(wikiEngine.pageExists(wikiPage)) + { + result = "<a href=\"" + portalHome + wikiHome + actionType + "action" + page - + pageName + "\">" - + link.substring(0, border) + + wikiPage + "\">" + + text + "</a>"; - } - else - result = "<u>"+link.substring(0, border)+"</u>"+"<a href=\"" + } + else + result = "<u>"+text+"</u>"+"<a href=\"" + portalHome + wikiHome + actionType + "action" + page - + pageName + "\">" + + wikiPage + "\">" + "?" + "</a>"; - } - - } else //[...] case - { - - if (isExternalLink(link)) { - result = "<a href=\"" + link + "\"target=\"_blank\">" + link - + "</a><img src=\"/file-access/default/members/jbosswiki/images/out.png\"/>"; - } else { - pageName = cleanLink(link); - if(wikiEngine.pageExists(pageName)) - { result = "<a href=\"" + portalHome + wikiHome + actionType - + "action" + page + cleanLink(link) + "\">" + link - + "</a>"; } - else - result = "<u>"+pageName+"</u>"+"<a href=\"" + portalHome + wikiHome + actionType - + "action" + page + pageName + "\">" + "?" - + "</a>"; } - } + + return result; } /** @@ -896,6 +926,30 @@ return clean.toString(); } + /** + * Returns true, if the argument contains a number, otherwise false. In a + * quick test this is roughly the same speed as Integer.parseInt() if the + * argument is a number, and roughly ten times the speed, if the argument is + * NOT a number. + */ + + private boolean isNumber( String s ) + { + if( s == null ) return false; + + if( s.length() > 1 && s.charAt(0) == '-' ) + s = s.substring(1); + + for( int i = 0; i < s.length(); i++ ) + { + if( !Character.isDigit(s.charAt(i)) ) + return false; + } + + return true; + } + + //not sure what it is supposed to do but neccessary to compile public void next() {} @@ -909,6 +963,7 @@ } try { + pageName = newPage.getName(); String newContent = parseLinks(newPage.getContent()); newPage.setPageContent(newContent); @@ -923,8 +978,9 @@ @Override public void init() { - portalHome = getProperty("htmlTranslatorURL"); + portalHome = getProperty("htmlTranslatorURL")+"portal/"; mediaPatterns = getProperty("imagePatterns"); + imagePath = getProperty("htmlTranslatorURL")+"wiki"; } |