1 17 18 19 20 package org.apache.lenya.cms.cocoon.components.modules.input; 21 22 import java.util.ArrayList ; 23 import java.util.Arrays ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.Map ; 27 28 import org.apache.avalon.framework.configuration.Configuration; 29 import org.apache.avalon.framework.configuration.ConfigurationException; 30 import org.apache.lenya.cms.publication.Document; 31 import org.apache.lenya.cms.publication.DocumentException; 32 import org.apache.lenya.cms.publication.DublinCoreImpl; 33 34 37 public class DublinCoreModule extends AbstractPageEnvelopeModule { 38 39 42 public Object getAttribute(String name, Configuration modeConf, Map objectModel) 43 throws ConfigurationException { 44 45 if (!Arrays.asList(DublinCoreImpl.ELEMENTS).contains(name) 46 && !Arrays.asList(DublinCoreImpl.TERMS).contains(name)) { 47 throw new ConfigurationException("The attribute [" + name + "] is not supported!"); 48 } 49 50 Document document = getEnvelope(objectModel).getDocument(); 51 52 if (document == null) { 53 throw new ConfigurationException("There is no document for this page envelope!"); 54 } 55 Object value; 56 try { 57 value = document.getDublinCore().getFirstValue(name); 58 } catch (DocumentException e) { 59 throw new ConfigurationException( 60 "Obtaining dublin core value for [" + name + "] failed: ", 61 e); 62 } 63 64 return value; 65 } 66 67 70 public Iterator getAttributeNames(Configuration modeConf, Map objectModel) 71 throws ConfigurationException { 72 73 List names = new ArrayList (); 74 names.addAll(Arrays.asList(DublinCoreImpl.ELEMENTS)); 75 names.addAll(Arrays.asList(DublinCoreImpl.TERMS)); 76 return names.iterator(); 77 } 78 79 82 public Object [] getAttributeValues(String name, Configuration modeConf, Map objectModel) 83 throws ConfigurationException { 84 Object [] objects = { getAttribute(name, modeConf, objectModel)}; 85 return objects; 86 } 87 88 } 89 | Popular Tags |