Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DefaultSiteTree.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DefaultSiteTree.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DefaultSiteTree.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DefaultSiteTree.java Wed Jan 30 23:44:03 2008
@@ -16,7 +16,6 @@
*/
/* @version $Id$ */
package org.apache.lenya.cms.publication;
-
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -35,556 +34,533 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-
/**
* Default Sitetree implementation
*/
public class DefaultSiteTree implements SiteTree, LastModified {
- private static Logger log = Logger.getLogger(DefaultSiteTree.class);
- private static Object lock = new Object();
- public static final String SITE_TREE_FILENAME = "sitetree.xml";
- private Document document = null;
- private File treefile = null;
- // the area is only retained to provide some more info when raising an
- // exception.
- private String area = "";
- private long lastModified = 0;
- /**
- * Create a DefaultSiteTree
- *
- * @param pubDir
- * the publication directory
- * @param area
- * the area
- *
- * @throws SiteTreeException
- * if an error occurs
- */
- protected DefaultSiteTree(File pubDir, String area) throws SiteTreeException {
- this(new File(pubDir, Publication.CONTENT_PATH + File.separator + area + File.separator + SITE_TREE_FILENAME));
- this.area = area;
- }
- /**
- * Create a DefaultSiteTree from a filename.
- *
- * @param treefilename
- * file name of the tree
- *
- * @throws SiteTreeException
- * if an error occurs
- *
- * @deprecated use the DefaultSiteTree(File pubDir, String area) constructor
- * instead.
- */
- public DefaultSiteTree(String treefilename) throws SiteTreeException {
- this(new File(treefilename));
- }
- /**
- * Create a DefaultSiteTree from a file.
- *
- * @param treefile
- * the file containing the tree
- *
- * @throws SiteTreeException
- * if an error occurs
- *
- * @deprecated this constructor will be private in the future
- */
- public DefaultSiteTree(File treefile) throws SiteTreeException {
- this.treefile = treefile;
- try {
- if (!treefile.isFile()) {
- // the treefile doesn't exist, so create it
- document = createDocument();
- } else {
- // Read tree
- document = DocumentHelper.readDocument(treefile);
+ private static Logger log = Logger.getLogger(DefaultSiteTree.class);
+ private static Object lock = new Object();
+ public static final String SITE_TREE_FILENAME = "sitetree.xml";
+ private Document document = null;
+ private File treefile = null;
+ // the area is only retained to provide some more info when raising an
+ // exception.
+ private String area = "";
+ private long lastModified = 0;
+ /**
+ * Create a DefaultSiteTree
+ *
+ * @param pubDir
+ * the publication directory
+ * @param area
+ * the area
+ *
+ * @throws SiteTreeException
+ * if an error occurs
+ */
+ protected DefaultSiteTree(File pubDir, String area) throws SiteTreeException {
+ this(new File(pubDir, Publication.CONTENT_PATH + File.separator + area + File.separator + SITE_TREE_FILENAME));
+ this.area = area;
+ }
+ /**
+ * Create a DefaultSiteTree from a filename.
+ *
+ * @param treefilename
+ * file name of the tree
+ *
+ * @throws SiteTreeException
+ * if an error occurs
+ *
+ * @deprecated use the DefaultSiteTree(File pubDir, String area) constructor instead.
+ */
+ public DefaultSiteTree(String treefilename) throws SiteTreeException {
+ this(new File(treefilename));
+ }
+ /**
+ * Create a DefaultSiteTree from a file.
+ *
+ * @param treefile
+ * the file containing the tree
+ *
+ * @throws SiteTreeException
+ * if an error occurs
+ *
+ * @deprecated this constructor will be private in the future
+ */
+ public DefaultSiteTree(File treefile) throws SiteTreeException {
+ this.treefile = treefile;
+ try{
+ if(!treefile.isFile()){
+ // the treefile doesn't exist, so create it
+ document = createDocument();
+ }else{
+ // Read tree
+ document = DocumentHelper.readDocument(treefile);
+ }
+ }catch(ParserConfigurationException e){
+ throw new SiteTreeException(e);
+ }catch(SAXException e){
+ throw new SiteTreeException(e);
+ }catch(IOException e){
+ throw new SiteTreeException(e);
+ }
+ }
+ /**
+ * Checks if the tree file has been modified externally and reloads the site tree.
+ *
+ * @throws SiteTreeException
+ * when something went wrong.
+ */
+ protected synchronized void checkModified() {
+ if(area.equals(Publication.LIVE_AREA) && treefile.isFile() && treefile.lastModified() > lastModified){
+ if(log.isDebugEnabled()){
+ log.debug("Sitetree [" + treefile + "] has changed: reloading.");
+ }
+ try{
+ document = DocumentHelper.readDocument(treefile);
+ }catch(Exception e){
+ throw new IllegalStateException(e.getMessage());
+ }
+ lastModified = treefile.lastModified();
+ }
+ }
+ /**
+ * Create a new DefaultSiteTree xml document.
+ *
+ * @return the new site document
+ *
+ * @throws ParserConfigurationException
+ * if an error occurs
+ */
+ public synchronized Document createDocument() throws ParserConfigurationException {
+ document = DocumentHelper.createDocument(NAMESPACE_URI, "site", null);
+ Element root = document.getDocumentElement();
+ root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ root.setAttribute("xsi:schemaLocation", "http://apache.org/cocoon/lenya/sitetree/1.0 ../../../../resources/entities/sitetree.xsd");
+ return document;
+ }
+ /**
+ * Find a node in a subtree. The search is started at the given node. The list of ids contains the document-id split by "/".
+ *
+ * @param node
+ * where to start the search
+ * @param ids
+ * list of node ids
+ *
+ * @return the node that matches the path given in the list of ids
+ */
+ protected synchronized Node findNode(Node node, List ids) {
+ checkModified();
+ if(ids.size() < 1){
+ return node;
+ }else{
+ NodeList nodes = node.getChildNodes();
+ for(int i = 0; i < nodes.getLength(); i++){
+ NamedNodeMap attributes = nodes.item(i).getAttributes();
+ if(attributes != null){
+ Node idAttribute = attributes.getNamedItem("id");
+ if(idAttribute != null && !"".equals(idAttribute.getNodeValue()) && idAttribute.getNodeValue().equals(ids.get(0))){
+ return findNode(nodes.item(i), ids.subList(1, ids.size()));
+ }
}
- } catch (ParserConfigurationException e) {
- throw new SiteTreeException(e);
- } catch (SAXException e) {
- throw new SiteTreeException(e);
- } catch (IOException e) {
- throw new SiteTreeException(e);
- }
- }
- /**
- * Checks if the tree file has been modified externally and reloads the site
- * tree.
- *
- * @throws SiteTreeException
- * when something went wrong.
- */
- protected synchronized void checkModified() {
- if (area.equals(Publication.LIVE_AREA) && treefile.isFile() && treefile.lastModified() > lastModified) {
- if (log.isDebugEnabled()) {
- log.debug("Sitetree [" + treefile + "] has changed: reloading.");
- }
- try {
- document = DocumentHelper.readDocument(treefile);
- } catch (Exception e) {
- throw new IllegalStateException(e.getMessage());
- }
- lastModified = treefile.lastModified();
- }
- }
- /**
- * Create a new DefaultSiteTree xml document.
- *
- * @return the new site document
- *
- * @throws ParserConfigurationException
- * if an error occurs
- */
- public synchronized Document createDocument() throws ParserConfigurationException {
- document = DocumentHelper.createDocument(NAMESPACE_URI, "site", null);
- Element root = document.getDocumentElement();
- root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
- root.setAttribute("xsi:schemaLocation", "http://apache.org/cocoon/lenya/sitetree/1.0 ../../../../resources/entities/sitetree.xsd");
- return document;
- }
- /**
- * Find a node in a subtree. The search is started at the given node. The
- * list of ids contains the document-id split by "/".
- *
- * @param node
- * where to start the search
- * @param ids
- * list of node ids
- *
- * @return the node that matches the path given in the list of ids
- */
- protected synchronized Node findNode(Node node, List ids) {
- checkModified();
- if (ids.size() < 1) {
- return node;
- } else {
- NodeList nodes = node.getChildNodes();
- for (int i = 0; i < nodes.getLength(); i++) {
- NamedNodeMap attributes = nodes.item(i).getAttributes();
- if (attributes != null) {
- Node idAttribute = attributes.getNamedItem("id");
- if (idAttribute != null && !"".equals(idAttribute.getNodeValue()) && idAttribute.getNodeValue().equals(ids.get(0))) {
- return findNode(nodes.item(i), ids.subList(1, ids.size()));
- }
- }
- }
- }
- // node wasn't found
- return null;
- }
- /**
- * (non-Javadoc)
- *
- * @see org.apache.lenya.cms.publication.SiteTree#addNode(org.apache.lenya.cms.publication.SiteTreeNode,
- * java.lang.String)
- */
- public synchronized void addNode(SiteTreeNode node, String refDocumentId) throws SiteTreeException {
- this.addNode(node.getAbsoluteParentId(), node.getId(), node.getLabels(), node.visibleInNav(), node.getHref(), node.getSuffix(), node.hasLink(), refDocumentId);
- }
- /**
- * (non-Javadoc)
- *
- * @see org.apache.lenya.cms.publication.SiteTree#addNode(java.lang.String,
- * java.lang.String, org.apache.lenya.cms.publication.Label[])
- */
- public synchronized void addNode(String parentid, String id, Label[] labels, boolean visibleInNav) throws SiteTreeException {
- addNode(parentid, id, labels, visibleInNav, null, null, false);
- }
- /**
- * (non-Javadoc)
- *
- * @see org.apache.lenya.cms.publication.SiteTree#addNode(java.lang.String,
- * java.lang.String, org.apache.lenya.cms.publication.Label[], boolean)
- */
- public synchronized void addNode(String parentid, String id, Label[] labels) throws SiteTreeException {
- addNode(parentid, id, labels, true);
- }
- /**
- * (non-Javadoc)
- *
- * @see org.apache.lenya.cms.publication.SiteTree#addNode(org.apache.lenya.cms.publication.SiteTreeNode)
- */
- public synchronized void addNode(SiteTreeNode node) throws SiteTreeException {
- this.addNode(node, null);
- }
- /**
- * (non-Javadoc)
- *
- * @see org.apache.lenya.cms.publication.SiteTree#addNode(java.lang.String,
- * org.apache.lenya.cms.publication.Label[], java.lang.String,
- * java.lang.String, boolean, java.lang.String)
- */
- public synchronized void addNode(String documentid, Label[] labels, boolean visibleInNav, String href, String suffix, boolean link, String refDocumentId) throws SiteTreeException {
- String parentid = "";
- StringTokenizer st = new StringTokenizer(documentid, "/");
- int length = st.countTokens();
- for (int i = 0; i < (length - 1); i++) {
- parentid = parentid + "/" + st.nextToken();
- }
- String id = st.nextToken();
- this.addNode(parentid, id, labels, visibleInNav, href, suffix, link, refDocumentId);
- }
- /**
- * (non-Javadoc)
- *
- * @see org.apache.lenya.cms.publication.SiteTree#addNode(java.lang.String,
- * org.apache.lenya.cms.publication.Label[], java.lang.String,
- * java.lang.String, boolean)
- */
- public synchronized void addNode(String documentid, Label[] labels, boolean visibleInNav, String href, String suffix, boolean link) throws SiteTreeException {
- this.addNode(documentid, labels, visibleInNav, href, suffix, link, null);
- }
- /**
- * (non-Javadoc)
- *
- * @see org.apache.lenya.cms.publication.SiteTree#addNode(java.lang.String,
- * java.lang.String, org.apache.lenya.cms.publication.Label[],
- * java.lang.String, java.lang.String, boolean)
- */
- public synchronized void addNode(String parentid, String id, Label[] labels, boolean visibleInNav, String href, String suffix, boolean link) throws SiteTreeException {
- this.addNode(parentid, id, labels, visibleInNav, href, suffix, link, null);
- }
- /**
- * (non-Javadoc)
- *
- * @see org.apache.lenya.cms.publication.SiteTree#addNode(java.lang.String,
- * java.lang.String, org.apache.lenya.cms.publication.Label[],
- * java.lang.String, java.lang.String, boolean)
- */
- public synchronized void addNode(String parentid, String id, Label[] labels, boolean visibleInNav, String href, String suffix, boolean link, String refDocumentId) throws SiteTreeException {
- Node parentNode = getNodeInternal(parentid);
- if (parentNode == null) {
- throw new SiteTreeException("Parentid: " + parentid + " in " + area + " tree not found");
- }
- log.debug("PARENT ELEMENT: " + parentNode);
- // Check if child already exists
- Node childNode = getNodeInternal(parentid + "/" + id);
- if (childNode != null) {
- log.info("This node: " + parentid + "/" + id + " has already been inserted");
- return;
- }
- // Create node
- NamespaceHelper helper = new NamespaceHelper(NAMESPACE_URI, "", document);
- Element child = helper.createElement(SiteTreeNodeImpl.NODE_NAME);
- child.setAttribute(SiteTreeNodeImpl.ID_ATTRIBUTE_NAME, id);
- if (visibleInNav) {
- child.setAttribute(SiteTreeNodeImpl.VISIBLEINNAV_ATTRIBUTE_NAME, "true");
- } else {
- child.setAttribute(SiteTreeNodeImpl.VISIBLEINNAV_ATTRIBUTE_NAME, "false");
- }
- if ((href != null) && (href.length() > 0)) {
- child.setAttribute(SiteTreeNodeImpl.HREF_ATTRIBUTE_NAME, href);
- }
- if ((suffix != null) && (suffix.length() > 0)) {
- child.setAttribute(SiteTreeNodeImpl.SUFFIX_ATTRIBUTE_NAME, suffix);
- }
- if (link) {
- child.setAttribute(SiteTreeNodeImpl.LINK_ATTRIBUTE_NAME, "true");
- }
- for (int i = 0; i < labels.length; i++) {
- String labelName = labels[i].getLabel();
- Element label = helper.createElement(SiteTreeNodeImpl.LABEL_NAME, labelName);
- String labelLanguage = labels[i].getLanguage();
- if ((labelLanguage != null) && (labelLanguage.length() > 0)) {
- label.setAttribute(SiteTreeNodeImpl.LANGUAGE_ATTRIBUTE_NAME, labelLanguage);
- }
- child.appendChild(label);
- }
- // Add Node
- if (refDocumentId != null && !refDocumentId.equals("")) {
- Node nextSibling = getNodeInternal(refDocumentId);
- if (nextSibling != null) {
- parentNode.insertBefore(child, nextSibling);
- } else {
- parentNode.appendChild(child);
- }
- } else {
+ }
+ }
+ // node wasn't found
+ return null;
+ }
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.lenya.cms.publication.SiteTree#addNode(org.apache.lenya.cms.publication.SiteTreeNode, java.lang.String)
+ */
+ public synchronized void addNode(SiteTreeNode node, String refDocumentId) throws SiteTreeException {
+ this.addNode(node.getAbsoluteParentId(), node.getId(), node.getLabels(), node.visibleInNav(), node.getHref(), node.getSuffix(), node.hasLink(), refDocumentId);
+ }
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.lenya.cms.publication.SiteTree#addNode(java.lang.String, java.lang.String, org.apache.lenya.cms.publication.Label[])
+ */
+ public synchronized void addNode(String parentid, String id, Label[] labels, boolean visibleInNav) throws SiteTreeException {
+ addNode(parentid, id, labels, visibleInNav, null, null, false);
+ }
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.lenya.cms.publication.SiteTree#addNode(java.lang.String, java.lang.String, org.apache.lenya.cms.publication.Label[], boolean)
+ */
+ public synchronized void addNode(String parentid, String id, Label[] labels) throws SiteTreeException {
+ addNode(parentid, id, labels, true);
+ }
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.lenya.cms.publication.SiteTree#addNode(org.apache.lenya.cms.publication.SiteTreeNode)
+ */
+ public synchronized void addNode(SiteTreeNode node) throws SiteTreeException {
+ this.addNode(node, null);
+ }
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.lenya.cms.publication.SiteTree#addNode(java.lang.String, org.apache.lenya.cms.publication.Label[], java.lang.String, java.lang.String, boolean, java.lang.String)
+ */
+ public synchronized void addNode(String documentid, Label[] labels, boolean visibleInNav, String href, String suffix, boolean link, String refDocumentId) throws SiteTreeException {
+ String parentid = "";
+ StringTokenizer st = new StringTokenizer(documentid, "/");
+ int length = st.countTokens();
+ for(int i = 0; i < (length - 1); i++){
+ parentid = parentid + "/" + st.nextToken();
+ }
+ String id = st.nextToken();
+ this.addNode(parentid, id, labels, visibleInNav, href, suffix, link, refDocumentId);
+ }
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.lenya.cms.publication.SiteTree#addNode(java.lang.String, org.apache.lenya.cms.publication.Label[], java.lang.String, java.lang.String, boolean)
+ */
+ public synchronized void addNode(String documentid, Label[] labels, boolean visibleInNav, String href, String suffix, boolean link) throws SiteTreeException {
+ this.addNode(documentid, labels, visibleInNav, href, suffix, link, null);
+ }
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.lenya.cms.publication.SiteTree#addNode(java.lang.String, java.lang.String, org.apache.lenya.cms.publication.Label[], java.lang.String, java.lang.String, boolean)
+ */
+ public synchronized void addNode(String parentid, String id, Label[] labels, boolean visibleInNav, String href, String suffix, boolean link) throws SiteTreeException {
+ this.addNode(parentid, id, labels, visibleInNav, href, suffix, link, null);
+ }
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.lenya.cms.publication.SiteTree#addNode(java.lang.String, java.lang.String, org.apache.lenya.cms.publication.Label[], java.lang.String, java.lang.String, boolean)
+ */
+ public synchronized void addNode(String parentid, String id, Label[] labels, boolean visibleInNav, String href, String suffix, boolean link, String refDocumentId) throws SiteTreeException {
+ Node parentNode = getNodeInternal(parentid);
+ if(parentNode == null){
+ throw new SiteTreeException("Parentid: " + parentid + " in " + area + " tree not found");
+ }
+ log.debug("PARENT ELEMENT: " + parentNode);
+ // Check if child already exists
+ Node childNode = getNodeInternal(parentid + "/" + id);
+ if(childNode != null){
+ log.info("This node: " + parentid + "/" + id + " has already been inserted");
+ return;
+ }
+ // Create node
+ NamespaceHelper helper = new NamespaceHelper(NAMESPACE_URI, "", document);
+ Element child = helper.createElement(SiteTreeNodeImpl.NODE_NAME);
+ child.setAttribute(SiteTreeNodeImpl.ID_ATTRIBUTE_NAME, id);
+ if(visibleInNav){
+ child.setAttribute(SiteTreeNodeImpl.VISIBLEINNAV_ATTRIBUTE_NAME, "true");
+ }else{
+ child.setAttribute(SiteTreeNodeImpl.VISIBLEINNAV_ATTRIBUTE_NAME, "false");
+ }
+ if((href != null) && (href.length() > 0)){
+ child.setAttribute(SiteTreeNodeImpl.HREF_ATTRIBUTE_NAME, href);
+ }
+ if((suffix != null) && (suffix.length() > 0)){
+ child.setAttribute(SiteTreeNodeImpl.SUFFIX_ATTRIBUTE_NAME, suffix);
+ }
+ if(link){
+ child.setAttribute(SiteTreeNodeImpl.LINK_ATTRIBUTE_NAME, "true");
+ }
+ for(int i = 0; i < labels.length; i++){
+ String labelName = labels[i].getLabel();
+ Element label = helper.createElement(SiteTreeNodeImpl.LABEL_NAME, labelName);
+ String labelLanguage = labels[i].getLanguage();
+ if((labelLanguage != null) && (labelLanguage.length() > 0)){
+ label.setAttribute(SiteTreeNodeImpl.LANGUAGE_ATTRIBUTE_NAME, labelLanguage);
+ }
+ child.appendChild(label);
+ }
+ // Add Node
+ if(refDocumentId != null && !refDocumentId.equals("")){
+ Node nextSibling = getNodeInternal(refDocumentId);
+ if(nextSibling != null){
+ parentNode.insertBefore(child, nextSibling);
+ }else{
parentNode.appendChild(child);
- }
- log.debug("Tree has been modified: " + document.getDocumentElement());
- }
- /**
- * (non-Javadoc)
- *
- * @see org.apache.lenya.cms.publication.SiteTree#addLabel(java.lang.String,
- * org.apache.lenya.cms.publication.Label)
- */
- public synchronized void addLabel(String documentId, Label label) {
- SiteTreeNode node = getNode(documentId);
- if (node != null) {
- node.addLabel(label);
- }
- }
- /**
- * (non-Javadoc)
- *
- * @see org.apache.lenya.cms.publication.SiteTree#removeLabel(java.lang.String,
- * org.apache.lenya.cms.publication.Label)
- */
- public synchronized void removeLabel(String documentId, Label label) {
- SiteTreeNode node = getNode(documentId);
- if (node != null) {
- node.removeLabel(label);
- }
- }
- /**
- * (non-Javadoc)
- *
- * @see org.apache.lenya.cms.publication.SiteTree#removeNode(java.lang.String)
- */
- public synchronized SiteTreeNode removeNode(String documentId) {
- // assert documentId != null;
- Node node = removeNodeInternal(documentId);
- if (node == null) {
- return null;
- }
- return new SiteTreeNodeImpl(node, this);
- }
- /*
- * (non-Javadoc)
- *
- * @see org.apache.lenya.cms.publication.SiteTree#deleteNode(java.lang.String)
- */
- public void deleteNode(String documentId) throws SiteTreeException {
- Node node = this.getNodeInternal(documentId);
- Node parentNode = node.getParentNode();
- Node newNode = parentNode.removeChild(node);
- }
- /**
- * removes the node corresponding to the given document-id and returns it
- *
- * @param documentId
- * the document-id of the Node to be removed
- *
- * @return the <code>Node</code> that was removed
- */
- private synchronized Node removeNodeInternal(String documentId) {
- Node node = this.getNodeInternal(documentId);
- Node parentNode = node.getParentNode();
- Node newNode = parentNode.removeChild(node);
- return newNode;
- }
- /**
- * Find a node for a given document-id
- *
- * @param documentId
- * the document-id of the Node that we're trying to get
- *
- * @return the Node if there is a Node for the given document-id, null
- * otherwise
- */
- private synchronized Node getNodeInternal(String documentId) {
- StringTokenizer st = new StringTokenizer(documentId, "/");
- ArrayList ids = new ArrayList();
- while (st.hasMoreTokens()) {
- ids.add(st.nextToken());
- }
- Node node = findNode(document.getDocumentElement(), ids);
- return node;
- }
- /**
- * @see org.apache.lenya.cms.publication.SiteTree#getNode(java.lang.String)
- */
- public synchronized SiteTreeNode getNode(String documentId) {
- // assert documentId != null;
- SiteTreeNode treeNode = null;
- Node node = getNodeInternal(documentId);
- if (node != null) {
- treeNode = new SiteTreeNodeImpl(node, this);
- }
- return treeNode;
- }
- /**
- * @see org.apache.lenya.cms.publication.SiteTree#getTopNodes()
- */
- public SiteTreeNode[] getTopNodes() {
- List childElements = new ArrayList();
- NamespaceHelper helper = new NamespaceHelper(NAMESPACE_URI, "", document);
- Element[] elements = helper.getChildren((Element) document.getDocumentElement(), SiteTreeNodeImpl.NODE_NAME);
- for (int i = 0; i < elements.length; i++) {
- SiteTreeNode newNode = new SiteTreeNodeImpl(elements[i], this);
- childElements.add(newNode);
- }
- return (SiteTreeNode[]) childElements.toArray(new SiteTreeNode[childElements.size()]);
- }
- /**
- * Move up the node amongst its siblings.
- *
- * @param documentid
- * The document id for the node.
- * @throws SiteTreeException
- * if the moving failed.
- */
- public synchronized void moveUp(String documentid) throws SiteTreeException {
- Node node = this.getNodeInternal(documentid);
- if (node == null) {
- throw new SiteTreeException("Node to move: " + documentid + " not found");
- }
- Node parentNode = node.getParentNode();
- if (parentNode == null) {
- throw new SiteTreeException("Parentid of node with documentid: " + documentid + " not found");
- }
- Node previousNode;
- try {
- previousNode = XPathAPI.selectSingleNode(node, "(preceding-sibling::*[local-name() = 'node'])[last()]");
- } catch (TransformerException e) {
- throw new SiteTreeException(e);
- }
- if (previousNode == null) {
- log.warn("Couldn't found a preceding sibling");
- return;
- }
- Node insertNode = parentNode.removeChild(node);
- parentNode.insertBefore(insertNode, previousNode);
- }
- /**
- * Move down the node amongst its siblings.
- *
- * @param documentid
- * The document id for the node.
- * @throws SiteTreeException
- * if the moving failed.
- */
- public synchronized void moveDown(String documentid) throws SiteTreeException {
- Node node = this.getNodeInternal(documentid);
- if (node == null) {
- throw new SiteTreeException("Node to move: " + documentid + " not found");
- }
- Node parentNode = node.getParentNode();
- if (parentNode == null) {
- throw new SiteTreeException("Parentid of node with documentid: " + documentid + " not found");
- }
- Node nextNode;
- try {
- nextNode = XPathAPI.selectSingleNode(node, "following-sibling::*[local-name() = 'node'][position()=2]");
- } catch (TransformerException e) {
- throw new SiteTreeException(e);
- }
- Node insertNode = parentNode.removeChild(node);
- if (nextNode == null) {
- log.warn("Couldn't found the second following sibling");
- parentNode.appendChild(insertNode);
- } else {
- parentNode.insertBefore(insertNode, nextNode);
- }
- }
- /**
- * (non-Javadoc)
- *
- * @see org.apache.lenya.cms.publication.SiteTree#importSubtree(org.apache.lenya.cms.publication.SiteTreeNode,
- * org.apache.lenya.cms.publication.SiteTreeNode, java.lang.String)
- */
- public synchronized void importSubtree(SiteTreeNode newParent, SiteTreeNode subtreeRoot, String newid, String refDocumentId) throws SiteTreeException {
- // assert subtreeRoot != null;
- // assert newParent != null;
- String parentId = newParent.getAbsoluteId();
- String id = newid;
- this.addNode(parentId, id, subtreeRoot.getLabels(), subtreeRoot.visibleInNav(), subtreeRoot.getHref(), subtreeRoot.getSuffix(), subtreeRoot.hasLink(), refDocumentId);
- newParent = this.getNode(parentId + "/" + id);
- if (newParent == null) {
- throw new SiteTreeException("The added node was not found.");
- }
- SiteTreeNode[] children = subtreeRoot.getChildren();
- if (children == null) {
- log.info("The node " + subtreeRoot.toString() + " has no children");
- return;
- } else {
- for (int i = 0; i < children.length; i++) {
- importSubtree(newParent, children[i], children[i].getId(), null);
- }
- }
- }
- /**
- * (non-Javadoc)
- *
- * @see org.apache.lenya.cms.publication.SiteTree#save()
- */
- public synchronized void save() throws SiteTreeException {
- try {
- DocumentHelper.writeDocument(document, treefile);
- } catch (TransformerException e) {
- throw new SiteTreeException("The document [" + document.getLocalName() + "] could not be transformed");
- } catch (IOException e) {
- throw new SiteTreeException("The saving of document [" + document.getLocalName() + "] failed");
- }
- lastModified = new Date().getTime();
- }
- /**
- * @see org.apache.lenya.cms.publication.SiteTree#setLabel(java.lang.String,
- * org.apache.lenya.cms.publication.Label)
- */
- public synchronized void setLabel(String documentId, Label label) {
- SiteTreeNode node = getNode(documentId);
- if (node != null) {
- node.setLabel(label);
- }
- }
- /**
- * @see org.apache.lenya.cms.publication.SiteTree#copy(org.apache.lenya.cms.publication.SiteTreeNode,
- * org.apache.lenya.cms.publication.SiteTreeNode, java.lang.String,
- * java.lang.String)
- */
- public void copy(SiteTreeNode src, SiteTreeNode dst, String newId, String followingSibling) throws SiteTreeException {
- // assert dst instanceof SiteTreeNodeImpl;
- SiteTreeNodeImpl dstNode = (SiteTreeNodeImpl) dst;
- if (this.equals(dstNode.getDefaultSiteTree())) {
- // Copy if this sitetree is the destination sitetree.
- // Acquire global sitetree lock to establish lock hierarchy in case
- // of copy operation
- synchronized (DefaultSiteTree.lock) {
- DefaultSiteTree srcSiteTree = ((SiteTreeNodeImpl) src).getDefaultSiteTree();
- synchronized (srcSiteTree) {
- synchronized (this) {
- String parentId = dst.getAbsoluteId();
- String id = newId;
- this.addNode(parentId, id, src.getLabels(), src.visibleInNav(), src.getHref(), src.getSuffix(), src.hasLink(), followingSibling);
- SiteTreeNode node = this.getNode(parentId + "/" + id);
- if (node == null) {
- throw new SiteTreeException("The added node was not found.");
- }
- SiteTreeNode[] children = src.getChildren();
- if (children == null) {
- log.debug("The node " + src.toString() + " has no children");
- return;
- } else {
- for (int i = 0; i < children.length; i++) {
- copy(children[i], node, children[i].getId(), null);
- }
- }
- }
- }
+ }
+ }else{
+ parentNode.appendChild(child);
+ }
+ log.debug("Tree has been modified: " + document.getDocumentElement());
+ }
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.lenya.cms.publication.SiteTree#addLabel(java.lang.String, org.apache.lenya.cms.publication.Label)
+ */
+ public synchronized void addLabel(String documentId, Label label) {
+ SiteTreeNode node = getNode(documentId);
+ if(node != null){
+ node.addLabel(label);
+ }
+ }
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.lenya.cms.publication.SiteTree#removeLabel(java.lang.String, org.apache.lenya.cms.publication.Label)
+ */
+ public synchronized void removeLabel(String documentId, Label label) {
+ SiteTreeNode node = getNode(documentId);
+ if(node != null){
+ node.removeLabel(label);
+ }
+ }
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.lenya.cms.publication.SiteTree#removeNode(java.lang.String)
+ */
+ public synchronized SiteTreeNode removeNode(String documentId) {
+ // assert documentId != null;
+ Node node = removeNodeInternal(documentId);
+ if(node == null){
+ return null;
+ }
+ return new SiteTreeNodeImpl(node, this);
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.lenya.cms.publication.SiteTree#deleteNode(java.lang.String)
+ */
+ public void deleteNode(String documentId) throws SiteTreeException {
+ Node node = this.getNodeInternal(documentId);
+ Node parentNode = node.getParentNode();
+ // Node newNode =
+ parentNode.removeChild(node);
+ }
+ /**
+ * removes the node corresponding to the given document-id and returns it
+ *
+ * @param documentId
+ * the document-id of the Node to be removed
+ *
+ * @return the <code>Node</code> that was removed
+ */
+ private synchronized Node removeNodeInternal(String documentId) {
+ Node node = this.getNodeInternal(documentId);
+ Node parentNode = node.getParentNode();
+ Node newNode = parentNode.removeChild(node);
+ return newNode;
+ }
+ /**
+ * Find a node for a given document-id
+ *
+ * @param documentId
+ * the document-id of the Node that we're trying to get
+ *
+ * @return the Node if there is a Node for the given document-id, null otherwise
+ */
+ private synchronized Node getNodeInternal(String documentId) {
+ StringTokenizer st = new StringTokenizer(documentId, "/");
+ ArrayList ids = new ArrayList();
+ while(st.hasMoreTokens()){
+ ids.add(st.nextToken());
+ }
+ Node node = findNode(document.getDocumentElement(), ids);
+ return node;
+ }
+ /**
+ * @see org.apache.lenya.cms.publication.SiteTree#getNode(java.lang.String)
+ */
+ public synchronized SiteTreeNode getNode(String documentId) {
+ // assert documentId != null;
+ SiteTreeNode treeNode = null;
+ Node node = getNodeInternal(documentId);
+ if(node != null){
+ treeNode = new SiteTreeNodeImpl(node, this);
+ }
+ return treeNode;
+ }
+ /**
+ * @see org.apache.lenya.cms.publication.SiteTree#getTopNodes()
+ */
+ public SiteTreeNode[] getTopNodes() {
+ List childElements = new ArrayList();
+ NamespaceHelper helper = new NamespaceHelper(NAMESPACE_URI, "", document);
+ Element[] elements = helper.getChildren((Element) document.getDocumentElement(), SiteTreeNodeImpl.NODE_NAME);
+ for(int i = 0; i < elements.length; i++){
+ SiteTreeNode newNode = new SiteTreeNodeImpl(elements[i], this);
+ childElements.add(newNode);
+ }
+ return (SiteTreeNode[]) childElements.toArray(new SiteTreeNode[childElements.size()]);
+ }
+ /**
+ * Move up the node amongst its siblings.
+ *
+ * @param documentid
+ * The document id for the node.
+ * @throws SiteTreeException
+ * if the moving failed.
+ */
+ public synchronized void moveUp(String documentid) throws SiteTreeException {
+ Node node = this.getNodeInternal(documentid);
+ if(node == null){
+ throw new SiteTreeException("Node to move: " + documentid + " not found");
+ }
+ Node parentNode = node.getParentNode();
+ if(parentNode == null){
+ throw new SiteTreeException("Parentid of node with documentid: " + documentid + " not found");
+ }
+ Node previousNode;
+ try{
+ previousNode = XPathAPI.selectSingleNode(node, "(preceding-sibling::*[local-name() = 'node'])[last()]");
+ }catch(TransformerException e){
+ throw new SiteTreeException(e);
+ }
+ if(previousNode == null){
+ log.warn("Couldn't found a preceding sibling");
+ return;
+ }
+ Node insertNode = parentNode.removeChild(node);
+ parentNode.insertBefore(insertNode, previousNode);
+ }
+ /**
+ * Move down the node amongst its siblings.
+ *
+ * @param documentid
+ * The document id for the node.
+ * @throws SiteTreeException
+ * if the moving failed.
+ */
+ public synchronized void moveDown(String documentid) throws SiteTreeException {
+ Node node = this.getNodeInternal(documentid);
+ if(node == null){
+ throw new SiteTreeException("Node to move: " + documentid + " not found");
+ }
+ Node parentNode = node.getParentNode();
+ if(parentNode == null){
+ throw new SiteTreeException("Parentid of node with documentid: " + documentid + " not found");
+ }
+ Node nextNode;
+ try{
+ nextNode = XPathAPI.selectSingleNode(node, "following-sibling::*[local-name() = 'node'][position()=2]");
+ }catch(TransformerException e){
+ throw new SiteTreeException(e);
+ }
+ Node insertNode = parentNode.removeChild(node);
+ if(nextNode == null){
+ log.warn("Couldn't found the second following sibling");
+ parentNode.appendChild(insertNode);
+ }else{
+ parentNode.insertBefore(insertNode, nextNode);
+ }
+ }
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.lenya.cms.publication.SiteTree#importSubtree(org.apache.lenya.cms.publication.SiteTreeNode, org.apache.lenya.cms.publication.SiteTreeNode, java.lang.String)
+ */
+ public synchronized void importSubtree(SiteTreeNode newParent, SiteTreeNode subtreeRoot, String newid, String refDocumentId) throws SiteTreeException {
+ // assert subtreeRoot != null;
+ // assert newParent != null;
+ String parentId = newParent.getAbsoluteId();
+ String id = newid;
+ this.addNode(parentId, id, subtreeRoot.getLabels(), subtreeRoot.visibleInNav(), subtreeRoot.getHref(), subtreeRoot.getSuffix(), subtreeRoot.hasLink(), refDocumentId);
+ newParent = this.getNode(parentId + "/" + id);
+ if(newParent == null){
+ throw new SiteTreeException("The added node was not found.");
+ }
+ SiteTreeNode[] children = subtreeRoot.getChildren();
+ if(children == null){
+ log.info("The node " + subtreeRoot.toString() + " has no children");
+ return;
+ }else{
+ for(int i = 0; i < children.length; i++){
+ importSubtree(newParent, children[i], children[i].getId(), null);
+ }
+ }
+ }
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.lenya.cms.publication.SiteTree#save()
+ */
+ public synchronized void save() throws SiteTreeException {
+ try{
+ DocumentHelper.writeDocument(document, treefile);
+ }catch(TransformerException e){
+ throw new SiteTreeException("The document [" + document.getLocalName() + "] could not be transformed");
+ }catch(IOException e){
+ throw new SiteTreeException("The saving of document [" + document.getLocalName() + "] failed");
+ }
+ lastModified = new Date().getTime();
+ }
+ /**
+ * @see org.apache.lenya.cms.publication.SiteTree#setLabel(java.lang.String, org.apache.lenya.cms.publication.Label)
+ */
+ public synchronized void setLabel(String documentId, Label label) {
+ SiteTreeNode node = getNode(documentId);
+ if(node != null){
+ node.setLabel(label);
+ }
+ }
+ /**
+ * @see org.apache.lenya.cms.publication.SiteTree#copy(org.apache.lenya.cms.publication.SiteTreeNode, org.apache.lenya.cms.publication.SiteTreeNode, java.lang.String, java.lang.String)
+ */
+ public void copy(SiteTreeNode src, SiteTreeNode dst, String newId, String followingSibling) throws SiteTreeException {
+ // assert dst instanceof SiteTreeNodeImpl;
+ SiteTreeNodeImpl dstNode = (SiteTreeNodeImpl) dst;
+ if(this.equals(dstNode.getDefaultSiteTree())){
+ // Copy if this sitetree is the destination sitetree.
+ // Acquire global sitetree lock to establish lock hierarchy in case
+ // of copy operation
+ synchronized (DefaultSiteTree.lock){
+ DefaultSiteTree srcSiteTree = ((SiteTreeNodeImpl) src).getDefaultSiteTree();
+ synchronized (srcSiteTree){
+ synchronized (this){
+ String parentId = dst.getAbsoluteId();
+ String id = newId;
+ this.addNode(parentId, id, src.getLabels(), src.visibleInNav(), src.getHref(), src.getSuffix(), src.hasLink(), followingSibling);
+ SiteTreeNode node = this.getNode(parentId + "/" + id);
+ if(node == null){
+ throw new SiteTreeException("The added node was not found.");
+ }
+ SiteTreeNode[] children = src.getChildren();
+ if(children == null){
+ log.debug("The node " + src.toString() + " has no children");
+ return;
+ }else{
+ for(int i = 0; i < children.length; i++){
+ copy(children[i], node, children[i].getId(), null);
+ }
+ }
+ }
}
- } else {
- // Delegate copy operation to destination sitetree.
- dstNode.getDefaultSiteTree().copy(src, dst, newId, followingSibling);
- }
- }
- /**
- * @see org.apache.lenya.cms.publication.SiteTree#move(org.apache.lenya.cms.publication.SiteTreeNode,
- * org.apache.lenya.cms.publication.SiteTreeNode, java.lang.String,
- * java.lang.String)
- */
- public void move(SiteTreeNode src, SiteTreeNode dst, String newId, String followingSibling) throws SiteTreeException {
- // assert dst != null;
- // assert src instanceof SiteTreeNodeImpl;
- // Acquire global sitetree lock to establish lock hierarchy in case of
- // move operation
- synchronized (DefaultSiteTree.lock) {
- // Lock both source and destination sitetree.
- synchronized (((SiteTreeNodeImpl) src).getDefaultSiteTree()) {
- synchronized (((SiteTreeNodeImpl) dst).getDefaultSiteTree()) {
- copy(src, dst, newId, followingSibling);
- DefaultSiteTree sitetree = ((SiteTreeNodeImpl) src).getDefaultSiteTree();
- sitetree.deleteNode(src.getAbsoluteId());
- }
+ }
+ }else{
+ // Delegate copy operation to destination sitetree.
+ dstNode.getDefaultSiteTree().copy(src, dst, newId, followingSibling);
+ }
+ }
+ /**
+ * @see org.apache.lenya.cms.publication.SiteTree#move(org.apache.lenya.cms.publication.SiteTreeNode, org.apache.lenya.cms.publication.SiteTreeNode, java.lang.String, java.lang.String)
+ */
+ public void move(SiteTreeNode src, SiteTreeNode dst, String newId, String followingSibling) throws SiteTreeException {
+ // assert dst != null;
+ // assert src instanceof SiteTreeNodeImpl;
+ // Acquire global sitetree lock to establish lock hierarchy in case of
+ // move operation
+ synchronized (DefaultSiteTree.lock){
+ // Lock both source and destination sitetree.
+ synchronized (((SiteTreeNodeImpl) src).getDefaultSiteTree()){
+ synchronized (((SiteTreeNodeImpl) dst).getDefaultSiteTree()){
+ copy(src, dst, newId, followingSibling);
+ DefaultSiteTree sitetree = ((SiteTreeNodeImpl) src).getDefaultSiteTree();
+ sitetree.deleteNode(src.getAbsoluteId());
}
- }
- }
- /**
- * @see org.apache.lenya.cms.publication.LastModified#getLastModified()
- */
- public long getLastModified() {
- return lastModified;
- }
+ }
+ }
+ }
+ /**
+ * @see org.apache.lenya.cms.publication.LastModified#getLastModified()
+ */
+ public long getLastModified() {
+ return lastModified;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentBuildException.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentBuildException.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentBuildException.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentBuildException.java Wed Jan 30 23:44:03 2008
@@ -14,41 +14,43 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.publication;
-
public class DocumentBuildException extends PublicationException {
- /**
- * Constructor.
- */
- public DocumentBuildException() {
- super();
- }
-
- /**
- * Constructor.
- * @param message A message.
- */
- public DocumentBuildException(String message) {
- super(message);
- }
-
- /**
- * Constructor.
- * @param cause The cause of the exception.
- */
- public DocumentBuildException(Throwable cause) {
- super(cause);
- }
-
- /**
- * Constructor.
- * @param message A message.
- * @param cause The cause of the exception.
- */
- public DocumentBuildException(String message, Throwable cause) {
- super(message, cause);
- }
+ private static final long serialVersionUID = 1L;
+ /**
+ * Constructor.
+ */
+ public DocumentBuildException() {
+ super();
+ }
+ /**
+ * Constructor.
+ *
+ * @param message
+ * A message.
+ */
+ public DocumentBuildException(String message) {
+ super(message);
+ }
+ /**
+ * Constructor.
+ *
+ * @param cause
+ * The cause of the exception.
+ */
+ public DocumentBuildException(Throwable cause) {
+ super(cause);
+ }
+ /**
+ * Constructor.
+ *
+ * @param message
+ * A message.
+ * @param cause
+ * The cause of the exception.
+ */
+ public DocumentBuildException(String message, Throwable cause) {
+ super(message, cause);
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentDoesNotExistException.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentDoesNotExistException.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentDoesNotExistException.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentDoesNotExistException.java Wed Jan 30 23:44:03 2008
@@ -14,47 +14,44 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.publication;
-
public class DocumentDoesNotExistException extends DocumentException {
-
- /**
- * Creates a new DocumentDoesNotExistException
- *
- */
- public DocumentDoesNotExistException() {
- super();
- }
-
- /**
- * Creates a new DocumentDoesNotExistException
- *
- * @param message the exception message
- */
- public DocumentDoesNotExistException(String message) {
- super(message);
- }
-
- /**
- * Creates a new DocumentDoesNotExistException
- *
- * @param message the exception message
- * @param cause the cause of the exception
- */
- public DocumentDoesNotExistException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Creates a new DocumentDoesNotExistException
- *
- * @param cause the cause of the exception
- */
- public DocumentDoesNotExistException(Throwable cause) {
- super(cause);
- }
-
+ private static final long serialVersionUID = 1L;
+ /**
+ * Creates a new DocumentDoesNotExistException
+ *
+ */
+ public DocumentDoesNotExistException() {
+ super();
+ }
+ /**
+ * Creates a new DocumentDoesNotExistException
+ *
+ * @param message
+ * the exception message
+ */
+ public DocumentDoesNotExistException(String message) {
+ super(message);
+ }
+ /**
+ * Creates a new DocumentDoesNotExistException
+ *
+ * @param message
+ * the exception message
+ * @param cause
+ * the cause of the exception
+ */
+ public DocumentDoesNotExistException(String message, Throwable cause) {
+ super(message, cause);
+ }
+ /**
+ * Creates a new DocumentDoesNotExistException
+ *
+ * @param cause
+ * the cause of the exception
+ */
+ public DocumentDoesNotExistException(Throwable cause) {
+ super(cause);
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentException.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentException.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentException.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentException.java Wed Jan 30 23:44:03 2008
@@ -14,47 +14,44 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.publication;
-
public class DocumentException extends PublicationException {
-
- /**
- * Creates a new DocumentException
- *
- */
- public DocumentException() {
- super();
- }
-
- /**
- * Creates a new DocumentException
- *
- * @param message the exception message
- */
- public DocumentException(String message) {
- super(message);
- }
-
- /**
- * Creates a new DocumentException
- *
- * @param message the exception message
- * @param cause the cause of the exception
- */
- public DocumentException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Creates a new DocumentException
- *
- * @param cause the cause of the exception
- */
- public DocumentException(Throwable cause) {
- super(cause);
- }
-
+ private static final long serialVersionUID = 1L;
+ /**
+ * Creates a new DocumentException
+ *
+ */
+ public DocumentException() {
+ super();
+ }
+ /**
+ * Creates a new DocumentException
+ *
+ * @param message
+ * the exception message
+ */
+ public DocumentException(String message) {
+ super(message);
+ }
+ /**
+ * Creates a new DocumentException
+ *
+ * @param message
+ * the exception message
+ * @param cause
+ * the cause of the exception
+ */
+ public DocumentException(String message, Throwable cause) {
+ super(message, cause);
+ }
+ /**
+ * Creates a new DocumentException
+ *
+ * @param cause
+ * the cause of the exception
+ */
+ public DocumentException(Throwable cause) {
+ super(cause);
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentTypeBuildException.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentTypeBuildException.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentTypeBuildException.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentTypeBuildException.java Wed Jan 30 23:44:03 2008
@@ -14,44 +14,40 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.publication;
-
public class DocumentTypeBuildException extends Exception {
- /**
- *
- */
- public DocumentTypeBuildException() {
- super();
- }
-
- /**
- * Creates a new DocumentTypeBuildException.
- *
- * @param message the exception message
- */
- public DocumentTypeBuildException(String message) {
- super(message);
- }
-
- /**
- * Creates a new DocumentTypeBuildException.
- *
- * @param message the exception message
- * @param cause the cause of the exception
- */
- public DocumentTypeBuildException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Creates a new DocumentTypeBuildException.
- *
- * @param cause the cause of the exception
- */
- public DocumentTypeBuildException(Throwable cause) {
- super(cause);
- }
+ private static final long serialVersionUID = 1L;
+ public DocumentTypeBuildException() {
+ super();
+ }
+ /**
+ * Creates a new DocumentTypeBuildException.
+ *
+ * @param message
+ * the exception message
+ */
+ public DocumentTypeBuildException(String message) {
+ super(message);
+ }
+ /**
+ * Creates a new DocumentTypeBuildException.
+ *
+ * @param message
+ * the exception message
+ * @param cause
+ * the cause of the exception
+ */
+ public DocumentTypeBuildException(String message, Throwable cause) {
+ super(message, cause);
+ }
+ /**
+ * Creates a new DocumentTypeBuildException.
+ *
+ * @param cause
+ * the cause of the exception
+ */
+ public DocumentTypeBuildException(Throwable cause) {
+ super(cause);
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DublinCoreHelper.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DublinCoreHelper.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DublinCoreHelper.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DublinCoreHelper.java Wed Jan 30 23:44:03 2008
@@ -14,76 +14,64 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.publication;
-
-import org.apache.log4j.Category;
-
+import org.apache.log4j.Logger;
/**
* Facade to get the DublinCore through the cms Document
*/
public final class DublinCoreHelper {
-
- /**
- *
- */
- private DublinCoreHelper() {
- }
-
- private static Category log = Category.getInstance(DublinCoreHelper.class);
-
- /**
- * Get the value of the DCIdentifier corresponding to a document id.
- *
- * @param publication
- * The publication the document(s) belongs to.
- * @param area
- * The area the document(s) belongs to.
- * @param documentId
- * The document id.
- * @return a String. The value of the DCIdentifier.
- * @throws SiteTreeException
- * when something with the sitetree went wrong.
- * @throws DocumentBuildException
- * when the building of a document failed.
- * @throws DocumentException
- * when something with the document went wrong.
- */
- public static String getDCIdentifier(Publication publication, String area, String documentId)
- throws SiteTreeException, DocumentBuildException, DocumentException {
- String identifier = null;
- String language = null;
- String url = null;
- Document document = null;
-
- SiteTree tree = publication.getTree(area);
- SiteTreeNode node = tree.getNode(documentId);
-
- DocumentBuilder builder = publication.getDocumentBuilder();
-
- int i = 0;
- Label[] labels = node.getLabels();
- if (labels.length > 0) {
- while (identifier == null && i < labels.length) {
- language = labels[i].getLanguage();
- url = builder.buildCanonicalUrl(publication, area, documentId, language);
- document = builder.buildDocument(publication, url);
- log.debug("document file : " + document.getFile().getAbsolutePath());
- DublinCore dublincore = document.getDublinCore();
- log.debug("dublincore title : " + dublincore.getFirstValue(DublinCore.ELEMENT_TITLE));
- identifier = dublincore.getFirstValue(DublinCore.ELEMENT_IDENTIFIER);
- i = i + 1;
- }
- }
- if (labels.length < 1 || identifier == null) {
- url = builder.buildCanonicalUrl(publication, area, documentId);
- document = builder.buildDocument(publication, url);
- DublinCore dublincore = document.getDublinCore();
- identifier = dublincore.getFirstValue(DublinCore.ELEMENT_IDENTIFIER);
- }
-
- return identifier;
- }
+ /**
+ *
+ */
+ private DublinCoreHelper() {
+ }
+ private static Logger log = Logger.getLogger(DublinCoreHelper.class);
+ /**
+ * Get the value of the DCIdentifier corresponding to a document id.
+ *
+ * @param publication
+ * The publication the document(s) belongs to.
+ * @param area
+ * The area the document(s) belongs to.
+ * @param documentId
+ * The document id.
+ * @return a String. The value of the DCIdentifier.
+ * @throws SiteTreeException
+ * when something with the sitetree went wrong.
+ * @throws DocumentBuildException
+ * when the building of a document failed.
+ * @throws DocumentException
+ * when something with the document went wrong.
+ */
+ public static String getDCIdentifier(Publication publication, String area, String documentId) throws SiteTreeException, DocumentBuildException, DocumentException {
+ String identifier = null;
+ String language = null;
+ String url = null;
+ Document document = null;
+ SiteTree tree = publication.getTree(area);
+ SiteTreeNode node = tree.getNode(documentId);
+ DocumentBuilder builder = publication.getDocumentBuilder();
+ int i = 0;
+ Label[] labels = node.getLabels();
+ if(labels.length > 0){
+ while(identifier == null && i < labels.length){
+ language = labels[i].getLanguage();
+ url = builder.buildCanonicalUrl(publication, area, documentId, language);
+ document = builder.buildDocument(publication, url);
+ log.debug("document file : " + document.getFile().getAbsolutePath());
+ DublinCore dublincore = document.getDublinCore();
+ log.debug("dublincore title : " + dublincore.getFirstValue(DublinCore.ELEMENT_TITLE));
+ identifier = dublincore.getFirstValue(DublinCore.ELEMENT_IDENTIFIER);
+ i = i + 1;
+ }
+ }
+ if(labels.length < 1 || identifier == null){
+ url = builder.buildCanonicalUrl(publication, area, documentId);
+ document = builder.buildDocument(publication, url);
+ DublinCore dublincore = document.getDublinCore();
+ identifier = dublincore.getFirstValue(DublinCore.ELEMENT_IDENTIFIER);
+ }
+ return identifier;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DublinCoreImpl.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DublinCoreImpl.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DublinCoreImpl.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DublinCoreImpl.java Wed Jan 30 23:44:03 2008
@@ -14,11 +14,8 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.publication;
-
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -26,389 +23,289 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
-
import org.apache.lenya.xml.DocumentHelper;
import org.apache.lenya.xml.NamespaceHelper;
-import org.apache.log4j.Category;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-
/**
- * Access dublin core meta data in documents.
- * This class uses the dublin core specification from 2003-03-04.
+ * Access dublin core meta data in documents. This class uses the dublin core specification from 2003-03-04.
*/
public class DublinCoreImpl {
- private static final Category log = Category.getInstance(DublinCoreImpl.class);
- private Document cmsdocument;
- private File infofile;
-
- private Map elements = new HashMap();
- private Map terms = new HashMap();
-
- private static final String META = "meta";
-
- private static final String DC_NAMESPACE = "http://purl.org/dc/elements/1.1/";
- private static final String DC_PREFIX = "dc";
-
- public static final String[] ELEMENTS =
- {
- DublinCore.ELEMENT_TITLE,
- DublinCore.ELEMENT_CREATOR,
- DublinCore.ELEMENT_SUBJECT,
- DublinCore.ELEMENT_DESCRIPTION,
- DublinCore.ELEMENT_PUBLISHER,
- DublinCore.ELEMENT_CONTRIBUTOR,
- DublinCore.ELEMENT_DATE,
- DublinCore.ELEMENT_TYPE,
- DublinCore.ELEMENT_FORMAT,
- DublinCore.ELEMENT_IDENTIFIER,
- DublinCore.ELEMENT_SOURCE,
- DublinCore.ELEMENT_LANGUAGE,
- DublinCore.ELEMENT_RELATION,
- DublinCore.ELEMENT_COVERAGE,
- DublinCore.ELEMENT_RIGHTS };
-
- // Dublin Core Terms
-
- private static final String DCTERMS_NAMESPACE = "http://purl.org/dc/terms/";
- private static final String DCTERMS_PREFIX = "dcterms";
-
- public static final String[] TERMS =
- {
- DublinCore.TERM_AUDIENCE,
- DublinCore.TERM_ALTERNATIVE,
- DublinCore.TERM_TABLEOFCONTENTS,
- DublinCore.TERM_ABSTRACT,
- DublinCore.TERM_CREATED,
- DublinCore.TERM_VALID,
- DublinCore.TERM_EXTENT,
- DublinCore.TERM_AVAILABLE,
- DublinCore.TERM_ISSUED,
- DublinCore.TERM_MODIFIED,
- DublinCore.TERM_EXTENT,
- DublinCore.TERM_MEDIUM,
- DublinCore.TERM_ISVERSIONOF,
- DublinCore.TERM_HASVERSION,
- DublinCore.TERM_ISREPLACEDBY,
- DublinCore.TERM_REPLACES,
- DublinCore.TERM_ISREQUIREDBY,
- DublinCore.TERM_REQUIRES,
- DublinCore.TERM_ISPARTOF,
- DublinCore.TERM_HASPART,
- DublinCore.TERM_ISREFERENCEDBY,
- DublinCore.TERM_REFERENCES,
- DublinCore.TERM_ISFORMATOF,
- DublinCore.TERM_HASFORMAT,
- DublinCore.TERM_CONFORMSTO,
- DublinCore.TERM_SPATIAL,
- DublinCore.TERM_TEMPORAL,
- DublinCore.TERM_MEDIATOR,
- DublinCore.TERM_DATEACCEPTED,
- DublinCore.TERM_DATECOPYRIGHTED,
- DublinCore.TERM_DATESUBMITTED,
- DublinCore.TERM_EDUCATIONLEVEL,
- DublinCore.TERM_ACCESSRIGHTS,
- DublinCore.TERM_BIBLIOGRAPHICCITATION };
-
- /**
- * Creates a new instance of Dublin Core
- *
- * @param aDocument the document for which the Dublin Core instance is created.
- *
- * @throws DocumentException if an error occurs
- */
- protected DublinCoreImpl(Document aDocument) throws DocumentException {
- this.cmsdocument = aDocument;
- infofile =
- cmsdocument.getPublication().getPathMapper().getFile(
- cmsdocument.getPublication(),
- cmsdocument.getArea(),
- cmsdocument.getId(),
- cmsdocument.getLanguage());
- loadValues();
- }
-
- /**
- * Loads the dublin core values from the XML file.
- * @throws DocumentException when something went wrong.
- */
- protected void loadValues() throws DocumentException {
-
- if (infofile.exists()) {
- org.w3c.dom.Document doc = null;
- try {
- doc = DocumentHelper.readDocument(infofile);
- } catch (Exception e) {
- throw new DocumentException("Parsing file [" + infofile + "] failed: ", e);
- }
-
- // FIXME: what if "lenya:meta" element doesn't exist yet?
- // Currently the element is inserted.
- Element metaElement = getMetaElement(doc);
-
- String[] namespaces = { DC_NAMESPACE, DCTERMS_NAMESPACE };
- String[] prefixes = { DC_PREFIX, DCTERMS_PREFIX };
- String[][] arrays = { ELEMENTS, TERMS };
- Map[] maps = { elements, terms };
-
- for (int type = 0; type < 2; type++) {
- NamespaceHelper helper = new NamespaceHelper(namespaces[type], prefixes[type], doc);
- String[] elementNames = arrays[type];
- for (int i = 0; i < elementNames.length; i++) {
- Element[] children = helper.getChildren(metaElement, elementNames[i]);
- String[] values = new String[children.length];
- for (int valueIndex = 0; valueIndex < children.length; valueIndex++) {
- values[valueIndex] =
- DocumentHelper.getSimpleElementText(children[valueIndex]);
- }
- maps[type].put(elementNames[i], values);
- }
- }
- }
-
- }
-
- /**
- * Save the meta data.
- *
- * @throws DocumentException if the meta data could not be made persistent.
- */
- public void save() throws DocumentException {
- org.w3c.dom.Document doc = null;
- try {
+ private Document cmsdocument;
+ private File infofile;
+ private Map elements = new HashMap();
+ private Map terms = new HashMap();
+ private static final String META = "meta";
+ private static final String DC_NAMESPACE = "http://purl.org/dc/elements/1.1/";
+ private static final String DC_PREFIX = "dc";
+ public static final String[] ELEMENTS = {DublinCore.ELEMENT_TITLE, DublinCore.ELEMENT_CREATOR, DublinCore.ELEMENT_SUBJECT, DublinCore.ELEMENT_DESCRIPTION, DublinCore.ELEMENT_PUBLISHER, DublinCore.ELEMENT_CONTRIBUTOR, DublinCore.ELEMENT_DATE, DublinCore.ELEMENT_TYPE, DublinCore.ELEMENT_FORMAT, DublinCore.ELEMENT_IDENTIFIER, DublinCore.ELEMENT_SOURCE, DublinCore.ELEMENT_LANGUAGE, DublinCore.ELEMENT_RELATION, DublinCore.ELEMENT_COVERAGE, DublinCore.ELEMENT_RIGHTS};
+ // Dublin Core Terms
+ private static final String DCTERMS_NAMESPACE = "http://purl.org/dc/terms/";
+ private static final String DCTERMS_PREFIX = "dcterms";
+ public static final String[] TERMS = {DublinCore.TERM_AUDIENCE, DublinCore.TERM_ALTERNATIVE, DublinCore.TERM_TABLEOFCONTENTS, DublinCore.TERM_ABSTRACT, DublinCore.TERM_CREATED, DublinCore.TERM_VALID, DublinCore.TERM_EXTENT, DublinCore.TERM_AVAILABLE, DublinCore.TERM_ISSUED, DublinCore.TERM_MODIFIED, DublinCore.TERM_EXTENT, DublinCore.TERM_MEDIUM, DublinCore.TERM_ISVERSIONOF, DublinCore.TERM_HASVERSION, DublinCore.TERM_ISREPLACEDBY, DublinCore.TERM_REPLACES, DublinCore.TERM_ISREQUIREDBY, DublinCore.TERM_REQUIRES, DublinCore.TERM_ISPARTOF, DublinCore.TERM_HASPART, DublinCore.TERM_ISREFERENCEDBY, DublinCore.TERM_REFERENCES, DublinCore.TERM_ISFORMATOF, DublinCore.TERM_HASFORMAT, DublinCore.TERM_CONFORMSTO, DublinCore.TERM_SPATIAL, DublinCore.TERM_TEMPORAL, DublinCore.TERM_MEDIATOR, DublinC
ore.TERM_DATEACCEPTED, DublinCore.TERM_DATECOPYRIGHTED, DublinCore.TERM_DATESUBMITTED, DublinCore.TERM_EDUCATIONLEVEL, DublinCore.TERM_ACCESSRIGHTS, DublinCore.TERM_BIBLIOGRAPHICCITATION};
+ /**
+ * Creates a new instance of Dublin Core
+ *
+ * @param aDocument
+ * the document for which the Dublin Core instance is created.
+ *
+ * @throws DocumentException
+ * if an error occurs
+ */
+ protected DublinCoreImpl(Document aDocument) throws DocumentException {
+ this.cmsdocument = aDocument;
+ infofile = cmsdocument.getPublication().getPathMapper().getFile(cmsdocument.getPublication(), cmsdocument.getArea(), cmsdocument.getId(), cmsdocument.getLanguage());
+ loadValues();
+ }
+ /**
+ * Loads the dublin core values from the XML file.
+ *
+ * @throws DocumentException
+ * when something went wrong.
+ */
+ protected void loadValues() throws DocumentException {
+ if(infofile.exists()){
+ org.w3c.dom.Document doc = null;
+ try{
doc = DocumentHelper.readDocument(infofile);
- } catch (ParserConfigurationException e) {
- throw new DocumentException(e);
- } catch (SAXException e) {
- throw new DocumentException(e);
- } catch (IOException e) {
- throw new DocumentException(e);
- }
-
- Element metaElement = getMetaElement(doc);
-
- String[] namespaces = { DC_NAMESPACE, DCTERMS_NAMESPACE };
- String[] prefixes = { DC_PREFIX, DCTERMS_PREFIX };
- String[][] arrays = { ELEMENTS, TERMS };
- Map[] maps = { elements, terms };
-
- List childNodes = new ArrayList();
- NodeList nodes = metaElement.getChildNodes();
- for (int i = 0; i < nodes.getLength(); i++) {
- if (nodes.item(i).getParentNode() == metaElement) {
- childNodes.add(nodes.item(i));
- }
- }
- Node[] children = (Node[])childNodes.toArray(new Node[childNodes.size()]);
- for (int i = 0; i < children.length; i++){
- metaElement.removeChild(children[i]);
- }
-
- for (int type = 0; type < 2; type++) {
+ }catch(Exception e){
+ throw new DocumentException("Parsing file [" + infofile + "] failed: ", e);
+ }
+ // FIXME: what if "lenya:meta" element doesn't exist yet?
+ // Currently the element is inserted.
+ Element metaElement = getMetaElement(doc);
+ String[] namespaces = {DC_NAMESPACE, DCTERMS_NAMESPACE};
+ String[] prefixes = {DC_PREFIX, DCTERMS_PREFIX};
+ String[][] arrays = {ELEMENTS, TERMS};
+ Map[] maps = {elements, terms};
+ for(int type = 0; type < 2; type++){
NamespaceHelper helper = new NamespaceHelper(namespaces[type], prefixes[type], doc);
String[] elementNames = arrays[type];
- for (int i = 0; i < elementNames.length; i++) {
- String[] values = (String[]) maps[type].get(elementNames[i]);
- for (int valueIndex = 0; valueIndex < values.length; valueIndex++) {
- Element valueElement =
- helper.createElement(elementNames[i], values[valueIndex]);
- metaElement.appendChild(valueElement);
- }
+ for(int i = 0; i < elementNames.length; i++){
+ Element[] children = helper.getChildren(metaElement, elementNames[i]);
+ String[] values = new String[children.length];
+ for(int valueIndex = 0; valueIndex < children.length; valueIndex++){
+ values[valueIndex] = DocumentHelper.getSimpleElementText(children[valueIndex]);
+ }
+ maps[type].put(elementNames[i], values);
}
- }
-
- try {
- DocumentHelper.writeDocument(doc, infofile);
- } catch (TransformerConfigurationException e) {
- throw new DocumentException(e);
- } catch (TransformerException e) {
- throw new DocumentException(e);
- } catch (IOException e) {
- throw new DocumentException(e);
- }
-
- }
-
- /**
- * Returns the Lenya meta data element.
- * @param doc The XML document.
- * @return A DOM element.
- */
- protected Element getMetaElement(org.w3c.dom.Document doc) throws DocumentException {
- NamespaceHelper namespaceHelper =
- new NamespaceHelper(PageEnvelope.NAMESPACE, PageEnvelope.DEFAULT_PREFIX, doc);
- Element documentElement = doc.getDocumentElement();
- Element metaElement = namespaceHelper.getFirstChild(documentElement, META);
-
- if (metaElement == null) {
- metaElement = namespaceHelper.createElement(META);
- Element[] children = DocumentHelper.getChildren(documentElement);
- if (children.length == 0) {
- documentElement.appendChild(metaElement);
- } else {
- documentElement.insertBefore(metaElement, children[0]);
+ }
+ }
+ }
+ /**
+ * Save the meta data.
+ *
+ * @throws DocumentException
+ * if the meta data could not be made persistent.
+ */
+ public void save() throws DocumentException {
+ org.w3c.dom.Document doc = null;
+ try{
+ doc = DocumentHelper.readDocument(infofile);
+ }catch(ParserConfigurationException e){
+ throw new DocumentException(e);
+ }catch(SAXException e){
+ throw new DocumentException(e);
+ }catch(IOException e){
+ throw new DocumentException(e);
+ }
+ Element metaElement = getMetaElement(doc);
+ String[] namespaces = {DC_NAMESPACE, DCTERMS_NAMESPACE};
+ String[] prefixes = {DC_PREFIX, DCTERMS_PREFIX};
+ String[][] arrays = {ELEMENTS, TERMS};
+ Map[] maps = {elements, terms};
+ List childNodes = new ArrayList();
+ NodeList nodes = metaElement.getChildNodes();
+ for(int i = 0; i < nodes.getLength(); i++){
+ if(nodes.item(i).getParentNode() == metaElement){
+ childNodes.add(nodes.item(i));
+ }
+ }
+ Node[] children = (Node[]) childNodes.toArray(new Node[childNodes.size()]);
+ for(int i = 0; i < children.length; i++){
+ metaElement.removeChild(children[i]);
+ }
+ for(int type = 0; type < 2; type++){
+ NamespaceHelper helper = new NamespaceHelper(namespaces[type], prefixes[type], doc);
+ String[] elementNames = arrays[type];
+ for(int i = 0; i < elementNames.length; i++){
+ String[] values = (String[]) maps[type].get(elementNames[i]);
+ for(int valueIndex = 0; valueIndex < values.length; valueIndex++){
+ Element valueElement = helper.createElement(elementNames[i], values[valueIndex]);
+ metaElement.appendChild(valueElement);
}
- }
-
- return metaElement;
- }
-
- /**
- * Returns the first value for a certain key.
- * @param key The key.
- * @return A string.
- */
- public String getFirstValue(String key) throws DocumentException {
- String value = null;
- String[] values = getElementOrTerm(key);
- if (values.length > 0) {
- value = values[0];
- }
- return value;
- }
-
- /**
- * Returns the element or term values, resp., for a certain key.
- * @param key The key.
- * @return An array of strings.
- */
- protected String[] getElementOrTerm(String key) throws DocumentException {
- String[] values;
-
- List elementList = Arrays.asList(ELEMENTS);
- List termList = Arrays.asList(TERMS);
- if (elementList.contains(key)) {
- values = (String[]) elements.get(key);
- } else if (termList.contains(key)) {
- values = (String[]) terms.get(key);
- } else {
- throw new DocumentException(
- "The key [" + key + "] does not refer to a dublin core element or term!");
- }
- if (values == null) {
- values = new String[0];
- }
- return values;
- }
-
- /**
- * @see org.apache.lenya.cms.publication.DublinCore#getValues(java.lang.String)
- */
- public String[] getValues(String key) throws DocumentException {
- return getElementOrTerm(key);
- }
-
- /**
- * @see org.apache.lenya.cms.publication.DublinCore#addValue(java.lang.String, java.lang.String)
- */
- public void addValue(String key, String value) throws DocumentException {
- String[] existingValues = getElementOrTerm(key);
- List list = new ArrayList(Arrays.asList(existingValues));
- list.add(value);
- String[] newValues = (String[]) list.toArray(new String[list.size()]);
-
- List elementList = Arrays.asList(ELEMENTS);
- List termList = Arrays.asList(TERMS);
- if (elementList.contains(key)) {
- elements.put(key, newValues);
- } else if (termList.contains(key)) {
- terms.put(key, newValues);
- } else {
- throw new DocumentException(
- "The key [" + key + "] does not refer to a dublin core element or term!");
- }
- }
-
- /**
- * @see org.apache.lenya.cms.publication.DublinCore#setValue(java.lang.String, java.lang.String)
- */
- public void setValue(String key, String value) throws DocumentException {
- String[] newValues = { value };
-
- List elementList = Arrays.asList(ELEMENTS);
- List termList = Arrays.asList(TERMS);
- if (elementList.contains(key)) {
- elements.put(key, newValues);
- } else if (termList.contains(key)) {
- terms.put(key, newValues);
- } else {
- throw new DocumentException(
- "The key [" + key + "] does not refer to a dublin core element or term!");
- }
- }
-
- /**
- * @see org.apache.lenya.cms.publication.DublinCore#addValues(java.lang.String, java.lang.String[])
- */
- public void addValues(String key, String[] values) throws DocumentException {
- for (int i = 0; i < values.length; i++) {
- addValue(key,values[i]);
- }
- }
-
- /**
- * @see org.apache.lenya.cms.publication.DublinCore#removeValue(java.lang.String, java.lang.String)
- */
- public void removeValue(String key, String value) throws DocumentException {
- String[] existingValues = getElementOrTerm(key);
- List list = new ArrayList(Arrays.asList(existingValues));
-
- if (!list.contains(value)) {
- throw new DocumentException(
- "The key [" + key + "] does not contain the value [" + value + "]!");
- }
-
- list.remove(value);
- String[] newValues = (String[]) list.toArray(new String[list.size()]);
-
- List elementList = Arrays.asList(ELEMENTS);
- List termList = Arrays.asList(TERMS);
- if (elementList.contains(key)) {
- elements.put(key, newValues);
- } else if (termList.contains(key)) {
- terms.put(key, newValues);
- } else {
- throw new DocumentException(
- "The key [" + key + "] does not refer to a dublin core element or term!");
- }
- }
-
- /**
- * @see org.apache.lenya.cms.publication.DublinCore#removeAllValues(java.lang.String)
- */
- public void removeAllValues(String key) throws DocumentException {
- List elementList = Arrays.asList(ELEMENTS);
- List termList = Arrays.asList(TERMS);
- if (elementList.contains(key)) {
- elements.put(key, new String[0]);
- } else if (termList.contains(key)) {
- terms.put(key, new String[0]);
- } else {
- throw new DocumentException(
- "The key [" + key + "] does not refer to a dublin core element or term!");
- }
- }
-
- /**
- * @see org.apache.lenya.cms.publication.DublinCore#replaceBy(org.apache.lenya.cms.publication.DublinCore)
- */
- public void replaceBy(DublinCore other) throws DocumentException {
- for (int i = 0; i < ELEMENTS.length; i++) {
- String key = ELEMENTS[i];
- removeAllValues(key);
- addValues(key, other.getValues(key));
- }
- for (int i = 0; i < TERMS.length; i++) {
- String key = TERMS[i];
- removeAllValues(key);
- addValues(key, other.getValues(key));
- }
- }
-
+ }
+ }
+ try{
+ DocumentHelper.writeDocument(doc, infofile);
+ }catch(TransformerConfigurationException e){
+ throw new DocumentException(e);
+ }catch(TransformerException e){
+ throw new DocumentException(e);
+ }catch(IOException e){
+ throw new DocumentException(e);
+ }
+ }
+ /**
+ * Returns the Lenya meta data element.
+ *
+ * @param doc
+ * The XML document.
+ * @return A DOM element.
+ */
+ protected Element getMetaElement(org.w3c.dom.Document doc) throws DocumentException {
+ NamespaceHelper namespaceHelper = new NamespaceHelper(PageEnvelope.NAMESPACE, PageEnvelope.DEFAULT_PREFIX, doc);
+ Element documentElement = doc.getDocumentElement();
+ Element metaElement = namespaceHelper.getFirstChild(documentElement, META);
+ if(metaElement == null){
+ metaElement = namespaceHelper.createElement(META);
+ Element[] children = DocumentHelper.getChildren(documentElement);
+ if(children.length == 0){
+ documentElement.appendChild(metaElement);
+ }else{
+ documentElement.insertBefore(metaElement, children[0]);
+ }
+ }
+ return metaElement;
+ }
+ /**
+ * Returns the first value for a certain key.
+ *
+ * @param key
+ * The key.
+ * @return A string.
+ */
+ public String getFirstValue(String key) throws DocumentException {
+ String value = null;
+ String[] values = getElementOrTerm(key);
+ if(values.length > 0){
+ value = values[0];
+ }
+ return value;
+ }
+ /**
+ * Returns the element or term values, resp., for a certain key.
+ *
+ * @param key
+ * The key.
+ * @return An array of strings.
+ */
+ protected String[] getElementOrTerm(String key) throws DocumentException {
+ String[] values;
+ List elementList = Arrays.asList(ELEMENTS);
+ List termList = Arrays.asList(TERMS);
+ if(elementList.contains(key)){
+ values = (String[]) elements.get(key);
+ }else if(termList.contains(key)){
+ values = (String[]) terms.get(key);
+ }else{
+ throw new DocumentException("The key [" + key + "] does not refer to a dublin core element or term!");
+ }
+ if(values == null){
+ values = new String[0];
+ }
+ return values;
+ }
+ /**
+ * @see org.apache.lenya.cms.publication.DublinCore#getValues(java.lang.String)
+ */
+ public String[] getValues(String key) throws DocumentException {
+ return getElementOrTerm(key);
+ }
+ /**
+ * @see org.apache.lenya.cms.publication.DublinCore#addValue(java.lang.String, java.lang.String)
+ */
+ public void addValue(String key, String value) throws DocumentException {
+ String[] existingValues = getElementOrTerm(key);
+ List list = new ArrayList(Arrays.asList(existingValues));
+ list.add(value);
+ String[] newValues = (String[]) list.toArray(new String[list.size()]);
+ List elementList = Arrays.asList(ELEMENTS);
+ List termList = Arrays.asList(TERMS);
+ if(elementList.contains(key)){
+ elements.put(key, newValues);
+ }else if(termList.contains(key)){
+ terms.put(key, newValues);
+ }else{
+ throw new DocumentException("The key [" + key + "] does not refer to a dublin core element or term!");
+ }
+ }
+ /**
+ * @see org.apache.lenya.cms.publication.DublinCore#setValue(java.lang.String, java.lang.String)
+ */
+ public void setValue(String key, String value) throws DocumentException {
+ String[] newValues = {value};
+ List elementList = Arrays.asList(ELEMENTS);
+ List termList = Arrays.asList(TERMS);
+ if(elementList.contains(key)){
+ elements.put(key, newValues);
+ }else if(termList.contains(key)){
+ terms.put(key, newValues);
+ }else{
+ throw new DocumentException("The key [" + key + "] does not refer to a dublin core element or term!");
+ }
+ }
+ /**
+ * @see org.apache.lenya.cms.publication.DublinCore#addValues(java.lang.String, java.lang.String[])
+ */
+ public void addValues(String key, String[] values) throws DocumentException {
+ for(int i = 0; i < values.length; i++){
+ addValue(key, values[i]);
+ }
+ }
+ /**
+ * @see org.apache.lenya.cms.publication.DublinCore#removeValue(java.lang.String, java.lang.String)
+ */
+ public void removeValue(String key, String value) throws DocumentException {
+ String[] existingValues = getElementOrTerm(key);
+ List list = new ArrayList(Arrays.asList(existingValues));
+ if(!list.contains(value)){
+ throw new DocumentException("The key [" + key + "] does not contain the value [" + value + "]!");
+ }
+ list.remove(value);
+ String[] newValues = (String[]) list.toArray(new String[list.size()]);
+ List elementList = Arrays.asList(ELEMENTS);
+ List termList = Arrays.asList(TERMS);
+ if(elementList.contains(key)){
+ elements.put(key, newValues);
+ }else if(termList.contains(key)){
+ terms.put(key, newValues);
+ }else{
+ throw new DocumentException("The key [" + key + "] does not refer to a dublin core element or term!");
+ }
+ }
+ /**
+ * @see org.apache.lenya.cms.publication.DublinCore#removeAllValues(java.lang.String)
+ */
+ public void removeAllValues(String key) throws DocumentException {
+ List elementList = Arrays.asList(ELEMENTS);
+ List termList = Arrays.asList(TERMS);
+ if(elementList.contains(key)){
+ elements.put(key, new String[0]);
+ }else if(termList.contains(key)){
+ terms.put(key, new String[0]);
+ }else{
+ throw new DocumentException("The key [" + key + "] does not refer to a dublin core element or term!");
+ }
+ }
+ /**
+ * @see org.apache.lenya.cms.publication.DublinCore#replaceBy(org.apache.lenya.cms.publication.DublinCore)
+ */
+ public void replaceBy(DublinCore other) throws DocumentException {
+ for(int i = 0; i < ELEMENTS.length; i++){
+ String key = ELEMENTS[i];
+ removeAllValues(key);
+ addValues(key, other.getValues(key));
+ }
+ for(int i = 0; i < TERMS.length; i++){
+ String key = TERMS[i];
+ removeAllValues(key);
+ addValues(key, other.getValues(key));
+ }
+ }
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.