ovidiu 02/02/12 17:54:25 Modified: src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap SchemeSitemap.java Log: (readResource) New function for reading files from the Web application. Revision Changes Path 1.4 +33 -1 xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap/SchemeSitemap.java Index: SchemeSitemap.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap/SchemeSitemap.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SchemeSitemap.java 19 Jan 2002 01:07:13 -0000 1.3 +++ SchemeSitemap.java 13 Feb 2002 01:54:25 -0000 1.4 @@ -1,6 +1,7 @@ package org.apache.cocoon.scheme.sitemap; import java.io.InputStream; +import java.io.InputStreamReader; import java.util.Date; import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.component.ComponentException; @@ -90,6 +91,36 @@ } /** + * Reads a resource from the current webapp and return its content + * as a string. + * + * @param source a <code>String</code> representing the resource + * name to be read. + * @return a <code>String</code> with the contents of the Webapp + * resource + * @throws Exception if anything goes wrong + */ + public String readResource(String source) + throws Exception + { + org.apache.cocoon.environment.Context context = + (org.apache.cocoon.environment.Context)cocoonContext.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT); + InputStream is = context.getResource(source).openStream(); + InputStreamReader isr = new InputStreamReader(is); + int size = 8192; + int len = size; + char[] cbuf = new char[size]; + StringBuffer buffer = new StringBuffer(); + + while ((len = isr.read(cbuf, 0, len)) != -1) + buffer.append(cbuf, 0, len); + + isr.close(); + is.close(); + return buffer.toString(); + } + + /** * Initialize the sitemap components according to the configuration * in components.xconf. * @@ -237,9 +268,10 @@ Date start = new Date(); + J2S.JavaObject ssitemap = new J2S.JavaObject(this); J2S.JavaObject sManager = new J2S.JavaObject(manager); J2S.JavaObject ssource = new J2S.JavaObject(sitemapSource); - Value[] args = new Value[] { sManager, ssource }; + Value[] args = new Value[] { ssitemap, sManager, ssource }; SchemeInterpreter interpreters = (SchemeInterpreter)manager.lookup(SchemeInterpreter.ROLE);
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]