You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by so...@apache.org on 2008/03/08 23:59:02 UTC
svn commit: r635107 [2/7] - in /lenya/branches/revolution/1.3.x: ./
src/cocoon/ src/java/org/apache/cocoon/components/source/
src/java/org/apache/lenya/ac/ src/java/org/apache/lenya/ac/cache/
src/java/org/apache/lenya/ac/file/ src/java/org/apache/lenya...
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/MoveSiteTreeNodeTask.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/MoveSiteTreeNodeTask.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/MoveSiteTreeNodeTask.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/MoveSiteTreeNodeTask.java Sat Mar 8 14:58:32 2008
@@ -19,8 +19,8 @@
package org.apache.lenya.cms.ant;
-import org.apache.lenya.cms.publication.SiteTree;
import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.SiteTree;
import org.apache.tools.ant.BuildException;
/**
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/RemoveLabelTask.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/RemoveLabelTask.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/RemoveLabelTask.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/RemoveLabelTask.java Sat Mar 8 14:58:32 2008
@@ -19,8 +19,8 @@
package org.apache.lenya.cms.ant;
-import org.apache.lenya.cms.publication.SiteTree;
import org.apache.lenya.cms.publication.Label;
+import org.apache.lenya.cms.publication.SiteTree;
import org.apache.lenya.cms.publication.SiteTreeException;
import org.apache.lenya.cms.publication.SiteTreeNode;
import org.apache.tools.ant.BuildException;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/RenameLabelTask.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/RenameLabelTask.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/RenameLabelTask.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/RenameLabelTask.java Sat Mar 8 14:58:32 2008
@@ -19,9 +19,9 @@
package org.apache.lenya.cms.ant;
-import org.apache.lenya.cms.publication.SiteTree;
import org.apache.lenya.cms.publication.DocumentException;
import org.apache.lenya.cms.publication.Label;
+import org.apache.lenya.cms.publication.SiteTree;
import org.apache.lenya.cms.publication.SiteTreeException;
import org.apache.lenya.cms.publication.SiteTreeNode;
import org.apache.tools.ant.BuildException;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/ResourcePublisher.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/ResourcePublisher.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/ResourcePublisher.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/ResourcePublisher.java Sat Mar 8 14:58:32 2008
@@ -23,7 +23,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentBuilder;
import org.apache.lenya.cms.publication.Publication;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/StaticHTMLExporter.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/StaticHTMLExporter.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/StaticHTMLExporter.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/StaticHTMLExporter.java Sat Mar 8 14:58:32 2008
@@ -22,7 +22,6 @@
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
-
import org.apache.lenya.cms.publishing.ExportException;
import org.apache.tools.ant.BuildException;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/DefaultLeafCreator.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/DefaultLeafCreator.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/DefaultLeafCreator.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/DefaultLeafCreator.java Sat Mar 8 14:58:32 2008
@@ -20,7 +20,6 @@
package org.apache.lenya.cms.authoring;
import java.io.File;
-
import org.apache.lenya.cms.publication.Publication;
public class DefaultLeafCreator extends DefaultCreator {
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/ParentChildCreatorInterface.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/ParentChildCreatorInterface.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/ParentChildCreatorInterface.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/ParentChildCreatorInterface.java Sat Mar 8 14:58:32 2008
@@ -21,9 +21,7 @@
import java.io.File;
import java.util.Map;
-
import org.apache.avalon.framework.configuration.Configuration;
-
import org.apache.lenya.cms.publication.Publication;
public interface ParentChildCreatorInterface {
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/AbstractAuthorizerAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/AbstractAuthorizerAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/AbstractAuthorizerAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/AbstractAuthorizerAction.java Sat Mar 8 14:58:32 2008
@@ -21,7 +21,6 @@
import java.util.HashMap;
import java.util.Map;
-
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/AccessControlAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/AccessControlAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/AccessControlAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/AccessControlAction.java Sat Mar 8 14:58:32 2008
@@ -21,7 +21,6 @@
import java.util.Collections;
import java.util.Map;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.service.ServiceSelector;
import org.apache.cocoon.acting.ConfigurableServiceableAction;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DelegatingAuthenticatorAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DelegatingAuthenticatorAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DelegatingAuthenticatorAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DelegatingAuthenticatorAction.java Sat Mar 8 14:58:32 2008
@@ -21,7 +21,6 @@
import java.util.Collections;
import java.util.Map;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DelegatingAuthorizerAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DelegatingAuthorizerAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DelegatingAuthorizerAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DelegatingAuthorizerAction.java Sat Mar 8 14:58:32 2008
@@ -21,7 +21,6 @@
import java.util.Collections;
import java.util.Map;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DocumentIdExistsAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DocumentIdExistsAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DocumentIdExistsAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DocumentIdExistsAction.java Sat Mar 8 14:58:32 2008
@@ -14,14 +14,10 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.cocoon.acting;
-
import java.util.Collections;
import java.util.Map;
-
import org.apache.avalon.framework.parameters.ParameterException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.AbstractAction;
@@ -29,67 +25,52 @@
import org.apache.cocoon.environment.SourceResolver;
import org.apache.lenya.cms.publication.PageEnvelope;
import org.apache.lenya.cms.publication.PageEnvelopeException;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.SiteTree;
import org.apache.lenya.cms.publication.SiteTreeException;
-
/**
- * Action that checks the sitetree if there is a node with the
- * current document-id. This is used to prevent creation of documents
- * with non-unique document-ids
+ * Action that checks the sitetree if there is a node with the current document-id. This is used to prevent creation of documents with non-unique document-ids
*/
public class DocumentIdExistsAction extends AbstractAction {
-
- /**
- * Check if there is a doument in the site tree with the given
- * document-id and area [optional].
- *
- * If yes return an empty map, if not return null.
- *
- * @param redirector a <code>Redirector</code> value
- * @param resolver a <code>SourceResolver</code> value
- * @param objectModel a <code>Map</code> value
- * @param source a <code>String</code> value
- * @param parameters a <code>Parameters</code> value
- *
- * @return an empty <code>Map</code> if there is a document
- * with the given document-id and area [optional, default is
- * the authoring area], null otherwiese
- *
- * @exception PageEnvelopeException if the PageEnvelope could not be created.
- * @exception SiteTreeException if the site tree can not be accessed.
- * @exception ParameterException if the parameters can not be accessed.
- */
-
- public static final String DOCUMENT_ID_PARAMETER_NAME = "document-id";
- public static final String AREA_PARAMETER_NAME="area";
-
- public Map act(
- Redirector redirector,
- SourceResolver resolver,
- Map objectModel,
- String source,
- Parameters parameters)
- throws PageEnvelopeException, SiteTreeException, ParameterException{
-
- if (!parameters.isParameter(DOCUMENT_ID_PARAMETER_NAME))
- return null;
- String documentId = parameters.getParameter(DOCUMENT_ID_PARAMETER_NAME);
-
- /* Use authoring area as default area for backward compatibility. */
- String area = parameters.getParameter(AREA_PARAMETER_NAME, Publication.AUTHORING_AREA);
-
- PageEnvelope pageEnvelope =
- PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
-
- SiteTree siteTree =
- pageEnvelope.getPublication().getTree(area);
-
- if (siteTree.getNode(documentId) != null) {
- return Collections.EMPTY_MAP;
- } else {
- return null;
- }
- }
+ /**
+ * Check if there is a doument in the site tree with the given document-id and area [optional].
+ *
+ * If yes return an empty map, if not return null.
+ *
+ * @param redirector
+ * a <code>Redirector</code> value
+ * @param resolver
+ * a <code>SourceResolver</code> value
+ * @param objectModel
+ * a <code>Map</code> value
+ * @param source
+ * a <code>String</code> value
+ * @param parameters
+ * a <code>Parameters</code> value
+ *
+ * @return an empty <code>Map</code> if there is a document with the given document-id and area [optional, default is the authoring area], null otherwiese
+ *
+ * @exception PageEnvelopeException
+ * if the PageEnvelope could not be created.
+ * @exception SiteTreeException
+ * if the site tree can not be accessed.
+ * @exception ParameterException
+ * if the parameters can not be accessed.
+ */
+ public static final String DOCUMENT_ID_PARAMETER_NAME = "document-id";
+ public static final String AREA_PARAMETER_NAME = "area";
+ public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws PageEnvelopeException, SiteTreeException, ParameterException {
+ if(!parameters.isParameter(DOCUMENT_ID_PARAMETER_NAME))
+ return null;
+ String documentId = parameters.getParameter(DOCUMENT_ID_PARAMETER_NAME);
+ /* Use authoring area as default area for backward compatibility. */
+ String area = parameters.getParameter(AREA_PARAMETER_NAME, Publication.AUTHORING_AREA);
+ PageEnvelope pageEnvelope = PageEnvelope.getCurrent();
+ SiteTree siteTree = pageEnvelope.getPublication().getTree(area);
+ if(siteTree.getNode(documentId) != null){
+ return Collections.EMPTY_MAP;
+ }else{
+ return null;
+ }
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/FirstChildExistsAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/FirstChildExistsAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/FirstChildExistsAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/FirstChildExistsAction.java Sat Mar 8 14:58:32 2008
@@ -14,16 +14,12 @@
* limitations under the License.
*
*/
-
/* $Id: LanguageExistsAction.java 43248 2004-08-17 21:58:49Z michi $ */
-
package org.apache.lenya.cms.cocoon.acting;
-
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.AbstractAction;
import org.apache.cocoon.environment.Redirector;
@@ -36,82 +32,71 @@
import org.apache.lenya.cms.publication.NoChildDocumentExistException;
import org.apache.lenya.cms.publication.PageEnvelope;
import org.apache.lenya.cms.publication.PageEnvelopeException;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.SiteTree;
import org.apache.lenya.cms.publication.SiteTreeException;
import org.apache.lenya.cms.publication.SiteTreeNode;
-
/**
- * Action that checks the sitetree if there is a child document with the
- * current language.
+ * Action that checks the sitetree if there is a child document with the current language.
*/
public class FirstChildExistsAction extends AbstractAction {
-
-
- /**
- * Check if the current document-id has a child document for the
- * currently requested language.
- *
- * If yes return an empty map, if not return null.
- *
- * @param redirector a <code>Redirector</code> value
- * @param resolver a <code>SourceResolver</code> value
- * @param objectModel a <code>Map</code> value
- * @param source a <code>String</code> value
- * @param parameters a <code>Parameters</code> value
- *
- * @return an empty <code>Map</code> if there is a version of this
- * document for the current language, null otherwiese
- *
- * @exception DocumentDoesNotExistException if there is no document with the specified document-id.
- * @exception PageEnvelopeException if the PageEnvelope could not be created.
- * @exception DocumentException if the language information could not be fetched from the document.
- * @throws SiteTreeException if the sitetree couldn't be created
- * @throws DocumentBuildException if the DocumentBuilder couldn't be created
- */
- public Map act(
- Redirector redirector,
- SourceResolver resolver,
- Map objectModel,
- String source,
- Parameters parameters)
- throws PageEnvelopeException, DocumentDoesNotExistException, DocumentException, SiteTreeException, DocumentBuildException {
-
- PageEnvelope pageEnvelope =
- PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
- Publication publication = pageEnvelope.getPublication();
- String area = pageEnvelope.getDocument().getArea();
- String language = pageEnvelope.getDocument().getLanguage();
- String id = pageEnvelope.getDocument().getId();
-
- SiteTree siteTree = publication.getTree(area);
- SiteTreeNode node = siteTree.getNode(id);
-
- if (node == null) {
- throw new DocumentDoesNotExistException("The document " + pageEnvelope.getDocument().getId() + " does not exist. Check sitetree, it might need to be reloaded.");
- }
-
- SiteTreeNode[] children = node.getChildren(language);
- if (children.length > 0) {
-
- String childNodeId = children[0].getId();
- String childId = id + "/" + childNodeId;
- DocumentBuilder builder = publication.getDocumentBuilder();
- String url = builder.buildCanonicalUrl(publication, area, childId, language);
- Document childDocument = builder.buildDocument(publication, url);
-
- if (!childDocument.existsInAnyLanguage()) {
- throw new NoChildDocumentExistException("The document " + childId + " does not exist. Check sitetree, it might need to be reloaded.");
- }
- List availableLanguages = Arrays.asList(childDocument.getLanguages());
-
- if (availableLanguages.contains(language)) {
- return Collections.unmodifiableMap(Collections.EMPTY_MAP);
- }
- } else {
- throw new NoChildDocumentExistException("This document has no children. Check sitetree, it might need to be reloaded.");
- }
- return null;
- }
+ /**
+ * Check if the current document-id has a child document for the currently requested language.
+ *
+ * If yes return an empty map, if not return null.
+ *
+ * @param redirector
+ * a <code>Redirector</code> value
+ * @param resolver
+ * a <code>SourceResolver</code> value
+ * @param objectModel
+ * a <code>Map</code> value
+ * @param source
+ * a <code>String</code> value
+ * @param parameters
+ * a <code>Parameters</code> value
+ *
+ * @return an empty <code>Map</code> if there is a version of this document for the current language, null otherwiese
+ *
+ * @exception DocumentDoesNotExistException
+ * if there is no document with the specified document-id.
+ * @exception PageEnvelopeException
+ * if the PageEnvelope could not be created.
+ * @exception DocumentException
+ * if the language information could not be fetched from the document.
+ * @throws SiteTreeException
+ * if the sitetree couldn't be created
+ * @throws DocumentBuildException
+ * if the DocumentBuilder couldn't be created
+ */
+ public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws PageEnvelopeException, DocumentDoesNotExistException, DocumentException, SiteTreeException, DocumentBuildException {
+ PageEnvelope pageEnvelope = PageEnvelope.getCurrent();
+ Publication publication = pageEnvelope.getPublication();
+ String area = pageEnvelope.getDocument().getArea();
+ String language = pageEnvelope.getDocument().getLanguage();
+ String id = pageEnvelope.getDocument().getId();
+ SiteTree siteTree = publication.getTree(area);
+ SiteTreeNode node = siteTree.getNode(id);
+ if(node == null){
+ throw new DocumentDoesNotExistException("The document " + pageEnvelope.getDocument().getId() + " does not exist. Check sitetree, it might need to be reloaded.");
+ }
+ SiteTreeNode[] children = node.getChildren(language);
+ if(children.length > 0){
+ String childNodeId = children[0].getId();
+ String childId = id + "/" + childNodeId;
+ DocumentBuilder builder = publication.getDocumentBuilder();
+ String url = builder.buildCanonicalUrl(publication, area, childId, language);
+ Document childDocument = builder.buildDocument(publication, url);
+ if(!childDocument.existsInAnyLanguage()){
+ throw new NoChildDocumentExistException("The document " + childId + " does not exist. Check sitetree, it might need to be reloaded.");
+ }
+ List availableLanguages = Arrays.asList(childDocument.getLanguages());
+ if(availableLanguages.contains(language)){
+ return Collections.unmodifiableMap(Collections.EMPTY_MAP);
+ }
+ }else{
+ throw new NoChildDocumentExistException("This document has no children. Check sitetree, it might need to be reloaded.");
+ }
+ return null;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ForceCheckInAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ForceCheckInAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ForceCheckInAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ForceCheckInAction.java Sat Mar 8 14:58:32 2008
@@ -19,20 +19,18 @@
package org.apache.lenya.cms.cocoon.acting;
+import java.util.Date;
import java.util.HashMap;
import java.util.Map;
-import java.util.Date;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.Request;
-import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.environment.Session;
+import org.apache.cocoon.environment.SourceResolver;
import org.apache.lenya.ac.Identity;
-import org.apache.lenya.cms.cocoon.acting.RevisionControllerAction;
-import org.apache.lenya.cms.rc.CheckOutEntry;
import org.apache.lenya.cms.rc.CheckInEntry;
+import org.apache.lenya.cms.rc.CheckOutEntry;
import org.apache.lenya.cms.rc.RCML;
/**
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/HTMLFormSaveAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/HTMLFormSaveAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/HTMLFormSaveAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/HTMLFormSaveAction.java Sat Mar 8 14:58:32 2008
@@ -24,16 +24,14 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
-
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.acting.AbstractConfigurableAction;
@@ -45,11 +43,9 @@
import org.apache.lenya.xml.DocumentHelper;
import org.apache.lenya.xml.RelaxNG;
import org.apache.lenya.xml.XPath;
-
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-
import org.xmldb.common.xml.queries.XObject;
import org.xmldb.common.xml.queries.XPathQuery;
import org.xmldb.common.xml.queries.XPathQueryFactory;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/LanguageExistsAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/LanguageExistsAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/LanguageExistsAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/LanguageExistsAction.java Sat Mar 8 14:58:32 2008
@@ -14,16 +14,12 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.cocoon.acting;
-
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.AbstractAction;
import org.apache.cocoon.environment.Redirector;
@@ -33,56 +29,46 @@
import org.apache.lenya.cms.publication.DocumentException;
import org.apache.lenya.cms.publication.PageEnvelope;
import org.apache.lenya.cms.publication.PageEnvelopeException;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
-
/**
- * Action that checks the sitetree if there is a node with the
- * current document-id and the current language, i.e. if the
- * current document has a version in the current language.
+ * Action that checks the sitetree if there is a node with the current document-id and the current language, i.e. if the current document has a version in the current language.
*/
public class LanguageExistsAction extends AbstractAction {
-
- /**
- * Check if the current document-id has a document for the
- * currently requested language.
- *
- * If yes return an empty map, if not return null.
- *
- * @param redirector a <code>Redirector</code> value
- * @param resolver a <code>SourceResolver</code> value
- * @param objectModel a <code>Map</code> value
- * @param source a <code>String</code> value
- * @param parameters a <code>Parameters</code> value
- *
- * @return an empty <code>Map</code> if there is a version of this
- * document for the current language, null otherwiese
- *
- * @exception DocumentDoesNotExistException if there is no document with the specified document-id.
- * @exception PageEnvelopeException if the PageEnvelope could not be created.
- * @exception DocumentException if the language information could not be fetched from the document.
- */
- public Map act(
- Redirector redirector,
- SourceResolver resolver,
- Map objectModel,
- String source,
- Parameters parameters)
- throws PageEnvelopeException, DocumentDoesNotExistException, DocumentException {
-
- PageEnvelope pageEnvelope =
- PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
-
- Document doc = pageEnvelope.getDocument();
- String language = doc.getLanguage();
-
- if (!doc.existsInAnyLanguage()) {
- throw new DocumentDoesNotExistException("Document " + doc.getId() + " does not exist. Check sitetree, it might need to be reloaded.");
- }
- List availableLanguages = Arrays.asList(doc.getLanguages());
-
- if (availableLanguages.contains(language)) {
- return Collections.unmodifiableMap(Collections.EMPTY_MAP);
- }
- return null;
- }
+ /**
+ * Check if the current document-id has a document for the currently requested language.
+ *
+ * If yes return an empty map, if not return null.
+ *
+ * @param redirector
+ * a <code>Redirector</code> value
+ * @param resolver
+ * a <code>SourceResolver</code> value
+ * @param objectModel
+ * a <code>Map</code> value
+ * @param source
+ * a <code>String</code> value
+ * @param parameters
+ * a <code>Parameters</code> value
+ *
+ * @return an empty <code>Map</code> if there is a version of this document for the current language, null otherwiese
+ *
+ * @exception DocumentDoesNotExistException
+ * if there is no document with the specified document-id.
+ * @exception PageEnvelopeException
+ * if the PageEnvelope could not be created.
+ * @exception DocumentException
+ * if the language information could not be fetched from the document.
+ */
+ public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws PageEnvelopeException, DocumentDoesNotExistException, DocumentException {
+ PageEnvelope pageEnvelope = PageEnvelope.getCurrent();
+ Document doc = pageEnvelope.getDocument();
+ String language = doc.getLanguage();
+ if(!doc.existsInAnyLanguage()){
+ throw new DocumentDoesNotExistException("Document " + doc.getId() + " does not exist. Check sitetree, it might need to be reloaded.");
+ }
+ List availableLanguages = Arrays.asList(doc.getLanguages());
+ if(availableLanguages.contains(language)){
+ return Collections.unmodifiableMap(Collections.EMPTY_MAP);
+ }
+ return null;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ParentChildCreatorAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ParentChildCreatorAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ParentChildCreatorAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ParentChildCreatorAction.java Sat Mar 8 14:58:32 2008
@@ -19,13 +19,18 @@
package org.apache.lenya.cms.cocoon.acting;
+import java.io.File;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.avalon.framework.parameters.ParameterException;
import org.apache.avalon.framework.parameters.Parameters;
-
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.acting.AbstractComplementaryConfigurableAction;
import org.apache.cocoon.environment.ObjectModelHelper;
@@ -33,28 +38,16 @@
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.environment.SourceResolver;
-
import org.apache.excalibur.source.Source;
-
import org.apache.lenya.cms.authoring.ParentChildCreatorInterface;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationFactory;
-
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.XPath;
-
import org.dom4j.io.SAXReader;
-
-import java.io.File;
-
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
public class ParentChildCreatorAction extends AbstractComplementaryConfigurableAction
implements Configurable {
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckoutTestAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckoutTestAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckoutTestAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckoutTestAction.java Sat Mar 8 14:58:32 2008
@@ -21,7 +21,6 @@
import java.util.HashMap;
import java.util.Map;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ResourceExistsAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ResourceExistsAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ResourceExistsAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ResourceExistsAction.java Sat Mar 8 14:58:32 2008
@@ -22,7 +22,6 @@
import java.io.File;
import java.net.URL;
import java.util.Map;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.acting.ServiceableAction;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/RevisionControllerAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/RevisionControllerAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/RevisionControllerAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/RevisionControllerAction.java Sat Mar 8 14:58:32 2008
@@ -30,7 +30,6 @@
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentBuilder;
import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.rc.RCEnvironment;
import org.apache.lenya.cms.rc.RevisionController;
@@ -72,7 +71,7 @@
PageEnvelope envelope = null;
Publication publication = null;
try{
- envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
+ envelope = PageEnvelope.getCurrent();
publication = envelope.getPublication();
document = envelope.getDocument();
}catch(Exception e){
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/RollbackAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/RollbackAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/RollbackAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/RollbackAction.java Sat Mar 8 14:58:32 2008
@@ -22,7 +22,6 @@
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/TaskAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/TaskAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/TaskAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/TaskAction.java Sat Mar 8 14:58:32 2008
@@ -21,7 +21,6 @@
import java.util.HashMap;
import java.util.Map;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.AbstractAction;
import org.apache.cocoon.environment.ObjectModelHelper;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/URIParametrizerAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/URIParametrizerAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/URIParametrizerAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/URIParametrizerAction.java Sat Mar 8 14:58:32 2008
@@ -20,7 +20,6 @@
package org.apache.lenya.cms.cocoon.acting;
import java.util.Map;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.ConfigurableServiceableAction;
import org.apache.cocoon.environment.ObjectModelHelper;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/UploadAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/UploadAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/UploadAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/UploadAction.java Sat Mar 8 14:58:32 2008
@@ -16,7 +16,6 @@
*/
/* $Id$ */
package org.apache.lenya.cms.cocoon.acting;
-
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -29,7 +28,6 @@
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
-import org.apache.commons.io.FilenameUtils;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.AbstractConfigurableAction;
import org.apache.cocoon.environment.ObjectModelHelper;
@@ -37,198 +35,190 @@
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.servlet.multipart.Part;
+import org.apache.commons.io.FilenameUtils;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
import org.apache.lenya.cms.publication.ResourcesManager;
import org.apache.lenya.xml.DocumentHelper;
import org.apache.lenya.xml.NamespaceHelper;
import org.w3c.dom.Element;
-
/**
- * The class <code>UploadAction</code> implements an action that allows for
- * asset and content upload. An upload consists of a file upload plus optionally
- * a file creation for the meta data of the asset.
+ * The class <code>UploadAction</code> implements an action that allows for asset and content upload. An upload consists of a file upload plus optionally a file creation for the meta data of the asset.
*
* Also see org.apache.lenya.cms.authoring.UploadHelper
*/
public class UploadAction extends AbstractConfigurableAction {
- private Document document;
- private PageEnvelope pageEnvelope;
- public static final String UPLOADASSET_PARAM_NAME = "properties.asset.data";
- public static final String UPLOADASSET_PARAM_PREFIX = "properties.asset.";
- public static final String UPLOADASSET_RETURN_FILESIZE = "file-size";
- public static final String UPLOADASSET_RETURN_MIMETYPE = "mime-type";
- public static final String CONTENT_PREFIX = "content";
- public static final String FILE_NAME_REGEXP = "[-a-zA-Z0-9_.]+";
- // optional parameters for meta data according to dublin core
- public static final String[] DUBLIN_CORE_PARAMETERS = { "title", "creator", "subject", "description", "publisher", "contributor", "date", "type", "format", "identifier", "source", "language", "relation", "coverage", "rights" };
- /**
- * Retrieve the file from the request and store it in the corresponding
- * directory, optionally create a meta file and optionally insert an image
- * tag in the requesting document.
- *
- * @param redirector
- * a <code>Redirector</code> value
- * @param resolver
- * a <code>SourceResolver</code> value
- * @param objectModel
- * a <code>Map</code> value
- * @param source
- * a <code>String</code> value
- * @param parameters
- * a <code>Parameters</code> value
- *
- * @return a <code>Map</code> containing the referer or null if the name
- * of the file to be uploaded contains characters that are not
- * allowed (@see FILE_NAME_REGEXP).
- *
- * @exception Exception
- * if an error occurs
- */
- public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception {
- Map results = new HashMap();
- Request request = ObjectModelHelper.getRequest(objectModel);
- pageEnvelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
- document = pageEnvelope.getDocument();
- File assetFile;
- logRequestParameters(request);
- // determine if the upload is an asset or a content upload
- String uploadType = request.getParameter("uploadtype");
- // make asset upload the default if it is not specified
- if (uploadType == null) {
- uploadType = "asset";
- }
- Map dublinCoreParams = getDublinCoreParameters(request);
- // upload the file to the uploadDir
- Part part = (Part) request.get(UPLOADASSET_PARAM_NAME);
- String fileName = part.getFileName();
- if (!fileName.matches(FILE_NAME_REGEXP) || FilenameUtils.getExtension(fileName).equals("")) {
- // the file name contains characters which mean trouble
- // and are therefore not allowed.
- getLogger().warn("The filename [" + fileName + "]Â is not valid for an asset.");
- return null;
- }
- // convert spaces in the file name to underscores
- fileName = fileName.replace(' ', '_');
- String mimeType = part.getMimeType();
- int fileSize = part.getSize();
- results.put(UPLOADASSET_RETURN_MIMETYPE, mimeType);
- results.put(UPLOADASSET_RETURN_FILESIZE, new Integer(fileSize));
- dublinCoreParams.put("format", mimeType);
- dublinCoreParams.put("extent", Integer.toString(fileSize));
- if (uploadType.equals("asset")) {
- ResourcesManager resourcesMgr = new ResourcesManager(document);
- assetFile = new File(resourcesMgr.getPath(), fileName);
- if (!resourcesMgr.getPath().exists()) {
- resourcesMgr.getPath().mkdirs();
- }
- // create an extra file containing the meta description for
- // the asset.
- File metaDataFile = new File(resourcesMgr.getPath(), fileName + ".meta");
- createMetaData(metaDataFile, dublinCoreParams);
- }
- // must be a content upload then
- else {
- assetFile = new File(document.getFile().getParent(), fileName);
- getLogger().debug("assetFile: " + assetFile);
- }
- saveAsset(assetFile, part);
- return Collections.unmodifiableMap(results);
- }
- /**
- * Saves the asset to a file.
- *
- * @param assetFile
- * The asset file.
- * @param part
- * The part of the multipart request.
- * @throws Exception
- * if an error occurs.
- */
- protected void saveAsset(File assetFile, Part part) throws Exception {
- if (!assetFile.exists()) {
- boolean created = assetFile.createNewFile();
- if (!created) {
- throw new RuntimeException("The file [" + assetFile + "]Â could not be created.");
- }
- }
- byte[] buf = new byte[4096];
- FileOutputStream out = new FileOutputStream(assetFile);
- try {
- InputStream in = part.getInputStream();
- int read = in.read(buf);
- while (read > 0) {
- out.write(buf, 0, read);
- read = in.read(buf);
- }
- } finally {
- out.close();
- }
- }
- /**
- * Logs the request parameters.
- *
- * @param request
- * The request.
- */
- protected void logRequestParameters(Request request) {
- for (Enumeration myenum = request.getParameterNames(); myenum.hasMoreElements();) {
- String param = (String) myenum.nextElement();
- getLogger().debug(param + ": " + request.getParameter(param) + " [" + request.get(param) + "]");
- }
- }
- /**
- * Retrieves optional parameters for the meta file which contains dublin
- * core information from the request.
- *
- * @param request
- * The request.
- * @return A map.
- */
- protected Map getDublinCoreParameters(Request request) {
- HashMap dublinCoreParams = new HashMap();
- for (int i = 0; i < DUBLIN_CORE_PARAMETERS.length; i++) {
- String paramName = DUBLIN_CORE_PARAMETERS[i];
- String paramValue = request.getParameter(UPLOADASSET_PARAM_PREFIX + paramName);
- if (paramValue == null) {
- paramValue = "";
- }
- dublinCoreParams.put(paramName, paramValue);
- }
- Iterator iter = dublinCoreParams.keySet().iterator();
- while (iter.hasNext()) {
- String paramName = (String) iter.next();
- getLogger().debug(paramName + ": " + dublinCoreParams.get(paramName));
- }
- return dublinCoreParams;
- }
- /**
- * Create the meta data file given the dublin core parameters.
- *
- * @param metaDataFile
- * the file where the meta data file is to be created
- * @param dublinCoreParams
- * a <code>Map</code> containing the dublin core values
- * @throws TransformerConfigurationException
- * if an error occurs.
- * @throws TransformerException
- * if an error occurs.
- * @throws IOException
- * if an error occurs
- * @throws ParserConfigurationException
- * if an error occurs.
- */
- protected void createMetaData(File metaDataFile, Map dublinCoreParams) throws TransformerConfigurationException, TransformerException, IOException, ParserConfigurationException {
- // assert (metaDataFile.getParentFile().exists());
- NamespaceHelper helper = new NamespaceHelper("http://purl.org/dc/elements/1.1/", "dc", "metadata");
- Element root = helper.getDocument().getDocumentElement();
- Iterator iter = dublinCoreParams.keySet().iterator();
- while (iter.hasNext()) {
- String tagName = (String) iter.next();
- String tagValue = (String) dublinCoreParams.get(tagName);
- root.appendChild(helper.createElement(tagName, tagValue));
- }
- DocumentHelper.writeDocument(helper.getDocument(), metaDataFile);
- }
+ private Document document;
+ private PageEnvelope pageEnvelope;
+ public static final String UPLOADASSET_PARAM_NAME = "properties.asset.data";
+ public static final String UPLOADASSET_PARAM_PREFIX = "properties.asset.";
+ public static final String UPLOADASSET_RETURN_FILESIZE = "file-size";
+ public static final String UPLOADASSET_RETURN_MIMETYPE = "mime-type";
+ public static final String CONTENT_PREFIX = "content";
+ public static final String FILE_NAME_REGEXP = "[-a-zA-Z0-9_.]+";
+ // optional parameters for meta data according to dublin core
+ public static final String[] DUBLIN_CORE_PARAMETERS = {"title", "creator", "subject", "description", "publisher", "contributor", "date", "type", "format", "identifier", "source", "language", "relation", "coverage", "rights"};
+ /**
+ * Retrieve the file from the request and store it in the corresponding directory, optionally create a meta file and optionally insert an image tag in the requesting document.
+ *
+ * @param redirector
+ * a <code>Redirector</code> value
+ * @param resolver
+ * a <code>SourceResolver</code> value
+ * @param objectModel
+ * a <code>Map</code> value
+ * @param source
+ * a <code>String</code> value
+ * @param parameters
+ * a <code>Parameters</code> value
+ *
+ * @return a <code>Map</code> containing the referer or null if the name of the file to be uploaded contains characters that are not allowed (@see FILE_NAME_REGEXP).
+ *
+ * @exception Exception
+ * if an error occurs
+ */
+ public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception {
+ Map results = new HashMap();
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ pageEnvelope = PageEnvelope.getCurrent();
+ document = pageEnvelope.getDocument();
+ File assetFile;
+ logRequestParameters(request);
+ // determine if the upload is an asset or a content upload
+ String uploadType = request.getParameter("uploadtype");
+ // make asset upload the default if it is not specified
+ if(uploadType == null){
+ uploadType = "asset";
+ }
+ Map dublinCoreParams = getDublinCoreParameters(request);
+ // upload the file to the uploadDir
+ Part part = (Part) request.get(UPLOADASSET_PARAM_NAME);
+ String fileName = part.getFileName();
+ if(!fileName.matches(FILE_NAME_REGEXP) || FilenameUtils.getExtension(fileName).equals("")){
+ // the file name contains characters which mean trouble
+ // and are therefore not allowed.
+ getLogger().warn("The filename [" + fileName + "]Â is not valid for an asset.");
+ return null;
+ }
+ // convert spaces in the file name to underscores
+ fileName = fileName.replace(' ', '_');
+ String mimeType = part.getMimeType();
+ int fileSize = part.getSize();
+ results.put(UPLOADASSET_RETURN_MIMETYPE, mimeType);
+ results.put(UPLOADASSET_RETURN_FILESIZE, new Integer(fileSize));
+ dublinCoreParams.put("format", mimeType);
+ dublinCoreParams.put("extent", Integer.toString(fileSize));
+ if(uploadType.equals("asset")){
+ ResourcesManager resourcesMgr = new ResourcesManager(document);
+ assetFile = new File(resourcesMgr.getPath(), fileName);
+ if(!resourcesMgr.getPath().exists()){
+ resourcesMgr.getPath().mkdirs();
+ }
+ // create an extra file containing the meta description for
+ // the asset.
+ File metaDataFile = new File(resourcesMgr.getPath(), fileName + ".meta");
+ createMetaData(metaDataFile, dublinCoreParams);
+ }
+ // must be a content upload then
+ else{
+ assetFile = new File(document.getFile().getParent(), fileName);
+ getLogger().debug("assetFile: " + assetFile);
+ }
+ saveAsset(assetFile, part);
+ return Collections.unmodifiableMap(results);
+ }
+ /**
+ * Saves the asset to a file.
+ *
+ * @param assetFile
+ * The asset file.
+ * @param part
+ * The part of the multipart request.
+ * @throws Exception
+ * if an error occurs.
+ */
+ protected void saveAsset(File assetFile, Part part) throws Exception {
+ if(!assetFile.exists()){
+ boolean created = assetFile.createNewFile();
+ if(!created){
+ throw new RuntimeException("The file [" + assetFile + "]Â could not be created.");
+ }
+ }
+ byte[] buf = new byte[4096];
+ FileOutputStream out = new FileOutputStream(assetFile);
+ try{
+ InputStream in = part.getInputStream();
+ int read = in.read(buf);
+ while(read > 0){
+ out.write(buf, 0, read);
+ read = in.read(buf);
+ }
+ }finally{
+ out.close();
+ }
+ }
+ /**
+ * Logs the request parameters.
+ *
+ * @param request
+ * The request.
+ */
+ protected void logRequestParameters(Request request) {
+ for(Enumeration myenum = request.getParameterNames(); myenum.hasMoreElements();){
+ String param = (String) myenum.nextElement();
+ getLogger().debug(param + ": " + request.getParameter(param) + " [" + request.get(param) + "]");
+ }
+ }
+ /**
+ * Retrieves optional parameters for the meta file which contains dublin core information from the request.
+ *
+ * @param request
+ * The request.
+ * @return A map.
+ */
+ protected Map getDublinCoreParameters(Request request) {
+ HashMap dublinCoreParams = new HashMap();
+ for(int i = 0; i < DUBLIN_CORE_PARAMETERS.length; i++){
+ String paramName = DUBLIN_CORE_PARAMETERS[i];
+ String paramValue = request.getParameter(UPLOADASSET_PARAM_PREFIX + paramName);
+ if(paramValue == null){
+ paramValue = "";
+ }
+ dublinCoreParams.put(paramName, paramValue);
+ }
+ Iterator iter = dublinCoreParams.keySet().iterator();
+ while(iter.hasNext()){
+ String paramName = (String) iter.next();
+ getLogger().debug(paramName + ": " + dublinCoreParams.get(paramName));
+ }
+ return dublinCoreParams;
+ }
+ /**
+ * Create the meta data file given the dublin core parameters.
+ *
+ * @param metaDataFile
+ * the file where the meta data file is to be created
+ * @param dublinCoreParams
+ * a <code>Map</code> containing the dublin core values
+ * @throws TransformerConfigurationException
+ * if an error occurs.
+ * @throws TransformerException
+ * if an error occurs.
+ * @throws IOException
+ * if an error occurs
+ * @throws ParserConfigurationException
+ * if an error occurs.
+ */
+ protected void createMetaData(File metaDataFile, Map dublinCoreParams) throws TransformerConfigurationException, TransformerException, IOException, ParserConfigurationException {
+ // assert (metaDataFile.getParentFile().exists());
+ NamespaceHelper helper = new NamespaceHelper("http://purl.org/dc/elements/1.1/", "dc", "metadata");
+ Element root = helper.getDocument().getDocumentElement();
+ Iterator iter = dublinCoreParams.keySet().iterator();
+ while(iter.hasNext()){
+ String tagName = (String) iter.next();
+ String tagValue = (String) dublinCoreParams.get(tagName);
+ root.appendChild(helper.createElement(tagName, tagValue));
+ }
+ DocumentHelper.writeDocument(helper.getDocument(), metaDataFile);
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/WorkflowInvokerAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/WorkflowInvokerAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/WorkflowInvokerAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/WorkflowInvokerAction.java Sat Mar 8 14:58:32 2008
@@ -16,7 +16,6 @@
*/
/* $Id$ */
package org.apache.lenya.cms.cocoon.acting;
-
import java.util.Collections;
import java.util.Map;
import org.apache.avalon.framework.parameters.Parameters;
@@ -27,16 +26,13 @@
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentBuilder;
import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.workflow.WorkflowFactory;
import org.apache.lenya.workflow.Event;
import org.apache.lenya.workflow.Situation;
import org.apache.lenya.workflow.SynchronizedWorkflowInstances;
-
/**
- * Action to invoke a workflow transition independently from the request
- * document URL. Parameters:
+ * Action to invoke a workflow transition independently from the request document URL. Parameters:
* <ul>
* <li><strong>area:</strong> The area.</li>
* <li><strong>document-id:</strong> The document id.</li>
@@ -45,53 +41,51 @@
* </ul>
*/
public class WorkflowInvokerAction extends AbstractAction {
- public static final String AREA = "area";
- public static final String DOCUMENT_ID = "document-id";
- public static final String LANGUAGE = "language";
- public static final String EVENT = "event";
- /**
- * @see org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector,
- * org.apache.cocoon.environment.SourceResolver, java.util.Map,
- * java.lang.String, org.apache.avalon.framework.parameters.Parameters)
- */
- public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception {
- String area = parameters.getParameter(AREA);
- String documentId = parameters.getParameter(DOCUMENT_ID);
- String language = parameters.getParameter(LANGUAGE);
- String eventName = parameters.getParameter(EVENT);
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(getClass().getName() + " invoked.");
- getLogger().debug(" Area: [" + area + "]");
- getLogger().debug(" Document ID: [" + documentId + "]");
- getLogger().debug(" Language: [" + language + "]");
- getLogger().debug(" Event: [" + eventName + "]");
- }
- PageEnvelope envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
- Publication publication = envelope.getPublication();
- DocumentBuilder builder = publication.getDocumentBuilder();
- String url = builder.buildCanonicalUrl(publication, area, documentId, language);
- Document document = builder.buildDocument(publication, url);
- WorkflowFactory factory = WorkflowFactory.newInstance();
- if (factory.hasWorkflow(document)) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(" Invoking workflow event");
+ public static final String AREA = "area";
+ public static final String DOCUMENT_ID = "document-id";
+ public static final String LANGUAGE = "language";
+ public static final String EVENT = "event";
+ /**
+ * @see org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector, org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
+ */
+ public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception {
+ String area = parameters.getParameter(AREA);
+ String documentId = parameters.getParameter(DOCUMENT_ID);
+ String language = parameters.getParameter(LANGUAGE);
+ String eventName = parameters.getParameter(EVENT);
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug(getClass().getName() + " invoked.");
+ getLogger().debug(" Area: [" + area + "]");
+ getLogger().debug(" Document ID: [" + documentId + "]");
+ getLogger().debug(" Language: [" + language + "]");
+ getLogger().debug(" Event: [" + eventName + "]");
+ }
+ PageEnvelope envelope = PageEnvelope.getCurrent();
+ Publication publication = envelope.getPublication();
+ DocumentBuilder builder = publication.getDocumentBuilder();
+ String url = builder.buildCanonicalUrl(publication, area, documentId, language);
+ Document document = builder.buildDocument(publication, url);
+ WorkflowFactory factory = WorkflowFactory.newInstance();
+ if(factory.hasWorkflow(document)){
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug(" Invoking workflow event");
+ }
+ SynchronizedWorkflowInstances instance = factory.buildSynchronizedInstance(document);
+ Situation situation = WorkflowHelper.buildSituation(objectModel);
+ Event[] events = instance.getExecutableEvents(situation);
+ Event event = null;
+ for(int i = 0; i < events.length; i++){
+ if(events[i].getName().equals(eventName)){
+ event = events[i];
}
- SynchronizedWorkflowInstances instance = factory.buildSynchronizedInstance(document);
- Situation situation = WorkflowHelper.buildSituation(objectModel);
- Event[] events = instance.getExecutableEvents(situation);
- Event event = null;
- for (int i = 0; i < events.length; i++) {
- if (events[i].getName().equals(eventName)) {
- event = events[i];
- }
- }
- // assert event != null;
- instance.invoke(situation, event);
- } else {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(" Document has no workflow.");
- }
- }
- return Collections.EMPTY_MAP;
- }
+ }
+ // assert event != null;
+ instance.invoke(situation, event);
+ }else{
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug(" Document has no workflow.");
+ }
+ }
+ return Collections.EMPTY_MAP;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/XopusHandlerAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/XopusHandlerAction.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/XopusHandlerAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/XopusHandlerAction.java Sat Mar 8 14:58:32 2008
@@ -24,8 +24,7 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-
-import org.apache.commons.io.FileUtils;
+import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.parameters.Parameters;
@@ -39,6 +38,7 @@
import org.apache.cocoon.environment.http.HttpRequest;
import org.apache.cocoon.util.IOUtils;
import org.apache.cocoon.util.PostInputStream;
+import org.apache.commons.io.FileUtils;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.xml.dom.DOMParser;
import org.apache.lenya.ac.Identity;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AccessControlModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AccessControlModule.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AccessControlModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AccessControlModule.java Sat Mar 8 14:58:32 2008
@@ -22,7 +22,6 @@
import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
-
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.service.ServiceException;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java Sat Mar 8 14:58:32 2008
@@ -14,75 +14,62 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.cocoon.components.modules.input;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentException;
import org.apache.lenya.cms.publication.DublinCoreImpl;
-
+import org.apache.lenya.cms.publication.PageEnvelope;
+import org.apache.lenya.cms.publication.PageEnvelopeException;
/**
* Input module to access the dublin core values.
*/
public class DublinCoreModule extends AbstractPageEnvelopeModule {
-
- /**
- * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
- */
- public Object getAttribute(String name, Configuration modeConf, Map objectModel)
- throws ConfigurationException {
-
- if (!Arrays.asList(DublinCoreImpl.ELEMENTS).contains(name)
- && !Arrays.asList(DublinCoreImpl.TERMS).contains(name)) {
- throw new ConfigurationException("The attribute [" + name + "] is not supported!");
- }
-
- Document document = getEnvelope(objectModel).getDocument();
-
- if (document == null) {
- throw new ConfigurationException("There is no document for this page envelope!");
- }
- Object value;
- try {
- value = document.getDublinCore().getFirstValue(name);
- } catch (DocumentException e) {
- throw new ConfigurationException(
- "Obtaining dublin core value for [" + name + "] failed: ",
- e);
- }
-
- return value;
- }
-
- /**
- * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
- */
- public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
- throws ConfigurationException {
-
- List names = new ArrayList();
- names.addAll(Arrays.asList(DublinCoreImpl.ELEMENTS));
- names.addAll(Arrays.asList(DublinCoreImpl.TERMS));
- return names.iterator();
- }
-
- /**
- * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
- */
- public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
- throws ConfigurationException {
- Object[] objects = { getAttribute(name, modeConf, objectModel)};
- return objects;
- }
-
+ /**
+ * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ */
+ public Object getAttribute(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
+ if(!Arrays.asList(DublinCoreImpl.ELEMENTS).contains(name) && !Arrays.asList(DublinCoreImpl.TERMS).contains(name)){
+ throw new ConfigurationException("The attribute [" + name + "] is not supported!");
+ }
+ Document document;
+ try{
+ document = PageEnvelope.getCurrent().getDocument();
+ }catch(PageEnvelopeException e1){
+ throw new ConfigurationException("Resolving page envelope failed: ", e1);
+ }
+ if(document == null){
+ throw new ConfigurationException("There is no document for this page envelope!");
+ }
+ Object value;
+ try{
+ value = document.getDublinCore().getFirstValue(name);
+ }catch(DocumentException e){
+ throw new ConfigurationException("Obtaining dublin core value for [" + name + "] failed: ", e);
+ }
+ return value;
+ }
+ /**
+ * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ */
+ public Iterator getAttributeNames(Configuration modeConf, Map objectModel) throws ConfigurationException {
+ List names = new ArrayList();
+ names.addAll(Arrays.asList(DublinCoreImpl.ELEMENTS));
+ names.addAll(Arrays.asList(DublinCoreImpl.TERMS));
+ return names.iterator();
+ }
+ /**
+ * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ */
+ public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
+ Object[] objects = {getAttribute(name, modeConf, objectModel)};
+ return objects;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java Sat Mar 8 14:58:32 2008
@@ -25,7 +25,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.service.ServiceException;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyUrlModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyUrlModule.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyUrlModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyUrlModule.java Sat Mar 8 14:58:32 2008
@@ -15,17 +15,15 @@
*
*/
package org.apache.lenya.cms.cocoon.components.modules.input;
-
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
-
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.components.modules.input.AbstractInputModule;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
@@ -40,10 +38,8 @@
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentBuilder;
import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
import org.apache.lenya.cms.publication.Proxy;
import org.apache.lenya.cms.publication.Publication;
-
/**
* Input module for getting the proxied URL of a document.
*
@@ -52,118 +48,86 @@
* </p>
*
* <p>
- * If there are no proxy settings in the file conf/publication.xconf, the values of the request
- * parameters 'server name' and 'port' will be used to construct the URL.
+ * If there are no proxy settings in the file conf/publication.xconf, the values of the request parameters 'server name' and 'port' will be used to construct the URL.
* </p>
*
* @version $Id:$
*/
public class ProxyUrlModule extends AbstractInputModule implements Serviceable {
-
- private ServiceManager manager;
-
- /**
- * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String,
- * org.apache.avalon.framework.configuration.Configuration, java.util.Map)
- */
- public Object getAttribute(String name, Configuration modeConf, Map objectModel)
- throws ConfigurationException {
-
- ServiceSelector serviceSelector = null;
- PolicyManager policyManager = null;
- AccessControllerResolver acResolver = null;
- AccreditableManager accreditableManager = null;
-
- // Get parameters
- final String[] attributes = name.split(":");
-
- if (attributes.length < 3) {
- throw new ConfigurationException("Invalid number of parameters: " + attributes.length
- + ". Expected area, document-id, language.");
- }
-
- final String area = attributes[0];
- final String documentId = attributes[1];
- final String language = attributes[2];
-
- String value = null;
- try {
- PageEnvelope envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
- Publication publication = envelope.getPublication();
-
- DocumentBuilder builder = publication.getDocumentBuilder();
-
- // Create canonical URL
- String canonicalUrl = builder
- .buildCanonicalUrl(publication, area, documentId, language);
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Created canonicalURL: " + canonicalUrl);
- }
-
- // Get proxy for document
- serviceSelector = (ServiceSelector) this.manager.lookup(AccessControllerResolver.ROLE
- + "Selector");
- acResolver = (AccessControllerResolver) serviceSelector
- .select(AccessControllerResolver.DEFAULT_RESOLVER);
-
- AccessController accessController = acResolver.resolveAccessController(canonicalUrl);
- if (accessController instanceof DefaultAccessController) {
- DefaultAccessController defaultAccessController = (DefaultAccessController) accessController;
- accreditableManager = defaultAccessController.getAccreditableManager();
- Authorizer[] authorizers = defaultAccessController.getAuthorizers();
- for (int i = 0; i < authorizers.length; i++) {
- if (authorizers[i] instanceof PolicyAuthorizer) {
- PolicyAuthorizer policyAuthorizer = (PolicyAuthorizer) authorizers[i];
- policyManager = policyAuthorizer.getPolicyManager();
- }
- }
- }
-
- Policy policy = policyManager.getPolicy(accreditableManager, canonicalUrl);
-
- Document doc = builder.buildDocument(publication, canonicalUrl);
-
- Proxy proxy = doc.getPublication().getProxy(doc, policy.isSSLProtected());
-
- if (proxy != null) {
- value = proxy.getURL(doc);
- } else {
- // Take server name and port from request.
- Request request = ObjectModelHelper.getRequest(objectModel);
- value = "http://" + request.getServerName() + ":" + request.getServerPort()
- + request.getContextPath() + doc.getCompleteURL();
+ private ServiceManager manager;
+ /**
+ * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ */
+ public Object getAttribute(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
+ ServiceSelector serviceSelector = null;
+ PolicyManager policyManager = null;
+ AccessControllerResolver acResolver = null;
+ AccreditableManager accreditableManager = null;
+ // Get parameters
+ final String[] attributes = name.split(":");
+ if(attributes.length < 3){
+ throw new ConfigurationException("Invalid number of parameters: " + attributes.length + ". Expected area, document-id, language.");
+ }
+ final String area = attributes[0];
+ final String documentId = attributes[1];
+ final String language = attributes[2];
+ String value = null;
+ try{
+ PageEnvelope envelope = PageEnvelope.getCurrent();
+ Publication publication = envelope.getPublication();
+ DocumentBuilder builder = publication.getDocumentBuilder();
+ // Create canonical URL
+ String canonicalUrl = builder.buildCanonicalUrl(publication, area, documentId, language);
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug("Created canonicalURL: " + canonicalUrl);
+ }
+ // Get proxy for document
+ serviceSelector = (ServiceSelector) this.manager.lookup(AccessControllerResolver.ROLE + "Selector");
+ acResolver = (AccessControllerResolver) serviceSelector.select(AccessControllerResolver.DEFAULT_RESOLVER);
+ AccessController accessController = acResolver.resolveAccessController(canonicalUrl);
+ if(accessController instanceof DefaultAccessController){
+ DefaultAccessController defaultAccessController = (DefaultAccessController) accessController;
+ accreditableManager = defaultAccessController.getAccreditableManager();
+ Authorizer[] authorizers = defaultAccessController.getAuthorizers();
+ for(int i = 0; i < authorizers.length; i++){
+ if(authorizers[i] instanceof PolicyAuthorizer){
+ PolicyAuthorizer policyAuthorizer = (PolicyAuthorizer) authorizers[i];
+ policyManager = policyAuthorizer.getPolicyManager();
+ }
}
-
- } catch (Exception e) {
- throw new ConfigurationException("Obtaining value for [" + name + "] failed: ", e);
- }
- return value;
- }
-
- /**
- * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration,
- * java.util.Map)
- */
- public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
- throws ConfigurationException {
- return Collections.EMPTY_SET.iterator();
- }
-
- /**
- * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String,
- * org.apache.avalon.framework.configuration.Configuration, java.util.Map)
- */
- public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
- throws ConfigurationException {
- Object[] objects = { getAttribute(name, modeConf, objectModel) };
- return objects;
- }
-
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager manager) throws ServiceException {
- this.manager = manager;
- }
+ }
+ Policy policy = policyManager.getPolicy(accreditableManager, canonicalUrl);
+ Document doc = builder.buildDocument(publication, canonicalUrl);
+ Proxy proxy = doc.getPublication().getProxy(doc, policy.isSSLProtected());
+ if(proxy != null){
+ value = proxy.getURL(doc);
+ }else{
+ // Take server name and port from request.
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ value = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + doc.getCompleteURL();
+ }
+ }catch(Exception e){
+ throw new ConfigurationException("Obtaining value for [" + name + "] failed: ", e);
+ }
+ return value;
+ }
+ /**
+ * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ */
+ public Iterator getAttributeNames(Configuration modeConf, Map objectModel) throws ConfigurationException {
+ return Collections.EMPTY_SET.iterator();
+ }
+ /**
+ * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ */
+ public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
+ Object[] objects = {getAttribute(name, modeConf, objectModel)};
+ return objects;
+ }
+ /**
+ * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationContentDirModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationContentDirModule.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationContentDirModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationContentDirModule.java Sat Mar 8 14:58:32 2008
@@ -19,7 +19,6 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
-
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationFallbackModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationFallbackModule.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationFallbackModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationFallbackModule.java Sat Mar 8 14:58:32 2008
@@ -5,47 +5,42 @@
* Window - Preferences - Java - Code Style - Code Templates
*/
package org.apache.lenya.cms.cocoon.components.modules.input;
-
import java.util.Map;
-
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.lenya.cms.publication.PageEnvelope;
+import org.apache.lenya.cms.publication.PageEnvelopeException;
import org.apache.lenya.cms.publication.Publication;
-
/**
* @author nobby
*
- * TODO To change the template for this generated type comment go to Window - Preferences - Java -
- * Code Style - Code Templates
+ * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
*/
public class PublicationFallbackModule extends FallbackModule {
-
- /**
- * Ctor.
- */
- public PublicationFallbackModule() {
- super();
- }
-
- /**
- * @throws ConfigurationException
- * @see org.apache.lenya.cms.cocoon.components.modules.input.FallbackModule#getBaseURIs(java.util.Map)
- */
- protected String[] getBaseURIs(Map objectModel) throws ConfigurationException {
- String[] superUris = super.getBaseURIs(objectModel);
- String[] uris = new String[superUris.length + 1];
-
- PageEnvelope envelope = getEnvelope(objectModel);
- String publicationId = envelope.getPublication().getId();
-
- String publicationUri = "context://" + Publication.PUBLICATION_PREFIX_URI + "/"
- + publicationId + "/lenya";
- uris[0] = publicationUri;
-
- for (int i = 0; i < superUris.length; i++) {
- uris[i + 1] = superUris[i];
- }
-
- return uris;
- }
+ /**
+ * Ctor.
+ */
+ public PublicationFallbackModule() {
+ super();
+ }
+ /**
+ * @throws ConfigurationException
+ * @see org.apache.lenya.cms.cocoon.components.modules.input.FallbackModule#getBaseURIs(java.util.Map)
+ */
+ protected String[] getBaseURIs(Map objectModel) throws ConfigurationException {
+ String[] superUris = super.getBaseURIs(objectModel);
+ String[] uris = new String[superUris.length + 1];
+ PageEnvelope envelope;
+ try{
+ envelope = PageEnvelope.getCurrent();
+ }catch(PageEnvelopeException e){
+ throw new ConfigurationException("Resolving page envelope failed: ", e);
+ }
+ String publicationId = envelope.getPublication().getId();
+ String publicationUri = "context://" + Publication.PUBLICATION_PREFIX_URI + "/" + publicationId + "/lenya";
+ uris[0] = publicationUri;
+ for(int i = 0; i < superUris.length; i++){
+ uris[i + 1] = superUris[i];
+ }
+ return uris;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org