1 17 18 package org.apache.lenya.cms.cocoon.components.modules.input; 19 20 import java.util.Collections ; 21 import java.util.Iterator ; 22 import java.util.Map ; 23 24 import org.apache.avalon.framework.configuration.Configuration; 25 import org.apache.avalon.framework.configuration.ConfigurationException; 26 import org.apache.avalon.framework.service.ServiceException; 27 import org.apache.avalon.framework.service.ServiceManager; 28 import org.apache.avalon.framework.service.Serviceable; 29 import org.apache.lenya.cms.publication.DocumentHelper; 30 31 43 public class DocumentURLModule extends AbstractPageEnvelopeModule implements Serviceable { 44 45 private ServiceManager manager; 46 47 51 public Object getAttribute(String name, Configuration modeConf, Map objectModel) 52 throws ConfigurationException { 53 54 String url; 55 56 final String [] attributes = name.split(":"); 57 58 if (attributes.length < 3) { 59 throw new ConfigurationException("Invalid number of parameters: " + attributes.length 60 + ". Expected 3 (area, document-id, language)"); 61 } 62 63 final String area = attributes[0]; 64 final String documentId = attributes[1]; 65 final String language = attributes[2]; 66 67 try { 68 DocumentHelper helper = new DocumentHelper(objectModel); 69 url = helper.getDocumentUrl(documentId, area, language); 70 } catch (Exception e) { 71 throw new ConfigurationException("Resolving attribute [" + name + "] failed: ", e); 72 } 73 74 return url; 75 } 76 77 81 public Iterator getAttributeNames(Configuration modeConf, Map objectModel) 82 throws ConfigurationException { 83 return Collections.EMPTY_SET.iterator(); 84 } 85 86 90 public Object [] getAttributeValues(String name, Configuration modeConf, Map objectModel) 91 throws ConfigurationException { 92 Object [] objects = { getAttribute(name, modeConf, objectModel) }; 93 return objects; 94 } 95 96 99 public void service(ServiceManager manager) throws ServiceException { 100 this.manager = manager; 101 } 102 103 } | Popular Tags |