[Yanel-commits] rev 25853 - in public/yanel/trunk/src/realms/jsp-wiki/resources: . jsp-wiki-resource jsp-wiki-resource/config jsp-wiki-resource/src jsp-wiki-resource/src/build jsp-wiki-resource/src/java jsp-wiki-resource/src/java/org jsp-wiki-resource/src/java/org/wyona jsp-wiki-resource/src/java/org/wyona/yanel jsp-wiki-resource/src/java/org/wyona/yanel/impl jsp-wiki-resource/src/java/org/wyona/yanel/impl/resources jsp-wiki-resource/xslt

michi at wyona.com michi at wyona.com
Tue Jul 10 10:20:29 CEST 2007


Author: michi
Date: 2007-07-10 10:20:28 +0200 (Tue, 10 Jul 2007)
New Revision: 25853

Added:
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/README.txt
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/build.xml
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/config/
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/config/wikiParser.config
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/resource.xml
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/build/
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/build/build.properties
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/build/dependencies.xml
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/build/spring-wiki-config.xml
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/java/
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/java/org/
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/java/org/wyona/
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/java/org/wyona/yanel/
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/java/org/wyona/yanel/impl/
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/java/org/wyona/yanel/impl/resources/
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/java/org/wyona/yanel/impl/resources/JSPWikiResource.java
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/xslt/
   public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/xslt/wiki2xhtml.xsl
Log:
jsp wiki resource started

Added: public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/README.txt
===================================================================
--- public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/README.txt	                        (rev 0)
+++ public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/README.txt	2007-07-10 08:20:28 UTC (rev 25853)
@@ -0,0 +1,21 @@
+Configuring the Wiki Parser:
+----------------------------
+
+The Wiki Parser can be configured at 3 different places:
+
+ - First it looks up the ".yanel-rti":
+   wiki-syntax: jspWikiParser
+
+ - Then the wiki resource will look up in the config directory:
+   .../wiki/config/wikiParser.config
+
+ - And last it will fallback to the hard-coded version within the Wiki java class
+
+
+The key of a Wiki Parser can be found at
+  .../wiki/src/build/spring-wiki-config.xml
+
+<beans>
+  <bean id="jspWikiParser" class="org.wyona.jspwiki.WikiParser"/>
+  <bean id ..../>
+</beans>

Added: public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/build.xml
===================================================================
--- public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/build.xml	                        (rev 0)
+++ public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/build.xml	2007-07-10 08:20:28 UTC (rev 25853)
@@ -0,0 +1,50 @@
+<?xml version="1.0"?>
+
+<project name="yanel-resource" default="compile">
+
+  <import file="src/build/dependencies.xml"/>
+
+  <target name="init" description="Initialize build" depends="dependencies">
+    <echo>Initialize build</echo>
+
+    <dirname property="resource.home.dir" file="${ant.file}"/>
+    <echo>Resource Home Directory: ${resource.home.dir}</echo>
+
+    <property file="${resource.home.dir}/src/build/local.build.properties"/>
+    <property file="${resource.home.dir}/src/build/build.properties"/>
+
+    <path id="classpath">
+      <pathelement path="${maven2.cp}"/>
+      <pathelement path="${maven2.resource.cp}"/>
+    </path>
+    <property name="resource.build.dir" value="${resource.home.dir}/build"/>
+    <property name="resource.classes.dir" value="${resource.build.dir}/classes"/>
+    <property name="resource.lib.dir" value="${resource.build.dir}/lib"/>
+    <property name="resource.java.dir" value="${resource.home.dir}/src/java"/>
+  </target>
+
+  <target name="compile" description="Compile Java classes" depends="init">
+
+    <mkdir dir="${resource.classes.dir}"/>
+    <javac srcdir="${resource.java.dir}" destdir="${resource.classes.dir}"
+      classpathref="classpath"
+      debug="true"
+    />
+    <mkdir dir="${resource.lib.dir}"/>
+    <jar destfile="${resource.lib.dir}/yanel-resource-${resource.name}-${resource.version}.jar"
+      basedir="${resource.classes.dir}"
+    />
+  </target>
+
+  <target name="clean" depends="init">
+    <delete dir="${resource.build.dir}"/>
+  </target>
+
+  <target name="copy-dependencies" depends="init">
+    <copy todir="${build.dir}/webapps/${servlet.context.prefix}/WEB-INF/classes" file="src/build/spring-wiki-config.xml"/>
+    <copy todir="${build.dir}/webapps/${servlet.context.prefix}/WEB-INF/lib">
+      <fileset refid="maven2.resource.fileset"/>
+      <mapper type="flatten"/>
+    </copy>
+  </target>
+</project>

Added: public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/config/wikiParser.config
===================================================================
--- public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/config/wikiParser.config	                        (rev 0)
+++ public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/config/wikiParser.config	2007-07-10 08:20:28 UTC (rev 25853)
@@ -0,0 +1 @@
+wiki-syntax: jspWikiParser

Added: public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/resource.xml
===================================================================
--- public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/resource.xml	                        (rev 0)
+++ public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/resource.xml	2007-07-10 08:20:28 UTC (rev 25853)
@@ -0,0 +1,16 @@
+<?xml version="1.0"?>
+
+<resource xmlns="http://www.wyona.org/yanel/1.0"
+  name="jsp-wiki"
+  namespace="http://www.wyona.org/yanel/resource/1.0"
+  class="org.wyona.yanel.impl.resources.JSPWikiResource"
+  >
+<description>
+Wiki (tested with JSPWiki content)
+</description>
+
+<rtd>
+  <property name="wiki-syntax" default-value="jspWikiParser"/>
+  <property name="xslt"/>
+</rtd>
+</resource>

Added: public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/build/build.properties
===================================================================
--- public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/build/build.properties	                        (rev 0)
+++ public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/build/build.properties	2007-07-10 08:20:28 UTC (rev 25853)
@@ -0,0 +1,2 @@
+resource.name=jsp-wiki
+resource.version=1.0-dev-rXXXXX

Added: public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/build/dependencies.xml
===================================================================
--- public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/build/dependencies.xml	                        (rev 0)
+++ public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/build/dependencies.xml	2007-07-10 08:20:28 UTC (rev 25853)
@@ -0,0 +1,58 @@
+<?xml version="1.0"?>
+
+<project name="wiki-dependencies" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
+
+  <target name="dependencies" description="Dependencies">
+    <!-- INFO: http://maven.apache.org/ant-tasks.html -->
+    <artifact:remoteRepository id="wyona.remote.repository" url="http://www.wyona.org/maven2/"/>
+
+    <artifact:dependencies pathId="maven2.classpath" filesetId="maven2.fileset">
+      <remoteRepository refid="wyona.remote.repository"/>
+      <dependency groupId="wyona-org-yanel" artifactId="yanel-core"
+                  version="${yanel.source.version}"/>
+      <dependency groupId="javax.servlet" artifactId="servlet-api" version="2.3"/>
+      <dependency groupId="xml-resolver" artifactId="xml-resolver" version="1.1"/>
+      <dependency groupId="xalan" artifactId="xalan" version="2.7.0"/>
+      <dependency groupId="wyona-org-yanel" artifactId="yanel-resource-wiki" version="1.0-dev-r25843"/>
+    </artifact:dependencies>
+
+    <artifact:dependencies pathId="maven2.resource.classpath" filesetId="maven2.resource.fileset">
+      <remoteRepository refid="wyona.remote.repository"/>
+
+      <dependency groupId="spring" artifactId="spring"
+                  version="2.0"/>
+      <dependency groupId="com-ecyrd-jspwiki" artifactId="JSPWiki-patched"
+                  version="2.4.71-r25408"/>
+
+      <dependency groupId="wyona-org-wiki-parser" artifactId="jsp-wiki-parser"
+                  version="0.0.1-dev-r24881"/>
+      <dependency groupId="wyona-org-wiki-parser" artifactId="wiki-parser-factory"
+                  version="r19560"/>
+      <dependency groupId="wyona-org-wiki-parser" artifactId="wyona-wiki-parser"
+                  version="r20641"/>
+      <dependency groupId="apache-org-lucene" artifactId="lucene-highlighter"
+                  version="1.x"/>
+      <dependency groupId="apache-org-commons" artifactId="jrcs-diff"
+                  version="1.x"/>
+      <dependency groupId="opensymphony" artifactId="oscache"
+                  version="2.3"/>
+      <dependency groupId="commons-lang" artifactId="commons-lang"
+                  version="2.2"/>
+      <dependency groupId="oro" artifactId="oro"
+                  version="2.0.8"/>
+      <dependency groupId="jdom" artifactId="jdom"
+                  version="1.0"/>
+
+      <dependency groupId="ecs" artifactId="ecs"
+                  version="1.4.2"/>
+      <dependency groupId="jaxen" artifactId="jaxen"
+                  version="1.1-beta-10"/>
+
+
+    </artifact:dependencies>
+
+    <property name="maven2.cp" refid="maven2.classpath"/>
+    <property name="maven2.resource.cp" refid="maven2.resource.classpath"/>
+  </target>
+
+</project>

Added: public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/build/spring-wiki-config.xml
===================================================================
--- public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/build/spring-wiki-config.xml	                        (rev 0)
+++ public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/build/spring-wiki-config.xml	2007-07-10 08:20:28 UTC (rev 25853)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+
+<beans>
+  <bean id="jspWikiParser" class="org.wyona.jspwiki.WikiParser"/>
+  <bean id="javaccWikiParser" class="org.wyona.wiki.Wiki2XML"/>
+</beans>

Added: public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/java/org/wyona/yanel/impl/resources/JSPWikiResource.java
===================================================================
--- public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/java/org/wyona/yanel/impl/resources/JSPWikiResource.java	                        (rev 0)
+++ public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/src/java/org/wyona/yanel/impl/resources/JSPWikiResource.java	2007-07-10 08:20:28 UTC (rev 25853)
@@ -0,0 +1,452 @@
+/*
+ * Copyright 2006 Wyona
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.wyona.org/licenses/APACHE-LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.wyona.yanel.impl.resources;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.HashMap;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.sax.SAXTransformerFactory;
+import javax.xml.transform.sax.TransformerHandler;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.log4j.Category;
+import org.apache.xml.resolver.tools.CatalogResolver;
+import org.apache.xml.serializer.Serializer;
+
+import org.wyona.wikiparser.IWikiParser;
+
+import org.wyona.yanel.core.Path;
+import org.wyona.yanel.core.Resource;
+import org.wyona.yanel.core.ResourceConfiguration;
+import org.wyona.yanel.core.api.attributes.CreatableV2;
+import org.wyona.yanel.core.api.attributes.ModifiableV2;
+import org.wyona.yanel.core.api.attributes.ViewableV1;
+import org.wyona.yanel.core.attributes.viewable.View;
+import org.wyona.yanel.core.attributes.viewable.ViewDescriptor;
+import org.wyona.yanel.core.serialization.SerializerFactory;
+import org.wyona.yanel.core.source.ResourceResolver;
+import org.wyona.yanel.core.transformation.I18nTransformer;
+import org.wyona.yanel.core.transformation.I18nTransformer2;
+import org.wyona.yanel.core.transformation.XIncludeTransformer;
+import org.wyona.yanel.core.util.PathUtil;
+
+import org.wyona.yarep.core.RepositoryException;
+import org.wyona.yarep.core.Repository;
+import org.wyona.yarep.util.RepoPath;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
+
+/**
+ * 
+ */
+public class JSPWikiResource extends Resource implements ViewableV1, CreatableV2, ModifiableV2 {
+
+    private static Category log = Category.getInstance(JSPWikiResource.class);
+    private final String XML_MIME_TYPE = "application/xml";
+    private DocumentBuilderFactory dbf = null;
+    private HashMap properties = new HashMap();
+    private final String DEFAULT_WIKI_PARSER_BEAN_ID = "jspWikiParser";
+    
+    /**
+     * 
+     */
+    public JSPWikiResource() {
+        dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        properties.put("title", "");
+    }
+
+    /**
+     * 
+     */
+    public ViewDescriptor[] getViewDescriptors() {
+        ViewDescriptor[] vd = new ViewDescriptor[3];
+        vd[0] = new ViewDescriptor("default");
+        vd[0].setMimeType("application/xhtml+xml");
+        vd[1] = new ViewDescriptor("source");
+        vd[1].setMimeType("application/xml");
+        vd[2] = new ViewDescriptor("txt");
+        vd[2].setMimeType("text/plain");
+        return vd;
+    }
+    
+    /**
+     * Get view of resource
+     */
+    public View getView(Path path, String viewId) {
+        try {
+            Repository dataRepo = getRealm().getRepository();
+            if (viewId != null && viewId.equals("txt")) {
+                View view = new View();
+                view.setInputStream(dataRepo.getInputStream(new org.wyona.yarep.core.Path(getPath())));
+                view.setMimeType("text/plain");
+                return view;
+            }
+
+            View defaultView = new View();
+            
+            String path2Resource = path.toString();
+            path2Resource = path2Resource.substring(0, path2Resource.lastIndexOf("/") + 1);
+            
+            String wikiParserBeanId = getWikiSyntax(path);
+            InputStream inputStream = dataRepo.getInputStream(new org.wyona.yarep.core.Path(getPath()));
+            IWikiParser wikiParser = (IWikiParser) yanel.getBeanFactory().getBean(wikiParserBeanId);
+            wikiParser.parse(inputStream);
+            
+            Transformer transformer = null;
+            if(viewId != null && viewId.equals("source")) {
+                transformer = TransformerFactory.newInstance().newTransformer();
+                defaultView.setMimeType(XML_MIME_TYPE);
+            } else {
+                File xsltFile = org.wyona.commons.io.FileUtil.file(getRTD().getConfigFile().getParentFile().getAbsolutePath(), "xslt" + File.separator + "wiki2xhtml.xsl");
+                log.debug("XSLT file: " + xsltFile);
+                transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(xsltFile));
+                transformer.setParameter("yanel.path.name", PathUtil.getName(getPath()));
+                transformer.setParameter("yanel.path", getPath());
+                defaultView.setMimeType("application/xhtml+xml");
+            }
+            LinkChecker linkChecker = new LinkChecker(path2Resource);
+            SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
+            saxParser.parse(wikiParser.getInputStream(), linkChecker);
+            
+            java.io.ByteArrayOutputStream byteArrayOutputStream = new java.io.ByteArrayOutputStream();
+            
+            transformer.transform(new StreamSource(linkChecker.getInputStream()), new StreamResult(byteArrayOutputStream));
+
+            inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
+            
+            if(viewId != null && viewId.equals("source")) {
+                defaultView.setInputStream(inputStream);
+                return defaultView;
+            }
+            
+            // create reader:
+            XMLReader xmlReader = XMLReaderFactory.createXMLReader();
+            CatalogResolver catalogResolver = new CatalogResolver();
+            xmlReader.setEntityResolver(catalogResolver);
+
+            // create xslt transformer:
+            TransformerHandler xsltHandler = null;
+            if(getXSLTPath() != null) {
+                
+                SAXTransformerFactory tf = (SAXTransformerFactory)TransformerFactory.newInstance();
+                xsltHandler = tf.newTransformerHandler(new StreamSource(dataRepo.getInputStream(new org.wyona.yarep.core.Path(getXSLTPath().toString()))));
+                transformer = xsltHandler.getTransformer();
+                transformer.setParameter("yanel.path.name", PathUtil.getName(getPath()));
+                transformer.setParameter("yanel.path", getPath());
+                transformer.setParameter("yanel.back2context", PathUtil.backToContext(realm, getPath()));
+                transformer.setParameter("yarep.back2realm", PathUtil.backToRealm(getPath()));
+                
+            }
+
+            // create xinclude transformer:
+            XIncludeTransformer xIncludeTransformer = new XIncludeTransformer();
+            ResourceResolver resolver = new ResourceResolver(this);
+            xIncludeTransformer.setResolver(resolver);
+            
+            // create i18n transformer:
+            I18nTransformer2 i18nTransformer = new I18nTransformer2("global", getRealm().getDefaultLanguage(), getRealm().getDefaultLanguage());
+            i18nTransformer.setEntityResolver(catalogResolver);
+            
+            // create serializer:
+            Serializer serializer = SerializerFactory.getSerializer(SerializerFactory.XHTML_STRICT);
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+            // chain everything together (create a pipeline):
+            if (xsltHandler != null) {
+                xmlReader.setContentHandler(xsltHandler);
+                xsltHandler.setResult(new SAXResult(xIncludeTransformer));
+            } else {
+                xmlReader.setContentHandler(xIncludeTransformer);
+            }
+            xIncludeTransformer.setResult(new SAXResult(i18nTransformer));
+            i18nTransformer.setResult(new SAXResult(serializer.asContentHandler()));
+            serializer.setOutputStream(baos);
+            
+            // execute pipeline:
+            xmlReader.parse(new InputSource(inputStream));
+
+            defaultView.setInputStream(new ByteArrayInputStream(baos.toByteArray()));
+            return defaultView;
+        } catch (Exception e) {
+            log.error(e, e);
+        }
+        return null;
+    }
+
+    /**
+     * 
+     */
+    public View getView(HttpServletRequest request, String viewId) {
+        String _language = getRealm().getDefaultLanguage();
+        try {
+            _language = request.getParameter("yanel.meta.language");
+        } catch(Exception e) {
+            //use fallback language
+            _language = getRealm().getDefaultLanguage();
+        }
+        //if(_language == null || ("").equals(_language)) _language = language;
+        //else language = _language;
+        return getView(new Path(request.getServletPath()), viewId);
+    }
+
+    /**
+     * 
+     */
+    public View getView(HttpServletRequest request, OutputStream outputStream, String viewId) {
+        return null;
+    }
+
+    /**
+     * Get path of global XSLT
+     */
+    private Path getXSLTPath() throws Exception {
+        ResourceConfiguration resConfig = getConfiguration();
+        String xslt = null;
+        if (resConfig != null) {
+            xslt = resConfig.getProperty("xslt");
+        } else {
+            // Fallback to deprecated RTI
+            xslt= getRTI().getProperty("xslt");
+        }
+
+        if (xslt != null) return new Path(xslt);
+        log.info("No XSLT Path for: " + getPath());
+        return null;
+    }
+    
+    /**
+     * this method will get the wikiparser type for this resource 
+     * first it will look up the rti resp. rtd than 
+     * it will look in the config file for this resource if none of the could be found
+     * it will use the default hard coded in this class  
+     */
+    private String getWikiSyntax(Path path) {
+        String wikiParserBeanId = null;
+
+        try {
+            // Check on Resource config resp. RTI
+            ResourceConfiguration resConfig = getConfiguration();
+            if (resConfig != null) {
+                wikiParserBeanId = resConfig.getProperty("wiki-syntax");
+            } else {
+                // Fallback to deprecated RTI
+                wikiParserBeanId = getRTI().getProperty("wiki-syntax");
+            }
+            if (wikiParserBeanId != null) return wikiParserBeanId;
+
+            // Check within resource type itself
+            File configFile = org.wyona.commons.io.FileUtil.file(getRTD().getConfigFile()
+                    .getParentFile()
+                    .getAbsolutePath(), "config" + File.separator + "wikiParser.config");
+            log.debug("configFile : " + configFile.getAbsolutePath());
+            java.io.BufferedReader br = new java.io.BufferedReader(new java.io.FileReader(configFile));
+            while ((wikiParserBeanId = br.readLine()) != null) {
+                if (wikiParserBeanId.indexOf("wiki-syntax:") == 0) {
+                    wikiParserBeanId = wikiParserBeanId.substring(13);
+                    log.debug("found wiki-syntax in config file: " + wikiParserBeanId);
+                    return wikiParserBeanId;
+                }
+            }
+        } catch (IOException ioe) {
+            log.error("IOException");
+        } catch (Exception e) {
+            log.error("Exception" + e);//was warn
+        } finally {
+            wikiParserBeanId = DEFAULT_WIKI_PARSER_BEAN_ID;    
+        }
+        log.warn("Using fallback default wiki parser: " + DEFAULT_WIKI_PARSER_BEAN_ID);
+        return DEFAULT_WIKI_PARSER_BEAN_ID;
+    }
+    
+
+    /**
+     * @return the empty wiki resource as String 
+     */
+    private String getEmptyWiki(String title) {
+        StringBuffer emptyWikiXml = new StringBuffer();
+        emptyWikiXml.append("!"+title);
+        
+        return emptyWikiXml.toString();
+    }
+    
+    /**
+     *
+     */
+    private String getWikiIntrospection(String title, String createName) {
+        StringBuffer emptyWikiPageContent = new StringBuffer();
+        emptyWikiPageContent.append("<?xml version=\"1.0\"?>");
+        emptyWikiPageContent.append("\n");
+        emptyWikiPageContent.append("\n<introspection xmlns=\"http://www.wyona.org/neutron/2.0\">");
+        emptyWikiPageContent.append("\n");
+        emptyWikiPageContent.append("\n  <resource name=\"" + title + "\">");
+        emptyWikiPageContent.append("\n  <edit mime-type=\"text/plain\">");
+        emptyWikiPageContent.append("\n    <checkout url=\"" + createName + "?yanel.resource.viewid=txt&amp;yanel.resource.usecase=checkout\" method=\"GET\"/>");
+        emptyWikiPageContent.append("\n    <checkin  url=\"" + createName + "?yanel.resource.usecase=checkin\" method=\"PUT\"/>");
+        emptyWikiPageContent.append("\n  </edit>");
+        emptyWikiPageContent.append("\n  </resource>");
+        emptyWikiPageContent.append("\n</introspection>");
+        
+        return emptyWikiPageContent.toString();
+    }    
+    
+    public String[] getPropertyNames() {
+        String[] propertyNames = (String[])properties.keySet().toArray(new String[properties.keySet().size()]);
+        return propertyNames;
+    }
+
+    public void setProperty(String name, Object value){
+        properties.put(name, value);
+    }
+
+    public Object getProperty(String name){
+        Object property = properties.get(name);
+        return property;
+    }
+    
+    public String getPropertyType(String propertyName){
+        //TODO not implemented yet
+        return null;
+    }
+  
+    /**
+     *
+     */
+    public void create(HttpServletRequest request){
+        String title = getRequest().getParameter("rp.title");
+        writeContentAndIntrospection(getEmptyWiki(title), title);
+    }
+ 
+    /**
+     * Write new content into data repository
+     */
+    public void writeContentAndIntrospection(String content, String title) {
+        try {
+            org.wyona.yarep.core.Path newPath = new org.wyona.yarep.core.Path(getPath().toString());
+            Repository dataRepo = getRealm().getRepository();
+
+            log.info("Writing content into repository \"" + dataRepo.getName() + "\" with content:\n" + content + "\nto path: " + newPath);
+            if (!dataRepo.existsNode(newPath.toString())) {
+                //TODO: Add nodes recursively ...
+                dataRepo.getNode(newPath.getParent().toString()).addNode(newPath.getName(), org.wyona.yarep.core.NodeType.RESOURCE);
+                log.warn("Node has been created: " + newPath);
+            }
+            Writer writer = dataRepo.getWriter(newPath);
+            writer.write(content);
+            writer.close();
+
+            org.wyona.yarep.core.Path introspectionPath = new org.wyona.yarep.core.Path(newPath.getParent() + "/introspection-" + newPath.getName() + ".xml");
+            String introspectionContent = getWikiIntrospection(title, newPath.getName());
+            log.error("DEBUG: Writing introspection into repository \"" + dataRepo.getName() + "\" with content:\n" + introspectionContent + "\nto path: " + introspectionPath);
+            if (!dataRepo.existsNode(introspectionPath.toString())) {
+                //TODO: Add nodes recursively ...
+                dataRepo.getNode(introspectionPath.getParent().toString()).addNode(introspectionPath.getName(), org.wyona.yarep.core.NodeType.RESOURCE);
+                log.warn("Node has been created: " + introspectionPath);
+            }
+            writer = dataRepo.getWriter(introspectionPath);
+            writer.write(introspectionContent);
+            writer.close();
+
+            // TODO: This seems to be a bad idea, rather use ?...&amp;yanel.resource.viewid=txt
+            //dataRepo.addSymbolicLink(newPath, new org.wyona.yarep.core.Path(newPath.toString() + ".txt"));
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+    }
+
+    /**
+     *
+     */
+    public HashMap createRTIProperties(HttpServletRequest request) {
+        HashMap map = new HashMap();
+        // TODO: Do not hardcode xslt ...
+        map.put("DO_NOT_HARDCODE_xslt", "/xslt/global.xsl");
+
+        // TODO: Make mime-type configurable (depending on global XSLT) ...
+        map.put("mime-type", "application/xhtml+xml");
+        return map;
+    }
+
+    /**
+     *
+     */
+    public boolean delete() {
+        log.warn("No implemented yet!");
+        return false;
+    }
+
+    /**
+     *
+     */
+    public InputStream getInputStream() {
+        log.warn("No implemented yet!");
+        return null;
+    }
+
+    /**
+     *
+     */
+    public java.io.Reader getReader() {
+        log.warn("No implemented yet!");
+        return null;
+    }
+
+    /**
+     *
+     */
+    public OutputStream getOutputStream() throws Exception {
+        return getRealm().getRepository().getOutputStream(new Path(getPath()));
+    }
+
+    /**
+     *
+     */
+    public Writer getWriter() {
+        log.warn("No implemented yet!");
+        return null;
+    }
+
+    /**
+     *
+     */
+    public long getLastModified() {
+        log.warn("No implemented yet!");
+        return -1;
+    }
+
+    /**
+     *
+     */
+    public void write(InputStream in) {
+        log.warn("No implemented yet!");
+    }
+}

Added: public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/xslt/wiki2xhtml.xsl
===================================================================
--- public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/xslt/wiki2xhtml.xsl	                        (rev 0)
+++ public/yanel/trunk/src/realms/jsp-wiki/resources/jsp-wiki-resource/xslt/wiki2xhtml.xsl	2007-07-10 08:20:28 UTC (rev 25853)
@@ -0,0 +1,232 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+  Copyright 1999-2004 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<xsl:stylesheet version="1.0"
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:wiki="http://www.wyona.org/yanel/1.0"
+                xmlns="http://www.w3.org/1999/xhtml"
+                >
+<!--
+                xmlns:dc="http://purl.org/dc/elements/1.1/"
+                >
+-->
+  
+  <xsl:param name="yanel.path.name" select="'YANEL_PATH_NAME_IS_NULL'"/>
+  <xsl:param name="yanel.path" select="'YANEL_PATH_IS_NULL'"/>
+  
+  <xsl:variable name="name-without-suffix" select="substring-before($yanel.path.name, '.')"/>
+  
+  <!-- TODO: Lenya stuff which needs to be replaced ... -->
+  <xsl:param name="area" select="'AREA_IS_NULL'"/>
+  <xsl:param name="publication" select="'PUBLICATION_IS_NULL'"/>
+  <xsl:param name="contextprefix" select="'CONTEXT_PREFIX_IS_NULL'"/>
+  
+  <xsl:template match="/">
+    <html>
+      <head>
+        <title>A Wiki page</title>
+          <link rel="neutron-introspection" href="introspection-{$yanel.path.name}.xml" type="application/neutron+xml"/>
+<!--
+        <xsl:choose>
+          <xsl:when test="string-length($name-without-suffix) > 0">
+            <link rel="neutron-introspection" href="introspection-{$name-without-suffix}.xml" type="application/neutron+xml"/>
+          </xsl:when>
+          <xsl:otherwise>
+            <link rel="neutron-introspection" href="introspection-{$yanel.path.name}.xml" type="application/neutron+xml"/>
+          </xsl:otherwise>
+        </xsl:choose>
+-->
+      </head>
+      <body>
+        <xsl:apply-templates/>
+      </body>
+    </html>
+  </xsl:template>
+  
+  <xsl:template match="wiki:wiki">
+    <xsl:apply-templates/>
+  </xsl:template>
+  
+  <xsl:template match="wiki:WikiBody">
+    <xsl:apply-templates/>
+  </xsl:template>
+  
+  <xsl:template match="wiki:Paragraph">
+    <p>
+      <xsl:apply-templates/>
+    </p>
+  </xsl:template>
+  
+  <xsl:template match="wiki:Title">
+    <h1>
+      <xsl:apply-templates/>
+    </h1>
+  </xsl:template>
+  
+  <xsl:template match="wiki:MainTitle">
+    <h2>
+      <xsl:apply-templates/>
+    </h2>
+  </xsl:template>
+  
+  <xsl:template match="wiki:MainMainTitle">
+    <h3>
+      <xsl:apply-templates/>
+    </h3>
+  </xsl:template>
+  
+  <xsl:template match="wiki:Bold">
+    <b>
+      <xsl:apply-templates/>
+    </b>
+  </xsl:template>
+  
+  <xsl:template match="wiki:Italic">
+    <i>
+      <xsl:apply-templates/>
+    </i>
+  </xsl:template>
+  
+  <xsl:template match="wiki:Underline">
+    <u>
+      <xsl:apply-templates/>
+    </u>
+  </xsl:template>
+  
+  <xsl:template match="wiki:ForceNewline">
+    <br/>
+    <xsl:apply-templates/>
+  </xsl:template>
+  
+  <xsl:template match="wiki:BList">
+    <ul>
+      <xsl:apply-templates/>
+    </ul>
+  </xsl:template>
+ 
+  <xsl:template match="wiki:BListItem">
+    <xsl:param name="depth" select="number(@depth)" />
+    <xsl:choose>
+      <xsl:when test="$depth &lt;= 1">
+        <li><xsl:apply-templates /></li>
+      </xsl:when>
+      <xsl:otherwise>
+        <ul>
+          <xsl:apply-templates select=".">
+            <xsl:with-param name="depth" select="$depth - 1" />
+          </xsl:apply-templates>
+        </ul>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  
+  <xsl:template match="wiki:NList">
+    <ol>
+      <xsl:apply-templates/>
+    </ol>
+  </xsl:template>
+  
+  <xsl:template match="wiki:NListItem">
+    <xsl:param name="depth" select="@depth" />
+    <xsl:choose>
+      <xsl:when test="$depth &lt;= 1">
+        <li><xsl:apply-templates /></li>
+      </xsl:when>
+      <xsl:otherwise>
+        <ol>
+          <xsl:apply-templates select=".">
+            <xsl:with-param name="depth" select="$depth - 1" />
+          </xsl:apply-templates>
+        </ol>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+  
+  <xsl:template match="wiki:Table">
+    <table style="border:1px #000000 solid; border-collapse: collapse;">
+      <xsl:for-each select="wiki:TableRow">
+        <tr>
+          <xsl:for-each select="wiki:TableCol">
+            <td style="border:1px #000000 solid; padding: 2px"><xsl:apply-templates/></td>
+          </xsl:for-each>
+        </tr>
+      </xsl:for-each>
+    </table>
+  </xsl:template>
+  
+  <xsl:template match="wiki:Hrule">
+    <hr/>
+    <xsl:apply-templates/>
+  </xsl:template>
+  
+  <xsl:template match="wiki:Link">
+    <xsl:choose>
+      <xsl:when test="@exist = 'false'">
+        <u>
+        <xsl:choose>
+          <xsl:when test="@label"><xsl:value-of select="@label"/></xsl:when>
+          <xsl:otherwise><xsl:value-of select="@href"/></xsl:otherwise>
+        </xsl:choose>
+        </u><a href="?yanel.usecase=create&amp;create.name={@href}">?</a>
+<!--
+        </u><a href="?yanel.usecase=create&amp;create.name={@href}&amp;resource.type=&lt;{http://www.wyona.org/yanel/resource/1.0}wiki/>">?</a><xsl:text>&#0160;</xsl:text>
+-->
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:choose>
+          <xsl:when test="@label">
+            <a href="{@href}"><xsl:value-of select="@label"/></a>
+          </xsl:when>
+          <xsl:otherwise>
+            <a href="{@href}"><xsl:value-of select="@href"/></a>
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+  
+  <xsl:template match="wiki:Text">
+    <xsl:value-of select="@value"/>
+  </xsl:template>
+  
+  <xsl:template match="wiki:PlainText">
+    <xsl:value-of select="@value"/>
+  </xsl:template>
+  
+  <xsl:template match="wiki:Plain">
+    <pre>
+      <xsl:apply-templates/>
+    </pre>
+  </xsl:template>
+  
+  <xsl:template match="wiki:Emoticons">
+    <xsl:apply-templates/>
+  </xsl:template>
+  
+  <xsl:template match="node()[starts-with(local-name(),'em_')]">
+    <xsl:call-template name="emoticon">
+      <xsl:with-param name="icon_name" select="local-name()"/>
+    </xsl:call-template>
+  </xsl:template>
+  
+  <xsl:template name="emoticon">
+    <xsl:param name="icon_name" select="none.png"/>
+    <img alt="{$icon_name}" src="{$contextprefix}/{$publication}/{$area}/{$icon_name}.png?lenya.module=wiki"/>
+  </xsl:template>
+  
+</xsl:stylesheet>




More information about the Yanel-commits mailing list