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);
}
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());
}
}
}
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;
}
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));
}
}
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;
}
Aggregations