You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by an...@apache.org on 2004/07/02 10:33:42 UTC
cvs commit: cocoon-2.1/src/java/org/apache/cocoon/reading ResourceReader.java
antonio 2004/07/02 01:33:42
Modified: src/java/org/apache/cocoon/generation FileGenerator.java
JXTemplateGenerator.java StatusGenerator.java
src/java/org/apache/cocoon/transformation
TraxTransformer.java
src/java/org/apache/cocoon/reading ResourceReader.java
Log:
Some fixes + formatting code
Revision Changes Path
1.10 +3 -2 cocoon-2.1/src/java/org/apache/cocoon/generation/FileGenerator.java
Index: FileGenerator.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/FileGenerator.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- FileGenerator.java 11 Jun 2004 20:32:20 -0000 1.9
+++ FileGenerator.java 2 Jul 2004 08:33:42 -0000 1.10
@@ -26,6 +26,7 @@
import org.xml.sax.SAXException;
import java.io.IOException;
+import java.io.Serializable;
import java.util.Map;
/**
@@ -88,7 +89,7 @@
*
* @return The generated key hashes the src
*/
- public java.io.Serializable getKey() {
+ public Serializable getKey() {
return this.inputSource.getURI();
}
1.51 +41 -53 cocoon-2.1/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java
Index: JXTemplateGenerator.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- JXTemplateGenerator.java 28 Jun 2004 09:25:39 -0000 1.50
+++ JXTemplateGenerator.java 2 Jul 2004 08:33:42 -0000 1.51
@@ -807,17 +807,12 @@
return getValue(expr, jexlContext, jxpathContext, null);
}
- static private int getIntValue(JXTExpression expr, JexlContext jexlContext,
- JXPathContext jxpathContext) throws Exception {
+ static private int getIntValue(JXTExpression expr, JexlContext jexlContext, JXPathContext jxpathContext) throws Exception {
Object res = getValue(expr, jexlContext, jxpathContext);
- if (res instanceof Number) {
- return ((Number)res).intValue();
- }
- return 0;
+ return res instanceof Number ? ((Number)res).intValue() : 0;
}
- static private Number getNumberValue(JXTExpression expr, JexlContext jexlContext,
- JXPathContext jxpathContext) throws Exception {
+ static private Number getNumberValue(JXTExpression expr, JexlContext jexlContext, JXPathContext jxpathContext) throws Exception {
Object res = getValue(expr, jexlContext, jxpathContext);
if (res instanceof Number) {
return (Number)res;
@@ -846,10 +841,13 @@
return res instanceof Boolean ? (Boolean)res : null;
}
+ private Object getNode(JXTExpression expr, JexlContext jexlContext, JXPathContext jxpathContext) throws Exception {
+ return getNode(expr, jexlContext, jxpathContext, null);
+ }
+
// Hack: try to prevent JXPath from converting result to a String
- private Object getNode(JXTExpression expr, JexlContext jexlContext,
- JXPathContext jxpathContext, Boolean lenient)
- throws Exception {
+ private Object getNode(JXTExpression expr, JexlContext jexlContext, JXPathContext jxpathContext, Boolean lenient)
+ throws Exception {
try {
Object compiled = expr.compiledExpression;
if (compiled instanceof CompiledExpression) {
@@ -858,29 +856,29 @@
if (lenient != null) jxpathContext.setLenient(lenient.booleanValue());
try {
Iterator iter = e.iteratePointers(jxpathContext);
- if (!iter.hasNext()) {
- return null;
- }
- Pointer first = (Pointer)iter.next();
- if (!iter.hasNext()) {
- return first.getNode();
- }
- List result = new LinkedList();
- result.add(first.getNode());
- boolean dom = (first.getNode() instanceof Node);
- while (iter.hasNext()) {
- Object obj = ((Pointer)iter.next()).getNode();
- dom = dom && (obj instanceof Node);
- result.add(obj);
- }
- Object[] arr;
- if (dom) {
- arr = new Node[result.size()];
- } else {
- arr = new Object[result.size()];
+ if (iter.hasNext()) {
+ Pointer first = (Pointer)iter.next();
+ if (iter.hasNext()) {
+ List result = new LinkedList();
+ result.add(first.getNode());
+ boolean dom = (first.getNode() instanceof Node);
+ while (iter.hasNext()) {
+ Object obj = ((Pointer)iter.next()).getNode();
+ dom = dom && (obj instanceof Node);
+ result.add(obj);
+ }
+ Object[] arr;
+ if (dom) {
+ arr = new Node[result.size()];
+ } else {
+ arr = new Object[result.size()];
+ }
+ result.toArray(arr);
+ return arr;
+ }
+ return first.getNode();
}
- result.toArray(arr);
- return arr;
+ return null;
} finally {
jxpathContext.setLenient(oldLenient);
}
@@ -898,10 +896,6 @@
}
}
- private Object getNode(JXTExpression expr, JexlContext jexlContext, JXPathContext jxpathContext) throws Exception {
- return getNode(expr, jexlContext, jxpathContext, null);
- }
-
static class Event {
final Locator location;
Event next; // in document order
@@ -2001,10 +1995,9 @@
stack.push(lastEvent);
}
- public void startElement(String namespaceURI, String localName,
- String qname, Attributes attrs) throws SAXException {
+ public void startElement(String namespaceURI, String localName, String qname, Attributes attrs) throws SAXException {
Event newEvent = null;
- AttributesImpl elementAttributes = new AttributesImpl( attrs );
+ AttributesImpl elementAttributes = new AttributesImpl(attrs);
int attributeCount = elementAttributes.getLength();
for (int i = 0; i < attributeCount; i++) {
String attributeURI = elementAttributes.getURI(i);
@@ -2140,10 +2133,8 @@
throw new SAXParseException("macro: \"name\" is required", locator, null);
}
} else if (localName.equals(PARAMETER)) {
- boolean syntaxErr = false;
- if (stack.size() < 1 ||
- !(stack.peek() instanceof StartDefine)) {
- syntaxErr = true;
+ if (stack.size() == 0 || !(stack.peek() instanceof StartDefine)) {
+ throw new SAXParseException("<parameter> not allowed here", locator, null);
} else {
String name = attrs.getValue("name");
String optional = attrs.getValue("optional");
@@ -2155,9 +2146,6 @@
throw new SAXParseException("parameter: \"name\" is required", locator, null);
}
}
- if (syntaxErr) {
- throw new SAXParseException("<parameter> not allowed here", locator, null);
- }
} else if (localName.equals(EVALBODY)) {
newEvent = new StartEvalBody(startElement);
} else if (localName.equals(EVAL)) {
@@ -2336,7 +2324,7 @@
* @see org.apache.avalon.excalibur.pool.Recyclable#recycle()
*/
public void recycle() {
- if ( this.resolver != null) {
+ if (this.resolver != null) {
this.resolver.release(this.inputSource);
}
this.inputSource = null;
@@ -3057,6 +3045,7 @@
throw new SAXParseException(e.getMessage(), ev.location, e);
}
} else if (ev instanceof StartTemplate) {
+ // EMPTY
} else if (ev instanceof StartEval) {
StartEval startEval = (StartEval)ev;
JXTExpression expr = startEval.value;
@@ -3229,12 +3218,12 @@
}
private Object getCurrentTemplateProperty(String propertyName) {
- final String uri = inputSource.getURI();
+ final String uri = this.inputSource.getURI();
StartDocument startEvent;
synchronized (cache) {
startEvent = (StartDocument)cache.get(uri);
}
- return startEvent != null ? startEvent.templateProperties.get(propertyName) : null;
+ return (startEvent != null) ? startEvent.templateProperties.get(propertyName) : null;
}
private NodeList toDOMNodeList(String elementName, StartInstruction si,
@@ -3242,8 +3231,7 @@
DOMBuilder builder = new DOMBuilder();
builder.startDocument();
builder.startElement(NS, elementName, elementName, EMPTY_ATTRS);
- execute(builder, jexlContext, jxpathContext, macroCall,
- si.next, si.endInstruction);
+ execute(builder, jexlContext, jxpathContext, macroCall, si.next, si.endInstruction);
builder.endElement(NS, elementName, elementName);
builder.endDocument();
Node node = builder.getDocument().getDocumentElement();
1.10 +15 -35 cocoon-2.1/src/java/org/apache/cocoon/generation/StatusGenerator.java
Index: StatusGenerator.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/StatusGenerator.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- StatusGenerator.java 26 May 2004 14:11:34 -0000 1.9
+++ StatusGenerator.java 2 Jul 2004 08:33:42 -0000 1.10
@@ -84,7 +84,6 @@
protected StoreJanitor storejanitor;
protected Store store_persistent;
-
/**
* The XML namespace for the output document.
*/
@@ -109,12 +108,12 @@
*/
public void service(ServiceManager manager) throws ServiceException {
super.service(manager);
- if ( this.manager.hasService(StoreJanitor.ROLE) ) {
+ if (this.manager.hasService(StoreJanitor.ROLE)) {
this.storejanitor = (StoreJanitor)manager.lookup(StoreJanitor.ROLE);
} else {
getLogger().info("StoreJanitor is not available. Sorry, no cache statistics");
}
- if ( this.manager.hasService(Store.PERSISTENT_STORE) ) {
+ if (this.manager.hasService(Store.PERSISTENT_STORE)) {
this.store_persistent = (Store)this.manager.lookup(Store.PERSISTENT_STORE);
} else {
getLogger().info("Persistent Store is not available. Sorry no cache statistics about it.");
@@ -122,9 +121,9 @@
}
public void dispose() {
- if ( this.manager != null ) {
- this.manager.release( this.store_persistent );
- this.manager.release( this.storejanitor );
+ if (this.manager != null) {
+ this.manager.release(this.store_persistent);
+ this.manager.release(this.storejanitor);
this.store_persistent = null;
this.storejanitor = null;
}
@@ -157,7 +156,6 @@
// The current date and time.
String dateTime = DateFormat.getDateTimeInstance().format(new Date());
-
String localHost;
// The local host.
@@ -199,8 +197,7 @@
atts.clear();
// qName = prefix + ':' + localName
atts.addAttribute(xlinkNamespace, "type", xlinkPrefix + ":type", "CDATA", "simple");
- atts.addAttribute(xlinkNamespace, "href", xlinkPrefix + ":href", "CDATA",
- SystemUtils.JAVA_VENDOR_URL);
+ atts.addAttribute(xlinkNamespace, "href", xlinkPrefix + ":href", "CDATA", SystemUtils.JAVA_VENDOR_URL);
addValue(ch, "java-vendor", SystemUtils.JAVA_VENDOR, atts);
endGroup(ch);
// END JRE
@@ -230,7 +227,7 @@
Iterator i = this.storejanitor.iterator();
while (i.hasNext()) {
Store store = (Store) i.next();
- startGroup(ch, store.getClass().getName()+" (hash = 0x"+Integer.toHexString(store.hashCode())+")" );
+ startGroup(ch, store.getClass().getName() + " (hash = 0x" + Integer.toHexString(store.hashCode()) + ")" );
int size = 0;
int empty = 0;
atts.clear();
@@ -239,7 +236,7 @@
// For each element in Store
Enumeration e = store.keys();
atts.clear();
- while( e.hasMoreElements() ) {
+ while(e.hasMoreElements()) {
size++;
Object key = e.nextElement();
Object val = store.get( key );
@@ -253,7 +250,6 @@
ch.endElement(namespace, "line", "line");
}
}
-
if (size == 0) {
ch.startElement(namespace, "line", "line", atts);
String value = "[empty]";
@@ -268,7 +264,7 @@
endGroup(ch);
}
- if ( this.store_persistent != null ) {
+ if (this.store_persistent != null) {
startGroup(ch, store_persistent.getClass().getName()+" (hash = 0x"+Integer.toHexString(store_persistent.hashCode())+")");
int size = 0;
int empty = 0;
@@ -280,7 +276,7 @@
size++;
Object key = enum.nextElement();
- Object val = store_persistent.get (key);
+ Object val = store_persistent.get(key);
String line = null;
if (val == null) {
empty++;
@@ -291,7 +287,6 @@
ch.endElement(namespace, "line", "line");
}
}
-
if (size == 0) {
ch.startElement(namespace, "line", "line", atts);
String value = "[empty]";
@@ -299,7 +294,7 @@
ch.endElement(namespace, "line", "line");
}
ch.endElement(namespace, "value", "value");
-
+
addValue(ch, "size", String.valueOf(size) + " items in cache (" + empty + " are empty)");
endGroup(ch);
}
@@ -316,12 +311,7 @@
/** Utility function to begin a <code>group</code> tag pair with added attributes. */
private void startGroup(ContentHandler ch, String name, Attributes atts) throws SAXException {
- AttributesImpl ai;
- if (atts == null) {
- ai = new AttributesImpl();
- } else {
- ai = new AttributesImpl(atts);
- }
+ AttributesImpl ai = (atts == null) ? new AttributesImpl() : new AttributesImpl(atts);
ai.addAttribute(namespace, "name", "name", "CDATA", name);
ch.startElement(namespace, "group", "group", ai);
}
@@ -338,12 +328,7 @@
/** Utility function to begin and end a <code>value</code> tag pair with added attributes. */
private void addValue(ContentHandler ch, String name, String value, Attributes atts) throws SAXException {
- AttributesImpl ai;
- if (atts == null) {
- ai = new AttributesImpl();
- } else {
- ai = new AttributesImpl(atts);
- }
+ AttributesImpl ai = (atts == null) ? new AttributesImpl() : new AttributesImpl(atts);
ai.addAttribute(namespace, "name", "name", "CDATA", name);
ch.startElement(namespace, "value", "value", ai);
ch.startElement(namespace, "line", "line", new AttributesImpl());
@@ -363,12 +348,7 @@
/** Utility function to begin and end a <code>value</code> tag pair with added attributes. */
private void addMultilineValue(ContentHandler ch, String name, List values, Attributes atts) throws SAXException {
- AttributesImpl ai;
- if (atts == null) {
- ai = new AttributesImpl();
- } else {
- ai = new AttributesImpl(atts);
- }
+ AttributesImpl ai = (atts == null) ? new AttributesImpl() : new AttributesImpl(atts);
ai.addAttribute(namespace, "name", "name", "CDATA", name);
ch.startElement(namespace, "value", "value", ai);
1.13 +3 -2 cocoon-2.1/src/java/org/apache/cocoon/transformation/TraxTransformer.java
Index: TraxTransformer.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/transformation/TraxTransformer.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- TraxTransformer.java 17 Jun 2004 14:55:24 -0000 1.12
+++ TraxTransformer.java 2 Jul 2004 08:33:42 -0000 1.13
@@ -17,6 +17,7 @@
package org.apache.cocoon.transformation;
import java.io.IOException;
+import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.HashMap;
@@ -326,7 +327,7 @@
*
* @return The generated key hashes the src
*/
- public java.io.Serializable getKey() {
+ public Serializable getKey() {
Map map = getLogicSheetParameters();
if (map == null) {
return this.inputSource.getURI();
1.8 +4 -3 cocoon-2.1/src/java/org/apache/cocoon/reading/ResourceReader.java
Index: ResourceReader.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/reading/ResourceReader.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ResourceReader.java 23 Jun 2004 19:14:34 -0000 1.7
+++ ResourceReader.java 2 Jul 2004 08:33:42 -0000 1.8
@@ -39,6 +39,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
@@ -173,7 +174,7 @@
*
* @return The generated key hashes the src
*/
- public java.io.Serializable getKey() {
+ public Serializable getKey() {
return inputSource.getURI();
}
@@ -184,7 +185,7 @@
* component is currently not cacheable.
*/
public SourceValidity getValidity() {
- if(request.getHeader("Range") != null) {
+ if (request.getHeader("Range") != null) {
// This is a byte range request so we can't use the cache, return null.
return null;
} else {