You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jh...@apache.org on 2006/03/11 10:57:29 UTC
svn commit: r385045 - in /cocoon/branches/BRANCH_2_1_X:
src/java/org/apache/cocoon/transformation/RoleFilterTransformer.java
status.xml
Author: jheymans
Date: Sat Mar 11 01:57:27 2006
New Revision: 385045
URL: http://svn.apache.org/viewcvs?rev=385045&view=rev
Log:
<action dev="JHS" type="fix" fixes-bug="COCOON-1335" due-to="Michal Durdina" due-to-email="durdina@asset.sk">
Removed dependency of RoleFilterTransformer on buggy FilterTransformer.
Also thanks to Andrew Stevens for updating the patch against recent branch and Doug Bennet for the reminder.
</action>
Modified:
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/RoleFilterTransformer.java
cocoon/branches/BRANCH_2_1_X/status.xml
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/RoleFilterTransformer.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/RoleFilterTransformer.java?rev=385045&r1=385044&r2=385045&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/RoleFilterTransformer.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/RoleFilterTransformer.java Sat Mar 11 01:57:27 2006
@@ -17,9 +17,11 @@
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
+import org.apache.excalibur.source.SourceValidity;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@@ -63,19 +65,23 @@
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @version CVS $Id$
*/
-public class RoleFilterTransformer extends FilterTransformer {
+public class RoleFilterTransformer
+ extends AbstractTransformer
+ implements CacheableProcessingComponent {
private final static String URI = "http://apache.org/cocoon/role-filter/1.0";
private final static String RESTRICT = "restricted";
private final static String VIEW = "read-only";
+
Request request = null;
-
+ private int skipCounter = 0;
+
public RoleFilterTransformer() {
}
public final void setup(SourceResolver resolver, Map objectModel, String src, Parameters params)
throws ProcessingException, SAXException, IOException {
- super.setup(resolver, objectModel, src, params);
this.request = ObjectModelHelper.getRequest(objectModel);
+ this.skipCounter = 0;
}
/**
@@ -87,48 +93,51 @@
public final void startElement(String uri, String loc, String raw, Attributes a)
throws SAXException {
- int roleIndex = a.getIndex(RoleFilterTransformer.URI, RoleFilterTransformer.RESTRICT);
- int viewIndex = a.getIndex(RoleFilterTransformer.URI, RoleFilterTransformer.VIEW);
- boolean propogate = true;
- boolean readOnly = false;
-
- if (roleIndex >= 0) {
- String roleRestriction = a.getValue(roleIndex);
- StringTokenizer roles = new StringTokenizer(roleRestriction, ",", false);
- propogate = false;
-
- while ((! propogate) && roles.hasMoreTokens()) {
- if (request.isUserInRole(roles.nextToken())) {
- propogate = true;
- }
- }
- }
-
- if (! propogate) {
- super.elementName = loc;
+ if (this.skipCounter > 0) {
+ this.skipCounter++;
} else {
- if (viewIndex >= 0) {
- String viewRestriction = a.getValue(viewIndex);
- StringTokenizer roles = new StringTokenizer(viewRestriction, ",", false);
+ int roleIndex = a.getIndex(RoleFilterTransformer.URI, RoleFilterTransformer.RESTRICT);
+ int viewIndex = a.getIndex(RoleFilterTransformer.URI, RoleFilterTransformer.VIEW);
+ boolean propogate = true;
+ boolean readOnly = false;
+
+ if (roleIndex >= 0) {
+ String roleRestriction = a.getValue(roleIndex);
+ StringTokenizer roles = new StringTokenizer(roleRestriction, ",", false);
+ propogate = false;
- while ((! readOnly) && roles.hasMoreTokens()) {
+ while ((! propogate) && roles.hasMoreTokens()) {
if (request.isUserInRole(roles.nextToken())) {
- readOnly = true;
+ propogate = true;
}
}
}
- }
- super.startElement(uri, loc, raw,
- this.copyAttributes(a, roleIndex, viewIndex, readOnly));
+ if (propogate) {
+ if (viewIndex >= 0) {
+ String viewRestriction = a.getValue(viewIndex);
+ StringTokenizer roles = new StringTokenizer(viewRestriction, ",", false);
+
+ while ((! readOnly) && roles.hasMoreTokens()) {
+ if (request.isUserInRole(roles.nextToken())) {
+ readOnly = true;
+ }
+ }
+ }
+ super.startElement(uri, loc, raw,
+ this.copyAttributes(a, roleIndex, viewIndex, readOnly));
+ } else {
+ this.skipCounter = 1;
+ }
+ }
}
public final void endElement(String uri, String loc, String raw)
throws SAXException {
- super.endElement(uri, loc, raw);
-
- if (! super.skip) {
- super.elementName = "";
+ if (skipCounter > 0) {
+ skipCounter--;
+ } else {
+ super.endElement(uri, loc, raw);
}
}
@@ -158,5 +167,51 @@
public void recycle() {
this.request = null;
super.recycle();
+ }
+
+ public void startEntity(String name) throws SAXException {
+ if (this.skipCounter == 0) {
+ super.startEntity(name);
+ }
+ }
+
+ public void endEntity(String name) throws SAXException {
+ if (this.skipCounter == 0) {
+ super.endEntity(name);
+ }
+ }
+
+ public void comment(char[] ch, int start, int len) throws SAXException {
+ if (this.skipCounter == 0) {
+ super.comment(ch, start, len);
+ }
+ }
+
+ public void characters(char[] c, int start, int len) throws SAXException {
+ if (this.skipCounter == 0) {
+ super.characters(c, start, len);
+ }
+ }
+
+ public void startCDATA() throws SAXException {
+ if (this.skipCounter == 0) {
+ super.startCDATA();
+ }
+ }
+
+ public void processingInstruction(String target, String data) throws SAXException {
+ if (this.skipCounter == 0) {
+ super.processingInstruction(target, data);
+ }
+ }
+
+ public SourceValidity getValidity() {
+ return null;
+ }
+
+ public void endCDATA() throws SAXException {
+ if (this.skipCounter == 0) {
+ super.endCDATA();
+ }
}
}
Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?rev=385045&r1=385044&r2=385045&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Sat Mar 11 01:57:27 2006
@@ -180,6 +180,10 @@
<release version="@version@" date="@date@">
-->
<release version="2.1.9" date="TBD">
+ <action dev="JHS" type="fix" fixes-bug="COCOON-1335" due-to="Michal Durdina" due-to-email="durdina@asset.sk">
+ Removed dependency of RoleFilterTransformer on buggy FilterTransformer.
+ Also thanks to Andrew Stevens for updating the patch against recent branch and Doug Bennet for the reminder.
+ </action>
<action dev="JBQ" type="add" fixes-bug="COCOON-1729" due-to="Rolf Metternich" due-to-email="rolf.metternich@ahafabrik.de">
Allow to add multiple rows at once to a Repeater using <fd:repeater-action command="add-row" number-of-rows="5" ...>
</action>