From: <jbo...@li...> - 2005-08-22 16:56:14
|
Author: ral...@jb... Date: 2005-08-22 12:56:09 -0400 (Mon, 22 Aug 2005) New Revision: 915 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: plugin links removed from pages revision 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-22 14:04:36 UTC (rev 914) +++ trunk/forge/portal-extensions/forge-wiki/src/etc/org/jboss/wiki/wikiPlugins.properties 2005-08-22 16:56:09 UTC (rev 915) @@ -1,4 +1,6 @@ # WikiPlugin properties. Use it wise. #specifies base URL for the portal htmlTranslatorURL = http://forge.sicore.org:8080/portal/ -# htmlTranslatorURL = http://loclahost:8080/portal/ \ No newline at end of file +#host:8080/portal/ +#extensions for images to be inlined, coma-separated +imagePatterns = .png , .jpeg , .gif , .bmp \ No newline at end of file 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-22 14:04:36 UTC (rev 914) +++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/HTMLTranslator.java 2005-08-22 16:56:09 UTC (rev 915) @@ -18,10 +18,8 @@ import java.util.regex.*; import java.util.ArrayList; import java.util.Collection; -//import java.util.Date; +import java.util.Iterator; import java.util.StringTokenizer; - -//import org.jboss.wiki.Credentials; import org.jboss.wiki.WikiEngine; import org.jboss.wiki.WikiPage; import org.jboss.wiki.WikiPlugin; @@ -29,10 +27,6 @@ public class HTMLTranslator extends WikiPlugin { - private Pattern myPattern; - - private Matcher myMatcher; - /* URL components, later to be configurable */ private String portalHome = ""; @@ -42,15 +36,10 @@ private String page = "&page="; - public ArrayList mediaPatterns; - - public ArrayList linkPatterns; - - public String[] textlinks; - - public String[] notextlinks; - + private String mediaPatterns; + private String[] mediaFormats = { "*.png", "*.jpeg", "*.gif" }; + /* formatting variables */ private boolean m_allowHTML = false; @@ -69,6 +58,7 @@ private int m_listlevel = 0; private int m_numlistlevel = 0; + private boolean m_camelCaseLinks = true; //camelCase enabled /** Tag that gets closed at EOL. */ @@ -77,8 +67,8 @@ /** Allow this many characters to be pushed back in the stream. */ private static final int PUSHBACK_BUFFER_SIZE = 8; /** - * These characters constitute word separators when trying - * to find CamelCase links. + * These characters constitute word separators when trying to find CamelCase + * links. */ private static final String WORD_SEPARATORS = ",.|:;+=&"; @@ -91,6 +81,8 @@ /** * Push back any character to the current input. Does not push back a read * EOF, though. + * + * @author Janne Jalkanen */ private void pushBack(int c) throws IOException { if (c != -1) { @@ -98,18 +90,22 @@ } } - /* - * compile all links to wiki pages or external pages of the form [...] or - * [...|...] + /** + * Wiki to HTML transformation method, plain URIs transformation not + * implemented + * + * @param page + * The String representation of a wiki page's content + * @return The final transformed into HTML string + * @author Janne Jalkanen + * @author Rali Genova */ public String parseLinks(String page) throws IOException { - m_in = new PushbackReader(new StringReader(page), PUSHBACK_BUFFER_SIZE); - String translatedContent = "";// = prepareText(text); + m_in = new PushbackReader(new StringReader(page), PUSHBACK_BUFFER_SIZE); StringBuffer buf = new StringBuffer(); StringBuffer word = null; int previousCh = -2; int start = 0; - boolean quitReading = false; boolean newLine = true; // FIXME: not true if reading starts in middle // of buffer @@ -117,6 +113,8 @@ while (!quitReading) { int ch = nextToken(); String s = null; + + //begin of HTML transformation if (m_isPre) { if (ch == '}') { buf.append(handleClosebrace()); @@ -135,7 +133,7 @@ // // CamelCase detection, a non-trivial endeavour. // We keep track of all white-space separated entities, which we - // hereby refer to as "words". We then check for an existence + // hereby refer to as "words". We then check for an existence // of a CamelCase format text string inside the "word", and // if one exists, we replace it with a proper link. // @@ -169,16 +167,11 @@ String camelCase = parseCamelCase(potentialLink); if( camelCase != null ) - { - // System.out.println("Buffer is "+buf); - - // System.out.println(" Replacing "+camelCase+" with proper link."); + { start = buf.toString().lastIndexOf( camelCase ); buf.replace(start, start+camelCase.length(), - handleHyperlinks(camelCase) ); - - // System.out.println(" Resulting with "+buf); + handleHyperlinks(camelCase) ); } // We've ended a word boundary, so time to reset. @@ -244,6 +237,10 @@ buf.append("\n"); newLine = true; } + /* + * wiki syntax handling, later to be refactored so multiple wiki + * syntax is supported + */ break; case '\\': @@ -330,10 +327,7 @@ case '\"': s = m_allowHTML ? "\"" : """; break; - - /* - * case '&': s = "&"; break; - */ + case '~': s = handleTilde(); break; @@ -353,13 +347,18 @@ } } - translatedContent = buf.toString(); - // translatedContent = translatedContent.replace("\n", "<BR>\n"); - // System.out.println("final string : "+ translatedContent); - - return translatedContent; + + + return buf.toString(); } - + /** + * @param link - + * potential camel case link to be tested + * @return the string itself if not a camel case, and a proper link + * otherwise + * @author Rali Genova + * @author Janne Jalkanen + */ public String parseCamelCase(String link) { String camelCasepattern = "^([^\\p{Alnum}]*|\\~)([\\p{Upper}]+[\\p{Lower}]+[\\p{Upper}]+[\\p{Alnum}]*)[^\\p{Alnum}]*$"; Pattern camelCase = Pattern.compile(camelCasepattern); @@ -382,14 +381,28 @@ /* a collection of all media formats allowed on wiki */ private Collection getImagePatterns() { - ArrayList patterns = new ArrayList(); - for (int i = 0; i < mediaFormats.length; i++) { - patterns.add(mediaFormats[i]); + ArrayList patt = new ArrayList(); + String imagepattern = mediaPatterns; + String[] elem = imagepattern.split(","); + for (int i = 0; i < elem.length; i++) { + patt.add(elem[i].trim()); } - return patterns; + return patt; } + + private boolean checkImageLink(String text) { + ArrayList ptrns = (ArrayList)getImagePatterns(); + for(int i = 0; i< ptrns.size(); i++) + { + if(text.endsWith((String)ptrns.get(i))) + {return true;} + } + + return false; + } + /** * Generic escape of next character or entity. */ @@ -719,19 +732,47 @@ return res; } + + /** + * Returns true if the link is really command to insert a plugin. + * <P> + * Currently we just check if the link starts with "{INSERT", or just plain + * "{" but not "{$". + * + * @author Janne Jalkanen + * + * @param link + * Link text, i.e. the contents of text between []. + * @return True, if this link seems to be a command to insert a plugin here. + */ + public static boolean isPluginLink( String link ) + { + return link.startsWith("{INSERT") || + (link.startsWith("{") && !link.startsWith("{$")); + } /** + * method to create links for external pages of Wiki pages + * * @param string - * @return + * @return the HTML link representation of the wiki page/external link + * @author Rali Genova */ private String handleHyperlinks(String link) { String result = ""; String pageName = ""; + if(isPluginLink(link)) + { + return null; //we do not include plugin links + } int border = link.indexOf('|'); if (border != -1) { if (isExternalLink(link.substring(border + 1)))//case // [...|externallink] - opens in new window { + //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] @@ -761,8 +802,7 @@ result = "<a href=\"" + link + "\"target=\"_blank\">" + link + "</a><img src=\"/file-access/default/members/jbosswiki/images/out.png\"/>"; } else { - pageName = cleanLink(link); - // System.out.println("********pageName is "+pageName); + pageName = cleanLink(link); if(wikiEngine.pageExists(pageName)) { result = "<a href=\"" + portalHome + wikiHome + actionType + "action" + page + cleanLink(link) + "\">" + link @@ -779,8 +819,10 @@ } /** * Figures out if a link is an off-site link. This recognizes the most - * common protocols by checking how it starts. - * (clears all white space in case the link starts with '\n' or [space] + * common protocols by checking how it starts. (clears all white space in + * case the link starts with '\n' or [space] + * + * @author Janne Jalkanen */ private boolean isExternalLink(String link) { link = link.trim(); @@ -808,6 +850,7 @@ * @return A cleaned link. * * @since 2.0 + * @author Janne Jalkanen */ public String cleanLink(String link) { StringBuffer clean = new StringBuffer(); @@ -857,11 +900,8 @@ public void next() {} - public WikiPage process(final WikiPage wikiPage, WikiSession wikiSession) { - //System.out.println("propertu: "+getProperty("htmlTranslatorURL")); - + public WikiPage process(final WikiPage wikiPage, WikiSession wikiSession) { WikiPage newPage = null; - try { newPage = (WikiPage) wikiPage.clone(); } catch (CloneNotSupportedException cnse) { @@ -884,33 +924,8 @@ @Override public void init() { portalHome = getProperty("htmlTranslatorURL"); + mediaPatterns = getProperty("imagePatterns"); } - - - // public static void main(String[] args) { - // String wikitext = "__Forge Portal__FORGE USER HOW TO:\\\\\n" - // + "[Add a new project and modify its - // data|http://www.NewProject.com]\\\\\n" - // + "[Add and manage project downloads|Project Downloads]\\\\\n" - // + "[Add and manage project freezone|Project *Freezone]\\\\\n" - // + "[Project Freezone]\\\\\n" - // + "[http://www.google.com]\\\\\n"; - // WikiContext wc = new WikiContext(); - // - // String elements = parseLinks(wikitext, wc); - // - // System.out.println(elements); - // } - - // public static void main(String[] args) { - // HTMLTranslator ht = new HTMLTranslator(); - // - // WikiPage wp = new WikiPage("name", new Credentials("tomek"), "content", - // 1, new Date()); - // - // wp = ht.process(wp); - // } - } \ No newline at end of file |