|
From: <jbo...@li...> - 2005-08-11 23:25:26
|
Author: szimano
Date: 2005-08-11 19:24:01 -0400 (Thu, 11 Aug 2005)
New Revision: 827
Added:
trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/HTMLTranslator.java
Removed:
trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/HashMap.java
trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/WikiParser.java
Modified:
trunk/forge/portal-extensions/forge-wiki/maven.xml
trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiContext.java
trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiEngine.java
trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPage.java
trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPlugin.java
trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPortlet.java
trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiType.java
Log:
plugins working so-so
Modified: trunk/forge/portal-extensions/forge-wiki/maven.xml
===================================================================
--- trunk/forge/portal-extensions/forge-wiki/maven.xml 2005-08-11 19:44:28 UTC (rev 826)
+++ trunk/forge/portal-extensions/forge-wiki/maven.xml 2005-08-11 23:24:01 UTC (rev 827)
@@ -10,6 +10,9 @@
<ant:fileset dir="src/java/org/jboss/wiki">
<ant:filename name="*.properties" />
</ant:fileset>
+ <ant:fileset dir="src/java/org/jboss/wiki">
+ <ant:filename name="*.xml" />
+ </ant:fileset>
</ant:copy>
<attainGoal name="war" />
Deleted: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/HashMap.java
===================================================================
--- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/HashMap.java 2005-08-11 19:44:28 UTC (rev 826)
+++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/HashMap.java 2005-08-11 23:24:01 UTC (rev 827)
@@ -1,8 +0,0 @@
- package org.jboss.wiki;
-
-/**
- * <p></p>
- *
- */
-public class HashMap {
- }
Modified: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiContext.java
===================================================================
--- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiContext.java 2005-08-11 19:44:28 UTC (rev 826)
+++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiContext.java 2005-08-11 23:24:01 UTC (rev 827)
@@ -14,7 +14,10 @@
* @author <a href="mailto:tom...@jb...">Tomasz Szymanski</a>
* @version $Id$
*/
+import java.util.Date;
+
import org.jboss.portal.core.model.User;
+import org.jboss.wiki.plugins.HTMLTranslator;
/**
* <p></p>
@@ -37,7 +40,6 @@
* <p></p>
*
*/
- public WikiType wikiType;
public WikiContext(User user, WikiType requestedType) {
this.user = user;
@@ -53,8 +55,10 @@
return user;
}
- public WikiType getWikiType() {
- return wikiType;
+
+ public WikiPage process(WikiPage wikiPage) {
+ return requestedType.process(wikiPage);
}
+
}
Modified: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiEngine.java
===================================================================
--- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiEngine.java 2005-08-11 19:44:28 UTC (rev 826)
+++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiEngine.java 2005-08-11 23:24:01 UTC (rev 827)
@@ -8,9 +8,15 @@
*************************************************/
package org.jboss.wiki;
+import java.util.Date;
import java.util.HashMap;
import java.util.Map;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.SAXException;
+
/**
*
* @author <a href="mailto:ds...@jb...">Damon Sicore</a>
@@ -30,17 +36,11 @@
*
*/
private String urlBase;
-
+
/**
* <p>Represents ...</p>
*
*/
- private Map wikiTypes;
-
-/**
- * <p>Represents ...</p>
- *
- */
private Map wikiTypePlugins;
/**
@@ -49,6 +49,8 @@
*/
private HashMap<String, WikiPage> pages;
+ private HashMap<String, WikiType> wikiTypes;
+
private MediaDataSource mediaDataSource;
/**
@@ -114,7 +116,7 @@
pages.put(pageName, ret);
}
- return ret;
+ return wikiContext.process(ret);
}
/**
@@ -124,18 +126,26 @@
* @return
*/
public void init() {
-
+ mediaDataSource = new FileDataSource();
+ pages = new HashMap<String, WikiPage>();
+ wikiTypes = new HashMap<String, WikiType>();
+ loadWikiTypes();
}
/**
- * <p>Does ...</p>
+ * <p>Parses configuration file to get WikiTypes</p>
*
*
* @return
*/
- protected void loadWikiTypes() {
- // your code here
- //return null;
+ protected void loadWikiTypes() {
+ try {
+ SAXParser sp = (SAXParserFactory.newInstance()).newSAXParser();
+ sp.parse(WikiTypeHandler.class.getResourceAsStream("WikiTypes.xml"), new WikiTypeHandler(this));
+ }
+ catch (Exception se) {
+ System.err.println("Error while parsing WikiType configuration: "+se);
+ }
}
/**
@@ -214,13 +224,37 @@
//return null;
}
+ public void addWikiType(String name, WikiType wikiType) {
+ System.out.println("[WIKIENGINE]: Added WikiType: "+name+" Class: "+wikiType);
+ wikiTypes.put(name, wikiType);
+ }
+
+ public WikiType getWikiType(String wikiTypeName) {
+ System.out.println("[WIKITYPE REQUEST]: "+wikiTypes.get(wikiTypeName));
+ return wikiTypes.get(wikiTypeName);
+ }
/**
* <p></p>
*
*/
public WikiEngine() {
- mediaDataSource = new FileDataSource();
- pages = new HashMap<String, WikiPage>();
-
+ init();
}
+
+
+
+ public static void main(String[] args) {
+ WikiEngine we = new WikiEngine();
+
+ WikiType wt = we.getWikiType("HTML");
+
+ WikiContext wc = new WikiContext(null, wt);
+
+ WikiPage wp = new WikiPage("name", new Credentials("tomek"), "[content|ble sme]", 1, new Date());
+
+ wp = wc.process(wp);
+
+ System.out.println(wp.getContent());
+ }
+
}
Modified: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPage.java
===================================================================
--- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPage.java 2005-08-11 19:44:28 UTC (rev 826)
+++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPage.java 2005-08-11 23:24:01 UTC (rev 827)
@@ -6,269 +6,308 @@
* See terms of license at gnu.org. *
* *
*************************************************/
- package org.jboss.wiki;
+package org.jboss.wiki;
import java.io.Serializable;
import java.util.Date;
+import java.util.HashMap;
/**
- * <p></p>
+ * <p>
+ * </p>
*
*/
- /**
- *
- * @author <a href="mailto:ds...@jb...">Damon Sicore</a>
- * @author <a href="mailto:tom...@jb...">Tomasz Szymanski</a>
- * @version $Id$
- */
-public class WikiPage implements Serializable, WikiProperties {
+/**
+ *
+ * @author <a href="mailto:ds...@jb...">Damon Sicore</a>
+ * @author <a href="mailto:tom...@jb...">Tomasz Szymanski</a>
+ * @version $Id$
+ */
+public class WikiPage implements Serializable, WikiProperties, Cloneable {
-/**
+ /**
*
*/
private static final long serialVersionUID = 1L;
-/**
- * <p>Represents ...</p>
- *
- */
- private String name;
+ /**
+ * <p>
+ * Represents ...
+ * </p>
+ *
+ */
+ private String name;
-/**
- * <p>Represents ...</p>
- *
- * WikiPage
- * This class is _abstract_
- * and has to be extended by the class
- * that we're willing to show our
- * content
- *
- * functions to be extended:
- * WikiPage(...) - constructor
- * getAttributes() - gets set of atributes
- * to be send to the appropriate JSP page
- * saveThisPage(data:Object) - saves
- * next version of this page with new data
- * getJSPPath() - gets apropriate JSP page
- * to show plugin
- * getDataProviderName - gets name of
- * the plugin _must_ be the same as in the
- * plugin name in plugin.xml
- */
- private Credentials lastAuthor;
+ /**
+ * <p>
+ * Represents ...
+ * </p>
+ *
+ * WikiPage This class is _abstract_ and has to be extended by the class
+ * that we're willing to show our content
+ *
+ * functions to be extended: WikiPage(...) - constructor getAttributes() -
+ * gets set of atributes to be send to the appropriate JSP page
+ * saveThisPage(data:Object) - saves next version of this page with new data
+ * getJSPPath() - gets apropriate JSP page to show plugin
+ * getDataProviderName - gets name of the plugin _must_ be the same as in
+ * the plugin name in plugin.xml
+ */
+ private Credentials lastAuthor;
-/**
- * <p>Represents ...</p>
- *
- */
- private int lastVersion;
+ /**
+ * <p>
+ * Represents ...
+ * </p>
+ *
+ */
+ private int lastVersion;
-/**
- * <p>Represents ...</p>
- *
- */
- private Date editDate;
+ /**
+ * <p>
+ * Represents ...
+ * </p>
+ *
+ */
+ private Date editDate;
-/**
- * <p>Represents ...</p>
- *
- */
- private MediaDataSource mediaDataSource;
+ /**
+ * <p>
+ * Represents ...
+ * </p>
+ *
+ */
+ private MediaDataSource mediaDataSource;
-/**
- * <p></p>
- *
- */
- public WikiEngine wikiEngine;
-/**
- * <p></p>
- *
- */
- public WikiEngine wikiEngine_1;
-
- private String pageContent;
+ /**
+ * <p>
+ * </p>
+ *
+ */
+ public WikiEngine wikiEngine;
-/**
- * <p>Does ...</p>
- *
- *
- * @return
- * @param pageName
- * @param data
- * @param pageAuthor
- * @param pageDate
- */
- public static WikiPage createPage(String pageName, Object data, String pageAuthor, java.util.Date pageDate) {
- // your code here
- return null;
- }
+ /**
+ * <p>
+ * </p>
+ *
+ */
+ public WikiEngine wikiEngine_1;
-/**
- * <p>Does ...</p>
- *
- *
- * @param pageName
- * @param pageAuthor
- * @param path
- */
- public WikiPage(String pageName, Credentials pageAuthor, String pageContent, int pageVersion, Date editDate) {
- name = pageName;
- lastAuthor = pageAuthor;
- this.pageContent = pageContent;
- lastVersion = pageVersion;
- this.editDate = editDate;
- }
+ private String pageContent;
-/**
- * <p>Does ...</p>
- *
- *
- * @return
- */
- public HashMap getAttributes() {
- // your code here
- return null;
- }
+ /**
+ * <p>
+ * Does ...
+ * </p>
+ *
+ *
+ * @return
+ * @param pageName
+ * @param data
+ * @param pageAuthor
+ * @param pageDate
+ */
+ public static WikiPage createPage(String pageName, Object data,
+ String pageAuthor, java.util.Date pageDate) {
+ // your code here
+ return null;
+ }
-/**
- * <p>Does ...</p>
- *
- */
- public void save() {
- // your code here
- }
+ /**
+ * <p>
+ * Does ...
+ * </p>
+ *
+ *
+ * @param pageName
+ * @param pageAuthor
+ * @param path
+ */
+ public WikiPage(String pageName, Credentials pageAuthor,
+ String pageContent, int pageVersion, Date editDate) {
+ name = pageName;
+ lastAuthor = pageAuthor;
+ this.pageContent = pageContent;
+ lastVersion = pageVersion;
+ this.editDate = editDate;
+ }
-/**
- * <p>Does ...</p>
- *
- *
- * @return
- */
- public String getPath() {
- // your code here
- return null;
- }
+ /**
+ * <p>
+ * Does ...
+ * </p>
+ *
+ *
+ * @return
+ */
+ public HashMap getAttributes() {
+ // your code here
+ return null;
+ }
-/**
- * <p>Does ...</p>
- *
- *
- * @return
- * @param mds
- */
- public boolean setMediaDataSource(MediaDataSource mds) {
- // your code here
- return false;
- }
+ /**
+ * <p>
+ * Does ...
+ * </p>
+ *
+ */
+ public void save() {
+ // your code here
+ }
-/**
- * <p>Does ...</p>
- *
- *
- * @param version
- * @return
- */
- public boolean updateToVersion(int version) {
- // your code here
- return false;
- }
+ /**
+ * <p>
+ * Does ...
+ * </p>
+ *
+ *
+ * @return
+ */
+ public String getPath() {
+ // your code here
+ return null;
+ }
-/**
- * <p>Does ...</p>
- *
- *
- * @return
- * @param version
- */
- public WikiPage getPageAtVersion(int version) {
- // your code here
- return null;
- }
+ /**
+ * <p>
+ * Does ...
+ * </p>
+ *
+ *
+ * @return
+ * @param mds
+ */
+ public boolean setMediaDataSource(MediaDataSource mds) {
+ // your code here
+ return false;
+ }
-/**
- * <p>Does ...</p>
- *
- *
- * @return
- */
- public String getContent() {
- return getPageContent();
- }
+ /**
+ * <p>
+ * Does ...
+ * </p>
+ *
+ *
+ * @param version
+ * @return
+ */
+ public boolean updateToVersion(int version) {
+ // your code here
+ return false;
+ }
-/**
- * <p>Does ...</p>
- *
- *
- * @return
- */
- public MediaDataSource getMediaDataSource() {
- // your code here
- return null;
- }
+ /**
+ * <p>
+ * Does ...
+ * </p>
+ *
+ *
+ * @return
+ * @param version
+ */
+ public WikiPage getPageAtVersion(int version) {
+ // your code here
+ return null;
+ }
-/**
- * <p>Does ...</p>
- *
- *
- * @return
- * @param text
- */
- public void setWikiText(int text) {
- // your code here
- //return null;
- }
-
- public void showPage() {
- System.out.println("Page name: "+getName());
- System.out.println("Page author: "+getLastAuthor());
- System.out.println("Page version: "+getLastVersion());
- System.out.println("Page editdate: "+getEditDate());
- System.out.println("Page Content: \n"+getContent());
- }
+ /**
+ * <p>
+ * Does ...
+ * </p>
+ *
+ *
+ * @return
+ */
+ public String getContent() {
+ return getPageContent();
+ }
-/**
- * <p></p>
- *
- */
- public MediaInternalization mediaInternalization;
+ /**
+ * <p>
+ * Does ...
+ * </p>
+ *
+ *
+ * @return
+ */
+ public MediaDataSource getMediaDataSource() {
+ // your code here
+ return null;
+ }
-public java.util.Date getEditDate() {
- return editDate;
-}
+ /**
+ * <p>
+ * Does ...
+ * </p>
+ *
+ *
+ * @return
+ * @param text
+ */
+ public void setWikiText(int text) {
+ // your code here
+ // return null;
+ }
-public void setEditDate(java.util.Date editDate) {
- this.editDate = editDate;
-}
+ public void showPage() {
+ System.out.println("Page name: " + getName());
+ System.out.println("Page author: " + getLastAuthor());
+ System.out.println("Page version: " + getLastVersion());
+ System.out.println("Page editdate: " + getEditDate());
+ System.out.println("Page Content: \n" + getContent());
+ }
-public Credentials getLastAuthor() {
- return lastAuthor;
-}
+ /**
+ * <p>
+ * </p>
+ *
+ */
+ public MediaInternalization mediaInternalization;
-public void setLastAuthor(Credentials lastAuthor) {
- this.lastAuthor = lastAuthor;
-}
+ public java.util.Date getEditDate() {
+ return editDate;
+ }
-public int getLastVersion() {
- return lastVersion;
-}
+ public void setEditDate(java.util.Date editDate) {
+ this.editDate = editDate;
+ }
-public void setLastVersion(int lastVersion) {
- this.lastVersion = lastVersion;
-}
+ public Credentials getLastAuthor() {
+ return lastAuthor;
+ }
-public String getName() {
- return name;
-}
+ public void setLastAuthor(Credentials lastAuthor) {
+ this.lastAuthor = lastAuthor;
+ }
-public void setName(String name) {
- this.name = name;
-}
+ public int getLastVersion() {
+ return lastVersion;
+ }
-public String getPageContent() {
- return pageContent;
-}
+ public void setLastVersion(int lastVersion) {
+ this.lastVersion = lastVersion;
+ }
-public void setPageContent(String pageContent) {
- this.pageContent = pageContent;
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getPageContent() {
+ return pageContent;
+ }
+
+ public void setPageContent(String pageContent) {
+ this.pageContent = pageContent;
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ WikiPage clonedPage = new WikiPage(getName(), getLastAuthor(),
+ getPageContent(), getLastVersion(), getEditDate());
+ return clonedPage;
+ }
}
- }
Modified: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPlugin.java
===================================================================
--- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPlugin.java 2005-08-11 19:44:28 UTC (rev 826)
+++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPlugin.java 2005-08-11 23:24:01 UTC (rev 827)
@@ -31,7 +31,7 @@
* @return
* @param content
*/
- public WikiPage apply(WikiPage wikiPage);
+ public WikiPage process(WikiPage wikiPage);
/**
* <p>Does ...</p>
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-11 19:44:28 UTC (rev 826)
+++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiPortlet.java 2005-08-11 23:24:01 UTC (rev 827)
@@ -35,47 +35,9 @@
wikiEngine = new WikiEngine();
}
- public String translateLinks(String content, String actionURL) {
- String href1regex = "\\[.+\\|.+\\]";
- String href2regex = "\\[.+\\]";
-
- String translatedContent = content;
-
- Matcher match;
-
- while ((match = Pattern.compile(href1regex).matcher(translatedContent))
- .find()) {
- translatedContent = match.replaceFirst("<a href=\""
- + actionURL
- + "&page="
- + (translatedContent.substring(translatedContent.indexOf(
- "|", match.start() + 1) + 1, match.end() - 1)).trim()
- + "\">"
- + translatedContent.substring(match.start() + 1,
- translatedContent.indexOf("|", match.start() + 1))
- + "</a>");
- }
-
- while ((match = Pattern.compile(href2regex).matcher(translatedContent))
- .find()) {
- translatedContent = match.replaceFirst("<a href=\""
- + actionURL
- + "&page="
- + (translatedContent.substring(match.start() + 1, match
- .end() - 1)).trim()
- + "\">"
- + translatedContent.substring(match.start() + 1, match
- .end() - 1) + "</a>");
- }
-
- translatedContent = translatedContent.replace("\n", "<BR>\n");
-
- return translatedContent;
- }
-
public void processAction(JBossActionRequest rReq, JBossActionResponse rResp) {
- WikiContext wikiContext = new WikiContext(rReq.getUser(), new WikiType());
+ WikiContext wikiContext = new WikiContext(rReq.getUser(), wikiEngine.getWikiType("HTML"));
if (rReq.getParameter("action") != null) {
rResp.setRenderParameter("action", rReq.getParameter("action"));
@@ -143,7 +105,7 @@
wikiPage = rReq.getParameter("page");
}
- WikiContext wikiContext = new WikiContext(rReq.getUser(), new WikiType());
+ WikiContext wikiContext = new WikiContext(rReq.getUser(), wikiEngine.getWikiType("HTML"));
PortletURL wikiURL = rRes.createActionURL();
@@ -161,7 +123,7 @@
pageToShow = wikiEngine.getByName(wikiPage, wikiContext);
}
- rReq.setAttribute("wikiContent", (page == "Wiki.jsp") ? translateLinks(pageToShow.getContent(), wikiURL.toString()) : pageToShow.getContent());
+ rReq.setAttribute("wikiContent", pageToShow.getContent());
rReq.setAttribute("wikiPage", wikiPage);
Modified: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiType.java
===================================================================
--- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiType.java 2005-08-11 19:44:28 UTC (rev 826)
+++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiType.java 2005-08-11 23:24:01 UTC (rev 827)
@@ -6,74 +6,140 @@
* See terms of license at gnu.org. *
* *
*************************************************/
- package org.jboss.wiki;
+package org.jboss.wiki;
+import java.util.HashMap;
import java.util.List;
+import java.util.Set;
/**
- * <p></p>
+ * <p>
+ * </p>
*
*/
- /**
- *
- * @author <a href="mailto:ds...@jb...">Damon Sicore</a>
- * @author <a href="mailto:tom...@jb...">Tomasz Szymanski</a>
- * @version $Id$
- */
-public class WikiType {
-
/**
- * <p>Represents ...</p>
*
+ * @author <a href="mailto:ds...@jb...">Damon Sicore</a>
+ * @author <a href="mailto:tom...@jb...">Tomasz Szymanski</a>
+ * @version $Id$
*/
- private List pluginChain;
-/**
- * <p></p>
- *
- */
- public WikiTypeDescriptor wikiTypeDescriptor;
-/**
- * <p></p>
- *
- */
- public WikiPluginChain wikiPluginChain;
-/**
- * <p></p>
- *
- */
- public WikiContext wikiContext;
+public class WikiType {
-/**
- * <p>Does ...</p>
- *
- *
- * @return
- */
- public void getPluginChain() {
- // your code here
- //return null;
- }
+ protected String name;
-/**
- * <p>Does ...</p>
- *
- *
- * @return
- */
- public void initPluginChain() {
- // your code here
- //return null;
- }
+ /**
+ * <p>
+ * Represents ...
+ * </p>
+ *
+ */
+ protected List pluginChain;
-/**
- * <p>Does ...</p>
- *
- *
- * @return
- * @param content
- */
- public String apply(String content) {
- // your code here
- return null;
- }
- }
+ /**
+ * <p>
+ * </p>
+ *
+ */
+ protected WikiTypeDescriptor wikiTypeDescriptor;
+
+ /**
+ * <p>
+ * </p>
+ *
+ */
+ protected WikiPluginChain wikiPluginChain;
+
+ /**
+ * <p>
+ * </p>
+ *
+ */
+ protected WikiContext wikiContext;
+
+ protected HashMap<String, WikiPlugin> plugins = new HashMap<String, WikiPlugin>();
+
+ /**
+ * <p>
+ * Does ...
+ * </p>
+ *
+ *
+ * @return
+ */
+ public void getPluginChain() {
+ // your code here
+ // return null;
+ }
+
+ /**
+ * <p>
+ * Does ...
+ * </p>
+ *
+ *
+ * @return
+ */
+
+ public void initPluginChain() {
+ // your code here
+ // return null;
+ }
+
+ public void addPlugin(String pluginName, String pluginClass) {
+
+ WikiPlugin plugin = null;
+
+ try {
+ plugin = (WikiPlugin) Class.forName(pluginClass).newInstance();
+ } catch (Exception e) {
+ System.err.println("Error while loading plugin: " + pluginName
+ + "\nclass: " + pluginClass + "\n" + e);
+ }
+
+ if (plugin != null) {
+ plugins.put(pluginName, plugin);
+
+ System.out.println("[WikiType:" + name + "]Plugin added: "
+ + pluginName + " class: " + pluginClass);
+ }
+
+ }
+
+ /**
+ * <p>
+ * Does ...
+ * </p>
+ *
+ *
+ * @return
+ * @param content
+ */
+ public WikiPage process(WikiPage wikiPage) {
+ WikiPage newPage = null;
+
+ try {
+ newPage = (WikiPage)wikiPage.clone();
+ }
+ catch (CloneNotSupportedException cnse) {
+ System.out.println("cannot clone the page: " + cnse);
+ }
+
+ Set<String> ks = plugins.keySet();
+
+ for (String str : ks) {
+ System.out.println("Executing plugin: "+str);
+ newPage = (plugins.get(str)).process(newPage);
+ }
+
+ return newPage;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ System.out.print("Setting new WikiType name: " + name);
+ this.name = name;
+ }
+}
Added: 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-11 19:44:28 UTC (rev 826)
+++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/HTMLTranslator.java 2005-08-11 23:24:01 UTC (rev 827)
@@ -0,0 +1,225 @@
+package org.jboss.wiki.plugins;
+
+/**
+ * @author rali
+ *
+ *
+ */
+import java.util.regex.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.StringTokenizer;
+
+import org.jboss.wiki.Credentials;
+import org.jboss.wiki.WikiPage;
+import org.jboss.wiki.WikiPlugin;
+
+public class HTMLTranslator implements WikiPlugin {
+
+ private Pattern myPattern;
+
+ private Matcher myMatcher;
+
+ /* URL components, later to be configurable */
+ private String portalHome = "http://forge.sicore.org:8080/portal/";
+
+ private String wikiHome = "index.html?ctrl:id=window.default.WikiPortletWindow";
+
+ private String actionType = "&ctrl:type=";
+
+ private String page = "&page=";
+
+ public ArrayList mediaPatterns;
+
+ public ArrayList linkPatterns;
+
+ public String[] textlinks;
+
+ public String[] notextlinks;
+
+ private String[] mediaFormats = { "*.png", "*.jpeg", "*.gif" };
+
+ public HTMLTranslator() {
+ }
+
+ /*
+ * compile all links to wiki pages or external pages of the form [...] or
+ * [...|...]
+ */
+ public String parseLinks(String text, String actionURL) {
+ String translatedContent = text;
+ String link;// = "";
+ String href1regex = "\\[.+\\|.+\\]";
+ String href2regex = "\\[.+\\]";
+ Pattern tLinks = Pattern.compile(href1regex);
+ Pattern links = Pattern.compile(href2regex);
+ Matcher textlinks = tLinks.matcher(text);
+ Matcher nontextlinks = links.matcher(text);
+
+ Matcher match;
+
+ while ((match = tLinks.matcher(translatedContent)).find()) {
+ link = (translatedContent.substring(translatedContent.indexOf("|",
+ match.start() + 1) + 1, match.end() - 1)).trim();
+ if (isExternalLink(link)) // outside link
+ {
+ translatedContent = match.replaceFirst("<a href=\""
+ + link
+ + "\">"
+ + translatedContent.substring(match.start() + 1,
+ translatedContent.indexOf("|",
+ match.start() + 1)) + "</a>");
+ } else
+ // need to implement pageExists
+ translatedContent = match.replaceFirst("<a href=\""
+ + portalHome
+ + wikiHome
+ + actionType
+ + "action"
+ + page
+ + cleanLink(link)
+ + "\">"
+ + translatedContent.substring(match.start() + 1,
+ translatedContent.indexOf("|",
+ match.start() + 1)) + "</a>");
+ }
+
+ while ((match = links.matcher(translatedContent)).find()) {
+ link = (translatedContent.substring(match.start() + 1,
+ match.end() - 1));
+ if (isExternalLink(link)) // outside link
+ {
+ translatedContent = match.replaceFirst("<a href=\"" + link
+ + "\">" + link + "</a>");
+ } else
+ translatedContent = match.replaceFirst("<a href=\""
+ + portalHome + wikiHome + actionType + "action" + page
+ + cleanLink(link) + "\">" + link + "</a>");
+ }
+
+ translatedContent = translatedContent.replace("\n", "<BR>\n");
+
+ return translatedContent;
+ }
+
+ /* 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]);
+ }
+
+ return patterns;
+ }
+
+ /**
+ * Figures out if a link is an off-site link. This recognizes the most
+ * common protocols by checking how it starts.
+ */
+ private boolean isExternalLink(String link) {
+ return link.startsWith("http:") || link.startsWith("ftp:")
+ || link.startsWith("https:") || link.startsWith("mailto:")
+ || link.startsWith("news:") || link.startsWith("file:");
+ }
+
+ /**
+ * 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
+ */
+ 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();
+ }
+
+ public WikiPage process(WikiPage wikiPage) {
+ WikiPage newPage = null;
+
+ try {
+ newPage = (WikiPage) wikiPage.clone();
+ } catch (CloneNotSupportedException cnse) {
+ System.out.println("cannot clone the page: " + cnse);
+ }
+
+ String newContent = parseLinks(newPage.getContent(), "dupa");
+
+ newPage.setPageContent(newContent);
+
+ return newPage;
+ }
+
+ public void next() {
+ // TODO Auto-generated method stub
+
+ }
+
+ // 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
Deleted: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/WikiParser.java
===================================================================
--- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/WikiParser.java 2005-08-11 19:44:28 UTC (rev 826)
+++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/WikiParser.java 2005-08-11 23:24:01 UTC (rev 827)
@@ -1,196 +0,0 @@
-package org.jboss.wiki.plugins;
-
-/**
- * @author rali
- *
- *
- */
-import java.util.regex.*;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.StringTokenizer;
-
-public class WikiParser {
-
- private static Pattern myPattern;
-
- private Matcher myMatcher;
-
- /* URL components, later to be configurable */
- private static String portalHome = "http://forge.sicore.org:8080/portal/";
-
- private static String wikiHome = "index.html?ctrl:id=window.default.WikiPortletWindow";
-
- private static String actionType = "&ctrl:type=";
-
- private static String page = "&page=";
-
- public ArrayList mediaPatterns;
-
- public ArrayList linkPatterns;
-
- public static String[] textlinks;
-
- public static String[] notextlinks;
-
- private String[] mediaFormats = { "*.png", "*.jpeg", "*.gif" };
-
- public WikiParser() {
- }
-
- /*
- * compile all links to wiki pages or external pages of the form [...] or
- * [...|...]
- */
- public static String parseLinks(String text, String actionURL) {
- String translatedContent = text;
- String link;// = "";
- String href1regex = "\\[.+\\|.+\\]";
- String href2regex = "\\[.+\\]";
- Pattern tLinks = Pattern.compile(href1regex);
- Pattern links = Pattern.compile(href2regex);
- Matcher textlinks = tLinks.matcher(text);
- Matcher nontextlinks = links.matcher(text);
-
- Matcher match;
-
- while ((match = tLinks.matcher(translatedContent)).find()) {
- link = (translatedContent.substring(translatedContent.indexOf("|",
- match.start() + 1) + 1, match.end() - 1)).trim();
- if (isExternalLink(link)) //outside link
- {
- translatedContent = match.replaceFirst("<a href=\""
- + link
- + "\">"
- + translatedContent.substring(match.start() + 1,
- translatedContent.indexOf("|",
- match.start() + 1)) + "</a>");
- } else
- //need to implement pageExists
- translatedContent = match.replaceFirst("<a href=\""
- + portalHome
- + wikiHome
- + actionType
- + "action"
- + page
- + cleanLink(link)
- + "\">"
- + translatedContent.substring(match.start() + 1,
- translatedContent.indexOf("|",
- match.start() + 1)) + "</a>");
- }
-
- while ((match = links.matcher(translatedContent)).find()) {
- link = (translatedContent.substring(match.start() + 1,
- match.end() - 1));
- if (isExternalLink(link)) //outside link
- {
- translatedContent = match.replaceFirst("<a href=\""
- + link
- + "\">"
- + link + "</a>");
- }else
- translatedContent = match.replaceFirst("<a href=\"" + portalHome
- + wikiHome
- + actionType
- + "action"
- + page
- + cleanLink(link)
- + "\">"+ link + "</a>");
- }
-
- translatedContent = translatedContent.replace("\n", "<BR>\n");
-
- return translatedContent;
- }
-
- /* 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]);
- }
-
- return patterns;
- }
-
- /**
- * Figures out if a link is an off-site link. This recognizes the most
- * common protocols by checking how it starts.
- */
- private static boolean isExternalLink(String link) {
- return link.startsWith("http:") || link.startsWith("ftp:")
- || link.startsWith("https:") || link.startsWith("mailto:")
- || link.startsWith("news:") || link.startsWith("file:");
- }
-
- /**
- * 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
- */
- public static 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();
- }
-
-// 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);
-// }
-
-}
\ No newline at end of file
|