Author: szimano Date: 2005-09-14 11:30:01 -0400 (Wed, 14 Sep 2005) New Revision: 1110 Added: trunk/forge/portal-extensions/jbosswiki/build.properties.sample trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/plugins/HTMLTranslatorParts.java Removed: trunk/forge/portal-extensions/jbosswiki/build.properties Modified: trunk/forge/portal-extensions/jbosswiki/forge-wiki/project.xml trunk/forge/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/jsp/Edit.jsp trunk/forge/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/jsp/PageInfo.jsp trunk/forge/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/jsp/Wiki.jsp trunk/forge/portal-extensions/jbosswiki/maven.xml trunk/forge/portal-extensions/jbosswiki/project.xml trunk/forge/portal-extensions/jbosswiki/wiki-common/project.xml trunk/forge/portal-extensions/jbosswiki/wiki-common/src/etc/org/jboss/wiki/WikiTypes.xml trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/plugins/RSSPlugin.java Log: jboss wiki to work on forge.sicore.org Deleted: trunk/forge/portal-extensions/jbosswiki/build.properties =================================================================== --- trunk/forge/portal-extensions/jbosswiki/build.properties 2005-09-14 15:07:40 UTC (rev 1109) +++ trunk/forge/portal-extensions/jbosswiki/build.properties 2005-09-14 15:30:01 UTC (rev 1110) @@ -1,15 +0,0 @@ -# Path to where JBoss AS is to be copied. -local.server.dir=/home/tomek/jboss/jboss - -# Path to where your portal extensions are to be deployed - you shouldn't -# have to change that. -local.deploy.dir=${local.server.dir}/server/all/deploy - -# Path to your local maven repository - you can comment this out if you use -# the default location. You can also create a build.properties in your home -# directory to set the maven.repo.local for all projects. -# maven.repo.local= - -# URL of your content repository. You don't have to specify this if you don't -# plan to update the content by maven (it's need for CruiseControl). -maven.scm.url= Copied: trunk/forge/portal-extensions/jbosswiki/build.properties.sample (from rev 1109, trunk/forge/portal-extensions/jbosswiki/build.properties) Modified: trunk/forge/portal-extensions/jbosswiki/forge-wiki/project.xml =================================================================== --- trunk/forge/portal-extensions/jbosswiki/forge-wiki/project.xml 2005-09-14 15:07:40 UTC (rev 1109) +++ trunk/forge/portal-extensions/jbosswiki/forge-wiki/project.xml 2005-09-14 15:30:01 UTC (rev 1110) @@ -84,13 +84,6 @@ </dependency> <dependency> - <groupId>informa</groupId> - <artifactId>informa</artifactId> - <version>0.6.0</version> - <jar>informa-0.6.0.jar</jar> - </dependency> - - <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>1.6</version> Modified: trunk/forge/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/jsp/Edit.jsp =================================================================== --- trunk/forge/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/jsp/Edit.jsp 2005-09-14 15:07:40 UTC (rev 1109) +++ trunk/forge/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/jsp/Edit.jsp 2005-09-14 15:30:01 UTC (rev 1110) @@ -4,7 +4,6 @@ See terms of license at gnu.org. --> -<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %> <%@ page isELIgnored ="false" %> <% Modified: trunk/forge/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/jsp/PageInfo.jsp =================================================================== --- trunk/forge/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/jsp/PageInfo.jsp 2005-09-14 15:07:40 UTC (rev 1109) +++ trunk/forge/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/jsp/PageInfo.jsp 2005-09-14 15:30:01 UTC (rev 1110) @@ -4,7 +4,6 @@ See terms of license at gnu.org. --> -<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %> <%@ page isELIgnored ="false" %> <% Modified: trunk/forge/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/jsp/Wiki.jsp =================================================================== --- trunk/forge/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/jsp/Wiki.jsp 2005-09-14 15:07:40 UTC (rev 1109) +++ trunk/forge/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/jsp/Wiki.jsp 2005-09-14 15:30:01 UTC (rev 1110) @@ -4,7 +4,6 @@ See terms of license at gnu.org. --> -<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %> <%@ page isELIgnored ="false" %> <% Modified: trunk/forge/portal-extensions/jbosswiki/maven.xml =================================================================== --- trunk/forge/portal-extensions/jbosswiki/maven.xml 2005-09-14 15:07:40 UTC (rev 1109) +++ trunk/forge/portal-extensions/jbosswiki/maven.xml 2005-09-14 15:30:01 UTC (rev 1110) @@ -9,14 +9,14 @@ --> <goal name="build"> - <!--<attainGoal name="wiki:build" />--> + <attainGoal name="wiki:build" /> </goal> <goal name="prj-install"> </goal> <goal name="deploy"> - <!--<attainGoal name="wiki:deploy" />--> + <attainGoal name="wiki:deploy" /> </goal> <goal name="wiki:build"> Modified: trunk/forge/portal-extensions/jbosswiki/project.xml =================================================================== --- trunk/forge/portal-extensions/jbosswiki/project.xml 2005-09-14 15:07:40 UTC (rev 1109) +++ trunk/forge/portal-extensions/jbosswiki/project.xml 2005-09-14 15:30:01 UTC (rev 1110) @@ -5,5 +5,14 @@ See terms of license at gnu.org. --> <project> +<pomVersion>3</pomVersion> + <id>jbosswiki</id> + <name>JBoss Wiki</name> + <currentVersion>1.0</currentVersion> + <organization> + <name>Tomasz Szymanski</name> + <url>http://mamut.net.pl</url> + </organization> + <description></description> </project> Modified: trunk/forge/portal-extensions/jbosswiki/wiki-common/project.xml =================================================================== --- trunk/forge/portal-extensions/jbosswiki/wiki-common/project.xml 2005-09-14 15:07:40 UTC (rev 1109) +++ trunk/forge/portal-extensions/jbosswiki/wiki-common/project.xml 2005-09-14 15:30:01 UTC (rev 1110) @@ -83,13 +83,6 @@ <jar>commons-fileupload-1.0.jar</jar> </dependency> - <dependency> - <groupId>informa</groupId> - <artifactId>informa</artifactId> - <version>0.6.0</version> - <jar>informa-0.6.0.jar</jar> - </dependency> - <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> Modified: trunk/forge/portal-extensions/jbosswiki/wiki-common/src/etc/org/jboss/wiki/WikiTypes.xml =================================================================== --- trunk/forge/portal-extensions/jbosswiki/wiki-common/src/etc/org/jboss/wiki/WikiTypes.xml 2005-09-14 15:07:40 UTC (rev 1109) +++ trunk/forge/portal-extensions/jbosswiki/wiki-common/src/etc/org/jboss/wiki/WikiTypes.xml 2005-09-14 15:30:01 UTC (rev 1110) @@ -56,5 +56,9 @@ <name>RSSPlugin</name> <class>org.jboss.wiki.plugins.RSSPlugin</class> </plugin> + <plugin> + <name>HTMLPartTranslator</name> + <class>org.jboss.wiki.plugins.HTMLTranslatorParts</class> + </plugin> </wikiType> </wikiTypes> \ No newline at end of file Added: trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/plugins/HTMLTranslatorParts.java =================================================================== --- trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/plugins/HTMLTranslatorParts.java 2005-09-14 15:07:40 UTC (rev 1109) +++ trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/plugins/HTMLTranslatorParts.java 2005-09-14 15:30:01 UTC (rev 1110) @@ -0,0 +1,1052 @@ +/************************************************** + * * + * JBoss Labs: Creating Professional Open Source * + * * + * Distributable under LGPL license. * + * See terms of license at gnu.org. * + * * + *************************************************/ + +/* + Copyright (C) 2005 Damon Sicore, + Rali Genova, + Tomasz Szymanski, + Adam Warski, + JBoss, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + */ + +/** + * Portions of this work are based on the work + * of Janne Jalkanen of the JSPWiki project. + * + * Marked Portions are Copyright (C) 2001-2002 Janne Jalkanen (Jan...@ik...) + * + * Those portions are marked by the 'author' javadoc tag + * and list Janne Jalkanen as the author of that method. + * + * This class is based on the JSPWiki 2.0 version + * of the TranslatorReader.java class. The original + * version of that class can be found here: + * + * http://anonsvn.labs.jboss.com/branches/forge/archives/jspwiki/src/com/ecyrd/jspwiki/TranslatorReader.java + * + */ +package org.jboss.wiki.plugins; + +/** + * @author <a href="mailto:ral...@jb...">Rali Genova </a> + * @author <a href="mailto:tom...@jb...">Tomasz Szymanski </a> + * + */ +import java.io.*; +import java.util.regex.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.StringTokenizer; +import java.util.Vector; + +import org.jboss.wiki.WikiEngine; +import org.jboss.wiki.WikiPage; +import org.jboss.wiki.WikiPlugin; +import org.jboss.wiki.WikiSession; + +public class HTMLTranslatorParts extends WikiPlugin { + + /* URL components, later to be configurable */ + private String portalHome = ""; + + public final static String pagePartRegexStart = "<!--page:start-->"; + + public final static String pagePartRegexEnd = "<!--page:end-->"; + + private final String pagePartRegex = pagePartRegexStart + ".*" + + pagePartRegexEnd; + + private String wikiHome = ""; + + // private String actionType = "&ctrl:type="; + + private String page = "&page="; + + private String mediaPatterns; + + private String imagePath; + + private String[] mediaFormats = { "*.png", "*.jpeg", "*.gif" }; + + /* formatting variables */ + + private boolean m_allowHTML = false; + + private boolean m_isbold = false; + + private boolean m_isitalic = false; + + private boolean m_isTypedText = false; + + private boolean m_istable = false; + + private boolean m_isPre = false; + + private boolean m_isdefinition = false; + + private int m_listlevel = 0; + + private int m_numlistlevel = 0; + + private boolean m_camelCaseLinks = true; // camelCase enabled + + /** Tag that gets closed at EOL. */ + private String m_closeTag = null; + + /** 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. + */ + 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 HTMLTranslatorParts() { + + } + + /** + * 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) { + m_in.unread(c); + } + } + + /** + * 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); + 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 + + while (!quitReading) { + int ch = nextToken(); + String s = null; + + // begin of HTML transformation + if (m_isPre) { + if (ch == '}') { + buf.append(handleClosebrace()); + } else if (ch == '<') { + buf.append("<"); + } else if (ch == '>') { + buf.append(">"); + } else if (ch == -1) { + quitReading = true; + } else { + buf.append((char) ch); + } + + continue; + } + // + // 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 + // of a CamelCase format text string inside the "word", and + // if one exists, we replace it with a proper link. + // + + if (m_camelCaseLinks) { + // Quick parse of start of a word boundary. + + if (word == null + && (Character.isWhitespace((char) previousCh) + || WORD_SEPARATORS.indexOf((char) previousCh) != -1 || newLine) + && !Character.isWhitespace((char) ch)) { + word = new StringBuffer(); + } + + // Are we currently tracking a word? + if (word != null) { + // + // Check for the end of the word. + // + + if (Character.isWhitespace((char) ch) || ch == -1 + || WORD_SEPARATORS.indexOf((char) ch) != -1) { + String potentialLink = word.toString(); + + String camelCase = parseCamelCase(potentialLink); + + if (camelCase != null) { + start = buf.toString().lastIndexOf(camelCase); + buf.replace(start, start + camelCase.length(), + handleHyperlinks(camelCase)); + } + + // We've ended a word boundary, so time to reset. + word = null; + } else { + // This should only be appending letters and digits. + word.append((char) ch); + } // if end of word + } // if word's not null + + // Always set the previous character to test for word starts. + previousCh = ch; + + } // if m_camelCaseLinks + // + // Check if any lists need closing down. + // + + if (newLine && ch != '*' && ch != ' ' && m_listlevel > 0) { + buf.append("</LI>\n"); + for (; m_listlevel > 0; m_listlevel--) { + buf.append("</UL>\n"); + } + } + + if (newLine && ch != '#' && ch != ' ' && m_numlistlevel > 0) { + buf.append("</LI>\n"); + for (; m_numlistlevel > 0; m_numlistlevel--) { + buf.append("</OL>\n"); + } + } + + if (newLine && ch != '|' && m_istable) { + buf.append("</TABLE>\n"); + m_istable = false; + m_closeTag = null; + } + + switch (ch) { + case '\r': + // DOS linefeeds we forget + s = null; + break; + + case '\n': + // + // Close things like headings, etc. + // + if (m_closeTag != null) { + buf.append(m_closeTag); + m_closeTag = null; + } + + m_isdefinition = false; + + if (newLine) { + // Paragraph change. + + buf.append("<P />\n"); + } else { + buf.append("\n"); + newLine = true; + } + /* + * wiki syntax handling, later to be refactored so multiple wiki + * syntax is supported + */ + + break; + case '\\': + s = handleBackslash(); + break; + + case '_': + s = handleUnderscore(); + break; + + case '\'': + s = handleApostrophe(); + break; + + case '{': + s = handleOpenbrace(); + break; + + case '}': + s = handleClosebrace(); + break; + + case '-': + s = handleDash(); + break; + + case '!': + if (newLine) { + s = handleHeading(); + } else { + s = "!"; + } + break; + + case ';': + if (newLine) { + s = handleDefinitionList(); + } else { + s = ";"; + } + break; + + case ':': + if (m_isdefinition) { + s = "</DT><DD>"; + m_isdefinition = false; + } else { + s = ":"; + } + break; + + case '[': + s = handleOpenbracket(); + break; + + case '*': + if (newLine) { + s = handleUnorderedList(); + } else { + s = "*"; + } + break; + + case '#': + if (newLine) { + s = handleOrderedList(); + } else { + s = "#"; + } + break; + + case '|': + s = handleBar(newLine); + break; + + case '<': + s = m_allowHTML ? "<" : "<"; + break; + + case '>': + s = m_allowHTML ? ">" : ">"; + break; + + case '\"': + s = m_allowHTML ? "\"" : """; + break; + + case '~': + s = handleTilde(); + break; + case -1: + quitReading = true; + break; + + default: + buf.append((char) ch); + newLine = false; + break; + } + if (s != null) { + buf.append(s); + + newLine = false; + } + + } + + 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); + Matcher camelMatch = camelCase.matcher(link); + if (camelMatch.matches()) { + String result = camelMatch.group(2); // get the camel case words + if (camelMatch.group(1) != null) { + if ((camelMatch.group(1).equals("~")) + || (camelMatch.group(1).indexOf('[') != -1)) { + return null; // this is camelCase escape or [...] link + } + } + return result; + + }// if match + return null; + } + + /* a collection of all media formats allowed on wiki */ + private Collection getImagePatterns() { + 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 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. + */ + private String handleTilde() throws IOException { + int ch = nextToken(); + + if (ch == '|') + return "|"; + + if (Character.isUpperCase((char) ch)) { + return String.valueOf((char) ch); + } + + // No escape. + pushBack(ch); + + return "~"; + } + + private String handleUnderscore() throws IOException { + int ch = nextToken(); + String res = "_"; + + if (ch == '_') { + res = m_isbold ? "</B>" : "<B>"; + m_isbold = !m_isbold; + } else { + pushBack(ch); + } + + return res; + } + + /** + * For example: italics. + */ + private String handleApostrophe() throws IOException { + int ch = nextToken(); + String res = "'"; + + if (ch == '\'') { + res = m_isitalic ? "</I>" : "<I>"; + m_isitalic = !m_isitalic; + } else { + m_in.unread(ch); + } + + return res; + } + + private String handleDash() throws IOException { + int ch = nextToken(); + + if (ch == '-') { + int ch2 = nextToken(); + + if (ch2 == '-') { + int ch3 = nextToken(); + + if (ch3 == '-') { + // Empty away all the rest of the dashes. + // Do not forget to return the first non-match back. + while ((ch = nextToken()) == '-') + ; + + pushBack(ch); + return "<HR />"; + } + + pushBack(ch3); + } + pushBack(ch2); + } + + pushBack(ch); + + return "-"; + } + + private String handleHeading() throws IOException { + StringBuffer buf = new StringBuffer(); + + int ch = nextToken(); + + if (ch == '!') { + int ch2 = nextToken(); + + if (ch2 == '!') { + buf.append("<H2>"); + m_closeTag = "</H2>"; + } else { + buf.append("<H3>"); + m_closeTag = "</H3>"; + pushBack(ch2); + } + } else { + buf.append("<H4>"); + m_closeTag = "</H4>"; + pushBack(ch); + } + + return buf.toString(); + } + + private String handleUnorderedList() throws IOException { + StringBuffer buf = new StringBuffer(); + + if (m_listlevel > 0) { + buf.append("</LI>\n"); + } + + int numBullets = countChars(m_in, '*') + 1; + + if (numBullets > m_listlevel) { + for (; m_listlevel < numBullets; m_listlevel++) + buf.append("<UL>\n"); + } else if (numBullets < m_listlevel) { + for (; m_listlevel > numBullets; m_listlevel--) + buf.append("</UL>\n"); + } + + buf.append("<LI>"); + + return buf.toString(); + } + + private String handleOrderedList() throws IOException { + StringBuffer buf = new StringBuffer(); + + if (m_numlistlevel > 0) { + buf.append("</LI>\n"); + } + + int numBullets = countChars(m_in, '#') + 1; + + if (numBullets > m_numlistlevel) { + for (; m_numlistlevel < numBullets; m_numlistlevel++) + buf.append("<OL>\n"); + } else if (numBullets < m_numlistlevel) { + for (; m_numlistlevel > numBullets; m_numlistlevel--) + buf.append("</OL>\n"); + } + + buf.append("<LI>"); + + return buf.toString(); + + } + + private int countChars(PushbackReader in, char c) throws IOException { + int count = 0; + int ch; + + while ((ch = in.read()) != -1) { + if ((char) ch == c) { + count++; + } else { + in.unread(ch); + break; + } + } + + return count; + } + + private String handleBar(boolean newLine) throws IOException { + StringBuffer sb = new StringBuffer(); + + if (!m_istable && !newLine) { + return "|"; + } + + if (newLine) { + if (!m_istable) { + sb.append("<TABLE CLASS=\"wikitable\" BORDER=\"1\">\n"); + m_istable = true; + } + + sb.append("<TR>"); + m_closeTag = "</TD></TR>"; + } + + int ch = nextToken(); + + if (ch == '|') { + if (!newLine) { + sb.append("</TH>"); + } + sb.append("<TH>"); + m_closeTag = "</TH></TR>"; + } else { + if (!newLine) { + sb.append("</TD>"); + } + sb.append("<TD>"); + pushBack(ch); + } + + return sb.toString(); + } + + private String handleDefinitionList() throws IOException { + if (!m_isdefinition) { + m_isdefinition = true; + + m_closeTag = "</DD>\n</DL>"; + + return "<DL>\n<DT>"; + } + + return ";"; + } + + private String handleBackslash() throws IOException { + int ch = nextToken(); + + if (ch == '\\') { + int ch2 = nextToken(); + + if (ch2 == '\\') { + return "<BR clear=\"all\" />"; + } + + pushBack(ch2); + + return "<BR />"; + } + + pushBack(ch); + + return "\\"; + } + + private String handleOpenbracket() throws IOException { + StringBuffer sb = new StringBuffer(); + int ch; + boolean isPlugin = false; + + while ((ch = nextToken()) == '[') { + sb.append((char) ch); + } + + if (sb.length() > 0) { + return sb.toString();// not a link + } + + // + // Find end of hyperlink + // + pushBack(ch); + ch = nextToken(); + + while (ch != -1) { + if (ch == ']')// && (!isPlugin || sb.charAt( sb.length()-1 ) == + // '}' + // ) ) + { + break; + } + + sb.append((char) ch); + + ch = nextToken(); + } + + if (ch == -1) { + + return sb.toString(); + } + + return handleHyperlinks(sb.toString()); + } + + private String handleOpenbrace() throws IOException { + int ch = nextToken(); + String res = "{"; + + if (ch == '{') { + int ch2 = nextToken(); + + if (ch2 == '{') { + res = "<PRE>"; + m_isPre = true; + } else { + pushBack(ch2); + + res = "<TT>"; + m_isTypedText = true; + } + } else { + pushBack(ch); + } + + return res; + } + + /** + * Handles both }} and }}} + */ + private String handleClosebrace() throws IOException { + String res = "}"; + + int ch2 = nextToken(); + + if (ch2 == '}') { + int ch3 = nextToken(); + + if (ch3 == '}') { + if (m_isPre) { + m_isPre = false; + res = "</PRE>"; + } else { + res = "}}}"; + } + } else { + pushBack(ch3); + + if (!m_isPre) { + res = "</TT>"; + m_isTypedText = false; + } else { + pushBack(ch2); + } + } + } else { + pushBack(ch2); + } + + 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 the HTML link representation of the wiki page/external link + * @author Rali Genova + */ + private String handleHyperlinks(String link) { + String result = ""; + String text = ""; + String wikiPage = ""; + + if (isPluginLink(link)) { + return null; // we do not include plugin links for now + } + int border = link.indexOf('|'); + 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)) { + 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 { + // check if a footnote + if (link.startsWith("#"))// footnote reference + { + // http://labs.jboss.com/JSPWiki/Wiki.jsp?page=TextFormattingRules#ref-TextFormattingRules-1 + result = "<a name=\"ref-" + pageName + "-" + link.substring(1) + + "\">[" + text + "]</A>"; + + } else if (isNumber(link))// defines footnote + { + result = "<a href=\"" + portalHome + wikiHome + 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 + page + + wikiPage + "\">" + text + "</a>"; + } else + result = "<u>" + text + "</u>" + "<a href=\"" + portalHome + + wikiHome + page + wikiPage + "\">" + "?" + "</a>"; + } + } + + return result; + } + + /** + * 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] + * + * @author Janne Jalkanen + */ + private boolean isExternalLink(String link) { + link = link.trim(); + return link.startsWith("http:") || link.startsWith("ftp:") + || link.startsWith("https:") || link.startsWith("mailto:") + || link.startsWith("news:") || link.startsWith("file:"); + } + + private int nextToken() throws IOException { + return m_in.read(); + } + + /** + * Push back any character to the current input. Does not push back a read + * EOF, though. + */ + + /** + * Cleans a Wiki name. + * <P>[ This is a link ] -> ThisIsALink + * + * @param link + * Link to be cleared. Null is safe, and causes this to return + * null. + * @return A cleaned link. + * + * @since 2.0 + * @author Janne Jalkanen + */ + public String cleanLink(String link) { + StringBuffer clean = new StringBuffer(); + + if (link == null) + return null; + + // + // Compress away all whitespace and capitalize + // all words in between. + // + + StringTokenizer st = new StringTokenizer(link, " -"); + + while (st.hasMoreTokens()) { + StringBuffer component = new StringBuffer(st.nextToken()); + + component.setCharAt(0, Character.toUpperCase(component.charAt(0))); + + // + // We must do this, because otherwise compiling on JDK 1.4 causes + // a downwards incompatibility to JDK 1.3. + // + clean.append(component.toString()); + } + + // + // Remove non-alphanumeric characters that should not + // be put inside WikiNames. Note that all valid + // Unicode letters are considered okay for WikiNames. + // It is the problem of the WikiPageProvider to take + // care of actually storing that information. + // + + for (int i = 0; i < clean.length(); i++) { + if (!(Character.isLetterOrDigit(clean.charAt(i)) + || clean.charAt(i) == '_' || clean.charAt(i) == '.')) { + clean.deleteCharAt(i); + --i; // We just shortened this buffer. + } + } + + 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() { + } + + public WikiPage process(final WikiPage wikiPage, WikiSession wikiSession) { + WikiPage newPage = null; + m_allowHTML = false; + m_isbold = false; + m_isitalic = false; + m_isTypedText = false; + m_istable = false; + m_isPre = false; + m_isdefinition = false; + m_listlevel = 0; + m_numlistlevel = 0; + m_camelCaseLinks = true; // camelCase enabled + /** Tag that gets closed at EOL. */ + m_closeTag = null; + + portalHome = (String) wikiSession.getAttribute("hostURL") + + (String) wikiSession.getAttribute("actionURL"); + wikiHome = ""; + imagePath = (String) wikiSession.getAttribute("hostURL") + "/wiki"; + + try { + newPage = (WikiPage) wikiPage.clone(); + } catch (CloneNotSupportedException cnse) { + System.out.println("cannot clone the page: " + cnse); + } + + pageName = newPage.getName(); + String newContent = parseParts(newPage.getContent()); + + newPage.setPageContent(newContent); + + return newPage; + } + + private String parseParts(String pageContent) { + String newPageContent = pageContent; + + try { + int lastBegIndx = 0; + while ((lastBegIndx = newPageContent.indexOf(pagePartRegexStart, + lastBegIndx)) != -1) { + int endIndx = newPageContent.indexOf(pagePartRegexEnd, + lastBegIndx); + + if (endIndx != -1) { + String pagePart = newPageContent.substring(lastBegIndx + pagePartRegexStart.length(), + endIndx); + String replace = parseLinks(pagePart).replaceAll("&", "&"); + + newPageContent = newPageContent.substring(0, lastBegIndx + + pagePartRegexStart.length()) + + replace + + newPageContent.substring(endIndx + + pagePartRegexEnd.length()); + + lastBegIndx += replace.length(); + } + + } + + } catch (IOException e) { + System.out.println(e); + newPageContent = "error on page"; + } + + return newPageContent; + + } + + @Override + public void init() { + mediaPatterns = getProperty("imagePatterns"); + + } + +} Modified: trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/plugins/RSSPlugin.java =================================================================== --- trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/plugins/RSSPlugin.java 2005-09-14 15:07:40 UTC (rev 1109) +++ trunk/forge/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/plugins/RSSPlugin.java 2005-09-14 15:30:01 UTC (rev 1110) @@ -13,6 +13,8 @@ public class RSSPlugin extends WikiPlugin { + private DifferenceEngine differenceEngine; + private void addItem(StringBuilder rssFeed, String title, String link, String description) { rssFeed.append("<item>\n"); @@ -29,7 +31,7 @@ "<!-- name=\"generator\" content=\"JBoss Wiki RSSPlugin\" -->\n"); rssFeed.append("<rss version=\"0.92\">\n"); rssFeed.append("<channel>\n"); - rssFeed.append("<title>JBoss Forge Wiki</title>\n"); + rssFeed.append("<title>JBoss Forge Wiki: "+wikiPage.getName()+"</title>\n"); rssFeed.append("<link>" + (String) wikiSession.getAttribute("hostURL") + "/wiki/" + wikiPage.getName() + "</link>\n"); rssFeed.append("<description>JBoss Wiki: " + wikiPage.getName() @@ -37,24 +39,36 @@ rssFeed.append("<language>en</language>\n"); for (int i = wikiPage.getLastVersion(); i > 0; i--) { + String content = HTMLTranslatorParts.pagePartRegexStart + + wikiPage.getPageAtVersion(true, i).getPageContent() + + HTMLTranslatorParts.pagePartRegexEnd; + + if (i > 1) { + try { + content = differenceEngine.colorizeDiff(differenceEngine.makeDiff(wikiPage.getPageAtVersion(true, i).getPageContent(), wikiPage.getPageAtVersion(true, i-1).getPageContent())) + "<br />\n<br />\n"+ content; + } + catch (IOException ioe) { + System.err.println("Couldn't get diff from pages: "+ioe); + } + } + addItem(rssFeed, wikiPage.getName() + " rev: " + i, (String) wikiSession.getAttribute("hostURL") + getProperty("wikiHome").replaceAll("&", "&") - + "&page=" + wikiPage.getName() + "&version=" + i, - wikiPage.getPageAtVersion(true, i).getPageContent()); + + "&page=" + wikiPage.getName() + + "&version=" + i, content); } rssFeed.append("</channel>\n</rss>\n"); - + wikiPage.setPageContent(rssFeed.toString()); - + return wikiPage; } @Override public void init() { - // TODO Auto-generated method stub - + differenceEngine = new DifferenceEngine("ISO-8859-1"); } } |