1 16 package org.apache.cocoon.portal.tools.transformation; 17 18 import org.apache.avalon.framework.activity.Disposable; 19 import org.apache.avalon.framework.service.ServiceException; 20 import org.apache.avalon.framework.service.ServiceManager; 21 import org.apache.cocoon.portal.tools.PortalToolManager; 22 import org.apache.cocoon.portal.tools.service.UserRightsService; 23 import org.apache.cocoon.transformation.AbstractSAXTransformer; 24 import org.apache.cocoon.xml.IncludeXMLConsumer; 25 import org.w3c.dom.DocumentFragment ; 26 import org.xml.sax.Attributes ; 27 import org.xml.sax.SAXException ; 28 29 33 public class CheckAccessTransformer extends AbstractSAXTransformer 34 implements Disposable { 35 36 public static final String RIGHTS_NAMESPACE_URI = 37 "http://apache.org/cocoon/portal/tools/rights/1.0"; 38 39 public static final String ACCESS_TAG = "access"; 40 public static final String RIGHT_ID = "id"; 41 42 private UserRightsService urs; 43 private PortalToolManager ptm; 44 45 48 public void service(ServiceManager manager) throws ServiceException { 49 super.service(manager); 50 ptm = (PortalToolManager) this.manager.lookup(PortalToolManager.ROLE); 51 urs = ptm.getUserRightsService(); 52 } 53 54 57 public void startElement(String uri, String name, String raw, Attributes attr) 58 throws SAXException { 59 if (RIGHTS_NAMESPACE_URI.equals(uri) && ACCESS_TAG.equals(name)) { 60 String id = attr.getValue(RIGHT_ID); 61 if(!urs.userIsAllowed(id, this.ptm.getPortalObjects().getProfileManager().getUser())) { 62 this.stack.push(new Boolean (false)); 63 } 64 this.startRecording(); 65 } else { 66 super.startElement(uri, name, raw, attr); 67 } 68 } 69 70 73 public void endElement(String uri, String name, String raw) 74 throws SAXException { 75 if(RIGHTS_NAMESPACE_URI.equals(uri) && ACCESS_TAG.equals(name)) { 76 DocumentFragment frag = this.endRecording(); 77 Boolean ignore = (Boolean ) this.stack.pop(); 78 if(!ignore.booleanValue()) 79 IncludeXMLConsumer.includeNode(frag, this.contentHandler, this.lexicalHandler); 80 } else { 81 super.endElement(uri, name, raw); 82 } 83 } 84 85 88 public void dispose() { 89 if (this.manager != null) { 90 this.manager.release(ptm); 91 ptm = null; 92 this.manager = null; 93 } 94 super.dispose(); 95 } 96 } 97 | Popular Tags |