Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Issue #93 - System.getProperty() not accessible in Applets.

Make access to this process a checked system.
  • Loading branch information...
commit 8c92811da94fdd6b7a9b52e767eb271038e52099 1 parent 548fa42
Rolf rolfl authored
3  contrib/src/java/org/jdom2/contrib/input/scanner/XPathMatcher.java
View
@@ -61,6 +61,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
import org.jdom2.Element;
import org.jdom2.JDOMException;
+import org.jdom2.internal.SystemProperty;
import org.xml.sax.Attributes;
@@ -373,7 +374,7 @@ public static final XPathMatcher newXPathMatcher(
if (constructor == null) {
// First call.
// => Load configuration to determine implementation.
- String className = System.getProperty(
+ String className = SystemProperty.get(
IMPLEMENTATION_CLASS_PROPERTY,
DEFAULT_IMPLEMENTATION_CLASS);
81 core/src/java/org/jdom2/internal/SystemProperty.java
View
@@ -0,0 +1,81 @@
+/*--
+
+ Copyright (C) 2012 Jason Hunter & Brett McLaughlin.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions, and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions, and the disclaimer that follows
+ these conditions in the documentation and/or other materials
+ provided with the distribution.
+
+ 3. The name "JDOM" must not be used to endorse or promote products
+ derived from this software without prior written permission. For
+ written permission, please contact <request_AT_jdom_DOT_org>.
+
+ 4. Products derived from this software may not be called "JDOM", nor
+ may "JDOM" appear in their name, without prior written permission
+ from the JDOM Project Management <request_AT_jdom_DOT_org>.
+
+ In addition, we request (but do not require) that you include in the
+ end-user documentation provided with the redistribution and/or in the
+ software itself an acknowledgement equivalent to the following:
+ "This product includes software developed by the
+ JDOM Project (http://www.jdom.org/)."
+ Alternatively, the acknowledgment may be graphical using the logos
+ available at http://www.jdom.org/images/logos.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ This software consists of voluntary contributions made by many
+ individuals on behalf of the JDOM Project and was originally
+ created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
+ Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
+ on the JDOM Project, please see <http://www.jdom.org/>.
+
+ */
+
+package org.jdom2.internal;
+
+/**
+ * System.getProperty(...) requires security permissions in Applets, and some
+ * other cases and this class contains static methods that allow the security
+ * exceptions to fail silently.
+ *
+ * @author Rolf Lear
+ *
+ */
+public final class SystemProperty {
+
+ /**
+ * Query the System properties for a particular property. If the property
+ * is not set, or not accessible, it returns the def value.
+ * @param property The property to get
+ * @param def The value to return if the property is not accessible or not set.
+ * @return the appropriate property value.
+ */
+ public static final String get(final String property, final String def) {
+ try {
+ return System.getProperty(property, def);
+ } catch (SecurityException se) {
+ return def;
+ }
+ }
+}
11 core/src/java/org/jdom2/output/Format.java
View
@@ -635,9 +635,13 @@ public EscapeStrategy getEscapeStrategy() {
}
/**
- * This will set the newline separator (<code>lineSeparator</code>).
- * The default is <code>\r\n</code>. To make it output
- * the system default line ending string, call
+ * This will set the newline separator (<code>LineSeparator</code>).
+ * The default is <code>\r\n</code>.
+ * <p>
+ * Use the {@link #setLineSeparator(LineSeparator)} method to set
+ * standard separators in an easier way.
+ * <p>
+ * To make it output the system default line ending string, call
* <code>setLineSeparator(System.getProperty("line.separator"))</code>.
*
* <p>
@@ -682,6 +686,7 @@ public EscapeStrategy getEscapeStrategy() {
* end-of-line modifications.
*
* @see #setTextMode
+ * @see #setLineSeparator(LineSeparator)
*
* @param separator <code>String</code> line separator to use.
* @return a pointer to this Format for chaining
5 core/src/java/org/jdom2/output/LineSeparator.java
View
@@ -55,6 +55,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
package org.jdom2.output;
import org.jdom2.JDOMConstants;
+import org.jdom2.internal.SystemProperty;
/**
* An enumeration of common separators that are used for JDOM output.
@@ -139,7 +140,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* the equivalent of {@link #DOS} on windows platforms, and
* of {@link #UNIX} on UNIX and Apple systems (after Mac OSX).
*/
- SYSTEM(System.getProperty("line.separator")),
+ SYSTEM(SystemProperty.get("line.separator", "\r\n")),
/** Perform no end-of-line processing. */
NONE(null),
@@ -160,7 +161,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
private static String getDefaultLineSeparator() {
// Android has some unique ordering requirements in this bootstrap process.
// also, Android will not have the system property set, so we can exit with the null.
- final String prop = System.getProperty(JDOMConstants.JDOM2_PROPERTY_LINE_SEPARATOR, "DEFAULT");
+ final String prop = SystemProperty.get(JDOMConstants.JDOM2_PROPERTY_LINE_SEPARATOR, "DEFAULT");
if ("DEFAULT".equals(prop)) {
// need to do this to catch the normal process where the property is not set
// which will cause the value 'DEFAULT' to be returned by the getProperty(),
3  core/src/java/org/jdom2/xpath/XPath.java
View
@@ -60,6 +60,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
import java.util.*;
import org.jdom2.*;
+import org.jdom2.internal.SystemProperty;
/**
@@ -126,7 +127,7 @@ public static XPath newInstance(String path) throws JDOMException {
// First call => Determine implementation.
String className;
try {
- className = System.getProperty(XPATH_CLASS_PROPERTY,
+ className = SystemProperty.get(XPATH_CLASS_PROPERTY,
DEFAULT_XPATH_CLASS);
}
catch (SecurityException ex1) {
3  core/src/java/org/jdom2/xpath/XPathFactory.java
View
@@ -63,6 +63,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
import org.jdom2.filter.Filter;
import org.jdom2.filter.Filters;
import org.jdom2.internal.ReflectionConstructor;
+import org.jdom2.internal.SystemProperty;
import org.jdom2.xpath.jaxen.JaxenXPathFactory;
/**
@@ -98,7 +99,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
*/
private static final AtomicReference<XPathFactory> defaultreference = new AtomicReference<XPathFactory>();
- private static final String DEFAULTFACTORY = System.getProperty(
+ private static final String DEFAULTFACTORY = SystemProperty.get(
JDOMConstants.JDOM2_PROPERTY_XPATH_FACTORY, null);
/**
Please sign in to comment.
Something went wrong with that request. Please try again.