[jboss-svn-commits] JBL Code SVN: r37906 - labs/jbosstm/branches/JBOSSTS_4_16/common/classes/com/arjuna/common/util/propertyservice.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Mar 5 10:35:57 EST 2012


Author: tomjenkinson
Date: 2012-03-05 10:35:57 -0500 (Mon, 05 Mar 2012)
New Revision: 37906

Modified:
   labs/jbosstm/branches/JBOSSTS_4_16/common/classes/com/arjuna/common/util/propertyservice/PropertiesFactory.java
Log:
JBTM-1054 updated with patch from Tomaz - much appreciated

Modified: labs/jbosstm/branches/JBOSSTS_4_16/common/classes/com/arjuna/common/util/propertyservice/PropertiesFactory.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_16/common/classes/com/arjuna/common/util/propertyservice/PropertiesFactory.java	2012-03-05 15:34:53 UTC (rev 37905)
+++ labs/jbosstm/branches/JBOSSTS_4_16/common/classes/com/arjuna/common/util/propertyservice/PropertiesFactory.java	2012-03-05 15:35:57 UTC (rev 37906)
@@ -20,6 +20,7 @@
  */
 package com.arjuna.common.util.propertyservice;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -30,6 +31,11 @@
 import java.util.Properties;
 
 import com.arjuna.common.util.ConfigurationInfo;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLResolver;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
 
 /*
  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
@@ -136,7 +142,7 @@
         }
 
         try {
-            inputProperties.loadFromXML(inputStream);
+		loadFromXML(inputProperties,inputStream);
         } finally {
             inputStream.close();
         }
@@ -157,6 +163,43 @@
         return outputProperties;
     }
 
+    private static Properties loadFromXML(Properties p, InputStream is) throws IOException {
+        try {
+            final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+            inputFactory.setXMLResolver(new XMLResolver() {
+                @Override
+                public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace) throws XMLStreamException {
+                    return new ByteArrayInputStream(new byte[0]);
+                }
+            });
+            XMLStreamReader parser = inputFactory.createXMLStreamReader(is);
+            /*
+             * xml looks like this
+             * <entry key="CoreEnvironmentBean.nodeIdentifier">1</entry>
+           */
+            while (true) {
+                int event = parser.next();
+                if (event == XMLStreamConstants.END_DOCUMENT) {
+                    parser.close();
+                    break;
+                }
+                if (event == XMLStreamConstants.START_ELEMENT) {
+                    String key = parser.getAttributeValue(0);
+                    String value = null;
+                    if (parser.next() == XMLStreamConstants.CHARACTERS) {
+                        value = parser.getText();
+                    }
+                    if (value == null) { value = ""; }
+                    if (key != null) {
+                        p.put(key, value);
+                    }
+                }
+            }
+        } catch (XMLStreamException e) {
+            throw new IOException("Could not read xml", e);
+        }
+        return null;
+    }
     private static synchronized void initDefaultProperties(String fileNamePropertyKey)
     {
         if(defaultProperties != null) {



More information about the jboss-svn-commits mailing list