Search in sources :

Example 36 with Enumeration

use of java.util.Enumeration in project j2objc by google.

the class OutputProperties method copyFrom.

/**
   * Copy the keys and values from the source to this object.  This will
   * not copy the default values.  This is meant to be used by going from
   * a higher precedence object to a lower precedence object, so that if a
   * key already exists, this method will not reset it.
   *
   * @param src non-null reference to the source properties.
   * @param shouldResetDefaults true if the defaults should be reset based on 
   *                            the method property.
   */
public void copyFrom(Properties src, boolean shouldResetDefaults) {
    Enumeration keys = src.keys();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        if (!isLegalPropertyKey(key))
            //"output property not recognized: "
            throw new IllegalArgumentException(XSLMessages.createMessage(XSLTErrorResources.ER_OUTPUT_PROPERTY_NOT_RECOGNIZED, new Object[] { key }));
        Object oldValue = m_properties.get(key);
        if (null == oldValue) {
            String val = (String) src.get(key);
            if (shouldResetDefaults && key.equals(OutputKeys.METHOD)) {
                setMethodDefaults(val);
            }
            m_properties.put(key, val);
        } else if (key.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) {
            m_properties.put(key, (String) oldValue + " " + (String) src.get(key));
        }
    }
}
Also used : Enumeration(java.util.Enumeration)

Example 37 with Enumeration

use of java.util.Enumeration in project j2objc by google.

the class EnvironmentCheck method appendFoundJars.

/**
   * Print out report of .jars found in a classpath. 
   *
   * Takes the information encoded from a checkPathForJars() 
   * call and dumps it out to our PrintWriter.
   *
   * @param container Node to append our report to
   * @param factory Document providing createElement, etc. services
   * @param v Vector of Hashtables of .jar file info
   * @param desc description to print out in header
   *
   * @return false if OK, true if any .jars were reported 
   * as having errors
   * @see #checkPathForJars(String, String[])
   */
protected boolean appendFoundJars(Node container, Document factory, Vector v, String desc) {
    if ((null == v) || (v.size() < 1))
        return false;
    boolean errors = false;
    for (int i = 0; i < v.size(); i++) {
        Hashtable subhash = (Hashtable) v.elementAt(i);
        for (Enumeration keys = subhash.keys(); keys.hasMoreElements(); ) /* no increment portion */
        {
            Object key = keys.nextElement();
            try {
                String keyStr = (String) key;
                if (keyStr.startsWith(ERROR)) {
                    errors = true;
                }
                Element node = factory.createElement("foundJar");
                node.setAttribute("name", keyStr.substring(0, keyStr.indexOf("-")));
                node.setAttribute("desc", keyStr.substring(keyStr.indexOf("-") + 1));
                node.appendChild(factory.createTextNode((String) subhash.get(keyStr)));
                container.appendChild(node);
            } catch (Exception e) {
                errors = true;
                Element node = factory.createElement("foundJar");
                node.appendChild(factory.createTextNode(ERROR + " Reading " + key + " threw: " + e.toString()));
                container.appendChild(node);
            }
        }
    }
    return errors;
}
Also used : Enumeration(java.util.Enumeration) Hashtable(java.util.Hashtable) Element(org.w3c.dom.Element)

Example 38 with Enumeration

use of java.util.Enumeration in project j2objc by google.

the class OutputPropertiesFactory method loadPropertiesFile.

/**
     * Load the properties file from a resource stream.  If a
     * key name such as "org.apache.xslt.xxx", fix up the start of
     * string to be a curly namespace.  If a key name starts with
     * "xslt.output.xxx", clip off "xslt.output.".  If a key name *or* a
     * key value is discovered, check for : in the text, and
     * fix it up to be ":", since earlier versions of the JDK do not
     * handle the escape sequence (at least in key names).
     *
     * @param resourceName non-null reference to resource name.
     * @param defaults Default properties, which may be null.
     */
private static Properties loadPropertiesFile(final String resourceName, Properties defaults) throws IOException {
    // This static method should eventually be moved to a thread-specific class
    // so that we can cache the ContextClassLoader and bottleneck all properties file
    // loading throughout Xalan.
    Properties props = new Properties(defaults);
    InputStream is = null;
    BufferedInputStream bis = null;
    try {
        if (ACCESS_CONTROLLER_CLASS != null) {
            is = (InputStream) AccessController.doPrivileged(new PrivilegedAction() {

                public Object run() {
                    return OutputPropertiesFactory.class.getResourceAsStream(resourceName);
                }
            });
        } else {
            // User may be using older JDK ( JDK < 1.2 )
            is = OutputPropertiesFactory.class.getResourceAsStream(resourceName);
        }
        bis = new BufferedInputStream(is);
        props.load(bis);
    } catch (IOException ioe) {
        if (defaults == null) {
            throw ioe;
        } else {
            throw new WrappedRuntimeException(Utils.messages.createMessage(MsgKey.ER_COULD_NOT_LOAD_RESOURCE, new Object[] { resourceName }), ioe);
        //"Could not load '"+resourceName+"' (check CLASSPATH), now using just the defaults ", ioe);
        }
    } catch (SecurityException se) {
        // Repeat IOException handling for sandbox/applet case -sc
        if (defaults == null) {
            throw se;
        } else {
            throw new WrappedRuntimeException(Utils.messages.createMessage(MsgKey.ER_COULD_NOT_LOAD_RESOURCE, new Object[] { resourceName }), se);
        //"Could not load '"+resourceName+"' (check CLASSPATH, applet security), now using just the defaults ", se);
        }
    } finally {
        if (bis != null) {
            bis.close();
        }
        if (is != null) {
            is.close();
        }
    }
    // Note that we're working at the HashTable level here,
    // and not at the Properties level!  This is important
    // because we don't want to modify the default properties.
    // NB: If fixupPropertyString ends up changing the property
    // name or value, we need to remove the old key and re-add
    // with the new key and value.  However, then our Enumeration
    // could lose its place in the HashTable.  So, we first
    // clone the HashTable and enumerate over that since the
    // clone will not change.  When we migrate to Collections,
    // this code should be revisited and cleaned up to use
    // an Iterator which may (or may not) alleviate the need for
    // the clone.  Many thanks to Padraig O'hIceadha
    // <padraig@gradient.ie> for finding this problem.  Bugzilla 2000.
    Enumeration keys = ((Properties) props.clone()).keys();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        // Now check if the given key was specified as a
        // System property. If so, the system property
        // overides the default value in the propery file.
        String value = null;
        try {
            value = System.getProperty(key);
        } catch (SecurityException se) {
        // No-op for sandbox/applet case, leave null -sc
        }
        if (value == null)
            value = (String) props.get(key);
        String newKey = fixupPropertyString(key, true);
        String newValue = null;
        try {
            newValue = System.getProperty(newKey);
        } catch (SecurityException se) {
        // No-op for sandbox/applet case, leave null -sc
        }
        if (newValue == null)
            newValue = fixupPropertyString(value, false);
        else
            newValue = fixupPropertyString(newValue, false);
        if (key != newKey || value != newValue) {
            props.remove(key);
            props.put(newKey, newValue);
        }
    }
    return props;
}
Also used : Enumeration(java.util.Enumeration) BufferedInputStream(java.io.BufferedInputStream) PrivilegedAction(java.security.PrivilegedAction) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) WrappedRuntimeException(org.apache.xml.serializer.utils.WrappedRuntimeException)

Example 39 with Enumeration

use of java.util.Enumeration in project j2objc by google.

the class NamespaceMappings method getMappingFromURI.

MappingRecord getMappingFromURI(String uri) {
    MappingRecord foundMap = null;
    Enumeration prefixes = m_namespaces.keys();
    while (prefixes.hasMoreElements()) {
        String prefix = (String) prefixes.nextElement();
        MappingRecord map2 = getMappingFromPrefix(prefix);
        if (map2 != null && (map2.m_uri).equals(uri)) {
            foundMap = map2;
            break;
        }
    }
    return foundMap;
}
Also used : Enumeration(java.util.Enumeration)

Example 40 with Enumeration

use of java.util.Enumeration in project guice by google.

the class ServletDefinitionTest method testServletInitAndConfig.

public final void testServletInitAndConfig() throws ServletException {
    Injector injector = createMock(Injector.class);
    Binding binding = createMock(Binding.class);
    expect(binding.acceptScopingVisitor((BindingScopingVisitor) anyObject())).andReturn(true);
    expect(injector.getBinding(Key.get(HttpServlet.class))).andReturn(binding);
    final HttpServlet mockServlet = new HttpServlet() {
    };
    expect(injector.getInstance(Key.get(HttpServlet.class))).andReturn(mockServlet).anyTimes();
    replay(injector, binding);
    //some init params
    //noinspection SSBasedInspection
    final Map<String, String> initParams = new ImmutableMap.Builder<String, String>().put("ahsd", "asdas24dok").put("ahssd", "asdasd124ok").build();
    String pattern = "/*";
    final ServletDefinition servletDefinition = new ServletDefinition(Key.get(HttpServlet.class), UriPatternType.get(UriPatternType.SERVLET, pattern), initParams, null);
    ServletContext servletContext = createMock(ServletContext.class);
    final String contextName = "thing__!@@44__SRV" + getClass();
    expect(servletContext.getServletContextName()).andReturn(contextName);
    replay(servletContext);
    servletDefinition.init(servletContext, injector, Sets.<HttpServlet>newIdentityHashSet());
    assertNotNull(mockServlet.getServletContext());
    assertEquals(contextName, mockServlet.getServletContext().getServletContextName());
    assertEquals(Key.get(HttpServlet.class).toString(), mockServlet.getServletName());
    final ServletConfig servletConfig = mockServlet.getServletConfig();
    final Enumeration names = servletConfig.getInitParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        assertTrue(initParams.containsKey(name));
        assertEquals(initParams.get(name), servletConfig.getInitParameter(name));
    }
    verify(injector, binding, servletContext);
}
Also used : Binding(com.google.inject.Binding) Enumeration(java.util.Enumeration) Injector(com.google.inject.Injector) HttpServlet(javax.servlet.http.HttpServlet) ServletConfig(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

Enumeration (java.util.Enumeration)1418 IOException (java.io.IOException)247 ArrayList (java.util.ArrayList)183 File (java.io.File)122 Vector (java.util.Vector)98 Properties (java.util.Properties)97 HashMap (java.util.HashMap)96 List (java.util.List)89 URL (java.net.URL)74 HashSet (java.util.HashSet)71 Map (java.util.Map)71 Hashtable (java.util.Hashtable)70 Iterator (java.util.Iterator)70 Set (java.util.Set)67 InputStream (java.io.InputStream)62 ZipEntry (java.util.zip.ZipEntry)62 ServletContext (javax.servlet.ServletContext)55 ZipFile (java.util.zip.ZipFile)51 FileInputStream (java.io.FileInputStream)48 ServletException (javax.servlet.ServletException)46