gianugo 2003/07/27 06:13:10
Added: src/blocks/linotype/java/org/apache/cocoon/components SourceRepository.java src/blocks/linotype/samples sitemap.source.xmap sourceflow.js Log: Started a (small) Linotype refactoring to make it source-oriented. When finished (it's almost working but still requires some tweaking) it will be possible to use Linotype with every (ModifiableTraversable) source as a repository - think file://, cvs:// or webdav://. Revision Changes Path 1.1 cocoon-2.1/src/blocks/linotype/java/org/apache/cocoon/components/SourceRepository.java Index: SourceRepository.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.components; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; import java.util.Iterator; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.environment.Request; import org.apache.cocoon.servlet.multipart.Part; import org.apache.excalibur.source.ModifiableSource; import org.apache.excalibur.source.ModifiableTraversableSource; import org.apache.excalibur.source.SourceException; import org.apache.excalibur.source.SourceUtil; import org.apache.excalibur.source.TraversableSource; /** * @author stefano */ public class SourceRepository { public static final String FILE_NAME = "document"; private static SourceRepository instance; private static Environment env; private SourceRepository() { env = CocoonComponentManager.getCurrentEnvironment(); } public static SourceRepository getInstance() { if (instance == null) { instance = new SourceRepository(); } return instance; } private static TraversableSource getCollection(String colName) { TraversableSource source; try { source = (TraversableSource) env.resolveURI(colName); } catch (MalformedURLException e) { throw new RuntimeException("'unable to resolve source: malformed URL"); } catch (IOException e) { throw new RuntimeException("'unable to resolve source: IOException"); } if (!source.isCollection()) throw new RuntimeException(colName + " is not a collection!"); return source; } public static void save(Request request, String dirName) throws Exception { TraversableSource collection = getCollection(dirName); ModifiableTraversableSource result; Enumeration params = request.getParameterNames(); while (params.hasMoreElements()) { String name = (String) params.nextElement(); if (name.indexOf("..") > -1) throw new Exception("We are under attack!!"); //System.out.println("[param] " + name); if (name.startsWith("save:")) { Part part = (Part) request.get(name); String code = name.substring(5); if (!(collection instanceof ModifiableSource)) { throw new RuntimeException("Cannot modify the given source"); } result = (ModifiableTraversableSource)env.resolveURI(collection.getURI() + "/" + code); save(part, result); } else if (name.startsWith("delete:")) { String value = request.getParameter(name); if (value.length() > 0) { String code = name.substring(7); result = (ModifiableTraversableSource)env.resolveURI(collection + "/" + code); remove(result); } } } } public static void save(Request request, String param, String dest) throws Exception { Part part = (Part) request.get(param); save(part, (ModifiableTraversableSource)env.resolveURI(dest)); } public static void save(Part part, ModifiableTraversableSource destination) throws Exception { InputStream in = null; OutputStream out = null; try { in = part.getInputStream(); out = destination.getOutputStream(); copy(in, out); } finally { if (out != null) { out.close(); } if (in != null) { in.close(); } } } public static OutputStream getOutputStream(String collection) throws IOException { String mainResource = collection + "/" + FILE_NAME + ".xml"; String versionedResource = collection + "/" + FILE_NAME + "." + getVersionID(collection) + ".xml"; copy(mainResource, versionedResource); return ((ModifiableSource)env.resolveURI(mainResource)).getOutputStream(); } public static void revertFrom(String collection, int version) throws IOException { String mainResource = collection + "/" + FILE_NAME + ".xml"; String versionedResource = collection + "/" + FILE_NAME + "." + version + ".xml"; copy(versionedResource,mainResource); } /** * Returns the highest version id of the files included in the given * directory. */ public static int getVersionID(String colName) { TraversableSource collection = getCollection(colName); int id = 0; Collection contents; try { contents = collection.getChildren(); } catch (SourceException se) { throw new RuntimeException("Unable to list contents for collection " + colName); } for (Iterator iter = contents.iterator(); iter.hasNext();) { TraversableSource content = (TraversableSource) iter.next(); if (!content.isCollection()) { try { int localid = getVersion(content.getName()); if (localid > id) id = localid; } catch (Exception e) {} } } return ++id; } public static Object[] getVersions(String colName) { TraversableSource collection = getCollection(colName); ArrayList versions = new ArrayList(); Collection contents; try { contents = collection.getChildren(); } catch (SourceException se) { throw new RuntimeException("Unable to list contents for collection " + colName); } for (Iterator iter = contents.iterator(); iter.hasNext();) { TraversableSource content = (TraversableSource) iter.next(); if (!content.isCollection()) { try { int version = getVersion(content.getName()); if (version > 0) { versions.add(new Integer(version)); } } catch (Exception e) {} } } return versions.toArray(); } /** * Return the version encoded into the name as a numeric subextension of * an .xml extension. * * Example: * anything.123.xml -> 123 * document.3.xml -> 3 * document.0.xml -> 0 * document.xml -> -1 * image.0.jpg -> -1 */ private static int getVersion(String name) { int extIndex = name.lastIndexOf(".xml"); if (extIndex > 0) { String nameWithoutExtension = name.substring(0,extIndex); int dotIndex = nameWithoutExtension.lastIndexOf('.'); if (dotIndex > 0) { String localidString = nameWithoutExtension.substring(dotIndex + 1); return Integer.parseInt(localidString); } } return -1; } public static int getID(String colName) { TraversableSource collection = getCollection(colName); int id = 0; Collection contents; try { contents = collection.getChildren(); } catch (SourceException se) { throw new RuntimeException("Unable to list contents for collection " + colName); } for (Iterator iter = contents.iterator(); iter.hasNext();) { TraversableSource content = (TraversableSource) iter.next(); if (content.isCollection()) { try { String name = content.getName(); int localid = Integer.parseInt(name); if (localid > id) id = localid; } catch (Exception e) {} } } return ++id; } public static boolean remove(String resourceName) { try { return remove((ModifiableTraversableSource)env.resolveURI(resourceName)); } catch (MalformedURLException e) { return false; } catch (IOException e) { return false; } } public static boolean remove(ModifiableTraversableSource resource) { boolean success = true; if (resource.isCollection()) { Collection contents; try { contents = resource.getChildren(); } catch (SourceException se) { throw new RuntimeException("Unable to list contents for collection " + resource); } for (Iterator iter = contents.iterator(); iter.hasNext();) { ModifiableTraversableSource element = (ModifiableTraversableSource) iter.next(); success = remove(element); } } try { resource.delete(); return success; } catch (SourceException e) { return false; } } public static void copy(String from, String to) throws IOException { copy((ModifiableTraversableSource)env.resolveURI(from), (ModifiableTraversableSource)env.resolveURI(to)); } public static void copy(ModifiableTraversableSource from, ModifiableTraversableSource to) throws IOException { if (!from.exists()) { throw new IOException("Cannot find source file/folder"); } if (from.isCollection()) { to.makeCollection(); Collection contents; try { contents = from.getChildren(); } catch (SourceException se) { throw new RuntimeException("Unable to list contents for collection " + from); } for (Iterator iter = contents.iterator(); iter.hasNext();) { ModifiableTraversableSource src = (ModifiableTraversableSource) iter.next(); SourceUtil.copy(src, env.resolveURI(to.getURI() + "/" + src.getName())); } } else { to = (ModifiableTraversableSource)env.resolveURI(to.getURI()); InputStream in = null; OutputStream out = null; try { in = from.getInputStream(); out = to.getOutputStream(); copy(in,out); } finally { if (out != null) out.close(); if (in != null) in.close(); } } } public static void copy(InputStream from, OutputStream to) throws IOException { byte[] buffer = new byte[64 * 1024]; int count = 0; do { to.write(buffer, 0, count); count = from.read(buffer, 0, buffer.length); } while (count != -1); } } 1.1 cocoon-2.1/src/blocks/linotype/samples/sitemap.source.xmap Index: sitemap.source.xmap =================================================================== <?xml version="1.0" encoding="UTF-8"?> <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0"> <!-- =========================== Components ================================ --> <map:components> <map:generators default="file"> <map:generator name="file" src="org.apache.cocoon.generation.FileGenerator" label="content,data" logger="sitemap.generator.file" pool-min="1" pool-grow="1" pool-max="8" /> <map:generator name="directory" src="org.apache.cocoon.generation.DirectoryGenerator" label="content,data" logger="sitemap.generator.file" pool-min="1" pool-grow="1" pool-max="8" /> <map:generator name="traversable" src="org.apache.cocoon.generation.TraversableGenerator" label="content,data" logger="sitemap.generator.file" pool-min="1" pool-grow="1" pool-max="8" /> <map:generator name="request" src="org.apache.cocoon.generation.RequestGenerator" label="data" logger="sitemap.generator.request" pool-min="1" pool-grow="1" pool-max="4" /> <map:generator name="jx" src="org.apache.cocoon.generation.JXTemplateGenerator" label="content,data" logger="sitemap.generator.jx" pool-min="1" pool-grow="1" pool-max="8" /> <map:generator name="notifying" src="org.apache.cocoon.sitemap.NotifyingGenerator"/> </map:generators> <map:transformers default="xslt"> <map:transformer name="xslt" src="org.apache.cocoon.transformation.TraxTransformer" logger="sitemap.transformer.xslt" pool-min="2" pool-grow="2" pool-max="8" > <use-request-parameters>false</use-request-parameters> <use-session-parameters>false</use-session-parameters> <use-cookie-parameters>false</use-cookie-parameters> <!-- Xalan --> <transformer-factory>org.apache.xalan.processor.TransformerFactoryImpl</transformer-factory> <!-- XSLTC --> <!--transformer-factory>org.apache.xalan.xsltc.trax.TransformerFactoryImpl</transformer-factory--> <!-- Old (6.5.2) Saxon: --> <!--transformer-factory>com.icl.saxon.TransformerFactoryImpl</transformer-factory--> <!-- New (7.x?) Saxon: --> <!--transformer-factory>net.sf.saxon.TransformerFactoryImpl</transformer-factory--> </map:transformer> <map:transformer name="cinclude" src="org.apache.cocoon.transformation.CIncludeTransformer" logger="sitemap.transformer.cinclude" pool-min="2" pool-grow="2" pool-max="8" /> <map:transformer name="jx" src="org.apache.cocoon.transformation.JXTemplateTransformer" logger="sitemap.transformer.jx" pool-min="2" pool-grow="2" pool-max="8" /> </map:transformers> <map:serializers default="xhtml"> <map:serializer name="links" logger="sitemap.serializer.links" src="org.apache.cocoon.serialization.LinkSerializer" /> <map:serializer name="xml" mime-type="text/xml" logger="sitemap.serializer.xml" src="org.apache.cocoon.serialization.XMLSerializer" /> <map:serializer name="html" mime-type="text/html" src="org.apache.cocoon.serialization.HTMLSerializer" logger="sitemap.serializer.html" pool-min="1" pool-grow="1" pool-max="8" > <buffer-size>1024</buffer-size> <encoding>ISO-8859-1</encoding> </map:serializer> <map:serializer name="xhtml" mime-type="text/html" src="org.apache.cocoon.serialization.XMLSerializer" logger="sitemap.serializer.xhtml" pool-min="1" pool-grow="1" pool-max="8" > <doctype-public>-//W3C//DTD XHTML 1.0 Strict//EN</doctype-public> <doctype-system>http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</doctype-system> <buffer-size>1024</buffer-size> <encoding>ISO-8859-1</encoding> </map:serializer> <map:serializer logger="sitemap.serializer.rss" mime-type="text/rss" name="rss" pool-grow="2" pool-max="10" pool-min="2" src="org.apache.cocoon.serialization.XMLSerializer"> <doctype-system>http://my.netscape.com/publish/formats/rss-0.91.dtd</doctype-system> <encoding>ISO-8859-1</encoding> </map:serializer> </map:serializers> <map:readers default="resource"> <map:reader name="resource" src="org.apache.cocoon.reading.ResourceReader" logger="sitemap.reader.resource" pool-min="1" pool-grow="1" pool-max="8" /> <map:reader name="image" src="org.apache.cocoon.reading.ImageReader" logger="sitemap.reader.image" pool-min="1" pool-grow="1" pool-max="8" /> </map:readers> <map:matchers default="wildcard"> <map:matcher logger="sitemap.matcher.wildcard" name="wildcard" src="org.apache.cocoon.matching.WildcardURIMatcher"/> </map:matchers> <map:selectors default="exception"> <map:selector name="exception" logger="sitemap.selector.exception" src="org.apache.cocoon.selection.ExceptionSelector"> <exception name="not-found" class="org.apache.cocoon.ResourceNotFoundException"/> <exception class="java.lang.Throwable" unroll="true"/> </map:selector> </map:selectors> <map:pipes default="caching"> <map:pipe name="caching" src="org.apache.cocoon.components.pipeline.impl.CachingProcessingPipeline"/> <map:pipe name="caching-point" src="org.apache.cocoon.components.pipeline.impl.CachingPointProcessingPipeline"> <autoCachingPoint>On</autoCachingPoint> </map:pipe> <map:pipe name="noncaching" src="org.apache.cocoon.components.pipeline.impl.NonCachingProcessingPipeline"/> </map:pipes> </map:components> <!-- =========================== Views ===================================== --> <map:views> <map:view from-label="content" name="content"> <map:serialize type="xml"/> </map:view> <map:view from-label="results" name="pretty-content"> <map:transform src="stylesheets/system/xml2html.xslt"/> <map:serialize type="xhtml"/> </map:view> <map:view from-position="last" name="links"> <map:serialize type="links"/> </map:view> </map:views> <!-- ========================== Flowscript ================================= --> <map:flow language="JavaScript"> <!-- <map:script src="flow.js"/> --> <map:script src="sourceflow.js"/> </map:flow> <!-- =========================== Pipelines ================================= --> <map:pipelines> <map:component-configurations> <global-variables> <home>http://127.0.0.1:8888/samples/linotype</home> <repo>webdav://user:[EMAIL PROTECTED]/dav/samples/linotype/repository</repo> <count>3</count> </global-variables> </map:component-configurations> <!-- ============================ Flow Hooks =============================== --> <map:pipeline> <map:match pattern="**/*.kont"> <map:call continuation="{2}"/> </map:match> </map:pipeline> <!-- ========================= Private Resources =========================== --> <map:pipeline internal-only="true"> <map:match pattern="news"> <map:generate src="cocoon:/news.xml"/> <map:transform src="stylesheets/news2html-homepage.xslt"> <map:parameter name="home" value="{global:home}"/> <map:parameter name="count" value="3"/> </map:transform> <map:serialize/> </map:match> <map:match pattern="news.xml"> <map:generate type="traversable" src="{global:repo}/news/" label="content"> <map:parameter name="sort" value="lastmodified"/> <map:parameter name="reverse" value="true"/> </map:generate> <map:transform src="stylesheets/hierarchy2cinclude.xslt"> <map:parameter name="prefix" value="news"/> </map:transform> <map:transform type="cinclude"/> <map:serialize type="xml"/> </map:match> <map:match pattern="news/*.xml"> <map:generate src="{global:repo}/news/{1}/document.xml"/> <map:serialize type="xml"/> </map:match> <map:match pattern="edit/news/*/"> <map:generate src="cocoon:/news/{1}.xml"/> <map:transform src="stylesheets/news2edit.xslt"> <map:parameter name="home" value="{global:home}"/> </map:transform> <map:transform type="jx"/> <map:serialize/> </map:match> <map:match pattern="edit/news/*/content"> <map:generate src="cocoon:/news/{1}.xml"/> <map:transform src="stylesheets/news2html-content.xslt"> <map:parameter name="home" value="{global:home}"/> </map:transform> <map:serialize/> </map:match> <map:match pattern="edit/news/*/image-*.*"> <map:read src="{global:repo}/news/{1}/image-{2}.{3}" mime-type="image/{3}"/> </map:match> <map:match pattern="edit/news/*/template.jpg"> <map:read src="images/image.jpg" mime-type="image/jpg"/> </map:match> <map:match pattern="edit/news/*/resizer.png"> <map:read src="images/resizer.png" mime-type="image/png"/> </map:match> <map:match pattern="screen/news"> <map:generate src="cocoon:/news.xml"/> <map:transform src="stylesheets/news2html-private.xslt"> <map:parameter name="home" value="{global:home}"/> </map:transform> <map:serialize/> </map:match> <map:match pattern="screen/*"> <map:generate src="screens/{1}.jx" type="jx"/> <map:serialize/> </map:match> <map:match pattern="action/save-news"> <map:generate type="request"/> <map:transform src="stylesheets/request2news.xslt"/> <map:serialize type="xml"/> </map:match> </map:pipeline> <!-- ========================= Public Resource ============================= --> <map:pipeline> <map:match pattern=""> <map:generate src="index.xhtml"/> <map:transform type="cinclude"/> <map:serialize/> </map:match> <map:match pattern="history"> <map:generate src="cocoon:/news.xml"/> <map:transform src="stylesheets/news2html-history.xslt"> <map:parameter name="home" value="{global:home}"/> </map:transform> <map:serialize/> </map:match> <map:match pattern="request"> <map:generate type="request"/> <!--map:transform src="stylesheets/system/xml2html.xslt"/--> <map:serialize type="xml"/> </map:match> <map:match pattern="rss/0.91/index.rss"> <map:generate src="cocoon:/news.xml"/> <map:transform src="stylesheets/news2rss-0.91.xslt"> <map:parameter name="home" value="{global:home}/news"/> <map:parameter name="count" value="5"/> </map:transform> <map:serialize type="xml"/> </map:match> <map:match pattern="rss/2.0/index.rss"> <map:generate src="cocoon:/news.xml"/> <map:transform src="stylesheets/news2rss-2.0.xslt"> <map:parameter name="home" value="{global:home}/news"/> <map:parameter name="count" value="5"/> </map:transform> <map:serialize type="xml"/> </map:match> <map:match pattern="private/"> <map:redirect-to uri="news"/> </map:match> <map:match pattern="private/edit/news/*/*"> <map:call function="main"> <map:parameter name="page" value="edit"/> <map:parameter name="id" value="{1}"/> <map:parameter name="type" value="news"/> <map:parameter name="subpage" value="{2}"/> </map:call> </map:match> <map:match pattern="private/**"> <map:call function="main"> <map:parameter name="page" value="{1}"/> </map:call> </map:match> <map:match pattern="news/*/image-*.*"> <map:read src="{global:repo}/news/{1}/image-{2}.{3}" mime-type="image/{3}"/> </map:match> <map:match pattern="news/*/image-*-(*,*).*"> <map:read type="image" src="{global:repo}/news/{1}/image-{2}.{5}" mime-type="image/{5}"> <map:parameter name="width" value="{3}"/> <map:parameter name="height" value="{4}"/> </map:read> </map:match> <map:match pattern="news/*/"> <map:generate src="{global:repo}/news/{1}/document.xml"/> <map:transform src="stylesheets/news2html-single.xslt"> <map:parameter name="home" value="{global:home}"/> </map:transform> <map:serialize/> </map:match> <map:match pattern="images/**.*"> <map:read mime-type="image/{2}" src="images/{1}.{2}"/> </map:match> <map:match pattern="styles/**.css"> <map:read mime-type="text/css" src="styles/{1}.css"/> </map:match> <map:match pattern="scripts/**.js"> <map:read mime-type="text/javascript" src="scripts/{1}.js"/> </map:match> <!-- =========================== Error Handler ============================= --> <map:handle-errors> <map:select> <map:when test="not-found"> <map:generate type="jx" src="screens/notfound.jx"/> </map:when> <map:otherwise> <map:generate type="notifying"/> <map:transform src="stylesheets/system/error2html-debug.xslt"> <map:parameter name="uri" value="{request:requestURI}"/> <map:parameter name="home" value="{global:home}"/> </map:transform> </map:otherwise> </map:select> <map:serialize/> </map:handle-errors> </map:pipeline> </map:pipelines> </map:sitemap> 1.1 cocoon-2.1/src/blocks/linotype/samples/sourceflow.js Index: sourceflow.js =================================================================== /* * Yeah, I know that hardwiring those is hacky as hell. But I'll try to * fix this with link translation later on. */ var configPath = cocoon.context.getRealPath("/") + "samples/linotype/"; var home = "webdav://dav:[EMAIL PROTECTED]:9999/dav/samples/linotype/"; var stream = new java.io.FileInputStream(configPath + "linotype.users.properties"); var users = new Packages.org.apache.cocoon.components.UserManager.getInstance(stream); var repo = new Packages.org.apache.cocoon.components.SourceRepository.getInstance(); var userid = ""; var username = ""; /* * Main entry point for the flow. This is where user authorization takes place. */ function main(action) { var args = new Array(arguments.length - 1); for (var i = 1; i < arguments.length; i++) { args[i-1] = arguments[i]; } if ((userid == undefined) || (userid == "")) { login(action, args); } invoke(action, args); } /* * If the user is not yet authorized, than authentication takes place */ function login(action, args) { var name = ""; var password = ""; var userError = ""; var passError = ""; while (true) { sendPageAndWait("screen/login", { username : name, userError : userError, passError : passError}); name = cocoon.request.getParameter("username"); password = cocoon.request.getParameter("password"); if (users.isValidName(name)) { if (users.isValidPassword(name,password)) { userid = name; username = users.getFullName(name); break; } else { userError = ""; passError = "Password doesn't match"; } } else { userError = "User not found"; passError = ""; } } cocoon.createSession(); } /* * Now that the user has been authenticated and authorized, execute what * he's asking for. This method checks the flowscript to see if the * called action exists as a flowscript function. If so, it's called with * the given arguments. If not, the appropriate admin screen is sent * to the user. */ function invoke(action, args) { func = this[action]; if (func != undefined) { func.apply(this,args); } else { sendPage("screen/" + action, {"user" : username}); } } // ----------------------------- actions ---------------------------------- /* * The logout action clears the userid from the session thus signaling * that the user has logged out and should be further considered authenticated. */ function logout() { userid = ""; sendPage("screen/logout"); } /* * The edit action performs the editing subflow. */ function edit(id,type,subpage) { var repository = home + "repository/" + type + "/"; if (id == "template") { id = repo.getID(repository); repo.copy(repository + "template", repository + id); redirect("../" + id + "/"); } else if ((subpage != undefined) && (subpage != "")) { sendPage("edit/" + type + "/" + id + "/" + subpage,{}); } else { var document = repository + id; while (true) { var versions = repo.getVersions(document); sendPageAndWait("edit/" + type + "/" + id + "/", { userid : userid, username : username, versions : versions, innerHTML : cocoon.request.getParameter("innerHTML") }); var action = cocoon.request.getParameter("action"); if (action == "delete") { repo.remove(document); break; } else if (action == "restore") { var version = cocoon.request.getParameter("version"); repo.revertFrom(document,version); } else { var output = repo.getOutputStream(document); process("samples/linotype/action/save-" + type,{},output); output.close(); repo.save(cocoon.request, document); if (action == "finish") break; } } redirect("../../../" + type); } }