svn commit: r1176905 [3/3] - in /lenya/contributions/2_0_X/modules/lenyaDocWriting: ./ client/ client/simple-client_files/ config/ docs/ java/ java/src/ java/src/org/ java/src/org/apache/ java/src/org/apache/lenya/ java/src/org/apache/lenya/transformat...
[email protected] Wed, 28 Sep 2011 14:49:02 -0000
| Newsgroups | gmane.comp.cms.lenya.cvs |
|---|---|
| Message-ID | <[email protected]> |
Added: lenya/contributions/2_0_X/modules/lenyaDocWriting/java/src/org/apache/lenya/transformation/AbstractLenyaDocWritingTransformer.java
URL: http://svn.apache.org/viewvc/lenya/contributions/2_0_X/modules/lenyaDocWriting/java/src/org/apache/lenya/transformation/AbstractLenyaDocWritingTransformer.java?rev=1176905&view=auto
==============================================================================
--- lenya/contributions/2_0_X/modules/lenyaDocWriting/java/src/org/apache/lenya/transformation/AbstractLenyaDocWritingTransformer.java (added)
+++ lenya/contributions/2_0_X/modules/lenyaDocWriting/java/src/org/apache/lenya/transformation/AbstractLenyaDocWritingTransformer.java Wed Sep 28 14:49:00 2011
@@ -0,0 +1,737 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lenya.transformation;
+
+import java.io.IOException;
+import java.util.Map;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.transformation.AbstractSAXTransformer;
+import org.apache.excalibur.source.ModifiableSource;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceException;
+import org.apache.excalibur.xml.dom.DOMParser;
+import org.apache.excalibur.xml.xpath.XPathProcessor;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.apache.lenya.cms.site.SiteStructure;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.cms.site.SiteException;
+import java.util.Stack;
+
+public abstract class AbstractLenyaDocWritingTransformer extends AbstractSAXTransformer {
+
+ public static final String SWT_URI = "http://4sengines/lenyadoc/0.1";
+ public static final String DEFAULT_SERIALIZER = "xml";
+
+ /** incoming elements */
+ // Lenyadoc element
+ public static final String LENYADOC_ELEMENT = "lenyadoc";
+ public static final String PARAMETERS_ELEMENT = "parameters";
+ public static final String PUBNAME_ELEMENT = "pubname";
+ public static final String RESOURCETYPE_ELEMENT = "resourcetype";
+ public static final String LANGUAGE_ELEMENT = "language";
+
+ public static final String PATH_ELEMENT = "path";
+ public static final String PARENTPATH_ELEMENT = "parentpath";
+ public static final String PATHNAME_ELEMENT = "pathname";
+
+ public static final String NAVTITLE_ELEMENT = "navtitle";
+
+ public static final String WORKFLOWSTATE_ELEMENT = "workflowstate";
+
+ public static final String CONTENT_ELEMENT = "content";
+ public static final String CONTENTPATH_ELEMENT = "contentpath";
+ public static final String REPLACEPATH_ELEMENT = "replacepath";
+ public static final String FRAGMENT_ELEMENT = "fragment";
+ public static final String FILE_ELEMENT = "file";
+
+ // LenyaDoc attributes
+ // -- for the lenyadoc:parameter section
+ public static final String IFDOCEXIST_ATTRIBUTE = "ifdocexist";
+ public static final String IFDOCEXIST_CREATE_VALUE = "create";
+ public static final String IFDOCEXIST_MODIFY_VALUE = "modify";
+ public static final String IFDOCEXIST_DELETE_VALUE = "delete";
+ public static final String IFDOCEXIST_ESCAPE_VALUE = "escape";
+
+ /** outgoing elements */
+ public static final String RESULT_ELEMENT = "sourceResult";
+ public static final String EXECUTION_ELEMENT = "execution";
+ public static final String BEHAVIOUR_ELEMENT = "behaviour";
+ public static final String ACTION_ELEMENT = "action";
+ public static final String MESSAGE_ELEMENT = "message";
+ public static final String SERIALIZER_ELEMENT = "serializer";
+
+ /***************************************************
+ **** lenyadoc outgoing elements
+ **/
+ /*
+ * ?? How to add lenyadoc: before my element ? I try that : public static
+ * final String LENYADOCRESULT_ELEMENT = "lenyadoc:lenyadocresult"; but
+ * after the tranformation <xsl:apply-template
+ * select="lenyadoc:lenyadocresult"/> don't match... ??
+ */
+ public static final String LENYADOCRESULT_ELEMENT = "lenyadocresult";
+ public static final String PATHRESULT_ELEMENT = "path";
+ public static final String UUIDRESULT_ELEMENT = "uuid";
+ public static final String NAMERESULT_ELEMENT = "name";
+
+ /** main (write or insert) tag attributes */
+ public static final String SERIALIZER_ATTRIBUTE = "serializer";
+ public static final String CREATE_ATTRIBUTE = "create";
+ public static final String OVERWRITE_ATTRIBUTE = "overwrite";
+ /** results */
+ public static final String RESULT_FAILED = "failed";
+ public static final String RESULT_SUCCESS = "success";
+ public static final String ACTION_NONE = "none";
+ public static final String ACTION_NEW = "new";
+ public static final String ACTION_OVER = "overwritten";
+ public static final String ACTION_DELETE = "deleted";
+ /** The current state */
+ // lenyadoc states
+ private static final int STATE_OUTSIDE = 0;
+ private static final int STATE_LENYADOC = 1;
+ private static final int STATE_PARAMETERS = 2;
+ private static final int STATE_PUBNAME = 3;
+ private static final int STATE_RESOURCETYPE = 31;
+ private static final int STATE_LANGUAGE = 32;
+ private static final int STATE_PATH = 4;
+ private static final int STATE_PARENTPATH = 41;
+ private static final int STATE_PATHNAME = 42;
+ private static final int STATE_NAVTITLE = 5;
+ private static final int STATE_CONTENT = 6;
+ private static final int STATE_CONTENTPATH = 7;
+ private static final int STATE_REPLACEPATH = 8;
+ private static final int STATE_FRAGMENT = 9;
+ private static final int STATE_FILE = 91;
+ private static final int STATE_WORKFLOWSTATE = 10;
+
+ private int state;
+ private int parent_state;
+
+ protected String workflowState = null;
+
+ /** The configured serializer name */
+ protected String configuredSerializerName;
+
+ /** The XPath processor */
+ protected XPathProcessor xpathProcessor;
+
+ protected String IfDocExistAttribute;
+
+ // TODO : destroy lenyaDoc on end of xml treatment
+ protected org.apache.lenya.cms.publication.Document lenyaDoc = null;
+
+ //override the AbstractSAXTransformer stack.
+ protected final Stack stack = new Stack();
+
+ /**
+ * Get the current <code>Configuration</code> instance used by this
+ * <code>Configurable</code>.
+ */
+ public void configure(Configuration configuration)
+ throws ConfigurationException {
+ super.configure(configuration);
+ this.configuredSerializerName = configuration.getChild(
+ SERIALIZER_ATTRIBUTE).getValue(DEFAULT_SERIALIZER);
+ }
+
+ /**
+ * Get the <code>Parameter</code> called "serializer" from the
+ * <code>Transformer</code> invocation.
+ */
+ public void setup(SourceResolver resolver, Map objectModel, String src,
+ Parameters par) throws ProcessingException, SAXException,
+ IOException {
+ super.setup(resolver, objectModel, src, par);
+
+ this.configuredSerializerName = par.getParameter(SERIALIZER_ATTRIBUTE,
+ this.configuredSerializerName);
+ this.state = STATE_OUTSIDE;
+ }
+
+ /**
+ * Receive notification of the beginning of an element.
+ *
+ * @param uri
+ * The Namespace URI, or the empty string if the element has no
+ * Namespace URI or if Namespace processing is not being
+ * performed.
+ * @param name
+ * The local name (without prefix), or the empty string if
+ * Namespace processing is not being performed.
+ * @param raw
+ * The raw XML 1.0 name (with prefix), or the empty string if raw
+ * names are not available.
+ * @param attr
+ * The attributes attached to the element. If there are no
+ * attributes, it shall be an empty Attributes object.
+ */
+ public void startTransformingElement(String uri, String name, String raw,
+ Attributes attr) throws SAXException, IOException,
+ ProcessingException {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(
+ "Start transforming element. uri=" + uri + ", name=" + name
+ + ", raw=" + raw + ", attr=" + attr);
+ }
+
+ // element /lenyadoc
+ if (this.state == STATE_OUTSIDE && name.equals(LENYADOC_ELEMENT)) {
+ this.state = STATE_LENYADOC;
+ this.parent_state = this.state;
+ //init global parameter workflowstate to null
+ workflowState = null;
+ }
+
+ // element /lenyadoc/parameters
+ else if (this.state == STATE_LENYADOC && name.equals(PARAMETERS_ELEMENT)) {
+ this.parent_state = this.state;
+ this.state = STATE_PARAMETERS;
+ this.stack.push("ENDPARAMETERS");
+ IfDocExistAttribute = getIfDocExistAttributeValue(attr);
+ }
+
+ // element /lenyadoc/parameters/pubname
+ else if (this.state == STATE_PARAMETERS && name.equals(PUBNAME_ELEMENT)) {
+ this.parent_state = this.state;
+ this.state = STATE_PUBNAME;
+ this.startTextRecording();
+
+ }
+
+ // element /lenyadoc/parameters/resourcetype
+ else if (this.state == STATE_PARAMETERS && name.equals(RESOURCETYPE_ELEMENT)) {
+ this.parent_state = this.state;
+ this.state = STATE_RESOURCETYPE;
+ this.startTextRecording();
+
+ }
+
+ // element /lenyadoc/parameters/language
+ else if (this.state == STATE_PARAMETERS && name.equals(LANGUAGE_ELEMENT)) {
+ this.parent_state = this.state;
+ this.state = STATE_LANGUAGE;
+ this.startTextRecording();
+
+ }
+
+ // element /lenyadoc/parameters/path
+ else if (this.state == STATE_PARAMETERS && name.equals(PATH_ELEMENT)) {
+ this.parent_state = this.state;
+ this.state = STATE_PATH;
+ this.startTextRecording();
+ }
+
+ // element /lenyadoc/parameters/parentpath
+ else if (this.state == STATE_PARAMETERS && name.equals(PARENTPATH_ELEMENT)) {
+ this.parent_state = this.state;
+ this.state = STATE_PARENTPATH;
+ this.startTextRecording();
+ }
+
+ // element /lenyadoc/parameters/pathname
+ else if (this.state == STATE_PARAMETERS && name.equals(PATHNAME_ELEMENT)) {
+ this.parent_state = this.state;
+ this.state = STATE_PATHNAME;
+ this.startTextRecording();
+ }
+
+ // element /lenyadoc/parameters/navtitle
+ else if (this.state == STATE_PARAMETERS && name.equals(NAVTITLE_ELEMENT)) {
+ this.parent_state = this.state;
+ this.state = STATE_NAVTITLE;
+ this.startTextRecording();
+ }
+
+ // element /lenyadoc/parameters/workflowstate
+ else if (this.state == STATE_PARAMETERS && name.equals(WORKFLOWSTATE_ELEMENT)) {
+ this.parent_state = this.state;
+ this.state = STATE_WORKFLOWSTATE;
+ this.startTextRecording();
+ }
+
+ // element /lenyadoc/content
+ else if (this.state == STATE_LENYADOC && name.equals(CONTENT_ELEMENT)) {
+ this.parent_state = this.state;
+ this.state = STATE_CONTENT;
+ this.stack.push("ENDCONTENT");
+ }
+
+ // element /lenyadoc/content/contentpath
+ else if (this.state == STATE_CONTENT && name.equals(CONTENTPATH_ELEMENT)) {
+ this.parent_state = this.state;
+ this.state = STATE_CONTENTPATH;
+ this.startTextRecording();
+ }
+
+ // element /lenyadoc/content/replacepath
+ else if (this.state == STATE_CONTENT && name.equals(REPLACEPATH_ELEMENT)) {
+ this.parent_state = this.state;
+ this.state = STATE_REPLACEPATH;
+ this.startTextRecording();
+ }
+
+ // element /lenyadoc/content/fragment
+ else if (this.state == STATE_CONTENT && name.equals(FRAGMENT_ELEMENT)) {
+ this.parent_state = this.state;
+ this.state = STATE_FRAGMENT;
+ this.startRecording();
+ }
+
+ // element /lenyadoc/content/file
+ else if (this.state == STATE_CONTENT && name.equals(FILE_ELEMENT)) {
+ this.parent_state = this.state;
+ this.state = STATE_FILE;
+ this.startTextRecording();
+ }
+
+ else {
+ // modif flo :: ajout d'un marqueur :
+ //reportResult("", "tag ELSE START", "NAME = ", name, "STATE = ", String.valueOf(this.state));
+ super.startTransformingElement(uri, name, raw, attr);
+ }
+ }
+
+ private String getIfDocExistAttributeValue(Attributes attr) {
+ // the default value
+ String result = new String(IFDOCEXIST_CREATE_VALUE);
+
+ // if attribute is another value than default
+ if (attr.getValue(IFDOCEXIST_ATTRIBUTE) != null) {
+ if (attr.getValue(IFDOCEXIST_ATTRIBUTE).equals(IFDOCEXIST_CREATE_VALUE)) {
+ // do nothing, the default value
+ }
+ if (attr.getValue(IFDOCEXIST_ATTRIBUTE).equals(IFDOCEXIST_MODIFY_VALUE)) {
+ result = new String(IFDOCEXIST_MODIFY_VALUE);
+ }
+ if (attr.getValue(IFDOCEXIST_ATTRIBUTE).equals(IFDOCEXIST_DELETE_VALUE)) {
+ result = new String(IFDOCEXIST_DELETE_VALUE);
+ }
+ if (attr.getValue(IFDOCEXIST_ATTRIBUTE).equals(IFDOCEXIST_ESCAPE_VALUE)) {
+ result = new String(IFDOCEXIST_ESCAPE_VALUE);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Receive notification of the end of an element.
+ *
+ * @param uri
+ * The Namespace URI, or the empty string if the element has no
+ * Namespace URI or if Namespace processing is not being
+ * performed.
+ * @param name
+ * The local name (without prefix), or the empty string if
+ * Namespace processing is not being performed.
+ * @param raw
+ * The raw XML 1.0 name (with prefix), or the empty string if raw
+ * names are not available.
+ */
+
+ // this function create the document at the end of <parameters> and work on
+ // doc's content at the end of <content>
+ public void endTransformingElement(String uri, String name, String raw)
+ throws SAXException, IOException, ProcessingException {
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(
+ "End transforming element. uri=" + uri + ", name=" + name
+ + ", raw=" + raw);
+ }
+ // END element /lenyadoc
+ if (this.state == STATE_LENYADOC && name.equals(LENYADOC_ELEMENT)) {
+ this.state = STATE_OUTSIDE;
+ this.parent_state = this.state;
+ // if lenyaDoc is not null
+ if (lenyaDoc != null) {
+ // write the document on the system
+ commitLenyaDoc();
+ // if the wokflowstate is not null
+ //if (workflowState != null){
+ //if (workflowState != null){
+ if (workflowState != null){
+ //reportResult("","CALL applyWorkflow","","","","");
+ applyWorkflowState();
+ }
+ } else {
+ // TODO : an error report on the result
+ }
+
+ }
+
+ // END element /lenyadoc/parameters
+ else if (this.state == STATE_PARAMETERS && name.equals(PARAMETERS_ELEMENT)) {
+ this.state = STATE_LENYADOC; // or this.parent_state ?
+ // Do someting on the end of paramters ? INIT the document ?
+ // reportResult("","tag FIN PARAMETERS","message = connection","","resultat","action = test");
+ // retrive values for the stack
+ String tag;
+ // /parameters elements
+ String pubname = null;
+ String resourceType = new String("xhtml"); // "xhtml" resourceType
+ // is the default value
+ String language = new String("en");// en is the default language
+ String path = null;
+ String parentpath = null;
+ String pathname = null;
+ String navtitle = null;
+ // workflowstate is not put in the stack because it's a global
+ // parameter
+
+ do {
+ tag = (String) this.stack.pop();
+ if (tag.equals("PUBNAME")) {
+ pubname = (String) this.stack.pop();
+ }
+ if (tag.equals("RESOURCETYPE")) {
+ resourceType = (String) this.stack.pop();
+ } else if (tag.equals("LANGUAGE")) {
+ language = (String) this.stack.pop();
+ } else if (tag.equals("PATH")) {
+ path = (String) this.stack.pop();
+
+ } else if (tag.equals("PARENTPATH")) {
+ parentpath = (String) this.stack.pop();
+
+ } else if (tag.equals("PATHNAME")) {
+ pathname = (String) this.stack.pop();
+
+ } else if (tag.equals("NAVTITLE")) {
+ navtitle = (String) this.stack.pop();
+ }
+ } while (!tag.equals("ENDPARAMETERS"));
+
+ // creation of the document
+ lenyaDoc = createLenyaDocument(pubname, resourceType, language, path, parentpath, pathname, navtitle);
+ }
+
+ // END element /lenyadoc/parameters/pubname
+ else if (this.state == STATE_PUBNAME && name.equals(PUBNAME_ELEMENT)) {
+ this.state = this.parent_state;
+ this.stack.push(this.endTextRecording());
+ this.stack.push("PUBNAME");
+ }
+
+ // END element /lenyadoc/parameters/resourceType
+ else if (this.state == STATE_RESOURCETYPE && name.equals(RESOURCETYPE_ELEMENT)) {
+ this.state = this.parent_state;
+ this.stack.push(this.endTextRecording());
+ this.stack.push("RESOURCETYPE");
+ // reportResult("","tag FIN PUBNAME","message = connection","","resultat","action = test");
+ }
+
+ // END element /lenyadoc/parameters/language
+ else if (this.state == STATE_LANGUAGE && name.equals(LANGUAGE_ELEMENT)) {
+ this.state = this.parent_state;
+ this.stack.push(this.endTextRecording());
+ this.stack.push("LANGUAGE");
+ // reportResult("","tag FIN PUBNAME","message = connection","","resultat","action = test");
+ }
+
+ // END element /lenyadoc/parameters/path
+ else if (this.state == STATE_PATH && name.equals(PATH_ELEMENT)) {
+ this.state = this.parent_state;
+ this.stack.push(this.endTextRecording());
+ this.stack.push("PATH");
+ // reportResult("","tag FIN PATH","message = connection","","resultat","action = test");
+ }
+
+ // END element /lenyadoc/parameters/parentpath
+ else if (this.state == STATE_PARENTPATH
+ && name.equals(PARENTPATH_ELEMENT)) {
+ this.state = this.parent_state;
+ this.stack.push(this.endTextRecording());
+ this.stack.push("PARENTPATH");
+ // reportResult("","tag FIN PATH","message = connection","","resultat","action = test");
+ }
+
+ // END element /lenyadoc/parameters/pathname
+ else if (this.state == STATE_PATHNAME && name.equals(PATHNAME_ELEMENT)) {
+ this.state = this.parent_state;
+ this.stack.push(this.endTextRecording());
+ this.stack.push("PATHNAME");
+ // reportResult("","tag FIN PATH","message = connection","","resultat","action = test");
+ }
+
+ // END element /lenyadoc/parameters/navtitle
+ else if (this.state == STATE_NAVTITLE && name.equals(NAVTITLE_ELEMENT)) {
+ this.state = this.parent_state;
+ this.stack.push(this.endTextRecording());
+ this.stack.push("NAVTITLE");
+ // reportResult("","tag FIN NAVTILE","message = connection","","resultat","action = test");
+ }
+
+ // END element /lenyadoc/parameters/workflowstate
+ else if (this.state == STATE_WORKFLOWSTATE
+ && name.equals(WORKFLOWSTATE_ELEMENT)) {
+ this.state = this.parent_state;
+ // don't use the stack push because workflowState is a global
+ // variable
+ workflowState = (String) this.endTextRecording();
+ }
+
+ // -----------------------------------------------------------------//
+ // --------------- elements in content
+ // END element /lenyadoc/content/contentpath
+ else if (this.state == STATE_CONTENTPATH
+ && name.equals(CONTENTPATH_ELEMENT)) {
+ this.state = this.parent_state;
+ this.stack.push(this.endTextRecording());
+ this.stack.push("CONTENTPATH");
+ // reportResult("","tag FIN CONTENTPATH","message = connection","","resultat","action = test");
+ }
+
+ // END element /lenyadoc/content/replacepath
+ else if (this.state == STATE_REPLACEPATH
+ && name.equals(REPLACEPATH_ELEMENT)) {
+ this.state = this.parent_state;
+ this.stack.push(this.endTextRecording());
+ this.stack.push("REPLACEPATH");
+ // reportResult("","tag FIN REPLACEPATH","message = connection","","resultat","action = test");
+ }
+
+ // END element /lenyadoc/content/fragment
+ else if (this.state == STATE_FRAGMENT && name.equals(FRAGMENT_ELEMENT)) {
+ this.state = this.parent_state;
+ this.stack.push(this.endRecording());
+ this.stack.push("FRAGMENT");
+ }
+
+ // END element /lenyadoc/content/file
+ else if (this.state == STATE_FILE && name.equals(FILE_ELEMENT)) {
+ this.state = this.parent_state;
+ this.stack.push(this.endTextRecording());
+ this.stack.push("FILE");
+ }
+
+ // END element /lenyadoc/content
+ // Set the content fragment in the lenyadoc
+ else if (this.state == STATE_CONTENT && name.equals(CONTENT_ELEMENT)) {
+ this.state = STATE_LENYADOC;
+ // retrieve values for the stack
+ String tag;
+ // /content elements
+ String contentpath = null;
+ String replacepath = null;
+ DocumentFragment fragment = null;
+ String fileURI = null;
+
+ do {
+ tag = (String) this.stack.pop();
+
+ // element inside /content
+ if (tag.equals("CONTENTPATH")) {
+ contentpath = (String) this.stack.pop();
+ } else if (tag.equals("REPLACEPATH")) {
+ replacepath = (String) this.stack.pop();
+ } else if (tag.equals("FRAGMENT")) {
+ fragment = (DocumentFragment) this.stack.pop();
+ }
+ else if (tag.equals("FILE")){
+ fileURI = (String) this.stack.pop();
+ }
+ } while (!tag.equals("ENDCONTENT"));
+
+ if (fragment != null){
+ setLenyaDocContent(contentpath, replacepath, fragment);
+ }
+ if (fileURI != null){
+ setLenyaMediaContent(fileURI);
+ }
+ }
+
+ /**
+ * fin TRansformation pour les Lenyadocs
+ * -----------------------------------------------------------------
+ * ----------------------------------------------------------------
+ */
+
+ // default
+ else {
+ // modif flo : suppression du super et ajout d'un marqueur :
+ // TODO : ?? an error message on the output ??
+ //reportResult("", "tag ELSE END", "NAME = ", name, "STATE = ", String.valueOf(this.state));
+ super.endTransformingElement(uri, name, raw);
+ }
+ }
+
+ abstract protected void setLenyaMediaContent(String fileURI);
+
+ abstract protected org.apache.lenya.cms.publication.Document createLenyaDocument(
+ String pubName, String ressourceType, String language, String path,
+ String parentPath, String pathName, String navTitle)
+ throws ProcessingException;
+
+ // write an xml fragment in the document do modifications document if asked
+ abstract protected void setLenyaDocContent(String contentpath, String replacePath, DocumentFragment fragment)
+ throws SAXException, IOException,ProcessingException;
+
+ abstract protected void commitLenyaDoc() throws ProcessingException;
+
+ abstract protected void applyWorkflowState() throws ProcessingException, SAXException;
+
+ /**
+ * Execute a usecase, but with NO check of roles and permissions (see document docs/workflow-invoker for explanations)
+ * @param webappUrl
+ * @param usecaseName
+ * @throws RuntimeException
+ */
+ abstract protected void executeUsecase(String webappUrl, String usecaseName)
+ throws RuntimeException;
+
+ // function from the source exemple
+ protected void createAncestorNodes(
+ org.apache.lenya.cms.publication.Document document)
+ throws PublicationException, SiteException {
+ SiteStructure liveSite = document.getPublication()
+ .getArea(Publication.LIVE_AREA).getSite();
+ String[] steps = document.getPath().substring(1).split("/");
+ int s = 0;
+ String path = "";
+ while (s < steps.length) {
+ if (!liveSite.contains(path)) {
+ liveSite.add(path);
+ }
+ path += "/" + steps[s];
+ s++;
+ }
+ }
+
+ /**
+ * Deletes a source
+ *
+ * @param systemID
+ */
+ private void deleteSource(String systemID) throws ProcessingException,
+ IOException, SAXException {
+ Source source = null;
+ try {
+ source = resolver.resolveURI(systemID);
+ if (!(source instanceof ModifiableSource)) {
+ throw new ProcessingException("Source '" + systemID
+ + "' is not writeable.");
+ }
+
+ ((ModifiableSource) source).delete();
+ reportResult("none", "delete", "source deleted successfully",
+ systemID, RESULT_SUCCESS, ACTION_DELETE);
+ } catch (SourceException se) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("FAIL exception: " + se, se);
+ }
+ reportResult("none", "delete",
+ "unable to delete source: " + se.getMessage(), systemID,
+ RESULT_FAILED, ACTION_DELETE);
+ } finally {
+ resolver.release(source);
+ }
+ }
+
+ // TODO: create a sendLenyaDocResult(lenya.document document)
+ protected void lenyaDocResult(String pathValue, String uuidValue, String name)
+ throws SAXException {
+ startElement(SWT_URI, LENYADOCRESULT_ELEMENT, LENYADOCRESULT_ELEMENT, EMPTY_ATTRIBUTES);
+
+ startElement(SWT_URI, PATHRESULT_ELEMENT, PATHRESULT_ELEMENT, EMPTY_ATTRIBUTES);
+ sendTextEvent(pathValue);
+ endElement(SWT_URI, PATHRESULT_ELEMENT, PATHRESULT_ELEMENT);
+
+ startElement(SWT_URI, UUIDRESULT_ELEMENT, UUIDRESULT_ELEMENT, EMPTY_ATTRIBUTES);
+ sendTextEvent(uuidValue);
+ endElement(SWT_URI, UUIDRESULT_ELEMENT, UUIDRESULT_ELEMENT);
+
+ startElement(SWT_URI, NAMERESULT_ELEMENT, NAMERESULT_ELEMENT, EMPTY_ATTRIBUTES);
+ sendTextEvent(name);
+ endElement(SWT_URI, NAMERESULT_ELEMENT, NAMERESULT_ELEMENT);
+
+ endElement(SWT_URI, LENYADOCRESULT_ELEMENT, LENYADOCRESULT_ELEMENT);
+ }
+
+ protected void reportResult(String localSerializer, String behaviour,
+ String message, String content, String execution, String action)
+ throws SAXException {
+ sendStartElementEvent(RESULT_ELEMENT);
+
+ if (localSerializer != null) {
+ sendStartElementEvent(SERIALIZER_ELEMENT);
+ sendTextEvent(localSerializer);
+ sendEndElementEvent(SERIALIZER_ELEMENT);
+ }
+ sendStartElementEvent(BEHAVIOUR_ELEMENT);
+ sendTextEvent(behaviour);
+ sendEndElementEvent(BEHAVIOUR_ELEMENT);
+ sendStartElementEvent(MESSAGE_ELEMENT);
+ sendTextEvent(message);
+ sendEndElementEvent(MESSAGE_ELEMENT);
+ sendStartElementEvent(CONTENT_ELEMENT);
+ sendTextEvent(content);
+ sendEndElementEvent(CONTENT_ELEMENT);
+ sendStartElementEvent(EXECUTION_ELEMENT);
+ sendTextEvent(execution);
+ sendEndElementEvent(EXECUTION_ELEMENT);
+ sendStartElementEvent(ACTION_ELEMENT);
+ sendTextEvent(action);
+ sendEndElementEvent(ACTION_ELEMENT);
+
+ sendEndElementEvent(RESULT_ELEMENT);
+ }
+
+ protected Document newDOMDocument() throws SAXException, ServiceException {
+ DOMParser parser = (DOMParser) this.manager.lookup(DOMParser.ROLE);
+ try {
+ return parser.createDocument();
+ } finally {
+ this.manager.release(parser);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ super.service(manager);
+ this.xpathProcessor = (XPathProcessor) this.manager
+ .lookup(XPathProcessor.ROLE);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.avalon.framework.activity.Disposable#dispose()
+ */
+ public void dispose() {
+ if (this.manager != null) {
+ this.manager.release(this.xpathProcessor);
+ this.xpathProcessor = null;
+ }
+ super.dispose();
+ }
+}
Added: lenya/contributions/2_0_X/modules/lenyaDocWriting/java/src/org/apache/lenya/transformation/LenyaDocWritingTransformer.java
URL: http://svn.apache.org/viewvc/lenya/contributions/2_0_X/modules/lenyaDocWriting/java/src/org/apache/lenya/transformation/LenyaDocWritingTransformer.java?rev=1176905&view=auto
==============================================================================
--- lenya/contributions/2_0_X/modules/lenyaDocWriting/java/src/org/apache/lenya/transformation/LenyaDocWritingTransformer.java (added)
+++ lenya/contributions/2_0_X/modules/lenyaDocWriting/java/src/org/apache/lenya/transformation/LenyaDocWritingTransformer.java Wed Sep 28 14:49:00 2011
@@ -0,0 +1,585 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lenya.transformation;
+
+import java.io.IOException;
+import org.apache.lenya.ac.AccessControlException;
+
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.xml.dom.DOMUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.apache.lenya.cms.ac.PublicationAccessControllerResolver;
+import org.apache.lenya.cms.publication.DocumentFactory;
+import org.apache.lenya.cms.publication.DocumentUtil;
+import org.apache.lenya.cms.publication.ResourceWrapper;
+import org.apache.lenya.cms.repository.RepositoryException;
+import org.apache.lenya.cms.repository.RepositoryUtil;
+import org.apache.lenya.cms.repository.Session;
+import org.apache.lenya.cms.publication.ResourceType;
+import org.apache.lenya.cms.publication.DocumentManager;
+import org.apache.lenya.cms.site.SiteStructure;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.cms.site.SiteException;
+import org.apache.lenya.cms.publication.DocumentBuildException;
+import org.apache.lenya.transaction.ConcurrentModificationException;
+import org.apache.lenya.ac.AccessControllerResolver;
+import org.apache.lenya.ac.AccreditableManager;
+import org.apache.lenya.ac.Identity;
+import org.apache.lenya.ac.User;
+import org.apache.lenya.ac.impl.DefaultAccessController;
+
+import javax.xml.parsers.*;
+import org.apache.lenya.xml.DocumentHelper;
+import org.apache.lenya.xml.NamespaceHelper;
+import org.apache.lenya.cms.usecase.Usecase;
+import org.apache.lenya.cms.usecase.UsecaseResolver;
+
+public class LenyaDocWritingTransformer extends AbstractLenyaDocWritingTransformer {
+
+ private boolean escape = false;
+ /**
+ * Constructor. Set the namespace.
+ */
+ public LenyaDocWritingTransformer() {
+ this.defaultNamespaceURI = SWT_URI;
+ }
+
+
+ protected void setLenyaMediaContent(String fileURI) {
+
+ //lenyaDoc.setSourceExtension("pdf");
+ ResourceWrapper wrapper = new ResourceWrapper(lenyaDoc, this.manager, getLogger());
+ try {
+ wrapper.write(fileURI);
+ //use Exception for catch as so many differents exceptions can be thrown
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ protected org.apache.lenya.cms.publication.Document createLenyaDocument(
+ String pubName, String ressourceType, String language, String path,
+ String parentPath, String pathName, String navTitle)
+ throws ProcessingException {
+
+ org.apache.lenya.cms.publication.Document doc = null;
+
+ try {
+ escape = false;
+
+
+ // TODO : offert the option to define the identity of the autor
+ // <identity><name></name><paswd></passwd></identity>
+ //seem not usefull
+ //org.apache.cocoon.environment.Session cocoonSession = request.getSession();
+ //Identity identity = (Identity) cocoonSession.getAttribute(Identity.class.getName());
+
+ //init des valeurs "Ã l'ancienne" cad / sans authentification par le code
+ org.apache.cocoon.environment.Session cocoonSession = request.getSession();
+ Identity identity = (Identity) cocoonSession.getAttribute(Identity.class.getName());
+
+ try{
+ DefaultAccessController ac = getAccessController(pubName);
+ AccreditableManager acMgr = ac.getAccreditableManager();
+ User user = acMgr.getUserManager().getUser("lenya");
+
+ ac.setupIdentity(request);
+
+ cocoonSession = request.getSession();
+ identity = (Identity) cocoonSession.getAttribute(Identity.class.getName());
+
+ identity.addIdentifiable(user);
+ ac.authorize(request);
+ //cocoonSession.setIdentity(identity);
+ }
+ catch(AccessControlException ace){
+ throw new ProcessingException(ace);
+ }
+
+
+ //-- fin test implementation de l'identity
+
+ //create a session with the identity
+ Session session = RepositoryUtil.createSession(manager, identity, true);
+
+ // create the documentFactory
+ DocumentFactory factory = DocumentUtil.createDocumentFactory(this.manager, session);
+
+ // select the publication
+ Publication pub = factory.getPublication(pubName);
+ SiteStructure site = pub.getArea(Publication.AUTHORING_AREA).getSite();
+
+ DocumentManager docManager = null;
+ docManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
+
+ // Initialization of the resource type
+ // TODO : put this step in case of creation of document, the
+ // parameter can be null if this is a modification of the document,
+ // or a delete
+ ServiceSelector resourceTypeSelector = null;
+ resourceTypeSelector = (ServiceSelector) this.manager.lookup(ResourceType.ROLE + "Selector");
+ ResourceType type = (ResourceType) resourceTypeSelector.select(ressourceType);
+ ResourceType.Sample sample = type.getSample(type.getSampleNames()[0]);
+
+ /** manage the path of the document **/
+ int plus = 0;
+ String workpath = null;
+ // if the path is not null, this is the final path
+ if (path != null) {
+ workpath = new String(path);
+ }
+ else if (parentPath != null) {
+ // ------ TODO : remove trailing slash / if any
+ workpath = new String(parentPath);
+ // if pathname exist in the xml
+ if (pathName != null) {
+ workpath = workpath.concat("/").concat(new String(pathName));
+ } else {
+ // if the pathname is not specified, create him from the navtitle
+ // TODO ?? : a test for the null of the navtitle ??
+ // ==> YES
+ workpath = workpath.concat("/").concat(java.net.URLEncoder.encode(navTitle, "UTF-8"));
+ }
+ }
+
+ String finalpath = new String(workpath);
+ // TODO : have the result of ifexist attribute in order to know if
+ // the creation stop or continue
+ // by default the +1 system in selected
+ // ==> see the buildPath function's comments
+ //String finalpath = buildPath(path,parentPath,pathName);
+
+ //TODO : when we want to modify a document's navTitle.
+ String finalnavtitle = getNavTitle(navTitle);
+
+ // Search if the document exist,
+ // if the document exist
+ if (site.contains(finalpath) && site.getNode(finalpath).hasLink(language)) {
+ // then check the ifdocexist attribute : IfDocExistAttribute
+ // --- if the attribute is "create", the default value
+ if (IfDocExistAttribute.equals(IFDOCEXIST_CREATE_VALUE)) {
+ // code to deal with multiple document with the same name
+ // and the same parent
+ while (site.contains(finalpath) && site.getNode(finalpath).hasLink(language)) {
+ plus += 1;
+ finalpath = workpath.concat(String.valueOf(plus));
+ finalnavtitle = navTitle.concat(String.valueOf(plus));
+ }
+ // creation of the document
+ doc = docManager.add(factory, type, sample.getUri(), pub,
+ Publication.AUTHORING_AREA, finalpath, language,
+ "xml", finalnavtitle, true);
+
+ doc.setMimeType(sample.getMimeType());
+ }
+ // --- if the attribute is modify
+ else if (IfDocExistAttribute.equals(IFDOCEXIST_MODIFY_VALUE)) {
+ doc = site.getNode(finalpath).getLink(language).getDocument();
+
+ } else if (IfDocExistAttribute.equals(IFDOCEXIST_DELETE_VALUE)) {
+ // TODO : implement that : a first idea :
+ // documentManager.delete(document)
+ // ==> see impacts on the rest of the code, if the xml have
+ // a <content> section
+ // ?? create a variable like escape (true/false) that is
+ // true for delete and escape attribute and false otherwise
+ // ??
+ } else if (IfDocExistAttribute.equals(IFDOCEXIST_ESCAPE_VALUE)) {
+ escape = true;
+ doc = site.getNode(finalpath).getLink(language).getDocument();
+ // TODO : the solution of the escape variable (see preceding
+ // comment) ??
+ }
+
+ }
+ // if the document don't exist, creation
+ else {
+ doc = docManager.add(factory, type, sample.getUri(), pub,
+ Publication.AUTHORING_AREA, finalpath, language, "xml",
+ finalnavtitle, true);
+
+ doc.setMimeType(sample.getMimeType());
+ }
+
+ /** end of managing the name of the document node **/
+
+ // End initialization of document
+ }
+
+ /**
+ * simplification de toutes les exeptions... a voir pour faire plus
+ * propre...
+ */
+ catch (ServiceException e) {
+ getLogger().debug("ServiceExeption Error");
+ throw new ProcessingException(
+ "Error geting publication id / area from page envelope", e);
+
+ }
+ catch (java.io.UnsupportedEncodingException uee) {
+ getLogger().debug("URL encoding exception Error");
+ throw new ProcessingException(
+ "Problem during title URL encoding", uee);
+
+ }
+ catch (SiteException es) {
+ getLogger().debug("SiteException Error");
+ throw new ProcessingException(
+ "Error when retrieve the site", es);
+
+ } catch (DocumentBuildException ed) {
+ getLogger().debug("DocumentBuildException Error");
+ throw new ProcessingException(
+ "Error when building the document", ed);
+ } catch (PublicationException ep) {
+ getLogger().debug("PublicationException Error");
+ throw new ProcessingException(
+ "Error getting publication id from page envelope", ep);
+ } catch (RepositoryException er) {
+ getLogger().debug("PublicationException Error");
+ throw new ProcessingException(
+ "Error getting repository from page envelope", er);
+ }
+
+ // do this in a finally, clean up all catch
+ return doc;
+ }
+
+ //method for AC management
+ protected DefaultAccessController getAccessController(String pubId) {
+ DefaultAccessController controller;
+ try {
+ ServiceSelector accessControllerResolverSelector;
+ AccessControllerResolver accessControllerResolver;
+ accessControllerResolverSelector = (ServiceSelector) this.manager.lookup(
+ AccessControllerResolver.ROLE + "Selector");
+
+ accessControllerResolver = (AccessControllerResolver) accessControllerResolverSelector
+ .select(AccessControllerResolver.DEFAULT_RESOLVER);
+
+ getLogger().info(
+ "Using access controller resolver: ["
+ + accessControllerResolver.getClass() + "]");
+
+// Publication pub = getPublication(session, pubId);
+// getLogger().info("Resolve access controller");
+// getLogger().info(
+// "Publication directory: [" + pub.getDirectory().getAbsolutePath() + "]");
+
+ String url = "/" + pubId + "/authoring/index.html";
+ controller = (DefaultAccessController) ((PublicationAccessControllerResolver) accessControllerResolver)
+ .resolveAccessController(url);
+
+ getLogger().info("Resolved access controller: [" + controller.getClass() + "]");
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return controller;
+ }
+
+
+ /*
+ * TODO : build this function. Have to change the way the path is created in order to take care of ifdocexist
+ */
+ private String buildPath(String path, String parentPath, String pathName) {
+
+ return null;
+ }
+
+ private String getNavTitle(String navTitle) {
+ if (navTitle == null) {
+ navTitle = "Default Nav Title";;
+ }
+ return navTitle;
+ }
+
+ // write the fragment in the document. Allow modification of source document
+ // l'appel a cette fonction ne permet pas de modifier le contenu du
+ // document...
+ public void setLenyaDocContent(String contentpath, String replacePath,
+ DocumentFragment fragment) throws ProcessingException {
+ if (!escape){
+ modifyLenyaDocContent(contentpath,replacePath,fragment);
+ }
+ }
+
+ private void modifyLenyaDocContent(String contentpath, String replacePath,
+ DocumentFragment fragment) throws ProcessingException {
+ try {
+
+ if (contentpath == null) {
+ throw new ProcessingException(
+ "insertFragment: path is required.");
+ }
+ if (contentpath.startsWith("/")) {
+ contentpath = contentpath.substring(1);
+ }
+ if (fragment == null) {
+ throw new ProcessingException(
+ "insertFragment: fragment is required.");
+ }
+
+ // first: read the source as a DOM
+ Document resource = null;
+ //boolean failed = true;
+ //boolean exists = false;
+ String message = "";
+
+ if (true) {
+ message = "content inserted at: " + contentpath;
+
+ // resource = SourceUtil.toDOM(source);
+ // How to do without the namespace helper in order to be more
+ // generic ?
+ org.w3c.dom.Document xmlDocSource = DocumentHelper
+ .readDocument(lenyaDoc.getInputStream());
+ NamespaceHelper helper = new NamespaceHelper(
+ "http://www.w3.org/1999/xhtml", "xhtml", xmlDocSource);
+ resource = helper.getDocument();
+
+ // import the fragment
+ Node importNode = resource.importNode(fragment, true);
+ // reportResult("","tag importNODE","NAME = ",importNode.toString(),"STATE = ","");
+ // get the node
+ Node parent = DOMUtil.selectSingleNode(resource, contentpath,
+ this.xpathProcessor);
+ // reportResult("","PARENT","NAME = ",parent.toString(),"STATE = ","");
+
+ /******************************************************************************************
+ ***************************************************************************
+ ----------------- définition des variables a changer pour
+ * permettre le remplacement -----------
+ */
+ String reinsertPath = null;
+ boolean overwrite = true;
+
+ // replace?
+ //If replacePath don't exist in source tree, the fragment content is added as a last child of the parent
+ if (replacePath != null) {
+ try {
+ //BUG ATTR_SELECTION
+ //Attention : test a faire et pb a résoudre : cette méthode ne permet pas de sélectionner des nodes avec un attribut
+ //par exemple tr[@id='testid'] ne revoi pas de résultats.
+ //le retour est le même en utilisant directement la méthode selectSingleNode
+ Node replaceNode = DOMUtil.getSingleNode(parent, replacePath, this.xpathProcessor);
+ //Node replaceNode = this.xpathProcessor.selectSingleNode(parent, replacePath);
+ //Workaround TODO if not clean solution : use dom nodes impl. Only work for a single node in replacePath
+ /*if (replaceNode == null){
+ NodeList childlist = parent.getChildNodes();
+ replaceNodeName = replacePath.regex("...")
+ attrName = replacePath.regex("...")
+ attrValue= replacePath.regex("...")
+ for each node in childlist {
+ if node.nodeName = replaceNodeName and node.attrValue(attrName) = attrValue
+ then replaceNode = node;
+ }
+
+ }*/
+
+ // reportResult("","tag remplaceNODE DEBUT","NAME = ",replaceNode.toString(),"STATE = ","");
+ // now get the parent of this node until it is the
+ // parent node for insertion
+ while (replaceNode != null
+ && !replaceNode.getParentNode().equals(parent)) {
+ replaceNode = replaceNode.getParentNode();
+ }
+ // reportResult("","tag replaceNODE FIN","NAME = ",replaceNode.toString(),"STATE = ","");
+ if (replaceNode != null) {
+ if (overwrite) {
+ if (parent.getNodeType() == Node.DOCUMENT_NODE) {
+ // replacing of the document element is not
+ // allowed
+ resource = newDOMDocument();
+ resource.appendChild(resource.importNode(
+ importNode, true));
+ parent = resource;
+ replaceNode = resource.importNode(
+ replaceNode, true);
+ } else {
+ parent.replaceChild(importNode, replaceNode);
+ // reportResult("","tag REMPLACEMENT","NAME = ",importNode.toString(),"STATE = ","");
+ }
+ message += ", replacing: " + replacePath;
+ if (reinsertPath != null) {
+ Node insertAt = DOMUtil.getSingleNode(
+ parent, reinsertPath,
+ this.xpathProcessor);
+ if (insertAt != null) {
+ while (replaceNode.hasChildNodes()) {
+ insertAt.appendChild(replaceNode
+ .getFirstChild());
+ }
+ } else { // reinsert point null
+ message = "replace failed, could not find your reinsert path: "
+ + reinsertPath;
+ resource = null;
+ }
+ }
+ } else { // overwrite was false
+ message = "replace failed, no overwrite allowed.";
+ resource = null;
+ }
+ } else { // specified replaceNode was not found
+ parent.appendChild(importNode);
+ }
+ } catch (javax.xml.transform.TransformerException sax) {
+ throw new ProcessingException("TransformerException: "
+ + sax, sax);
+ }
+
+ } else { // no replace path, just do an insert at end
+ parent.appendChild(importNode);
+ }
+
+ // Create?
+ }
+
+ // write document
+ /***
+ * see the possibility to include a serializer choice for the
+ * document writing
+ **/
+ // this test is valuable ??
+ if (resource != null) {
+ // Write the dom content in the lenya Document
+ org.apache.lenya.cms.cocoon.source.SourceUtil.writeDOM(
+ resource, lenyaDoc.getOutputStream());
+ }
+ }
+
+ /**
+ * simplification de toutes les exeptions... a voir pour faire plus
+ * propre...
+ */
+ catch (ServiceException e) {
+ getLogger().debug("ServiceExeption Error");
+ throw new ProcessingException(
+ "Error geting publication id / area from page envelope", e);
+
+ }
+ catch (ParserConfigurationException pe) {
+ getLogger().debug("PublicationException Error");
+ throw new ProcessingException(
+ "Error geting publication id / area from page envelope", pe);
+ }
+ catch (javax.xml.transform.TransformerException sax) {
+ throw new ProcessingException("TransformerException: " + sax, sax);
+ } catch (SAXException e) {
+ throw new ProcessingException("TransformerException: " + e, e);
+ } catch (IOException e) {
+ throw new ProcessingException("TransformerException: " + e, e);
+ }
+
+ }
+
+
+ protected void commitLenyaDoc() throws ProcessingException {
+ // attention cette opération nécessite de prendre en compte une exeption
+ // en cas de modification concourrantes
+ // Write the document for this session
+ // TODO : see the Andreas mail and catch the error
+ // session.commit();
+ try {
+ if(!escape){
+ lenyaDoc.getRepositoryNode().getSession().commit();
+ }
+ // TODO : put an if and the treatment of the attribute
+ lenyaDocResult(lenyaDoc.getPath(), lenyaDoc.getUUID(), lenyaDoc.getName());
+ }
+ // ToDO : xml error response
+ catch (RepositoryException re) {
+ throw new ProcessingException("TransformerException: ", re);
+ } catch (ConcurrentModificationException ev) {
+ getLogger().debug("PublicationException Error");
+ throw new ProcessingException(
+ "Error geting publication id / area from page envelope", ev);
+ } catch (SAXException e) {
+ throw new ProcessingException(
+ "Error geting publication id / area from page envelope", e);
+ }
+ }
+
+ protected void applyWorkflowState() throws ProcessingException, SAXException {
+ //read document docs/workflow-invoker as this implementation don't ckeck role and permissions
+
+ String webappUrl = lenyaDoc.getCanonicalWebappURL();
+ String workflowUsecase = "workflow.";
+ if (workflowState.equals("submit") | workflowState.equals("publish") ){
+ executeUsecase(webappUrl, workflowUsecase.concat("submit"));
+ if (workflowState.equals("publish")){
+ executeUsecase(webappUrl, workflowUsecase.concat("publish"));
+ }
+ }
+ else{
+ reportResult("", "WARNING","worflowState not implemented", "This workflow state is still not implemented in the transformer.", "See function applyWorkflowState", "");
+ }
+
+ }
+
+ /**
+ * Execute a usecase, but with NO check of roles and permissions (see document docs/workflow-invoker for explanations)
+ * @param webappUrl
+ * @param usecaseName
+ * @throws RuntimeException
+ */
+ protected void executeUsecase(String webappUrl, String usecaseName)
+ throws RuntimeException {
+ // code come with modifications from
+ // src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/impl/UsecaseInvokerImpl.java
+ // public void invoke(String webappUrl, String usecaseName, Map
+ // parameters)
+
+ UsecaseResolver resolver = null;
+ Usecase usecase = null;
+ try {
+ resolver = (UsecaseResolver) this.manager
+ .lookup(UsecaseResolver.ROLE);
+ usecase = resolver.resolve(webappUrl, usecaseName);
+
+ usecase.checkPreconditions();
+
+ usecase.lockInvolvedObjects();
+ usecase.checkExecutionConditions();
+ usecase.execute();
+
+ usecase.checkPostconditions();
+
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (resolver != null) {
+ if (usecase != null) {
+ try {
+ resolver.release(usecase);
+ } catch (ServiceException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ this.manager.release(resolver);
+ }
+ }
+
+ }
+}
Added: lenya/contributions/2_0_X/modules/lenyaDocWriting/java/test/org/apache/lenya/transformation/WorkflowLenyaDocTranformerTest.java
URL: http://svn.apache.org/viewvc/lenya/contributions/2_0_X/modules/lenyaDocWriting/java/test/org/apache/lenya/transformation/WorkflowLenyaDocTranformerTest.java?rev=1176905&view=auto
==============================================================================
--- lenya/contributions/2_0_X/modules/lenyaDocWriting/java/test/org/apache/lenya/transformation/WorkflowLenyaDocTranformerTest.java (added)
+++ lenya/contributions/2_0_X/modules/lenyaDocWriting/java/test/org/apache/lenya/transformation/WorkflowLenyaDocTranformerTest.java Wed Sep 28 14:49:00 2011
@@ -0,0 +1,298 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+//package org.apache.lenya.modules.collection;
+package org.apache.lenya.transformation;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.lenya.ac.AccessControlException;
+import org.apache.lenya.ac.impl.AbstractAccessControlTest;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentBuildException;
+import org.apache.lenya.cms.publication.DocumentFactory;
+import org.apache.lenya.cms.publication.DocumentManager;
+import org.apache.lenya.cms.publication.DocumentUtil;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.cms.publication.ResourceType;
+import org.apache.lenya.cms.repository.Session;
+import org.apache.lenya.cms.site.SiteManager;
+import org.apache.lenya.cms.site.SiteStructure;
+import org.apache.lenya.transaction.TransactionException;
+
+//import for this test case
+import org.apache.lenya.ac.Identity;
+import org.apache.lenya.cms.repository.RepositoryUtil;
+
+//import for error management
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.cocoon.ProcessingException;
+import org.apache.excalibur.source.SourceException;
+import org.apache.lenya.cms.repository.RepositoryException;
+import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.cms.site.SiteException;
+import org.apache.lenya.cms.publication.DocumentBuildException;
+import org.apache.lenya.transaction.ConcurrentModificationException;
+import java.io.IOException;
+import org.apache.lenya.cms.usecase.UsecaseMessage;
+import org.apache.lenya.cms.usecase.UsecaseException;
+
+import org.apache.lenya.cms.usecase.UsecaseInvoker;
+import java.util.HashMap;
+import java.util.Map;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Arrays;
+
+/**
+ * publication workflow test.
+ */
+public class WorkflowLenyaDocTranformerTest extends AbstractAccessControlTest {
+
+
+ //global variable for document creation
+ private String pubname = "default";
+ private String language = "en";
+ private String existingpath = "/concepts";
+ private String finalpathDoc1 = "/concepts/docu1";
+ private String navTitleDoc1 = "docu1";
+ private String finalpathDoc2 = "/concepts/docu2";
+ private String navTitleDoc2 = "docu2";
+
+ //test for publishing an already existing document... work
+ public void testWorkflowOnExistingDoc(){
+
+ org.apache.lenya.cms.publication.Document lenyaDoc = null;
+
+ //nouvelle technique
+ try{
+ Session session = RepositoryUtil.getSession(getManager(), getRequest());
+ DocumentFactory factory = DocumentUtil.createDocumentFactory(getManager(), session);
+ //create the documentFactory
+
+ //select the publication
+ Publication pub = factory.getPublication(pubname);
+
+ SiteStructure site = pub.getArea(Publication.AUTHORING_AREA).getSite();
+
+ //publish an existing document
+ lenyaDoc = site.getNode(existingpath).getLink(language).getDocument();
+
+ applyWorkflowState("publish", lenyaDoc);
+ //end publishing an existing document
+ }
+ //TODO : a better try/catch machine (more precise errors)
+ // ?? some output for the test can be setting here ?
+ catch(Exception e){
+ //do nothing for now
+ }
+
+ }
+
+ public void testSubmitState(){
+
+ org.apache.lenya.cms.publication.Document lenyaDoc = null;
+ //create the lenyaDoc
+ try{
+ lenyaDoc = createLenyaDocument(pubname,"xhtml",finalpathDoc1,navTitleDoc1);
+ // applyWorkflowState("submit", lenyaDoc);
+ }
+ catch(IOException ioe){
+ //report error
+ }
+ catch(ProcessingException pe){
+ //err
+ }
+
+ }
+ /*
+ private void testPublishState(){
+ org.apache.lenya.cms.publication.Document lenyaDoc = null;
+ //create the lenyaDoc
+ try{
+ lenyaDoc = createLenyaDocument(pubname,"xhtml",finalpathDoc2,navTitleDoc2);
+ applyWorkflowState("publish", lenyaDoc);
+ }
+ catch(IOException ioe){
+ //report error
+ }
+ catch(ProcessingException pe){
+ //err
+ }
+
+ }
+ */
+ private void applyWorkflowState(String finalState, Document lenyaDoc)
+ throws ProcessingException{
+
+ try {
+ if (lenyaDoc == null){
+ // report a problem
+ //reportResult("","PROBLEM 34","NULL DOC PROBLEM","","","");
+ }
+ else {
+ if (finalState.equals("submit")|finalState.equals("publish")){
+ UsecaseInvoker invoker = null;
+
+ invoker = (UsecaseInvoker) getManager().lookup(UsecaseInvoker.ROLE);
+ Map params = new HashMap();
+
+ invoker.invoke(lenyaDoc.getCanonicalWebappURL(), "workflow.submit", params);
+
+ if (invoker.getResult() != UsecaseInvoker.SUCCESS) {
+ ///A REMETTRE
+ List messages = invoker.getErrorMessages();
+ for (Iterator i = messages.iterator(); i.hasNext();) {
+ UsecaseMessage message = (UsecaseMessage) i.next();
+ //!!!! report a problem
+ }
+ }
+
+ if (invoker != null) {
+ getManager().release(invoker);
+ }
+
+ //lenyaDoc.getRepositoryNode().getSession().commit();
+
+ }//fin du if finalState
+
+ if (finalState.equals("submit")|finalState.equals("publish")){
+
+ //---- deuxième invoker
+ UsecaseInvoker invoker2 = null;
+
+ invoker2 = (UsecaseInvoker) getManager().lookup(UsecaseInvoker.ROLE);
+ Map params2 = new HashMap();
+
+ invoker2.invoke(lenyaDoc.getCanonicalWebappURL(), "workflow.publish", params2);
+
+ //lenyaDoc.getRepositoryNode().getSession().commit();
+
+ if (invoker2.getResult() != UsecaseInvoker.SUCCESS) {
+ //A REMETTRE
+ List messages2 = invoker2.getErrorMessages();
+ for (Iterator i2 = messages2.iterator(); i2.hasNext();) {
+ UsecaseMessage message2 = (UsecaseMessage) i2.next();
+ //addErrorMessage(message2.getMessage(), message2.getParameters());
+ //reportResult("","PROBLEM","USECASE PROBLEM22",message2.getMessage(),Arrays.toString(message2.getParameters()),"");
+ }
+ }
+
+ if (invoker2 != null) {
+ getManager().release(invoker2);
+ }
+ }
+ }//fin du else
+ }
+ catch( ServiceException se){
+ //reportResult("","PROBLEM 2","ServiceException",se.getMessage(),"","");
+ }
+ catch (UsecaseException ue){
+ //reportResult("","PROBLEM 3","UsecaseException",ue.getMessage(),"","");
+ }
+
+
+ }
+
+ protected org.apache.lenya.cms.publication.Document createLenyaDocument(String pubname, String ressourceType, String finalpath, String finalnavtitle)
+ throws IOException, ProcessingException {
+
+ String language = "en";
+
+ org.apache.lenya.cms.publication.Document doc = null;
+
+ try{
+ org.apache.cocoon.environment.Session cocoonSession = getRequest().getSession();
+
+ Identity identity = (Identity) cocoonSession.getAttribute(Identity.class.getName());
+ Session session = RepositoryUtil.createSession(getManager(), identity, true);
+
+ //create the documentFactory
+ DocumentFactory factory = DocumentUtil.createDocumentFactory(getManager(), session);
+
+ //select the publication
+ Publication pub = factory.getPublication(pubname);
+
+ DocumentManager docManager = null;
+ ServiceSelector selector = null;
+ SiteManager siteManager = null;
+ ServiceSelector resourceTypeSelector = null;
+
+ docManager = (DocumentManager) getManager().lookup(DocumentManager.ROLE);
+
+ resourceTypeSelector = (ServiceSelector) getManager().lookup(
+ ResourceType.ROLE + "Selector");
+ ResourceType type = (ResourceType) resourceTypeSelector.select(ressourceType);
+
+ ResourceType.Sample sample = type.getSample(type.getSampleNames()[0]);
+
+ SiteStructure site = pub.getArea(Publication.AUTHORING_AREA).getSite();
+
+ doc = docManager.add(factory, type, sample.getUri(), pub,
+ Publication.AUTHORING_AREA,finalpath,
+ language, "xml",finalnavtitle,true);
+
+ doc.setMimeType(sample.getMimeType());
+ /** manage the name of the document node **/
+
+ try{
+ doc.getRepositoryNode().getSession().commit();
+ }
+ catch(ConcurrentModificationException cme){
+ //reportResult("","PROBLEM 5","Concurrent modification",cme.getMessage(),"","");
+ }
+
+ // End initialization of document
+ }
+
+ catch (ServiceException e)
+ {
+ getLogger().debug("ServiceExeption Error");
+ throw new ProcessingException("Error geting publication id / area from page envelope", e);
+
+ }
+
+ catch (SiteException es)
+ {
+ getLogger().debug("SiteException Error");
+ throw new ProcessingException("Error geting publication id / area from page envelope", es);
+
+ }
+ catch (DocumentBuildException ed)
+ {
+ getLogger().debug("DocumentBuildException Error");
+ throw new ProcessingException("Error geting publication id / area from page envelope", ed);
+ }
+ catch (PublicationException ep)
+ {
+ getLogger().debug("PublicationException Error");
+ throw new ProcessingException("Error geting publication id / area from page envelope", ep);
+ }
+ catch (RepositoryException er)
+ {
+ getLogger().debug("PublicationException Error");
+ throw new ProcessingException("Error geting publication id / area from page envelope", er);
+ }
+
+ //do this in a finally, clean up all catch
+ return doc;
+
+ //fin fonction
+ }
+
+}
Added: lenya/contributions/2_0_X/modules/lenyaDocWriting/java/test/procedure
URL: http://svn.apache.org/viewvc/lenya/contributions/2_0_X/modules/lenyaDocWriting/java/test/procedure?rev=1176905&view=auto
==============================================================================
--- lenya/contributions/2_0_X/modules/lenyaDocWriting/java/test/procedure (added)
+++ lenya/contributions/2_0_X/modules/lenyaDocWriting/java/test/procedure Wed Sep 28 14:49:00 2011
@@ -0,0 +1,6 @@
+
+test 1: publication d'un document existant
+test 2 : création d'un document et publicatoin 1
+test 3: création d'un document et publication 1 & 2
+
+test 4 : création d'un document... puis publication 1 et 2
Added: lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/addResource.xml
URL: http://svn.apache.org/viewvc/lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/addResource.xml?rev=1176905&view=auto
==============================================================================
--- lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/addResource.xml (added)
+++ lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/addResource.xml Wed Sep 28 14:49:00 2011
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<lenyadoc:lenyadoc xmlns:lenyadoc="http://4sengines/lenyadoc/0.1">
+
+ <lenyadoc:parameters>
+ <lenyadoc:resourcetype>resource</lenyadoc:resourcetype>
+ <lenyadoc:pubname>default</lenyadoc:pubname>
+ <lenyadoc:path>/tutorial</lenyadoc:path>
+ <lenyadoc:navtitle>pdfImport</lenyadoc:navtitle>
+ </lenyadoc:parameters>
+
+ <lenyadoc:content>
+ <!--<lenyadoc:file>samples/test.pdf</lenyadoc:file>-->
+ <lenyadoc:file>/home/florent/devel/dev-others/gasoil/versions/dev/lenya/tomcat/webapps/lenya/lenya/modules/lenyaDocWriting/samples/test.pdf</lenyadoc:file>
+ </lenyadoc:content>
+
+</lenyadoc:lenyadoc>
Added: lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/addxhtmlfile.xml
URL: http://svn.apache.org/viewvc/lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/addxhtmlfile.xml?rev=1176905&view=auto
==============================================================================
--- lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/addxhtmlfile.xml (added)
+++ lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/addxhtmlfile.xml Wed Sep 28 14:49:00 2011
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<lenyadoc:lenyadoc xmlns:lenyadoc="http://4sengines/lenyadoc/0.1" xmlns:xhtml="http://www.w3.org/1999/xhtml">
+
+ <lenyadoc:parameters>
+ <lenyadoc:resourcetype>xhtml</lenyadoc:resourcetype>
+ <lenyadoc:pubname>default</lenyadoc:pubname>
+ <lenyadoc:parentpath>/tutorial</lenyadoc:parentpath>
+ <lenyadoc:language>en</lenyadoc:language>
+ <lenyadoc:navtitle>Title of your new document</lenyadoc:navtitle>
+ </lenyadoc:parameters>
+ <!-- replace the body content of the default resource created -->
+ <lenyadoc:content>
+ <lenyadoc:contentpath>html</lenyadoc:contentpath>
+ <lenyadoc:replacepath>body</lenyadoc:replacepath>
+ <lenyadoc:fragment>
+ <xhtml:body>
+ <xhtml:p> here you have new content !! </xhtml:p>
+ </xhtml:body>
+ </lenyadoc:fragment>
+
+ </lenyadoc:content>
+
+</lenyadoc:lenyadoc>
Added: lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/hackaton-test.xml
URL: http://svn.apache.org/viewvc/lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/hackaton-test.xml?rev=1176905&view=auto
==============================================================================
--- lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/hackaton-test.xml (added)
+++ lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/hackaton-test.xml Wed Sep 28 14:49:00 2011
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<lenyadoc:lenyadoc xmlns:lenyadoc="http://4sengines/lenyadoc/0.1" xmlns:xhtml="http://www.w3.org/1999/xhtml">
+<lenyadoc:parameters>
+<lenyadoc:resourcetype>xhtml</lenyadoc:resourcetype>
+<lenyadoc:pubname>default</lenyadoc:pubname>
+<lenyadoc:parentpath>/tutorial</lenyadoc:parentpath>
+<lenyadoc:language>en</lenyadoc:language>
+<lenyadoc:navtitle>resta </lenyadoc:navtitle>
+</lenyadoc:parameters>
+<!-- replace the body content of the default resource created -->
+<lenyadoc:content>
+<lenyadoc:contentpath>html</lenyadoc:contentpath>
+<lenyadoc:replacepath>body</lenyadoc:replacepath>
+<lenyadoc:fragment>
+<xhtml:body>
+<xhtml:p>This is some content that will be editable with TinyMCE.</xhtml:p></xhtml:body>
+</lenyadoc:fragment>
+</lenyadoc:content>
+</lenyadoc:lenyadoc>
Added: lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/test.pdf
URL: http://svn.apache.org/viewvc/lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/test.pdf?rev=1176905&view=auto
==============================================================================
Binary file - no diff available.
Propchange: lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/test.pdf
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/xslt/autoDefinedPathName.xsl
URL: http://svn.apache.org/viewvc/lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/xslt/autoDefinedPathName.xsl?rev=1176905&view=auto
==============================================================================
--- lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/xslt/autoDefinedPathName.xsl (added)
+++ lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/xslt/autoDefinedPathName.xsl Wed Sep 28 14:49:00 2011
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
+ xmlns:col="http://apache.org/cocoon/lenya/collection/1.0"
+ xmlns:xhtml="http://www.w3.org/1999/xhtml"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:source="http://apache.org/cocoon/source/1.0"
+ xmlns:lenyadoc="http://4sengines/lenyadoc/0.1"
+ >
+
+ <xsl:param name="nomfichier" select="'defaultName'"/>
+
+
+ <xsl:template match="/">
+ <h1> test transformer </h1>
+
+ <lenyadoc:lenyadoc
+ xmlns:lenyadoc="http://4sengines/lenyadoc/0.1">
+
+ <lenyadoc:parameters>
+
+ <lenyadoc:pubname>default</lenyadoc:pubname>
+
+ <lenyadoc:parentpath>/tutorial</lenyadoc:parentpath>
+
+ <!-- pathname is automatically created from the navtitle -->
+ <lenyadoc:navtitle>PUBLICATION</lenyadoc:navtitle>
+ <lenyadoc:workflowstate>publish</lenyadoc:workflowstate>
+
+ </lenyadoc:parameters>
+ <!-- premier remplacement : h1 -->
+ <lenyadoc:content>
+ <lenyadoc:contentpath>html/body</lenyadoc:contentpath>
+ <lenyadoc:replacepath>h1</lenyadoc:replacepath>
+ <lenyadoc:fragment>
+ <xhtml:h3> remplacement REUSSI </xhtml:h3>
+ </lenyadoc:fragment>
+
+ </lenyadoc:content>
+
+ <!-- deuxieme remplacement p-->
+ <lenyadoc:content>
+ <lenyadoc:contentpath>html/body</lenyadoc:contentpath>
+ <!-- improve the tranformer in order to have a p[2]
+ replacepath working -->
+ <lenyadoc:replacepath>p</lenyadoc:replacepath>
+ <lenyadoc:fragment>
+ <xhtml:h2>here come NEW content de TEST !!</xhtml:h2>
+ </lenyadoc:fragment>
+ </lenyadoc:content>
+ </lenyadoc:lenyadoc>
+
+ <h1> FIN test transformer </h1>
+ </xsl:template>
+
+
+</xsl:stylesheet>
Added: lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/xslt/userDefinedPathName.xsl
URL: http://svn.apache.org/viewvc/lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/xslt/userDefinedPathName.xsl?rev=1176905&view=auto
==============================================================================
--- lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/xslt/userDefinedPathName.xsl (added)
+++ lenya/contributions/2_0_X/modules/lenyaDocWriting/samples/xslt/userDefinedPathName.xsl Wed Sep 28 14:49:00 2011
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
+ xmlns:col="http://apache.org/cocoon/lenya/collection/1.0"
+ xmlns:xhtml="http://www.w3.org/1999/xhtml"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:source="http://apache.org/cocoon/source/1.0"
+ xmlns:lenyadoc="http://4sengines/lenyadoc/0.1"
+ >
+
+ <xsl:param name="nomfichier" select="'defaultName'"/>
+
+
+ <xsl:template match="/">
+ <h1> test transformer </h1>
+
+ <lenyadoc:lenyadoc
+ xmlns:lenyadoc="http://4sengines/lenyadoc/0.1">
+
+ <lenyadoc:parameters>
+
+ <lenyadoc:pubname>dev</lenyadoc:pubname>
+ <lenyadoc:path>/tutorial/AUTOTRANSFORM</lenyadoc:path>
+ <lenyadoc:navtitle>AUTOTRANSFORM</lenyadoc:navtitle>
+
+ </lenyadoc:parameters>
+ <!-- premier remplacement : h1 -->
+ <lenyadoc:content>
+ <lenyadoc:contentpath>html/body</lenyadoc:contentpath>
+ <lenyadoc:replacepath>h1</lenyadoc:replacepath>
+ <lenyadoc:fragment>
+ <xhtml:h3> remplacement REUSSI </xhtml:h3>
+ </lenyadoc:fragment>
+
+ </lenyadoc:content>
+
+ <!-- deuxieme remplacement p-->
+ <lenyadoc:content>
+ <lenyadoc:contentpath>html/body</lenyadoc:contentpath>
+ <!-- improve the tranformer in order to have a p[2]
+ replacepath working -->
+ <lenyadoc:replacepath>p</lenyadoc:replacepath>
+ <lenyadoc:fragment>
+ <xhtml:h2>here come NEW content !!</xhtml:h2>
+ </lenyadoc:fragment>
+ </lenyadoc:content>
+ </lenyadoc:lenyadoc>
+
+ <h1> FIN test transformer </h1>
+ </xsl:template>
+
+
+</xsl:stylesheet>
Added: lenya/contributions/2_0_X/modules/lenyaDocWriting/sitemap.xmap
URL: http://svn.apache.org/viewvc/lenya/contributions/2_0_X/modules/lenyaDocWriting/sitemap.xmap?rev=1176905&view=auto
==============================================================================
--- lenya/contributions/2_0_X/modules/lenyaDocWriting/sitemap.xmap (added)
+++ lenya/contributions/2_0_X/modules/lenyaDocWriting/sitemap.xmap Wed Sep 28 14:49:00 2011
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
+ license agreements. See the NOTICE file distributed with this work for additional
+ information regarding copyright ownership. The ASF licenses this file to
+ You under the Apache License, Version 2.0 (the "License"); you may not use
+ this file except in compliance with the License. You may obtain a copy of
+ the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+ by applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ OF ANY KIND, either express or implied. See the License for the specific
+ language governing permissions and limitations under the License. -->
+
+<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
+
+ <map:components>
+ <map:transformers default="xslt">
+ <map:transformer logger="sitemap.transformer.lenyadoc-writing" name="lenyadoc-writing" src="org.apache.lenya.transformation.LenyaDocWritingTransformer" />
+ </map:transformers>
+ </map:components>
+
+
+ <map:pipelines>
+
+ <!-- pipeline for REST service -->
+ <map:pipeline type="noncaching">
+
+ <map:match pattern="create">
+ <map:generate src="{request-param:processing}"/>
+ <map:transform type="lenyadoc-writing">
+ <map:parameter name="serializer" value="xml" />
+ </map:transform>
+ <map:serialize type="xml" />
+ </map:match>
+
+ </map:pipeline>
+
+ <!-- pipeline for demonstration purpose -->
+ <map:pipeline type="noncaching">
+ <!-- to test it : http://SERVER-NAME/lenya/default/modules/lenyaDocWriting/testwriter
+ -->
+ <map:match pattern="testwriter">
+ <map:generate src="test/lanceur.xml" />
+ <map:transform src="samples/xslt/autoDefinedPathName.xsl" />
+ <map:transform type="lenyadoc-writing">
+ <map:parameter name="serializer" value="xml" />
+ </map:transform>
+ <map:serialize type="xml" />
+ </map:match>
+
+ <map:match pattern="addMedia">
+ <map:generate src="samples/addResource.xml" />
+ <map:transform type="lenyadoc-writing">
+ <map:parameter name="serializer" value="xml" />
+ </map:transform>
+ <map:serialize type="xml" />
+ </map:match>
+
+ <!-- create documents to reflect a directory listing -->
+
+ <map:match pattern="createRoot">
+ <!-- TODO : replace this cocoon call to the classic one -->
+ <!-- BUGGY to remember <map:generate src="cocoon:/getDirectoryListing"/> -->
+ <map:transform src="xslt/import/dir2lenyaDocTransformer.xsl">
+ <map:parameter name="basePath" value="{request-param:basePath}"/>
+ <map:parameter name="pubName" value="gasoil"/>
+ <map:parameter name="pubPath" value="/enovRepository"/>
+ </map:transform>
+
+ <map:transform type="lenyadoc-writing"/>
+
+ <map:serialize type="xml"/>
+ </map:match>
+
+ <!-- @TASK : a pipeline that create a document and a children of this
+ document -->
+
+ <!-- @TASK : apipeline that modify a just created document (the parent
+ of the precedent pipelie ? YES -->
+
+ </map:pipeline>
+
+ </map:pipelines>
+</map:sitemap>
Added: lenya/contributions/2_0_X/modules/lenyaDocWriting/test/lanceur.xml
URL: http://svn.apache.org/viewvc/lenya/contributions/2_0_X/modules/lenyaDocWriting/test/lanceur.xml?rev=1176905&view=auto
==============================================================================
--- lenya/contributions/2_0_X/modules/lenyaDocWriting/test/lanceur.xml (added)
+++ lenya/contributions/2_0_X/modules/lenyaDocWriting/test/lanceur.xml Wed Sep 28 14:49:00 2011
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<h1> affichage du lanceur </h1>
Added: lenya/contributions/2_0_X/modules/lenyaDocWriting/utils/lenyaDoc-templates.xsl
URL: http://svn.apache.org/viewvc/lenya/contributions/2_0_X/modules/lenyaDocWriting/utils/lenyaDoc-templates.xsl?rev=1176905&view=auto
==============================================================================
--- lenya/contributions/2_0_X/modules/lenyaDocWriting/utils/lenyaDoc-templates.xsl (added)
+++ lenya/contributions/2_0_X/modules/lenyaDocWriting/utils/lenyaDoc-templates.xsl Wed Sep 28 14:49:00 2011
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xhtml="http://www.w3.org/1999/xhtml"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:voc="http://apache.org/cocoon/lenya/vocabulary/1.0"
+ xmlns:col="http://apache.org/cocoon/lenya/collection/1.0"
+ xmlns:cal="http://apache.org/cocoon/lenya/4sengines/calendar/0.1"
+ xmlns:lenyadoc="http://4sengines/lenyadoc/0.1"
+ exclude-result-prefixes="xhtml col cal lenyadoc voc"
+ >
+
+
+
+ <!-- named template for create documents with no content -->
+ <xsl:template name="doc-template-no-content">
+ <!-- resourceType param can be suppress if xhtml, it's a default value for the transformer -->
+ <xsl:param name="resourceType">xhtml</xsl:param>
+ <xsl:param name="language">en</xsl:param>
+ <xsl:param name="navTitle"/>
+ <xsl:param name="parentPath"/>
+ <!-- TODO : supprimer cette notion de subparrent lorsque creation OK -->
+ <xsl:param name="subparent"/>
+
+ <lenyadoc:lenyadoc>
+
+ <lenyadoc:parameters ifdocexist="modify">
+
+ <lenyadoc:pubname><xsl:value-of select="$pubname"/></lenyadoc:pubname>
+
+ <lenyadoc:parentpath><xsl:value-of select="$parentPath"/><xsl:value-of select="$subparent"/></lenyadoc:parentpath>
+
+ <lenyadoc:resourcetype><xsl:value-of select="$resourceType"/></lenyadoc:resourcetype>
+
+ <lenyadoc:navtitle><xsl:value-of select="$navTitle"/></lenyadoc:navtitle>
+
+ <lenyadoc:language><xsl:value-of select="$language"/></lenyadoc:language>
+
+ </lenyadoc:parameters>
+ <!-- no content modification, so, end of definition file -->
+
+ </lenyadoc:lenyadoc>
+ </xsl:template>
+
+</xsl:stylesheet>