haul 2002/07/14 07:47:03
Modified: src/java/org/apache/cocoon/components/language/markup/xsp
XSPUtil.java
Log:
fix util.xsl
Revision Changes Path
1.10 +59 -2
xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/XSPUtil.java
Index: XSPUtil.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/XSPUtil.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- XSPUtil.java 13 Jun 2002 09:28:15 -0000 1.9
+++ XSPUtil.java 14 Jul 2002 14:47:03 -0000 1.10
@@ -64,6 +64,8 @@
import org.xml.sax.SAXException;
import org.apache.cocoon.environment.SourceResolver;
+import org.apache.avalon.framework.component.ComponentManager;
+import org.apache.avalon.framework.component.Component;
import org.apache.excalibur.source.Source;
import java.lang.Long;
@@ -73,6 +75,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
+import java.util.HashMap;
/**
* The XSP <code>Utility</code> object helper
@@ -279,8 +282,10 @@
StringBuffer result = new StringBuffer();
InputStream stream = null;
+ Source resource = null;
try {
- Source resource = resolver.resolveURI(uri);
+ Map mymap = new HashMap();
+ resource = resolver.resolveURI(uri);
long length = resource.getContentLength();
stream = new BufferedInputStream(resource.getInputStream());
if (length != -1) {
@@ -303,8 +308,60 @@
} finally {
if ( stream != null )
try {stream.close();} catch (Exception ase) { throw new
RuntimeException(ase.getMessage()); }
+ if ( resource != null )
+ resolver.release(resource);
}
return result.toString();
}
+
+
+ public static void includeSource(String uri, String base, SourceResolver
resolver, ContentHandler contentHandler)
+ throws RuntimeException {
+
+ if (base != null) base = (base != "" ? base : null);
+ Source source = null;
+ try {
+ source = resolver.resolveURI(uri, base, null);
+ resolver.toSAX(source, new
org.apache.cocoon.xml.IncludeXMLConsumer(contentHandler));
+ } catch (Exception e) {
+ throw new RuntimeException("Error including source "+base+"
"+uri+":"+e.getMessage());
+ } finally {
+ if (source != null)
+ resolver.release(source);
+ }
+ }
+
+ public static void includeString(String string, ComponentManager manager,
ContentHandler contentHandler)
+ throws RuntimeException {
+
+ XSPUtil.includeInputSource(new InputSource( new StringReader(
String.valueOf(string))), manager, contentHandler);
+ }
+
+ public static void includeFile(String name, ComponentManager manager,
ContentHandler contentHandler, Map objectModel)
+ throws RuntimeException {
+
+ try {
+ XSPUtil.includeInputSource(new InputSource(new
FileReader(XSPUtil.relativeFilename(name,objectModel))),
+ manager, contentHandler);
+ } catch (IOException e) {
+ throw new RuntimeException("Could not include file "+name+" : " +
e.getMessage());
+ }
+ }
+
+ public static void includeInputSource(InputSource source, ComponentManager
manager, ContentHandler contentHandler)
+ throws RuntimeException {
+
+ Parser newParser = null;
+
+ try {
+ newParser = (Parser) manager.lookup(Parser.ROLE);
+ XSPUtil.include(source, contentHandler, newParser);
+ } catch (Exception e) {
+ throw new RuntimeException("Could not include page " + e.getMessage());
+ } finally {
+ if (newParser != null) manager.release((Component) newParser);
+ }
+ }
+
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]