vgritsenko 2002/07/25 21:40:49
Modified: src/java/org/apache/cocoon/components/xscript Tag:
cocoon_2_0_3_branch StringBufferContentHandler.java
XScriptManager.java XScriptManagerImpl.java
XScriptObject.java XScriptObjectFromURL.java
XScriptObjectInlineXML.java
XScriptObjectResult.java XScriptVariableScope.java
Log:
reformat code
Revision Changes Path
No revision
No revision
1.4.2.2 +121 -136
xml-cocoon2/src/java/org/apache/cocoon/components/xscript/StringBufferContentHandler.java
Index: StringBufferContentHandler.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/xscript/StringBufferContentHandler.java,v
retrieving revision 1.4.2.1
retrieving revision 1.4.2.2
diff -u -r1.4.2.1 -r1.4.2.2
--- StringBufferContentHandler.java 20 Jun 2002 04:24:30 -0000 1.4.2.1
+++ StringBufferContentHandler.java 26 Jul 2002 04:40:49 -0000 1.4.2.2
@@ -50,17 +50,13 @@
*/
package org.apache.cocoon.components.xscript;
-import java.util.Stack;
-import java.io.StringReader;
-import java.io.StringBufferInputStream;
-import java.io.IOException;
-
-import org.xml.sax.InputSource;
+import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
-import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
+import java.util.Stack;
+
/**
* A <code>ContentHandler</code> that accumulates the SAX stream into
@@ -71,124 +67,116 @@
* @version CVS $Id$
* @since August 30, 2001
*/
-public class StringBufferContentHandler extends DefaultHandler
-{
- private Stack namespaces = new Stack();
- ContentHandler contentHandler;
- StringBuffer stringBuffer;
- static Object marker = new Object();
-
- public StringBufferContentHandler(StringBuffer stringBuffer)
- {
- this.stringBuffer = stringBuffer;
- }
-
- public void setNextContentHandler(ContentHandler handler)
- {
- this.contentHandler = handler;
- }
-
- public void startPrefixMapping(String prefix, String uri)
- throws SAXException
- {
- namespaces.push(new NPU(prefix, uri));
- }
-
- public void endPrefixMapping(String prefix)
- throws SAXException
- {
- namespaces.pop();
- }
-
- public void startElement(String uri, String loc, String qName, Attributes a)
- throws SAXException
- {
- int lastNamespaceIndex = 0;
-
- lastNamespaceIndex = namespaces.size() - 1;
- while(lastNamespaceIndex >= 0
- && namespaces.elementAt(lastNamespaceIndex) != marker) {
- lastNamespaceIndex--;
- }
-
- if (lastNamespaceIndex < 0) {
- lastNamespaceIndex = 0;
- } else if (namespaces.elementAt(lastNamespaceIndex) == marker) {
- lastNamespaceIndex++;
- }
-
- namespaces.push(marker);
-
- stringBuffer.append("<").append(qName);
-
- for (int i = 0, len = a.getLength(); i < len; i++) {
- // Check if the attribute is a namespace declaration. Some
- // parsers (Xerces) sometimes pass the namespace declaration
- // as an attribute. We need to catch this case so that we
- // don't end up generating the namespace declaration twice.
- String attrName = a.getQName(i);
-
- if (attrName.startsWith("xmlns:")) {
- // We have a namespace declaration
- String name = a.getLocalName(i);
-
- // Check whether this namespace has been already declared
- boolean found = false;
- for (int j = namespaces.size() - 1;
- j >= lastNamespaceIndex;
- j--) {
- Object obj = namespaces.elementAt(j);
- if (obj == marker) {
- continue;
- }
- NPU npu = (NPU)obj;
-
- if (name.equals(npu.prefix)) {
- found = true;
- break;
- }
+public class StringBufferContentHandler extends DefaultHandler {
+ private Stack namespaces = new Stack();
+ ContentHandler contentHandler;
+ StringBuffer stringBuffer;
+ static Object marker = new Object();
+
+ public StringBufferContentHandler(StringBuffer stringBuffer) {
+ this.stringBuffer = stringBuffer;
+ }
+
+ public void setNextContentHandler(ContentHandler handler) {
+ this.contentHandler = handler;
+ }
+
+ public void startPrefixMapping(String prefix, String uri)
+ throws SAXException {
+ namespaces.push(new NPU(prefix, uri));
+ }
+
+ public void endPrefixMapping(String prefix)
+ throws SAXException {
+ namespaces.pop();
+ }
+
+ public void startElement(String uri, String loc, String qName, Attributes a)
+ throws SAXException {
+ int lastNamespaceIndex = 0;
+
+ lastNamespaceIndex = namespaces.size() - 1;
+ while (lastNamespaceIndex >= 0
+ && namespaces.elementAt(lastNamespaceIndex) != marker) {
+ lastNamespaceIndex--;
}
- if (!found) {
- namespaces.push(new NPU(name, a.getValue(i)));
+ if (lastNamespaceIndex < 0) {
+ lastNamespaceIndex = 0;
+ } else if (namespaces.elementAt(lastNamespaceIndex) == marker) {
+ lastNamespaceIndex++;
}
- } else {
- // Normal attribute
- stringBuffer.append(" ").append(a.getQName(i)).append("=\"");
- escape(stringBuffer, a.getValue(i));
- stringBuffer.append("\"");
- }
- }
- if (namespaces.size() != 0) {
- for (int i = namespaces.size() - 1; i >= lastNamespaceIndex; i--) {
- Object obj = namespaces.elementAt(i);
- if (obj == marker) {
- continue;
+ namespaces.push(marker);
+
+ stringBuffer.append("<").append(qName);
+
+ for (int i = 0, len = a.getLength(); i < len; i++) {
+ // Check if the attribute is a namespace declaration. Some
+ // parsers (Xerces) sometimes pass the namespace declaration
+ // as an attribute. We need to catch this case so that we
+ // don't end up generating the namespace declaration twice.
+ String attrName = a.getQName(i);
+
+ if (attrName.startsWith("xmlns:")) {
+ // We have a namespace declaration
+ String name = a.getLocalName(i);
+
+ // Check whether this namespace has been already declared
+ boolean found = false;
+ for (int j = namespaces.size() - 1;
+ j >= lastNamespaceIndex;
+ j--) {
+ Object obj = namespaces.elementAt(j);
+ if (obj == marker) {
+ continue;
+ }
+ NPU npu = (NPU) obj;
+
+ if (name.equals(npu.prefix)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ namespaces.push(new NPU(name, a.getValue(i)));
+ }
+ } else {
+ // Normal attribute
+ stringBuffer.append(" ").append(a.getQName(i)).append("=\"");
+ escape(stringBuffer, a.getValue(i));
+ stringBuffer.append("\"");
+ }
+ }
+
+ if (namespaces.size() != 0) {
+ for (int i = namespaces.size() - 1; i >= lastNamespaceIndex; i--) {
+ Object obj = namespaces.elementAt(i);
+ if (obj == marker) {
+ continue;
+ }
+ NPU npu = (NPU) obj;
+ stringBuffer.append("
xmlns:").append(npu.prefix).append("=\"").append(npu.uri).append("\"");
+ }
}
- NPU npu = (NPU)obj;
- stringBuffer.append("
xmlns:").append(npu.prefix).append("=\"").append(npu.uri).append("\"");
- }
- }
- stringBuffer.append(">");
- }
-
- public void endElement(String uri, String loc, String qName)
- throws SAXException
- {
- stringBuffer.append("</").append(qName).append(">");
-
- Object obj;
- do {
- obj = namespaces.pop();
- } while (obj != marker);
- }
-
- public void characters(char ch[], int start, int len)
- throws SAXException
- {
- escape(stringBuffer, ch, start, len);
- }
+ stringBuffer.append(">");
+ }
+
+ public void endElement(String uri, String loc, String qName)
+ throws SAXException {
+ stringBuffer.append("</").append(qName).append(">");
+
+ Object obj;
+ do {
+ obj = namespaces.pop();
+ } while (obj != marker);
+ }
+
+ public void characters(char ch[], int start, int len)
+ throws SAXException {
+ escape(stringBuffer, ch, start, len);
+ }
/**
@@ -226,19 +214,16 @@
}
}
-class NPU
-{
- public String prefix;
- public String uri;
-
- NPU(String prefix, String uri)
- {
- this.prefix = prefix;
- this.uri = uri;
- }
-
- public String toString()
- {
- return this.prefix + "=" + this.uri;
- }
+class NPU {
+ public String prefix;
+ public String uri;
+
+ NPU(String prefix, String uri) {
+ this.prefix = prefix;
+ this.uri = uri;
+ }
+
+ public String toString() {
+ return this.prefix + "=" + this.uri;
+ }
}
1.4.2.1 +133 -135
xml-cocoon2/src/java/org/apache/cocoon/components/xscript/XScriptManager.java
Index: XScriptManager.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/xscript/XScriptManager.java,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -u -r1.4 -r1.4.2.1
--- XScriptManager.java 22 Feb 2002 07:00:15 -0000 1.4
+++ XScriptManager.java 26 Jul 2002 04:40:49 -0000 1.4.2.1
@@ -50,7 +50,6 @@
*/
package org.apache.cocoon.components.xscript;
-import org.apache.avalon.framework.component.ComponentManager;
/**
* <code>XScriptManager</code> is the public interface used to
@@ -61,137 +60,136 @@
* @version CVS $Id$
* @since August 4, 2001
*/
-public interface XScriptManager
-{
- String ROLE = "org.apache.cocoon.components.xscript.XScriptManager";
-
- String XSCRIPT_NS = "http://apache.org/xsp/xscript/1.0";
-
- /**
- * The variable's global scope. Each Cocoon instance has exactly one
- * global scope for variables.
- */
- int GLOBAL_SCOPE = 1;
- /**
- * The session scope. This scope is specific to a particular
- * activation of an XSP page, which is usually identified by the
- * session id of the user that sent the HTTP request. From XScript's
- * point of view however, the session identifier is not interpreted
- * in any way, so a client can define its own notion of "session".
- */
- int SESSION_SCOPE = 2;
-
- /**
- * The page scope. This is scope very specific to an XSP page, and
- * defines variables visible only within the context of that
- * page. No other XSP page can access these variables, unless it
- * knows the identifier used by that page to store its
- * variables. This identifier is not necessarily the URL or full
- * path of that page; it is up to the page to define it.
- */
- int PAGE_SCOPE = 3;
-
- /**
- * Search for a variable in all the accessible scopes. The variable
- * is first searched in the current session scope. If no variable is
- * found here, the current page scope is searched next. If nothing
- * is found either, the global scope is searched.
- */
- int ALL_SCOPES = 4;
-
- /**
- * Obtains the object value of the
- * <code>name</code> variable in <code>scope</code>. The
- * <code>context</code> parameter is interpreted differently
- * depending on the value of <code>scope</code>, as follows:
- *
- * <ul>
- *
- * <li>if <code>scope</code> is <code>{@link #GLOBAL_SCOPE}</code>, the
- * value of <code>context is ignored.
- *
- * <li>if <code>scope</code> is <code>{@link
- * #SESSION_SCOPE}</code>, the value of <code>context</code> is
- * interpreted as the session identifier.
- *
- * <li>if <code>scope</code> is <code>{@link #PAGE_SCOPE}</code>, the value
- * of <code>context</code> is interpreted as an identifier of the
- * page. This could be the URL of the page or the path of the file
- * name in the file system.
- *
- * </ul>
- *
- * @param name a <code>String</code> value
- * @param scope an <code>int</code> value
- * @param context a <code>String</code> value whose interpretation
- * depends on <code>scope</code>
- * @return a <code>{@link XScriptObject}</code> value
- */
- XScriptObject get(String name, int scope, String context)
- throws IllegalArgumentException;
-
- /**
- * Search for the first occurence of the variable
- * <code>name</code>.
- *
- * <p>The search happens first in the session scope
- * identified by <code>sessionContext</code>. If no variable is
- * found here, the search continues in the page scope identified by
- * <code>pageContext</code>. If no variable is found here, it's
- * finally searched in the global scope.
- *
- * <p>The <code>XScriptObject</code> value of the variable is
- * returned if a variable is found in one of the scopes, otherwise
- * an exception is thrown.
- *
- * @param name a <code>String</code> value
- * @param sessionContext a <code>String</code> value
- * @param pageContext a <code>String</code> value
- * @return a <code>XScriptObject</code> value
- * @exception IllegalArgumentException if an error occurs
- */
- XScriptObject getFirst(String name,
- String sessionContext,
- String pageContext)
- throws IllegalArgumentException;
-
- /**
- * Defines or overwrites the value of variable
- * <code>name</code> in <code>scope</code>. The <code>context</code>
- * argument is interpreted as described in {@link #get(String, int,
- * String)}.
- *
- * @param name a <code>String</code> value
- * @param value a <code>XScriptObject</code> value
- * @param scope an <code>int</code> value
- * @param context a <code>String</code> value whose interpretation
- * depends on <code>scope</code>
- */
- void put(String name, XScriptObject value, int scope, String context)
- throws IllegalArgumentException;
-
- /**
- * Removes a variable previously declared in <code>scope</code>
- * within <code>context</code>. Such a variable could be declared
- * using the {@link #put(String, XScriptObject, int, String)}
- * method.
- *
- * @param name a <code>String</code> value
- * @param scope an <code>int</code> value
- * @param context a <code>String</code> value
- */
- void remove(String name, int scope, String context);
-
- /**
- * Remove the first appearance of <code>name</code> in the all the
- * currently accessible scopes. The search happens as described in
- * {@link #getFirst(String,String,String)}.
- *
- * @param name a <code>String</code> value
- * @param sessionContext a <code>String</code> value
- * @param pageContext a <code>String</code> value
- * @exception IllegalArgumentException if an error occurs
- */
- void removeFirst(String name, String sessionContext, String pageContext)
- throws IllegalArgumentException;
+public interface XScriptManager {
+ String ROLE = "org.apache.cocoon.components.xscript.XScriptManager";
+
+ String XSCRIPT_NS = "http://apache.org/xsp/xscript/1.0";
+
+ /**
+ * The variable's global scope. Each Cocoon instance has exactly one
+ * global scope for variables.
+ */
+ int GLOBAL_SCOPE = 1;
+ /**
+ * The session scope. This scope is specific to a particular
+ * activation of an XSP page, which is usually identified by the
+ * session id of the user that sent the HTTP request. From XScript's
+ * point of view however, the session identifier is not interpreted
+ * in any way, so a client can define its own notion of "session".
+ */
+ int SESSION_SCOPE = 2;
+
+ /**
+ * The page scope. This is scope very specific to an XSP page, and
+ * defines variables visible only within the context of that
+ * page. No other XSP page can access these variables, unless it
+ * knows the identifier used by that page to store its
+ * variables. This identifier is not necessarily the URL or full
+ * path of that page; it is up to the page to define it.
+ */
+ int PAGE_SCOPE = 3;
+
+ /**
+ * Search for a variable in all the accessible scopes. The variable
+ * is first searched in the current session scope. If no variable is
+ * found here, the current page scope is searched next. If nothing
+ * is found either, the global scope is searched.
+ */
+ int ALL_SCOPES = 4;
+
+ /**
+ * Obtains the object value of the
+ * <code>name</code> variable in <code>scope</code>. The
+ * <code>context</code> parameter is interpreted differently
+ * depending on the value of <code>scope</code>, as follows:
+ *
+ * <ul>
+ *
+ * <li>if <code>scope</code> is <code>{@link #GLOBAL_SCOPE}</code>, the
+ * value of <code>context is ignored.
+ *
+ * <li>if <code>scope</code> is <code>{@link
+ * #SESSION_SCOPE}</code>, the value of <code>context</code> is
+ * interpreted as the session identifier.
+ *
+ * <li>if <code>scope</code> is <code>{@link #PAGE_SCOPE}</code>, the value
+ * of <code>context</code> is interpreted as an identifier of the
+ * page. This could be the URL of the page or the path of the file
+ * name in the file system.
+ *
+ * </ul>
+ *
+ * @param name a <code>String</code> value
+ * @param scope an <code>int</code> value
+ * @param context a <code>String</code> value whose interpretation
+ * depends on <code>scope</code>
+ * @return a <code>{@link XScriptObject}</code> value
+ */
+ XScriptObject get(String name, int scope, String context)
+ throws IllegalArgumentException;
+
+ /**
+ * Search for the first occurence of the variable
+ * <code>name</code>.
+ *
+ * <p>The search happens first in the session scope
+ * identified by <code>sessionContext</code>. If no variable is
+ * found here, the search continues in the page scope identified by
+ * <code>pageContext</code>. If no variable is found here, it's
+ * finally searched in the global scope.
+ *
+ * <p>The <code>XScriptObject</code> value of the variable is
+ * returned if a variable is found in one of the scopes, otherwise
+ * an exception is thrown.
+ *
+ * @param name a <code>String</code> value
+ * @param sessionContext a <code>String</code> value
+ * @param pageContext a <code>String</code> value
+ * @return a <code>XScriptObject</code> value
+ * @exception IllegalArgumentException if an error occurs
+ */
+ XScriptObject getFirst(String name,
+ String sessionContext,
+ String pageContext)
+ throws IllegalArgumentException;
+
+ /**
+ * Defines or overwrites the value of variable
+ * <code>name</code> in <code>scope</code>. The <code>context</code>
+ * argument is interpreted as described in {@link #get(String, int,
+ * String)}.
+ *
+ * @param name a <code>String</code> value
+ * @param value a <code>XScriptObject</code> value
+ * @param scope an <code>int</code> value
+ * @param context a <code>String</code> value whose interpretation
+ * depends on <code>scope</code>
+ */
+ void put(String name, XScriptObject value, int scope, String context)
+ throws IllegalArgumentException;
+
+ /**
+ * Removes a variable previously declared in <code>scope</code>
+ * within <code>context</code>. Such a variable could be declared
+ * using the {@link #put(String, XScriptObject, int, String)}
+ * method.
+ *
+ * @param name a <code>String</code> value
+ * @param scope an <code>int</code> value
+ * @param context a <code>String</code> value
+ */
+ void remove(String name, int scope, String context);
+
+ /**
+ * Remove the first appearance of <code>name</code> in the all the
+ * currently accessible scopes. The search happens as described in
+ * {@link #getFirst(String,String,String)}.
+ *
+ * @param name a <code>String</code> value
+ * @param sessionContext a <code>String</code> value
+ * @param pageContext a <code>String</code> value
+ * @exception IllegalArgumentException if an error occurs
+ */
+ void removeFirst(String name, String sessionContext, String pageContext)
+ throws IllegalArgumentException;
}
1.6.2.2 +211 -224
xml-cocoon2/src/java/org/apache/cocoon/components/xscript/XScriptManagerImpl.java
Index: XScriptManagerImpl.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/xscript/XScriptManagerImpl.java,v
retrieving revision 1.6.2.1
retrieving revision 1.6.2.2
diff -u -r1.6.2.1 -r1.6.2.2
--- XScriptManagerImpl.java 14 Apr 2002 04:06:19 -0000 1.6.2.1
+++ XScriptManagerImpl.java 26 Jul 2002 04:40:49 -0000 1.6.2.2
@@ -50,20 +50,17 @@
*/
package org.apache.cocoon.components.xscript;
-import java.util.HashMap;
-
-import org.apache.avalon.framework.logger.AbstractLoggable;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.parameters.Parameterizable;
-import org.apache.avalon.framework.parameters.ParameterException;
-
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
+import org.apache.avalon.framework.logger.AbstractLoggable;
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
-import org.apache.cocoon.components.xscript.XScriptObjectFromURL;
+import java.util.HashMap;
/**
* The actual implementation of the <code>XScriptManager</code> interface.
@@ -73,219 +70,209 @@
* @since August 4, 2001
*/
public class XScriptManagerImpl
- extends AbstractLoggable
- implements XScriptManager, Composable, Component, Parameterizable, ThreadSafe
-{
- /**
- * The global scope. All the global variables are indexed in this
- * space by their name.
- */
- XScriptVariableScope globalScope = new XScriptVariableScope();
-
- /**
- * The session scope. The key in this hash table is the session
- * identifier, which should be a <code>String</code> object. The
- * value is an {@link XScriptVariableScope} instance which holds the
- * variables in a session scope.
- */
- HashMap sessionScope = new HashMap();
-
- /**
- * Page specific variables. The key in the hash map is an identifier
- * for the page, usually the full path name to the page. The value
- * is an {@link XScriptVariableScope} instance which holds the
- * variables in a page scope.
- */
- HashMap pageScope = new HashMap();
-
- /**
- * The <code>ComponentManager</code> instance.
- */
- protected ComponentManager manager = null;
-
- public void compose(ComponentManager manager) throws ComponentException
- {
- this.manager = manager;
- getLogger().debug("XScriptManager component initialized.");
- }
-
- public void register(XScriptObject object)
- {
- try {
- object.compose(manager);
- } catch (ComponentException ex) {
- }
- }
-
- public void parameterize(Parameters params) throws ParameterException
- {
- String[] names = params.getNames();
- for (int i = 0; i < names.length; i++) {
- String resourceString = params.getParameter(names[i]);
- XScriptObject resource = new XScriptObjectFromURL(this, resourceString);
- globalScope.put(names[i], resource);
- }
- }
-
- private IllegalArgumentException
- createAccessException(String msg, String name, int scope, String context)
- {
- StringBuffer message = new StringBuffer("Cannot ").append(msg)
- .append(" variable named '").append(name)
- .append("' in ");
-
- if (scope == XScriptManager.GLOBAL_SCOPE)
- message.append("global scope");
- else if (scope == XScriptManager.SESSION_SCOPE)
- message.append("session scope");
- else if (scope == XScriptManager.PAGE_SCOPE)
- message.append("page scope");
- else
- message.append("unknown scope (").append(scope).append(")");
-
- message.append(" with context '").append(context).append("'");
- return new IllegalArgumentException(message.toString());
- }
-
- public XScriptObject get(String name, int scope, String context)
- throws IllegalArgumentException
- {
- if (scope == XScriptManager.GLOBAL_SCOPE) {
- return globalScope.get(name);
- } else if (scope == XScriptManager.SESSION_SCOPE) {
- XScriptVariableScope s = (XScriptVariableScope)sessionScope.get(context);
- if (s != null)
- return s.get(name);
- } else if (scope == XScriptManager.PAGE_SCOPE) {
- XScriptVariableScope s = (XScriptVariableScope)pageScope.get(context);
- if (s != null)
- return s.get(name);
- }
-
- throw createAccessException("find", name, scope, context);
- }
-
- public XScriptObject getFirst(String name,
- String sessionContext,
- String pageContext)
- throws IllegalArgumentException
- {
- XScriptVariableScope scope;
-
- // Lookup in the session scope first.
- scope = (XScriptVariableScope)sessionScope.get(sessionContext);
- if (scope != null) {
- synchronized(scope) {
- if (scope.defines(name)) {
- return scope.get(name);
- }
- }
- }
-
- // No luck finding `name' in session scope, try in page scope.
- scope = (XScriptVariableScope)pageScope.get(pageContext);
- if (scope != null) {
- synchronized(scope) {
- if (scope.defines(name)) {
- return scope.get(name);
- }
- }
- }
-
- // No luck finding `name' in the page scope, try the global scope.
- synchronized(globalScope) {
- if (globalScope.defines(name)) {
- return globalScope.get(name);
- }
- }
-
- // No variable `name' found, throw an exception.
- throw new IllegalArgumentException("getFirst: no variable '" + name
- + "' accessible from this scope!");
- }
-
- public void put(String name, XScriptObject value, int scope, String context)
- {
- if (scope == XScriptManager.GLOBAL_SCOPE) {
- globalScope.put(name, value);
- } else if (scope == XScriptManager.SESSION_SCOPE) {
- XScriptVariableScope s = (XScriptVariableScope)sessionScope.get(context);
- if (s == null) {
- s = new XScriptVariableScope();
- sessionScope.put(context, s);
- }
- s.put(name, value);
- } else if (scope == XScriptManager.PAGE_SCOPE) {
- XScriptVariableScope s = (XScriptVariableScope)pageScope.get(context);
- if (s == null) {
- s = new XScriptVariableScope();
- pageScope.put(context, s);
- }
- s.put(name, value);
- } else {
- throw createAccessException("create", name, scope, context);
- }
- }
-
- public void remove(String name, int scope, String context)
- throws IllegalArgumentException
- {
- if (scope == XScriptManager.GLOBAL_SCOPE) {
- globalScope.remove(name);
- } else if (scope == XScriptManager.SESSION_SCOPE) {
- XScriptVariableScope s = (XScriptVariableScope)sessionScope.get(context);
- if (s != null) {
- s.remove(name);
- }
- } else if (scope == XScriptManager.PAGE_SCOPE) {
- XScriptVariableScope s = (XScriptVariableScope)pageScope.get(context);
- if (s != null) {
- s.remove(name);
- }
- } else {
- throw createAccessException("remove", name, scope, context);
- }
- }
-
- public void removeFirst(String name,
- String sessionContext,
- String pageContext)
- throws IllegalArgumentException
- {
- XScriptVariableScope scope;
-
- // Lookup in the session scope first.
- scope = (XScriptVariableScope)sessionScope.get(sessionContext);
- if (scope != null) {
- synchronized(scope) {
- if (scope.defines(name)) {
- scope.remove(name);
- return;
- }
- }
- }
-
- // No luck finding `name' in session scope, try in page scope.
- scope = (XScriptVariableScope)pageScope.get(pageContext);
- if (scope != null) {
- synchronized(scope) {
- if (scope.defines(name)) {
- scope.remove(name);
- return;
- }
- }
- }
-
- // No luck finding `name' in the page scope, try the global scope.
- synchronized(globalScope) {
- if (globalScope.defines(name)) {
- globalScope.remove(name);
- return;
- }
- }
-
- // No variable `name' found, throw an exception.
- throw new IllegalArgumentException("removeFirst: no variable '" + name
- + "' accessible from this scope!");
- }
+ extends AbstractLoggable
+ implements XScriptManager, Composable, Component, Parameterizable,
ThreadSafe {
+ /**
+ * The global scope. All the global variables are indexed in this
+ * space by their name.
+ */
+ XScriptVariableScope globalScope = new XScriptVariableScope();
+
+ /**
+ * The session scope. The key in this hash table is the session
+ * identifier, which should be a <code>String</code> object. The
+ * value is an {@link XScriptVariableScope} instance which holds the
+ * variables in a session scope.
+ */
+ HashMap sessionScope = new HashMap();
+
+ /**
+ * Page specific variables. The key in the hash map is an identifier
+ * for the page, usually the full path name to the page. The value
+ * is an {@link XScriptVariableScope} instance which holds the
+ * variables in a page scope.
+ */
+ HashMap pageScope = new HashMap();
+
+ /**
+ * The <code>ComponentManager</code> instance.
+ */
+ protected ComponentManager manager = null;
+
+ public void compose(ComponentManager manager) throws ComponentException {
+ this.manager = manager;
+ getLogger().debug("XScriptManager component initialized.");
+ }
+
+ public void register(XScriptObject object) {
+ try {
+ object.compose(manager);
+ } catch (ComponentException ex) {
+ }
+ }
+
+ public void parameterize(Parameters params) throws ParameterException {
+ String[] names = params.getNames();
+ for (int i = 0; i < names.length; i++) {
+ String resourceString = params.getParameter(names[i]);
+ XScriptObject resource = new XScriptObjectFromURL(this, resourceString);
+ globalScope.put(names[i], resource);
+ }
+ }
+
+ private IllegalArgumentException
+ createAccessException(String msg, String name, int scope, String
context) {
+ StringBuffer message = new StringBuffer("Cannot ").append(msg)
+ .append(" variable named '").append(name)
+ .append("' in ");
+
+ if (scope == XScriptManager.GLOBAL_SCOPE)
+ message.append("global scope");
+ else if (scope == XScriptManager.SESSION_SCOPE)
+ message.append("session scope");
+ else if (scope == XScriptManager.PAGE_SCOPE)
+ message.append("page scope");
+ else
+ message.append("unknown scope (").append(scope).append(")");
+
+ message.append(" with context '").append(context).append("'");
+ return new IllegalArgumentException(message.toString());
+ }
+
+ public XScriptObject get(String name, int scope, String context)
+ throws IllegalArgumentException {
+ if (scope == XScriptManager.GLOBAL_SCOPE) {
+ return globalScope.get(name);
+ } else if (scope == XScriptManager.SESSION_SCOPE) {
+ XScriptVariableScope s = (XScriptVariableScope)
sessionScope.get(context);
+ if (s != null)
+ return s.get(name);
+ } else if (scope == XScriptManager.PAGE_SCOPE) {
+ XScriptVariableScope s = (XScriptVariableScope) pageScope.get(context);
+ if (s != null)
+ return s.get(name);
+ }
+
+ throw createAccessException("find", name, scope, context);
+ }
+
+ public XScriptObject getFirst(String name,
+ String sessionContext,
+ String pageContext)
+ throws IllegalArgumentException {
+ XScriptVariableScope scope;
+
+ // Lookup in the session scope first.
+ scope = (XScriptVariableScope) sessionScope.get(sessionContext);
+ if (scope != null) {
+ synchronized (scope) {
+ if (scope.defines(name)) {
+ return scope.get(name);
+ }
+ }
+ }
+
+ // No luck finding `name' in session scope, try in page scope.
+ scope = (XScriptVariableScope) pageScope.get(pageContext);
+ if (scope != null) {
+ synchronized (scope) {
+ if (scope.defines(name)) {
+ return scope.get(name);
+ }
+ }
+ }
+
+ // No luck finding `name' in the page scope, try the global scope.
+ synchronized (globalScope) {
+ if (globalScope.defines(name)) {
+ return globalScope.get(name);
+ }
+ }
+
+ // No variable `name' found, throw an exception.
+ throw new IllegalArgumentException("getFirst: no variable '" + name
+ + "' accessible from this scope!");
+ }
+
+ public void put(String name, XScriptObject value, int scope, String context) {
+ if (scope == XScriptManager.GLOBAL_SCOPE) {
+ globalScope.put(name, value);
+ } else if (scope == XScriptManager.SESSION_SCOPE) {
+ XScriptVariableScope s = (XScriptVariableScope)
sessionScope.get(context);
+ if (s == null) {
+ s = new XScriptVariableScope();
+ sessionScope.put(context, s);
+ }
+ s.put(name, value);
+ } else if (scope == XScriptManager.PAGE_SCOPE) {
+ XScriptVariableScope s = (XScriptVariableScope) pageScope.get(context);
+ if (s == null) {
+ s = new XScriptVariableScope();
+ pageScope.put(context, s);
+ }
+ s.put(name, value);
+ } else {
+ throw createAccessException("create", name, scope, context);
+ }
+ }
+
+ public void remove(String name, int scope, String context)
+ throws IllegalArgumentException {
+ if (scope == XScriptManager.GLOBAL_SCOPE) {
+ globalScope.remove(name);
+ } else if (scope == XScriptManager.SESSION_SCOPE) {
+ XScriptVariableScope s = (XScriptVariableScope)
sessionScope.get(context);
+ if (s != null) {
+ s.remove(name);
+ }
+ } else if (scope == XScriptManager.PAGE_SCOPE) {
+ XScriptVariableScope s = (XScriptVariableScope) pageScope.get(context);
+ if (s != null) {
+ s.remove(name);
+ }
+ } else {
+ throw createAccessException("remove", name, scope, context);
+ }
+ }
+
+ public void removeFirst(String name,
+ String sessionContext,
+ String pageContext)
+ throws IllegalArgumentException {
+ XScriptVariableScope scope;
+
+ // Lookup in the session scope first.
+ scope = (XScriptVariableScope) sessionScope.get(sessionContext);
+ if (scope != null) {
+ synchronized (scope) {
+ if (scope.defines(name)) {
+ scope.remove(name);
+ return;
+ }
+ }
+ }
+
+ // No luck finding `name' in session scope, try in page scope.
+ scope = (XScriptVariableScope) pageScope.get(pageContext);
+ if (scope != null) {
+ synchronized (scope) {
+ if (scope.defines(name)) {
+ scope.remove(name);
+ return;
+ }
+ }
+ }
+
+ // No luck finding `name' in the page scope, try the global scope.
+ synchronized (globalScope) {
+ if (globalScope.defines(name)) {
+ globalScope.remove(name);
+ return;
+ }
+ }
+
+ // No variable `name' found, throw an exception.
+ throw new IllegalArgumentException("removeFirst: no variable '" + name
+ + "' accessible from this scope!");
+ }
}
1.7.2.3 +121 -128
xml-cocoon2/src/java/org/apache/cocoon/components/xscript/XScriptObject.java
Index: XScriptObject.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/xscript/XScriptObject.java,v
retrieving revision 1.7.2.2
retrieving revision 1.7.2.3
diff -u -r1.7.2.2 -r1.7.2.3
--- XScriptObject.java 27 Jun 2002 19:07:56 -0000 1.7.2.2
+++ XScriptObject.java 26 Jul 2002 04:40:49 -0000 1.7.2.3
@@ -50,23 +50,26 @@
*/
package org.apache.cocoon.components.xscript;
-import javax.xml.transform.stream.StreamResult;
-import java.util.Date;
-import java.io.IOException;
-import java.io.CharArrayWriter;
-
-import org.xml.sax.SAXException;
-import org.xml.sax.InputSource;
-import org.xml.sax.ContentHandler;
-import org.apache.cocoon.xml.EmbeddedXMLPipe;
-import org.apache.cocoon.environment.Source;
-import org.apache.cocoon.components.xslt.XSLTProcessor;
-import org.apache.cocoon.ProcessingException;
-import org.apache.avalon.excalibur.xml.Parser;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.ComponentException;
+import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
+import org.apache.avalon.framework.parameters.Parameters;
+
+import org.apache.avalon.excalibur.xml.Parser;
+
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.components.xslt.XSLTProcessor;
+import org.apache.cocoon.environment.Source;
+import org.apache.cocoon.xml.EmbeddedXMLPipe;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.xml.transform.stream.StreamResult;
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.util.Date;
/**
* <code>XScriptObject</code> is the root class implemented by all the
@@ -77,116 +80,106 @@
* @version CVS $Id$
* @since August 4, 2001
*/
-public abstract class XScriptObject implements Source, Composable
-{
- /**
- * The creation date of this <code>XScriptObject</code>.
- */
- Date lastModifiedDate = new Date();
-
- /**
- * The <code>XScriptManager</code> object that's managing this
- * <code>XScriptObject</code> value.
- */
- XScriptManager xscriptManager;
-
- protected ComponentManager componentManager;
-
- /**
- * Creates a new <code>XScriptObject</code> instance.
- *
- * @param manager a <code>XScriptManager</code> value
- */
- public XScriptObject(XScriptManager manager)
- {
- this.xscriptManager = manager;
- ((XScriptManagerImpl)this.xscriptManager).register(this);
- }
-
- public void compose(ComponentManager manager)
- throws ComponentException
- {
- this.componentManager = manager;
- }
-
- /**
- * Apply the XSLT stylesheet defined by the <code>stylesheet</code>
- * variable to this instance. Return the result of the
- * transformation as an <code>XScriptObject</code>.
- *
- * @param stylesheet a <code>XScriptObject</code> value
- * @param params a <code>Parameters</code> value containing optional
- * arguments to be passed to the XSLT processor.
- * @return <code>XScriptObject</code> object containing the result
- * of the XSLT processing.
- * @exception IllegalArgumentException if an error occurs
- * @exception ProcessingException if an error occurs
- */
- public XScriptObject transform(XScriptObject stylesheet, Parameters params)
- throws IllegalArgumentException, ProcessingException
- {
- try {
- CharArrayWriter writer = new CharArrayWriter();
- StreamResult result = new StreamResult(writer);
-
- XSLTProcessor transformer
- = (XSLTProcessor)componentManager.lookup(XSLTProcessor.ROLE);
-
- try {
- transformer.transform(this, stylesheet, params, result);
- } finally {
- componentManager.release(transformer);
- }
-
- return new XScriptObjectResult(xscriptManager, writer.toString());
- }
- catch (ComponentException ex) {
- throw new ProcessingException(ex);
- }
- }
-
- public void toEmbeddedSAX(ContentHandler handler) throws SAXException
- {
- EmbeddedXMLPipe newHandler = new EmbeddedXMLPipe(handler);
- toSAX(newHandler);
- }
-
- /* The Source interface methods. */
-
- public void toSAX(ContentHandler handler) throws SAXException
- {
- Parser parser = null;
- try {
- parser = (Parser)componentManager.lookup(Parser.ROLE);
- InputSource source = getInputSource();
- parser.parse(source, handler);
- } catch (SAXException e) {
- throw e;
- } catch (Exception e) {
- throw new SAXException(e);
- } finally {
- if (parser != null) {
- componentManager.release(parser);
- }
- }
- }
-
- public long getLastModified()
- {
- return lastModifiedDate.getTime();
- }
-
- public abstract long getContentLength();
-
- public InputSource getInputSource()
- throws ProcessingException, IOException
- {
- InputSource is = new InputSource(getInputStream());
- is.setSystemId(getSystemId());
- return is;
- }
-
- public void recycle()
- {
- }
+public abstract class XScriptObject implements Source, Composable {
+ /**
+ * The creation date of this <code>XScriptObject</code>.
+ */
+ Date lastModifiedDate = new Date();
+
+ /**
+ * The <code>XScriptManager</code> object that's managing this
+ * <code>XScriptObject</code> value.
+ */
+ XScriptManager xscriptManager;
+
+ protected ComponentManager componentManager;
+
+ /**
+ * Creates a new <code>XScriptObject</code> instance.
+ *
+ * @param manager a <code>XScriptManager</code> value
+ */
+ public XScriptObject(XScriptManager manager) {
+ this.xscriptManager = manager;
+ ((XScriptManagerImpl) this.xscriptManager).register(this);
+ }
+
+ public void compose(ComponentManager manager)
+ throws ComponentException {
+ this.componentManager = manager;
+ }
+
+ /**
+ * Apply the XSLT stylesheet defined by the <code>stylesheet</code>
+ * variable to this instance. Return the result of the
+ * transformation as an <code>XScriptObject</code>.
+ *
+ * @param stylesheet a <code>XScriptObject</code> value
+ * @param params a <code>Parameters</code> value containing optional
+ * arguments to be passed to the XSLT processor.
+ * @return <code>XScriptObject</code> object containing the result
+ * of the XSLT processing.
+ * @exception IllegalArgumentException if an error occurs
+ * @exception ProcessingException if an error occurs
+ */
+ public XScriptObject transform(XScriptObject stylesheet, Parameters params)
+ throws IllegalArgumentException, ProcessingException {
+ try {
+ CharArrayWriter writer = new CharArrayWriter();
+ StreamResult result = new StreamResult(writer);
+
+ XSLTProcessor transformer
+ = (XSLTProcessor) componentManager.lookup(XSLTProcessor.ROLE);
+
+ try {
+ transformer.transform(this, stylesheet, params, result);
+ } finally {
+ componentManager.release(transformer);
+ }
+
+ return new XScriptObjectResult(xscriptManager, writer.toString());
+ } catch (ComponentException ex) {
+ throw new ProcessingException(ex);
+ }
+ }
+
+ public void toEmbeddedSAX(ContentHandler handler) throws SAXException {
+ EmbeddedXMLPipe newHandler = new EmbeddedXMLPipe(handler);
+ toSAX(newHandler);
+ }
+
+ /* The Source interface methods. */
+
+ public void toSAX(ContentHandler handler) throws SAXException {
+ Parser parser = null;
+ try {
+ parser = (Parser) componentManager.lookup(Parser.ROLE);
+ InputSource source = getInputSource();
+ parser.parse(source, handler);
+ } catch (SAXException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new SAXException(e);
+ } finally {
+ if (parser != null) {
+ componentManager.release(parser);
+ }
+ }
+ }
+
+ public long getLastModified() {
+ return lastModifiedDate.getTime();
+ }
+
+ public abstract long getContentLength();
+
+ public InputSource getInputSource()
+ throws ProcessingException, IOException {
+ InputSource is = new InputSource(getInputStream());
+ is.setSystemId(getSystemId());
+ return is;
+ }
+
+ public void recycle() {
+ }
}
1.5.2.2 +65 -72
xml-cocoon2/src/java/org/apache/cocoon/components/xscript/XScriptObjectFromURL.java
Index: XScriptObjectFromURL.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/xscript/XScriptObjectFromURL.java,v
retrieving revision 1.5.2.1
retrieving revision 1.5.2.2
diff -u -r1.5.2.1 -r1.5.2.2
--- XScriptObjectFromURL.java 14 Apr 2002 04:06:19 -0000 1.5.2.1
+++ XScriptObjectFromURL.java 26 Jul 2002 04:40:49 -0000 1.5.2.2
@@ -50,14 +50,15 @@
*/
package org.apache.cocoon.components.xscript;
-import java.net.URLConnection;
-import java.net.URL;
-import java.io.InputStream;
-import java.io.IOException;
+import org.apache.avalon.framework.component.ComponentException;
-import org.apache.cocoon.components.url.URLFactory;
import org.apache.cocoon.ProcessingException;
-import org.apache.avalon.framework.component.ComponentException;
+import org.apache.cocoon.components.url.URLFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
/**
* An <code>XScriptObject</code> created from the contents of a URL.
@@ -66,69 +67,61 @@
* @version CVS $Id$
* @since August 30, 2001
*/
-public class XScriptObjectFromURL extends XScriptObject
-{
- /**
- * The content obtained from this URL becomes the content of this
- * instance.
- */
- String systemId;
-
- /**
- * The content length.
- */
- int contentLength;
-
- /**
- * When was the content of the URL last modified.
- */
- long lastModified;
-
- public XScriptObjectFromURL(XScriptManager manager, String systemId)
- {
- super(manager);
- this.systemId = systemId;
- }
-
- public InputStream getInputStream()
- throws ProcessingException, IOException
- {
- try {
- URLFactory urlFactory = (URLFactory)componentManager.lookup(URLFactory.ROLE);
- URL url = urlFactory.getURL(systemId);
- URLConnection conn = url.openConnection();
- InputStream is = conn.getInputStream();
- contentLength = conn.getContentLength();
- componentManager.release(urlFactory);
-
- return is;
- } catch (ComponentException ex) {
- throw new ProcessingException(ex);
- }
- }
-
- public long getContentLength()
- {
- return contentLength;
- }
-
- public long getLastModified()
- {
- return lastModified;
- }
-
- public String getSystemId()
- {
- // FIXME: generate a real system id to represent this object
- return "xscript:url:" + systemId;
- }
-
- public void recycle()
- {
- }
-
- public String toString()
- {
- return new StringBuffer("XScriptObjectFromURL(systemId =
").append(systemId).append(")").toString();
- }
+public class XScriptObjectFromURL extends XScriptObject {
+ /**
+ * The content obtained from this URL becomes the content of this
+ * instance.
+ */
+ String systemId;
+
+ /**
+ * The content length.
+ */
+ int contentLength;
+
+ /**
+ * When was the content of the URL last modified.
+ */
+ long lastModified;
+
+ public XScriptObjectFromURL(XScriptManager manager, String systemId) {
+ super(manager);
+ this.systemId = systemId;
+ }
+
+ public InputStream getInputStream()
+ throws ProcessingException, IOException {
+ try {
+ URLFactory urlFactory = (URLFactory)
componentManager.lookup(URLFactory.ROLE);
+ URL url = urlFactory.getURL(systemId);
+ URLConnection conn = url.openConnection();
+ InputStream is = conn.getInputStream();
+ contentLength = conn.getContentLength();
+ componentManager.release(urlFactory);
+
+ return is;
+ } catch (ComponentException ex) {
+ throw new ProcessingException(ex);
+ }
+ }
+
+ public long getContentLength() {
+ return contentLength;
+ }
+
+ public long getLastModified() {
+ return lastModified;
+ }
+
+ public String getSystemId() {
+ // FIXME: generate a real system id to represent this object
+ return "xscript:url:" + systemId;
+ }
+
+ public void recycle() {
+ }
+
+ public String toString() {
+ return new StringBuffer("XScriptObjectFromURL(systemId =
").append(systemId).append(")").toString();
+ }
}
1.4.2.3 +70 -86
xml-cocoon2/src/java/org/apache/cocoon/components/xscript/XScriptObjectInlineXML.java
Index: XScriptObjectInlineXML.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/xscript/XScriptObjectInlineXML.java,v
retrieving revision 1.4.2.2
retrieving revision 1.4.2.3
diff -u -r1.4.2.2 -r1.4.2.3
--- XScriptObjectInlineXML.java 20 Jun 2002 04:28:10 -0000 1.4.2.2
+++ XScriptObjectInlineXML.java 26 Jul 2002 04:40:49 -0000 1.4.2.3
@@ -50,19 +50,15 @@
*/
package org.apache.cocoon.components.xscript;
-import java.util.Stack;
-import java.io.StringReader;
-import java.io.StringBufferInputStream;
-import java.io.InputStream;
-import java.io.IOException;
+import org.apache.cocoon.ProcessingException;
-import org.xml.sax.helpers.DefaultHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.InputSource;
import org.xml.sax.ContentHandler;
-import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
-import org.apache.cocoon.ProcessingException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringBufferInputStream;
+import java.io.StringReader;
/**
* An <code>XScriptObject</code> created from an inline XML fragment.
@@ -72,79 +68,67 @@
* @version CVS $Id$
* @since July 7, 2001
*/
-public class XScriptObjectInlineXML extends XScriptObject
-{
- StringBuffer stringBuffer;
- StringBufferContentHandler streamHandler;
-
- public XScriptObjectInlineXML(XScriptManager manager)
- {
- super(manager);
- stringBuffer = new StringBuffer();
- stringBuffer.append("<?xml version=\"1.0\"?>\n\n");
- streamHandler = new StringBufferContentHandler(stringBuffer);
- }
-
- public XScriptObjectInlineXML(XScriptManager manager,
- StringBuffer stringBuffer)
- {
- super(manager);
- this.stringBuffer = stringBuffer;
- streamHandler = new StringBufferContentHandler(stringBuffer);
- }
-
- public XScriptObjectInlineXML(XScriptManager manager, String string)
- {
- super(manager);
- this.stringBuffer = new StringBuffer(string);
- streamHandler = new StringBufferContentHandler(stringBuffer);
- }
-
- public InputStream getInputStream()
- throws ProcessingException, IOException
- {
- // FIXME(VG): This method should never be used because it
- // incorrectly converts characters into bytes.
- return new StringBufferInputStream(stringBuffer.toString());
- }
-
- public InputSource getInputSource()
- throws ProcessingException, IOException
- {
- InputSource is = new InputSource(new StringReader(stringBuffer.toString()));
- is.setSystemId(getSystemId());
- return is;
- }
-
- public ContentHandler getContentHandler()
- {
- return streamHandler;
- }
-
- public void setNextContentHandler(ContentHandler handler)
- {
- streamHandler.setNextContentHandler(handler);
- }
-
- public String toString()
- {
- return stringBuffer.toString();
- }
-
- public long getContentLength()
- {
- return stringBuffer.length();
- }
-
- public String getContent()
- {
- return stringBuffer.toString();
- }
-
- public String getSystemId()
- {
- // FIXME: Implement a URI scheme to be able to refer to XScript
- // variables by URI
- return "xscript:inline:" + System.identityHashCode(this);
- }
+public class XScriptObjectInlineXML extends XScriptObject {
+ StringBuffer stringBuffer;
+ StringBufferContentHandler streamHandler;
+
+ public XScriptObjectInlineXML(XScriptManager manager) {
+ super(manager);
+ stringBuffer = new StringBuffer();
+ stringBuffer.append("<?xml version=\"1.0\"?>\n\n");
+ streamHandler = new StringBufferContentHandler(stringBuffer);
+ }
+
+ public XScriptObjectInlineXML(XScriptManager manager,
+ StringBuffer stringBuffer) {
+ super(manager);
+ this.stringBuffer = stringBuffer;
+ streamHandler = new StringBufferContentHandler(stringBuffer);
+ }
+
+ public XScriptObjectInlineXML(XScriptManager manager, String string) {
+ super(manager);
+ this.stringBuffer = new StringBuffer(string);
+ streamHandler = new StringBufferContentHandler(stringBuffer);
+ }
+
+ public InputStream getInputStream()
+ throws ProcessingException, IOException {
+ // FIXME(VG): This method should never be used because it
+ // incorrectly converts characters into bytes.
+ return new StringBufferInputStream(stringBuffer.toString());
+ }
+
+ public InputSource getInputSource()
+ throws ProcessingException, IOException {
+ InputSource is = new InputSource(new StringReader(stringBuffer.toString()));
+ is.setSystemId(getSystemId());
+ return is;
+ }
+
+ public ContentHandler getContentHandler() {
+ return streamHandler;
+ }
+
+ public void setNextContentHandler(ContentHandler handler) {
+ streamHandler.setNextContentHandler(handler);
+ }
+
+ public String toString() {
+ return stringBuffer.toString();
+ }
+
+ public long getContentLength() {
+ return stringBuffer.length();
+ }
+
+ public String getContent() {
+ return stringBuffer.toString();
+ }
+
+ public String getSystemId() {
+ // FIXME: Implement a URI scheme to be able to refer to XScript
+ // variables by URI
+ return "xscript:inline:" + System.identityHashCode(this);
+ }
}
1.4.2.1 +31 -40
xml-cocoon2/src/java/org/apache/cocoon/components/xscript/XScriptObjectResult.java
Index: XScriptObjectResult.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/xscript/XScriptObjectResult.java,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -u -r1.4 -r1.4.2.1
--- XScriptObjectResult.java 22 Feb 2002 07:00:15 -0000 1.4
+++ XScriptObjectResult.java 26 Jul 2002 04:40:49 -0000 1.4.2.1
@@ -50,14 +50,11 @@
*/
package org.apache.cocoon.components.xscript;
+import org.apache.cocoon.ProcessingException;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import javax.xml.transform.Result;
-import javax.xml.transform.sax.SAXResult;
-import javax.xml.transform.stream.StreamResult;
-import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.components.url.URLFactory;
/**
* An <code>XScriptObject</code> created from a JAXP
@@ -67,38 +64,32 @@
* @version CVS $Id$
* @since August 30, 2001
*/
-public class XScriptObjectResult extends XScriptObject
-{
- /**
- * The XML content of this object.
- */
- String content;
-
- public XScriptObjectResult(XScriptManager manager, String content)
- {
- super(manager);
- this.content = content;
- }
-
- public InputStream getInputStream()
- throws ProcessingException, IOException
- {
- return new ByteArrayInputStream(content.getBytes());
- }
-
- public long getContentLength()
- {
- return content.length();
- }
-
- public String getSystemId()
- {
- // FIXME: Return a real URL that identifies this object
- return "file:/";
- }
-
- public String toString()
- {
- return "XScriptObjectResult: " + content;
- }
+public class XScriptObjectResult extends XScriptObject {
+ /**
+ * The XML content of this object.
+ */
+ String content;
+
+ public XScriptObjectResult(XScriptManager manager, String content) {
+ super(manager);
+ this.content = content;
+ }
+
+ public InputStream getInputStream()
+ throws ProcessingException, IOException {
+ return new ByteArrayInputStream(content.getBytes());
+ }
+
+ public long getContentLength() {
+ return content.length();
+ }
+
+ public String getSystemId() {
+ // FIXME: Return a real URL that identifies this object
+ return "file:/";
+ }
+
+ public String toString() {
+ return "XScriptObjectResult: " + content;
+ }
}
1.4.2.1 +43 -48
xml-cocoon2/src/java/org/apache/cocoon/components/xscript/XScriptVariableScope.java
Index: XScriptVariableScope.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/xscript/XScriptVariableScope.java,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -u -r1.4 -r1.4.2.1
--- XScriptVariableScope.java 22 Feb 2002 07:00:15 -0000 1.4
+++ XScriptVariableScope.java 26 Jul 2002 04:40:49 -0000 1.4.2.1
@@ -61,55 +61,50 @@
* @version CVS $Id$
* @since August 4, 2001
*/
-public class XScriptVariableScope
-{
- /**
- * The variables store; each entry is <code>String</code>
- * representing the name of the variable, with the corresponding
- * value an {@link XScriptObject}.
- */
- HashMap variables = new HashMap();
+public class XScriptVariableScope {
+ /**
+ * The variables store; each entry is <code>String</code>
+ * representing the name of the variable, with the corresponding
+ * value an {@link XScriptObject}.
+ */
+ HashMap variables = new HashMap();
- /**
- * Define a new variable or overwrite the value of an existing
- * variable in this scope.
- *
- * @param name a <code>String</code> value
- * @param value a <code>{@link XScriptObject}</code> value
- */
- public synchronized void put(String name, XScriptObject value)
- {
- variables.put(name, value);
- }
+ /**
+ * Define a new variable or overwrite the value of an existing
+ * variable in this scope.
+ *
+ * @param name a <code>String</code> value
+ * @param value a <code>{@link XScriptObject}</code> value
+ */
+ public synchronized void put(String name, XScriptObject value) {
+ variables.put(name, value);
+ }
- /**
- * Obtains the value of the XScript <code>name</code> variable.
- *
- * @param name a <code>String</code> value
- * @return a <code>{@link XScriptObject}</code> value
- */
- public synchronized XScriptObject get(String name)
- throws IllegalArgumentException
- {
- if (!variables.containsKey(name))
- throw new IllegalArgumentException("Cannot find variable '"
- + name + "'!");
- return (XScriptObject)variables.get(name);
- }
+ /**
+ * Obtains the value of the XScript <code>name</code> variable.
+ *
+ * @param name a <code>String</code> value
+ * @return a <code>{@link XScriptObject}</code> value
+ */
+ public synchronized XScriptObject get(String name)
+ throws IllegalArgumentException {
+ if (!variables.containsKey(name))
+ throw new IllegalArgumentException("Cannot find variable '"
+ + name + "'!");
+ return (XScriptObject) variables.get(name);
+ }
- /**
- * Removes the XScript variable that's accessible via
- * <code>name</code>.
- *
- * @param name a <code>String</code> value
- */
- public synchronized void remove(String name)
- {
- variables.remove(name);
- }
+ /**
+ * Removes the XScript variable that's accessible via
+ * <code>name</code>.
+ *
+ * @param name a <code>String</code> value
+ */
+ public synchronized void remove(String name) {
+ variables.remove(name);
+ }
- public synchronized boolean defines(String name)
- {
- return variables.containsKey(name);
- }
+ public synchronized boolean defines(String name) {
+ return variables.containsKey(name);
+ }
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]