move classes
git-svn-id: https://svn.apache.org/repos/asf/lenya/trunk@1072578 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/metadata/usecases/Metadata.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/metadata/usecases/Metadata.java
new file mode 100644
index 0000000..feb9ce3
--- /dev/null
+++ b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/metadata/usecases/Metadata.java
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ *
+ */
+package org.apache.lenya.cms.metadata.usecases;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.lenya.cms.metadata.Element;
+import org.apache.lenya.cms.metadata.MetaData;
+import org.apache.lenya.cms.metadata.MetaDataRegistry;
+import org.apache.lenya.cms.publication.Document;
+//florent : duplicate import org.apache.lenya.cms.publication.Node;
+import org.apache.lenya.cms.repository.Node;
+import org.apache.lenya.cms.site.usecases.SiteUsecase;
+import org.apache.lenya.cms.usecase.UsecaseException;
+import org.apache.lenya.cms.workflow.WorkflowUtil;
+
+/**
+ * Usecase to edit metadata for a resource.
+ *
+ * @version $Id$
+ */
+public class Metadata extends SiteUsecase {
+
+ private MetaDataRegistry metaDataRegistry;
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
+ */
+ protected Node[] getNodesToLock() throws UsecaseException {
+ Node[] objects = new Node[0];
+ if(getSourceDocument() != null) {
+ objects = new Node[] { getSourceDocument() };
+ }
+ return objects;
+ }
+
+ /**
+ * Object to pass a meta data entry to the view.
+ */
+ public static class MetaDataWrapper {
+
+ private String[] values;
+ private Element element;
+ private boolean editable;
+
+ /**
+ * @param element The element.
+ * @param values The values for the element.
+ * @param canChange If the element value can be changed via the GUI. A <code>true</code>
+ * value is only effective if the element itself is editable.
+ */
+ public MetaDataWrapper(Element element, String[] values, boolean canChange) {
+ this.values = values;
+ this.element = element;
+ this.editable = element.isEditable() && canChange;
+ }
+
+ /**
+ * @return The values for the element.
+ */
+ public String[] getValues() {
+ return this.values;
+ }
+
+ /**
+ * @return The element.
+ */
+ public Element getElement() {
+ return this.element;
+ }
+
+ /**
+ * @return If the value can be changed via the GUI.
+ */
+ public boolean isEditable() {
+ return this.editable;
+ }
+
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
+ */
+ protected void initParameters() {
+ super.initParameters();
+
+ Document doc = getSourceDocument();
+ if (doc == null) {
+ return;
+ }
+
+
+ try {
+ boolean canChange = WorkflowUtil.canInvoke(doc, "edit");
+
+ if (!canChange) {
+ addInfoMessage("cannot-change-metadata");
+ }
+
+ List numbers = new ArrayList();
+ Map num2namespace = new HashMap();
+ List keyList = new ArrayList();
+
+ String[] namespaces = getMetaDataRegistry().getNamespaceUris();
+
+ for (int nsIndex = 0; nsIndex < namespaces.length; nsIndex++) {
+ MetaData meta = doc.getMetaData(namespaces[nsIndex]);
+ String[] keys = meta.getPossibleKeys();
+ for (int keyIndex = 0; keyIndex < keys.length; keyIndex++) {
+ String key = "ns" + nsIndex + "." + keys[keyIndex];
+ String[] values = meta.getValues(keys[keyIndex]);
+ Element element = meta.getElementSet().getElement(keys[keyIndex]);
+ setParameter(key, new MetaDataWrapper(element, values, canChange));
+ keyList.add(key);
+ }
+ numbers.add("" + nsIndex);
+ num2namespace.put("" + nsIndex, namespaces[nsIndex]);
+ }
+
+ setParameter("numbers", numbers);
+ setParameter("namespaces", num2namespace);
+
+ Collections.sort(keyList);
+ setParameter("keys", keyList);
+
+ } catch (Exception e) {
+ getLogger().error("Unable to load meta data.", e);
+ addErrorMessage("Unable to load meta data: " + e.getMessage());
+ }
+ }
+
+ protected MetaDataRegistry getMetaDataRegistry() {
+ return metaDataRegistry;
+ }
+
+ public void setMetaDataRegistry(MetaDataRegistry metaDataRegistry) {
+ this.metaDataRegistry = metaDataRegistry;
+ }
+
+}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/AbstractLink.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/AbstractLink.java
deleted file mode 100644
index fe01f12..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/AbstractLink.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-/* @version $Id$ */
-
-package org.apache.lenya.cms.site;
-
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.Publication;
-
-/**
- * The AbstractLink class encapsulates a string label and a associated language.
- */
-public abstract class AbstractLink implements Link {
- private String label = null;
- private String language = null;
-
- /**
- * Creates a new AbstractLink object.
- * @param node The site node.
- * @param _label the actual label
- * @param _language the language
- */
- public AbstractLink(SiteNode node, String _label, String _language) {
- this.label = _label;
- this.language = _language;
- this.node = node;
- }
-
- /**
- * Get the actual label of the AbstractLink object
- *
- * @return the actual label as a String
- */
- public String getLabel() {
- return this.label;
- }
-
- /**
- * Get the language of this AbstractLink object
- *
- * @return the language
- */
-
- public String getLanguage() {
- return this.language;
- }
-
- /**
- * (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- public String toString() {
- return getLabel() + " " + getLanguage();
- }
-
- /**
- * (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object obj) {
- boolean equals = false;
-
- if (getClass().isInstance(obj)) {
- AbstractLink otherLabel = (AbstractLink) obj;
- equals = getLabel().equals(otherLabel.getLabel())
- && getLanguage().equals(otherLabel.getLanguage());
- }
-
- return equals;
- }
-
- /**
- * (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- return getLabel().hashCode() + getLanguage().hashCode();
- }
-
- private SiteNode node;
-
- public Document getDocument() {
- SiteNode node = getNode();
- String uuid = node.getUuid();
- if (uuid == null) {
- throw new UnsupportedOperationException("The node [" + node + "] has no UUID.");
- }
- Publication pub = node.getStructure().getPublication();
- String area = node.getStructure().getArea();
- return pub.getArea(area).getDocument(uuid, getLanguage());
- }
-
- public SiteNode getNode() {
- return this.node;
- }
-
- public void setLabel(String label) {
- this.label = label;
- save();
- }
-
- protected void save() {
- }
-
-}
\ No newline at end of file
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/AbstractSiteManager.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/AbstractSiteManager.java
deleted file mode 100644
index 0f2f784..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/AbstractSiteManager.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.lenya.cms.site;
-
-import java.util.Arrays;
-import java.util.Comparator;
-
-import org.apache.cocoon.util.AbstractLogEnabled;
-
-/**
- * Abstract base class for site managers.
- *
- * @version $Id$
- */
-public abstract class AbstractSiteManager extends AbstractLogEnabled implements SiteManager {
-
- /**
- * @see org.apache.lenya.cms.site.SiteManager#sortAscending(org.apache.lenya.cms.publication.util.DocumentSet)
- */
- public SiteNode[] sortAscending(SiteNode[] nodes) throws SiteException {
- if (nodes.length > 0) {
-
- if (!check(new NodeSet(nodes))) {
- throw new SiteException("The dependence relation is not a strict partial order!");
- }
-
- SiteNode[] sortedNodes = (SiteNode[]) Arrays.asList(nodes).toArray(
- new SiteNode[nodes.length]);
- Arrays.sort(sortedNodes, new NodeComparator());
- return sortedNodes;
- } else {
- return nodes;
- }
- }
-
- /**
- * Checks if the dependence relation is a strict partial order.
- *
- * @param set The document set to check.
- * @return A boolean value.
- * @throws SiteException when something went wrong.
- */
- protected boolean check(NodeSet set) throws SiteException {
- boolean isStrictPartialOrder = isIrreflexive(set) && isAntisymmetric(set)
- && isTransitive(set);
- return isStrictPartialOrder;
- }
-
- /**
- * Checks if the dependence relation is antisymmetric.
- *
- * @param set The document set to check.
- * @return A boolean value.
- * @throws SiteException when something went wrong.
- */
- protected boolean isAntisymmetric(NodeSet set) throws SiteException {
- SiteNode[] resources = set.getNodes();
- boolean isAntisymmetric = true;
- for (int i = 0; i < resources.length; i++) {
- for (int j = i + 1; j < resources.length; j++) {
- if (requires(resources[i], resources[j]) && requires(resources[j], resources[i])
- && !(resources[i] == resources[j])) {
- isAntisymmetric = false;
- }
- }
- }
- return isAntisymmetric;
- }
-
- /**
- * Checks if the dependence relation is transitive.
- *
- * @param set The document set to check.
- * @return A boolean value.
- * @throws SiteException when something went wrong.
- */
- protected boolean isTransitive(NodeSet set) throws SiteException {
- SiteNode[] resources = set.getNodes();
- boolean isTransitive = true;
- for (int i = 0; i < resources.length; i++) {
- for (int j = i + 1; j < resources.length; j++) {
- for (int k = j + 1; k < resources.length; k++) {
- if (requires(resources[i], resources[j])
- && requires(resources[j], resources[k])
- && !requires(resources[i], resources[k])) {
- isTransitive = false;
- }
- }
- }
- }
- return isTransitive;
- }
-
- /**
- * Checks if the dependence relation is irreflexive.
- *
- * @param set The document set.
- * @return A boolean value
- * @throws SiteException
- */
- protected boolean isIrreflexive(NodeSet set) throws SiteException {
- SiteNode[] resources = set.getNodes();
- boolean isIrreflexive = true;
- for (int i = 0; i < resources.length; i++) {
- if (requires(resources[i], resources[i])) {
- isIrreflexive = false;
- }
- }
- return isIrreflexive;
- }
-
- /**
- * Compares nodes according to the dependence relation.
- */
- public class NodeComparator implements Comparator {
-
- /**
- * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
- */
- public int compare(Object arg0, Object arg1) {
- int result = 0;
- if (arg0 instanceof SiteNode && arg1 instanceof SiteNode) {
- SiteNode doc1 = (SiteNode) arg0;
- SiteNode doc2 = (SiteNode) arg1;
-
- try {
- if (AbstractSiteManager.this.requires(doc1, doc2)) {
- result = 1;
- } else if (AbstractSiteManager.this.requires(doc2, doc1)) {
- result = -1;
- }
- } catch (SiteException e) {
- throw new RuntimeException(e);
- }
- }
- return result;
- }
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/AbstractSiteNode.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/AbstractSiteNode.java
deleted file mode 100644
index bcd161f..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/AbstractSiteNode.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site;
-
-import java.util.Arrays;
-
-import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.cocoon.util.AbstractLogEnabled;
-import org.apache.commons.lang.Validate;
-import org.apache.commons.logging.Log;
-import org.apache.lenya.cms.publication.Publication;
-
-/**
- * Abstract site node implementation.
- */
-public abstract class AbstractSiteNode extends AbstractLogEnabled implements SiteNode {
-
- private String path;
- private SiteStructure structure;
- private String uuid;
-
- protected AbstractSiteNode(Publication publication, SiteStructure structure, String path,
- String uuid, Log logger)
- {
- Validate.notNull(structure);
- Validate.notNull(path);
- Validate.isTrue(path.startsWith("/"), "Path must start with /");
- Validate.notNull(uuid);
- this.structure = structure;
- this.path = path;
- this.uuid = uuid;
- }
-
- public String getPath() {
- return path;
- }
-
- public SiteStructure getStructure() {
- return this.structure;
- }
-
- public boolean equals(Object obj) {
- if (obj == null || !(obj instanceof SiteNode)) {
- return false;
- }
- String thisKey = getKey(getStructure().getPublication(),
- getStructure().getArea(),
- getPath());
- SiteNode node = (SiteNode) obj;
- String nodeKey = getKey(node.getStructure().getPublication(),
- node.getStructure().getArea(),
- node.getPath());
- return thisKey.equals(nodeKey);
- }
-
- public int hashCode() {
- return getKey(getStructure().getPublication(), getStructure().getArea(), getPath()).hashCode();
- }
-
- protected static String getKey(Publication pub, String area, String docId) {
- return pub.getId() + ":" + area + ":" + docId;
- }
-
- public SiteNode getParent() throws SiteException {
- String id = getPath().substring(1);
- String[] steps = id.split("/");
- if (steps.length == 1) {
- throw new SiteException("The node [" + getPath() + "] is a top-level node.");
- } else {
- int lastIndex = id.lastIndexOf("/");
- String parentId = id.substring(0, lastIndex);
- return getStructure().getNode("/" + parentId);
- }
- }
-
- public boolean isTopLevel() {
- return getPath().lastIndexOf("/") == 0;
- }
-
- public String getUuid() {
- return this.uuid;
- }
-
- public boolean hasLink(String language) {
- return Arrays.asList(getLanguages()).contains(language);
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/Link.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/Link.java
deleted file mode 100644
index d7e3f14..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/Link.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site;
-
-import org.apache.lenya.cms.publication.Document;
-
-/**
- * A link in the site structure references a document.
- * A site node contains a link for each translation.
- */
-public interface Link {
-
- /**
- * @return The language of this link.
- */
- String getLanguage();
-
- /**
- * @return The document this link points to.
- */
- Document getDocument();
-
- /**
- * @return The node this link belongs to.
- */
- SiteNode getNode();
-
- /**
- * @return The label of this link.
- */
- String getLabel();
-
- /**
- * @param label The new label.
- */
- void setLabel(String label);
-
- /**
- * Removes the link.
- */
- void delete();
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/NodeIterator.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/NodeIterator.java
deleted file mode 100644
index 9806b82..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/NodeIterator.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-
-import org.apache.commons.lang.Validate;
-
-/**
- * Node iterator.
- */
-public class NodeIterator {
-
- private Iterator delegate;
-
- /**
- * @param collection The collection to iterate over.
- */
- public NodeIterator(Collection collection) {
- Validate.notNull(collection);
- this.delegate = collection.iterator();
- }
-
- /**
- * @param nodes The nodes to iterate over.
- */
- public NodeIterator(SiteNode[] nodes) {
- Validate.notNull(nodes);
- this.delegate = Arrays.asList(nodes).iterator();
- }
-
- /**
- * @return A site node.
- * @see Iterator#next()
- */
- public SiteNode next() {
- return (SiteNode) this.delegate.next();
- }
-
- /**
- * @return A boolean value.
- * @see Iterator#hasNext()
- */
- public boolean hasNext() {
- return this.delegate.hasNext();
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/NodeSet.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/NodeSet.java
deleted file mode 100644
index c0ee4cd..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/NodeSet.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.cocoon.spring.configurator.WebAppContextUtils;
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentException;
-import org.apache.lenya.cms.publication.util.DocumentSet;
-
-/**
- * A set containing nodes.
- */
-public class NodeSet {
-
- /**
- * Ctor.
- * @param manager The service manager.
- */
- public NodeSet() {
- }
-
- /**
- * Ctor.
- * @param _nodes The initial nodes.
- */
- public NodeSet(SiteNode[] _nodes) {
- for (int i = 0; i < _nodes.length; i++) {
- add(_nodes[i]);
- }
- }
-
- /**
- * Ctor.
- * @param documents The corresponding documents to derive nodes from.
- */
- public NodeSet(DocumentSet documents) {
- Document[] docs = documents.getDocuments();
- for (int i = 0; i < docs.length; i++) {
- SiteNode node;
- try {
- node = docs[i].getLink().getNode();
- } catch (DocumentException e) {
- throw new RuntimeException(e);
- }
- if (!contains(node)) {
- add(node);
- }
- }
- }
-
- /**
- * @param node A node.
- * @return If the node is contained.
- */
- public boolean contains(SiteNode node) {
- return getSet().contains(node);
- }
-
- private Set nodes = new HashSet();
-
- /**
- * Returns the list object that stores the documents.
- * @return A list.
- */
- protected Set getSet() {
- return this.nodes;
- }
-
- /**
- * Returns the documents contained in this set.
- *
- * @return An array of documents.
- */
- public SiteNode[] getNodes() {
- return (SiteNode[]) this.nodes.toArray(new SiteNode[this.nodes.size()]);
- }
-
- /**
- * Adds a node to this set.
- * @param node The node to add.
- */
- public void add(SiteNode node) {
- assert node != null;
- assert !this.nodes.contains(node);
- this.nodes.add(node);
- }
-
- /**
- * Checks if this set is empty.
- * @return A boolean value.
- */
- public boolean isEmpty() {
- return getSet().isEmpty();
- }
-
- /**
- * Removes a node.
- * @param resource The node.
- */
- public void remove(SiteNode resource) {
- assert resource != null;
- assert getSet().contains(resource);
- getSet().remove(resource);
- }
-
- /**
- * Removes all nodes.
- */
- public void clear() {
- getSet().clear();
- }
-
- /**
- * @return An iterator iterating in undetermined order.
- */
- public NodeIterator iterator() {
- return new NodeIterator(getNodes());
- }
-
- /**
- * @return An iterator iterating in ascending order.
- */
- public NodeIterator ascending() {
- SiteNode[] nodes = getNodesAscending();
- return new NodeIterator(nodes);
- }
-
- /**
- * @return An iterator iterating in descending order.
- */
- public NodeIterator descending() {
- SiteNode[] nodes = getNodesAscending();
- List list = Arrays.asList(nodes);
- Collections.reverse(list);
- return new NodeIterator(list);
- }
-
- protected SiteNode[] getNodesAscending() {
- if (isEmpty()) {
- return new SiteNode[0];
- }
-
- try {
- String hint = getNodes()[0].getStructure().getPublication().getSiteManagerHint();
- SiteManager siteManager = (SiteManager) WebAppContextUtils.getCurrentWebApplicationContext().getBean(
- SiteManager.class.getName() + "/" + hint);
- return siteManager.sortAscending(getNodes());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * @return All documents referenced by this node set.
- */
- public Document[] getDocuments() {
- List documents = new ArrayList();
- for (NodeIterator i = iterator(); i.hasNext();) {
- SiteNode node = i.next();
- String[] langs = node.getLanguages();
- for (int l = 0; l < langs.length; l++) {
- try {
- documents.add(node.getLink(langs[l]).getDocument());
- } catch (SiteException e) {
- throw new RuntimeException(e);
- }
- }
- }
- return (Document[]) documents.toArray(new Document[documents.size()]);
- }
-
- /**
- * Adds all nodes from a node set to this.
- * @param set The set.
- */
- public void addAll(NodeSet set) {
- this.nodes.addAll(set.getSet());
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/SiteException.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/SiteException.java
deleted file mode 100644
index a0acfc3..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/SiteException.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.lenya.cms.site;
-
-import org.apache.lenya.cms.publication.PublicationException;
-
-/**
- * Site structure management exception.
- *
- * @version $Id$
- */
-public class SiteException extends PublicationException {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * Ctor.
- */
- public SiteException() {
- super();
- }
-
- /**
- * Ctor.
- * @param message The message.
- */
- public SiteException(String message) {
- super(message);
- }
-
- /**
- * Ctor.
- * @param cause The cause.
- */
- public SiteException(Throwable cause) {
- super(cause);
- }
-
- /**
- * Ctor.
- * @param message The message.
- * @param cause The cause.
- */
- public SiteException(String message, Throwable cause) {
- super(message, cause);
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/SiteManager.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/SiteManager.java
deleted file mode 100644
index a1c83e3..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/SiteManager.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.lenya.cms.site;
-
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentLocator;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.Session;
-
-/**
- * <p>
- * A site structure management component.
- * </p>
- *
- * <p>
- * A site manager has a dependence relation, which is always applied to documents of a single
- * language. This means a document may not require a document of another language. Dependence on a
- * set of resources must be a strict partial order <strong>< </strong>:
- * </p>
- * <ul>
- * <li><em>irreflexive:</em> d <strong>< </strong>d does not hold for any resource d</li>
- * <li><em>antisymmetric:</em> d <strong>< </strong>e and e <strong>< </strong>d implies d=e</li>
- * <li><em>transitive:</em> d <strong>< </strong>e and e <strong>< </strong>f implies d
- * <strong>< </strong>f</li>
- * </ul>
- *
- * @version $Id$
- */
-public interface SiteManager {
-
- /**
- * The Avalon role.
- */
- String ROLE = SiteManager.class.getName();
-
- /**
- * Checks if a resource requires another one.
- * @param dependingResource The depending resource.
- * @param requiredResource The required resource.
- * @return A boolean value.
- * @throws SiteException if an error occurs.
- */
- boolean requires(SiteNode dependingResource, SiteNode requiredResource) throws SiteException;
-
- /**
- * Returns the resources which are required by a certain resource.
- *
- * @param session The session to operate on.
- * @param locator The depending locator.
- * @return An array of resources.
- * @throws SiteException if an error occurs.
- */
- DocumentLocator[] getRequiredResources(Session session, DocumentLocator locator)
- throws SiteException;
-
- /**
- * Returns the resources which require a certain resource.
- *
- * @param resource The required resource.
- * @return An array of resources.
- * @throws SiteException if an error occurs.
- */
- SiteNode[] getRequiringResources(SiteNode resource) throws SiteException;
-
- /**
- * Adds a document to the site structure.
- * @param path The path.
- * @param document The document to add.
- * @throws SiteException if the document is already contained.
- */
- void add(String path, Document document) throws SiteException;
-
- /**
- * Sets a document to the site structure.
- * @param path The path.
- * @param document The document to add.
- * @throws SiteException if the document is already contained or if the path doesn't exist.
- */
- void set(String path, Document document) throws SiteException;
-
- /**
- * Checks if the site structure contains a certain resource in a certain area.
- *
- * @param resource The resource.
- * @return A boolean value.
- * @throws SiteException if an error occurs.
- */
- boolean contains(Document resource) throws SiteException;
-
- /**
- * Checks if the site structure contains any language version of a certain resource in a certain
- * area.
- *
- * @param resource The resource.
- * @return A boolean value.
- * @throws SiteException if an error occurs.
- */
- boolean containsInAnyLanguage(Document resource) throws SiteException;
-
- /**
- * Copies a document in the site structure.
- *
- * @param sourceDocument The source document.
- * @param destinationDocument The destination document.
- * @throws SiteException when something went wrong.
- */
- void copy(Document sourceDocument, Document destinationDocument) throws SiteException;
-
- /**
- * Sets the visibility of a node in the navigation. It is meant to hide specific nodes within
- * the "public" navigation whereas the node is visible within the info/site area.
- *
- * @param document The document.
- * @param visibleInNav The visibility.
- * @throws SiteException if an error occurs.
- */
- void setVisibleInNav(Document document, boolean visibleInNav) throws SiteException;
-
- /**
- * Returns the visibility of a node in the navigation.
- *
- * @param document The document.
- * @return A boolean value.
- * @throws SiteException if an error occurs.
- */
- boolean isVisibleInNav(Document document) throws SiteException;
-
- /**
- * Returns all documents in a certain area.
- *
- * @param publication The publication.
- * @param area The area.
- * @return An array of documents.
- * @throws SiteException if an error occurs.
- */
- Document[] getDocuments(Publication publication, String area) throws SiteException;
-
- /**
- * Sorts a set of nodes using the "requires" relation.
- *
- * @param nodes The set.
- * @return A sorted array of nodes.
- * @throws SiteException if an error occurs.
- */
- SiteNode[] sortAscending(SiteNode[] nodes) throws SiteException;
-
- /**
- * @param publication The publication.
- * @param area The area.
- * @return The object that holds the site structure information.
- * @throws SiteException if an error occurs.
- */
- SiteStructure getSiteStructure(Publication publication, String area) throws SiteException;
-
- /**
- * Checks if the document does already exist. If it does, returns a non-existing document with a
- * similar document ID. If it does not, the original document is returned.
- * @param session The session.
- * @param locator The locator.
- * @return A locator.
- * @throws SiteException if the new document could not be built.
- */
- DocumentLocator getAvailableLocator(Session session, DocumentLocator locator)
- throws SiteException;
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/SiteNode.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/SiteNode.java
deleted file mode 100644
index af9936c..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/SiteNode.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site;
-
-/**
- * A node in the site structure.
- */
-public interface SiteNode {
-
- /**
- * @return The site structure this node belongs to.
- */
- SiteStructure getStructure();
-
- /**
- * @return The path.
- */
- String getPath();
-
- /**
- * @return The parent node.
- * @throws SiteException If the node has no parent.
- */
- SiteNode getParent() throws SiteException;
-
- /**
- * @return If this is a top level node. Top level nodes have no parents.
- */
- boolean isTopLevel();
-
- /**
- * @return The languages of this node.
- */
- String[] getLanguages();
-
- /**
- * @param language The language.
- * @return The link for the language.
- * @throws SiteException if no link is contained for the language.
- */
- Link getLink(String language) throws SiteException;
-
- /**
- * @return The UUID of this node.
- */
- String getUuid();
-
- /**
- * Checks if a link for a certain language is contained.
- * @param language The language.
- * @return A boolean value.
- */
- boolean hasLink(String language);
-
- /**
- * @return The name, i.e. the last path element.
- */
- String getName();
-
- /**
- * @return if the node is visible in the navigation.
- */
- boolean isVisible();
-
- /**
- * Sets the node visibility in the navigation.
- * @param visibleInNav if the node should be visible.
- */
- void setVisible(boolean visibleInNav);
-
- /**
- * Deletes this node.
- */
- void delete();
-
- /**
- * @return The children of this node.
- */
- SiteNode[] getChildren();
-
- /**
- * @return if the node has an external link.
- */
- boolean hasLink();
-
- /**
- * @return The external link.
- */
- String getHref();
-
- /**
- * @return The suffix.
- */
- String getSuffix();
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/SiteStructure.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/SiteStructure.java
deleted file mode 100644
index dc7f3cb..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/SiteStructure.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site;
-
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.Node;
-import org.apache.lenya.cms.publication.Publication;
-
-/**
- * Object to hold a site structure information.
- *
- * @version $Id$
- */
-public interface SiteStructure extends Node {
-
- /**
- * @return The publication.
- */
- Publication getPublication();
-
- /**
- * @return The area.
- */
- String getArea();
-
- /**
- * @return All nodes in this structure.
- */
- SiteNode[] getNodes();
-
- /**
- * @param path The path.
- * @return A site node.
- * @throws SiteException if no node is contained for the path.
- */
- SiteNode getNode(String path) throws SiteException;
-
- /**
- * Checks if a node is contained for a certain path.
- * @param path The path.
- * @return A boolean value.
- */
- boolean contains(String path);
-
- /**
- * Checks if a link is contained for a certain path and language.
- * @param path The path.
- * @param language The language.
- * @return A boolean value.
- */
- boolean contains(String path, String language);
-
- /**
- * Checks if the structure contains a link with a certain UUID and language.
- * @param uuid The UUID.
- * @param language The language.
- * @return A boolean value.
- */
- boolean containsByUuid(String uuid, String language);
-
- /**
- * Checks if the structure contains any language version of a document.
- * @param uuid The uuid.
- * @return A boolean value.
- */
- boolean containsInAnyLanguage(String uuid);
-
- /**
- * Returns a node for a certain UUID.
- * @param uuid The UUID.
- * @param language The language.
- * @return a link.
- * @throws SiteException if no node is contained for the UUID.
- */
- Link getByUuid(String uuid, String language) throws SiteException;
-
- /**
- * Adds a link to a document.
- * @param path The path.
- * @param doc The document.
- * @return A link.
- * @throws SiteException if the document is already contained or the node
- * for this path already contains a link for this language.
- */
- Link add(String path, Document doc) throws SiteException;
-
- /**
- * Adds a site node.
- * @param path The path.
- * @return A site node.
- * @throws SiteException if the path is already contained.
- */
- SiteNode add(String path) throws SiteException;
-
- /**
- * Adds a site node before a specific other node.
- * @param path The path.
- * @param followingSiblingPath The path of the node which will be the
- * following sibling of the node to insert.
- * @return A site node.
- * @throws SiteException if the path is already contained.
- */
- SiteNode add(String path, String followingSiblingPath) throws SiteException;
-
- /**
- * @return The top level nodes.
- */
- SiteNode[] getTopLevelNodes();
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/SiteUtil.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/SiteUtil.java
deleted file mode 100644
index 53a27d7..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/SiteUtil.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.cocoon.spring.configurator.WebAppContextUtils;
-import org.apache.lenya.cms.publication.DocumentLocator;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.Session;
-
-/**
- * Utility to handle site structures.
- *
- * @version $Id$
- */
-public class SiteUtil {
-
- private SiteUtil() {
- }
-
- /**
- * Returns a sub-site starting with a certain node, which includes the node itself and all nodes
- * which require this node, in preorder.
- *
- * @param node The top-level document.
- * @return A document set.
- * @throws SiteException if an error occurs.
- */
- public static NodeSet getSubSite(SiteNode node) throws SiteException {
- SiteManager siteManager = null;
- SiteNode[] subsite;
- try {
- String hint = node.getStructure().getPublication().getSiteManagerHint();
- siteManager = (SiteManager) WebAppContextUtils.getCurrentWebApplicationContext()
- .getBean(SiteManager.class.getName() + "/" + hint);
-
- Set nodes = new HashSet();
- nodes.add(node);
-
- SiteNode[] requiringNodes = siteManager.getRequiringResources(node);
- for (int i = 0; i < requiringNodes.length; i++) {
- nodes.add(requiringNodes[i]);
- }
-
- subsite = (SiteNode[]) nodes.toArray(new SiteNode[nodes.size()]);
- } catch (Exception e) {
- throw new SiteException(e);
- }
- return new NodeSet(subsite);
- }
-
- /**
- * @see org.apache.lenya.cms.site.SiteManager#getAvailableLocator(DocumentFactory,
- * DocumentLocator)
- * @param factory The factory.
- * @param locator The locator.
- * @return A document.
- * @throws SiteException if an error occurs.
- */
- public static DocumentLocator getAvailableLocator(Session session,
- DocumentLocator locator) throws SiteException {
- SiteManager siteManager = null;
- try {
- Publication pub = session.getPublication(locator.getPublicationId());
- siteManager = (SiteManager) WebAppContextUtils.getCurrentWebApplicationContext()
- .getBean(SiteManager.ROLE + "/" + pub.getSiteManagerHint());
- return siteManager.getAvailableLocator(session, locator);
- } catch (Exception e) {
- throw new SiteException(e);
- }
- }
-
-}
\ No newline at end of file
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Archive.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Archive.java
deleted file mode 100644
index f0c1247..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Archive.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import org.apache.lenya.cms.publication.Publication;
-
-/**
- * Archive usecase handler.
- *
- * @version $Id:$
- */
-public class Archive extends MoveSubsite {
-
- /**
- * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getSourceAreas()
- */
- protected String[] getSourceAreas() {
- return new String[] { Publication.AUTHORING_AREA };
- }
-
- /**
- * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getTargetArea()
- */
- protected String getTargetArea() {
- return Publication.ARCHIVE_AREA;
- }
-
- /**
- * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getEvent()
- */
- protected String getEvent() {
- return "archive";
- }
-
-
-}
\ No newline at end of file
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Assets.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Assets.java
deleted file mode 100644
index 8d281b8..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Assets.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentException;
-import org.apache.lenya.cms.site.SiteException;
-import org.apache.lenya.cms.site.SiteNode;
-import org.apache.lenya.util.ServletHelper;
-
-/**
- * Usecase to add Assets to a resource.
- *
- * @version $Id$
- */
-public class Assets extends SiteUsecase {
-
- protected static final String PARAMETER_UPLOAD_ENABLED = "uploadEnabled";
- protected static final String MESSAGE_UPLOAD_DISABLED = "upload-disabled";
-
- protected void prepareView() throws Exception {
- super.prepareView();
-
- if (getSourceDocument() != null) {
- try {
- Document[] resourceDocs = getResourceDocuments();
- setParameter("resourceDocuments", resourceDocs);
- } catch (final Exception e) {
- throw new RuntimeException(e);
- }
-
- if (!ServletHelper.isUploadEnabled()) {
- addErrorMessage(MESSAGE_UPLOAD_DISABLED);
- setParameter(PARAMETER_UPLOAD_ENABLED, Boolean.FALSE);
- }
- }
- }
-
- protected Document[] getResourceDocuments() throws DocumentException, SiteException {
- List list = new ArrayList();
- Document[] docs = getSourceDocument().area().getDocuments();
- SiteNode node = getSourceDocument().getLink().getNode();
- for (int i = 0; i < docs.length; i++) {
- if (docs[i].hasLink() && !docs[i].getLink().getNode().isTopLevel()
- && docs[i].getLink().getNode().getParent().getPath().equals(node.getPath())
- && docs[i].getResourceType().getName().equals("resource")) {
- list.add(docs[i]);
- }
- }
- return (Document[]) list.toArray(new Document[list.size()]);
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ChangeLabel.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ChangeLabel.java
deleted file mode 100644
index ad9d313..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ChangeLabel.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentException;
-import org.apache.lenya.cms.publication.Node;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.site.SiteStructure;
-import org.apache.lenya.cms.usecase.DocumentUsecase;
-import org.apache.lenya.cms.usecase.UsecaseException;
-import org.apache.lenya.cms.workflow.WorkflowUtil;
-import org.apache.lenya.cms.workflow.usecases.UsecaseWorkflowHelper;
-
-/**
- * Change the label of a document.
- *
- * @version $Id$
- */
-public class ChangeLabel extends DocumentUsecase {
-
- protected static final String LABEL = "label";
- protected static final String DOCUMENT_ID = "documentId";
-
- protected String getEvent() {
- return "edit";
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
- */
- protected void doCheckPreconditions() throws Exception {
- super.doCheckPreconditions();
- if (hasErrors()) {
- return;
- }
-
- Document doc = getSourceDocument();
- if (!getSourceDocument().getArea().equals(Publication.AUTHORING_AREA)) {
- addErrorMessage("This usecase can only be invoked in the authoring area!");
- }
-
- UsecaseWorkflowHelper.checkWorkflow(this, getEvent(), doc, getLogger());
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
- */
- protected Node[] getNodesToLock() throws UsecaseException {
- List nodes = new ArrayList();
- if (getSourceDocument() != null) {
- SiteStructure structure = getSourceDocument().area().getSite();
- nodes.add(structure);
- }
-
- return (Node[]) nodes.toArray(new Node[nodes.size()]);
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
- */
- protected void initParameters() {
- super.initParameters();
- Document document = getSourceDocument();
- try {
- if (document != null && document.exists()) {
- setParameter(DOCUMENT_ID, document.getUUID());
- setParameter(LABEL, document.getLink().getLabel());
- }
- } catch (final DocumentException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
- */
- protected void doCheckExecutionConditions() throws Exception {
- String label = getParameterAsString(LABEL);
- if (label.trim().equals("")) {
- addErrorMessage("missing-navigation-title");
- }
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
- */
- protected void doExecute() throws Exception {
- super.doExecute();
-
- Document document = getSourceDocument();
- String label = getParameterAsString(LABEL).trim();
- document.getLink().setLabel(label);
-
- WorkflowUtil.invoke(document, getEvent());
-
- }
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ChangeNodeID.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ChangeNodeID.java
deleted file mode 100644
index 99bfa53..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ChangeNodeID.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentBuildException;
-import org.apache.lenya.cms.publication.DocumentBuilder;
-import org.apache.lenya.cms.publication.DocumentException;
-import org.apache.lenya.cms.publication.DocumentLocator;
-import org.apache.lenya.cms.publication.DocumentManager;
-import org.apache.lenya.cms.publication.Node;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.site.NodeIterator;
-import org.apache.lenya.cms.site.NodeSet;
-import org.apache.lenya.cms.site.SiteException;
-import org.apache.lenya.cms.site.SiteNode;
-import org.apache.lenya.cms.site.SiteStructure;
-import org.apache.lenya.cms.site.SiteUtil;
-import org.apache.lenya.cms.usecase.DocumentUsecase;
-import org.apache.lenya.cms.usecase.UsecaseException;
-
-/**
- * Change the node ID of a document.
- *
- * @version $Id$
- */
-public class ChangeNodeID extends DocumentUsecase {
-
- protected static final String NODE_ID = "nodeId";
- private DocumentManager documentManager;
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
- */
- protected void initParameters() {
- super.initParameters();
- Document document = getSourceDocument();
- if (document != null) {
- setParameter(NODE_ID, document.getName());
- }
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
- */
- protected Node[] getNodesToLock() throws UsecaseException {
-
- List nodes = new ArrayList();
-
- try {
- if (getSourceDocument() != null) {
- Node siteNode = getSourceDocument().area().getSite();
- nodes.add(siteNode);
-
- Document sourceDocument = getSourceDocument();
-
- NodeSet subsite = SiteUtil.getSubSite(sourceDocument.getLink().getNode());
- for (NodeIterator i = subsite.iterator(); i.hasNext();) {
- SiteNode node = i.next();
- String[] languages = node.getLanguages();
- for (int l = 0; l < languages.length; l++) {
- Document doc = node.getLink(languages[l]).getDocument();
- nodes.add(doc);
- }
- }
- }
- } catch (Exception e) {
- throw new UsecaseException(e);
- }
-
- return (Node[]) nodes.toArray(new Node[nodes.size()]);
- }
-
- protected List getAllLanguageVersionNodes(Document doc) throws DocumentException, DocumentBuildException {
- String[] languages = doc.getLanguages();
- List nodes = new ArrayList();
- for (int i = 0; i < languages.length; i++) {
- nodes.add(doc.getTranslation(languages[i]));
- }
- return nodes;
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
- */
- protected void doCheckPreconditions() throws Exception {
- super.doCheckPreconditions();
- if (hasErrors()) {
- return;
- }
-
- if (!getSourceDocument().getArea().equals(Publication.AUTHORING_AREA)) {
- addErrorMessage("This usecase can only be invoked in the authoring area!");
- } else {
- if (getSourceDocument().existsAreaVersion(Publication.LIVE_AREA)) {
- addErrorMessage("This usecase cannot be invoked when the live version exists!");
- }
- }
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
- */
- protected void doCheckExecutionConditions() throws Exception {
- super.doCheckExecutionConditions();
-
- String nodeId = getParameterAsString(NODE_ID);
- DocumentBuilder builder = getSourceDocument().getPublication().getDocumentBuilder();
- if (!builder.isValidDocumentName(nodeId)) {
- addErrorMessage("The document ID is not valid.");
- } else {
- DocumentLocator target = getTargetLocator();
- Publication pub = getSession().getPublication(target.getPublicationId());
- SiteStructure site = pub.getArea(target.getArea()).getSite();
- if (site.contains(target.getPath(), target.getLanguage())) {
- addErrorMessage("The document does already exist.");
- }
- }
- }
-
- protected DocumentLocator getTargetLocator() throws DocumentBuildException, SiteException,
- DocumentException {
- String nodeId = getParameterAsString(NODE_ID);
- Document doc = getSourceDocument();
- DocumentLocator loc = DocumentLocator.getLocator(doc.getPublication().getId(), doc
- .getArea(), doc.getPath(), doc.getLanguage());
- DocumentLocator parent = loc.getParent();
- return parent.getChild(nodeId);
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
- */
- protected void doExecute() throws Exception {
- super.doExecute();
-
- Document targetDoc;
- Document source = getSourceDocument();
- DocumentLocator target = getTargetLocator();
- getDocumentManager().moveAll(source.area(), source.getPath(), source.area(), target.getPath());
- targetDoc = target.getDocument(getSession());
-
- setTargetDocument(targetDoc);
- }
-
- /**
- * Returns the resulting document when the node ID would be changed.
- * @return A document.
- */
- protected String getNewDocumentId() {
- String nodeId = getParameterAsString(NODE_ID);
-
- String oldPath;
- try {
- oldPath = getSourceDocument().getPath();
- } catch (DocumentException e) {
- throw new RuntimeException(e);
- }
- int lastSlashIndex = oldPath.lastIndexOf("/");
- String strippedDocumentId = oldPath.substring(0, lastSlashIndex + 1);
- String newDocumentId = strippedDocumentId + nodeId;
-
- return newDocumentId;
- }
-
- protected DocumentManager getDocumentManager() {
- return documentManager;
- }
-
- /**
- * TODO: Bean wiring
- */
- public void setDocumentManager(DocumentManager documentManager) {
- this.documentManager = documentManager;
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ChangeVisibility.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ChangeVisibility.java
deleted file mode 100644
index f872fc1..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ChangeVisibility.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentException;
-import org.apache.lenya.cms.publication.Node;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.site.SiteNode;
-import org.apache.lenya.cms.site.SiteStructure;
-import org.apache.lenya.cms.usecase.DocumentUsecase;
-import org.apache.lenya.cms.usecase.Usecase;
-import org.apache.lenya.cms.usecase.UsecaseException;
-import org.apache.lenya.cms.workflow.WorkflowUtil;
-import org.apache.lenya.cms.workflow.usecases.UsecaseWorkflowHelper;
-
-/**
- * Switch the navigation visibility of a document.
- */
-public class ChangeVisibility extends DocumentUsecase {
-
- protected String getEvent() {
- return "edit";
- }
-
- public Object getParameter(String name) {
- if (name.equals(Usecase.PARAMETER_ITEM_STATE)) {
- Document doc = getSourceDocument();
- try {
- return doc != null ? Boolean.valueOf(doc.getLink().getNode().isVisible()) : null;
- } catch (DocumentException e) {
- throw new RuntimeException(e);
- }
- } else {
- return super.getParameter(name);
- }
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
- */
- protected void doCheckPreconditions() throws Exception {
- super.doCheckPreconditions();
- if (hasErrors()) {
- return;
- }
-
- Document doc = getSourceDocument();
- if (!getSourceDocument().getArea().equals(Publication.AUTHORING_AREA)) {
- addErrorMessage("This usecase can only be invoked in the authoring area!");
- }
-
- String[] languages = doc.getLanguages();
- for (int i = 0; i < languages.length; i++) {
- Document version = doc.getTranslation(languages[i]);
- UsecaseWorkflowHelper.checkWorkflow(this, getEvent(), version, getLogger());
- }
- }
-
- protected void doExecute() throws Exception {
- super.doExecute();
- Document doc = getSourceDocument();
- SiteNode node = doc.getLink().getNode();
- node.setVisible(!node.isVisible());
-
- String[] languages = doc.getLanguages();
- for (int i = 0; i < languages.length; i++) {
- Document version = doc.getTranslation(languages[i]);
- WorkflowUtil.invoke(version, getEvent());
- }
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
- */
- protected Node[] getNodesToLock() throws UsecaseException {
- List nodes = new ArrayList();
- if (getSourceDocument() != null) {
- SiteStructure structure = getSourceDocument().area().getSite();
- nodes.add(structure);
- }
-
- return (Node[]) nodes.toArray(new Node[nodes.size()]);
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Clipboard.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Clipboard.java
deleted file mode 100644
index afbe2c4..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Clipboard.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.ResourceNotFoundException;
-import org.apache.lenya.cms.publication.Session;
-
-/**
- * Clipboard for cut/copy/paste of documents. The clipping method is either {@link #METHOD_CUT} or
- * {@link #METHOD_COPY}.
- *
- * @version $Id$
- */
-public class Clipboard {
-
- private String publicationId;
- private String area;
- private String uuid;
- private String language;
- private int method;
-
- /**
- * The "cut" method.
- */
- public static final int METHOD_CUT = 0;
-
- /**
- * The "copy" method.
- */
- public static final int METHOD_COPY = 1;
-
- /**
- * Ctor.
- * @param document The document to put on the clipboard.
- * @param _method The clipping method.
- */
- public Clipboard(Document document, int _method) {
- this.publicationId = document.getPublication().getId();
- this.area = document.getArea();
- this.uuid = document.getUUID();
- this.language = document.getLanguage();
- this.method = _method;
- }
-
- /**
- * Returns the document for the current session.
- * @param session The session.
- * @return A document.
- * @throws ResourceNotFoundException if the document does not exist.
- */
- public Document getDocument(Session session) throws ResourceNotFoundException {
- return session.getPublication(this.publicationId).getArea(this.area).getDocument(this.uuid,
- this.language);
- }
-
- /**
- * @return The ID of the publication the document belongs to.
- */
- public String getPublicationId() {
- return this.publicationId;
- }
-
- /**
- * Returns the method of this clipboard.
- * @return An integer.
- */
- public int getMethod() {
- return this.method;
- }
-}
\ No newline at end of file
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ClipboardHelper.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ClipboardHelper.java
deleted file mode 100644
index 5b94f6f..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ClipboardHelper.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-/**
- * Helper class for clipboard handling.
- *
- * @version $Id$
- */
-public class ClipboardHelper {
-
- /**
- * Returns the clipboard attachted to the session.
- * @param context The context containing the session.
- * @return A clipboard or <code>null</code> if no clipboard is attached to
- * the session.
- */
- public Clipboard getClipboard(HttpServletRequest request) {
- HttpSession session = request.getSession();
- return (Clipboard) session.getAttribute(getSessionAttributeName());
- }
-
- /**
- * @return The name of the session attribute to hold the clipboard.
- */
- protected String getSessionAttributeName() {
- return Clipboard.class.getName();
- }
-
- /**
- * Saves the clipboard to the session.
- * @param context The context.
- * @param clipboard The clipboard.
- */
- public void saveClipboard(HttpServletRequest request, Clipboard clipboard) {
- HttpSession session = request.getSession();
- session.setAttribute(getSessionAttributeName(), clipboard);
- }
-
- /**
- * Removes the clipboard from the session.
- * @param context The context.
- */
- public void removeClipboard(HttpServletRequest request) {
- HttpSession session = request.getSession();
- session.removeAttribute(getSessionAttributeName());
- }
-
-}
\ No newline at end of file
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Copy.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Copy.java
deleted file mode 100644
index a2f1eed..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Copy.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.cocoon.processing.ProcessInfoProvider;
-import org.apache.cocoon.spring.configurator.WebAppContextUtils;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.usecase.DocumentUsecase;
-
-/**
- * Copy a document into the clipboard.
- *
- * @version $Id$
- */
-public class Copy extends DocumentUsecase {
-
- protected void doCheckPreconditions() throws Exception {
- super.doCheckPreconditions();
- if (hasErrors()) {
- return;
- }
- if (!getSourceDocument().getArea().equals(Publication.AUTHORING_AREA)) {
- addErrorMessage("only-in-authoring-area");
- }
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
- */
- protected void doExecute() throws Exception {
- super.doExecute();
-
- Clipboard clipboard = new Clipboard(getSourceDocument(), Clipboard.METHOD_COPY);
- ClipboardHelper helper = new ClipboardHelper();
- helper.saveClipboard(getRequest(), clipboard);
- }
-
- protected HttpServletRequest getRequest() {
- ProcessInfoProvider process = (ProcessInfoProvider) WebAppContextUtils
- .getCurrentWebApplicationContext().getBean(ProcessInfoProvider.ROLE);
- return process.getRequest();
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Create.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Create.java
deleted file mode 100644
index 6bb1d42..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Create.java
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.GregorianCalendar;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-import org.apache.cocoon.processing.ProcessInfoProvider;
-import org.apache.cocoon.spring.configurator.WebAppContextUtils;
-import org.apache.lenya.ac.Identity;
-import org.apache.lenya.ac.User;
-import org.apache.lenya.cms.metadata.MetaData;
-import org.apache.lenya.cms.metadata.MetaDataException;
-import org.apache.lenya.cms.metadata.dublincore.DublinCore;
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentManager;
-import org.apache.lenya.cms.publication.Node;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.ResourceType;
-import org.apache.lenya.cms.publication.ResourceTypeResolver;
-import org.apache.lenya.cms.publication.URLInformation;
-import org.apache.lenya.cms.site.SiteStructure;
-import org.apache.lenya.cms.usecase.AbstractUsecase;
-import org.apache.lenya.cms.usecase.UsecaseException;
-
-/**
- * <p>
- * Abstract superclass for usecases to create a document.
- * </p>
- * <p>
- * You can pass the following parameters into the usecase:
- * </p>
- * <ul>
- * <li><strong>path</strong> - the path of the document to create (optional)</li>
- * </ul>
- *
- * @version $Id$
- */
-public abstract class Create extends AbstractUsecase {
-
- protected static final String RESOURCE_TYPES = "resourceTypes";
- protected static final String LANGUAGE = "language";
- protected static final String LANGUAGES = "languages";
- protected static final String PATH = "path";
- protected static final String NODE_NAME = "nodeName";
- protected static final String VISIBLEINNAV = "visibleInNav";
- protected static final String SAMPLE = "sample";
- protected static final String SAMPLES = "samples";
-
- private DocumentManager documentManager;
- private ResourceTypeResolver resourceTypeResolver;
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
- */
- protected void doCheckPreconditions() throws Exception {
- super.doCheckPreconditions();
-
- if (!getArea().equals(Publication.AUTHORING_AREA)) {
- addErrorMessage("This usecase can only be invoked in the authoring area!");
- }
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
- */
- protected Node[] getNodesToLock() throws UsecaseException {
- try {
- SiteStructure structure = getPublication().getArea(getArea()).getSite();
- Node[] nodes = { structure };
- return nodes;
- } catch (Exception e) {
- throw new UsecaseException(e);
- }
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
- */
- protected void doCheckExecutionConditions() throws Exception {
- String navigationTitle = getDublinCoreParameter(DublinCore.ELEMENT_TITLE);
- if (navigationTitle.trim().equals("")) {
- addErrorMessage("missing-navigation-title");
- }
-
- if (getInitialDocument() == null) {
- String[] samples = (String[]) getParameter(SAMPLES);
- String sample = getParameterAsString(SAMPLE);
- if (samples != null && samples.length > 1 && (sample == null || sample.equals(""))) {
- addErrorMessage("missing-page-layout");
- }
- }
-
- if (isPathValid()) {
- String path = getNewDocumentPath();
- SiteStructure site = getPublication().getArea(getArea()).getSite();
- if (!createVersion() && site.contains(path)) {
- String[] params = { path };
- addErrorMessage("path-already-exists", params);
- }
- }
-
- String doctypeName = getDocumentTypeName();
- if (getParameterAsString(SAMPLE) == null && doctypeName != null) {
- initSampleParameters();
- }
- }
-
- /**
- * This method is used by {@link #doCheckExecutionConditions()} to check if the path entered by
- * the user is valid. If not, checking the existence of the new document in the site structure
- * is omitted because this operation could cause errors.
- * @return A boolean value.
- */
- protected boolean isPathValid() {
- return true;
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
- */
- protected void doExecute() throws Exception {
- super.doExecute();
-
- // create new document
- ResourceType resourceType = null;
-
- String language = getParameterAsString(LANGUAGE);
- Document initialDocument = getInitialDocument();
-
- Document document;
-
- String title = getDublinCoreParameter(DublinCore.ELEMENT_TITLE).trim();
-
- if (createVersion()) {
- document = documentManager.addVersion(initialDocument, getArea(), language, true);
- document.getLink().setLabel(title);
- } else {
- if (initialDocument == null) {
- resourceType = getResourceTypeResolver().getResourceType(getDocumentTypeName());
- String sampleName = getParameterAsString(SAMPLE, resourceType.getSampleNames()[0]);
- ResourceType.Sample sample = resourceType.getSample(sampleName);
- document = documentManager.add(resourceType, sample.getUri(),
- getPublication(), getArea(), getNewDocumentPath(), language,
- getSourceExtension(), title, getVisibleInNav());
- document.setMimeType(sample.getMimeType());
- } else {
- document = documentManager.add(initialDocument, getArea(), getNewDocumentPath(),
- language, getSourceExtension(), title, getVisibleInNav());
- }
- }
-
- setMetaData(document);
-
- // the location to navigate to after completion of usecase
- setDefaultTargetURL(document.getCanonicalWebappURL());
- }
-
- protected String getDublinCoreParameter(String name) {
- Object param = getParameter(DUBLIN_CORE_PREFIX + name);
- if (param != null && getParameter(DUBLIN_CORE_PREFIX + name).getClass().isArray()) {
- String[] values = (String[]) getParameter(DUBLIN_CORE_PREFIX + name);
- StringBuffer paramValue = new StringBuffer();
- for (int i = 0; i < values.length; i++) {
- String value = values[i];
- if (i > 0)
- paramValue.append(',').append(value);
- else
- paramValue.append(value);
- }
- return paramValue.toString();
- }
- return getParameterAsString(DUBLIN_CORE_PREFIX + name, null);
- }
-
- protected void setDublinCoreParameter(String name, String value) {
- setParameter(DUBLIN_CORE_PREFIX + name, value);
- }
-
- protected abstract boolean createVersion();
-
- /**
- * @return the extension to use for the document source.
- */
- protected abstract String getSourceExtension();
-
- /**
- * @return the name of the document being created in the usecase
- */
- protected abstract String getNewDocumentName();
-
- /**
- * @return the id of the new document being created in the usecase
- */
- protected abstract String getNewDocumentPath();
-
- /**
- * If the document created in the usecase shall have initial contents copied from an existing
- * document, construct that document in this method.
- *
- * @return A document.
- */
- protected Document getInitialDocument() {
- return null;
- }
-
- /**
- * @return The type of the created document.
- */
- protected abstract String getDocumentTypeName();
-
- protected static final String DUBLIN_CORE_PREFIX = "dublincore.";
-
- /**
- * Sets the meta data of the created document.
- *
- * @param document The document.
- * @throws MetaDataException if an error occurs.
- */
- protected void setMetaData(Document document) throws MetaDataException {
-
- if (document == null)
- throw new IllegalArgumentException("parameter document may not be null");
-
- MetaData dcMetaData = document.getMetaData(DublinCore.DC_NAMESPACE);
- String[] dcKeys = dcMetaData.getAvailableKeys();
-
- for (int i = 0; i < dcKeys.length; i++) {
- String param = getDublinCoreParameter(dcKeys[i]);
- if (param != null) {
- dcMetaData.setValue(dcKeys[i], param);
- }
- }
-
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
- */
- protected void initParameters() {
- super.initParameters();
-
- ProcessInfoProvider process = (ProcessInfoProvider) WebAppContextUtils
- .getCurrentWebApplicationContext().getBean(ProcessInfoProvider.ROLE);
- HttpServletRequest request = process.getRequest();
- HttpSession session = request.getSession(false);
- Identity identity = (Identity) session.getAttribute(Identity.class.getName());
- User user = identity.getUser();
- if (user != null) {
- setDublinCoreParameter(DublinCore.ELEMENT_CREATOR, user.getId());
- } else {
- setDublinCoreParameter(DublinCore.ELEMENT_CREATOR, "");
- }
-
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- setDublinCoreParameter(DublinCore.ELEMENT_DATE, format.format(new GregorianCalendar()
- .getTime()));
-
- String doctypeName = getDocumentTypeName();
- if (doctypeName != null) {
- initSampleParameters();
- setParameter(RESOURCE_TYPES, Collections.EMPTY_LIST);
- } else {
- String[] resourceTypes = getPublication().getResourceTypeNames();
- setParameter(RESOURCE_TYPES, Arrays.asList(resourceTypes));
- }
- }
-
- protected void initSampleParameters() {
- ResourceType resourceType = null;
- try {
- resourceType = getResourceTypeResolver().getResourceType(getDocumentTypeName());
- String[] samples = resourceType.getSampleNames();
- if (samples.length == 0) {
- addErrorMessage("The resource type [" + resourceType.getName()
- + "] doesn't provide any samples!");
- } else {
- setParameter(SAMPLES, samples);
- String presetSample = getParameterAsString(SAMPLE);
- if (presetSample == null) {
- setParameter(SAMPLE, samples[0]);
- } else {
- List sampleList = Arrays.asList(samples);
- if (!sampleList.contains(presetSample)) {
- getLogger().warn(
- "Sample [" + presetSample + "] not defined, using default sample.");
- setParameter(SAMPLE, samples[0]);
- }
- }
- }
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * @return The source document or <code>null</code> if the usecase was not invoked on a
- * document.
- */
- protected Document getSourceDocument() {
- Document document = null;
- String url = getSourceURL();
- try {
- if (getSession().getUriHandler().isDocument(url)) {
- document = getSession().getUriHandler().getDocument(url);
- }
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- return document;
- }
-
- /**
- * @return The new document.
- */
- protected Document getNewDocument() {
- try {
- String path = getNewDocumentPath();
- String language = getParameterAsString(LANGUAGE);
- return getPublication().getArea(getArea()).getSite().getNode(path).getLink(language)
- .getDocument();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * @return The area without the "info-" prefix.
- */
- public String getArea() {
- URLInformation info = new URLInformation(getSourceURL());
- return info.getArea();
- }
-
- /**
- * @return the visibleInNav Attribute of the document being created in the usecase
- */
- protected boolean getVisibleInNav() {
- if (getParameterAsString(VISIBLEINNAV).equals("false")) {
- return false;
- }
- return true;
- }
-
- protected DocumentManager getDocumentManager() {
- return documentManager;
- }
-
- /**
- * TODO: Bean wiring
- */
- public void setDocumentManager(DocumentManager documentManager) {
- this.documentManager = documentManager;
- }
-
- protected ResourceTypeResolver getResourceTypeResolver() {
- return resourceTypeResolver;
- }
-
- /**
- * TODO: Bean wiring
- */
- public void setResourceTypeResolver(ResourceTypeResolver resourceTypeResolver) {
- this.resourceTypeResolver = resourceTypeResolver;
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/CreateDocument.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/CreateDocument.java
deleted file mode 100644
index b91c82d..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/CreateDocument.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import java.util.Arrays;
-
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentBuilder;
-import org.apache.lenya.cms.publication.DocumentException;
-import org.apache.lenya.cms.publication.DocumentLocator;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationException;
-import org.apache.lenya.cms.site.SiteStructure;
-
-/**
- * Usecase to create a document.
- *
- * @version $Id$
- */
-public class CreateDocument extends Create {
-
- protected static final String PARENT_PATH = "parentPath";
-
- protected static final String DOCUMENT_TYPE = "doctype";
-
- protected static final String RELATION = "relation";
- protected static final String RELATIONS = "relations";
- protected static final String RELATION_CHILD = "child";
- protected static final String RELATION_BEFORE = "sibling before";
- protected static final String RELATION_AFTER = "sibling after";
- protected static final String PATH_PROVIDED = "pathProvided";
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
- */
- protected void initParameters() {
- super.initParameters();
-
- Document parent = getSourceDocument();
- if (parent == null) {
- setParameter(PARENT_PATH, "");
- } else {
- setParameter(LANGUAGE,parent.getLanguage());
- try {
- setParameter(PARENT_PATH, parent.getPath());
- } catch (DocumentException e) {
- throw new RuntimeException(e);
- }
- }
-
- String[] languages = getPublication().getLanguages();
- if (languages.length == 0) {
- addErrorMessage("The publication doesn't contain any languages!");
- }
- setParameter(LANGUAGES, languages);
-
- Document sourceDoc = getSourceDocument();
- String[] childOnly = { RELATION_CHILD };
- String[] childAndAfter = { RELATION_CHILD, RELATION_AFTER };
- String[] relations = sourceDoc == null ? childOnly : childAndAfter;
-
- setParameter(RELATIONS, relations);
- setParameter(RELATION, RELATION_CHILD);
-
- String path = getParameterAsString(PATH);
- boolean provided = path != null && !path.equals("");
- setParameter(PATH_PROVIDED, Boolean.valueOf(provided));
- }
-
- protected void doCheckPreconditions() throws Exception {
- super.doCheckPreconditions();
- if (getParameterAsBoolean(PATH_PROVIDED, false)) {
- validateProvidedPath();
- }
- }
-
- protected void validateProvidedPath() throws PublicationException {
- String path = getParameterAsString(PATH);
- Publication pub = getPublication();
- SiteStructure site = pub.getArea(getArea()).getSite();
- if (site.contains(path)) {
- addErrorMessage("path-already-exists");
- }
- else if (path.length() <= 2 || !path.startsWith("/") || path.endsWith("/")) {
- addErrorMessage("invalid-path");
- }
- else {
- String[] steps = path.substring(1).split("/");
- DocumentBuilder builder = pub.getDocumentBuilder();
- for (int i = 0; i < steps.length; i++) {
- if (!builder.isValidDocumentName(steps[i])) {
- addErrorMessage("node-name-special-characters");
- }
- }
- if (steps.length > 1) {
- String parentPath = path.substring(0, path.lastIndexOf("/"));
- if (!site.contains(parentPath)) {
- addErrorMessage("parent-does-not-exist");
- }
- }
- }
- }
-
- /**
- * Override this method to support other relations.
- * @return The supported relations.
- */
- protected String[] getSupportedRelations() {
- return new String[] { RELATION_CHILD, RELATION_AFTER };
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
- */
- protected void doCheckExecutionConditions() throws Exception {
- super.doCheckExecutionConditions();
-
- String relation = getParameterAsString(RELATION);
-
- if (!Arrays.asList(getSupportedRelations()).contains(relation)) {
- addErrorMessage("The relation '" + relation + "' is not supported.");
- }
-
- if (getParameterAsBoolean(PATH_PROVIDED, false)) {
- validateProvidedPath();
- } else {
- String nodeName = getNodeName();
- if (nodeName.equals("")) {
- addErrorMessage("missing-node-name");
- } else if (!getPublication().getDocumentBuilder().isValidDocumentName(nodeName)) {
- addErrorMessage("node-name-special-characters");
- }
- }
- }
-
- protected String getNodeName() {
- return getParameterAsString(NODE_NAME).trim();
- }
-
- protected boolean isPathValid() {
- String nodeName = getNewDocumentName();
- DocumentBuilder builder = getPublication().getDocumentBuilder();
- return !nodeName.trim().equals("") && builder.isValidDocumentName(nodeName);
- }
-
- /**
- * @see Create#getNewDocumentName()
- */
- protected String getNewDocumentName() {
- String nodeName;
- if (getParameterAsBoolean(PATH_PROVIDED, false)) {
- final String path = getParameterAsString(PATH);
- nodeName = path.substring(path.lastIndexOf("/") + 1);
- } else {
- nodeName = getNodeName();
- }
- return nodeName;
- }
-
- /**
- * @return The relation between the source document and the created
- * document.
- */
- protected String getRelation() {
- return getParameterAsString(RELATION);
- }
-
- /**
- * @see Create#getNewDocumentPath()
- */
- protected String getNewDocumentPath() {
- if (getParameterAsBoolean(PATH_PROVIDED, false)) {
- return getParameterAsString(PATH);
- } else {
- String relation = getRelation();
- Document sourceDoc = getSourceDocument();
- if (sourceDoc == null) {
- return "/" + getNewDocumentName();
- } else {
- DocumentLocator sourceLoc = getSourceDocument().getLocator();
- if (relation.equals(RELATION_CHILD)) {
- return sourceLoc.getChild(getNewDocumentName()).getPath();
- } else if (relation.equals(RELATION_BEFORE) || relation.equals(RELATION_AFTER)) {
- return sourceLoc.getParent().getChild(getNewDocumentName()).getPath();
- } else {
- throw new IllegalStateException("unsupported relation " + relation);
- }
- }
- }
- }
-
- /**
- * @see org.apache.lenya.cms.site.usecases.Create#getDocumentTypeName()
- */
- protected String getDocumentTypeName() {
- return getParameterAsString(DOCUMENT_TYPE);
- }
-
- protected String getSourceExtension() {
- return "xml";
- }
-
- protected boolean createVersion() {
- return false;
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/CreateLanguage.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/CreateLanguage.java
deleted file mode 100644
index 247ad7f..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/CreateLanguage.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentBuildException;
-import org.apache.lenya.cms.publication.DocumentException;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.ResourceType;
-
-/**
- * Usecase to create a new language version of a resource.
- *
- * @version $Id$
- */
-public class CreateLanguage extends Create {
-
- private String documentTypeName;
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
- */
- protected void doCheckPreconditions() throws Exception {
- super.doCheckPreconditions();
-
- if (getSourceDocument() == null) {
- addErrorMessage("This operation must be invoked on a document.");
- return;
- }
-
- String area = getSourceDocument().getArea();
- if (!area.equals(Publication.AUTHORING_AREA)) {
- addErrorMessage("This operation is only supported in the authoring area.");
- return;
- }
-
- if (getNonExistingLanguages().isEmpty()) {
- addErrorMessage("All language versions already exist.");
- }
- }
-
- /**
- * @return All languages supported by the publication for which this document does not yet have
- * a version
- * @throws DocumentBuildException if an error occurs.
- * @throws DocumentException if an error occurs.
- */
- protected List getNonExistingLanguages() throws DocumentBuildException, DocumentException {
- Document source = getSourceDocument();
- List nonExistingLanguages = new ArrayList();
- String[] languages = source.getPublication().getLanguages();
- for (int i = 0; i < languages.length; i++) {
- if (!source.existsTranslation(languages[i])) {
- nonExistingLanguages.add(languages[i]);
- }
- }
- return nonExistingLanguages;
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
- */
- protected void initParameters() {
- super.initParameters();
-
- Document source = getSourceDocument();
- if (source != null) {
- try {
- setParameter(PATH, source.getPath());
- List nonExistingLanguages = getNonExistingLanguages();
- setParameter(LANGUAGES, nonExistingLanguages
- .toArray(new String[nonExistingLanguages.size()]));
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- }
-
- /**
- * For new language version of a document, name is the same as that document's
- * @see Create#getNewDocumentName()
- */
- protected String getNewDocumentName() {
- return getSourceDocument().getName();
- }
-
- /**
- * For new language version of a document, the path is the same as that document's
- * @see Create#getNewDocumentPath()
- */
- protected String getNewDocumentPath() {
- try {
- return getSourceDocument().getPath();
- } catch (DocumentException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * New language version of a document: use that document's content
- * @see Create#getInitialDocument()
- */
- protected Document getInitialDocument() {
- return getSourceDocument();
- }
-
- /**
- * @see Create#getDocumentTypeName()
- */
- protected String getDocumentTypeName() {
- if (this.documentTypeName == null && getSourceDocument() != null) {
- try {
- ResourceType type = getSourceDocument().getResourceType();
- this.documentTypeName = type.getName();
-
- List nonExistingLanguages = getNonExistingLanguages();
- setParameter(LANGUAGES, nonExistingLanguages
- .toArray(new String[nonExistingLanguages.size()]));
-
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- return this.documentTypeName;
- }
-
- protected String getSourceExtension() {
- return getSourceDocument().getSourceExtension();
- }
-
- protected boolean createVersion() {
- return true;
- }
-
-}
\ No newline at end of file
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Cut.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Cut.java
deleted file mode 100644
index 4780739..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Cut.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.cocoon.processing.ProcessInfoProvider;
-import org.apache.cocoon.spring.configurator.WebAppContextUtils;
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.site.SiteStructure;
-import org.apache.lenya.cms.usecase.DocumentUsecase;
-
-/**
- * Cut a document into the clipboard.
- *
- * @version $Id$
- */
-public class Cut extends DocumentUsecase {
-
- protected static final String MESSAGE_ISLIVE = "cut-error-islive";
-
- protected void doCheckPreconditions() throws Exception {
- super.doCheckPreconditions();
- if (hasErrors()) {
- return;
- }
-
- Document doc = getSourceDocument();
- if (!doc.getArea().equals(Publication.AUTHORING_AREA)) {
- addErrorMessage("only-in-authoring-area");
- }
- SiteStructure liveSite = doc.getPublication().getArea(Publication.LIVE_AREA).getSite();
- if (liveSite.contains(doc.getPath())) {
- addErrorMessage(MESSAGE_ISLIVE);
- }
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
- */
- protected void doExecute() throws Exception {
- super.doExecute();
-
- Clipboard clipboard = new Clipboard(getSourceDocument(), Clipboard.METHOD_CUT);
- ClipboardHelper helper = new ClipboardHelper();
- helper.saveClipboard(getRequest(), clipboard);
- }
-
- protected HttpServletRequest getRequest() {
- ProcessInfoProvider process = (ProcessInfoProvider) WebAppContextUtils
- .getCurrentWebApplicationContext().getBean(ProcessInfoProvider.ROLE);
- return process.getRequest();
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Delete.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Delete.java
deleted file mode 100644
index d7374be..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Delete.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import org.apache.lenya.cms.publication.Publication;
-
-/**
- * Delete a document and all its descendants, including all language versions. The documents are
- * moved to the trash.
- *
- * @version $Id$
- */
-public class Delete extends MoveSubsite {
-
- /**
- * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getSourceAreas()
- */
- protected String[] getSourceAreas() {
- return new String[] { Publication.AUTHORING_AREA, Publication.ARCHIVE_AREA };
- }
-
- /**
- * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getTargetArea()
- */
- protected String getTargetArea() {
- return Publication.TRASH_AREA;
- }
-
- /**
- * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getEvent()
- */
- protected String getEvent() {
- return "delete";
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/DeleteLanguage.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/DeleteLanguage.java
deleted file mode 100644
index d63e17f..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/DeleteLanguage.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.Node;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.util.DocumentHelper;
-import org.apache.lenya.cms.usecase.DocumentUsecase;
-import org.apache.lenya.cms.usecase.UsecaseException;
-
-/**
- * Delete a language version.
- *
- * @version $Id$
- */
-public class DeleteLanguage extends DocumentUsecase {
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
- */
- protected void doCheckPreconditions() throws Exception {
- super.doCheckPreconditions();
- if (hasErrors()) {
- return;
- }
-
- Document doc = getSourceDocument();
-
- if (!doc.getArea().equals(Publication.AUTHORING_AREA)) {
- addErrorMessage("This usecase can only be invoked in the authoring area!");
- } else if (doc.getLanguages().length == 1) {
- addErrorMessage("The last language version cannot be removed.");
- }
-
- if (doc.existsVersion(Publication.LIVE_AREA, doc.getLanguage())) {
- addErrorMessage("The document can't be deleted if a live version exists.");
- }
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
- */
- protected Node[] getNodesToLock() throws UsecaseException {
- List nodes = new ArrayList();
- if(getSourceDocument() != null) {
- Node docNode = getSourceDocument();
- Node siteNode = getSourceDocument().area().getSite();
- nodes.add(docNode);
- nodes.add(siteNode);
- }
- return (Node[]) nodes.toArray(new Node[nodes.size()]);
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
- */
- protected void doExecute() throws Exception {
- super.doExecute();
-
- Document document = getSourceDocument();
- document.getLink().delete();
- document.delete();
-
- setTargetDocument(DocumentHelper.getExistingLanguageVersion(document));
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/EmptyTrash.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/EmptyTrash.java
deleted file mode 100644
index e292e18..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/EmptyTrash.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-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.DocumentManager;
-import org.apache.lenya.cms.publication.Node;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationException;
-import org.apache.lenya.cms.publication.URLInformation;
-import org.apache.lenya.cms.publication.util.DocumentSet;
-import org.apache.lenya.cms.site.SiteException;
-import org.apache.lenya.cms.site.SiteStructure;
-import org.apache.lenya.cms.usecase.AbstractUsecase;
-import org.apache.lenya.cms.usecase.UsecaseException;
-
-/**
- * Empty the trash.
- *
- * @version $Id$
- */
-public class EmptyTrash extends AbstractUsecase {
-
- protected static final String DOCUMENTS = "documents";
-
- private DocumentManager documentManager;
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
- */
- protected void initParameters() {
- super.initParameters();
- try {
- Document[] documents = getTrashDocuments();
- setParameter(DOCUMENTS, Arrays.asList(documents));
- } catch (SiteException e) {
- throw new RuntimeException(e);
- } catch (PublicationException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Lock the following objects:
- * <ul>
- * <li>all involved documents in the trash area</li>
- * <li>the document trash site structure</li>
- * </ul>
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
- */
- protected Node[] getNodesToLock() throws UsecaseException {
- List nodes = new ArrayList();
- try {
- String pubId = new URLInformation(getSourceURL()).getPublicationId();
- Publication publication = getSession().getPublication(pubId);
- Document[] docs = getTrashDocuments();
- for (int i = 0; i < docs.length; i++) {
- nodes.add(docs[i]);
- }
- SiteStructure structure = publication.getArea(Publication.TRASH_AREA).getSite();
- nodes.add(structure);
- } catch (Exception e) {
- throw new UsecaseException(e);
- }
- return (Node[]) nodes.toArray(new Node[nodes.size()]);
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
- */
- protected void doExecute() throws Exception {
- super.doExecute();
- Document[] documents = getTrashDocuments();
- DocumentSet set = new DocumentSet(documents);
- getDocumentManager().delete(set);
- }
-
- /**
- * @return The documents in the trash area.
- * @throws PublicationException if an error occurs.
- * @throws SiteException if an error occurs.
- */
- protected Document[] getTrashDocuments() throws PublicationException, SiteException {
- String pubId = new URLInformation(getSourceURL()).getPublicationId();
- Publication pub = getSession().getPublication(pubId);
- return pub.getArea(Publication.TRASH_AREA).getDocuments();
- }
-
- protected DocumentManager getDocumentManager() {
- return documentManager;
- }
-
- /**
- * TODO: Bean wiring
- */
- public void setDocumentManager(DocumentManager documentManager) {
- this.documentManager = documentManager;
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ForceCheckIn.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ForceCheckIn.java
deleted file mode 100644
index 9b8f03b..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ForceCheckIn.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Vector;
-import java.util.WeakHashMap;
-
-import javax.servlet.http.HttpSession;
-
-import org.apache.lenya.ac.Identity;
-import org.apache.lenya.ac.User;
-import org.apache.lenya.cms.metadata.dublincore.DublinCoreHelper;
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.Node;
-import org.apache.lenya.cms.usecase.DocumentUsecase;
-import org.apache.lenya.modules.monitoring.SessionListener;
-
-/**
- * Force a document to be checked in (override a checkout).
- */
-public class ForceCheckIn extends DocumentUsecase {
-
- private static final String IDENTITY = Identity.class.getName();
- private static final String HISTORY = "org.apache.lenya.cms.cocoon.acting.History";
-
- protected void doCheckPreconditions() throws Exception {
- super.doCheckPreconditions();
-
- Document doc = getSourceDocument();
- if (doc == null) {
- return;
- }
-
- Node node = doc;
- if (!node.isCheckedOut()) {
- String[] params = { DublinCoreHelper.getTitle(doc, true) };
- addErrorMessage("not-checked-out", params);
- }
- }
-
- protected void prepareView() throws Exception {
- Node node = getSourceDocument();
- if (node.isCheckedOut()) {
- String userId = node.getCheckoutUserId();
- User currentUser = getSession().getIdentity().getUser();
- if (currentUser == null || !userId.equals(currentUser.getId())) {
- String[] params = { userId };
- if (isLoggedIn(userId)) {
- addInfoMessage("user-logged-in", params);
- }
- else {
- addInfoMessage("user-not-logged-in", params);
- }
- }
- }
- }
-
- protected boolean isLoggedIn(String userId) {
- String pubId = getSourceDocument().getPublication().getId();
- SessionListener sessions = new SessionListener();
- WeakHashMap allSessions = sessions.getAllSessions();
-
- boolean loggedIn = false;
- Iterator userit = allSessions.entrySet().iterator();
- while (userit.hasNext()) {
- Map.Entry entry = (Map.Entry) userit.next();
- HttpSession nextsession = (HttpSession) entry.getValue();
-
- Identity identity = (Identity) nextsession.getAttribute(IDENTITY);
-
- if(identity == null) {
- continue;
- }
-
- User user = identity.getUser();
- Vector history = (Vector) nextsession.getAttribute(HISTORY);
- String publicationID = getPublicationIDfromHistory(history);
- if (publicationID.equals(pubId) && user != null && user.getId().equals(userId)) {
- loggedIn = true;
- }
- }
- return loggedIn;
- }
-
- protected void doExecute() throws Exception {
- super.doExecute();
- getSourceDocument().forceCheckIn();
- }
-
- /**
- * Extract the publicationID from the history information stored in the
- * session
- *
- * @param history The history stored in the session.. An entry looks like \/
- * <publication-id>/authoring/index.html
- * @return A publication ID.
- */
- private String getPublicationIDfromHistory(Vector history) {
- String firstElement = history.firstElement().toString();
- String publicationID = firstElement.substring(1, firstElement.indexOf("/", 1));
- return publicationID;
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ForceLiveCheckIn.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ForceLiveCheckIn.java
deleted file mode 100644
index e0ae7b1..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/ForceLiveCheckIn.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import org.apache.lenya.cms.publication.Node;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationException;
-import org.apache.lenya.cms.usecase.AbstractUsecase;
-
-/**
- * Force check in of the live node
- *
- */
-public class ForceLiveCheckIn extends AbstractUsecase {
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
- */
- protected void doCheckPreconditions() throws Exception {
- super.doCheckPreconditions();
- Publication pub = getPublication();
- if(pub == null) {
- return;
- }
- Node node = getNode();
- if (!node.isCheckedOut()) {
- String[] params = { "Live" };
- addErrorMessage("not-checked-out", params);
- }
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
- */
- protected void doExecute() throws Exception {
- super.doExecute();
-
- getNode().forceCheckIn();
-
- }
-
- private Node getNode() throws PublicationException {
- return getPublication().getArea(Publication.LIVE_AREA).getSite();
- }
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Move.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Move.java
deleted file mode 100644
index caf073e..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Move.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import org.apache.lenya.cms.site.usecases.SiteUsecase;
-import org.apache.lenya.cms.usecase.UsecaseException;
-
-/**
- * Usecase to move a resource.
- *
- * @version $Id$
- */
-public class Move extends SiteUsecase {
-
- /**
- * Ctor.
- */
- public Move() {
- super();
- }
-
- /**
- * Validates the request parameters.
- * @throws UsecaseException if an error occurs.
- */
- void validate() throws UsecaseException {
- // do nothing
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
- */
- protected void doCheckExecutionConditions() throws Exception {
- validate();
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
- */
- protected void doExecute() throws Exception {
- super.doExecute();
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.Usecase#setParameter(java.lang.String,
- * java.lang.Object)
- */
- public void setParameter(String name, Object value) {
- super.setParameter(name, value);
- }
-}
\ No newline at end of file
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/MoveSubsite.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/MoveSubsite.java
deleted file mode 100644
index 62f11fa..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/MoveSubsite.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.commons.lang.Validate;
-import org.apache.lenya.cms.publication.Area;
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentLocator;
-import org.apache.lenya.cms.publication.DocumentManager;
-import org.apache.lenya.cms.publication.Node;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationException;
-import org.apache.lenya.cms.site.Link;
-import org.apache.lenya.cms.site.NodeSet;
-import org.apache.lenya.cms.site.SiteException;
-import org.apache.lenya.cms.site.SiteNode;
-import org.apache.lenya.cms.site.SiteStructure;
-import org.apache.lenya.cms.site.SiteUtil;
-import org.apache.lenya.cms.usecase.DocumentUsecase;
-import org.apache.lenya.cms.usecase.UsecaseException;
-import org.apache.lenya.cms.workflow.WorkflowUtil;
-import org.apache.lenya.cms.workflow.usecases.UsecaseWorkflowHelper;
-import org.apache.lenya.workflow.Workflowable;
-
-/**
- * Usecase to move a subsite to another area.
- *
- * @version $Id:$
- */
-public abstract class MoveSubsite extends DocumentUsecase {
-
- /**
- * @return The possible source areas.
- */
- protected abstract String[] getSourceAreas();
-
- /**
- * @return The target area.
- */
- protected abstract String getTargetArea();
-
- private DocumentManager documentManager;
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
- */
- protected void doCheckPreconditions() throws Exception {
- super.doCheckPreconditions();
- if (hasErrors()) {
- return;
- }
-
- List sourceAreas = Arrays.asList(getSourceAreas());
- if (!sourceAreas.contains(getSourceDocument().getArea())) {
- addErrorMessage("This usecase can only be invoked in the authoring area!");
- } else {
-
- Document document = getSourceDocument();
-
- NodeSet subsite = SiteUtil.getSubSite(document.getLink().getNode());
- Document[] docs = subsite.getDocuments();
- for (int i = 0; i < docs.length; i++) {
- if (docs[i].existsAreaVersion(Publication.LIVE_AREA)) {
- Document liveVersion = docs[i].getAreaVersion(Publication.LIVE_AREA);
- addErrorMessage("delete-doc-live", new String[] { liveVersion.toString() });
- }
- UsecaseWorkflowHelper.checkWorkflow(this, getEvent(), docs[i], getLogger());
- }
- }
- }
-
- /**
- * @return The workflow event.
- */
- protected abstract String getEvent();
-
- /**
- * Lock all source documents and the site structure repository nodes because changes to the site
- * structure would compromise the operation.
- */
- protected Node[] getNodesToLock() throws UsecaseException {
- Set nodes = new HashSet();
-
- if (getSourceDocument() != null) {
- try {
-
- SiteStructure sourceSite = getSourceDocument().area().getSite();
- SiteStructure targetSite = getSourceDocument().getPublication().getArea(
- getTargetArea()).getSite();
-
- nodes.add(sourceSite);
- nodes.add(targetSite);
-
- Document[] docs = SiteUtil.getSubSite(getSourceDocument().getLink().getNode())
- .getDocuments();
- for (int i = 0; i < docs.length; i++) {
- nodes.add(docs[i]);
- }
-
- } catch (PublicationException e) {
- throw new UsecaseException(e);
- }
- }
-
- return (Node[]) nodes.toArray(new Node[nodes.size()]);
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
- */
- protected void doExecute() throws Exception {
-
- String targetAreaName = getTargetArea();
- Document doc = getSourceDocument();
- Document[] sources = SiteUtil.getSubSite(doc.getLink().getNode()).getDocuments();
- Area targetArea = doc.getPublication().getArea(targetAreaName);
-
- DocumentLocator targetLoc = doc.getLocator().getAreaVersion(targetAreaName);
- targetLoc = SiteUtil.getAvailableLocator(getSession(), targetLoc);
-
- for (int i = 0; i < sources.length; i++) {
- WorkflowUtil.invoke(sources[i], getEvent(), true);
-
- if (this.getClass().getName().equals(Restore.class.getName())) {
- Workflowable workflowable = WorkflowUtil.getWorkflowable(sources[i]);
- String state = workflowable.getLatestVersion().getState();
- if (!state.equals("authoring")) {
- addErrorMessage("The state is [" + state + "] instead of [authoring]!");
- }
- }
-
- }
-
- getDocumentManager().moveAll(doc.area(), doc.getPath(), targetArea, targetLoc.getPath());
-
- setTargetDocument(doc.getAreaVersion(targetAreaName));
-
- }
-
- public String getTargetURL(boolean success) {
- if (getTargetArea().equals(Publication.AUTHORING_AREA)) {
- return super.getTargetURL(success);
- }
-
- String url;
- if (!success) {
- url = getSourceURL();
- } else {
- try {
- Document document = getTargetDocument(success);
- SiteStructure site = document.getPublication().getArea(Publication.AUTHORING_AREA)
- .getSite();
- return getTargetUrl(site, document.getPath()) + getExitQueryString();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- return url + getExitQueryString();
- }
-
- protected static String getTargetUrl(SiteStructure site, String path) throws SiteException {
- if (path.length() == 0) {
- return "/" + site.getPublication().getId() + "/" + site.getArea() + "/";
- } else if (site.contains(path)) {
- SiteNode node = site.getNode(path);
- if (node.getLanguages().length > 0) {
- Link link;
- String defaultLanguage = site.getPublication().getDefaultLanguage();
- if (node.hasLink(defaultLanguage)) {
- link = node.getLink(defaultLanguage);
- } else {
- link = node.getLink(node.getLanguages()[0]);
- }
- return link.getDocument().getCanonicalWebappURL();
- } else {
- return getTargetUrl(site, getParentPath(path));
- }
- } else {
- return getTargetUrl(site, getParentPath(path));
- }
- }
-
- protected static String getParentPath(String path) {
- Validate.notNull(path);
- Validate.notEmpty(path);
- return path.substring(0, path.lastIndexOf("/"));
- }
-
- protected DocumentManager getDocumentManager() {
- return documentManager;
- }
-
- /**
- * TODO: Bean wiring
- */
- public void setDocumentManager(DocumentManager documentManager) {
- this.documentManager = documentManager;
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Overview.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Overview.java
deleted file mode 100644
index 43adffc..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Overview.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Date;
-
-import org.apache.lenya.cms.metadata.MetaData;
-import org.apache.lenya.cms.metadata.dublincore.DublinCore;
-import org.apache.lenya.cms.publication.Area;
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.URLInformation;
-import org.apache.lenya.cms.site.usecases.SiteUsecase;
-import org.apache.lenya.cms.workflow.WorkflowUtil;
-import org.apache.lenya.workflow.Version;
-import org.apache.lenya.workflow.Workflow;
-import org.apache.lenya.workflow.WorkflowManager;
-import org.apache.lenya.workflow.Workflowable;
-
-/**
- * Usecase to display the overview tab in the site area for a document.
- *
- * @version $Id$
- */
-public class Overview extends SiteUsecase {
-
- protected static final String LASTMODIFIED = "lastmodified";
- protected static final String LANGUAGES = "languages";
- protected static final String STATE = "state";
- protected static final String ISLIVE = "isLive";
- protected static final String VISIBLE_IN_NAVIGATION = "visibleInNav";
- protected static final String WORKFLOW_VARIABLE_ISLIVE = "is_live";
- protected static final String PARAM_NUMBER_OF_DOCUMENTS = "numberOfDocuments";
- protected static final String PARAM_NUMBER_OF_SITE_NODES = "numberOfSiteNodes";
-
- private WorkflowManager workflowManager;
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
- */
- protected void initParameters() {
- super.initParameters();
-
- try {
- Document doc = getSourceDocument();
- if (doc == null) {
- URLInformation info = new URLInformation(getSourceURL());
- Publication pub = getSession().getPublication(info.getPublicationId());
- Area area = pub.getArea(info.getArea());
- setParameter(PARAM_NUMBER_OF_DOCUMENTS, new Integer(area.getDocuments().length));
- setParameter(PARAM_NUMBER_OF_SITE_NODES, new Integer(area.getSite().getNodes().length));
- }
- else {
- // read parameters from Dublin Core meta-data
- MetaData dc = doc.getMetaData(DublinCore.DC_NAMESPACE);
- setParameter(DublinCore.ELEMENT_TITLE, dc.getFirstValue(DublinCore.ELEMENT_TITLE));
- setParameter(DublinCore.ELEMENT_DESCRIPTION, dc
- .getFirstValue(DublinCore.ELEMENT_DESCRIPTION));
-
- // read parameters from document attributes
- setParameter(LANGUAGES, doc.getLanguages());
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
- String lastModified = format
- .format(new Date(getSourceDocument().getLastModified()));
- setParameter(LASTMODIFIED, lastModified);
- boolean visible = doc.getLink().getNode().isVisible();
- setParameter(VISIBLE_IN_NAVIGATION, Boolean.valueOf(visible));
-
- Workflowable workflowable = WorkflowUtil.getWorkflowable(doc);
- if (getWorkflowManager().hasWorkflow(workflowable)) {
- Workflow workflow = getWorkflowManager().getWorkflowSchema(workflowable);
- String[] variableNames = workflow.getVariableNames();
- Version latestVersion = workflowable.getLatestVersion();
- Boolean isLive = null;
- if (latestVersion != null) {
- setParameter(STATE, latestVersion.getState());
- if (Arrays.asList(variableNames).contains(WORKFLOW_VARIABLE_ISLIVE)) {
- isLive = Boolean.valueOf(latestVersion
- .getValue(WORKFLOW_VARIABLE_ISLIVE));
- }
- } else {
- setParameter(STATE, workflow.getInitialState());
- if (Arrays.asList(variableNames).contains(WORKFLOW_VARIABLE_ISLIVE)) {
- isLive = Boolean.valueOf(workflow
- .getInitialValue(WORKFLOW_VARIABLE_ISLIVE));
- }
- }
- setParameter(ISLIVE, isLive);
- } else {
- setParameter(STATE, "");
- }
- }
-
- } catch (final Exception e) {
- addErrorMessage("Could not read a value. See log files for details.");
- getLogger().error("Could not read value for Overview usecase. ", e);
- }
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
- */
- protected void doCheckPreconditions() throws Exception {
- // don't complain if document is null
- }
-
- protected WorkflowManager getWorkflowManager() {
- return workflowManager;
- }
-
- /**
- * TODO: Bean wiring
- */
- public void setWorkflowManager(WorkflowManager workflowManager) {
- this.workflowManager = workflowManager;
- }
-
-}
\ No newline at end of file
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Paste.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Paste.java
deleted file mode 100644
index ff22639..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Paste.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.cocoon.processing.ProcessInfoProvider;
-import org.apache.cocoon.spring.configurator.WebAppContextUtils;
-import org.apache.lenya.cms.publication.Area;
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentBuildException;
-import org.apache.lenya.cms.publication.DocumentException;
-import org.apache.lenya.cms.publication.DocumentLocator;
-import org.apache.lenya.cms.publication.DocumentManager;
-import org.apache.lenya.cms.publication.Node;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.URLInformation;
-import org.apache.lenya.cms.site.NodeSet;
-import org.apache.lenya.cms.site.SiteException;
-import org.apache.lenya.cms.site.SiteNode;
-import org.apache.lenya.cms.site.SiteUtil;
-import org.apache.lenya.cms.usecase.AbstractUsecase;
-import org.apache.lenya.cms.usecase.UsecaseException;
-
-/**
- * Paste a document from the clipboard.
- *
- * @version $Id$
- */
-public class Paste extends AbstractUsecase {
-
- protected static final String CLIPBOARD_LABEL = "clipboardLabel";
-
- private DocumentManager documentManager;
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
- */
- protected void doCheckPreconditions() throws Exception {
- super.doCheckPreconditions();
-
- if (hasErrors()) {
- return;
- }
-
- if (!getArea().getName().equals(Publication.AUTHORING_AREA)) {
- addErrorMessage("only-in-authoring-area");
- }
-
- Clipboard clipboard = new ClipboardHelper().getClipboard(getRequest());
- if (clipboard == null) {
- addErrorMessage("clipboard-empty");
- } else {
- Document doc = getSourceDocument();
- if (doc != null) {
- Document clippedDoc = clipboard.getDocument(getSession());
- String uuid = clippedDoc.getUUID();
- SiteNode node = doc.getLink().getNode();
- if (clipboard.getMethod() == Clipboard.METHOD_CUT) {
- if (willPasteInOwnSubtree(node, uuid)) {
- addErrorMessage("will-paste-in-own-subtree");
- }
- }
- }
- }
- }
-
- protected boolean willPasteInOwnSubtree(SiteNode node, String uuid) throws SiteException {
- String nodeUuid = node.getUuid();
- if (nodeUuid.equals(uuid)) {
- return true;
- } else if (!node.isTopLevel()) {
- return willPasteInOwnSubtree(node.getParent(), uuid);
- } else {
- return false;
- }
- }
-
- protected Document getSourceDocument() {
- Document doc = null;
- String sourceUrl = getParameterAsString(SOURCE_URL);
- if (getSession().getUriHandler().isDocument(sourceUrl)) {
- doc = getSession().getUriHandler().getDocument(sourceUrl);
- }
- return doc;
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
- */
- protected void initParameters() {
- super.initParameters();
-
- Clipboard clipboard = new ClipboardHelper().getClipboard(getRequest());
- if (clipboard != null) {
- String label;
- try {
- label = clipboard.getDocument(getSession()).getLink().getLabel();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- setParameter(CLIPBOARD_LABEL, label);
- }
- }
-
- protected Publication getPublication() {
- URLInformation info = new URLInformation(getSourceURL());
- String pubId = info.getPublicationId();
- return getSession().getPublication(pubId);
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
- */
- protected Node[] getNodesToLock() throws UsecaseException {
- List nodes = new ArrayList();
-
- try {
-
- Clipboard clipboard = new ClipboardHelper().getClipboard(getRequest());
- if (clipboard != null) {
-
- Node siteNode = getArea().getSite();
- nodes.add(siteNode);
-
- Publication pub = getPublication();
- Document clippedDocument = clipboard.getDocument(getSession());
-
- NodeSet subsite = SiteUtil.getSubSite(clippedDocument.getLink().getNode());
- Document[] subsiteDocs = subsite.getDocuments();
-
- for (int i = 0; i < subsiteDocs.length; i++) {
- if (clipboard.getMethod() == Clipboard.METHOD_CUT) {
- nodes.add(subsiteDocs[i]);
- }
- }
- }
-
- } catch (Exception e) {
- throw new UsecaseException(e);
- }
-
- return (Node[]) nodes.toArray(new Node[nodes.size()]);
- }
-
- protected Area getArea() {
- Publication pub = getPublication();
- URLInformation info = new URLInformation(getSourceURL());
- return pub.getArea(info.getArea());
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
- */
- protected void doExecute() throws Exception {
- super.doExecute();
-
- ClipboardHelper helper = new ClipboardHelper();
-
- HttpServletRequest request = getRequest();
- Clipboard clipboard = helper.getClipboard(request);
- Publication pub = getPublication();
- Document clippedDocument = clipboard.getDocument(getSession());
-
- final String targetPath = getTargetPath();
- final Area area = clippedDocument.area();
- if (clipboard.getMethod() == Clipboard.METHOD_COPY) {
- getDocumentManager().copyAll(area, clippedDocument.getPath(), area, targetPath);
- } else if (clipboard.getMethod() == Clipboard.METHOD_CUT) {
- getDocumentManager().moveAll(area, clippedDocument.getPath(), area, targetPath);
- } else {
- throw new RuntimeException("This clipboard method is not supported!");
- }
-
- helper.removeClipboard(request);
- }
-
- protected String getTargetPath() throws SiteException, DocumentBuildException,
- ServiceException, DocumentException {
- Clipboard clipboard = new ClipboardHelper().getClipboard(getRequest());
- Publication pub = getPublication();
- Document clippedDocument = clipboard.getDocument(getSession());
-
- String targetArea = getArea().getName();
- String language = clippedDocument.getLanguage();
- String nodeId = clippedDocument.getName();
-
- Document sourceDoc = getSourceDocument();
- String basePath = sourceDoc != null ? sourceDoc.getPath() : "";
-
- String potentialPath = basePath + "/" + nodeId;
-
- DocumentLocator potentialLoc = DocumentLocator.getLocator(getPublication().getId(),
- targetArea, potentialPath, language);
- return SiteUtil.getAvailableLocator(getSession(), potentialLoc).getPath();
- }
-
- protected HttpServletRequest getRequest() {
- ProcessInfoProvider process = (ProcessInfoProvider) WebAppContextUtils
- .getCurrentWebApplicationContext().getBean(ProcessInfoProvider.ROLE);
- return process.getRequest();
- }
-
- protected DocumentManager getDocumentManager() {
- return documentManager;
- }
-
- /**
- * TODO: Bean wiring
- */
- public void setDocumentManager(DocumentManager documentManager) {
- this.documentManager = documentManager;
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Restore.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Restore.java
deleted file mode 100644
index 6ece53a..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Restore.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import org.apache.lenya.cms.publication.Area;
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentLocator;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.site.SiteUtil;
-import org.apache.lenya.cms.workflow.WorkflowUtil;
-import org.apache.lenya.workflow.Workflowable;
-
-/**
- * Restore usecase handler.
- *
- * @version $Id:$
- */
-public class Restore extends MoveSubsite {
-
- /**
- * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getSourceAreas()
- */
- protected String[] getSourceAreas() {
- return new String[] { Publication.TRASH_AREA, Publication.ARCHIVE_AREA };
- }
-
- /**
- * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getTargetArea()
- */
- protected String getTargetArea() {
- return Publication.AUTHORING_AREA;
- }
-
- /**
- * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getEvent()
- */
- protected String getEvent() {
- return "restore";
- }
-
- protected void doCheckPreconditions() throws Exception {
- super.doCheckPreconditions();
-
- String targetAreaName = getTargetArea();
- Document doc = getSourceDocument();
- if (doc == null) {
- return;
- }
- // Check to see if parent node exists in target to prevent ghost nodes
- Area targetArea = doc.getPublication().getArea(targetAreaName);
- DocumentLocator targetLoc = doc.getLocator().getAreaVersion(targetAreaName);
- targetLoc = SiteUtil.getAvailableLocator(getSession(), targetLoc);
- String targetPath = targetLoc.getPath();
- targetPath = targetPath.substring(0, targetPath.lastIndexOf('/'));
- if (!targetArea.getSite().contains(targetPath)) {
- addErrorMessage("The authoring path [" + targetPath + "] does not exist.");
- }
- }
-
- protected void doCheckPostconditions() throws Exception {
- super.doCheckPostconditions();
-
- Document doc = getTargetDocument(true);
- Workflowable workflowable = WorkflowUtil.getWorkflowable(doc);
- String state = workflowable.getLatestVersion().getState();
- if (!state.equals("authoring")) {
- addErrorMessage("The state is [" + state + "] instead of [authoring]!");
- }
-
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Revisions.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Revisions.java
deleted file mode 100644
index 470a5ee..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Revisions.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.History;
-import org.apache.lenya.cms.workflow.WorkflowUtil;
-import org.apache.lenya.workflow.Version;
-import org.apache.lenya.workflow.Workflow;
-import org.apache.lenya.workflow.Workflowable;
-
-/**
- * Usecase to display revisions of a resource.
- *
- * @version $Id$
- */
-public class Revisions extends SiteUsecase {
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters() TODO filter out checkin
- * entries
- */
- protected void initParameters() {
- super.initParameters();
- Document sourceDoc = getSourceDocument();
- if (sourceDoc != null) {
- try {
- History history = sourceDoc.getHistory();
-
- int[] numbers = history.getRevisionNumbers();
- Document[] revisions = new Document[numbers.length];
- for (int i = 0; i < numbers.length; i++) {
- revisions[i] = sourceDoc.getRevision(numbers[i]);
- }
- setParameter("revisions", revisions);
-
- Boolean canRollback = Boolean
- .valueOf(WorkflowUtil.canInvoke(sourceDoc, getEvent()));
- setParameter("canRollback", canRollback);
-
- if (WorkflowUtil.hasWorkflow(sourceDoc)) {
- Workflowable workflowable = WorkflowUtil.getWorkflowable(sourceDoc);
- Version latestVersion = workflowable.getLatestVersion();
- String state;
- if (latestVersion != null) {
- state = latestVersion.getState();
- } else {
- Workflow workflow = WorkflowUtil.getWorkflowSchema(sourceDoc);
- state = workflow.getInitialState();
- }
- setParameter("workflowState", state);
- }
- } catch (final Exception e) {
- throw new RuntimeException(e);
- }
-
- /*
- * // since we need both state and canInvoke, we could deal with the avalon // component
- * ourselves rather than using WorkflowUtil - saves one // service manager lookup. //
- * problem is that DocumentWorkflowable is not public and Workflowable is abstract :(
- *
- * WorkflowManager wfManager = null; String workflowState; Boolean canRollback; try {
- * wfManager = (WorkflowManager) this.manager.lookup(WorkflowManager.ROLE); Workflowable
- * workflowable = new DocumentWorkflowable( this.manager,
- * getDocumentFactory().getSession(), sourceDoc, getLogger() ); workflowState =
- * workflowable.getLatestVersion().getState(); canRollback = new
- * Boolean(wfManager.canInvoke(workflowable, WORKFLOW_EVENT_EDIT)); } catch
- * (ServiceException e) { throw new RuntimeException(e); } finally { if (wfManager !=
- * null) { manager.release(wfManager); } } setParameter("workflowState", workflowState);
- * setParameter("canRollback", canRollback);
- */
-
- }
- }
-
- protected String getEvent() {
- return getParameterAsString("workflowEvent");
- }
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Rollback.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Rollback.java
deleted file mode 100644
index c5a7f43..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/Rollback.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import org.apache.lenya.cms.usecase.DocumentUsecase;
-import org.apache.lenya.cms.usecase.UsecaseException;
-import org.apache.lenya.cms.workflow.WorkflowUtil;
-import org.apache.lenya.cms.workflow.usecases.UsecaseWorkflowHelper;
-
-/**
- * Rollback.
- */
-public class Rollback extends DocumentUsecase {
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
- */
- protected org.apache.lenya.cms.publication.Node[] getNodesToLock() throws UsecaseException {
- org.apache.lenya.cms.publication.Node[] objects = { getSourceDocument() };
- return objects;
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
- */
- protected void doCheckPreconditions() throws Exception {
- super.doCheckPreconditions();
- UsecaseWorkflowHelper.checkWorkflow(this, getEvent(), getSourceDocument(), getLogger());
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
- */
- protected void doExecute() throws Exception {
- super.doExecute();
-
- int revision = getParameterAsInteger("rollbackRevision", -1);
-
- getSourceDocument().rollback(revision);
-
- WorkflowUtil.invoke(getSourceDocument(), getEvent());
- }
-
- protected String getEvent() {
- return getParameterAsString("workflowEvent");
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/SiteOverview.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/SiteOverview.java
deleted file mode 100644
index be30877..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/SiteOverview.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentException;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationException;
-import org.apache.lenya.cms.publication.RepositoryException;
-import org.apache.lenya.cms.publication.ResourceType;
-import org.apache.lenya.cms.site.SiteException;
-import org.apache.lenya.cms.usecase.AbstractUsecase;
-import org.apache.lenya.cms.workflow.WorkflowUtil;
-import org.apache.lenya.workflow.Version;
-import org.apache.lenya.workflow.Workflow;
-import org.apache.lenya.workflow.WorkflowException;
-import org.apache.lenya.workflow.Workflowable;
-
-/**
- * Overview over all documents.
- */
-public class SiteOverview extends AbstractUsecase {
-
- protected static final String ALL_DOCUMENTS = "allDocuments";
- protected static final String DOCUMENTS = "documents";
- protected static final String FILTER_WORKFLOW_STATE_VALUES = "filterWorkflowStateValues";
- protected static final String FILTER_RESOURCE_TYPE_VALUES = "filterResourceTypeValues";
-
- protected static final String KEY_PATH = "keyPath";
- protected static final String KEY_RESOURCE_TYPE = "keyResourceType";
- protected static final String KEY_WORKFLOW_STATE = "keyWorkflowState";
- protected static final String KEY_LANGUAGE = "keyLanguage";
- protected static final String KEY_LAST_MODIFIED = "keyLastModified";
- protected static final String KEY_URL = "keyUrl";
- protected static final String KEY_CHECKED_OUT = "keyCheckedOut";
- protected static final String KEY_CONTENT_LENGTH = "keyContentLength";
- protected static final String PARAMETER_KEYS = "keys";
-
- protected static final String[] KEYS = { KEY_PATH, KEY_LANGUAGE, KEY_RESOURCE_TYPE,
- KEY_WORKFLOW_STATE, KEY_LAST_MODIFIED, KEY_CONTENT_LENGTH, KEY_CHECKED_OUT };
-
- protected static final String FILTER_RESOURCE_TYPE = "filterResourceType";
- protected static final String FILTER_WORKFLOW_STATE = "filterWorkflowState";
- protected static final String FILTER_LANGUAGE = "filterLanguage";
- protected static final String PARAMETER_FILTERS = "filters";
-
- protected static final String[] FILTERS = { FILTER_LANGUAGE, FILTER_RESOURCE_TYPE,
- FILTER_WORKFLOW_STATE };
-
- protected static final String VALUE_ALL = "- all -";
-
- protected static final String SORT = "sort";
-
- protected static final String ORDER = "order";
-
- protected static final String DESC = "desc";
- protected static final String ASC = "asc";
-
- protected void prepareView() throws Exception {
- super.prepareView();
- setDefaultParameter(SORT, KEY_PATH);
- setDefaultParameter(ORDER, ASC);
-
- try {
- Document[] documents = getDocuments();
- List entries = new ArrayList();
- for (int i = 0; i < documents.length; i++) {
- entries.add(createEntry(documents[i]));
- }
-
- prepareFilters(entries);
-
- List filteredDocuments = filter(entries);
- sort(filteredDocuments);
- setParameter(DOCUMENTS, filteredDocuments);
-
- setParameter(PARAMETER_KEYS, Arrays.asList(KEYS));
-
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- protected void setDefaultParameter(String name, String value) {
- if (getParameter(name) == null) {
- setParameter(name, value);
- }
- }
-
- protected Entry createEntry(Document doc) throws DocumentException, WorkflowException,
- RepositoryException {
- Entry entry = new Entry();
- if (doc.hasLink()) {
- entry.setValue(KEY_PATH, doc.getPath());
- } else {
- entry.setValue(KEY_PATH, "not in site structure");
- }
- entry.setValue(KEY_RESOURCE_TYPE, ResourceType.I18N_PREFIX
- + doc.getResourceType().getName());
- entry.setValue(KEY_LANGUAGE, doc.getLanguage());
- entry.setValue(KEY_URL, doc.getCanonicalWebappURL());
- entry.setValue(KEY_CONTENT_LENGTH, "" + (doc.getContentLength() / 1000));
-
- DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String lastModified = format.format(new Date(doc.getLastModified()));
- entry.setValue(KEY_LAST_MODIFIED, lastModified);
-
- if (WorkflowUtil.hasWorkflow(doc)) {
- Workflowable workflowable = WorkflowUtil.getWorkflowable(doc);
- Version latestVersion = workflowable.getLatestVersion();
- String state;
- if (latestVersion != null) {
- state = latestVersion.getState();
- } else {
- Workflow workflow = WorkflowUtil.getWorkflowSchema(doc);
- state = workflow.getInitialState();
- }
- entry.setValue(KEY_WORKFLOW_STATE, state);
- } else {
- entry.setValue(KEY_WORKFLOW_STATE, "");
- }
-
- if (doc.isCheckedOut()) {
- entry.setValue(KEY_CHECKED_OUT, doc.getCheckoutUserId());
- } else {
- entry.setValue(KEY_CHECKED_OUT, "");
- }
- return entry;
- }
-
- protected void prepareFilters(List entries) {
- for (int i = 0; i < FILTERS.length; i++) {
- SortedSet filterValues = new TreeSet();
- filterValues.add(VALUE_ALL);
-
- String key = "key" + FILTERS[i].substring("filter".length());
-
- for (Iterator docs = entries.iterator(); docs.hasNext();) {
- Entry entry = (Entry) docs.next();
- filterValues.add(entry.getValue(key));
- }
- setParameter(FILTERS[i] + "Values", filterValues);
- setDefaultParameter(FILTERS[i], VALUE_ALL);
- }
- setParameter(PARAMETER_FILTERS, Arrays.asList(FILTERS));
- }
-
- protected void sort(List documents) {
- String sort = getParameterAsString(SORT);
- String order = getParameterAsString(ORDER, ASC);
- if (sort != null) {
- Comparator comparator = new EntryComparator(sort, order);
- Collections.sort(documents, comparator);
- }
- }
-
- protected List filter(List entries) {
- List filteredDocuments = new ArrayList(entries);
-
- for (int i = 0; i < FILTERS.length; i++) {
- String key = "key" + FILTERS[i].substring("filter".length());
- String filterValue = getParameterAsString(FILTERS[i]);
- if (!filterValue.equals(VALUE_ALL)) {
- Entry[] allEntries = (Entry[]) filteredDocuments
- .toArray(new Entry[filteredDocuments.size()]);
- for (int entryIndex = 0; entryIndex < allEntries.length; entryIndex++) {
- if (!allEntries[entryIndex].getValue(key).equals(filterValue)) {
- filteredDocuments.remove(allEntries[entryIndex]);
- }
- }
- }
- }
- return filteredDocuments;
- }
-
- /**
- * @return The documents in the authoring area.
- * @throws PublicationException if an error occurs.
- * @throws SiteException if an error occurs.
- */
- protected Document[] getDocuments() throws PublicationException, SiteException {
- return getPublication().getArea(Publication.AUTHORING_AREA).getDocuments();
- }
-
- /**
- * Comparator for entries.
- */
- public static class EntryComparator implements Comparator {
-
- private String key;
- private String order;
-
- /**
- * @param key The key to compare.
- * @param order The order string ({@link SiteOverview#ASC} or {@link SiteOverview#DESC}).
- */
- public EntryComparator(String key, String order) {
- this.key = key;
- this.order = order;
- }
-
- /**
- * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
- */
- public int compare(Object arg0, Object arg1) {
- Entry e1 = (Entry) arg0;
- Entry e2 = (Entry) arg1;
-
- String value1 = e1.getValue(this.key);
- String value2 = e2.getValue(this.key);
- if (this.order.equals(DESC))
- return value2.compareTo(value1);
- else
- return value1.compareTo(value2);
- }
-
- }
-
- /**
- * Stores document-related information.
- */
- public static class Entry {
-
- private Map values = new HashMap();
-
- /**
- * Ctor.
- */
- public Entry() {
- }
-
- /**
- * @param key The key.
- * @param value The value.
- */
- public void setValue(String key, String value) {
- this.values.put(key, value);
- }
-
- /**
- * @param key The key.
- * @return The value.
- */
- public String getValue(String key) {
- return (String) this.values.get(key);
- }
-
- }
-
-}
diff --git a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/SiteUsecase.java b/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/SiteUsecase.java
deleted file mode 100644
index f98ad05..0000000
--- a/org.apache.lenya.core.sitemanagement/src/main/java/org/apache/lenya/cms/site/usecases/SiteUsecase.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.lenya.cms.site.usecases;
-
-import org.apache.lenya.cms.usecase.DocumentUsecase;
-
-/**
- * Super class for site related usecases.
- *
- * @version $Id$
- */
-public class SiteUsecase extends DocumentUsecase {
-
-
-}
\ No newline at end of file