public Object getAttribute(String name) { if (name.startsWith("org.apache.tomcat")) { // XXX XXX XXX XXX Security - servlets may get too much access !!! // right now we don't check because we need JspServlet to // be able to access classloader and classpath if (name.equals("org.apache.tomcat.jsp_classpath")) { String cp = getServletLoader().getClassPath(); return cp; } if (name.equals("org.apache.tomcat.protection_domain")) { return getProtectionDomain(); } if (name.equals("org.apache.tomcat.classloader")) { return this.getServletLoader().getClassLoader(); } if (name.equals(FacadeManager.FACADE_ATTRIBUTE)) { if (!allowAttribute(name)) return null; return this.getFacadeManager(); } return null; // org.apache.tomcat namespace is reserved in tomcat } else { Object o = attributes.get(name); return attributes.get(name); } }
/** * Add a servlet with the given name to the container. The servlet will be loaded by the * container's class loader and instantiated using the given class name. * * <p>Called to add a new servlet from web.xml */ public void addServlet(ServletWrapper wrapper) throws TomcatException { wrapper.setContext(this); String name = wrapper.getServletName(); // System.out.println("Adding servlet " + name + " " + wrapper); // check for duplicates if (servlets.get(name) != null) { log("Removing duplicate servlet " + name + " " + wrapper); removeServletByName(name); // getServletByName(name).destroy(); } servlets.put(name, wrapper); }
/** * Maps a named servlet to a particular path or extension. If the named servlet is unregistered, * it will be added and subsequently mapped. * * <p>Note that the order of resolution to handle a request is: * * <p>exact mapped servlet (eg /catalog) prefix mapped servlets (eg /foo/bar/*) extension mapped * servlets (eg *jsp) default servlet */ public void addServletMapping(String path, String servletName) throws TomcatException { if (mappings.get(path) != null) { log("Removing duplicate " + path + " -> " + mappings.get(path)); mappings.remove(path); Container ct = (Container) containers.get(path); removeContainer(ct); } ServletWrapper sw = (ServletWrapper) servlets.get(servletName); if (sw == null) { // Workaround for frequent "bug" in web.xmls // Declare a default mapping log("Mapping with unregistered servlet " + servletName); sw = addServlet(servletName, servletName); } if ("/".equals(path)) defaultServlet = sw; mappings.put(path, sw); Container map = new Container(); map.setContext(this); map.setHandler(sw); map.setPath(path); contextM.addContainer(map); containers.put(path, map); }
/** * Will add a new security constraint: For all paths: if( match(path) && match(method) && match( * transport ) ) then require("roles") * * <p>This is equivalent with adding a Container with the path, method and transport. If the * container will be matched, the request will have to pass the security constraints. */ public void addSecurityConstraint( String path[], String methods[], String roles[], String transport) throws TomcatException { for (int i = 0; i < path.length; i++) { Container ct = new Container(); ct.setContext(this); ct.setTransport(transport); ct.setRoles(roles); ct.setPath(path[i]); ct.setMethods(methods); // XXX check if exists, merge if true. constraints.put(path[i], ct); // contextM.addSecurityConstraint( this, path[i], ct); contextM.addContainer(ct); } }
public Enumeration getTaglibs() { return tagLibs.keys(); }
public void addInitParameter(String name, String value) { initializationParameters.put(name, value); }
public void removeAttribute(String name) { attributes.remove(name); }
public String getErrorPage(String errorCode) { return (String) errorPages.get(errorCode); }
/** Add Env-entry to this context */ public void addEnvEntry(String name, String type, String value, String description) { System.out.println("Add env-entry " + name + " " + type + " " + value + " " + description); if (name == null || type == null) throw new IllegalArgumentException(); envEntryTypes.put(name, type); if (value != null) envEntryValues.put(name, value); }
public String getTaglibLocation(String uri) { return (String) tagLibs.get(uri); }
public Container getContainer(String path) { return (Container) containers.get(path); }
/** Remove the servlet with a specific name */ public void removeServletByName(String servletName) throws TomcatException { servlets.remove(servletName); }
public Enumeration getContainers() { return containers.elements(); }
public String getInitParameter(String name) { return (String) initializationParameters.get(name); }
public Enumeration getEnvEntries() { return envEntryTypes.keys(); }
public String getEnvEntryValue(String name) { return (String) envEntryValues.get(name); }
public String getEnvEntryType(String name) { return (String) envEntryTypes.get(name); }
public Enumeration getContainerLocations() { return containers.keys(); }
public Enumeration getInitParameterNames() { return initializationParameters.keys(); }
public void removeContainer(Container ct) { containers.remove(ct.getPath()); }
public Enumeration getAttributeNames() { return attributes.keys(); }
public ServletWrapper getServletByName(String servletName) { return (ServletWrapper) servlets.get(servletName); }
public void setAttribute(String name, Object object) { attributes.put(name, object); }
public Enumeration getServletNames() { return servlets.keys(); }
/** Add a taglib declaration for this context */ public void addTaglib(String uri, String location) { // System.out.println("Add taglib " + uri + " " + location ); tagLibs.put(uri, location); }