View Javadoc
1   /*
2    * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4    *
5    * This code is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License version 2 only, as
7    * published by the Free Software Foundation.  Oracle designates this
8    * particular file as subject to the "Classpath" exception as provided
9    * by Oracle in the LICENSE file that accompanied this code.
10   *
11   * This code is distributed in the hope that it will be useful, but WITHOUT
12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14   * version 2 for more details (a copy is included in the LICENSE file that
15   * accompanied this code).
16   *
17   * You should have received a copy of the GNU General Public License version
18   * 2 along with this work; if not, write to the Free Software Foundation,
19   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20   *
21   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22   * or visit www.oracle.com if you need additional information or have any
23   * questions.
24   */
25  
26  package com.sun.org.apache.xalan.internal.utils;
27  
28  
29  import com.sun.org.apache.xalan.internal.XalanConstants;
30  import javax.xml.XMLConstants;
31  
32  /**
33   * This class manages security related properties
34   *
35   */
36  public final class XMLSecurityPropertyManager extends FeaturePropertyBase {
37  
38      /**
39       * Properties managed by the security property manager
40       */
41      public static enum Property {
42          ACCESS_EXTERNAL_DTD(XMLConstants.ACCESS_EXTERNAL_DTD,
43                  XalanConstants.EXTERNAL_ACCESS_DEFAULT),
44          ACCESS_EXTERNAL_STYLESHEET(XMLConstants.ACCESS_EXTERNAL_STYLESHEET,
45                  XalanConstants.EXTERNAL_ACCESS_DEFAULT);
46  
47          final String name;
48          final String defaultValue;
49  
50          Property(String name, String value) {
51              this.name = name;
52              this.defaultValue = value;
53          }
54  
55          public boolean equalsName(String propertyName) {
56              return (propertyName == null) ? false : name.equals(propertyName);
57          }
58  
59          String defaultValue() {
60              return defaultValue;
61          }
62      }
63  
64  
65      /**
66       * Default constructor. Establishes default values
67       */
68      public XMLSecurityPropertyManager() {
69          values = new String[Property.values().length];
70          for (Property property : Property.values()) {
71              values[property.ordinal()] = property.defaultValue();
72          }
73          //read system properties or jaxp.properties
74          readSystemProperties();
75      }
76  
77      /**
78       * Get the index by property name
79       * @param propertyName property name
80       * @return the index of the property if found; return -1 if not
81       */
82      public int getIndex(String propertyName){
83          for (Property property : Property.values()) {
84              if (property.equalsName(propertyName)) {
85                  //internally, ordinal is used as index
86                  return property.ordinal();
87              }
88          }
89          return -1;
90      }
91  
92      /**
93       * Read from system properties, or those in jaxp.properties
94       */
95      private void readSystemProperties() {
96          getSystemProperty(Property.ACCESS_EXTERNAL_DTD,
97                  XalanConstants.SP_ACCESS_EXTERNAL_DTD);
98          getSystemProperty(Property.ACCESS_EXTERNAL_STYLESHEET,
99                  XalanConstants.SP_ACCESS_EXTERNAL_STYLESHEET);
100     }
101 
102 }