cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r515650 - /cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/WriteDOMSessionTransformer.java
Date Wed, 07 Mar 2007 17:12:00 GMT
Author: joerg
Date: Wed Mar  7 09:11:58 2007
New Revision: 515650

URL: http://svn.apache.org/viewvc?view=rev&rev=515650
Log:
COCOON-2021: prevent NPE in case session is not available

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/WriteDOMSessionTransformer.java

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/WriteDOMSessionTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/WriteDOMSessionTransformer.java?view=diff&rev=515650&r1=515649&r2=515650
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/WriteDOMSessionTransformer.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/WriteDOMSessionTransformer.java
Wed Mar  7 09:11:58 2007
@@ -59,7 +59,10 @@
     public static final String DOM_ROOT_ELEMENT = "dom-root-element";
 
     private boolean buildDom = false;
-    private boolean sessionAvailable = false;
+    /**
+     * component was correctly setup
+     */
+    private boolean setup = false;
 
     private Session session;
     private DOMBuilder builder;
@@ -76,7 +79,7 @@
         this.session = null;
         this.builder = null;
         this.buildDom = false;
-        this.sessionAvailable = false;
+        this.setup = false;
     }
 
     /* BEGIN SitemapComponent methods */
@@ -91,11 +94,11 @@
             DOMName = parameters.getParameter(WriteDOMSessionTransformer.DOM_NAME, null);
             rootElement = parameters.getParameter(WriteDOMSessionTransformer.DOM_ROOT_ELEMENT,
null);
             if (DOMName != null && rootElement != null) {
-                // only now we know it is usefull to store something in the session
+                // only now we know it is useful to store something in the session
                 getLogger().debug("WriteSessionTransformer: " + WriteDOMSessionTransformer.DOM_NAME
+ "=" +
                                   DOMName + "; " + WriteDOMSessionTransformer.DOM_ROOT_ELEMENT
+ "=" +
                                   rootElement);
-                sessionAvailable = true;
+                setup = true;
                 storedPrefixMap = new HashMap();
             } else {
                 getLogger().error("WriteSessionTransformer: need " + WriteDOMSessionTransformer.DOM_NAME
+
@@ -115,7 +118,7 @@
         super.startPrefixMapping(prefix, uri);
         if (buildDom) {
             builder.startPrefixMapping(prefix, uri);
-        } else {
+        } else if (setup) {
             storePrefixMapping(prefix, uri);
         }
     }
@@ -123,7 +126,7 @@
     public void startElement(String uri, String name, String raw, Attributes attributes)
     throws SAXException {
         // only build the DOM tree if session is available
-        if (name.equalsIgnoreCase(rootElement) && sessionAvailable) {
+        if (setup && name.equalsIgnoreCase(rootElement)) {
             getLogger().debug("WriteSessionTransformer: start building DOM tree");
             buildDom = true;
             builder = new DOMBuilder();
@@ -138,7 +141,7 @@
 
     public void endElement(String uri, String name, String raw)
             throws SAXException {
-        if (name.equalsIgnoreCase(rootElement) && sessionAvailable) {
+        if (setup && name.equalsIgnoreCase(rootElement)) {
             buildDom = false;
             builder.endElement(uri, name, raw);
             builder.endDocument();
@@ -179,10 +182,11 @@
     }
 
     protected void launchStoredMappings() throws SAXException {
-        Iterator it = storedPrefixMap.keySet().iterator();
+        Iterator it = storedPrefixMap.entrySet().iterator();
         while (it.hasNext()) {
-            String pre = (String) it.next();
-            String uri = (String) storedPrefixMap.get(pre);
+            Map.Entry entry = (Map.Entry) it.next();
+            String pre = (String) entry.getKey();
+            String uri = (String) entry.getValue();
             getLogger().debug("WriteSessionTransformer: launching prefix mapping[ pre: "
+ pre + " uri: " + uri + " ]");
             builder.startPrefixMapping(pre, uri);
         }



Mime
View raw message