static {
   List aliasList = new ArrayList();
   Enumeration pe = ConfigurationManager.propertyNames();
   while (pe.hasMoreElements()) {
     String key = (String) pe.nextElement();
     if (key.startsWith(CONFIG_PREFIX)) aliasList.add(key.substring(CONFIG_PREFIX.length()));
   }
   aliases = (String[]) aliasList.toArray(new String[aliasList.size()]);
 }
  // load the namespace and schema from config
  private void init() throws CrosswalkInternalException {
    if (namespaces != null || schemaLocation != null) return;
    String myAlias = getPluginInstanceName();
    if (myAlias == null) {
      log.error(
          "Must use PluginManager to instantiate XSLTDisseminationCrosswalk so the class knows its name.");
      throw new CrosswalkInternalException(
          "Must use PluginManager to instantiate XSLTDisseminationCrosswalk so the class knows its name.");
    }

    // all configs for this plugin instance start with this:
    String prefix = CONFIG_PREFIX + DIRECTION + "." + myAlias + ".";

    // get the schema location string, should already be in the
    // right format for value of "schemaLocation" attribute.
    schemaLocation = ConfigurationManager.getProperty(prefix + "schemaLocation");
    if (schemaLocation == null)
      log.warn("No schemaLocation for crosswalk=" + myAlias + ", key=" + prefix + "schemaLocation");

    // sanity check: schemaLocation should have space.
    else if (schemaLocation.length() > 0 && schemaLocation.indexOf(" ") < 0)
      log.warn(
          "Possible INVALID schemaLocation (no space found) for crosswalk="
              + myAlias
              + ", key="
              + prefix
              + "schemaLocation"
              + "\n\tCorrect format is \"{namespace} {schema-URL}\"");

    // grovel for namespaces of the form:
    //  crosswalk.diss.{PLUGIN_NAME}.namespace.{PREFIX} = {URI}
    String nsPrefix = prefix + "namespace.";
    Enumeration pe = ConfigurationManager.propertyNames();
    List nsList = new ArrayList();
    while (pe.hasMoreElements()) {
      String key = (String) pe.nextElement();
      if (key.startsWith(nsPrefix))
        nsList.add(
            Namespace.getNamespace(
                key.substring(nsPrefix.length()), ConfigurationManager.getProperty(key)));
    }
    namespaces = (Namespace[]) nsList.toArray(new Namespace[nsList.size()]);

    preferList = ConfigurationManager.getBooleanProperty(prefix + "preferList", false);
  }
  /**
   * Loads maps from configuration unless it's already done. The configuration properties are a map
   * starting with the "metadata.hide." prefix followed by schema, element and qualifier separated
   * by dots and the value is true (hidden) or false (exposed).
   */
  protected synchronized void init() {
    if (!isInitialized()) {
      hiddenElementSets = new HashMap<>();
      hiddenElementMaps = new HashMap<>();

      Enumeration pne = ConfigurationManager.propertyNames();
      while (pne.hasMoreElements()) {
        String key = (String) pne.nextElement();
        if (key.startsWith(CONFIG_PREFIX)) {
          String mdField = key.substring(CONFIG_PREFIX.length());
          String segment[] = mdField.split("\\.", 3);

          // got schema.element.qualifier
          if (segment.length == 3) {
            Map<String, Set<String>> eltMap = hiddenElementMaps.get(segment[0]);
            if (eltMap == null) {
              eltMap = new HashMap<String, Set<String>>();
              hiddenElementMaps.put(segment[0], eltMap);
            }
            if (!eltMap.containsKey(segment[1])) {
              eltMap.put(segment[1], new HashSet<String>());
            }
            eltMap.get(segment[1]).add(segment[2]);
          }

          // got schema.element
          else if (segment.length == 2) {
            if (!hiddenElementSets.containsKey(segment[0])) {
              hiddenElementSets.put(segment[0], new HashSet<String>());
            }
            hiddenElementSets.get(segment[0]).add(segment[1]);
          }

          // oops..
          else {
            log.warn(
                "Bad format in hidden metadata directive, field=\""
                    + mdField
                    + "\", config property="
                    + key);
          }
        }
      }
    }
  }
예제 #4
0
  /**
   * Initialize an IP authenticator, reading in the configuration. Note this will never fail if the
   * configuration is bad -- a warning will be logged.
   */
  public IPAuthentication() {
    ipMatchers = new ArrayList<IPMatcher>();
    ipNegativeMatchers = new ArrayList<IPMatcher>();
    ipMatcherGroupIDs = new HashMap<IPMatcher, Integer>();
    ipMatcherGroupNames = new HashMap<IPMatcher, String>();

    Enumeration e = ConfigurationManager.propertyNames();

    while (e.hasMoreElements()) {
      String propName = (String) e.nextElement();
      if (propName.startsWith("authentication.ip.")) {
        String[] nameParts = propName.split("\\.");

        if (nameParts.length == 3) {
          addMatchers(nameParts[2], ConfigurationManager.getProperty(propName));
        } else {
          log.warn("Malformed configuration property name: " + propName);
        }
      }
    }
  }