[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xmlbeans-dev
Subject:    PATCH: Fix incorrect System.getProperty() behaviour
From:       Mark Swanson <mark () ScheduleWorld ! com>
Date:       2005-03-20 3:58:29
Message-ID: 423CF4E5.3090708 () ScheduleWorld ! com
[Download RAW message or body]

This patch works for me. I created a single file: SystemProperties.java. 
All code that used to call System.getProperty() now calls 
SystemProperties.getProperty().

By default (and if possible) SystemProperties contains 
System.getProperty() so no one should notice anything. However, this 
class enables folks like me to use XmlBeans in a secure environment.

I really like XmlBeans and I've been using it successfully in production 
environments for some time. I'm sure other folks will want to use 
XmlBeans within secure applications and will also benefit from this patch.

Please consider it.
Comments welcome.

Cheers.


Index: src/xmlcomp/org/apache/xmlbeans/impl/tool/CodeGenUtil.java
===================================================================
--- src/xmlcomp/org/apache/xmlbeans/impl/tool/CodeGenUtil.java 
(revision 158290)
+++ src/xmlcomp/org/apache/xmlbeans/impl/tool/CodeGenUtil.java  (working 
copy)
@@ -15,6 +15,8 @@

  package org.apache.xmlbeans.impl.tool;

+import org.apache.xmlbeans.impl.common.SystemProperties;
+
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Iterator;
@@ -268,7 +270,7 @@
      public static File[] systemClasspath()
      {
          List cp = new ArrayList();
-        String[] systemcp = 
System.getProperty("java.class.path").split(File.pathSeparator);
+        String[] systemcp = 
SystemProperties.getProperty("java.class.path").split(File.pathSeparator);
          for (int i = 0; i < systemcp.length; i++)
          {
              cp.add(new File(systemcp[i]));
@@ -364,7 +366,7 @@
              return result;
          }

-        String home = System.getProperty("java.home");
+        String home = SystemProperties.getProperty("java.home");

          String sep  = File.separator;
          result = new File(home + sep + ".." + sep + "bin", tool);
Index: src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCodeGenerator.java
===================================================================
--- src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCodeGenerator.java 
(revision 158290)
+++ src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCodeGenerator.java 
(working copy)
@@ -18,6 +18,7 @@
  import org.apache.xmlbeans.SchemaType;
  import org.apache.xmlbeans.SchemaTypeSystem;
  import org.apache.xmlbeans.impl.common.IOUtil;
+import org.apache.xmlbeans.impl.common.SystemProperties;
  import org.apache.xmlbeans.impl.common.XmlErrorWatcher;
  import org.apache.xmlbeans.impl.schema.SchemaTypeCodePrinter;
  import org.apache.xmlbeans.impl.schema.SchemaTypeSystemCompiler;
@@ -102,7 +103,7 @@
  // Some beta builds of JDK1.5 are having troubles creating temp 
directories
  // if the java.io.tmpdir doesn't exist.  This seems to help.
  try {
-  File tmpDirFile = new File(System.getProperty("java.io.tmpdir"));
+  File tmpDirFile = new 
File(SystemProperties.getProperty("java.io.tmpdir"));
    tmpDirFile.mkdirs();
  } catch(Exception e) { e.printStackTrace(); }

Index: src/xmlcomp/org/apache/xmlbeans/impl/tool/Diff.java
===================================================================
--- src/xmlcomp/org/apache/xmlbeans/impl/tool/Diff.java (revision 158290)
+++ src/xmlcomp/org/apache/xmlbeans/impl/tool/Diff.java (working copy)
@@ -15,6 +15,7 @@

  package org.apache.xmlbeans.impl.tool;

+import org.apache.xmlbeans.impl.common.SystemProperties;
  import org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl;

  import java.io.*;
@@ -275,7 +276,7 @@

      private static boolean isDiffIndex()
      {
-        String prop = System.getProperty("xmlbeans.diff.diffIndex");
+        String prop = 
SystemProperties.getProperty("xmlbeans.diff.diffIndex");
          if (prop == null)
              return true;
          if ("0".equals(prop) || "false".equalsIgnoreCase(prop))
Index: src/xmlcomp/org/apache/xmlbeans/impl/tool/XSTCTester.java
===================================================================
--- src/xmlcomp/org/apache/xmlbeans/impl/tool/XSTCTester.java 
(revision 158290)
+++ src/xmlcomp/org/apache/xmlbeans/impl/tool/XSTCTester.java   (working 
copy)
@@ -15,6 +15,7 @@

  package org.apache.xmlbeans.impl.tool;

+import org.apache.xmlbeans.impl.common.SystemProperties;
  import org.apache.xmlbeans.impl.xb.ltgfmt.TestsDocument;
  import org.apache.xmlbeans.impl.xb.ltgfmt.FileDesc;
  import org.apache.xmlbeans.XmlOptions;
@@ -178,7 +179,7 @@

          // Launch results
          System.out.println("Results output to " + resultsFile);
-        if 
(System.getProperty("os.name").toLowerCase().indexOf("windows") >= 0)
+        if 
(SystemProperties.getProperty("os.name").toLowerCase().indexOf("windows") 
 >= 0)
              Runtime.getRuntime().exec("cmd /c start iexplore \"" + 
resultsFile.getAbsolutePath() + "\"");
          else
              Runtime.getRuntime().exec("mozilla file://" + 
resultsFile.getAbsolutePath());
Index: src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java
===================================================================
--- src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java 
(revision 158290)
+++ src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java 
(working copy)
@@ -27,6 +27,7 @@
  import org.apache.xmlbeans.ResourceLoader;
  import org.apache.xmlbeans.impl.common.IOUtil;
  import org.apache.xmlbeans.impl.common.ResolverUtil;
+import org.apache.xmlbeans.impl.common.SystemProperties;
  import org.apache.xmlbeans.impl.common.XmlErrorPrinter;
  import org.apache.xmlbeans.impl.common.XmlErrorWatcher;
  import org.apache.xmlbeans.impl.schema.PathResourceLoader;
@@ -1049,7 +1050,7 @@

          // Calculate the usenames based on the relativized filenames 
on the filesystem
          if (baseDir == null)
-            baseDir = new File(System.getProperty("user.dir"));
+            baseDir = new File(SystemProperties.getProperty("user.dir"));

          ResourceLoader cpResourceLoader = null;

Index: src/common/org/apache/xmlbeans/impl/common/ResolverUtil.java
===================================================================
--- src/common/org/apache/xmlbeans/impl/common/ResolverUtil.java 
(revision 158290)
+++ src/common/org/apache/xmlbeans/impl/common/ResolverUtil.java 
(working copy)
@@ -31,7 +31,7 @@
      {
          try
          {
-            Object o = 
Class.forName(System.getProperty("xmlbean.entityResolver")).newInstance();
+            Object o = 
Class.forName(SystemProperties.getProperty("xmlbean.entityResolver")).newInstance();
              _entityResolver = (EntityResolver)o;
          }
          catch (Exception e)
Index: src/common/org/apache/xmlbeans/impl/common/XBeanDebug.java
===================================================================
--- src/common/org/apache/xmlbeans/impl/common/XBeanDebug.java 
(revision 158290)
+++ src/common/org/apache/xmlbeans/impl/common/XBeanDebug.java  (working 
copy)
@@ -33,7 +33,7 @@
      private static int initializeBitsFromProperty()
      {
          int bits = 0;
-        String prop = System.getProperty(traceProp, defaultProp);
+        String prop = SystemProperties.getProperty(traceProp, defaultProp);
          if (prop.indexOf("TRACE_SCHEMA_LOADING") >= 0)
              bits |= TRACE_SCHEMA_LOADING;
          return bits;
Index: 
src/xmlinputstream/org/apache/xmlbeans/xml/stream/utils/NestedThrowable.java
===================================================================
--- 
src/xmlinputstream/org/apache/xmlbeans/xml/stream/utils/NestedThrowable.java(revision 
158290)
+++ 
src/xmlinputstream/org/apache/xmlbeans/xml/stream/utils/NestedThrowable.java(working 
copy)
@@ -28,6 +28,8 @@
  import java.io.PrintStream;
  import java.lang.reflect.InvocationTargetException;

+import org.apache.xmlbeans.impl.common.SystemProperties;
+
  public interface NestedThrowable {

    /** Get the nested Throwable. */
@@ -44,7 +46,7 @@

    static class Util {

-    private static String EOL = System.getProperty("line.separator");
+    private static String EOL = 
SystemProperties.getProperty("line.separator");

      /**
       * Prints the exception message and its nested exception message.
Index: src/store/org/apache/xmlbeans/impl/store/Saver.java
===================================================================
--- src/store/org/apache/xmlbeans/impl/store/Saver.java (revision 158290)
+++ src/store/org/apache/xmlbeans/impl/store/Saver.java (working copy)
@@ -22,6 +22,7 @@

  import org.apache.xmlbeans.impl.common.QNameHelper;
  import org.apache.xmlbeans.impl.common.EncodingMap;
+import org.apache.xmlbeans.impl.common.SystemProperties;

  import java.io.Writer;
  import java.io.Reader;
@@ -2949,7 +2950,7 @@
      private String    _initialDefaultUri;

      static final String _newLine =
-        System.getProperty( "line.separator" ) == null
+        SystemProperties.getProperty( "line.separator" ) == null
              ? "\n"
-            : System.getProperty( "line.separator" );
-}
\ No newline at end of file
+            : SystemProperties.getProperty( "line.separator" );
+}
Index: src/xmlpublic/org/apache/xmlbeans/XmlCalendar.java
===================================================================
--- src/xmlpublic/org/apache/xmlbeans/XmlCalendar.java  (revision 158290)
+++ src/xmlpublic/org/apache/xmlbeans/XmlCalendar.java  (working copy)
@@ -15,6 +15,8 @@

  package org.apache.xmlbeans;

+import org.apache.xmlbeans.impl.common.SystemProperties;
+
  import java.util.GregorianCalendar;
  import java.util.Calendar;
  import java.util.Date;
@@ -261,7 +263,7 @@
          {
              try
              {
-                String yearstring = System.getProperty("user.defaultyear");
+                String yearstring = 
SystemProperties.getProperty("user.defaultyear");
                  if (yearstring != null)
                      defaultYear = Integer.parseInt(yearstring);
                  else
Index: src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java
===================================================================
--- src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java 
(revision 158290)
+++ src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java (working 
copy)
@@ -18,6 +18,7 @@
  import org.apache.xmlbeans.XmlErrorCodes;
  import org.apache.xmlbeans.impl.common.QNameHelper;
  import org.apache.xmlbeans.impl.common.ResolverUtil;
+import org.apache.xmlbeans.impl.common.SystemProperties;
  import org.apache.xmlbeans.XmlObject;
  import org.apache.xmlbeans.SchemaGlobalElement;
  import org.apache.xmlbeans.SchemaComponent;
@@ -512,13 +513,13 @@

          _compatMap = 
(Map)options.get(XmlOptions.COMPILE_SUBSTITUTE_NAMES);
          _noUpa = options.hasOption(XmlOptions.COMPILE_NO_UPA_RULE) ? 
true :
- 
!"true".equals(System.getProperty("xmlbean.uniqueparticleattribution", 
"true"));
+ 
!"true".equals(SystemProperties.getProperty("xmlbean.uniqueparticleattribution", 
"true"));
          _noPvr = options.hasOption(XmlOptions.COMPILE_NO_PVR_RULE) ? 
true :
- 
!"true".equals(System.getProperty("xmlbean.particlerestriction", "true"));
+ 
!"true".equals(SystemProperties.getProperty("xmlbean.particlerestriction", 
"true"));
          _noAnn = options.hasOption(XmlOptions.COMPILE_NO_ANNOTATIONS) 
? true :
- 
!"true".equals(System.getProperty("xmlbean.schemaannotations", "true"));
+ 
!"true".equals(SystemProperties.getProperty("xmlbean.schemaannotations", 
"true"));
          _doingDownloads = 
options.hasOption(XmlOptions.COMPILE_DOWNLOAD_URLS) ? true :
- 
"true".equals(System.getProperty("xmlbean.downloadurls", "false"));
+ 
"true".equals(SystemProperties.getProperty("xmlbean.downloadurls", 
"false"));
          _entityResolver = 
(EntityResolver)options.get(XmlOptions.ENTITY_RESOLVER);

          if (_entityResolver == null)
Index: 
src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
===================================================================
--- 
src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java 
    (revision 158290)
+++ 
src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java 
    (working copy)
@@ -42,6 +42,7 @@
  import org.apache.xmlbeans.ResourceLoader;
  import org.apache.xmlbeans.impl.common.NameUtil;
  import org.apache.xmlbeans.impl.common.QNameHelper;
+import org.apache.xmlbeans.impl.common.SystemProperties;
  import org.apache.xmlbeans.impl.common.XBeanDebug;
  import org.apache.xmlbeans.impl.util.HexBin;
  import org.apache.xmlbeans.impl.values.XmlObjectBase;
@@ -858,7 +859,7 @@
                  String[] props = new String[] { "user.name", 
"user.dir", "user.timezone", "user.country", "java.class.path", 
"java.home", "java.vendor", "java.version", "os.version" };
                  for (int i = 0; i < props.length; i++)
                  {
-                    String prop = System.getProperty(props[i]);
+                    String prop = SystemProperties.getProperty(props[i]);
                      if (prop != null)
                      {
                          daos.writeUTF(prop);
Index: 
src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java
===================================================================
--- 
src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java 
    (revision 158290)
+++ 
src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java 
    (working copy)
@@ -28,6 +28,7 @@

  import javax.xml.namespace.QName;
  import org.apache.xmlbeans.impl.common.NameUtil;
+import org.apache.xmlbeans.impl.common.SystemProperties;
  import org.apache.xmlbeans.PrePostExtension;
  import org.apache.xmlbeans.InterfaceExtension;
  import org.apache.xmlbeans.SchemaType;
@@ -49,9 +50,9 @@


      static final String LINE_SEPARATOR =
-        System.getProperty("line.separator") == null
+        SystemProperties.getProperty("line.separator") == null
              ? "\n"
-            : System.getProperty("line.separator");
+            : SystemProperties.getProperty("line.separator");

      static final String MAX_SPACES = " 
         ";
      static final int INDENT_INCREMENT = 4;
Index: src/saaj_api/javax/xml/soap/FactoryFinder.java
===================================================================
--- src/saaj_api/javax/xml/soap/FactoryFinder.java      (revision 158290)
+++ src/saaj_api/javax/xml/soap/FactoryFinder.java      (working copy)
@@ -22,6 +22,7 @@
  import java.io.InputStreamReader;

  import java.util.Properties;
+import org.apache.xmlbeans.impl.common.SystemProperties;

  /**
   * This class is used to locate factory classes for javax.xml.soap.
@@ -76,14 +77,14 @@
       */
      static Object find(String factoryPropertyName, String 
defaultFactoryClassName) throws SOAPException {
          try {
-            String factoryClassName = 
System.getProperty(factoryPropertyName);
+            String factoryClassName = 
SystemProperties.getProperty(factoryPropertyName);
              if (factoryClassName != null) {
                  return newInstance(factoryClassName);
              }
          } catch (SecurityException securityexception) {}

          try {
-            String propertiesFileName = System.getProperty("java.home")
+            String propertiesFileName = 
SystemProperties.getProperty("java.home")
                                          + File.separator + "lib"
                                          + File.separator + 
"jaxm.properties";
              File file = new File(propertiesFileName);
Index: build.xml
===================================================================
--- build.xml   (revision 158290)
+++ build.xml   (working copy)
@@ -454,7 +454,11 @@
          <javac srcdir="src/xmlinputstream"
              source="${javac.source}" target="${javac.target}"
              destdir="build/classes/xmlinputstream"
-            debug="on"/>
+            debug="on">
+            <classpath>
+                <pathelement location="build/classes/common"/>
+            </classpath>
+               </javac>
      </target>

      <!-- xmlpublic target 
============================================== -->
@@ -464,6 +468,7 @@
          <javac srcdir="src/xmlpublic" 
destdir="build/classes/xmlpublic" source="${javac.source}" 
target="${javac.target}" debug="on">
              <classpath>
                  <pathelement location="build/classes/xmlinputstream"/>
+                <pathelement location="build/classes/common"/>
                  <pathelement location="build/lib/jsr173_api.jar"/>
              </classpath>
          </javac>
@@ -644,6 +649,7 @@
          <mkdir dir="build/classes/saaj_api"/>
          <javac srcdir="src/saaj_api" destdir="build/classes/saaj_api" 
source="${javac.source}" target="${javac.target}" debug="on">
              <classpath id="saaj_api.compile.path">
+                <pathelement location="build/classes/common"/>
              </classpath>
          </javac>



-- 
Free replacement for Exchange and Outlook (Contacts and Calendar)
http://www.ScheduleWorld.com/
WAP: http://www.ScheduleWorld.com/sw/WAPToday?id=4000&tz=EST
WebDAV: http://www.ScheduleWorld.com/sw/webDAVDir/4000.ics
VFREEBUSY: http://www.ScheduleWorld.com/sw/freebusy/4000.ifb

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic