Author: bpoussin Date: 2010-12-07 17:21:53 +0100 (Tue, 07 Dec 2010) New Revision: 575 Url: http://nuiton.org/repositories/revision/wikitty/575 Log: create new module wikitty-publication (proof of concept currently) Added: trunk/wikitty-publication/ trunk/wikitty-publication/LICENSE.txt trunk/wikitty-publication/README.txt trunk/wikitty-publication/changelog.txt trunk/wikitty-publication/pom.xml trunk/wikitty-publication/src/ trunk/wikitty-publication/src/main/ trunk/wikitty-publication/src/main/java/ trunk/wikitty-publication/src/main/java/org/ trunk/wikitty-publication/src/main/java/org/nuiton/ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/AbstractAction.java trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionEdit.java trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionError.java trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionEval.java trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionRaw.java trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionView.java trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationAction.java trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationContext.java trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationServlet.java trunk/wikitty-publication/src/main/resources/ trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-default.properties trunk/wikitty-publication/src/main/resources/wikitty-publication.properties trunk/wikitty-publication/src/main/webapp/ trunk/wikitty-publication/src/main/webapp/WEB-INF/ trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/ trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/edit.jsp trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/footer.jsp trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/header.jsp trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/view.jsp trunk/wikitty-publication/src/main/webapp/WEB-INF/web.xml trunk/wikitty-publication/src/main/webapp/css/ trunk/wikitty-publication/src/main/webapp/css/wikitty-publication.css trunk/wikitty-publication/src/main/xmi/ trunk/wikitty-publication/src/main/xmi/wikitty-publication.properties trunk/wikitty-publication/src/main/xmi/wikitty-publication.zargo trunk/wikitty-publication/src/test/ trunk/wikitty-publication/src/test/java/ trunk/wikitty-publication/src/test/java/org/ trunk/wikitty-publication/src/test/java/org/nuiton/ trunk/wikitty-publication/src/test/java/org/nuiton/wikitty/ trunk/wikitty-publication/src/test/java/org/nuiton/wikitty/publication/ Added: trunk/wikitty-publication/LICENSE.txt =================================================================== --- trunk/wikitty-publication/LICENSE.txt (rev 0) +++ trunk/wikitty-publication/LICENSE.txt 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,166 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + Added: trunk/wikitty-publication/pom.xml =================================================================== --- trunk/wikitty-publication/pom.xml (rev 0) +++ trunk/wikitty-publication/pom.xml 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,129 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.nuiton</groupId> + <artifactId>wikitty</artifactId> + <version>3.0-SNAPSHOT</version> + </parent> + + <!-- ************************************************************* --> + <!-- *** POM Relationships *************************************** --> + <!-- ************************************************************* --> + + <groupId>org.nuiton.wikitty</groupId> + <artifactId>wikitty-publication</artifactId> + + <dependencies> + <dependency> + <groupId>org.nuiton.wikitty</groupId> + <artifactId>wikitty-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.nuiton.wikitty</groupId> + <artifactId>wikitty-jdbc-impl</artifactId> + <version>${project.version}</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.nuiton.wikitty</groupId> + <artifactId>wikitty-solr-impl</artifactId> + <version>${project.version}</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-utils</artifactId> + </dependency> + + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + </dependency> + + </dependencies> + + <!-- ************************************************************* --> + <!-- *** Project Information ************************************* --> + <!-- ************************************************************* --> + + <name>Wikitty :: publication</name> + + <description>Web publication for Wikitty</description> + <inceptionYear>2010</inceptionYear> + + <!-- ************************************************************* --> + <!-- *** Build Settings ****************************************** --> + <!-- ************************************************************* --> + + <packaging>war</packaging> + + <build> + + <resources> + <resource> + <directory>src/main/resources</directory> + </resource> + <resource> + <directory>${project.build.directory}/generated-sources/models</directory> + <includes> + <include>*.objectmodel</include> + <include>*.properties</include> + </includes> + </resource> + </resources> + + <plugins> + <plugin> + <groupId>org.nuiton.eugene</groupId> + <artifactId>maven-eugene-plugin</artifactId> + <executions> + <execution> + <id>api-generation</id> + <phase>generate-sources</phase> + <configuration> + <inputs> + <input>zargo</input> + </inputs> + <fullPackagePath>org.nuiton.wikitty.publication.entities</fullPackagePath> + <defaultPackage>org.nuiton.wikitty.publication.entities</defaultPackage> + <extractedPackages>org.nuiton.wikitty.publication.entities</extractedPackages> + <templates>org.nuiton.wikitty.generator.WikittyMetaGenerator</templates> + </configuration> + <goals> + <goal>smart-generate</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + + </build> + +</project> Added: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/AbstractAction.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/AbstractAction.java (rev 0) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/AbstractAction.java 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,33 @@ +package org.nuiton.wikitty.publication; + + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public abstract class AbstractAction implements WikittyPublicationAction { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(AbstractAction.class); + + protected String mapping = null; + + @Override + public String getMapping() { + return mapping; + } + + @Override + public void setMapping(String mapping) { + this.mapping = mapping; + } + + +} Added: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionEdit.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionEdit.java (rev 0) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionEdit.java 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,134 @@ +package org.nuiton.wikitty.publication; + +import java.util.Map; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.ApplicationConfig; +import org.nuiton.wikitty.WikittyProxy; +import org.nuiton.wikitty.entities.Wikitty; +import org.nuiton.wikitty.entities.WikittyExtension; +import org.nuiton.wikitty.entities.WikittyImpl; +import org.nuiton.wikitty.search.Criteria; +import org.nuiton.wikitty.search.Search; +import org.nuiton.wikitty.search.operators.Element; + +/** + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class ActionEdit extends AbstractAction { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(ActionError.class); + + protected ApplicationConfig appConfig; + + public ActionEdit(ApplicationConfig appConfig) { + this.appConfig = appConfig; + } + + @Override + public Object doAction(WikittyPublicationContext context) { + WikittyProxy proxy = context.getWikittyProxy(); + + String result = "no query"; + if (context.getMandatoryArguments().size() > 0) { + log.info("args " + context.getMandatoryArguments()); + String [] arg = context.getMandatoryArguments().get(0).split("="); + + Wikitty w; + switch (arg.length) { + case 0: + // new wikitty without extension and edit + w = new WikittyImpl(); + break; + case 1: + // new wikitty with one extension and edit + w = new WikittyImpl(); + WikittyExtension ext = proxy.restoreExtensionLastVersion(arg[0]); + if (ext != null) { + w.addExtension(ext); + } + break; + default: + // find and edit + Criteria criteria = Search.query().eq(arg[0], arg[1]).criteria(); + w = proxy.findByCriteria(criteria); + } + + if (w == null && "0.0".equals(context.getArguments().get("version"))) { + // c'est un nouvel objet, il n'a pas encore ete sauve, mais on veut le faire + String id = context.getArguments().get("id"); + w = new WikittyImpl(id); + } + + if (w == null) { + context.setContentType("text/plain"); + result = String.format( + "no data found for %s with value %s", arg[0], arg[1]); + } else { + if (context.getArguments().containsKey("delete")) { + String id = context.getArguments().get("id"); + context.getWikittyProxy().delete(id); + } else if (context.getArguments().containsKey("store")) { + // change and store wikitty + + // ajout des extensions si necessaire + String [] extNames = context.getRequest().getParameterValues("extensions"); + if (extNames != null) { + for (String extName : extNames) { + WikittyExtension ext = proxy.restoreExtensionLastVersion(extName); + if (ext != null) { + w.addExtension(ext); + } + } + } + + // modifie tous les champs presents dans le formulaire + for (Map.Entry<String, String> field : context.getArguments().entrySet()) { + if (field.getKey().contains(".")) { + String extName = WikittyExtension.extractExtensionName(field.getKey()); + String fieldName = WikittyExtension.extractFieldName(field.getKey()); + + if (w.hasField(extName, fieldName)) { + w.setField(extName, fieldName, field.getValue()); + } + } + } + + // sauve le wikitty modifie + context.getWikittyProxy().store(w); + } + + // forward l'affichage de la page vers la jsp d'edition + context.setContentType("forward/jsp"); + context.getRequest().setAttribute( + WikittyPublicationContext.CONTEXT_VAR, context); + context.getRequest().setAttribute("wikitty", w); + result = "/WEB-INF/jsp/edit.jsp"; + } + } + + return result; + } + + /** + * create url to edit wikitty object, assume that edition already start + * add context.getActionName() return edit action name. + * + * @param context + * @param w + * @return + */ + public String makeUrl(WikittyPublicationContext context, Wikitty w) { + String url = getMapping() + "/" + + Element.ELT_ID + "=" + w.getId(); + url = context.makeUrl(url); + return url; + } + +} Added: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionError.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionError.java (rev 0) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionError.java 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,61 @@ +package org.nuiton.wikitty.publication; + + +import javax.servlet.http.HttpServletRequest; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.ExceptionUtil; + +/** + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class ActionError extends AbstractAction { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(ActionError.class); + + protected Throwable error = null; + + public ActionError(Throwable error) { + this.error = error; + } + + @Override + public Object doAction(WikittyPublicationContext context) { + error.printStackTrace(); + + HttpServletRequest req = context.getRequest(); + String result = "<html><body>Error: " + + "<br>context: " + context + + "<br>" + + "<br>getContextPath: " + req.getContextPath() + + "<br>getMethod: " + req.getMethod() + + "<br>getPathInfo: " + req.getPathInfo() + + "<br>getPathTranslated: " + req.getPathTranslated() + + "<br>getQueryString: " + req.getQueryString() + + "<br>getRemoteUser: " + req.getRemoteUser() + + "<br>getRequestURI: " + req.getRequestURI() + + "<br>getRequestURI: " + req.getRequestURI() + + "<br>getRequestedSessionId: " + req.getRequestedSessionId() + + "<br>getServletPath: " + req.getServletPath() + + "<br>getCharacterEncoding: " + req.getCharacterEncoding() + + "<br>getContentType: " + req.getContentType() + + "<br>getLocalAddr: " + req.getLocalAddr() + + "<br>getLocalName: " + req.getLocalName() + + "<br>getProtocol: " + req.getProtocol() + + "<br>getRemoteAddr: " + req.getRemoteAddr() + + "<br>getRemoteHost: " + req.getRemoteHost() + + "<br>getScheme: " + req.getScheme() + + "<br>getServerName: " + req.getServerName() + + "<br>" + + "<br>error:<pre>" + ExceptionUtil.stackTrace(error) + "</pre>" + + "</body></html>"; + return result; + } + +} Added: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionEval.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionEval.java (rev 0) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionEval.java 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,99 @@ +package org.nuiton.wikitty.publication; + +import java.util.List; +import javax.script.Bindings; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineFactory; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.ApplicationConfig; +import org.nuiton.wikitty.WikittyException; +import org.nuiton.wikitty.WikittyProxy; +import org.nuiton.wikitty.publication.entities.WikittyPubText; +import org.nuiton.wikitty.search.Criteria; +import org.nuiton.wikitty.search.Search; + +/** + * Permet d'evaluer un WikittyPubText et de retourner la valeur de l'evaluation. + * La variable de nom {@link WikittyPublicationContext#CONTEXT_VAR} et de type + * {@link WikittyPublicationContext} est positionnee dans l'environnement + * d'evaluation. + * + * Le script doit positionner convenablement la valeur de + * {@link WikittyPublicationContext#setContentType(java.lang.String)} par + * rapport a l'objet retourne + * + * L'evaluateur est recherche via la valeur du champs + * {@link WikittyPubText#getMimeType()}. + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class ActionEval extends AbstractAction { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(ActionError.class); + + protected ApplicationConfig appConfig; + protected ScriptEngineManager scriptEnginManager; + + public ActionEval(ApplicationConfig appConfig) { + this.appConfig = appConfig; + + scriptEnginManager = new ScriptEngineManager(); + } + + @Override + public Object doAction(WikittyPublicationContext context) { + WikittyProxy proxy = context.getWikittyProxy(); + + Object result = "no query"; + if (context.getMandatoryArguments().size() > 0) { + log.info("args " + context.getMandatoryArguments()); + String [] arg = context.getMandatoryArguments().get(0).split("="); + + Criteria criteria = Search.query().eq(arg[0], arg[1]).criteria(); + WikittyPubText w = proxy.findByCriteria(WikittyPubText.class, criteria); + if (w == null) { + result = String.format( + "no data found for %s with value %s", arg[0], arg[1]); + } else { + String mimetype = w.getMimeType(); + ScriptEngine scriptEngin = scriptEnginManager.getEngineByMimeType(mimetype); + if (scriptEngin == null) { + List<ScriptEngineFactory> factories = + scriptEnginManager.getEngineFactories(); + String msgFactories = ""; + for (ScriptEngineFactory f : factories) { + msgFactories += String.format( + "\n%s extensions: %s mimetypes: %s", + f.getEngineName(), f.getExtensions(), f.getMimeTypes()); + } + throw new WikittyException(String.format( + "Can't find engine for %s(%s). Available engines: %s", + w.getName(), w.getMimeType(), msgFactories)); + } else { + Bindings bindings = scriptEngin.createBindings(); + bindings.put(WikittyPublicationContext.CONTEXT_VAR, context); + String script = w.getContent(); + try { + result = scriptEngin.eval(script, bindings); + } catch (ScriptException eee) { + throw new WikittyException(String.format( + "Can't evaluated script %s(%s=>%s) script was\n%s", + w.getName(), w.getMimeType(), + scriptEngin.getFactory().getEngineName(), script), eee); + } + } + } + } + + return result; + } + +} Added: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionRaw.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionRaw.java (rev 0) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionRaw.java 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,105 @@ +package org.nuiton.wikitty.publication; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.ApplicationConfig; +import org.nuiton.wikitty.WikittyProxy; +import org.nuiton.wikitty.entities.Wikitty; +import org.nuiton.wikitty.entities.WikittyExtension; +import org.nuiton.wikitty.search.Criteria; +import org.nuiton.wikitty.search.Search; + +/** + * Action permettant de retourner la valeur d'un champs d'un object. + * Elle peut-etre utilisee pour retourner une image ou un document stocke dans + * un champs d'un wikitty + * + * Cette action prend deux arguments obligatoires + * <li> l'argument de recherche du wikitty + * <li> le champs qu'il faut retourner en raw + * + * et un argument optionnel + * <li> le type mime du contenu qui peut-etre un champs de l'objet + * + * exemple + * <pre> + * ram/WikittyPubData.name=MonImage.jpg/WikittyPubData.content?mimetype=WikittyPubData.mimetype + * ram/WikittyPubText.name=Tuto/WikittyPubText.content?mimetype=WikittyPubText.mimetype + * ram/WikittyUser.login=admin/WikittyUser.password?mimetype=text/plain + * </pre> + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class ActionRaw extends AbstractAction { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(ActionError.class); + + static final public int ARG_QUERY = 0; + static final public int ARG_CONTENT_FIELD = 1; + static final public String ARG_MIMETYPE = "mimetype"; + + static final protected String exampleUsage = + "ram/WikittyPubData.name=MonImage.jpg/WikittyPubData.content?mimetype=WikittyPubData.mimetype\n" + + "ram/WikittyPubText.name=Tuto/WikittyPubText.content?mimetype=WikittyPubText.mimetype\n" + + "ram/WikittyUser.login=admin/WikittyUser.password?mimetype=text/plain\n"; + + protected ApplicationConfig appConfig; + + public ActionRaw(ApplicationConfig appConfig) { + this.appConfig = appConfig; + } + + @Override + public Object doAction(WikittyPublicationContext context) { + WikittyProxy proxy = context.getWikittyProxy(); + + Object result = "no query"; + if (context.getMandatoryArguments().size() < 2) { + context.setContentType("text/html"); + result = String.format("<html><head></head><body>" + + "<h1>bad query</h1>" + + "Usage example" + + "<pre>%s</pre>" + + "</body></html>\n", exampleUsage); + } else { + log.info("args " + context.getMandatoryArguments()); + String [] arg = context.getMandatoryArguments().get(ARG_QUERY).split("="); + + Criteria criteria = Search.query().eq(arg[0], arg[1]).criteria(); + Wikitty w = proxy.findByCriteria(criteria); + if (w == null) { + result = String.format( + "no data found for %s with value %s", arg[0], arg[1]); + } else { + // looking for mimetype field + String mimetype = context.getArguments().get(ARG_MIMETYPE); + if (mimetype != null) { + int i = mimetype.indexOf('.'); + if (i > 0) { // perhaps fully qualified field + String extName = WikittyExtension.extractExtensionName(mimetype); + String fieldName = WikittyExtension.extractFieldName(mimetype); + if (w.hasField(extName, fieldName)) { + // mimetype target field in wikitty + // replace with field value + mimetype = w.getFieldAsString(extName, fieldName); + } + } + context.setContentType(mimetype); + } + String contentField = context.getMandatoryArguments().get(ARG_CONTENT_FIELD); + String extName = WikittyExtension.extractExtensionName(contentField); + String fieldName = WikittyExtension.extractFieldName(contentField); + + result = w.getFieldAsObject(extName, fieldName); + } + } + + return result; + } + +} Added: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionView.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionView.java (rev 0) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionView.java 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,87 @@ +package org.nuiton.wikitty.publication; + +import java.util.Map; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.ApplicationConfig; +import org.nuiton.util.StringUtil; +import org.nuiton.wikitty.WikittyProxy; +import org.nuiton.wikitty.entities.Wikitty; +import org.nuiton.wikitty.entities.WikittyExtension; +import org.nuiton.wikitty.entities.WikittyImpl; +import org.nuiton.wikitty.search.Criteria; +import org.nuiton.wikitty.search.PagedResult; +import org.nuiton.wikitty.search.Search; +import org.nuiton.wikitty.search.operators.Element; + +/** + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class ActionView extends AbstractAction { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(ActionError.class); + + protected ApplicationConfig appConfig; + + public ActionView(ApplicationConfig appConfig) { + this.appConfig = appConfig; + } + + @Override + public Object doAction(WikittyPublicationContext context) { + WikittyProxy proxy = context.getWikittyProxy(); + + String r = context.getArguments().get("r"); + if (r == null || "".equals(r)) { + r = "*"; + } + String first = context.getArgument("first", "0"); + String end = context.getArgument("end", "100"); + int firstIndex = StringUtil.toInt(first); + int endIndex = StringUtil.toInt(end); + + Criteria criteria = Search.query().keyword(r).criteria(); + criteria.setFirstIndex(firstIndex); + criteria.setEndIndex(endIndex); + + PagedResult<Wikitty> pagedResult = proxy.findAllByCriteria(criteria); + + String id = context.getArguments().get("id"); + Wikitty w = proxy.restore(id); + + // forward l'affichage de la page vers la jsp d'edition + context.setContentType("forward/jsp"); + context.getRequest().setAttribute( + WikittyPublicationContext.CONTEXT_VAR, context); + context.getRequest().setAttribute("r", r); + context.getRequest().setAttribute("first", first); + context.getRequest().setAttribute("end", end); + context.getRequest().setAttribute("wikitty", w); + context.getRequest().setAttribute("pagedResult", pagedResult); + String result = "/WEB-INF/jsp/view.jsp"; + + return result; + } + + /** + * create url to edit wikitty object, assume that edition already start + * add context.getActionName() return edit action name. + * + * @param context + * @param w + * @return + */ + static public String makeUrl(WikittyPublicationContext context, Wikitty w) { + String url = context.getActionName() + "/" + + Element.ELT_ID + "=" + w.getId(); + url = context.makeUrl(url); + return url; + } + +} Added: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationAction.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationAction.java (rev 0) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationAction.java 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,16 @@ +package org.nuiton.wikitty.publication; + +/** + * each action can be used by multiple thread + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public interface WikittyPublicationAction { + public String getMapping(); + public void setMapping(String mapping); + public Object doAction(WikittyPublicationContext context); +} Added: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationContext.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationContext.java (rev 0) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationContext.java 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,294 @@ +package org.nuiton.wikitty.publication; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.ApplicationConfig; +import org.nuiton.util.ArgumentsParserException; +import org.nuiton.util.ObjectUtil; +import org.nuiton.util.StringUtil; +import org.nuiton.wikitty.WikittyConfig; +import org.nuiton.wikitty.WikittyException; +import org.nuiton.wikitty.WikittyProxy; +import org.nuiton.wikitty.WikittyService; +import org.nuiton.wikitty.WikittyServiceFactory; +import org.nuiton.wikitty.entities.WikittyExtension; +import org.nuiton.wikitty.entities.WikittyLabelAbstract; +import org.nuiton.wikitty.entities.WikittyTreeNodeAbstract; +import org.nuiton.wikitty.entities.WikittyUserAbstract; +import org.nuiton.wikitty.publication.entities.WikittyPubDataAbstract; +import org.nuiton.wikitty.publication.entities.WikittyPubTextAbstract; + +/** + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class WikittyPublicationContext { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(WikittyPublicationContext.class); + + /** variable name use to put context in script and jsp */ + static final public String CONTEXT_VAR = "WPContext"; + + /** configuration option name FIXME poussin 20101206 use OptionDef */ + static final public String CONFIG_FILE = "wikitty.publication.config.pattern"; + static final public String ACTION_PREFIX = "wikitty.publication.action"; + + static final protected Map<String, WikittyService> services = + new HashMap<String, WikittyService>(); + static final protected Map<String, WikittyPublicationAction> actions = + new HashMap<String, WikittyPublicationAction>(); + + protected ApplicationConfig appConfig; + protected HttpServletRequest req; + protected HttpServletResponse resp; + protected String wsContext = null; + protected String actionName = null; + protected List<String> mandatoryArguments = new ArrayList<String>(); + protected Map<String, String> arguments = new HashMap<String, String>(); + protected WikittyProxy proxy = null; + + protected String contentType = "text/html"; + + public WikittyPublicationContext(ApplicationConfig appConfig) { + this.appConfig = appConfig; + + // force load of action in configuration + for(String key : appConfig.getFlatOptions().stringPropertyNames()) { + if (key.startsWith(ACTION_PREFIX)) { + String action = key.substring(ACTION_PREFIX.length() + 1); + getAction(action); + } + } + } + + /** + * add here all extension that WikittyService must know + */ + protected void addRequiredExtension(WikittyService ws) { + List<WikittyExtension> exts = new ArrayList<WikittyExtension>(); + + exts.addAll(WikittyUserAbstract.extensions); + exts.addAll(WikittyLabelAbstract.extensions); + exts.addAll(WikittyTreeNodeAbstract.extensions); + exts.addAll(WikittyPubTextAbstract.extensions); + exts.addAll(WikittyPubDataAbstract.extensions); + + ws.storeExtension(null, exts); + } + + /** + * set attributes: + * <li> req + * <li> wsContext + * <li> actionName + * <li> mandatoryArguments + * <li> arguments + * + * @param req + */ + public void parse(HttpServletRequest req, HttpServletResponse resp) { + this.req = req; + this.resp = resp; + + String path = req.getPathInfo(); + + // path start with '/' then comps[0] == empty + String[] comps = StringUtil.split(path, "/"); + if (comps.length > 0) { + wsContext = comps[1]; + } + if (comps.length > 1) { + actionName = comps[2]; + } + + for (int i = 3; i < comps.length; i++) { + mandatoryArguments.add(comps[i]); + } + for (Enumeration<String> e=req.getParameterNames(); e.hasMoreElements();) { + String name = e.nextElement(); + String value = req.getParameter(name); + arguments.put(name, value); + } + log.info(String.format( + "path %s => ws: %s action: %s mandatoryArguments: %s arguments: %s", + path, wsContext, actionName, mandatoryArguments, arguments)); + } + + public HttpServletRequest getRequest() { + return req; + } + + public HttpServletResponse getResponse() { + return resp; + } + + public ApplicationConfig getAppConfig() { + return appConfig; + } + + public String getActionName() { + return actionName; + } + + public WikittyProxy getWikittyProxy() { + if (proxy == null) { + proxy = new WikittyProxy(getAppConfig(), getWikittyService()); + } + return proxy; + } + + /** + * add context to the url and parameter if necessary + * @param url + * @return + */ + public String makeUrl(String url) { + String finalUrl = url; + if (!finalUrl.startsWith("/")) { + finalUrl = "/" + finalUrl; + } + finalUrl = getRequest().getContextPath() + "/" + wsContext + finalUrl; + finalUrl = getResponse().encodeURL(finalUrl); + if (log.isInfoEnabled()) { + log.info(String.format("transforme url from '%s' to '%s'", url, finalUrl)); + } + return finalUrl; + } + + public WikittyService getWikittyService() { + WikittyService result = services.get(wsContext); + if (result == null) { + String patternConfigFilename = appConfig.getOption(CONFIG_FILE); + + // load default configuration for all wikitty service + String filename = String.format(patternConfigFilename, "default"); + ApplicationConfig wsConfigDefault; + try { + wsConfigDefault = new ApplicationConfig(filename); + + // change juste data dir with context path + String dataDir = wsConfigDefault.getOption( + WikittyConfig.WikittyOption.WIKITTY_DATA_DIR.getKey()); + wsConfigDefault.setOption( + WikittyConfig.WikittyOption.WIKITTY_DATA_DIR.getKey(), + dataDir + File.separator + wsContext); + } catch (ArgumentsParserException eee) { + throw new WikittyException(String.format( + "Can't parse configuration %s", filename), eee); + } + + // read specifique configuration with default config as default properties + filename = String.format(patternConfigFilename, wsContext); + ApplicationConfig wsConfig; + try { + wsConfig = new ApplicationConfig(wsConfigDefault.getFlatOptions()); + wsConfig.setConfigFileName(filename); + wsConfig.parse(null); + } catch (ArgumentsParserException eee) { + throw new WikittyException(String.format( + "Can't parse configuration %s", filename), eee); + } + synchronized (services) { + result = services.get(wsContext); + if (result == null) { + result = WikittyServiceFactory.buildWikittyService(wsConfig); + addRequiredExtension(result); + services.put(wsContext, result); + } + } + } + return result; + } + + public List<String> getMandatoryArguments() { + return mandatoryArguments; + } + + public Map<String, String> getArguments() { + return arguments; + } + + public String getArgument(String name, String defaultValue) { + String result = defaultValue; + if (getArguments().containsKey(name)) { + result = getArguments().get(name); + } + return result; + } + + public WikittyPublicationAction getAction() { + WikittyPublicationAction result = getAction(actionName); + return result; + } + + + public <E extends WikittyPublicationAction> E getAction(Class<E> actionClass) { + E result = null; + for (WikittyPublicationAction a : actions.values()) { + if (actionClass.isInstance(a)) { + result = (E)a; + break; + } + } + return result; + } + + public WikittyPublicationAction getAction(String actionName) { + if (log.isInfoEnabled()) { + log.info(String.format("Looking for class for '%s' action", actionName)); + } + WikittyPublicationAction result = actions.get(actionName); + if (result == null) { + String action = ACTION_PREFIX + "." + actionName; + log.info(String.format("try to load action %s", action)); + try { + Class<WikittyPublicationAction> clazz = (Class<WikittyPublicationAction>) + appConfig.getOptionAsClass(action); + Collection args = Collections.singleton(appConfig); + result = ObjectUtil.newInstance(clazz, args, true); + result.setMapping(actionName); + actions.put(actionName, result); + } catch (Exception eee) { + log.error(String.format("Can't find action %s", action), eee); + result = new ActionError(eee); + } + } + return result; + } + + public String getContentType() { + return contentType; + } + + public void setContentType(String contentType) { + this.contentType = contentType; + } + + @Override + public String toString() { + String path = req.getPathInfo(); + String result = String.format("WPContext [path: %s\n" + + " ws: %s\n" + + " action: %s\n" + + " mandatoryArguments: %s\n" + + " arguments: %s\n" + + "]", path, wsContext, actionName, mandatoryArguments, arguments); + return result; + } + +} Added: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationServlet.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationServlet.java (rev 0) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationServlet.java 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,107 @@ +package org.nuiton.wikitty.publication; + + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.ApplicationConfig; +import org.nuiton.util.ArgumentsParserException; + +/** + * url: + * <pre> + * /[context]/[action]/[action argument]?[action argument]#[fragment] + * </pre> + * + * example: + * <pre> + * /codelutin/raw/WikittyPubData.name=lutin.jpg/WikittyPubData.content?mimetype=WikittyPubData.mimetype + * </pre> + * + * <li>la config du WikittyService sera lu dans la config + * wikitty.publication.config.pattern en remplacant %s par 'default' + * la valeur de 'wikitty.data.directory' est modifier pour lui ajouter le + * context par defaut en plus, puis le fichier de config specifique au context est lu + * qui peut alors ecraser 'wikitty.data.directory' et toutes les autres valeurs + * par defaut + * <li>l'action executee sera 'raw' la classe associee sera trouve dans le fichier + * de config WikittyPublication. + * <li> le reste sont des arguments specifique a l'action que l'action pourra + * trouver dans: {@link WikittyPublicationContext#getMandatoryArguments()} et + * {@link WikittyPublicationContext#getArguments()}. + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class WikittyPublicationServlet extends HttpServlet { + + static public ApplicationConfig appConfig; + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(WikittyPublicationServlet.class); + + public void init() throws ServletException { + try { + appConfig = new ApplicationConfig(); + appConfig.setConfigFileName("wikitty-publication.properties"); + appConfig.parse(null); + } catch(ArgumentsParserException eee) { + throw new ServletException("Can't get filename config prefix", eee); + } + } + + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + doPost(req, resp); + } + + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + + Object result; + WikittyPublicationContext context = new WikittyPublicationContext(appConfig); + try { + context.parse(req, resp); + + if ("true".equals(context.getArguments().get("debug"))) { + // debug asked, not do action, but show context + result = context.toString(); + context.setContentType("text/plain"); + } else { + WikittyPublicationAction action = context.getAction(); + result = action.doAction(context); + } + } catch (Throwable eee) { + WikittyPublicationAction action = new ActionError(eee); + result = action.doAction(context); + } + + String contentType = context.getContentType(); + if (contentType != null && contentType.startsWith("forward")) { + req.getRequestDispatcher(String.valueOf(result)).forward(req, resp); + } else { + if (contentType != null) { + resp.setContentType(contentType); + } + if (result instanceof byte[]) { + ServletOutputStream out = resp.getOutputStream(); + out.write((byte[]) result); + out.flush(); + } else { + PrintWriter out = resp.getWriter(); + out.write(String.valueOf(result)); + out.flush(); + } + } + } + +} Added: trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-default.properties =================================================================== --- trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-default.properties (rev 0) +++ trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-default.properties 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,50 @@ +### +# #%L +# Wikitty :: publication +# +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2009 - 2010 CodeLutin, Benjamin Poussin +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Lesser Public License for more details. +# +# You should have received a copy of the GNU General Lesser Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/lgpl-3.0.html>. +# #L% +### +wikitty.data.directory=./target/data +wikitty.storage.jdbc.queryfile=wikitty-jdbc-query.properties +wikitty.storage.jdbc.driver=org.h2.Driver +wikitty.storage.jdbc.host=jdbc:h2:file:${wikitty.data.directory}/data/db +wikitty.storage.jdbc.login=sa +wikitty.storage.jdbc.password= +wikitty.storage.jdbc.xadatasource=org.h2.jdbcx.JdbcDataSource +wikitty.storage.jdbc.xadatasource.org.h2.jdbcx.JdbcDataSource.URL=${wikitty.storage.jdbc.host} +wikitty.storage.jdbc.xadatasource.org.h2.jdbcx.JdbcDataSource.user=${wikitty.storage.jdbc.login} +wikitty.storage.jdbc.xadatasource.org.h2.jdbcx.JdbcDataSource.password=${wikitty.storage.jdbc.password} +wikitty.searchengine.solr.directory.data=${wikitty.data.directory}/data/solr +wikitty.searchengine.solr.directory.factory=solr.StandardDirectoryFactory +wikitty.WikittyService.components=org.nuiton.wikitty.services.WikittyServiceStorage,\ +org.nuiton.wikitty.services.WikittyServiceNotifier,\ +org.nuiton.wikitty.services.WikittyServiceCached,\ +org.nuiton.wikitty.services.WikittyServiceSecurity +wikitty.WikittyServiceStorage.components=org.nuiton.wikitty.jdbc.WikittyExtensionStorageJDBC,\ +org.nuiton.wikitty.jdbc.WikittyStorageJDBC,\ +org.nuiton.wikitty.solr.WikittySearchEngineSolr +wikitty.service.cache.listenevents=false +wikitty.service.cache.allwaysRestoreCopies=false +wikitty.service.event.propagate=false +wikitty.service.event.listen=false +wikitty.addon.export.threadnumber=1 +wikitty.addon.export.directory=${wikitty.data.directory}/export +wikitty.addon.export.publicurl=file://${wikitty.data.directory}/export/ Added: trunk/wikitty-publication/src/main/resources/wikitty-publication.properties =================================================================== --- trunk/wikitty-publication/src/main/resources/wikitty-publication.properties (rev 0) +++ trunk/wikitty-publication/src/main/resources/wikitty-publication.properties 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,29 @@ +### +# #%L +# Wikitty :: publication +# +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2009 - 2010 CodeLutin, Benjamin Poussin +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Lesser Public License for more details. +# +# You should have received a copy of the GNU General Lesser Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/lgpl-3.0.html>. +# #L% +### +wikitty.publication.config.pattern=wikitty-publication-ws-%s.properties +wikitty.publication.action.edit=org.nuiton.wikitty.publication.ActionEdit +wikitty.publication.action.eval=org.nuiton.wikitty.publication.ActionEval +wikitty.publication.action.raw=org.nuiton.wikitty.publication.ActionRaw +wikitty.publication.action.view=org.nuiton.wikitty.publication.ActionView Added: trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/edit.jsp =================================================================== --- trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/edit.jsp (rev 0) +++ trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/edit.jsp 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,107 @@ +<%-- + Document : edit + Created on : 6 d�c. 2010, 18:32:18 + Author : poussin +--%> + +<%@page import="org.apache.commons.lang.StringEscapeUtils"%> +<%@page import="org.nuiton.wikitty.entities.FieldType"%> +<%@page import="java.util.Collection"%> +<%@page import="org.nuiton.wikitty.WikittyProxy"%> +<%@page import="org.nuiton.wikitty.WikittyService"%> +<%@page import="org.nuiton.wikitty.entities.WikittyExtension"%> +<%@page import="org.nuiton.wikitty.publication.ActionEdit"%> +<%@page import="org.nuiton.wikitty.entities.Wikitty"%> +<%@page import="org.nuiton.wikitty.publication.WikittyPublicationContext"%> + +<h1>Edit ${wikitty.id}</h1> + +<pre>${wikitty}</pre> + +<% +WikittyPublicationContext context = (WikittyPublicationContext) + request.getAttribute(WikittyPublicationContext.CONTEXT_VAR); +Wikitty wikitty = (Wikitty)request.getAttribute("wikitty"); +ActionEdit action = context.getAction(ActionEdit.class); +String url = action.makeUrl(context, wikitty); +%> + +<form action='<%=url%>' method="post"> + <input type="hidden" name="id" value="${wikitty.id}" /> + <input type="hidden" name="version" value="${wikitty.version}" /> + <fieldset> + <legend><span class="legend">Extensions</span></legend> + <% + WikittyProxy proxy = context.getWikittyProxy(); + Collection<String> allExt = proxy.getAllExtensionIds(); + if (allExt != null && allExt.size() > 0) { + %> + <select name="extensions" size="10" multiple="multiple"> + <% + for (String extId : allExt) { + String extName = WikittyExtension.computeName(extId); + String selected = wikitty.hasExtension(extName)?"selected":""; + %> + <option value="<%=extName%>" <%=selected%>><%=extName%></option> + <% + } + %> + </select> + <% + } + %> + </fieldset> + + <% + int index = 0; + for (WikittyExtension ext : wikitty.getExtensions()) { + String extName = ext.getName(); + %> + <fieldset> + <legend><span class="legend"><%=extName%></span></legend> + <% + for (String fieldName : ext.getFieldNames()) { + FieldType fieldType = wikitty.getExtension(extName).getFieldType(fieldName); + %> + <div> + <label for="<%=extName%>.<%=fieldName%>" tabindex="<%=++index%>"><span class="label"><%=fieldName%></span></label> + <% + switch(fieldType.getType()) { + case BOOLEAN: + boolean valueBool = wikitty.getFieldAsBoolean(ext.getName(), fieldName); + String checked = valueBool?"checked='true'":""; + %> + <input type="checkbox" name="<%=extName%>.<%=fieldName%>" value="true" <%=checked%>/> + <% + break; + default: + Object valueObject = wikitty.getFieldAsObject(ext.getName(), fieldName); + String valueString = ""; + if (valueObject != null) { + valueString = String.valueOf(valueObject); + } + + valueString = StringEscapeUtils.escapeHtml(valueString); + if (valueString.contains("\n") || "true".equals(fieldType.getTagValue("multiline"))) { + %> + <textarea cols="80" rows="20" name="<%=extName%>.<%=fieldName%>"><%=valueString%></textarea> + <% + } else { + %> + <input type="text" name="<%=extName%>.<%=fieldName%>" value="<%=valueString%>" /> + <% + } + } + %> + <%=fieldType.toDefinition("")%> + </div> + <% + } + %> + </fieldset> + <% + } + %> + <input type="submit" name="store" value="Store" /> + <input type="submit" name="delete" value="Delete" /> +</form> Added: trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/footer.jsp =================================================================== --- trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/footer.jsp (rev 0) +++ trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/footer.jsp 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,9 @@ +<%-- + Document : footer + Created on : 6 d�c. 2010, 19:21:22 + Author : poussin +--%> + +<div id="copyright"> Copyright Code Lutin 2010, AGPLv3 </div> + </body> +</html> Added: trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/header.jsp =================================================================== --- trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/header.jsp (rev 0) +++ trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/header.jsp 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,17 @@ +<%-- + Document : header + Created on : 6 déc. 2010, 19:21:06 + Author : poussin +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/html4/loose.dtd"> + +<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <title>Wikitty</title> + <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/wikitty-publication.css"> + </head> + <body> Added: trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/view.jsp =================================================================== --- trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/view.jsp (rev 0) +++ trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/view.jsp 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,51 @@ +<%-- + Document : view + Created on : 7 d�c. 2010, 04:18:13 + Author : poussin +--%> + +<%@page import="org.nuiton.wikitty.publication.ActionEdit"%> +<%@page import="org.nuiton.wikitty.publication.WikittyPublicationContext"%> +<%@page import="org.nuiton.wikitty.search.PagedResult"%> +<%@page import="org.nuiton.wikitty.entities.Wikitty"%> + +<h1>Wikitty View</h1> + +<% +WikittyPublicationContext context = (WikittyPublicationContext) + request.getAttribute(WikittyPublicationContext.CONTEXT_VAR); +PagedResult<Wikitty> pagedResult = (PagedResult<Wikitty>)request.getAttribute("pagedResult"); +Wikitty wikitty = (Wikitty)request.getAttribute("wikitty"); + +ActionEdit actionEdit = context.getAction(ActionEdit.class); +%> + +<form action="" method="post"> + <div> + <textarea name="r" rows="4" cols="20"><%=request.getAttribute("r")%></textarea> + </div> + <label for="first">First</label> <input type="text" name="first" value="<%=context.getArgument("first", "0")%>" /> + <label for="first">First</label> <input type="text" name="end" value="<%=context.getArgument("end", "100")%>" /> + <input type="submit" name="id" value="Search"/> + +<pre> +${wikitty} +</pre> + + <%=pagedResult.getFirstIndice()%>-<%=pagedResult.getFirstIndice() + pagedResult.size()%>/${pagedResult.numFound} + <table> + <% + + for (Wikitty w : pagedResult.getAll()) { + %> + <tr> + <td><a href="<%=actionEdit.makeUrl(context, w)%>">edit</a></td> + <td><input type="submit" name="id" value="<%=w.getId()%>"/></td> + <td><%=w.getExtensionNames()%></td> + </tr> + <% + } + %> + </table> +</form> + \ No newline at end of file Added: trunk/wikitty-publication/src/main/webapp/WEB-INF/web.xml =================================================================== --- trunk/wikitty-publication/src/main/webapp/WEB-INF/web.xml (rev 0) +++ trunk/wikitty-publication/src/main/webapp/WEB-INF/web.xml 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http:/java.sun.com/dtd/web-app_2_3.dtd"> + <!-- SERVLET --> + <display-name>Wikitty Publication</display-name> + <servlet> + <servlet-class>org.nuiton.wikitty.publication.WikittyPublicationServlet</servlet-class> + <servlet-name>Controller</servlet-name> + </servlet> + <welcome-file-list> + <welcome-file>/</welcome-file> + </welcome-file-list> + <!-- SERVLET MAPPING --> + <servlet-mapping> + <servlet-name>Controller</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>default</servlet-name> + <url-pattern>/css/*</url-pattern> + </servlet-mapping> + <jsp-config> + <jsp-property-group> + <description>JSP page location</description> + <display-name>jsp</display-name> + <url-pattern>/WEB-INF/jsp/*</url-pattern> + <include-prelude>/WEB-INF/jsp/header.jsp</include-prelude> + <include-coda>/WEB-INF/jsp/footer.jsp</include-coda> + </jsp-property-group> + </jsp-config> +</web-app> Added: trunk/wikitty-publication/src/main/webapp/css/wikitty-publication.css =================================================================== --- trunk/wikitty-publication/src/main/webapp/css/wikitty-publication.css (rev 0) +++ trunk/wikitty-publication/src/main/webapp/css/wikitty-publication.css 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,6 @@ +label { + float : left; + width : 200px; + text-align: right; + padding: 0px 5px 0 0; +} Added: trunk/wikitty-publication/src/main/xmi/wikitty-publication.properties =================================================================== --- trunk/wikitty-publication/src/main/xmi/wikitty-publication.properties (rev 0) +++ trunk/wikitty-publication/src/main/xmi/wikitty-publication.properties 2010-12-07 16:21:53 UTC (rev 575) @@ -0,0 +1,31 @@ +### +# #%L +# Wikitty :: api +# +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2009 - 2010 CodeLutin, Benjamin Poussin +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Lesser Public License for more details. +# +# You should have received a copy of the GNU General Lesser Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/lgpl-3.0.html>. +# #L% +### +org.nuiton.wikitty.publication.entities.WikittyPubText.class.tagvalue.version=1.0 +org.nuiton.wikitty.publication.entities.WikittyPubText.attribute.name.tagvalue.unique=true +org.nuiton.wikitty.publication.entities.WikittyPubText.attribute.name.tagvalue.notNull=true +org.nuiton.wikitty.publication.entities.WikittyPubText.attribute.content.tagvalue.multiline=true +org.nuiton.wikitty.publication.entities.WikittyPubData.class.tagvalue.version=1.0 +org.nuiton.wikitty.publication.entities.WikittyPubData.attribute.name.tagvalue.unique=true +org.nuiton.wikitty.publication.entities.WikittyPubData.attribute.name.tagvalue.notNull=true Added: trunk/wikitty-publication/src/main/xmi/wikitty-publication.zargo =================================================================== (Binary files differ) Property changes on: trunk/wikitty-publication/src/main/xmi/wikitty-publication.zargo ___________________________________________________________________ Added: svn:mime-type + application/octet-stream