1 17 18 package org.apache.lenya.cms.ac; 19 20 import org.apache.avalon.framework.logger.AbstractLogEnabled; 21 import org.apache.avalon.framework.service.ServiceException; 22 import org.apache.avalon.framework.service.ServiceManager; 23 import org.apache.avalon.framework.service.Serviceable; 24 import org.apache.excalibur.source.Source; 25 import org.apache.excalibur.source.SourceResolver; 26 import org.apache.lenya.ac.AccessControlException; 27 import org.apache.lenya.ac.Accreditable; 28 import org.apache.lenya.ac.AccreditableManager; 29 import org.apache.lenya.ac.Policy; 30 import org.apache.lenya.ac.PolicyManager; 31 import org.apache.lenya.ac.impl.PolicyBuilder; 32 import org.apache.lenya.xml.DocumentHelper; 33 import org.w3c.dom.Document ; 34 35 39 public class SitemapPolicyManager extends AbstractLogEnabled implements PolicyManager, Serviceable { 40 41 45 public Policy getPolicy(AccreditableManager accreditableManager, String url) 46 throws AccessControlException { 47 48 url = url.substring(1); 49 50 int slashIndex = url.indexOf("/"); 51 if (slashIndex == -1) { 52 slashIndex = url.length(); 53 } 54 55 String publicationId = url.substring(0, slashIndex); 56 url = url.substring(publicationId.length()); 57 58 SourceResolver resolver = null; 59 Policy policy = null; 60 Source source = null; 61 try { 62 resolver = (SourceResolver) getManager().lookup(SourceResolver.ROLE); 63 64 String policyUrl = publicationId + "/policies" + url + ".acml"; 65 getLogger().debug("Policy URL: " + policyUrl); 66 source = resolver.resolveURI("cocoon://" + policyUrl); 67 Document document = DocumentHelper.readDocument(source.getInputStream()); 68 policy = new PolicyBuilder(accreditableManager).buildPolicy(document); 69 70 } catch (Exception e) { 71 throw new AccessControlException(e); 72 } finally { 73 if (resolver != null) { 74 if (source != null) { 75 resolver.release(source); 76 } 77 getManager().release(resolver); 78 } 79 } 80 return policy; 81 } 82 83 private ServiceManager manager; 84 85 88 public void service(ServiceManager manager) throws ServiceException { 89 this.manager = manager; 90 } 91 92 96 public ServiceManager getManager() { 97 return manager; 98 } 99 100 104 public void accreditableRemoved(AccreditableManager manager, Accreditable accreditable) 105 throws AccessControlException { 106 } 107 108 112 public void accreditableAdded(AccreditableManager manager, Accreditable accreditable) 113 throws AccessControlException { 114 } 115 116 } | Popular Tags |