cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp XSPUtil.java
Date Wed, 22 May 2002 16:02:29 GMT
haul        02/05/22 09:02:29

  Modified:    src/java/org/apache/cocoon/components/language/markup/xsp
                        XSPUtil.java
  Log:
  added util:get-source and util:include-source tags
  plus helper function in XSPUtil
  
  Revision  Changes    Path
  1.7       +38 -1     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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XSPUtil.java	22 Feb 2002 07:00:08 -0000	1.6
  +++ XSPUtil.java	22 May 2002 16:02:29 -0000	1.7
  @@ -63,6 +63,10 @@
   import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
   
  +import org.apache.cocoon.environment.SourceResolver;
  +import org.apache.cocoon.environment.Source;
  +import java.lang.Long;
  +
   import java.io.*;
   import java.net.URLDecoder;
   import java.net.URLEncoder;
  @@ -74,7 +78,7 @@
    * The XSP <code>Utility</code> object helper
    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
    * @author <a href="mailto:bloritsch@apache.org>Berin Loritsch</a>
  - * @version CVS $Id: XSPUtil.java,v 1.6 2002/02/22 07:00:08 cziegeler Exp $
  + * @version CVS $Id: XSPUtil.java,v 1.7 2002/05/22 16:02:29 haul Exp $
    */
   public class XSPUtil {
       public static String pathComponent(String filename) {
  @@ -270,4 +274,37 @@
           Context context = ObjectModelHelper.getContext(objectModel);
           return context.getAttribute(name);
       }
  +
  +    public static String getSourceAsString(String uri, SourceResolver resolver) throws
RuntimeException {
  +
  +        StringBuffer result = new StringBuffer();
  +        InputStream stream = null;
  +        try {
  +            Source resource = resolver.resolve(uri);
  +            long length = resource.getContentLength();
  +            stream = new BufferedInputStream(resource.getInputStream());
  +            if (length != -1) {
  +                byte[] buffer = new byte[(new Long(length)).intValue()];
  +                stream.read(buffer);
  +                stream.close();
  +                if (buffer != null) result.append(new String(buffer));
  +            } else {
  +                int readBytes = 0;
  +                do {
  +                    byte[] buffer = new byte[4*1024];
  +                    readBytes = stream.read(buffer);
  +                    if (readBytes == -1) break;
  +                    if (readBytes > 0) result.append(new String(buffer,0,readBytes));
  +                } while (true);
  +                stream.close();
  +            }
  +        } catch (Exception e) {
  +            throw new RuntimeException(e.getMessage());
  +        } finally {
  +            if ( stream != null ) 
  +                try {stream.close();} catch (Exception ase) {  throw new RuntimeException(ase.getMessage());
}
  +        } 
  +        return result.toString();
  +    }
  +
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message