cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r157071 - cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/tools/generation/I18nCatalogueGenerator.java
Date Fri, 11 Mar 2005 11:16:08 GMT
Author: cziegeler
Date: Fri Mar 11 03:16:05 2005
New Revision: 157071

URL: http://svn.apache.org/viewcvs?view=rev&rev=157071
Log:
Make Cocoon compilable with JDK 1.3. Patch by Jens Maukisch

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/tools/generation/I18nCatalogueGenerator.java

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/tools/generation/I18nCatalogueGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/tools/generation/I18nCatalogueGenerator.java?view=diff&r1=157070&r2=157071
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/tools/generation/I18nCatalogueGenerator.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/tools/generation/I18nCatalogueGenerator.java
Fri Mar 11 03:16:05 2005
@@ -15,10 +15,7 @@
  */
 package org.apache.cocoon.portal.tools.generation;
 
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.StringReader;
 import java.net.MalformedURLException;
 import java.util.Iterator;
 import java.util.List;
@@ -26,15 +23,18 @@
 
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.cocoon.ProcessingException;
 import org.apache.cocoon.environment.SourceResolver;
 import org.apache.cocoon.generation.ServiceableGenerator;
 import org.apache.cocoon.portal.tools.PortalToolCatalogue;
 import org.apache.cocoon.portal.tools.PortalToolManager;
+import org.apache.cocoon.xml.IncludeXMLConsumer;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.xml.sax.SAXParser;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
 
 /**
  * 
@@ -43,9 +43,8 @@
 public class I18nCatalogueGenerator extends ServiceableGenerator {
     
     private SAXParser parser;
-
-    private String catalogueStartTag = "<?xml version=\"1.0\"?><catalogue>";
-    private String catalogueEndTag = "</catalogue>";
+    private PortalToolManager ptm;
+    private final String CATALOGUE_TAG = "catalogue";
     private String lang = ".xml";
     private StringBuffer i18n = new StringBuffer();
     
@@ -54,59 +53,55 @@
      */
     public void generate() throws IOException, SAXException,
             ProcessingException {
-        StringBuffer catalogue = new StringBuffer();
-        catalogue.append(catalogueStartTag).append(i18n.toString()).append(catalogueEndTag);
//add pi and catalogue tags
-        final InputSource inputSource = new InputSource(new StringReader(catalogue.toString()));
-        try {
-            parser = (SAXParser)this.manager.lookup(SAXParser.ROLE);
-        } catch (ServiceException e) {
-            e.printStackTrace();
-        }
-        parser.parse(inputSource, super.xmlConsumer);
-    }
-    
-    /* (non-Javadoc)
-     * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
-     */
-    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)

-    					throws ProcessingException, SAXException, IOException {
-        super.setup(resolver, objectModel, src, par);
-        if(src.indexOf("_") != -1) {
-            lang = src.substring(src.indexOf("_"), src.length());
-            lang = lang.toLowerCase();
-        }
-        PortalToolManager ptm = null;
-        try {
-            ptm = (PortalToolManager) this.manager.lookup(PortalToolManager.ROLE);
+    	this.xmlConsumer.startDocument();
+    	this.xmlConsumer.startElement("", CATALOGUE_TAG, CATALOGUE_TAG, new AttributesImpl());
             List cats = ptm.getI18n();
             for(Iterator it = cats.iterator(); it.hasNext();) {
                 PortalToolCatalogue ptc = (PortalToolCatalogue) it.next();
                 try {
                     Source cat;
 	                cat = resolver.resolveURI(ptc.getLocation() + ptc.getName() + lang);
-	                // if(!cat.exists()) {
-	                //    cat = resolver.resolveURI(ptc.getLocation() + ptc.getName() + ".xml");
// default file
-	                // }
-	                BufferedReader br = new BufferedReader(new InputStreamReader(cat.getInputStream()));
-	                String tmp = new String();
-	                while(br.ready()) {
-	                    tmp = tmp + br.readLine();
-	                }
-                    tmp = tmp.replaceAll("<\\?(.+)\\?>",""); // remove processing instr.
-                    tmp = tmp.replaceAll("<catalogue([^>]+)?>{1}" ,""); // remove
catalogue tags
-                    tmp = tmp.replaceAll("</catalogue>", "");
-                    tmp = tmp.replaceAll("<!--(.+)-->", "");
-                    i18n.append(tmp);
+	                IncludeXMLConsumer ixc = new IncludeXMLConsumer(this.xmlConsumer);
+	                ixc.setIgnoreRootElement(true);
+	                this.parser.parse(new InputSource(cat.getInputStream()),  ixc);
                 } catch (MalformedURLException e) {
+                	// ignore
                 } catch (IOException e) {
+                	// ignore
                 }
             }
-        } catch (ServiceException e) {
-            e.printStackTrace();
-        } finally {
-            this.manager.release(ptm);
+        this.xmlConsumer.endElement("", CATALOGUE_TAG, CATALOGUE_TAG);
+        this.xmlConsumer.endDocument();
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
+     */
+    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)

+    					throws ProcessingException, SAXException, IOException {
+        super.setup(resolver, objectModel, src, par);
+        if(src.indexOf("_") != -1) {
+            this.lang = src.substring(src.indexOf("_"), src.length());
+            this.lang = this.lang.toLowerCase();
         }
-        
+
     }
+    
+    /* (non-Javadoc)
+	 * @see org.apache.cocoon.generation.ServiceableGenerator#service(org.apache.avalon.framework.service.ServiceManager)
+	 */
+	public void service(ServiceManager manager) throws ServiceException {
+		super.service(manager);
+		this.parser = (SAXParser)this.manager.lookup(SAXParser.ROLE);
+		ptm = (PortalToolManager) this.manager.lookup(PortalToolManager.ROLE);
+	}
 
+	/* (non-Javadoc)
+	 * @see org.apache.cocoon.generation.ServiceableGenerator#dispose()
+	 */
+	public void dispose() {
+		super.dispose();
+		this.manager.release(this.parser);
+		this.manager.release(this.ptm);
+	}
 }



Mime
View raw message