From: <tri...@us...> - 2008-07-24 11:01:55
|
Revision: 49 http://staticwiki.svn.sourceforge.net/staticwiki/?rev=49&view=rev Author: triathlon98 Date: 2008-07-24 11:01:51 +0000 (Thu, 24 Jul 2008) Log Message: ----------- SW-14 start servlet for (dynamic view) on wiki Modified Paths: -------------- trunk/pom.xml trunk/staticwiki-renderer/src/main/java/org/staticwiki/wiki/DefaultTemplateLoader.java trunk/staticwiki-renderer/src/main/java/org/staticwiki/wiki/WikiFactory.java Added Paths: ----------- trunk/staticwiki-servlet/ trunk/staticwiki-servlet/pom.xml trunk/staticwiki-servlet/src/ trunk/staticwiki-servlet/src/main/ trunk/staticwiki-servlet/src/main/java/ trunk/staticwiki-servlet/src/main/java/org/ trunk/staticwiki-servlet/src/main/java/org/staticwiki/ trunk/staticwiki-servlet/src/main/java/org/staticwiki/servlet/ trunk/staticwiki-servlet/src/main/java/org/staticwiki/servlet/ServletMacroLoader.java trunk/staticwiki-servlet/src/main/java/org/staticwiki/servlet/ServletTemplateLoader.java trunk/staticwiki-servlet/src/main/java/org/staticwiki/servlet/WikiServlet.java trunk/staticwiki-servlet/src/main/resources/ trunk/staticwiki-servlet/src/main/resources/wiki/ trunk/staticwiki-servlet/src/main/resources/wiki/sample/ trunk/staticwiki-servlet/src/main/resources/wiki/sample/META-INF/ trunk/staticwiki-servlet/src/main/resources/wiki/sample/META-INF/macro/ trunk/staticwiki-servlet/src/main/resources/wiki/sample/META-INF/resources/ trunk/staticwiki-servlet/src/main/resources/wiki/sample/META-INF/resources/wiki.css trunk/staticwiki-servlet/src/main/resources/wiki/sample/META-INF/template/ trunk/staticwiki-servlet/src/main/resources/wiki/sample/META-INF/template/WIKI.html trunk/staticwiki-servlet/src/main/resources/wiki/sample/info.meta trunk/staticwiki-servlet/src/main/resources/wiki/sample/info.wiki trunk/staticwiki-servlet/src/main/webapp/ trunk/staticwiki-servlet/src/main/webapp/WEB-INF/ trunk/staticwiki-servlet/src/main/webapp/WEB-INF/jboss-web.xml trunk/staticwiki-servlet/src/main/webapp/WEB-INF/web.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2008-06-03 18:58:38 UTC (rev 48) +++ trunk/pom.xml 2008-07-24 11:01:51 UTC (rev 49) @@ -79,6 +79,7 @@ <modules> <module>staticwiki-renderer</module> + <module>staticwiki-servlet</module> <module>staticwiki-editor</module> </modules> @@ -207,6 +208,11 @@ <artifactId>joda-time</artifactId> <version>1.4</version> </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + </dependency> </dependencies> </dependencyManagement> <repositories> Modified: trunk/staticwiki-renderer/src/main/java/org/staticwiki/wiki/DefaultTemplateLoader.java =================================================================== --- trunk/staticwiki-renderer/src/main/java/org/staticwiki/wiki/DefaultTemplateLoader.java 2008-06-03 18:58:38 UTC (rev 48) +++ trunk/staticwiki-renderer/src/main/java/org/staticwiki/wiki/DefaultTemplateLoader.java 2008-07-24 11:01:51 UTC (rev 49) @@ -32,7 +32,7 @@ return slurp( stream ); } - public String slurp( InputStream stream ) + public static String slurp( InputStream stream ) throws WikiException { if ( stream == null ) return ""; @@ -40,11 +40,12 @@ { BufferedReader br = new BufferedReader( new InputStreamReader( stream, "UTF-8" ) ); TextBuilder sb = TextBuilder.newInstance(); - String line = null; + String line; while ( ( line = br.readLine() ) != null ) { - sb.append( line + "\n" ); + sb.append( line ); + sb.append( "\n" ); } br.close(); Modified: trunk/staticwiki-renderer/src/main/java/org/staticwiki/wiki/WikiFactory.java =================================================================== --- trunk/staticwiki-renderer/src/main/java/org/staticwiki/wiki/WikiFactory.java 2008-06-03 18:58:38 UTC (rev 48) +++ trunk/staticwiki-renderer/src/main/java/org/staticwiki/wiki/WikiFactory.java 2008-07-24 11:01:51 UTC (rev 49) @@ -25,16 +25,17 @@ */ public class WikiFactory { + public static final String PIPELINE_DEFINITION = "org/staticwiki/wiki/WikiRenderPipeline.txt"; public static WikiRenderer getWikiRenderer() throws WikiException { - return getWikiRenderer( "org/staticwiki/wiki/WikiRenderPipeline.txt", new ResourceHandlerAdapter() ); + return getWikiRenderer( PIPELINE_DEFINITION, new ResourceHandlerAdapter() ); } public static WikiRenderer getWikiRenderer( ResourceHandler resourceHandler ) throws WikiException { - return getWikiRenderer( "org/staticwiki/wiki/WikiRenderPipeline.txt", resourceHandler ); + return getWikiRenderer( PIPELINE_DEFINITION, resourceHandler ); } public static WikiRenderer getWikiRenderer( String pipelineResource ) @@ -57,7 +58,7 @@ return new DefaultWikiRenderer( context ); } - private static WikiSubRenderer getRenderPipeline( String pipelineResource ) + public static WikiSubRenderer getRenderPipeline( String pipelineResource ) throws WikiException { InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream( pipelineResource ); Added: trunk/staticwiki-servlet/pom.xml =================================================================== --- trunk/staticwiki-servlet/pom.xml (rev 0) +++ trunk/staticwiki-servlet/pom.xml 2008-07-24 11:01:51 UTC (rev 49) @@ -0,0 +1,46 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>org.staticwiki</groupId> + <artifactId>staticwiki</artifactId> + <version>0.9.1-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <groupId>org.staticwiki</groupId> + <artifactId>staticwiki-servlet</artifactId> + <packaging>war</packaging> + <version>0.9.1-SNAPSHOT</version> + <name>staticwiki-servlet</name> + <description> + Create a dynamic wiki based on the staticwiki renderer. + </description> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-war-plugin</artifactId> + <configuration> + <!--<archiveClasses>true</archiveClasses>--> + <dependentWarExcludes>WEB-INF/web.xml,index.*</dependentWarExcludes> + <warSourceExcludes> + WEB-INF/lib/javassist*.jar,WEB-INF/lib/log4j*.jar,WEB-INF/lib/commons-*.jar + </warSourceExcludes> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.staticwiki</groupId> + <artifactId>staticwiki-renderer</artifactId> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> +</project> Added: trunk/staticwiki-servlet/src/main/java/org/staticwiki/servlet/ServletMacroLoader.java =================================================================== --- trunk/staticwiki-servlet/src/main/java/org/staticwiki/servlet/ServletMacroLoader.java (rev 0) +++ trunk/staticwiki-servlet/src/main/java/org/staticwiki/servlet/ServletMacroLoader.java 2008-07-24 11:01:51 UTC (rev 49) @@ -0,0 +1,66 @@ +/** + * This file is part of the staticwiki project. + * + * The contents of this file are subject to the GNU Lesser General Public License Version 2.1 or later (the "LGPL") + * (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.fsf.org/licenses/lgpl.html + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF + * ANY KIND, either express or implied. See the License for the specific language governing rights and + * limitations under the License. + */ + +package org.staticwiki.servlet; + +import org.staticwiki.wiki.macro.DefaultMacroLoader; +import org.staticwiki.wiki.macro.WikiMacro; +import org.staticwiki.wiki.macro.DefaultWikiMacro; +import org.staticwiki.wiki.WikiException; + +import java.io.File; +import java.io.InputStream; +import java.io.IOException; +import java.io.FileInputStream; +import java.util.Properties; + +/** + * Macro loader which gets the macro definitions from the META-INF/macro directory from the pages metadata container. + * So if the metadata for the file was at "blabla/page.md", the macro will be searched in "blabla/META-INF/macro/". + * + * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a> + */ +public class ServletMacroLoader + extends DefaultMacroLoader +{ + File meta; + + public ServletMacroLoader( File meta ) + { + this.meta = new File( meta.getParent(), WikiServlet.MACROS ); + } + + public WikiMacro load( CharSequence macroName ) + throws WikiException + { + File macro = new File( meta, macroName + ".properties" ); + if ( macro.exists() ) + { + Properties prop = new Properties(); + try + { + prop.load( new FileInputStream( macro ) ); + } + catch ( IOException ioe ) + { + throw new WikiException( ioe ); + } + boolean hasBody = "true".equals( prop.get( "hasBody" ) ); + String template = (String) prop.get( "template" ); + return new DefaultWikiMacro( macroName.toString(), hasBody, template ); + } + else + { + return super.load( macroName ); + } + } +} Added: trunk/staticwiki-servlet/src/main/java/org/staticwiki/servlet/ServletTemplateLoader.java =================================================================== --- trunk/staticwiki-servlet/src/main/java/org/staticwiki/servlet/ServletTemplateLoader.java (rev 0) +++ trunk/staticwiki-servlet/src/main/java/org/staticwiki/servlet/ServletTemplateLoader.java 2008-07-24 11:01:51 UTC (rev 49) @@ -0,0 +1,64 @@ +/** + * This file is part of the staticwiki project. + * + * The contents of this file are subject to the GNU Lesser General Public License Version 2.1 or later (the "LGPL") + * (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.fsf.org/licenses/lgpl.html + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF + * ANY KIND, either express or implied. See the License for the specific language governing rights and + * limitations under the License. + */ + +package org.staticwiki.servlet; + +import org.staticwiki.wiki.DefaultTemplateLoader; +import org.staticwiki.wiki.WikiException; +import org.apache.log4j.Logger; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +/** + * Template loader which gets the macro definitions from the META-INF/template directory from the pages metadata + * container. So if the metadata for the file was at "blabla/page.md", the template will be searched in + * "blabla/META-INF/template/". + * + * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a> + */ +public class ServletTemplateLoader + extends DefaultTemplateLoader +{ + private static final Logger log = Logger.getLogger( ServletTemplateLoader.class ); + + private File meta; + + public ServletTemplateLoader( File meta ) + { + this.meta = new File( meta.getParent(), WikiServlet.TEMPLATES ); + } + + public CharSequence getTemplate( String templateName ) + throws WikiException + { + try + { + File template = new File( meta, templateName + ".vm" ); + if ( template.exists() ) + { + return DefaultTemplateLoader.slurp( new FileInputStream( template ) ); + } + else + { + return super.getTemplate( templateName ); + } + + } + catch ( IOException ioe ) + { + log.error( "problem reading template " + templateName + " from meta " + meta.getAbsoluteFile(), ioe ); + } + return ""; + } +} Added: trunk/staticwiki-servlet/src/main/java/org/staticwiki/servlet/WikiServlet.java =================================================================== --- trunk/staticwiki-servlet/src/main/java/org/staticwiki/servlet/WikiServlet.java (rev 0) +++ trunk/staticwiki-servlet/src/main/java/org/staticwiki/servlet/WikiServlet.java 2008-07-24 11:01:51 UTC (rev 49) @@ -0,0 +1,109 @@ +/** + * This file is part of the staticwiki project. + * + * The contents of this file are subject to the GNU Lesser General Public License Version 2.1 or later (the "LGPL") + * (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.fsf.org/licenses/lgpl.html + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF + * ANY KIND, either express or implied. See the License for the specific language governing rights and + * limitations under the License. + */ + +package org.staticwiki.servlet; + +import org.staticwiki.wiki.*; +import org.apache.log4j.Logger; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.ServletException; +import java.io.*; + +/** + * Factory class to get a wiki renderer + * + * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a> + */ +public class WikiServlet + extends HttpServlet +{ + private static final Logger log = Logger.getLogger( WikiServlet.class ); + private static final String WIKI_ROOT = "wiki-root"; + + public static final String META = "META-INF/"; + public static final String MACROS = META + "macro"; + public static final String TEMPLATES = META + "template"; + public static final String RESOURCES = META + "resources"; + + protected void doGet( HttpServletRequest request, HttpServletResponse response ) + throws ServletException, IOException + { + String root = getServletConfig().getInitParameter( WIKI_ROOT ); + System.out.println( "root is " + root ); + System.out.println( "request uri is " + request.getRequestURI() ); + System.out.println( "servlet path is " + request.getServletPath() ); + System.out.println( "path info is " + request.getPathInfo() ); + System.out.println( "path translated is " + request.getPathTranslated() ); + System.out.println( "context path is " + request.getContextPath() ); + System.out.println( "remote user " + request.getRemoteUser() ); + + String fname = request.getPathInfo(); + // quick error checking, the meta stuff should not be directly accessible + if ( fname.contains( META ) ) + { + response.sendError( HttpServletResponse.SC_NOT_FOUND ); + return; + } + + String fnameOriginal = fname; + if ( fname.endsWith( ".html" ) ) fname = fname.substring( 0, fname.length() - 5 ); + File meta = new File( root, fname + ".meta" ); + if ( meta.exists() ) + { + File wiki = new File( root, fname + ".wiki" ); + try + { + DefaultWikiContext context = new DefaultWikiContext(); + context.setRenderPipeline( WikiFactory.getRenderPipeline( WikiFactory.PIPELINE_DEFINITION ) ); + context.setResourceHandler( new AllowAllResourceHandler() ); + context.setMacroLoader( new ServletMacroLoader( meta ) ); + context.setTemplateLoader( new ServletTemplateLoader( meta ) ); + WikiRenderer wikiRenderer = WikiFactory.getWikiRenderer( context ); + wikiRenderer.render( new FileReader( wiki ), response.getWriter() ); + } + catch ( WikiException we ) + { + log.error( "wiki render error" + we.toString(), we ); + response.sendError( HttpServletResponse.SC_INTERNAL_SERVER_ERROR ); + } + } + else + { + // @todo file location should be properly defined, it should split between path and filename and insert the "META-INF/resources" instead of prepending + File resource = new File( root, RESOURCES + fnameOriginal ); + if ( resource.exists() ) + { + copyStream( new FileInputStream( resource ), response.getOutputStream() ); + } + else + { + response.sendError( HttpServletResponse.SC_NOT_FOUND ); + } + } + } + + private void copyStream( InputStream in, OutputStream out ) + { + int data; + try + { + while ( ( data = in.read() ) >= 0 ) out.write( data ); + } + catch ( IOException ioe ) + { + log.error( "error while copying resource" + ioe.toString(), ioe ); + } + } +} Added: trunk/staticwiki-servlet/src/main/resources/wiki/sample/META-INF/resources/wiki.css =================================================================== --- trunk/staticwiki-servlet/src/main/resources/wiki/sample/META-INF/resources/wiki.css (rev 0) +++ trunk/staticwiki-servlet/src/main/resources/wiki/sample/META-INF/resources/wiki.css 2008-07-24 11:01:51 UTC (rev 49) @@ -0,0 +1,17 @@ +.wikiFootnoteMarker { + font-size : 60%; + vertical-align : super; + cursor : pointer; +} +.wikiFootnote { + font-size : 80%; + border : thin dotted black; + background-color : #FFFFCC; + margin : 2px 10em 2px 10em; +} + +#toc { + float : right; + width : 200px; + border : thin solid black; +} Added: trunk/staticwiki-servlet/src/main/resources/wiki/sample/META-INF/template/WIKI.html =================================================================== --- trunk/staticwiki-servlet/src/main/resources/wiki/sample/META-INF/template/WIKI.html (rev 0) +++ trunk/staticwiki-servlet/src/main/resources/wiki/sample/META-INF/template/WIKI.html 2008-07-24 11:01:51 UTC (rev 49) @@ -0,0 +1,13 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://wwww.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title>wiki main title</title> + <meta http-equiv="content-type" content="text/html;charset=UTF-8"/> + <style type="text/css" media="all"> + @import "wiki.css"; + </style> +</head> +<body> + <div class="wiki">$context.render($macro)</div> +</body> +</html> Added: trunk/staticwiki-servlet/src/main/resources/wiki/sample/info.wiki =================================================================== --- trunk/staticwiki-servlet/src/main/resources/wiki/sample/info.wiki (rev 0) +++ trunk/staticwiki-servlet/src/main/resources/wiki/sample/info.wiki 2008-07-24 11:01:51 UTC (rev 49) @@ -0,0 +1,25 @@ +h1. Test wiki file + +I Just _need_ some test information to verify that the wiki servlet works. + +h2. Metadata + +This uses a metadata file which can store extra information about the wiki document. This can be particularly useful for building a [subjectory|http://hoppie.nl/] as this allow having a set of fixed fields which _can_ be added in page and which can be rendered as part of the _skin_. + +h2. Content negotiation and skinning + +Though at first only intended to render html output, it is intended that different skins can be used based on content negotiation. This could be used to render html, pdf, original wiki source, txf,... + +The skin which should be used for each of the ... + +h2. Move, rename, recreate pages + +When pages are moved or renamed in the wiki, it is intended that the original location is changed to a pointer to the new location. ... + +h2. Versioning + +This wiki is based on file system only. The versioning should be handled by backing the data by a subversion repository. + +h2. Non-wiki content + +Each directory can contain a "META-INF" subdirectory. This is not directly rendered, but instead \ No newline at end of file Added: trunk/staticwiki-servlet/src/main/webapp/WEB-INF/jboss-web.xml =================================================================== --- trunk/staticwiki-servlet/src/main/webapp/WEB-INF/jboss-web.xml (rev 0) +++ trunk/staticwiki-servlet/src/main/webapp/WEB-INF/jboss-web.xml 2008-07-24 11:01:51 UTC (rev 49) @@ -0,0 +1,7 @@ +<jboss-web> + <!-- Uncomment the security-domain to enable security. You will + need to edit the htmladaptor login configuration to setup the + login modules used to authentication users. --> + <!--<security-domain>java:/jaas/wiki</security-domain>--> + <context-root>wiki</context-root> +</jboss-web> \ No newline at end of file Added: trunk/staticwiki-servlet/src/main/webapp/WEB-INF/web.xml =================================================================== --- trunk/staticwiki-servlet/src/main/webapp/WEB-INF/web.xml (rev 0) +++ trunk/staticwiki-servlet/src/main/webapp/WEB-INF/web.xml 2008-07-24 11:01:51 UTC (rev 49) @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE web-app + PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" + "http://java.sun.com/dtd/web-app_2_3.dtd"> +<web-app> + <display-name>staticwiki servlet</display-name> + <servlet> + <servlet-name>wiki</servlet-name> + <servlet-class>org.staticwiki.servlet.WikiServlet</servlet-class> + <init-param> + <param-name>wiki-root</param-name> + <param-value>/home/joachim/data/wiki/test</param-value> + </init-param> + </servlet> + <servlet-mapping> + <servlet-name>wiki</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> +</web-app> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |