1 17 18 19 20 package org.apache.lenya.cms.cocoon.components.modules.input; 21 22 import java.util.Arrays ; 23 import java.util.Iterator ; 24 import java.util.Map ; 25 26 import org.apache.avalon.framework.configuration.Configuration; 27 import org.apache.avalon.framework.configuration.ConfigurationException; 28 import org.apache.cocoon.components.modules.input.AbstractInputModule; 29 import org.apache.lenya.cms.publication.PageEnvelope; 30 import org.apache.lenya.cms.publication.PageEnvelopeFactory; 31 import org.apache.lenya.cms.publication.Publication; 32 import org.apache.lenya.cms.publication.SiteTree; 33 import org.apache.lenya.cms.publication.SiteTreeNode; 34 35 public class SitetreeModule extends AbstractInputModule { 36 37 public static final String AUTHORING_NODE = "authoring-node"; 38 public static final String LIVE_NODE = "live-node"; 39 public static final String TRASH_NODE = "trash-node"; 40 public static final String ARCHIVE_NODE = "archive-node"; 41 public static final String FIRST_CHILD_ID = "first-child-id"; 42 43 protected static final String [] PARAMETER_NAMES = { AUTHORING_NODE, LIVE_NODE, TRASH_NODE, ARCHIVE_NODE, FIRST_CHILD_ID }; 44 45 48 public Object getAttribute(String name, Configuration modeConf, Map objectModel) 49 throws ConfigurationException { 50 51 Object value = null; 52 53 try { 54 PageEnvelope envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel); 55 Publication publication = envelope.getPublication(); 56 57 if (name.equals(AUTHORING_NODE)) { 58 SiteTree authoringTree = publication.getTree(Publication.AUTHORING_AREA); 59 value = authoringTree.getNode(envelope.getDocument().getId()); 60 } 61 62 if (name.equals(LIVE_NODE)) { 63 SiteTree liveTree = publication.getTree(Publication.LIVE_AREA); 64 value = liveTree.getNode(envelope.getDocument().getId()); 65 } 66 67 if (name.equals(TRASH_NODE)) { 68 SiteTree trashTree = publication.getTree(Publication.TRASH_AREA); 69 value = trashTree.getNode(envelope.getDocument().getId()); 70 } 71 72 if (name.equals(ARCHIVE_NODE)) { 73 SiteTree archiveTree = publication.getTree(Publication.ARCHIVE_AREA); 74 value = archiveTree.getNode(envelope.getDocument().getId()); 75 } 76 77 if (name.equals(FIRST_CHILD_ID)) { 78 SiteTree siteTree = publication.getTree(envelope.getDocument().getArea()); 79 SiteTreeNode node = siteTree.getNode(envelope.getDocument().getId()); 80 SiteTreeNode[] children = node.getChildren(envelope.getDocument().getLanguage()); 81 if (children.length > 0){ 82 value = children[0].getId(); 83 } else { 84 value = null; 85 } 86 } 87 88 } catch (Exception e) { 89 throw new ConfigurationException("Obtaining value for [" + name + "] failed: ", e); 90 } 91 92 return value; 93 } 94 95 98 public Iterator getAttributeNames(Configuration modeConf, Map objectModel) 99 throws ConfigurationException { 100 return Arrays.asList(PARAMETER_NAMES).iterator(); 101 } 102 103 106 public Object [] getAttributeValues(String name, Configuration modeConf, Map objectModel) 107 throws ConfigurationException { 108 Object [] objects = { getAttribute(name, modeConf, objectModel) }; 109 return objects; 110 } 111 112 } 113 | Popular Tags |