Search in sources :

Example 26 with Enumeration

use of java.util.Enumeration in project sonarqube by SonarSource.

the class ActionServlet method initModulePrefixes.

/**
     * <p>Saves a String[] of module prefixes in the ServletContext under
     * Globals.MODULE_PREFIXES_KEY.  <strong>NOTE</strong> - the "" prefix for
     * the default module is not included in this list.</p>
     *
     * @param context The servlet context.
     * @since Struts 1.2
     */
protected void initModulePrefixes(ServletContext context) {
    ArrayList prefixList = new ArrayList();
    Enumeration names = context.getAttributeNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        if (!name.startsWith(Globals.MODULE_KEY)) {
            continue;
        }
        String prefix = name.substring(Globals.MODULE_KEY.length());
        if (prefix.length() > 0) {
            prefixList.add(prefix);
        }
    }
    String[] prefixes = (String[]) prefixList.toArray(new String[prefixList.size()]);
    context.setAttribute(Globals.MODULE_PREFIXES_KEY, prefixes);
}
Also used : Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList)

Example 27 with Enumeration

use of java.util.Enumeration in project sonarqube by SonarSource.

the class ActionServlet method destroyModules.

// ------------------------------------------------------ Protected Methods
/**
     * <p>Gracefully terminate use of any modules associated with this
     * application (if any).</p>
     *
     * @since Struts 1.1
     */
protected void destroyModules() {
    ArrayList values = new ArrayList();
    Enumeration names = getServletContext().getAttributeNames();
    while (names.hasMoreElements()) {
        values.add(names.nextElement());
    }
    Iterator keys = values.iterator();
    while (keys.hasNext()) {
        String name = (String) keys.next();
        Object value = getServletContext().getAttribute(name);
        if (!(value instanceof ModuleConfig)) {
            continue;
        }
        ModuleConfig config = (ModuleConfig) value;
        if (this.getProcessorForModule(config) != null) {
            this.getProcessorForModule(config).destroy();
        }
        getServletContext().removeAttribute(name);
        PlugIn[] plugIns = (PlugIn[]) getServletContext().getAttribute(Globals.PLUG_INS_KEY + config.getPrefix());
        if (plugIns != null) {
            for (int i = 0; i < plugIns.length; i++) {
                int j = plugIns.length - (i + 1);
                plugIns[j].destroy();
            }
            getServletContext().removeAttribute(Globals.PLUG_INS_KEY + config.getPrefix());
        }
    }
}
Also used : Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 28 with Enumeration

use of java.util.Enumeration in project sonarqube by SonarSource.

the class ActionServlet method splitAndResolvePaths.

/**
     * <p>Takes a comma-delimited string and splits it into paths, then
     * resolves those paths using the ServletContext and appropriate
     * ClassLoader.  When loading from the classloader, multiple resources per
     * path are supported to support, for example, multiple jars containing
     * the same named config file.</p>
     *
     * @param paths A comma-delimited string of paths
     * @return A list of resolved URL's for all found resources
     * @throws ServletException if a servlet exception is thrown
     */
protected List splitAndResolvePaths(String paths) throws ServletException {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    if (loader == null) {
        loader = this.getClass().getClassLoader();
    }
    ArrayList resolvedUrls = new ArrayList();
    URL resource;
    String path = null;
    try {
        // Process each specified resource path
        while (paths.length() > 0) {
            resource = null;
            int comma = paths.indexOf(',');
            if (comma >= 0) {
                path = paths.substring(0, comma).trim();
                paths = paths.substring(comma + 1);
            } else {
                path = paths.trim();
                paths = "";
            }
            if (path.length() < 1) {
                break;
            }
            if (path.charAt(0) == '/') {
                resource = getServletContext().getResource(path);
            }
            if (resource == null) {
                if (log.isDebugEnabled()) {
                    log.debug("Unable to locate " + path + " in the servlet context, " + "trying classloader.");
                }
                Enumeration e = loader.getResources(path);
                if (!e.hasMoreElements()) {
                    String msg = internal.getMessage("configMissing", path);
                    log.error(msg);
                    throw new UnavailableException(msg);
                } else {
                    while (e.hasMoreElements()) {
                        resolvedUrls.add(e.nextElement());
                    }
                }
            } else {
                resolvedUrls.add(resource);
            }
        }
    } catch (MalformedURLException e) {
        handleConfigException(path, e);
    } catch (IOException e) {
        handleConfigException(path, e);
    }
    return resolvedUrls;
}
Also used : MalformedURLException(java.net.MalformedURLException) Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) UnavailableException(javax.servlet.UnavailableException) IOException(java.io.IOException) URL(java.net.URL)

Example 29 with Enumeration

use of java.util.Enumeration in project sonarqube by SonarSource.

the class MockMultipartRequestHandler method handleRequest.

/**
      * <p>Mock parsing of the ServletInputStream.</p>
      *
      * <p>Constructs a <code>Hashtable</code> of elements
      *    from the HttpServletRequest's parameters - no
      *    <code>FormFile</code> elements are created.</p>
      * @param request Mock request instance.
      * @throws ServletException If there is a problem with
      * processing the request.
      */
public void handleRequest(HttpServletRequest request) throws ServletException {
    elements = new Hashtable();
    Enumeration enumer = request.getParameterNames();
    while (enumer.hasMoreElements()) {
        String key = enumer.nextElement().toString();
        elements.put(key, request.getParameter(key));
    }
}
Also used : Enumeration(java.util.Enumeration) Hashtable(java.util.Hashtable)

Example 30 with Enumeration

use of java.util.Enumeration in project sonarqube by SonarSource.

the class BaseConfig method copyProperties.

/**
     * <p>Return a copy of the properties held by this object.</p>
     */
protected Properties copyProperties() {
    Properties copy = new Properties();
    Enumeration keys = properties.propertyNames();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        copy.setProperty(key, properties.getProperty(key));
    }
    return copy;
}
Also used : Enumeration(java.util.Enumeration) Properties(java.util.Properties)

Aggregations

Enumeration (java.util.Enumeration)1179 IOException (java.io.IOException)202 ArrayList (java.util.ArrayList)141 File (java.io.File)102 HashMap (java.util.HashMap)86 Properties (java.util.Properties)85 Vector (java.util.Vector)83 List (java.util.List)77 HashSet (java.util.HashSet)65 Hashtable (java.util.Hashtable)63 Map (java.util.Map)59 Set (java.util.Set)59 URL (java.net.URL)57 ZipEntry (java.util.zip.ZipEntry)55 ServletContext (javax.servlet.ServletContext)53 Iterator (java.util.Iterator)50 InputStream (java.io.InputStream)47 ZipFile (java.util.zip.ZipFile)46 FileInputStream (java.io.FileInputStream)40 X509Certificate (java.security.cert.X509Certificate)37