cziegeler 02/01/08 02:47:46
Modified: src/java/org/apache/cocoon/caching NOPCacheValidity.java
src/java/org/apache/cocoon/generation
AbstractServerPage.java
FragmentExtractorGenerator.java
src/java/org/apache/cocoon/reading DatabaseReader.java
src/java/org/apache/cocoon/serialization
AbstractTextSerializer.java FOPSerializer.java
SVGSerializer.java
src/java/org/apache/cocoon/transformation
FilterTransformer.java
FragmentExtractorTransformer.java
RoleFilterTransformer.java
Log:
1. Added constant to NOPCacheValidity
2. Changed all uses of NOPCacheValidity to use this constant
3. Made the FilterTransformer cacheable
Revision Changes Path
1.2 +3 -1
xml-cocoon2/src/java/org/apache/cocoon/caching/NOPCacheValidity.java
Index: NOPCacheValidity.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/caching/NOPCacheValidity.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NOPCacheValidity.java 3 Jan 2002 12:31:08 -0000 1.1
+++ NOPCacheValidity.java 8 Jan 2002 10:47:45 -0000 1.2
@@ -12,10 +12,12 @@
* This might be the most used CacheValidity object for serializers.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.1 $ $Date: 2002/01/03 12:31:08 $
+ * @version CVS $Revision: 1.2 $ $Date: 2002/01/08 10:47:45 $
*/
public final class NOPCacheValidity
implements CacheValidity {
+
+ public static final CacheValidity CACHE_VALIDITY = new NOPCacheValidity();
public boolean isValid(CacheValidity validity) {
return validity instanceof NOPCacheValidity;
1.2 +2 -2
xml-cocoon2/src/java/org/apache/cocoon/generation/AbstractServerPage.java
Index: AbstractServerPage.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/generation/AbstractServerPage.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractServerPage.java 3 Jan 2002 12:31:16 -0000 1.1
+++ AbstractServerPage.java 8 Jan 2002 10:47:45 -0000 1.2
@@ -22,7 +22,7 @@
* declares variables that must be explicitly initialized by code generators.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a>
- * @version CVS $Revision: 1.1 $ $Date: 2002/01/03 12:31:16 $
+ * @version CVS $Revision: 1.2 $ $Date: 2002/01/08 10:47:45 $
*/
public abstract class AbstractServerPage
extends ServletGenerator implements CompiledComponent, Cacheable
@@ -103,7 +103,7 @@
if (hasContentChanged(request))
return null;
else
- return new NOPCacheValidity();
+ return NOPCacheValidity.CACHE_VALIDITY;
}
// FIXME: Add more methods!
1.2 +2 -2
xml-cocoon2/src/java/org/apache/cocoon/generation/FragmentExtractorGenerator.java
Index: FragmentExtractorGenerator.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/generation/FragmentExtractorGenerator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FragmentExtractorGenerator.java 3 Jan 2002 12:31:16 -0000 1.1
+++ FragmentExtractorGenerator.java 8 Jan 2002 10:47:45 -0000 1.2
@@ -36,7 +36,7 @@
* This is by no means complete yet, but it should prove useful, particularly
* for offline generation.
* @author <a href="mailto:[EMAIL PROTECTED]">Paul Russell</a>
- * @version CVS $Revision: 1.1 $ $Date: 2002/01/03 12:31:16 $
+ * @version CVS $Revision: 1.2 $ $Date: 2002/01/08 10:47:45 $
*/
public class FragmentExtractorGenerator extends AbstractGenerator
implements Recyclable, Cacheable {
@@ -83,7 +83,7 @@
* component is currently not cacheable.
*/
public CacheValidity generateValidity() {
- return new NOPCacheValidity();
+ return NOPCacheValidity.CACHE_VALIDITY;
}
public void generate() throws SAXException {
1.2 +1 -1
xml-cocoon2/src/java/org/apache/cocoon/reading/DatabaseReader.java
Index: DatabaseReader.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/reading/DatabaseReader.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DatabaseReader.java 3 Jan 2002 12:31:18 -0000 1.1
+++ DatabaseReader.java 8 Jan 2002 10:47:45 -0000 1.2
@@ -292,7 +292,7 @@
return new TimeStampCacheValidity(this.lastModified);
} else {
if (this.defaultCache) {
- return new NOPCacheValidity();
+ return NOPCacheValidity.CACHE_VALIDITY;
} else {
return null;
}
1.2 +48 -48
xml-cocoon2/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java
Index: AbstractTextSerializer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractTextSerializer.java 3 Jan 2002 12:31:19 -0000 1.1
+++ AbstractTextSerializer.java 8 Jan 2002 10:47:45 -0000 1.2
@@ -44,7 +44,7 @@
* (Apache Software Foundation, Exoffice Technologies)
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
- * @version CVS $Revision: 1.1 $ $Date: 2002/01/03 12:31:19 $
+ * @version CVS $Revision: 1.2 $ $Date: 2002/01/08 10:47:45 $
*/
public abstract class AbstractTextSerializer extends AbstractSerializer implements
Configurable, Cacheable, Poolable {
@@ -62,23 +62,23 @@
* The default output buffer size.
*/
private static final int DEFAULT_BUFFER_SIZE = 8192;
-
+
/**
* The output buffer size to use.
*/
private int outputBufferSize = DEFAULT_BUFFER_SIZE;
-
+
/**
* Cache for avoiding unnecessary checks of namespaces abilities.
* It associates a Boolean to the transformer class name.
*/
private static Map needsNamespaceCache = new HashMap();
-
+
/**
* The pipe that adds namespaces as xmlns attributes.
*/
private NamespaceAsAttributes namespacePipe;
-
+
/**
* Interpose namespace pipe if needed.
*/
@@ -151,7 +151,7 @@
Configuration bsc = conf.getChild("buffer-size", false);
if(null != bsc)
outputBufferSize = bsc.getValueAsInteger(DEFAULT_BUFFER_SIZE);
-
+
// configure xalan
Configuration cdataSectionElements =
conf.getChild("cdata-section-elements");
Configuration dtPublic = conf.getChild("doctype-public");
@@ -194,7 +194,7 @@
if (! version.getLocation().equals("-")) {
format.put(OutputKeys.VERSION,version.getValue());
}
-
+
// Check if we need namespace as attributes.
try {
if (needsNamespacesAsAttributes()) {
@@ -228,9 +228,9 @@
* component is currently not cacheable.
*/
public CacheValidity generateValidity() {
- return new NOPCacheValidity();
+ return NOPCacheValidity.CACHE_VALIDITY;
}
-
+
/**
* Checks if the used Trax implementation correctly handles namespaces set using
* <code>startPrefixMapping()</code>, but wants them also as 'xmlns:'
attributes.
@@ -240,75 +240,75 @@
* xmlns:xxx attributes) and check if they are present in the resulting text.
*/
protected boolean needsNamespacesAsAttributes() throws Exception {
-
+
SAXTransformerFactory factory = getTransformerFactory();
-
+
Boolean cacheValue =
(Boolean)this.needsNamespaceCache.get(factory.getClass().getName());
if (cacheValue != null) {
return cacheValue.booleanValue();
-
+
} else {
// Serialize a minimal document to check how namespaces are handled.
StringWriter writer = new StringWriter();
-
+
String uri = "namespaceuri";
String prefix = "nsp";
String check = "xmlns:" + prefix + "='" + uri + "'";
-
+
TransformerHandler handler = factory.newTransformerHandler();
-
+
handler.setResult(new StreamResult(writer));
handler.getTransformer().setOutputProperties(format);
-
+
// Output a single element
handler.startDocument();
handler.startPrefixMapping(prefix, uri);
handler.startElement(uri, "element", "", new AttributesImpl());
handler.endPrefixMapping(prefix);
handler.endDocument();
-
+
String text = writer.toString();
-
+
// Check if the namespace is there (replace " by ' to be sure of what
we search in)
boolean needsIt = (text.replace('"', '\'').indexOf(check) == -1);
-
+
String msg = needsIt ? " needs namespace attributes (will be slower)." :
" handles correctly namespaces.";
-
+
getLogger().debug("Trax handler " + handler.getClass().getName() + msg);
-
+
this.needsNamespaceCache.put(factory.getClass().getName(), new
Boolean(needsIt));
-
+
return needsIt;
}
}
//--------------------------------------------------------------------------------------------
-
+
/**
* A pipe that ensures that all namespace prefixes are also present as
* 'xmlns:' attributes. This used to circumvent Xalan's serialization behaviour
* which is to ignore namespaces if they're not present as 'xmlns:xxx'
attributes.
*/
public static class NamespaceAsAttributes extends AbstractXMLPipe {
-
+
/**
* The prefixes of startPreficMapping() declarations for the coming element.
*/
private List prefixList = new ArrayList();
-
+
/**
* The URIs of startPrefixMapping() declarations for the coming element.
*/
private List uriList = new ArrayList();
-
+
/**
* Maps of URI<->prefix mappings. Used to work around a bug in the Xalan
* serializer.
*/
private Map uriToPrefixMap = new HashMap();
private Map prefixToUriMap = new HashMap();
-
+
/**
* True if there has been some startPrefixMapping() for the coming element.
*/
@@ -333,7 +333,7 @@
this.hasMappings = true;
this.prefixList.add(prefix);
this.uriList.add(uri);
-
+
// append the prefix colon now, in order to save concatenations later,
but
// only for non-empty prefixes.
if(prefix.length() > 0) {
@@ -341,12 +341,12 @@
} else {
this.uriToPrefixMap.put(uri, prefix);
}
-
+
this.prefixToUriMap.put(prefix, uri);
-
+
super.startPrefixMapping(prefix, uri);
}
-
+
/**
* Ensure all namespace declarations are present as <code>xmlns:</code>
attributes
* and add those needed before calling superclass. This is a workaround for
a Xalan bug
@@ -355,27 +355,27 @@
*/
public void startElement(String eltUri, String eltLocalName, String
eltQName, Attributes attrs)
throws SAXException {
-
+
// try to restore the qName. The map already contains the colon
if (null != eltUri && eltUri.length() != 0 &&
this.uriToPrefixMap.containsKey(eltUri) )
eltQName = (String) this.uriToPrefixMap.get(eltUri) + eltLocalName;
-
+
if (this.hasMappings) {
// Add xmlns* attributes where needed
-
+
// New Attributes if we have to add some.
AttributesImpl newAttrs = null;
-
+
int mappingCount = this.prefixList.size();
int attrCount = attrs.getLength();
-
+
for(int mapping = 0; mapping < mappingCount; mapping++) {
-
+
// Build infos for this namespace
String uri = (String)this.uriList.get(mapping);
String prefix = (String)this.prefixList.get(mapping);
String qName = prefix.equals("") ? "xmlns" : ("xmlns:" +
prefix);
-
+
// Search for the corresponding xmlns* attribute
boolean found = false;
find : for (int attr = 0; attr < attrCount; attr++) {
@@ -389,7 +389,7 @@
break find;
}
}
-
+
if (!found) {
// Need to add this namespace
if (newAttrs == null) {
@@ -400,7 +400,7 @@
else
newAttrs = new AttributesImpl(attrs);
}
-
+
if (prefix.equals("")) {
newAttrs.addAttribute(Constants.XML_NAMESPACE_URI,
"xmlns", "xmlns", "CDATA", uri);
} else {
@@ -408,10 +408,10 @@
}
}
} // end for mapping
-
+
// Cleanup for the next element
clearMappings();
-
+
// Start element with new attributes, if any
super.startElement(eltUri, eltLocalName, eltQName, newAttrs == null
? attrs : newAttrs);
}
@@ -420,8 +420,8 @@
super.startElement(eltUri, eltLocalName, eltQName, attrs);
}
}
-
-
+
+
/**
* Receive notification of the end of an element.
* Try to restore the element qName.
@@ -431,7 +431,7 @@
// try to restore the qName. The map already contains the colon
if(null != eltUri && eltUri.length() != 0 &&
this.uriToPrefixMap.containsKey(eltUri) )
eltQName = (String) this.uriToPrefixMap.get(eltUri) + eltLocalName;
-
+
super.endElement(eltUri, eltLocalName, eltQName);
}
@@ -448,10 +448,10 @@
this.uriToPrefixMap.remove((String) this.prefixToUriMap.get(prefix));
this.prefixToUriMap.remove(prefix);
}
-
+
super.endPrefixMapping(prefix);
}
-
+
/**
*
*/
@@ -462,7 +462,7 @@
clearMappings();
super.endDocument();
}
-
+
private void clearMappings()
{
this.hasMappings = false;
1.2 +11 -11
xml-cocoon2/src/java/org/apache/cocoon/serialization/FOPSerializer.java
Index: FOPSerializer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/serialization/FOPSerializer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FOPSerializer.java 3 Jan 2002 12:31:19 -0000 1.1
+++ FOPSerializer.java 8 Jan 2002 10:47:45 -0000 1.2
@@ -38,18 +38,18 @@
*/
protected Driver driver;
- /**
- * The current <code>Renderer</code>.
+ /**
+ * The current <code>Renderer</code>.
*/
protected Renderer renderer;
- /**
- * The Renderer Factory to use
+ /**
+ * The Renderer Factory to use
*/
protected static RendererFactory factory =
ExtendableRendererFactory.getRendererFactoryImplementation();
- /**
- * The current <code>mime-type</code>.
+ /**
+ * The current <code>mime-type</code>.
*/
protected String mimetype;
@@ -61,7 +61,7 @@
/**
* Set the configurations for this serializer.
*/
- public void configure(Configuration conf)
+ public void configure(Configuration conf)
throws ConfigurationException {
String userConfig = null;
java.io.File userConfigFile = null;
@@ -71,7 +71,7 @@
if (child != null) {
try {
userConfig = child.getAttribute("src");
- } catch(Exception ex) {
+ } catch(Exception ex) {
// No config file specified
}
}
@@ -96,7 +96,7 @@
}
}
- // Get the mime type.
+ // Get the mime type.
this.mimetype = conf.getAttribute("mime-type");
getLogger().debug("FOPSerializer mime-type:" + mimetype);
@@ -117,7 +117,7 @@
}
}
}
-
+
// Do we have a renderer yet?
if (this.renderer == null ) {
throw new ConfigurationException(
@@ -181,7 +181,7 @@
* component is currently not cacheable.
*/
public CacheValidity generateValidity() {
- return new NOPCacheValidity();
+ return NOPCacheValidity.CACHE_VALIDITY;
}
/**
1.2 +2 -2
xml-cocoon2/src/java/org/apache/cocoon/serialization/SVGSerializer.java
Index: SVGSerializer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/serialization/SVGSerializer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SVGSerializer.java 3 Jan 2002 12:31:19 -0000 1.1
+++ SVGSerializer.java 8 Jan 2002 10:47:45 -0000 1.2
@@ -48,7 +48,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Ross Burton</a>
- * @version CVS $Revision: 1.1 $ $Date: 2002/01/03 12:31:19 $
+ * @version CVS $Revision: 1.2 $ $Date: 2002/01/08 10:47:45 $
*/
public class SVGSerializer extends SVGBuilder
implements Composable, Serializer, Configurable, Poolable, Cacheable,
Contextualizable {
@@ -259,7 +259,7 @@
* component is currently not cacheable.
*/
public CacheValidity generateValidity() {
- return new NOPCacheValidity();
+ return NOPCacheValidity.CACHE_VALIDITY;
}
/**
1.2 +159 -128
xml-cocoon2/src/java/org/apache/cocoon/transformation/FilterTransformer.java
Index: FilterTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/FilterTransformer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FilterTransformer.java 3 Jan 2002 12:31:20 -0000 1.1
+++ FilterTransformer.java 8 Jan 2002 10:47:46 -0000 1.2
@@ -3,7 +3,11 @@
import org.apache.avalon.excalibur.pool.Poolable;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.caching.Cacheable;
+import org.apache.cocoon.caching.CacheValidity;
+import org.apache.cocoon.caching.NOPCacheValidity;
import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.util.HashUtil;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@@ -25,139 +29,166 @@
* Only the 3th block will be shown, containing only 5 row elements.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Sven Beauprez</a>
- * @version CVS $Revision: 1.1 $ $Date: 2002/01/03 12:31:20 $ $Author: giacomo $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
+ * @version CVS $Revision: 1.2 $ $Date: 2002/01/08 10:47:46 $ $Author: cziegeler $
*/
-public class FilterTransformer extends AbstractTransformer implements Poolable {
- private static final String ELEMENT = "element-name";
- private static final String COUNT = "count";
- private static final String BLOCKNR = "blocknr";
- private static final String BLOCK = "block";
- private static final String BLOCKID = "id";
- private static final int DEFAULT_COUNT = 10;
- private static final int DEFAULT_BLOCK = 1;
-
- private int counter;
- private int count;
- private int blocknr;
- private int currentBlocknr;
- protected String elementName;
- private String parentName;
- boolean skip;
- boolean foundIt;
-
- /** BEGIN SitemapComponent methods **/
- public void setup(SourceResolver resolver, Map objectModel, String source,
Parameters parameters)
- throws ProcessingException, SAXException, IOException {
- counter=0;
- currentBlocknr=0;
- skip=false;
- foundIt=false;
- parentName=null;
- elementName = parameters.getParameter(FilterTransformer.ELEMENT, "");
- count = parameters.getParameterAsInteger(FilterTransformer.COUNT,
FilterTransformer.DEFAULT_COUNT);
- blocknr = parameters.getParameterAsInteger(FilterTransformer.BLOCKNR,
FilterTransformer.DEFAULT_BLOCK);
- if (elementName == null || count == 0) {
- getLogger().warn("FilterTransformer: both "+ FilterTransformer.ELEMENT + "
and " +
+public class FilterTransformer
+extends AbstractTransformer
+implements Poolable, Cacheable {
+
+ private static final String ELEMENT = "element-name";
+ private static final String COUNT = "count";
+ private static final String BLOCKNR = "blocknr";
+ private static final String BLOCK = "block";
+ private static final String BLOCKID = "id";
+ private static final int DEFAULT_COUNT = 10;
+ private static final int DEFAULT_BLOCK = 1;
+
+ protected int counter;
+ protected int count;
+ protected int blocknr;
+ protected int currentBlocknr;
+ protected String elementName;
+ protected String parentName;
+ protected boolean skip;
+ protected boolean foundIt;
+
+ /** BEGIN SitemapComponent methods **/
+ public void setup(SourceResolver resolver,
+ Map objectModel,
+ String source,
+ Parameters parameters)
+ throws ProcessingException, SAXException, IOException {
+ this.counter=0;
+ this.currentBlocknr=0;
+ this.skip=false;
+ this.foundIt=false;
+ this.parentName=null;
+ this.elementName = parameters.getParameter(FilterTransformer.ELEMENT, "");
+ this.count = parameters.getParameterAsInteger(FilterTransformer.COUNT,
FilterTransformer.DEFAULT_COUNT);
+ this.blocknr = parameters.getParameterAsInteger(FilterTransformer.BLOCKNR,
FilterTransformer.DEFAULT_BLOCK);
+ if (this.elementName == null || this.elementName.equals("") || this.count
== 0) {
+ throw new ProcessingException("FilterTransformer: both "+
FilterTransformer.ELEMENT + " and " +
FilterTransformer.COUNT + " parameters need to be
specified");
+ }
}
- }
- /** END SitemapComponent methods **/
- protected boolean isSkipping() {
- return skip;
- }
-
- /** BEGIN SAX ContentHandler handlers **/
- public void startElement(String uri, String name, String raw, Attributes
attributes)
- throws SAXException {
- if (name.equalsIgnoreCase(elementName)) {
- foundIt=true;
- counter++;
- if (counter <= (count*(blocknr)) && counter > (count*(blocknr-1))) {
- skip=false;
- } else {
- skip=true;
- }
- if (currentBlocknr != (int)Math.ceil((float)counter/count)) {
- currentBlocknr = (int)Math.ceil((float)counter/count);
- AttributesImpl attr = new AttributesImpl();
-
attr.addAttribute(uri,FilterTransformer.BLOCKID,FilterTransformer.BLOCKID,"CDATA",String.valueOf(currentBlocknr));
- if (counter < count) {
-
super.contentHandler.startElement(uri,FilterTransformer.BLOCK,FilterTransformer.BLOCK,attr);
- } else {
-
super.contentHandler.endElement(uri,FilterTransformer.BLOCK,FilterTransformer.BLOCK);
-
super.contentHandler.startElement(uri,FilterTransformer.BLOCK,FilterTransformer.BLOCK,attr);
}
- }
- } else if (!foundIt) {
- parentName = name;
- }
- if (!skip) {
- super.contentHandler.startElement(uri,name,raw,attributes);
- }
- }
-
- public void endElement(String uri,String name,String raw)
- throws SAXException {
- if (name.equals(parentName) && foundIt) {
-
-
super.contentHandler.endElement(uri,FilterTransformer.BLOCK,FilterTransformer.BLOCK);
- super.contentHandler.endElement(uri,name,raw);
- foundIt=false;
- skip=false;
- } else if (!skip) {
- super.contentHandler.endElement(uri,name,raw);
- }
- }
-
- public void characters(char c[], int start, int len)
- throws SAXException {
- if (!skip) {
- super.contentHandler.characters(c,start,len);
- }
- }
-
- public void processingInstruction(String target, String data)
- throws SAXException {
- if (!skip) {
- super.contentHandler.processingInstruction(target, data);
- }
- }
-
- public void startEntity(String name)
- throws SAXException {
- if (!skip) {
- super.lexicalHandler.startEntity(name);
- }
- }
-
- public void endEntity(String name)
- throws SAXException {
- if (!skip) {
- super.lexicalHandler.endEntity( name);
- }
- }
-
- public void startCDATA()
- throws SAXException {
- if (!skip) {
- super.lexicalHandler.startCDATA();
- }
- }
-
- public void endCDATA()
- throws SAXException {
- if (!skip) {
- super.lexicalHandler.endCDATA();
- }
- }
-
- public void comment(char ch[], int start, int len)
- throws SAXException {
- if (!skip) {
- super.lexicalHandler.comment(ch, start, len);
+ /**
+ * Generate the unique key.
+ * This key must be unique inside the space of this component.
+ * This method must be invoked before the generateValidity() method.
+ *
+ * @return The generated key or <code>0</code> if the component
+ * is currently not cacheable.
+ */
+ public long generateKey() {
+ final StringBuffer hash = new StringBuffer(this.elementName);
+ hash.append('<').append(this.count).append('>').append(this.blocknr);
+ return HashUtil.hash(hash);
+ }
+
+ /**
+ * Generate the validity object.
+ * Before this method can be invoked the generateKey() method
+ * must be invoked.
+ *
+ * @return The generated validity object or <code>null</code> if the
+ * component is currently not cacheable.
+ */
+ public CacheValidity generateValidity() {
+ return NOPCacheValidity.CACHE_VALIDITY;
+ }
+
+ /** BEGIN SAX ContentHandler handlers **/
+ public void startElement(String uri, String name, String raw, Attributes
attributes)
+ throws SAXException {
+ if (name.equalsIgnoreCase(elementName)) {
+ this.foundIt = true;
+ this.counter++;
+ if (this.counter <= (this.count*(this.blocknr)) && this.counter >
(this.count*(this.blocknr-1))) {
+ this.skip = false;
+ } else {
+ this.skip = true;
+ }
+ if (this.currentBlocknr !=
(int)Math.ceil((float)this.counter/this.count)) {
+ this.currentBlocknr =
(int)Math.ceil((float)this.counter/this.count);
+ AttributesImpl attr = new AttributesImpl();
+
attr.addAttribute(uri,FilterTransformer.BLOCKID,FilterTransformer.BLOCKID,"CDATA",String.valueOf(this.currentBlocknr));
+ if (this.counter < this.count) {
+
super.contentHandler.startElement(uri,FilterTransformer.BLOCK,FilterTransformer.BLOCK,attr);
+ } else {
+
super.contentHandler.endElement(uri,FilterTransformer.BLOCK,FilterTransformer.BLOCK);
+
super.contentHandler.startElement(uri,FilterTransformer.BLOCK,FilterTransformer.BLOCK,attr);
+ }
+ }
+ } else if (!this.foundIt) {
+ this.parentName = name;
+ }
+ if (!this.skip) {
+ super.contentHandler.startElement(uri,name,raw,attributes);
+ }
+ }
+
+ public void endElement(String uri,String name,String raw)
+ throws SAXException {
+ if (this.foundIt && name.equals(this.parentName)) {
+
super.contentHandler.endElement(uri,FilterTransformer.BLOCK,FilterTransformer.BLOCK);
+ super.contentHandler.endElement(uri,name,raw);
+ this.foundIt = false;
+ this.skip = false;
+ } else if (!this.skip) {
+ super.contentHandler.endElement(uri,name,raw);
+ }
+ }
+
+ public void characters(char c[], int start, int len)
+ throws SAXException {
+ if (!this.skip) {
+ super.contentHandler.characters(c,start,len);
+ }
+ }
+
+ public void processingInstruction(String target, String data)
+ throws SAXException {
+ if (!this.skip) {
+ super.contentHandler.processingInstruction(target, data);
+ }
+ }
+
+ public void startEntity(String name)
+ throws SAXException {
+ if (!this.skip) {
+ super.lexicalHandler.startEntity(name);
+ }
+ }
+
+ public void endEntity(String name)
+ throws SAXException {
+ if (!this.skip) {
+ super.lexicalHandler.endEntity( name);
+ }
+ }
+
+ public void startCDATA()
+ throws SAXException {
+ if (!this.skip) {
+ super.lexicalHandler.startCDATA();
+ }
+ }
+
+ public void endCDATA()
+ throws SAXException {
+ if (!this.skip) {
+ super.lexicalHandler.endCDATA();
+ }
+ }
+
+ public void comment(char ch[], int start, int len)
+ throws SAXException {
+ if (!this.skip) {
+ super.lexicalHandler.comment(ch, start, len);
+ }
}
- }
- /** END SAX ContentHandler handlers **/
}
1.2 +2 -2
xml-cocoon2/src/java/org/apache/cocoon/transformation/FragmentExtractorTransformer.java
Index: FragmentExtractorTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/FragmentExtractorTransformer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FragmentExtractorTransformer.java 3 Jan 2002 12:31:20 -0000 1.1
+++ FragmentExtractorTransformer.java 8 Jan 2002 10:47:46 -0000 1.2
@@ -42,7 +42,7 @@
* <a href="http://c2.com/cgi/wiki?YouArentGonnaNeedIt">you aren't gonna need
it</a>,
* so I've just used very simple extraction based on a URI and local name.
* @author <a href="mailto:[EMAIL PROTECTED]">Paul Russell</a>
- * @version CVS $Revision: 1.1 $ $Date: 2002/01/03 12:31:20 $
+ * @version CVS $Revision: 1.2 $ $Date: 2002/01/08 10:47:46 $
*/
public class FragmentExtractorTransformer extends AbstractTransformer
implements Composable, Disposable, Cacheable, Poolable {
@@ -98,7 +98,7 @@
* component is currently not cacheable.
*/
public CacheValidity generateValidity() {
- return new NOPCacheValidity();
+ return NOPCacheValidity.CACHE_VALIDITY;
}
/**
1.2 +9 -2
xml-cocoon2/src/java/org/apache/cocoon/transformation/RoleFilterTransformer.java
Index: RoleFilterTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/RoleFilterTransformer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RoleFilterTransformer.java 3 Jan 2002 12:31:20 -0000 1.1
+++ RoleFilterTransformer.java 8 Jan 2002 10:47:46 -0000 1.2
@@ -43,7 +43,7 @@
* will work as expected.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
- * @version CVS $Revision: 1.1 $ $Date: 2002/01/03 12:31:20 $ $Author: giacomo $
+ * @version CVS $Revision: 1.2 $ $Date: 2002/01/08 10:47:46 $ $Author: cziegeler $
*/
public class RoleFilterTransformer extends FilterTransformer {
private final static String URI = "http://apache.org/cocoon/role-filter/1.0";
@@ -60,6 +60,13 @@
this.request = (Request) objectModel.get(Constants.REQUEST_OBJECT);
}
+ /**
+ * Disable caching
+ */
+ public long generateKey() {
+ return 0;
+ }
+
public final void startElement(String uri, String loc, String raw, Attributes a)
throws SAXException {
int roleIndex = a.getIndex(RoleFilterTransformer.URI,
RoleFilterTransformer.RESTRICT);
@@ -102,7 +109,7 @@
throws SAXException {
super.endElement(uri, loc, raw);
- if (! super.isSkipping()) {
+ if (! super.skip) {
super.elementName = "";
}
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]