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/01/31 08:44:36 UTC
svn commit: r617035 [9/22] - in /lenya/branches/revolution/1.3.x: ./
src/java/org/apache/lenya/ac/ src/java/org/apache/lenya/ac/cache/
src/java/org/apache/lenya/ac/cifs/ src/java/org/apache/lenya/ac/file/
src/java/org/apache/lenya/ac/impl/ src/java/org...
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/NoChildDocumentExistException.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/NoChildDocumentExistException.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/NoChildDocumentExistException.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/NoChildDocumentExistException.java Wed Jan 30 23:44:03 2008
@@ -14,47 +14,44 @@
* limitations under the License.
*
*/
-
/* $Id: DocumentDoesNotExistException.java 42598 2004-03-01 16:18:28Z gregor $ */
-
package org.apache.lenya.cms.publication;
-
public class NoChildDocumentExistException extends DocumentException {
-
- /**
- * Creates a new NoChildDocumentExistException
- *
- */
- public NoChildDocumentExistException() {
- super();
- }
-
- /**
- * Creates a new NoChildDocumentExistException
- *
- * @param message the exception message
- */
- public NoChildDocumentExistException(String message) {
- super(message);
- }
-
- /**
- * Creates a new NoChildDocumentExistException
- *
- * @param message the exception message
- * @param cause the cause of the exception
- */
- public NoChildDocumentExistException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Creates a new NoChildDocumentExistException
- *
- * @param cause the cause of the exception
- */
- public NoChildDocumentExistException(Throwable cause) {
- super(cause);
- }
-
+ private static final long serialVersionUID = 1L;
+ /**
+ * Creates a new NoChildDocumentExistException
+ *
+ */
+ public NoChildDocumentExistException() {
+ super();
+ }
+ /**
+ * Creates a new NoChildDocumentExistException
+ *
+ * @param message
+ * the exception message
+ */
+ public NoChildDocumentExistException(String message) {
+ super(message);
+ }
+ /**
+ * Creates a new NoChildDocumentExistException
+ *
+ * @param message
+ * the exception message
+ * @param cause
+ * the cause of the exception
+ */
+ public NoChildDocumentExistException(String message, Throwable cause) {
+ super(message, cause);
+ }
+ /**
+ * Creates a new NoChildDocumentExistException
+ *
+ * @param cause
+ * the cause of the exception
+ */
+ public NoChildDocumentExistException(Throwable cause) {
+ super(cause);
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PageEnvelopeException.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PageEnvelopeException.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PageEnvelopeException.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PageEnvelopeException.java Wed Jan 30 23:44:03 2008
@@ -14,47 +14,45 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.publication;
-
-
/**
* This exception is thrown when the creation of a {@link PageEnvelope} object fails.
*/
public class PageEnvelopeException extends Exception {
- /**
- * Creates a new PageEnvelopeException.
- */
- public PageEnvelopeException() {
- }
-
- /**
- * Creates a new PageEnvelopeException.
- *
- * @param message the exception message
- */
- public PageEnvelopeException(String message) {
- super(message);
- }
-
- /**
- * Creates a new PageEnvelopeException.
- *
- * @param message the exception message
- * @param cause the cause of the exception
- */
- public PageEnvelopeException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Creates a new PageEnvelopeException.
- *
- * @param cause the cause of the exception
- */
- public PageEnvelopeException(Throwable cause) {
- super(cause);
- }
+ private static final long serialVersionUID = 1L;
+ /**
+ * Creates a new PageEnvelopeException.
+ */
+ public PageEnvelopeException() {
+ }
+ /**
+ * Creates a new PageEnvelopeException.
+ *
+ * @param message
+ * the exception message
+ */
+ public PageEnvelopeException(String message) {
+ super(message);
+ }
+ /**
+ * Creates a new PageEnvelopeException.
+ *
+ * @param message
+ * the exception message
+ * @param cause
+ * the cause of the exception
+ */
+ public PageEnvelopeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+ /**
+ * Creates a new PageEnvelopeException.
+ *
+ * @param cause
+ * the cause of the exception
+ */
+ public PageEnvelopeException(Throwable cause) {
+ super(cause);
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationException.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationException.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationException.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationException.java Wed Jan 30 23:44:03 2008
@@ -14,47 +14,44 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.publication;
-
public class PublicationException extends Exception {
-
- /**
- * Creates a new PublicationException.
- *
- */
- public PublicationException() {
- super();
- }
-
- /**
- * Creates a new PublicationException.
- *
- * @param message the exception message
- */
- public PublicationException(String message) {
- super(message);
- }
-
- /**
- * Creates a new PublicationException.
- *
- * @param message the exception message
- * @param cause the cause of the exception
- */
- public PublicationException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Creates a new PublicationException.
- *
- * @param cause the cause of the exception
- */
- public PublicationException(Throwable cause) {
- super(cause);
- }
-
+ private static final long serialVersionUID = 1L;
+ /**
+ * Creates a new PublicationException.
+ *
+ */
+ public PublicationException() {
+ super();
+ }
+ /**
+ * Creates a new PublicationException.
+ *
+ * @param message
+ * the exception message
+ */
+ public PublicationException(String message) {
+ super(message);
+ }
+ /**
+ * Creates a new PublicationException.
+ *
+ * @param message
+ * the exception message
+ * @param cause
+ * the cause of the exception
+ */
+ public PublicationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+ /**
+ * Creates a new PublicationException.
+ *
+ * @param cause
+ * the cause of the exception
+ */
+ public PublicationException(Throwable cause) {
+ super(cause);
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationFactory.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationFactory.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationFactory.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationFactory.java Wed Jan 30 23:44:03 2008
@@ -16,7 +16,6 @@
*/
/* $Id$ */
package org.apache.lenya.cms.publication;
-
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
@@ -29,179 +28,172 @@
import org.apache.excalibur.source.SourceUtil;
import org.apache.lenya.cms.publication.file.FilePublication;
import org.apache.lenya.util.ServletHelper;
-import org.apache.log4j.Category;
-
+import org.apache.log4j.Logger;
/**
* Factory for creating publication objects.
*/
public final class PublicationFactory {
- private static Category log = Category.getInstance(PublicationFactory.class);
- /**
- * Create a new <code>PublicationFactory</code>.
- */
- private PublicationFactory() {
- }
- private static Map keyToPublication = new HashMap();
- /**
- * Creates a new publication. The publication ID is resolved from the
- * request URI. The servlet context path is resolved from the context
- * object.
- *
- * @param objectModel
- * The object model of the Cocoon component.
- *
- * @return a <code>Publication</code>
- *
- * @throws PublicationException
- * if there was a problem creating the publication.
- */
- public static Publication getPublication(Map objectModel) throws PublicationException {
- // assert objectModel != null;
- Request request = ObjectModelHelper.getRequest(objectModel);
- Context context = ObjectModelHelper.getContext(objectModel);
- return getPublication(request, context);
- }
- /**
- * Create a new publication with the given publication-id and servlet
- * context path. These publications are cached and reused for similar
- * requests.
- *
- * @param id
- * the publication id
- * @param servletContextPath
- * the servlet context path of the publication
- *
- * @return a <code>Publication</code>
- *
- * @throws PublicationException
- * if there was a problem creating the publication.
- */
- public static Publication getPublication(String id, String servletContextPath) throws PublicationException {
- // assert id != null;
- // assert servletContextPath != null;
- String key = generateKey(id, servletContextPath);
- Publication publication = null;
- if (keyToPublication.containsKey(key)) {
- publication = (Publication) keyToPublication.get(key);
- } else {
- if (PublicationFactory.existsPublication(id, servletContextPath)) {
- publication = new FilePublication(id, servletContextPath);
- keyToPublication.put(key, publication);
- }
- }
- if (publication == null) {
- throw new PublicationException("The publication for ID [" + id + "] could not be created.");
- }
- return publication;
- }
- /**
- * Generates a key to cache a publication. The cache key is constructed
- * using the canonical servlet context path and the publication ID.
- *
- * @param publicationId
- * The publication ID.
- * @param servletContextPath
- * The servlet context path.
- * @return A cache key.
- * @throws PublicationException
- * when the servlet context does not exist.
- */
- protected static String generateKey(String publicationId, String servletContextPath) throws PublicationException {
- String key;
- File servletContext = new File(servletContextPath);
- String canonicalPath;
- try {
- canonicalPath = servletContext.getCanonicalPath();
- } catch (IOException e) {
- throw new PublicationException(e);
- }
- key = canonicalPath + "_" + publicationId;
- return key;
- }
- /**
- * Creates a new publication based on a request and a context.
- *
- * @param request
- * A request.
- * @param context
- * A context.
- *
- * @return A publication.
- *
- * @throws PublicationException
- * if there was a problem creating the publication.
- */
- public static Publication getPublication(Request request, Context context) throws PublicationException {
- log.debug("Creating publication from Cocoon object model");
- String webappUrl = ServletHelper.getWebappURI(request);
- String servletContextPath = context.getRealPath("");
- return getPublication(webappUrl, new File(servletContextPath));
- }
- /**
- * Creates a publication from a webapp URL and a servlet context directory.
- *
- * @param webappUrl
- * The URL within the web application (without context prefix)
- * @param servletContext
- * The Lenya servlet context directory
- * @return A publication
- * @throws PublicationException
- * when something went wrong
- */
- public static Publication getPublication(String webappUrl, File servletContext) throws PublicationException {
- log.debug("Creating publication from webapp URL and servlet context");
- log.debug(" Webapp URL: [" + webappUrl + "]");
- String publicationId = new URLInformation(webappUrl).getPublicationId();
- Publication publication = getPublication(publicationId, servletContext.getAbsolutePath());
- return publication;
- }
- /**
- * Checks if a publication with a certain ID exists in a certain context.
- *
- * @param id
- * The publication ID.
- * @param servletContextPath
- * The webapp context path.
- * @return <code>true</code> if the publication exists, <code>false</code>
- * otherwise.
- */
- public static boolean existsPublication(String id, String servletContextPath) {
- if (servletContextPath.endsWith("/")) {
- servletContextPath = servletContextPath.substring(0, servletContextPath.length() - 1);
- }
- File publicationDirectory = new File(servletContextPath + File.separator + Publication.PUBLICATION_PREFIX + File.separator + id);
- boolean exists = true;
- exists = exists && publicationDirectory.isDirectory();
- exists = exists && new File(publicationDirectory, Publication.CONFIGURATION_FILE).exists();
- return exists;
- }
- /**
- * Creates a publication using a source resolver and a request.
- *
- * @param resolver
- * The source resolver.
- * @param request
- * The request.
- * @return A publication.
- * @throws PublicationException
- * when something went wrong.
- */
- public static Publication getPublication(SourceResolver resolver, Request request) throws PublicationException {
- log.debug("Creating publication from resolver and request");
- Publication publication;
- String webappUri = ServletHelper.getWebappURI(request);
- Source source = null;
- try {
- source = resolver.resolveURI("context:///");
- File servletContext = SourceUtil.getFile(source);
- publication = PublicationFactory.getPublication(webappUri, servletContext);
- } catch (Exception e) {
- throw new PublicationException(e);
- } finally {
- if (source != null) {
- resolver.release(source);
- }
- }
- return publication;
- }
+ private static Logger log = Logger.getLogger(PublicationFactory.class);
+ /**
+ * Create a new <code>PublicationFactory</code>.
+ */
+ private PublicationFactory() {
+ }
+ private static Map keyToPublication = new HashMap();
+ /**
+ * Creates a new publication. The publication ID is resolved from the request URI. The servlet context path is resolved from the context object.
+ *
+ * @param objectModel
+ * The object model of the Cocoon component.
+ *
+ * @return a <code>Publication</code>
+ *
+ * @throws PublicationException
+ * if there was a problem creating the publication.
+ */
+ public static Publication getPublication(Map objectModel) throws PublicationException {
+ // assert objectModel != null;
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ Context context = ObjectModelHelper.getContext(objectModel);
+ return getPublication(request, context);
+ }
+ /**
+ * Create a new publication with the given publication-id and servlet context path. These publications are cached and reused for similar requests.
+ *
+ * @param id
+ * the publication id
+ * @param servletContextPath
+ * the servlet context path of the publication
+ *
+ * @return a <code>Publication</code>
+ *
+ * @throws PublicationException
+ * if there was a problem creating the publication.
+ */
+ public static Publication getPublication(String id, String servletContextPath) throws PublicationException {
+ // assert id != null;
+ // assert servletContextPath != null;
+ String key = generateKey(id, servletContextPath);
+ Publication publication = null;
+ if(keyToPublication.containsKey(key)){
+ publication = (Publication) keyToPublication.get(key);
+ }else{
+ if(PublicationFactory.existsPublication(id, servletContextPath)){
+ publication = new FilePublication(id, servletContextPath);
+ keyToPublication.put(key, publication);
+ }
+ }
+ if(publication == null){
+ throw new PublicationException("The publication for ID [" + id + "] could not be created.");
+ }
+ return publication;
+ }
+ /**
+ * Generates a key to cache a publication. The cache key is constructed using the canonical servlet context path and the publication ID.
+ *
+ * @param publicationId
+ * The publication ID.
+ * @param servletContextPath
+ * The servlet context path.
+ * @return A cache key.
+ * @throws PublicationException
+ * when the servlet context does not exist.
+ */
+ protected static String generateKey(String publicationId, String servletContextPath) throws PublicationException {
+ String key;
+ File servletContext = new File(servletContextPath);
+ String canonicalPath;
+ try{
+ canonicalPath = servletContext.getCanonicalPath();
+ }catch(IOException e){
+ throw new PublicationException(e);
+ }
+ key = canonicalPath + "_" + publicationId;
+ return key;
+ }
+ /**
+ * Creates a new publication based on a request and a context.
+ *
+ * @param request
+ * A request.
+ * @param context
+ * A context.
+ *
+ * @return A publication.
+ *
+ * @throws PublicationException
+ * if there was a problem creating the publication.
+ */
+ public static Publication getPublication(Request request, Context context) throws PublicationException {
+ log.debug("Creating publication from Cocoon object model");
+ String webappUrl = ServletHelper.getWebappURI(request);
+ String servletContextPath = context.getRealPath("");
+ return getPublication(webappUrl, new File(servletContextPath));
+ }
+ /**
+ * Creates a publication from a webapp URL and a servlet context directory.
+ *
+ * @param webappUrl
+ * The URL within the web application (without context prefix)
+ * @param servletContext
+ * The Lenya servlet context directory
+ * @return A publication
+ * @throws PublicationException
+ * when something went wrong
+ */
+ public static Publication getPublication(String webappUrl, File servletContext) throws PublicationException {
+ log.debug("Creating publication from webapp URL and servlet context");
+ log.debug(" Webapp URL: [" + webappUrl + "]");
+ String publicationId = new URLInformation(webappUrl).getPublicationId();
+ Publication publication = getPublication(publicationId, servletContext.getAbsolutePath());
+ return publication;
+ }
+ /**
+ * Checks if a publication with a certain ID exists in a certain context.
+ *
+ * @param id
+ * The publication ID.
+ * @param servletContextPath
+ * The webapp context path.
+ * @return <code>true</code> if the publication exists, <code>false</code> otherwise.
+ */
+ public static boolean existsPublication(String id, String servletContextPath) {
+ if(servletContextPath.endsWith("/")){
+ servletContextPath = servletContextPath.substring(0, servletContextPath.length() - 1);
+ }
+ File publicationDirectory = new File(servletContextPath + File.separator + Publication.PUBLICATION_PREFIX + File.separator + id);
+ boolean exists = true;
+ exists = exists && publicationDirectory.isDirectory();
+ exists = exists && new File(publicationDirectory, Publication.CONFIGURATION_FILE).exists();
+ return exists;
+ }
+ /**
+ * Creates a publication using a source resolver and a request.
+ *
+ * @param resolver
+ * The source resolver.
+ * @param request
+ * The request.
+ * @return A publication.
+ * @throws PublicationException
+ * when something went wrong.
+ */
+ public static Publication getPublication(SourceResolver resolver, Request request) throws PublicationException {
+ log.debug("Creating publication from resolver and request");
+ Publication publication;
+ String webappUri = ServletHelper.getWebappURI(request);
+ Source source = null;
+ try{
+ source = resolver.resolveURI("context:///");
+ File servletContext = SourceUtil.getFile(source);
+ publication = PublicationFactory.getPublication(webappUri, servletContext);
+ }catch(Exception e){
+ throw new PublicationException(e);
+ }finally{
+ if(source != null){
+ resolver.release(source);
+ }
+ }
+ return publication;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationModules.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationModules.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationModules.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationModules.java Wed Jan 30 23:44:03 2008
@@ -9,8 +9,13 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.lenya.cms.modules.Module;
import org.apache.lenya.cms.modules.Modules;
-//TODO: Rearchitect so can reset all without restarting Lenya?
+/**
+ *
+ * @author solprovider
+ * @since 1.3
+ */
public class PublicationModules {
+ // TODO: Rearchitect class so can reset all without restarting Lenya?
private List templates = new ArrayList(); // Default list of Publications for inherit.
// TODO: external and exclude should have defaults in module.xml.
// Current algorithm needs replacing.
@@ -28,16 +33,17 @@
// static Map globalvariables = new HashMap(); // module.variable = value from global module.xml
// static boolean isGlobalvariablesSet = false;
private String publicationId;
- private String servletContextPath;
+ // private String servletContextPath;
private String contentType;
// Dev testing
Configuration config;
- public PublicationModules(String publicationId, String contentType, String servletContextPath, Configuration config) {
+ public PublicationModules(String publicationId, String contentType, Configuration config) {
+ // public PublicationModules(String publicationId, String contentType, String servletContextPath, Configuration config) {
if(null == config)
return;
int i;
this.publicationId = publicationId;
- this.servletContextPath = servletContextPath;
+ // this.servletContextPath = servletContextPath;
this.contentType = contentType;
this.config = config; // TESTING
String[] attrnames = config.getAttributeNames();
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/SiteTreeException.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/SiteTreeException.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/SiteTreeException.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/SiteTreeException.java Wed Jan 30 23:44:03 2008
@@ -14,47 +14,45 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.publication;
-
/**
* Exceptions for site tree handling.
*/
public class SiteTreeException extends Exception {
-
- /**
- * Creates a new SiteTreeException.
- */
- public SiteTreeException() {
- }
-
- /**
- * Creates a new SiteTreeException.
- *
- * @param message the exception message
- */
- public SiteTreeException(String message) {
- super(message);
- }
-
- /**
- * Creates a new SiteTreeException.
- *
- * @param message the exception message
- * @param cause the cause of the exception
- */
- public SiteTreeException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Creates a new SiteTreeException.
- *
- * @param cause the cause of the exception
- */
- public SiteTreeException(Throwable cause) {
- super(cause);
- }
+ private static final long serialVersionUID = 1L;
+ /**
+ * Creates a new SiteTreeException.
+ */
+ public SiteTreeException() {
+ }
+ /**
+ * Creates a new SiteTreeException.
+ *
+ * @param message
+ * the exception message
+ */
+ public SiteTreeException(String message) {
+ super(message);
+ }
+ /**
+ * Creates a new SiteTreeException.
+ *
+ * @param message
+ * the exception message
+ * @param cause
+ * the cause of the exception
+ */
+ public SiteTreeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+ /**
+ * Creates a new SiteTreeException.
+ *
+ * @param cause
+ * the cause of the exception
+ */
+ public SiteTreeException(Throwable cause) {
+ super(cause);
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/XlinkCollection.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/XlinkCollection.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/XlinkCollection.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/XlinkCollection.java Wed Jan 30 23:44:03 2008
@@ -14,102 +14,96 @@
* limitations under the License.
*
*/
-
package org.apache.lenya.cms.publication;
-
import java.io.IOException;
-
import javax.xml.parsers.ParserConfigurationException;
-
import org.apache.lenya.xml.NamespaceHelper;
import org.apache.lenya.xml.XLink;
-import org.apache.log4j.Category;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
-
/**
* Implementation of a Collection. In the collection are xlink inserted.
+ *
* @author <a href="mailto:edith@apache.org">Edith Chevrier </a>
* @author <a href="mailto:andreas@apache.org">Andreas Hartmann </a>
* @version $Id$
*/
public class XlinkCollection extends CollectionImpl {
-
- private static final Category log = Category.getInstance(XlinkCollection.class);
-
- /**
- * Ctor.
- * @param publication A publication.
- * @param id The document ID.
- * @param area The area the document belongs to.
- * @throws DocumentException when something went wrong.
- */
- public XlinkCollection(Publication publication, String id, String area)
- throws DocumentException {
- super(publication, id, area);
- }
-
- /**
- * Ctor.
- * @param publication A publication.
- * @param id The document ID.
- * @param area The area the document belongs to.
- * @param language The language of the document.
- * @throws DocumentException when something went wrong.
- */
- public XlinkCollection(Publication publication, String id, String area, String language)
- throws DocumentException {
- super(publication, id, area, language);
- }
-
- /**
- * (non-Javadoc)
- * @see org.apache.lenya.cms.publication.CollectionImpl#createDocumentElement(org.apache.lenya.cms.publication.Document,
- * org.apache.lenya.xml.NamespaceHelper)
- */
- protected Element createDocumentElement(Document document, NamespaceHelper helper)
- throws DocumentException {
- Element element = super.createDocumentElement(document, helper);
- String path = getXlinkHref(document);
- element.setAttributeNS(XLink.XLINK_NAMESPACE, "xlink:" + XLink.ATTRIBUTE_HREF, path);
- element.setAttributeNS(XLink.XLINK_NAMESPACE, "xlink:" + XLink.ATTRIBUTE_SHOW, "embed");
- element.normalize();
- return element;
- }
-
- /**
- * Returns the href attribute string for a certain document.
- * @param document The document.
- * @return A string.
- * @throws DocumentException when something went wrong.
- */
- protected String getXlinkHref(Document document) throws DocumentException {
- String path = null;
- try {
- path = document.getFile().getCanonicalPath();
- } catch (IOException e) {
- throw new DocumentException("Couldn't found the file path for the document ["
- + document + "]", e);
- }
- return path;
- }
-
- /**
- * Adds the XLink namespace declaration to the document element.
- * @see org.apache.lenya.cms.publication.CollectionImpl#getNamespaceHelper()
- */
- protected NamespaceHelper getNamespaceHelper() throws DocumentException,
- ParserConfigurationException, SAXException, IOException {
-
- NamespaceHelper helper = super.getNamespaceHelper();
- Element collectionElement = helper.getDocument().getDocumentElement();
- String namespaceDeclaration = collectionElement.getAttributeNS(
- "http://www.w3.org/2000/xmlns/", "xlink");
- if (namespaceDeclaration == null || !namespaceDeclaration.equals(XLink.XLINK_NAMESPACE)) {
- collectionElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink",
- XLink.XLINK_NAMESPACE);
- }
- return helper;
- }
-
+ /**
+ * Ctor.
+ *
+ * @param publication
+ * A publication.
+ * @param id
+ * The document ID.
+ * @param area
+ * The area the document belongs to.
+ * @throws DocumentException
+ * when something went wrong.
+ */
+ public XlinkCollection(Publication publication, String id, String area) throws DocumentException {
+ super(publication, id, area);
+ }
+ /**
+ * Ctor.
+ *
+ * @param publication
+ * A publication.
+ * @param id
+ * The document ID.
+ * @param area
+ * The area the document belongs to.
+ * @param language
+ * The language of the document.
+ * @throws DocumentException
+ * when something went wrong.
+ */
+ public XlinkCollection(Publication publication, String id, String area, String language) throws DocumentException {
+ super(publication, id, area, language);
+ }
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.lenya.cms.publication.CollectionImpl#createDocumentElement(org.apache.lenya.cms.publication.Document, org.apache.lenya.xml.NamespaceHelper)
+ */
+ protected Element createDocumentElement(Document document, NamespaceHelper helper) throws DocumentException {
+ Element element = super.createDocumentElement(document, helper);
+ String path = getXlinkHref(document);
+ element.setAttributeNS(XLink.XLINK_NAMESPACE, "xlink:" + XLink.ATTRIBUTE_HREF, path);
+ element.setAttributeNS(XLink.XLINK_NAMESPACE, "xlink:" + XLink.ATTRIBUTE_SHOW, "embed");
+ element.normalize();
+ return element;
+ }
+ /**
+ * Returns the href attribute string for a certain document.
+ *
+ * @param document
+ * The document.
+ * @return A string.
+ * @throws DocumentException
+ * when something went wrong.
+ */
+ protected String getXlinkHref(Document document) throws DocumentException {
+ String path = null;
+ try{
+ path = document.getFile().getCanonicalPath();
+ }catch(IOException e){
+ throw new DocumentException("Couldn't found the file path for the document [" + document + "]", e);
+ }
+ return path;
+ }
+ /**
+ * Adds the XLink namespace declaration to the document element.
+ *
+ * @see org.apache.lenya.cms.publication.CollectionImpl#getNamespaceHelper()
+ */
+ protected NamespaceHelper getNamespaceHelper() throws DocumentException, ParserConfigurationException, SAXException, IOException {
+ NamespaceHelper helper = super.getNamespaceHelper();
+ Element collectionElement = helper.getDocument().getDocumentElement();
+ String namespaceDeclaration = collectionElement.getAttributeNS("http://www.w3.org/2000/xmlns/", "xlink");
+ if(namespaceDeclaration == null || !namespaceDeclaration.equals(XLink.XLINK_NAMESPACE)){
+ collectionElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink", XLink.XLINK_NAMESPACE);
+ }
+ return helper;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java Wed Jan 30 23:44:03 2008
@@ -14,21 +14,18 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.publication.task;
-
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-
-import org.apache.commons.io.FileUtils;
import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.commons.io.FileUtils;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationException;
import org.apache.lenya.cms.publication.PublicationFactory;
import org.apache.lenya.cms.publication.ResourcesManager;
import org.apache.lenya.cms.rc.FileReservedCheckInException;
@@ -43,322 +40,305 @@
import org.apache.lenya.workflow.Situation;
import org.apache.lenya.workflow.SynchronizedWorkflowInstances;
import org.apache.lenya.workflow.WorkflowException;
-import org.apache.log4j.Category;
-
+import org.apache.log4j.Logger;
/**
* Abstract super class for publication-based tasks.
*/
public abstract class PublicationTask extends AbstractTask {
-
- private static final Category log = Category.getInstance(PublicationTask.class);
-
- private Publication publication;
-
- /**
- * Returns the publication used by this task.
- * @return A publication.
- * @throws ExecutionException when an error occurs.
- */
- protected Publication getPublication() throws ExecutionException {
- if (publication == null) {
- try {
- String publicationId = getParameters().getParameter(Task.PARAMETER_PUBLICATION_ID);
- String servletContextPath =
- getParameters().getParameter(Task.PARAMETER_SERVLET_CONTEXT);
- publication = PublicationFactory.getPublication(publicationId, servletContextPath);
- } catch (Exception e) {
- throw new ExecutionException(e);
- }
- }
- return publication;
- }
-
- /**
- * Copies the resources of a document to another document.
- * @param sourceDocument The source document.
- * @param destinationDocument The destination document.
- * @throws PublicationException when something went wrong.
- * @throws ExecutionException when something went wrong.
- * @throws IOException when something went wrong.
- */
- protected void copyResources(Document sourceDocument, Document destinationDocument)
- throws ExecutionException {
-
- if (log.isDebugEnabled()) {
- log.debug("Copying resources");
- }
-
- ResourcesManager sourceManager = new ResourcesManager(sourceDocument);
- ResourcesManager destinationManager = new ResourcesManager(destinationDocument);
-
- List resourcesList = new ArrayList(Arrays.asList(sourceManager.getResources()));
- resourcesList.addAll(Arrays.asList(sourceManager.getMetaFiles()));
- File[] resources = (File[]) resourcesList.toArray(new File[resourcesList.size()]);
- File destinationDirectory = destinationManager.getPath();
-
- for (int i = 0; i < resources.length; i++) {
- File destinationResource = new File(destinationDirectory, resources[i].getName());
-
- if (log.isDebugEnabled()) {
- log.debug(
- "Copy file ["
- + resources[i].getAbsolutePath()
- + "] to ["
- + destinationResource.getAbsolutePath()
- + "]");
- }
- try {
- FileUtils.copyFile(resources[i], destinationResource);
- } catch (IOException e) {
- throw new ExecutionException(e);
- }
- }
- }
-
- public static final String PARAMETER_WORKFLOW_EVENT = "workflow-event";
- public static final String PARAMETER_USER_ID = "user-id";
- public static final String PARAMETER_IP_ADDRESS = "ip-address";
- public static final String PARAMETER_ROLE_IDS = "role-ids";
- public static final String ROLE_SEPARATOR_REGEXP = ",";
-
- /**
- * Checks if the workflow event can be invoked on a document.
- * @param document The document.
- * @return A boolean value.
- * @throws ExecutionException when something went wrong.
- */
- protected boolean canWorkflowFire(Document document) throws ExecutionException {
-
- if (log.isDebugEnabled()) {
- log.debug("Checking workflow of document [" + document + "].");
- }
-
- boolean canFire = true;
-
- WorkflowFactory factory = WorkflowFactory.newInstance();
- if (factory.hasWorkflow(document)) {
- try {
- Situation situation = getSituation();
-
- SynchronizedWorkflowInstances instance;
- try {
- instance = factory.buildSynchronizedInstance(document);
- } catch (WorkflowException e) {
- throw new ExecutionException(e);
- }
- Event event = getExecutableEvent(instance, situation);
-
- if (event == null) {
- canFire = false;
- }
-
- }
- catch (Exception e) {
- throw new ExecutionException(e);
+ private static Logger log = Logger.getLogger(PublicationTask.class);
+ private Publication publication;
+ /**
+ * Returns the publication used by this task.
+ *
+ * @return A publication.
+ * @throws ExecutionException
+ * when an error occurs.
+ */
+ protected Publication getPublication() throws ExecutionException {
+ if(publication == null){
+ try{
+ String publicationId = getParameters().getParameter(Task.PARAMETER_PUBLICATION_ID);
+ String servletContextPath = getParameters().getParameter(Task.PARAMETER_SERVLET_CONTEXT);
+ publication = PublicationFactory.getPublication(publicationId, servletContextPath);
+ }catch(Exception e){
+ throw new ExecutionException(e);
+ }
+ }
+ return publication;
+ }
+ /**
+ * Copies the resources of a document to another document.
+ *
+ * @param sourceDocument
+ * The source document.
+ * @param destinationDocument
+ * The destination document.
+ * @throws PublicationException
+ * when something went wrong.
+ * @throws ExecutionException
+ * when something went wrong.
+ * @throws IOException
+ * when something went wrong.
+ */
+ protected void copyResources(Document sourceDocument, Document destinationDocument) throws ExecutionException {
+ if(log.isDebugEnabled()){
+ log.debug("Copying resources");
+ }
+ ResourcesManager sourceManager = new ResourcesManager(sourceDocument);
+ ResourcesManager destinationManager = new ResourcesManager(destinationDocument);
+ List resourcesList = new ArrayList(Arrays.asList(sourceManager.getResources()));
+ resourcesList.addAll(Arrays.asList(sourceManager.getMetaFiles()));
+ File[] resources = (File[]) resourcesList.toArray(new File[resourcesList.size()]);
+ File destinationDirectory = destinationManager.getPath();
+ for(int i = 0; i < resources.length; i++){
+ File destinationResource = new File(destinationDirectory, resources[i].getName());
+ if(log.isDebugEnabled()){
+ log.debug("Copy file [" + resources[i].getAbsolutePath() + "] to [" + destinationResource.getAbsolutePath() + "]");
+ }
+ try{
+ FileUtils.copyFile(resources[i], destinationResource);
+ }catch(IOException e){
+ throw new ExecutionException(e);
+ }
+ }
+ }
+ public static final String PARAMETER_WORKFLOW_EVENT = "workflow-event";
+ public static final String PARAMETER_USER_ID = "user-id";
+ public static final String PARAMETER_IP_ADDRESS = "ip-address";
+ public static final String PARAMETER_ROLE_IDS = "role-ids";
+ public static final String ROLE_SEPARATOR_REGEXP = ",";
+ /**
+ * Checks if the workflow event can be invoked on a document.
+ *
+ * @param document
+ * The document.
+ * @return A boolean value.
+ * @throws ExecutionException
+ * when something went wrong.
+ */
+ protected boolean canWorkflowFire(Document document) throws ExecutionException {
+ if(log.isDebugEnabled()){
+ log.debug("Checking workflow of document [" + document + "].");
+ }
+ boolean canFire = true;
+ WorkflowFactory factory = WorkflowFactory.newInstance();
+ if(factory.hasWorkflow(document)){
+ try{
+ Situation situation = getSituation();
+ SynchronizedWorkflowInstances instance;
+ try{
+ instance = factory.buildSynchronizedInstance(document);
+ }catch(WorkflowException e){
+ throw new ExecutionException(e);
}
- }
- return canFire;
- }
-
- /**
- * Returns the workflow situation.
- * @return A situation.
- * @throws ParameterException when something went wrong.
- */
- protected Situation getSituation() throws ParameterException {
- WorkflowFactory workflowFactory = WorkflowFactory.newInstance();
- String userId = getParameters().getParameter(PARAMETER_USER_ID);
- String machineIp = getParameters().getParameter(PARAMETER_IP_ADDRESS);
- Situation situation = workflowFactory.buildSituation(getRoleIDs(), userId, machineIp);
- return situation;
- }
-
- /**
- * Invokes the workflow on a document.
- * @param document The document.
- * @throws ParameterException when something went wrong.
- * @throws WorkflowException when something went wrong.
- */
- protected void triggerWorkflow(Document document) throws ExecutionException {
-
- if (log.isDebugEnabled()) {
- log.debug("Trying to execute workflow on document [" + document.getId() + "].");
- }
-
- WorkflowFactory factory = WorkflowFactory.newInstance();
- if (factory.hasWorkflow(document)) {
- try {
- String userId = getParameters().getParameter(PARAMETER_USER_ID);
- String machineIp = getParameters().getParameter(PARAMETER_IP_ADDRESS);
-
- SynchronizedWorkflowInstances instance;
- try {
- instance = factory.buildSynchronizedInstance(document);
- } catch (WorkflowException e) {
- throw new ExecutionException(e);
- }
- Situation situation = factory.buildSituation(getRoleIDs(), userId, machineIp);
-
- Event event = getExecutableEvent(instance, situation);
-
-// assert event != null;
-
- if (log.isDebugEnabled()) {
- log.debug("Invoking event [" + event.getName() + "]");
- }
- instance.invoke(situation, event);
- if (log.isDebugEnabled()) {
- log.debug("Invoking transition completed.");
- }
- } catch (Exception e) {
- throw new ExecutionException(e);
+ Event event = getExecutableEvent(instance, situation);
+ if(event == null){
+ canFire = false;
}
- } else {
- if (log.isDebugEnabled()) {
- log.debug("No workflow associated with document.");
+ }catch(Exception e){
+ throw new ExecutionException(e);
+ }
+ }
+ return canFire;
+ }
+ /**
+ * Returns the workflow situation.
+ *
+ * @return A situation.
+ * @throws ParameterException
+ * when something went wrong.
+ */
+ protected Situation getSituation() throws ParameterException {
+ WorkflowFactory workflowFactory = WorkflowFactory.newInstance();
+ String userId = getParameters().getParameter(PARAMETER_USER_ID);
+ String machineIp = getParameters().getParameter(PARAMETER_IP_ADDRESS);
+ Situation situation = workflowFactory.buildSituation(getRoleIDs(), userId, machineIp);
+ return situation;
+ }
+ /**
+ * Invokes the workflow on a document.
+ *
+ * @param document
+ * The document.
+ * @throws ParameterException
+ * when something went wrong.
+ * @throws WorkflowException
+ * when something went wrong.
+ */
+ protected void triggerWorkflow(Document document) throws ExecutionException {
+ if(log.isDebugEnabled()){
+ log.debug("Trying to execute workflow on document [" + document.getId() + "].");
+ }
+ WorkflowFactory factory = WorkflowFactory.newInstance();
+ if(factory.hasWorkflow(document)){
+ try{
+ String userId = getParameters().getParameter(PARAMETER_USER_ID);
+ String machineIp = getParameters().getParameter(PARAMETER_IP_ADDRESS);
+ SynchronizedWorkflowInstances instance;
+ try{
+ instance = factory.buildSynchronizedInstance(document);
+ }catch(WorkflowException e){
+ throw new ExecutionException(e);
}
- }
-
- }
-
- /**
- * Returns the executable event for the provided {@link #PARAMETER_WORKFLOW_EVENT} parameter.
- * @param instance The workflow instance.
- * @param situation The situation.
- * @return An event.
- * @throws WorkflowException when something went wrong.
- * @throws ParameterException when the {@link #PARAMETER_WORKFLOW_EVENT} parameter could not be resolved.
- */
- protected Event getExecutableEvent(SynchronizedWorkflowInstances instance, Situation situation)
- throws WorkflowException, ParameterException {
-
- String workflowEvent = getEventName();
-
- Event event = null;
- Event[] events = instance.getExecutableEvents(situation);
-
- if (log.isDebugEnabled()) {
- log.debug("Workflow event name: [" + workflowEvent + "]");
- log.debug("Resolved executable events.");
- }
-
- for (int i = 0; i < events.length; i++) {
- if (events[i].getName().equals(workflowEvent)) {
- event = events[i];
+ Situation situation = factory.buildSituation(getRoleIDs(), userId, machineIp);
+ Event event = getExecutableEvent(instance, situation);
+ // assert event != null;
+ if(log.isDebugEnabled()){
+ log.debug("Invoking event [" + event.getName() + "]");
}
- }
-
- if (log.isDebugEnabled()) {
- log.debug("Executable event found: [" + event + "]");
- }
-
- if (event == null) {
- log.error("Event [" + workflowEvent + "] cannot be invoked!");
- }
-
- return event;
- }
-
- /**
- * Returns the workflow event name.
- * @return A string.
- * @throws ParameterException when the parameter does not exist.
- */
- protected String getEventName() throws ParameterException {
- String workflowEvent = getParameters().getParameter(PARAMETER_WORKFLOW_EVENT);
- return workflowEvent;
- }
-
- /**
- * Returns the role IDs.
- * @return An array of strings.
- */
- protected String[] getRoleIDs() throws ParameterException {
- String rolesString = getParameters().getParameter(PARAMETER_ROLE_IDS);
- String[] roles = rolesString.split(ROLE_SEPARATOR_REGEXP);
- return roles;
- }
-
- private RevisionController revisionController;
-
- /**
- * Returns the revision controller.
- * @return A revision controller.
- * @throws ExecutionException
- * @throws IOException when something went wrong.
- */
- protected RevisionController getRevisionController() throws RevisionControlException, ExecutionException {
- if (revisionController == null) {
- File publicationDir = publication.getDirectory();
- RCEnvironment rcEnvironment;
- try {
- File servletContext = publication.getServletContext();
- rcEnvironment = RCEnvironment.getInstance(servletContext.getCanonicalPath());
- } catch (IOException e) {
- throw new RevisionControlException(e);
+ instance.invoke(situation, event);
+ if(log.isDebugEnabled()){
+ log.debug("Invoking transition completed.");
}
-
- File rcmlDirectory = new File(publicationDir, rcEnvironment.getRCMLDirectory());
- File backupDirectory = new File(publicationDir, rcEnvironment.getBackupDirectory());
-
- revisionController =
- new RevisionController(
- rcmlDirectory.getAbsolutePath(),
- backupDirectory.getAbsolutePath(),
- publicationDir.getAbsolutePath());
- }
- return revisionController;
- }
-
- /**
- * Returns the revision file path of a document.
- * @param document The document.
- * @return A string.
- * @throws IOException when something went wrong.
- */
- protected String getRevisionFilePath(Document document) throws IOException {
- String path = document.getFile().getCanonicalPath()
- .substring(publication.getDirectory().getCanonicalPath().length());
- return path;
- }
-
-
- /**
- * Checks if the document can be checked out.
- * @param document The document
- * @return A boolean value.
- * @throws ExecutionException when something went wrong.
- * @throws IOException when something went wrong.
- * @throws Exception when something went wrong.
- */
- protected boolean canCheckOut(Document document) throws ExecutionException, IOException, Exception{
- String userId = getParameters().getParameter(PARAMETER_USER_ID);
- String path = getRevisionFilePath(document);
- return getRevisionController().canCheckOut(path, userId);
- }
-
- /**Checks in a document and creates a revision, if backup is true.
- * @param document
- * @param backup A boolean Value
- * @throws FileReservedCheckInException when something went wrong.
- * @throws Exception when something went wrong.
- */
- protected void reservedCheckIn(Document document, boolean backup)
- throws FileReservedCheckInException, Exception {
- String userId = getParameters().getParameter(PARAMETER_USER_ID);
- String path = getRevisionFilePath(document);
- getRevisionController().reservedCheckIn(path, userId, backup);
- }
-
- /**
- * Checks out a document.
- * @param document The document
- * @throws IOException when something went wrong.
- * @throws Exception when something went wrong.
- */
- protected void reservedCheckOut(Document document) throws IOException, Exception {
- String userId = getParameters().getParameter(PARAMETER_USER_ID);
- String path = getRevisionFilePath(document);
- getRevisionController().reservedCheckOut(path, userId);
- }
+ }catch(Exception e){
+ throw new ExecutionException(e);
+ }
+ }else{
+ if(log.isDebugEnabled()){
+ log.debug("No workflow associated with document.");
+ }
+ }
+ }
+ /**
+ * Returns the executable event for the provided {@link #PARAMETER_WORKFLOW_EVENT} parameter.
+ *
+ * @param instance
+ * The workflow instance.
+ * @param situation
+ * The situation.
+ * @return An event.
+ * @throws WorkflowException
+ * when something went wrong.
+ * @throws ParameterException
+ * when the {@link #PARAMETER_WORKFLOW_EVENT} parameter could not be resolved.
+ */
+ protected Event getExecutableEvent(SynchronizedWorkflowInstances instance, Situation situation) throws WorkflowException, ParameterException {
+ String workflowEvent = getEventName();
+ Event event = null;
+ Event[] events = instance.getExecutableEvents(situation);
+ if(log.isDebugEnabled()){
+ log.debug("Workflow event name: [" + workflowEvent + "]");
+ log.debug("Resolved executable events.");
+ }
+ for(int i = 0; i < events.length; i++){
+ if(events[i].getName().equals(workflowEvent)){
+ event = events[i];
+ }
+ }
+ if(log.isDebugEnabled()){
+ log.debug("Executable event found: [" + event + "]");
+ }
+ if(event == null){
+ log.error("Event [" + workflowEvent + "] cannot be invoked!");
+ }
+ return event;
+ }
+ /**
+ * Returns the workflow event name.
+ *
+ * @return A string.
+ * @throws ParameterException
+ * when the parameter does not exist.
+ */
+ protected String getEventName() throws ParameterException {
+ String workflowEvent = getParameters().getParameter(PARAMETER_WORKFLOW_EVENT);
+ return workflowEvent;
+ }
+ /**
+ * Returns the role IDs.
+ *
+ * @return An array of strings.
+ */
+ protected String[] getRoleIDs() throws ParameterException {
+ String rolesString = getParameters().getParameter(PARAMETER_ROLE_IDS);
+ String[] roles = rolesString.split(ROLE_SEPARATOR_REGEXP);
+ return roles;
+ }
+ private RevisionController revisionController;
+ /**
+ * Returns the revision controller.
+ *
+ * @return A revision controller.
+ * @throws ExecutionException
+ * @throws IOException
+ * when something went wrong.
+ */
+ protected RevisionController getRevisionController() throws RevisionControlException, ExecutionException {
+ if(revisionController == null){
+ File publicationDir = publication.getDirectory();
+ RCEnvironment rcEnvironment;
+ try{
+ File servletContext = publication.getServletContext();
+ rcEnvironment = RCEnvironment.getInstance(servletContext.getCanonicalPath());
+ }catch(IOException e){
+ throw new RevisionControlException(e);
+ }
+ File rcmlDirectory = new File(publicationDir, rcEnvironment.getRCMLDirectory());
+ File backupDirectory = new File(publicationDir, rcEnvironment.getBackupDirectory());
+ revisionController = new RevisionController(rcmlDirectory.getAbsolutePath(), backupDirectory.getAbsolutePath(), publicationDir.getAbsolutePath());
+ }
+ return revisionController;
+ }
+ /**
+ * Returns the revision file path of a document.
+ *
+ * @param document
+ * The document.
+ * @return A string.
+ * @throws IOException
+ * when something went wrong.
+ */
+ protected String getRevisionFilePath(Document document) throws IOException {
+ String path = document.getFile().getCanonicalPath().substring(publication.getDirectory().getCanonicalPath().length());
+ return path;
+ }
+ /**
+ * Checks if the document can be checked out.
+ *
+ * @param document
+ * The document
+ * @return A boolean value.
+ * @throws ExecutionException
+ * when something went wrong.
+ * @throws IOException
+ * when something went wrong.
+ * @throws Exception
+ * when something went wrong.
+ */
+ protected boolean canCheckOut(Document document) throws ExecutionException, IOException, Exception {
+ String userId = getParameters().getParameter(PARAMETER_USER_ID);
+ String path = getRevisionFilePath(document);
+ return getRevisionController().canCheckOut(path, userId);
+ }
+ /**
+ * Checks in a document and creates a revision, if backup is true.
+ *
+ * @param document
+ * @param backup
+ * A boolean Value
+ * @throws FileReservedCheckInException
+ * when something went wrong.
+ * @throws Exception
+ * when something went wrong.
+ */
+ protected void reservedCheckIn(Document document, boolean backup) throws FileReservedCheckInException, Exception {
+ String userId = getParameters().getParameter(PARAMETER_USER_ID);
+ String path = getRevisionFilePath(document);
+ getRevisionController().reservedCheckIn(path, userId, backup);
+ }
+ /**
+ * Checks out a document.
+ *
+ * @param document
+ * The document
+ * @throws IOException
+ * when something went wrong.
+ * @throws Exception
+ * when something went wrong.
+ */
+ protected void reservedCheckOut(Document document) throws IOException, Exception {
+ String userId = getParameters().getParameter(PARAMETER_USER_ID);
+ String path = getRevisionFilePath(document);
+ getRevisionController().reservedCheckOut(path, userId);
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/util/LinkRewriter.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/util/LinkRewriter.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/util/LinkRewriter.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/util/LinkRewriter.java Wed Jan 30 23:44:03 2008
@@ -15,17 +15,11 @@
*
*/
package org.apache.lenya.cms.publication.util;
-
import java.io.File;
import java.io.FileFilter;
-import java.io.FilenameFilter;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-
-import javax.xml.parsers.ParserConfigurationException;
-
import org.apache.commons.io.FilenameUtils;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentBuilder;
@@ -35,160 +29,139 @@
import org.w3c.dom.Attr;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
/**
- * Rewrite the links in a publication. This is used after renaming / moving a
- * document.
+ * Rewrite the links in a publication. This is used after renaming / moving a document.
*
* @version $Id:$
*/
public class LinkRewriter {
-
- private FileFilter directoryFilter = new FileFilter() {
-
- public boolean accept(File file) {
- return file.isDirectory();
- }
- };
-
- private FileFilter xmlFileFilter = new FileFilter() {
-
- public boolean accept(File file) {
- return file.isFile() && FilenameUtils.getExtension(file.getName()).equals("xml");
- }
- };
-
- /**
- * Ctor.
- */
- public LinkRewriter() {
- }
-
- /**
- * Rewrites the links to a document and all its descendants, including all
- * language versions.
- * @param originalTargetDocument The original target document.
- * @param newTargetDocument The new target document.
- * @param contextPath The servlet context path.
- */
- public void rewriteLinks(Document originalTargetDocument, Document newTargetDocument,
- String contextPath) {
-
- Publication publication = originalTargetDocument.getPublication();
- String area = originalTargetDocument.getArea();
- File[] files = getDocumentFiles(publication, area);
-
- DocumentBuilder builder = publication.getDocumentBuilder();
-
- try {
- for (int fileIndex = 0; fileIndex < files.length; fileIndex++) {
- org.w3c.dom.Document xmlDocument = DocumentHelper.readDocument(files[fileIndex]);
- boolean linksRewritten = false;
-
- String[] xPaths = publication.getRewriteAttributeXPaths();
- for (int xPathIndex = 0; xPathIndex < xPaths.length; xPathIndex++) {
- NodeList nodes = XPathAPI.selectNodeList(xmlDocument, xPaths[xPathIndex]);
- for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) {
- Node node = nodes.item(nodeIndex);
- if (node.getNodeType() != Node.ATTRIBUTE_NODE) {
- throw new RuntimeException("The XPath [" + xPaths[xPathIndex]
- + "] may only match attribute nodes!");
+ private FileFilter directoryFilter = new FileFilter() {
+ public boolean accept(File file) {
+ return file.isDirectory();
+ }
+ };
+ private FileFilter xmlFileFilter = new FileFilter() {
+ public boolean accept(File file) {
+ return file.isFile() && FilenameUtils.getExtension(file.getName()).equals("xml");
+ }
+ };
+ /**
+ * Ctor.
+ */
+ public LinkRewriter() {
+ }
+ /**
+ * Rewrites the links to a document and all its descendants, including all language versions.
+ *
+ * @param originalTargetDocument
+ * The original target document.
+ * @param newTargetDocument
+ * The new target document.
+ * @param contextPath
+ * The servlet context path.
+ */
+ public void rewriteLinks(Document originalTargetDocument, Document newTargetDocument, String contextPath) {
+ Publication publication = originalTargetDocument.getPublication();
+ String area = originalTargetDocument.getArea();
+ File[] files = getDocumentFiles(publication, area);
+ DocumentBuilder builder = publication.getDocumentBuilder();
+ try{
+ for(int fileIndex = 0; fileIndex < files.length; fileIndex++){
+ org.w3c.dom.Document xmlDocument = DocumentHelper.readDocument(files[fileIndex]);
+ boolean linksRewritten = false;
+ String[] xPaths = publication.getRewriteAttributeXPaths();
+ for(int xPathIndex = 0; xPathIndex < xPaths.length; xPathIndex++){
+ NodeList nodes = XPathAPI.selectNodeList(xmlDocument, xPaths[xPathIndex]);
+ for(int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++){
+ Node node = nodes.item(nodeIndex);
+ if(node.getNodeType() != Node.ATTRIBUTE_NODE){
+ throw new RuntimeException("The XPath [" + xPaths[xPathIndex] + "] may only match attribute nodes!");
+ }
+ Attr attribute = (Attr) node;
+ final String url = attribute.getValue();
+ if(url.startsWith(contextPath + "/" + publication.getId())){
+ final String webappUrl = url.substring(contextPath.length());
+ if(builder.isDocument(publication, webappUrl)){
+ Document targetDocument = builder.buildDocument(publication, webappUrl);
+ if(matches(targetDocument, originalTargetDocument)){
+ String newTargetUrl = getNewTargetURL(targetDocument, originalTargetDocument, newTargetDocument);
+ attribute.setValue(contextPath + newTargetUrl);
+ linksRewritten = true;
}
- Attr attribute = (Attr) node;
- final String url = attribute.getValue();
-
- if (url.startsWith(contextPath + "/" + publication.getId())) {
- final String webappUrl = url.substring(contextPath.length());
-
- if (builder.isDocument(publication, webappUrl)) {
- Document targetDocument = builder.buildDocument(publication, webappUrl);
-
- if (matches(targetDocument, originalTargetDocument)) {
- String newTargetUrl = getNewTargetURL(targetDocument,
- originalTargetDocument,
- newTargetDocument);
- attribute.setValue(contextPath + newTargetUrl);
- linksRewritten = true;
- }
- }
- }
- }
- }
-
- if (linksRewritten) {
- DocumentHelper.writeDocument(xmlDocument, files[fileIndex]);
- }
+ }
+ }
+ }
+ }
+ if(linksRewritten){
+ DocumentHelper.writeDocument(xmlDocument, files[fileIndex]);
}
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Checks if targetDocument refers to originalTargetDocument, to one of its
- * language versions, to one of its descendants, or to a language version of
- * one of the descendants.
- * @param targetDocument The target document.
- * @param originalTargetDocument The original target document.
- * @return A boolean value.
- */
- protected boolean matches(Document targetDocument, Document originalTargetDocument) {
- String matchString = originalTargetDocument.getId() + "/";
- String testString = targetDocument.getId() + "/";
- return testString.startsWith(matchString);
- }
-
- /**
- * Rewrites a document.
- * @param targetDocument The target document to rewrite.
- * @param originalTargetDocument The original target document.
- * @param newTargetDocument The new target document.
- * @return A string.
- */
- protected String getNewTargetURL(Document targetDocument, Document originalTargetDocument,
- Document newTargetDocument) {
- String originalId = originalTargetDocument.getId();
- String targetId = targetDocument.getId();
- String childString = targetId.substring(originalId.length());
-
- DocumentBuilder builder = targetDocument.getPublication().getDocumentBuilder();
- String newTargetUrl = builder.buildCanonicalUrl(newTargetDocument.getPublication(),
- newTargetDocument.getArea(),
- newTargetDocument.getId() + childString,
- targetDocument.getLanguage());
-
- return newTargetUrl;
- }
-
- /**
- * Returns all XML files in a specific area.
- * @param publication The publication.
- * @param area The area.
- * @return An array of files.
- */
- protected File[] getDocumentFiles(Publication publication, String area) {
- File directory = publication.getContentDirectory(area);
- List files = getDocumentFiles(directory);
- return (File[]) files.toArray(new File[files.size()]);
- }
-
- /**
- * Returns all XML files in a specific directory.
- * @param directory The directory.
- * @return A list of files.
- */
- protected List getDocumentFiles(File directory) {
-
- List list = new ArrayList();
-
- File[] directories = directory.listFiles(directoryFilter);
- for (int i = 0; i < directories.length; i++) {
- list.addAll(getDocumentFiles(directories[i]));
- }
- File[] xmlFiles = directory.listFiles(xmlFileFilter);
- list.addAll(Arrays.asList(xmlFiles));
- return list;
- }
-
+ }
+ }catch(Exception e){
+ throw new RuntimeException(e);
+ }
+ }
+ /**
+ * Checks if targetDocument refers to originalTargetDocument, to one of its language versions, to one of its descendants, or to a language version of one of the descendants.
+ *
+ * @param targetDocument
+ * The target document.
+ * @param originalTargetDocument
+ * The original target document.
+ * @return A boolean value.
+ */
+ protected boolean matches(Document targetDocument, Document originalTargetDocument) {
+ String matchString = originalTargetDocument.getId() + "/";
+ String testString = targetDocument.getId() + "/";
+ return testString.startsWith(matchString);
+ }
+ /**
+ * Rewrites a document.
+ *
+ * @param targetDocument
+ * The target document to rewrite.
+ * @param originalTargetDocument
+ * The original target document.
+ * @param newTargetDocument
+ * The new target document.
+ * @return A string.
+ */
+ protected String getNewTargetURL(Document targetDocument, Document originalTargetDocument, Document newTargetDocument) {
+ String originalId = originalTargetDocument.getId();
+ String targetId = targetDocument.getId();
+ String childString = targetId.substring(originalId.length());
+ DocumentBuilder builder = targetDocument.getPublication().getDocumentBuilder();
+ String newTargetUrl = builder.buildCanonicalUrl(newTargetDocument.getPublication(), newTargetDocument.getArea(), newTargetDocument.getId() + childString, targetDocument.getLanguage());
+ return newTargetUrl;
+ }
+ /**
+ * Returns all XML files in a specific area.
+ *
+ * @param publication
+ * The publication.
+ * @param area
+ * The area.
+ * @return An array of files.
+ */
+ protected File[] getDocumentFiles(Publication publication, String area) {
+ File directory = publication.getContentDirectory(area);
+ List files = getDocumentFiles(directory);
+ return (File[]) files.toArray(new File[files.size()]);
+ }
+ /**
+ * Returns all XML files in a specific directory.
+ *
+ * @param directory
+ * The directory.
+ * @return A list of files.
+ */
+ protected List getDocumentFiles(File directory) {
+ List list = new ArrayList();
+ File[] directories = directory.listFiles(directoryFilter);
+ for(int i = 0; i < directories.length; i++){
+ list.addAll(getDocumentFiles(directories[i]));
+ }
+ File[] xmlFiles = directory.listFiles(xmlFileFilter);
+ list.addAll(Arrays.asList(xmlFiles));
+ return list;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org