Author: szimano
Date: 2005-08-24 08:40:41 -0400 (Wed, 24 Aug 2005)
New Revision: 936
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/WikiPortlet.java
trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/fileaccess/WikiFileAccessFilter.java
trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/HTMLTranslator.java
trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/Edit.jsp
trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/PageInfo.jsp
trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/Wiki.jsp
Log:
http://domain/wiki/Page access + small chenges
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 20:18:53 UTC (rev 935)
+++ trunk/forge/portal-extensions/forge-wiki/src/etc/org/jboss/wiki/wikiPlugins.properties 2005-08-24 12:40:41 UTC (rev 936)
@@ -4,3 +4,5 @@
#htmlTranslatorURL = http://localhost:8080/
#extensions for images to be inlined, coma-separated
imagePatterns = .png , .jpeg , .gif , .bmp
+#wikiHome part of url. Leave it you use default portlet conifguration
+wikiHome = index.html?ctrl:id=window.default.WikiPortletWindow&ctrl:type=action
Modified: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPortlet.java
===================================================================
--- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPortlet.java 2005-08-23 20:18:53 UTC (rev 935)
+++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPortlet.java 2005-08-24 12:40:41 UTC (rev 936)
@@ -213,12 +213,16 @@
if (rReq.getParameter("version") != null) {
// show previous version of page
+
System.out.println("Getting page " + wikiPage + " at version "
+ rReq.getParameter("version"));
pageToShow = wikiEngine.getByName(wikiPage, null, Integer
.valueOf(rReq.getParameter("version")));
- rReq.setAttribute("showedVersion", Integer.valueOf(rReq
+
+ if (pageToShow.getLastVersion() != pageToShow.getVersion()) {
+ rReq.setAttribute("showedVersion", Integer.valueOf(rReq
.getParameter("version")));
+ }
} else {
pageToShow = wikiEngine.getByName(wikiPage, null);
}
@@ -286,8 +290,11 @@
+ rReq.getParameter("version"));
pageToShow = wikiEngine.getByName(wikiPage, wikiContext,
Integer.valueOf(rReq.getParameter("version")));
- rReq.setAttribute("showedVersion", Integer.valueOf(rReq
+
+ if (pageToShow.getLastVersion() != pageToShow.getVersion()) {
+ rReq.setAttribute("showedVersion", Integer.valueOf(rReq
.getParameter("version")));
+ }
} else {
pageToShow = wikiEngine.getByName(wikiPage, wikiContext);
}
@@ -312,7 +319,7 @@
rReq
.setAttribute(
"wikiName",
- "<img src=\"/file-access/default/members/jbosswiki/images/JBossWikiLogoMedium.png\" width=\"100\" />");
+ "<img src=\"/file-access/default/members/jbosswiki/images/JBossWikiLogoMedium.png\" width=\"100\" border=\"0\" />");
rReq.setAttribute("wikiContent", pageToShow.getContent());
@@ -324,6 +331,8 @@
rReq.setAttribute("logedIn", (rReq.getUser() != null) ? "true"
: "false");
+
+ rReq.setAttribute("defaultPage", defaultPage);
rRes.setTitle("Wiki");
if (javax.portlet.WindowState.NORMAL.equals(rReq.getWindowState())
Modified: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/fileaccess/WikiFileAccessFilter.java
===================================================================
--- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/fileaccess/WikiFileAccessFilter.java 2005-08-23 20:18:53 UTC (rev 935)
+++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/fileaccess/WikiFileAccessFilter.java 2005-08-24 12:40:41 UTC (rev 936)
@@ -22,19 +22,21 @@
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.jboss.wiki.FileDataSource;
+import org.jboss.wiki.WikiPlugin;
// import org.jboss.forge.common.content.ContentManager;
// import org.jboss.forge.common.ForgeHelper;
/**
- * A filter that enables to download files form the jspwiki structure
+ * A filter that enables to download files form the jspwiki structure +
+ * redirects to pages by typing http://domain/wiki/Page
*
* @author tomek
*/
-
public class WikiFileAccessFilter implements Filter {
/**
* <code>BUF_SIZE</code> - size of a buffer, which is used while reading a
@@ -44,6 +46,8 @@
private String attachementsPath;
+ private String host;
+
/*
* private ForgeHelper forgeHelper; private ContentManager contentManager;
*/
@@ -62,13 +66,21 @@
try {
props.load(FileDataSource.class
.getResourceAsStream("filedatasource.properties"));
+
+ // get the path to attachment property
+ attachementsPath = props.getProperty("pathToAttachements");
+
+ props.load(WikiPlugin.class
+ .getResourceAsStream("wikiPlugins.properties"));
+
+ // get the host
+ host = props.getProperty("htmlTranslatorURL") + "portal/"
+ + props.getProperty("wikiHome");
+
} catch (IOException e) {
System.err.println(e);
}
- // get the apropriate property
- attachementsPath = props.getProperty("pathToAttachements");
-
System.out.println("[WikiFileAccess]Loaded attachements path: "
+ attachementsPath);
}
@@ -78,69 +90,81 @@
if (request instanceof HttpServletRequest) {
HttpServletRequest httpRequest = (HttpServletRequest) request;
+ HttpServletResponse httpResponse = (HttpServletResponse) response;
String requestURI = httpRequest.getRequestURI();
// Parse URI to get filename and page name
String[] tokens = requestURI.split("[/]");
- // get fileName of attachement and page which is connected to
- String fileName = tokens[tokens.length - 1];
- String pageName = tokens[tokens.length - 2];
+ System.out.println("length " + tokens.length);
- System.out.println("[WikiFileAccess]Getting file: " + fileName
- + " of page: " + pageName);
+ if (tokens.length == 3) {
+ // show page
+ System.out.println("redirecting: " + host + "&page="
+ + tokens[tokens.length - 1]);
- Properties props = new Properties();
+ httpResponse.sendRedirect(host + "&page="
+ + tokens[tokens.length - 1]);
+ } else {
+ // get fileName of attachement and page which is connected to
+ String fileName = tokens[tokens.length - 1];
+ String pageName = tokens[tokens.length - 2];
- try {
- props.load(new FileInputStream(new File(attachementsPath + "/"
- + pageName + "-att/" + fileName
- + "-dir/attachment.properties")));
- } catch (IOException e) {
- System.err.println(e);
- }
+ System.out.println("[WikiFileAccess]Getting file: " + fileName
+ + " of page: " + pageName);
- // looking for the newst version
- int version = 1;
+ Properties props = new Properties();
- while (props.getProperty((version + 1) + ".author") != null) {
- version++;
- }
+ try {
+ props.load(new FileInputStream(new File(attachementsPath
+ + "/" + pageName + "-att/" + fileName
+ + "-dir/attachment.properties")));
+ } catch (IOException e) {
+ System.err.println(e);
+ }
- tokens = fileName.split("\\.");
+ // looking for the newst version
+ int version = 1;
- File file = new File(
- attachementsPath
- + "/"
- + pageName
- + "-att/"
- + fileName
- + "-dir/"
- + version
- + "."
- + ((fileName.indexOf(".") != -1) ? tokens[tokens.length - 1]
- : "bin"));
+ while (props.getProperty((version + 1) + ".author") != null) {
+ version++;
+ }
- FileInputStream fileIS = new FileInputStream(file);
+ tokens = fileName.split("\\.");
- ServletOutputStream os = response.getOutputStream();
+ File file = new File(
+ attachementsPath
+ + "/"
+ + pageName
+ + "-att/"
+ + fileName
+ + "-dir/"
+ + version
+ + "."
+ + ((fileName.indexOf(".") != -1) ? tokens[tokens.length - 1]
+ : "bin"));
- response.setContentType(mimeTypes.getContentType(file));
- response.setContentLength((int) file.length());
+ FileInputStream fileIS = new FileInputStream(file);
- // Transferring the bytes
- try {
- byte[] buffer = new byte[BUF_SIZE];
- int read;
- while ((read = fileIS.read(buffer)) != -1)
- os.write(buffer, 0, read);
- } catch (Exception e2) {
- // Nothing that we can really do. Just send an incomplete
- // file.
- } finally {
- os.close();
- fileIS.close();
+ ServletOutputStream os = response.getOutputStream();
+
+ response.setContentType(mimeTypes.getContentType(file));
+ response.setContentLength((int) file.length());
+
+ // Transferring the bytes
+ try {
+ byte[] buffer = new byte[BUF_SIZE];
+ int read;
+ while ((read = fileIS.read(buffer)) != -1)
+ os.write(buffer, 0, read);
+ } catch (Exception e2) {
+ // Nothing that we can really do. Just send an incomplete
+ // file.
+ } finally {
+ os.close();
+ fileIS.close();
+ }
}
} else {
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 20:18:53 UTC (rev 935)
+++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/HTMLTranslator.java 2005-08-24 12:40:41 UTC (rev 936)
@@ -12,7 +12,7 @@
/**
* @author <a href="mailto:ral...@jb...">Rali Genova </a>
*
- *
+ *
*/
import java.io.*;
import java.util.regex.*;
@@ -27,960 +27,933 @@
public class HTMLTranslator extends WikiPlugin {
- /* URL components, later to be configurable */
- private String portalHome = "";
+ /* URL components, later to be configurable */
+ private String portalHome = "";
- private String wikiHome = "index.html?ctrl:id=window.default.WikiPortletWindow";
+ private String wikiHome = "";
- private String actionType = "&ctrl:type=";
+ // private String actionType = "&ctrl:type=";
- private String page = "&page=";
+ private String page = "&page=";
- private String mediaPatterns;
- private String imagePath;
-
- private String[] mediaFormats = { "*.png", "*.jpeg", "*.gif" };
- /* formatting variables */
+ private String mediaPatterns;
- private boolean m_allowHTML = false;
+ private String imagePath;
- private boolean m_isbold = false;
+ private String[] mediaFormats = { "*.png", "*.jpeg", "*.gif" };
- private boolean m_isitalic = false;
+ /* formatting variables */
- private boolean m_isTypedText = false;
+ private boolean m_allowHTML = false;
- private boolean m_istable = false;
+ private boolean m_isbold = false;
- private boolean m_isPre = false;
+ private boolean m_isitalic = false;
- private boolean m_isdefinition = false;
+ private boolean m_isTypedText = false;
- private int m_listlevel = 0;
+ private boolean m_istable = false;
- private int m_numlistlevel = 0;
-
- private boolean m_camelCaseLinks = true; //camelCase enabled
+ private boolean m_isPre = false;
- /** Tag that gets closed at EOL. */
- private String m_closeTag = null;
+ private boolean m_isdefinition = false;
- /** 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 int m_listlevel = 0;
- private PushbackReader m_in;
-
- //stores the name of the wiki page we are currently processing
- private String pageName = "";
+ private int m_numlistlevel = 0;
- public HTMLTranslator() {
+ private boolean m_camelCaseLinks = true; // camelCase enabled
- }
+ /** Tag that gets closed at EOL. */
+ private String m_closeTag = null;
- /**
- * 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);
- }
- }
+ /** Allow this many characters to be pushed back in the stream. */
+ private static final int PUSHBACK_BUFFER_SIZE = 8;
- /**
- * 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
+ /**
+ * These characters constitute word separators when trying to find CamelCase
+ * links.
+ */
+ private static final String WORD_SEPARATORS = ",.|:;+=&";
- 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);
- }
+ private PushbackReader m_in;
- 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.
+ // stores the name of the wiki page we are currently processing
+ private String pageName = "";
- if( word == null &&
- (Character.isWhitespace( (char)previousCh ) ||
- WORD_SEPARATORS.indexOf( (char)previousCh ) != -1 ||
- newLine ) &&
- !Character.isWhitespace( (char) ch ) )
- {
- word = new StringBuffer();
- }
+ public HTMLTranslator() {
- // 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();
+ /**
+ * 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);
+ }
+ }
- String camelCase = parseCamelCase(potentialLink);
+ /**
+ * 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
- if( camelCase != null )
- {
- start = buf.toString().lastIndexOf( camelCase );
- buf.replace(start,
- start+camelCase.length(),
- handleHyperlinks(camelCase) );
- }
+ while (!quitReading) {
+ int ch = nextToken();
+ String s = null;
- // 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
+ // 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);
+ }
- // Always set the previous character to test for word starts.
- previousCh = ch;
-
- } // if m_camelCaseLinks
- //
- // Check if any lists need closing down.
- //
+ 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 (newLine && ch != '*' && ch != ' ' && m_listlevel > 0) {
- buf.append("</LI>\n");
- for (; m_listlevel > 0; m_listlevel--) {
- buf.append("</UL>\n");
- }
- }
+ if (m_camelCaseLinks) {
+ // Quick parse of start of a word boundary.
- if (newLine && ch != '#' && ch != ' ' && m_numlistlevel > 0) {
- buf.append("</LI>\n");
- for (; m_numlistlevel > 0; m_numlistlevel--) {
- buf.append("</OL>\n");
- }
- }
+ if (word == null
+ && (Character.isWhitespace((char) previousCh)
+ || WORD_SEPARATORS.indexOf((char) previousCh) != -1 || newLine)
+ && !Character.isWhitespace((char) ch)) {
+ word = new StringBuffer();
+ }
- if (newLine && ch != '|' && m_istable) {
- buf.append("</TABLE>\n");
- m_istable = false;
- m_closeTag = null;
- }
+ // Are we currently tracking a word?
+ if (word != null) {
+ //
+ // Check for the end of the word.
+ //
- switch (ch) {
- case '\r':
- // DOS linefeeds we forget
- s = null;
- break;
+ if (Character.isWhitespace((char) ch) || ch == -1
+ || WORD_SEPARATORS.indexOf((char) ch) != -1) {
+ String potentialLink = word.toString();
- case '\n':
- //
- // Close things like headings, etc.
- //
- if (m_closeTag != null) {
- buf.append(m_closeTag);
- m_closeTag = null;
- }
+ String camelCase = parseCamelCase(potentialLink);
- m_isdefinition = false;
+ if (camelCase != null) {
+ start = buf.toString().lastIndexOf(camelCase);
+ buf.replace(start, start + camelCase.length(),
+ handleHyperlinks(camelCase));
+ }
- if (newLine) {
- // Paragraph change.
+ // 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
- buf.append("<P>\n");
- } else {
- buf.append("\n");
- newLine = true;
- }
- /*
- * wiki syntax handling, later to be refactored so multiple wiki
- * syntax is supported
- */
+ // Always set the previous character to test for word starts.
+ previousCh = ch;
- break;
- case '\\':
- s = handleBackslash();
- break;
+ } // if m_camelCaseLinks
+ //
+ // Check if any lists need closing down.
+ //
- case '_':
- s = handleUnderscore();
- break;
+ if (newLine && ch != '*' && ch != ' ' && m_listlevel > 0) {
+ buf.append("</LI>\n");
+ for (; m_listlevel > 0; m_listlevel--) {
+ buf.append("</UL>\n");
+ }
+ }
- case '\'':
- s = handleApostrophe();
- break;
+ if (newLine && ch != '#' && ch != ' ' && m_numlistlevel > 0) {
+ buf.append("</LI>\n");
+ for (; m_numlistlevel > 0; m_numlistlevel--) {
+ buf.append("</OL>\n");
+ }
+ }
- case '{':
- s = handleOpenbrace();
- break;
+ if (newLine && ch != '|' && m_istable) {
+ buf.append("</TABLE>\n");
+ m_istable = false;
+ m_closeTag = null;
+ }
- case '}':
- s = handleClosebrace();
- break;
+ switch (ch) {
+ case '\r':
+ // DOS linefeeds we forget
+ s = null;
+ break;
- case '-':
- s = handleDash();
- break;
+ case '\n':
+ //
+ // Close things like headings, etc.
+ //
+ if (m_closeTag != null) {
+ buf.append(m_closeTag);
+ m_closeTag = null;
+ }
- case '!':
- if (newLine) {
- s = handleHeading();
- } else {
- s = "!";
- }
- break;
+ m_isdefinition = false;
- case ';':
- if (newLine) {
- s = handleDefinitionList();
- } else {
- s = ";";
- }
- break;
+ if (newLine) {
+ // Paragraph change.
- case ':':
- if (m_isdefinition) {
- s = "</DT><DD>";
- m_isdefinition = false;
- } else {
- s = ":";
- }
- break;
+ buf.append("<P>\n");
+ } else {
+ buf.append("\n");
+ newLine = true;
+ }
+ /*
+ * wiki syntax handling, later to be refactored so multiple wiki
+ * syntax is supported
+ */
- case '[':
- s = handleOpenbracket();
- break;
+ break;
+ case '\\':
+ s = handleBackslash();
+ break;
- case '*':
- if (newLine) {
- s = handleUnorderedList();
- } else {
- s = "*";
- }
- break;
+ case '_':
+ s = handleUnderscore();
+ break;
- case '#':
- if (newLine) {
- s = handleOrderedList();
- } else {
- s = "#";
- }
- break;
+ case '\'':
+ s = handleApostrophe();
+ break;
- case '|':
- s = handleBar(newLine);
- break;
+ case '{':
+ s = handleOpenbrace();
+ break;
- case '<':
- s = m_allowHTML ? "<" : "<";
- break;
+ case '}':
+ s = handleClosebrace();
+ break;
- case '>':
- s = m_allowHTML ? ">" : ">";
- break;
+ case '-':
+ s = handleDash();
+ break;
- case '\"':
- s = m_allowHTML ? "\"" : """;
- break;
-
- case '~':
- s = handleTilde();
- break;
- case -1:
- quitReading = true;
- break;
+ case '!':
+ if (newLine) {
+ s = handleHeading();
+ } else {
+ s = "!";
+ }
+ break;
- default:
- buf.append((char) ch);
- newLine = false;
- break;
- }
- if (s != null) {
- buf.append(s);
+ case ';':
+ if (newLine) {
+ s = handleDefinitionList();
+ } else {
+ s = ";";
+ }
+ break;
- newLine = false;
- }
+ case ':':
+ if (m_isdefinition) {
+ s = "</DT><DD>";
+ m_isdefinition = false;
+ } else {
+ s = ":";
+ }
+ break;
- }
-
-
- 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;
+ case '[':
+ s = handleOpenbracket();
+ break;
- }//if match
- return null;
- }
+ case '*':
+ if (newLine) {
+ s = handleUnorderedList();
+ } else {
+ s = "*";
+ }
+ break;
- /* 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());
- }
+ case '#':
+ if (newLine) {
+ s = handleOrderedList();
+ } else {
+ s = "#";
+ }
+ break;
- 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;
- }
+ case '|':
+ s = handleBar(newLine);
+ break;
+ case '<':
+ s = m_allowHTML ? "<" : "<";
+ break;
- /**
- * Generic escape of next character or entity.
- */
- private String handleTilde() throws IOException {
- int ch = nextToken();
+ case '>':
+ s = m_allowHTML ? ">" : ">";
+ break;
- if (ch == '|')
- return "|";
+ case '\"':
+ s = m_allowHTML ? "\"" : """;
+ break;
- if (Character.isUpperCase((char) ch)) {
- return String.valueOf((char) ch);
- }
+ case '~':
+ s = handleTilde();
+ break;
+ case -1:
+ quitReading = true;
+ break;
- // No escape.
- pushBack(ch);
+ default:
+ buf.append((char) ch);
+ newLine = false;
+ break;
+ }
+ if (s != null) {
+ buf.append(s);
- return "~";
- }
+ newLine = false;
+ }
- 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 buf.toString();
+ }
- return res;
- }
+ /**
+ * @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;
- /**
- * For example: italics.
- */
- private String handleApostrophe() throws IOException {
- int ch = nextToken();
- String res = "'";
+ }// if match
+ return null;
+ }
- if (ch == '\'') {
- res = m_isitalic ? "</I>" : "<I>";
- m_isitalic = !m_isitalic;
- } else {
- m_in.unread(ch);
- }
+ /* 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 res;
- }
+ return patt;
+ }
- private String handleDash() throws IOException {
- int ch = nextToken();
+ 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;
+ }
+ }
- if (ch == '-') {
- int ch2 = nextToken();
+ return false;
+ }
- if (ch2 == '-') {
- int ch3 = nextToken();
+ /**
+ * Generic escape of next character or entity.
+ */
+ private String handleTilde() throws IOException {
+ int ch = nextToken();
- if (ch3 == '-') {
- // Empty away all the rest of the dashes.
- // Do not forget to return the first non-match back.
- while ((ch = nextToken()) == '-')
- ;
+ if (ch == '|')
+ return "|";
- pushBack(ch);
- return "<HR />";
- }
+ if (Character.isUpperCase((char) ch)) {
+ return String.valueOf((char) ch);
+ }
- pushBack(ch3);
- }
- pushBack(ch2);
- }
+ // No escape.
+ pushBack(ch);
- pushBack(ch);
+ return "~";
+ }
- return "-";
- }
+ private String handleUnderscore() throws IOException {
+ int ch = nextToken();
+ String res = "_";
- private String handleHeading() throws IOException {
- StringBuffer buf = new StringBuffer();
+ if (ch == '_') {
+ res = m_isbold ? "</B>" : "<B>";
+ m_isbold = !m_isbold;
+ } else {
+ pushBack(ch);
+ }
- int ch = nextToken();
+ return res;
+ }
- if (ch == '!') {
- int ch2 = nextToken();
+ /**
+ * For example: italics.
+ */
+ private String handleApostrophe() throws IOException {
+ int ch = nextToken();
+ String res = "'";
- 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);
- }
+ if (ch == '\'') {
+ res = m_isitalic ? "</I>" : "<I>";
+ m_isitalic = !m_isitalic;
+ } else {
+ m_in.unread(ch);
+ }
- return buf.toString();
- }
+ return res;
+ }
- private String handleUnorderedList() throws IOException {
- StringBuffer buf = new StringBuffer();
+ private String handleDash() throws IOException {
+ int ch = nextToken();
- if (m_listlevel > 0) {
- buf.append("</LI>\n");
- }
+ if (ch == '-') {
+ int ch2 = nextToken();
- int numBullets = countChars(m_in, '*') + 1;
+ if (ch2 == '-') {
+ int ch3 = nextToken();
- 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");
- }
+ if (ch3 == '-') {
+ // Empty away all the rest of the dashes.
+ // Do not forget to return the first non-match back.
+ while ((ch = nextToken()) == '-')
+ ;
- buf.append("<LI>");
+ pushBack(ch);
+ return "<HR />";
+ }
- return buf.toString();
- }
+ pushBack(ch3);
+ }
+ pushBack(ch2);
+ }
- private String handleOrderedList() throws IOException {
- StringBuffer buf = new StringBuffer();
+ pushBack(ch);
- if (m_numlistlevel > 0) {
- buf.append("</LI>\n");
- }
+ return "-";
+ }
- int numBullets = countChars(m_in, '#') + 1;
+ private String handleHeading() throws IOException {
+ StringBuffer buf = new StringBuffer();
- 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");
- }
+ int ch = nextToken();
- buf.append("<LI>");
+ if (ch == '!') {
+ int ch2 = nextToken();
- return buf.toString();
+ 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 int countChars(PushbackReader in, char c) throws IOException {
- int count = 0;
- int ch;
+ private String handleUnorderedList() throws IOException {
+ StringBuffer buf = new StringBuffer();
- while ((ch = in.read()) != -1) {
- if ((char) ch == c) {
- count++;
- } else {
- in.unread(ch);
- break;
- }
- }
+ if (m_listlevel > 0) {
+ buf.append("</LI>\n");
+ }
- return count;
- }
+ int numBullets = countChars(m_in, '*') + 1;
- private String handleBar(boolean newLine) throws IOException {
- StringBuffer sb = new StringBuffer();
+ 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");
+ }
- if (!m_istable && !newLine) {
- return "|";
- }
+ buf.append("<LI>");
- if (newLine) {
- if (!m_istable) {
- sb.append("<TABLE CLASS=\"wikitable\" BORDER=\"1\">\n");
- m_istable = true;
- }
+ return buf.toString();
+ }
- sb.append("<TR>");
- m_closeTag = "</TD></TR>";
- }
+ private String handleOrderedList() throws IOException {
+ StringBuffer buf = new StringBuffer();
- int ch = nextToken();
+ if (m_numlistlevel > 0) {
+ buf.append("</LI>\n");
+ }
- 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);
- }
+ int numBullets = countChars(m_in, '#') + 1;
- return sb.toString();
- }
+ 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");
+ }
- private String handleDefinitionList() throws IOException {
- if (!m_isdefinition) {
- m_isdefinition = true;
+ buf.append("<LI>");
- m_closeTag = "</DD>\n</DL>";
+ return buf.toString();
- return "<DL>\n<DT>";
- }
+ }
- return ";";
- }
+ private int countChars(PushbackReader in, char c) throws IOException {
+ int count = 0;
+ int ch;
- private String handleBackslash() throws IOException {
- int ch = nextToken();
+ while ((ch = in.read()) != -1) {
+ if ((char) ch == c) {
+ count++;
+ } else {
+ in.unread(ch);
+ break;
+ }
+ }
- if (ch == '\\') {
- int ch2 = nextToken();
+ return count;
+ }
- if (ch2 == '\\') {
- return "<BR clear=\"all\" />";
- }
+ private String handleBar(boolean newLine) throws IOException {
+ StringBuffer sb = new StringBuffer();
- pushBack(ch2);
+ if (!m_istable && !newLine) {
+ return "|";
+ }
- return "<BR />";
- }
+ if (newLine) {
+ if (!m_istable) {
+ sb.append("<TABLE CLASS=\"wikitable\" BORDER=\"1\">\n");
+ m_istable = true;
+ }
- pushBack(ch);
+ sb.append("<TR>");
+ m_closeTag = "</TD></TR>";
+ }
- return "\\";
- }
+ int ch = nextToken();
- private String handleOpenbracket() throws IOException {
- StringBuffer sb = new StringBuffer();
- int ch;
- boolean isPlugin = false;
+ 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);
+ }
- while ((ch = nextToken()) == '[') {
- sb.append((char) ch);
- }
+ return sb.toString();
+ }
- if (sb.length() > 0) {
- return sb.toString();//not a link
- }
+ private String handleDefinitionList() throws IOException {
+ if (!m_isdefinition) {
+ m_isdefinition = true;
- //
- // Find end of hyperlink
- //
- pushBack(ch);
- ch = nextToken();
+ m_closeTag = "</DD>\n</DL>";
- while (ch != -1) {
- if (ch == ']')//&& (!isPlugin || sb.charAt( sb.length()-1 ) == '}'
- // ) )
- {
- break;
- }
+ return "<DL>\n<DT>";
+ }
- sb.append((char) ch);
+ return ";";
+ }
- ch = nextToken();
- }
+ private String handleBackslash() throws IOException {
+ int ch = nextToken();
- if (ch == -1) {
+ if (ch == '\\') {
+ int ch2 = nextToken();
- return sb.toString();
- }
+ if (ch2 == '\\') {
+ return "<BR clear=\"all\" />";
+ }
- return handleHyperlinks(sb.toString());
- }
+ pushBack(ch2);
- private String handleOpenbrace() throws IOException {
- int ch = nextToken();
- String res = "{";
+ return "<BR />";
+ }
- if (ch == '{') {
- int ch2 = nextToken();
+ pushBack(ch);
- if (ch2 == '{') {
- res = "<PRE>";
- m_isPre = true;
- } else {
- pushBack(ch2);
+ return "\\";
+ }
- res = "<TT>";
- m_isTypedText = true;
- }
- } else {
- pushBack(ch);
- }
+ private String handleOpenbracket() throws IOException {
+ StringBuffer sb = new StringBuffer();
+ int ch;
+ boolean isPlugin = false;
- return res;
- }
+ while ((ch = nextToken()) == '[') {
+ sb.append((char) ch);
+ }
- /**
- * Handles both }} and }}}
- */
- private String handleClosebrace() throws IOException {
- String res = "}";
+ if (sb.length() > 0) {
+ return sb.toString();// not a link
+ }
- int ch2 = nextToken();
+ //
+ // Find end of hyperlink
+ //
+ pushBack(ch);
+ ch = nextToken();
- if (ch2 == '}') {
- int ch3 = nextToken();
+ while (ch != -1) {
+ if (ch == ']')// && (!isPlugin || sb.charAt( sb.length()-1 ) ==
+ // '}'
+ // ) )
+ {
+ break;
+ }
- if (ch3 == '}') {
- if (m_isPre) {
- m_isPre = false;
- res = "</PRE>";
- } else {
- res = "}}}";
- }
- } else {
- pushBack(ch3);
+ sb.append((char) ch);
- if (!m_isPre) {
- res = "</TT>";
- m_isTypedText = false;
- } else {
- pushBack(ch2);
- }
- }
- } else {
- pushBack(ch2);
- }
+ ch = nextToken();
+ }
- 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("{$"));
- }
+ if (ch == -1) {
- /**
- * 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 + 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
- + wikiPage + "\">"
- + text
- + "</a>";
- }
- else
- result = "<u>"+text+"</u>"+"<a href=\""
- + portalHome + wikiHome + actionType
- + "action" + page
- + wikiPage + "\">"
- + "?" + "</a>";
- }
- }
+ return sb.toString();
+ }
-
+ return handleHyperlinks(sb.toString());
+ }
- 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 String handleOpenbrace() throws IOException {
+ int ch = nextToken();
+ String res = "{";
- private int nextToken() throws IOException {
- return m_in.read();
- }
+ if (ch == '{') {
+ int ch2 = nextToken();
- /**
- * Push back any character to the current input. Does not push back a read
- * EOF, though.
- */
+ if (ch2 == '{') {
+ res = "<PRE>";
+ m_isPre = true;
+ } else {
+ pushBack(ch2);
- /**
- * 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();
+ res = "<TT>";
+ m_isTypedText = true;
+ }
+ } else {
+ pushBack(ch);
+ }
- if (link == null)
- return null;
+ return res;
+ }
- //
- // Compress away all whitespace and capitalize
- // all words in between.
- //
+ /**
+ * Handles both }} and }}}
+ */
+ private String handleClosebrace() throws IOException {
+ String res = "}";
- StringTokenizer st = new StringTokenizer(link, " -");
+ int ch2 = nextToken();
- while (st.hasMoreTokens()) {
- StringBuffer component = new StringBuffer(st.nextToken());
+ if (ch2 == '}') {
+ int ch3 = nextToken();
- component.setCharAt(0, Character.toUpperCase(component.charAt(0)));
+ if (ch3 == '}') {
+ if (m_isPre) {
+ m_isPre = false;
+ res = "</PRE>";
+ } else {
+ res = "}}}";
+ }
+ } else {
+ pushBack(ch3);
- //
- // We must do this, because otherwise compiling on JDK 1.4 causes
- // a downwards incompatibility to JDK 1.3.
- //
- clean.append(component.toString());
- }
+ if (!m_isPre) {
+ res = "</TT>";
+ m_isTypedText = false;
+ } else {
+ pushBack(ch2);
+ }
+ }
+ } else {
+ pushBack(ch2);
+ }
- //
- // 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.
- //
+ return res;
+ }
- 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.
- }
- }
+ /**
+ * 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("{$"));
+ }
- 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.
- */
+ /**
+ * 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 = "";
- private boolean isNumber( String s )
- {
- if( s == null ) return false;
+ 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);
- if( s.length() > 1 && s.charAt(0) == '-' )
- s = s.substring(1);
+ } else // [link] case
+ {
+ text = link;
- for( int i = 0; i < s.length(); i++ )
- {
- if( !Character.isDigit(s.charAt(i)) )
- return false;
- }
+ }
- return true;
- }
+ // 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>";
-
- //not sure what it is supposed to do but neccessary to compile
- public void next()
- {}
+ } else if (isNumber(link))// defines footnote
+ {
+ result = "<a href=\"" + portalHome + wikiHome + page + pageName
+ + "#ref-" + pageName + "-" + link + "\">[" + text
+ + "]</A>";
+ }
- public WikiPage process(final WikiPage wikiPage, WikiSession wikiSession) {
- WikiPage newPage = null;
- try {
- newPage = (WikiPage) wikiPage.clone();
- } catch (CloneNotSupportedException cnse) {
- System.out.println("cannot clone the page: " + cnse);
- }
+ // check if not an image link as well
+ else if (checkImageLink(link)) {
+ result = "<img src=\"" + imagePath + "/" + pageName + "/"
+ + link + "\" alt=\"" + text + "\">";
- try {
- pageName = newPage.getName();
- String newContent = parseLinks(newPage.getContent());
+ }
+ // 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>";
+ }
+ }
- newPage.setPageContent(newContent);
+ return result;
+ }
- return newPage;
- } catch (IOException e) {
- System.out.println(e);
- newPage.setPageContent("error on page");
- }
- return newPage;
- }
+ /**
+ * 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;
+ try {
+ newPage = (WikiPage) wikiPage.clone();
+ } catch (CloneNotSupportedException cnse) {
+ System.out.println("cannot clone the page: " + cnse);
+ }
+
+ try {
+ pageName = newPage.getName();
+ String newContent = parseLinks(newPage.getContent());
+
+ newPage.setPageContent(newContent);
+
+ return newPage;
+ } catch (IOException e) {
+ System.out.println(e);
+ newPage.setPageContent("error on page");
+ }
+ return newPage;
+ }
+
@Override
public void init() {
- portalHome = getProperty("htmlTranslatorURL")+"portal/";
- mediaPatterns = getProperty("imagePatterns");
- imagePath = getProperty("htmlTranslatorURL")+"wiki";
-
+ portalHome = getProperty("htmlTranslatorURL") + "portal/";
+ mediaPatterns = getProperty("imagePatterns");
+ imagePath = getProperty("htmlTranslatorURL") + "wiki";
+ wikiHome = getProperty("wikiHome");
}
}
\ No newline at end of file
Modified: trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/Edit.jsp
===================================================================
--- trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/Edit.jsp 2005-08-23 20:18:53 UTC (rev 935)
+++ trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/Edit.jsp 2005-08-24 12:40:41 UTC (rev 936)
@@ -18,13 +18,17 @@
String wikiContent = (String)request.getAttribute("wikiContent");
String wikiPage = (String)request.getAttribute("wikiPage");
String lockMsg = (String)request.getAttribute("lockMsg");
+ String defaultPage = (String)request.getAttribute("defaultPage");
if (lockMsg == null)
lockMsg = "";
%>
-<h2><%=wikiName%>: <%=wikiPage%></h2>
+<h2><a href="<%=actionURL%>&page=<%=defaultPage%>"><%=wikiName%></a>/ <%=wikiPage%> </h2>
+<!--
+<br />
+<a href="<%=actionURL%>&page=<%=defaultPage%>"><%=defaultPage%></a><br />-->
<hr />
<div style="color:#FF0000"><%=lockMsg%></div>
@@ -33,7 +37,7 @@
<input type="hidden" name="editedPage" value="<%=wikiPage%>" />
<input type="hidden" name="page" value="<%=wikiPage%>" />
<input type="submit" value="Save" name="editAction" />
-<input type="submit" value="Preview" name="editAction" />
+<!--<input type="submit" value="Preview" name="editAction" />-->
<input type="submit" value="Cancel" name="editAction" />
</form>
Here's a short reminder on what elements you have at your disposal:
Modified: trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/PageInfo.jsp
===================================================================
--- trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/PageInfo.jsp 2005-08-23 20:18:53 UTC (rev 935)
+++ trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/PageInfo.jsp 2005-08-24 12:40:41 UTC (rev 936)
@@ -17,17 +17,21 @@
String wikiName = (String)request.getAttribute("wikiName");
//String wikiContent = (String)request.getAttribute("wikiContent");
String wikiPage = (String)request.getAttribute("wikiPage");
+ String defaultPage = (String)request.getAttribute("defaultPage");
//java.util.Date editDate = (java.util.Date)request.getAttribute("editDate");
//org.jboss.wiki.Credentials author = (org.jboss.wiki.Credentials)request.getAttribute("author");
%>
-<h2><%=wikiName%>/ <%=wikiPage%></h2>
+<h2><a href="<%=actionURL%>&page=<%=defaultPage%>"><%=wikiName%></a>/ <%=wikiPage%> </h2>
-<hr />
+<!--<hr />
+<a href="<%=actionURL%>&page=<%=defaultPage%>"><%=defaultPage%></a>
<div class="wikiTrail">Your trail: <i>TODO</i></div>
-
+-->
<hr />
+<h3>History of page: <a href="<%=actionURL%>&page=<%=wikiPage%>"><%=wikiPage%></a></h3>
+<hr />
<table>
<tr>
@@ -70,4 +74,4 @@
</tr>
</table>
-<a href="<%=actionURL%>&page=<%=wikiPage%>">Back to <%=wikiPage%></a>
+
Modified: trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/Wiki.jsp
===================================================================
--- trunk/forge/portal-extensions/forge-wiki/src/web/WEB-INF/jsp/Wiki.jsp 2005-...
[truncated message content] |