From: <jbo...@li...> - 2005-08-11 23:38:20
|
Author: szimano Date: 2005-08-11 19:37:01 -0400 (Thu, 11 Aug 2005) New Revision: 828 Added: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiTypeHandler.java trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiTypes.xml trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/HTMLWikiType.java Log: couple files missing for plugins in wiki Added: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiTypeHandler.java =================================================================== --- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiTypeHandler.java 2005-08-11 23:24:01 UTC (rev 827) +++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiTypeHandler.java 2005-08-11 23:37:01 UTC (rev 828) @@ -0,0 +1,179 @@ +/************************************************** + * * + * JBoss Labs: Creating Professional Open Source * + * * + * Distributable under LGPL license. * + * See terms of license at gnu.org. * + * * + *************************************************/ +package org.jboss.wiki; + +import java.util.Stack; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * The WikiTypeHandler for parsing WikiType xml file. + * <p> + * + * @author <a href="mailto:ds...@jb...">Damon Sicore</a> + * @author <a href="mailto:tom...@jb...">Tomasz Szimanski</a> + * @version $Id$ + */ + +public class WikiTypeHandler extends DefaultHandler { + + private String lastWikiType = ""; + + private Stack<String> elements = new Stack<String>(); + + private boolean isInsidePlugin = false; + + private WikiEngine wikiEngine; + + private WikiType wikiType; + + private String wikiTypeName; + + private String pluginName = "", pluginClass = ""; + + @Override + public void endDocument() throws SAXException { + super.endDocument(); + + System.out.println("WikiType configuration file parsed."); + } + + @Override + public void endElement(String uri, String localName, String qName) + throws SAXException { + super.endElement(uri, localName, qName); + + if (qName.equals("plugin")) { + isInsidePlugin = false; + } else if ((qName.equals("wikiType")) && (wikiType != null)) { + // add WikiType + + wikiEngine.addWikiType(wikiType.getName(), wikiType); + wikiType = null; + wikiTypeName = null; + } + + // System.out.println("End element: "+uri+" "+localName+" "+qName); + } + + @Override + public void error(SAXParseException e) throws SAXException { + super.error(e); + System.err.println("[WikiType Parser:ERROR]: " + e); + } + + @Override + public void fatalError(SAXParseException e) throws SAXException { + super.fatalError(e); + System.err.println("[WikiType Parser:FATAL ERROR]: " + e); + } + + @Override + public void startDocument() throws SAXException { + super.startDocument(); + System.out.println("Parsing the WikiType configuration file..."); + } + + @Override + public void startElement(String uri, String localName, String qName, + Attributes attributes) throws SAXException { + super.startElement(uri, localName, qName, attributes); + /* + * System.out.println("Element: uri: "+uri+" lname: "+localName+" qname: + * "+qName); for (int i = 0; i < attributes.getLength(); i++) { + * System.out.println("Attr "+i+": "+attributes.getQName(i)+" = + * "+attributes.getIndex(attributes.getQName(i))); } + */ + if (qName.equals("plugin")) { + isInsidePlugin = true; + } else if (qName.equals("wikiType")) { + // start building new WikiType + + //wikiType = new WikiType(); + } + + elements.push(qName); + } + + @Override + public void warning(SAXParseException e) throws SAXException { + super.warning(e); + System.out.println("[WikiType Parser:WARNING]: " + e); + } + + public WikiTypeHandler(WikiEngine wikiEngine) { + this.wikiEngine = wikiEngine; + } + + @Override + public void characters(char[] ch, int start, int length) + throws SAXException { + super.characters(ch, start, length); + String element; + + String s = (new String(ch)).substring(start, start + length); + + if (((int) s.charAt(0) != 9) + && ((int) s.charAt(0) != 10) + && (!elements.isEmpty())) { + + element = elements.pop(); + + if ((element.equals("class")) && (!isInsidePlugin)) { + // class for wikiType + + try { + wikiType = (WikiType)Class.forName(s).newInstance(); + } + catch(Exception e) { + System.err.println("Cannot load WikiType class: "+e); + } + + if (wikiTypeName != null) { + wikiType.setName(wikiTypeName); + wikiTypeName = null; + } + + } else if ((element.equals("name")) || (element.equals("class"))) { + if (isInsidePlugin) { + // set name and class - if we have them both - add plugin to + // wikitype + + if (element.equals("class")) { + pluginClass = s; + } else { + pluginName = s; + } + + + if ((pluginName.length() > 0) && (pluginClass.length() > 0)) { + // we have em both - add a plugin + + wikiType.addPlugin(pluginName, pluginClass); + + pluginClass = pluginName = ""; + } + + + } else { + // here only if found name of WikiType (see prev. if clause) + if (wikiType != null) { + wikiType.setName(s); + } + else { + wikiTypeName = s; + } + } + } + } + } +} Added: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiTypes.xml =================================================================== --- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiTypes.xml 2005-08-11 23:24:01 UTC (rev 827) +++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/WikiTypes.xml 2005-08-11 23:37:01 UTC (rev 828) @@ -0,0 +1,16 @@ +<wikiTypes> + <wikiType> + <name>HTML</name> + <class>org.jboss.wiki.plugins.HTMLWikiType</class> + <plugin> + <name>wikiToHtmlTranslator</name> + <class>org.jboss.wiki.plugins.HTMLTranslator</class> + </plugin> + + <!--<plugin> + <name>trail</name> + <class>org.jboss.wiki.plugins.TrailPlugin</class> + </plugin>--> + + </wikiType> +</wikiTypes> \ No newline at end of file Added: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/HTMLWikiType.java =================================================================== --- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/HTMLWikiType.java 2005-08-11 23:24:01 UTC (rev 827) +++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/HTMLWikiType.java 2005-08-11 23:37:01 UTC (rev 828) @@ -0,0 +1,12 @@ +package org.jboss.wiki.plugins; + +import org.jboss.wiki.WikiType; + +public class HTMLWikiType extends WikiType { + + public HTMLWikiType () { + + } + + +} |