List of usage examples for javax.servlet ServletConfig getInitParameterNames
public Enumeration<String> getInitParameterNames();
Enumeration
of String
objects, or an empty Enumeration
if the servlet has no initialization parameters. From source file:org.apache.jetspeed.services.resources.VariableResourcesService.java
/** * Initializer method that sets up the generic resources. * * @param confs A Configurations object. *///from ww w.j av a2s . c o m private void initVariables(ServletConfig config) { ServletContext ctxt = config.getServletContext(); String path = ctxt.getRealPath("/"); // define web app dir if (path != null) { variables.put(WEBAPP_DIR, normalizePath(path)); } // FIXME. the following code blocks on Tomcat // when loaded on startup /* path = ctxt.getContext("/").getRealPath("/"); if (path != null ) { variables.put(WEB_DIR, normalizePath(path) ); } */ // define JVM app dir try { path = new File(".").getCanonicalPath(); if (path != null) { variables.put(JVM_DIR, normalizePath(path)); } } catch (IOException e) { //very unlikely that the JVM can't //resolve its path //But logging it anyway... logger.error("Exception define JVM app dir", e); } // load servlet init parameters as variables, they may override // the previously defined variables. All param names are folded // to lower case Enumeration en = config.getInitParameterNames(); while (en.hasMoreElements()) { String paramName = (String) en.nextElement(); String paramValue = config.getInitParameter(paramName); variables.put(paramName.toLowerCase(), paramValue); } }
From source file:org.getobjects.servlets.WOServletAdaptor.java
@Override public void init(final ServletConfig _cfg) throws ServletException { // Jetty: org.mortbay.jetty.servlet.ServletHolder$Config@114024 super.init(_cfg); String an = this.valueFromServletConfig(_cfg, "WOAppName"); String ac = this.valueFromServletConfig(_cfg, "WOAppClass"); if (ac == null) ac = an;/*from w ww .ja v a 2 s.c o m*/ if (an == null && ac != null) { /* if only the class is set, we use the shortname of the class */ int dotidx = ac.lastIndexOf('.'); an = dotidx < 1 ? ac : ac.substring(dotidx + 1); } if (an == null) { log.warn("no WOAppName specified in servlet context: " + _cfg); an = WOApplication.class.getName(); } /* Construct properties for the volatile "domain" from servlet init * parameters and context init parameters and attributes. * It's probably best to have a real UserDefaults concept, but for the * time being this is better than nothing. */ final Properties properties = new Properties(); Enumeration parameterNamesEnum = _cfg.getInitParameterNames(); while (parameterNamesEnum.hasMoreElements()) { final String name = (String) parameterNamesEnum.nextElement(); final String value = _cfg.getInitParameter(name); if (name != null && value != null) properties.put(name, value); else if (value == null) log.error("Got no value for init parameter: " + name); } /* The ServletContext may override the previous init parameters. * ServletContext init parameters will be overridden by attributes. */ final ServletContext sctx = _cfg.getServletContext(); if (sctx != null) { parameterNamesEnum = sctx.getInitParameterNames(); while (parameterNamesEnum.hasMoreElements()) { final String name = (String) parameterNamesEnum.nextElement(); properties.put(name, sctx.getInitParameter(name)); } final Enumeration attributeNamesEnum = sctx.getAttributeNames(); while (attributeNamesEnum.hasMoreElements()) { final String name = (String) attributeNamesEnum.nextElement(); properties.put(name, sctx.getAttribute(name)); } } this.initApplicationWithName(an, ac, properties); }
From source file:org.sakaiproject.portal.charon.SkinnableCharonPortal.java
private void showSnoop(PortalRenderContext rcontext, boolean b, ServletConfig servletConfig, HttpServletRequest req) {/*ww w. ja v a 2 s.c om*/ Enumeration e = null; rcontext.put("snoopRequest", req.toString()); if (servletConfig != null) { Map<String, Object> m = new HashMap<String, Object>(); e = servletConfig.getInitParameterNames(); if (e != null) { while (e.hasMoreElements()) { String param = (String) e.nextElement(); m.put(param, servletConfig.getInitParameter(param)); } } rcontext.put("snoopServletConfigParams", m); } rcontext.put("snoopRequest", req); e = req.getHeaderNames(); if (e.hasMoreElements()) { Map<String, Object> m = new HashMap<String, Object>(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); m.put(name, req.getHeader(name)); } rcontext.put("snoopRequestHeaders", m); } e = req.getParameterNames(); if (e.hasMoreElements()) { Map<String, Object> m = new HashMap<String, Object>(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); m.put(name, req.getParameter(name)); } rcontext.put("snoopRequestParamsSingle", m); } e = req.getParameterNames(); if (e.hasMoreElements()) { Map<String, Object> m = new HashMap<String, Object>(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); String[] vals = (String[]) req.getParameterValues(name); StringBuilder sb = new StringBuilder(); if (vals != null) { sb.append(vals[0]); for (int i = 1; i < vals.length; i++) sb.append(" ").append(vals[i]); } m.put(name, sb.toString()); } rcontext.put("snoopRequestParamsMulti", m); } e = req.getAttributeNames(); if (e.hasMoreElements()) { Map<String, Object> m = new HashMap<String, Object>(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); m.put(name, req.getAttribute(name)); } rcontext.put("snoopRequestAttr", m); } }
From source file:org.amplafi.jawr.maven.JawrMojo.java
private void setupJawrConfig(ServletConfig config, ServletContext context, final Map<String, Object> attributes, final Response respData) { expect(config.getServletContext()).andReturn(context).anyTimes(); expect(config.getServletName()).andReturn("maven-jawr-plugin").anyTimes(); context.log(isA(String.class)); expectLastCall().anyTimes();/*from w ww . j av a 2 s . c om*/ expect(context.getResourcePaths(isA(String.class))).andAnswer(new IAnswer<Set>() { public Set<String> answer() throws Throwable { final Set<String> set = new HashSet<String>(); // hack to disallow orphan bundles Exception e = new Exception(); for (StackTraceElement trace : e.getStackTrace()) { if (trace.getClassName().endsWith("OrphanResourceBundlesMapper")) { return set; } } String path = (String) EasyMock.getCurrentArguments()[0]; File file = new File(getRootPath() + path); if (file.exists() && file.isDirectory()) { for (String one : file.list()) { set.add(path + one); } } return set; } }).anyTimes(); expect(context.getResourceAsStream(isA(String.class))).andAnswer(new IAnswer<InputStream>() { public InputStream answer() throws Throwable { String path = (String) EasyMock.getCurrentArguments()[0]; File file = new File(getRootPath(), path); return new FileInputStream(file); } }).anyTimes(); expect(context.getAttribute(isA(String.class))).andAnswer(new IAnswer<Object>() { public Object answer() throws Throwable { return attributes.get(EasyMock.getCurrentArguments()[0]); } }).anyTimes(); context.setAttribute(isA(String.class), isA(Object.class)); expectLastCall().andAnswer(new IAnswer<Object>() { public Object answer() throws Throwable { String key = (String) EasyMock.getCurrentArguments()[0]; Object value = EasyMock.getCurrentArguments()[1]; attributes.put(key, value); return null; } }).anyTimes(); expect(config.getInitParameterNames()).andReturn(new Enumeration<String>() { public boolean hasMoreElements() { return false; } public String nextElement() { return null; } }).anyTimes(); expect(config.getInitParameter(JawrConstant.TYPE_INIT_PARAMETER)).andAnswer(new IAnswer<String>() { public String answer() throws Throwable { return respData == null ? null : respData.getType(); } }).anyTimes(); expect(config.getInitParameter("configLocation")).andReturn(getConfigLocation()).anyTimes(); expect(config.getInitParameter("configPropertiesSourceClass")).andReturn(null).anyTimes(); }
From source file:ORG.oclc.os.SRW.SRWServletInfo.java
public void init(final ServletConfig config) { try {/*w w w .j a v a 2 s .c o m*/ String propsfilePath = EscidocConfiguration.getInstance() .get(EscidocConfiguration.SEARCH_PROPERTIES_DIRECTORY, "search/config"); if (!propsfilePath.equals("")) { String escidocHome = EscidocConfiguration.getInstance().getEscidocHome(); if (!escidocHome.isEmpty()) { if (!escidocHome.endsWith("/")) { escidocHome += "/"; } escidocHome += "conf/"; if (propsfilePath.startsWith("/")) { propsfilePath = propsfilePath.substring(1); } propsfilePath = escidocHome + propsfilePath; } if (!propsfilePath.endsWith("/")) { propsfilePath += "/"; } } propsfileName = propsfilePath + "SRWServer.props"; log.info("Reading properties file: " + propsfileName); srwHome = config.getServletContext().getRealPath("/"); if (srwHome.endsWith("/")) srwHome = srwHome.substring(0, srwHome.length() - 1); if (srwHome.endsWith("\\")) srwHome = srwHome.substring(0, srwHome.length() - 1); log.debug("srwHome=" + srwHome); int off = srwHome.lastIndexOf('/'); if (off < 0) off = srwHome.lastIndexOf('\\'); if (off > 0) { webappHome = srwHome.substring(0, off); log.debug("webappHome=" + webappHome); off = webappHome.lastIndexOf('/'); if (off < 0) off = webappHome.lastIndexOf('\\'); if (off > 0) tomcatHome = webappHome.substring(0, off); log.debug("tomcatHome=" + tomcatHome); } InputStream is; try { is = Utilities.openInputStream(propsfileName, srwHome, null); properties.load(is); properties.setProperty("propsfilePath", propsfilePath); is.close(); } catch (java.io.FileNotFoundException e) { log.info("Unable to load properties file: " + propsfileName); log.info("Will using web.xml for configuration parameters"); Enumeration enumer = config.getInitParameterNames(); String propName; while (enumer.hasMoreElements()) { propName = (String) enumer.nextElement(); properties.setProperty(propName, config.getInitParameter(propName)); } } buildDbList(properties, dbVector, dbnames, config.getServletContext().getRealPath("/")); srwHome = properties.getProperty("SRW.Home"); if (srwHome == null) { srwHome = config.getServletContext().getRealPath("/"); } log.info("SRW.Home=" + srwHome); pathInfoIndex = Integer .parseInt(properties.getProperty("pathInfoIndex", Integer.toString(pathInfoIndex))); log.info("pathInfoIndex=" + pathInfoIndex); resultSetIdleTime = Integer .parseInt(properties.getProperty("resultSetIdleTime", Integer.toString(resultSetIdleTime))); log.info("resultSetIdleTime=" + resultSetIdleTime + " seconds"); defaultDatabase = properties.getProperty("default.database"); if (defaultDatabase == null) defaultDatabase = "default.database not specified in properties file"; log.info("default.database=" + defaultDatabase); indexDotHtmlLocation = properties.getProperty("index.html"); if (indexDotHtmlLocation == null) indexDotHtmlLocation = srwHome + "index.html"; String s = properties.getProperty("makeIndex.html"); if (s != null) if (s.equalsIgnoreCase("true")) makeIndexDotHtml = true; // any dbs to open automatically? s = properties.getProperty("SRW.OpenAllDatabasesOnStartup"); if (s == null) { // maybe a short list to open? s = properties.getProperty("SRW.OpenDatabasesInListOnStartup"); if (s != null) { log.info("Opening databases: " + s); createDBs(s); } else log.info("Not opening databases yet"); } else if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("t") || s.equals("1")) { Enumeration enumer = properties.propertyNames(); int offset; String dbname, list = new String(","), t; while (enumer.hasMoreElements()) { t = (String) enumer.nextElement(); if (t.startsWith("db.")) { offset = t.indexOf(".", 3); dbname = t.substring(3, offset); if (list.indexOf(", " + dbname + ",") == -1) { // not yet in list list = list + " " + dbname + ","; } } } log.info("Opening all databases :" + list); createDBs(list); } // load the sru-srw extension mapping table Enumeration enumer = properties.propertyNames(); String extension, namespace, sruParm, t; while (enumer.hasMoreElements()) { t = (String) enumer.nextElement(); if (t.startsWith("extension.") && !t.endsWith(".namespace")) { sruParm = t.substring(10); extension = properties.getProperty(t); extensions.put(sruParm, extension); log.debug("added extension=" + extension + ", with sru parm=" + sruParm); namespace = properties.getProperty("extension." + extension + ".namespace"); namespaces.put(sruParm, namespace); log.debug("added namespace=" + namespace + ", with sru parm=" + sruParm); } } log.info("SRWServletInfo initialization complete"); } catch (Exception e) { log.error(e, e); } }