Method from org.apache.tomcat.util.http.mapper.Mapper Detail: |
public void addContext(String hostName,
String path,
Object context,
String[] welcomeResources,
Context resources) {
Host[] hosts = this.hosts;
int pos = find(hosts, hostName);
if( pos < 0 ) {
addHost(hostName, new String[0], "");
hosts = this.hosts;
pos = find(hosts, hostName);
}
if (pos < 0) {
logger.error("No host found: " + hostName);
}
Host host = hosts[pos];
if (host.name.equals(hostName)) {
int slashCount = slashCount(path);
synchronized (host) {
Context[] contexts = host.contextList.contexts;
// Update nesting
if (slashCount > host.contextList.nesting) {
host.contextList.nesting = slashCount;
}
Context[] newContexts = new Context[contexts.length + 1];
Context newContext = new Context();
newContext.name = path;
newContext.object = context;
newContext.welcomeResources = welcomeResources;
newContext.resources = resources;
if (insertMap(contexts, newContexts, newContext)) {
host.contextList.contexts = newContexts;
}
}
}
}
Add a new Context to an existing Host. |
public synchronized void addHost(String name,
String[] aliases,
Object host) {
Host[] newHosts = new Host[hosts.length + 1];
Host newHost = new Host();
ContextList contextList = new ContextList();
newHost.name = name;
newHost.contextList = contextList;
newHost.object = host;
if (insertMap(hosts, newHosts, newHost)) {
hosts = newHosts;
}
for (int i = 0; i < aliases.length; i++) {
newHosts = new Host[hosts.length + 1];
newHost = new Host();
newHost.name = aliases[i];
newHost.contextList = contextList;
newHost.object = host;
if (insertMap(hosts, newHosts, newHost)) {
hosts = newHosts;
}
}
}
Add a new host to the mapper. |
public synchronized void addHostAlias(String name,
String alias) {
int pos = find(hosts, name);
if (pos < 0) {
// Should not be adding an alias for a host that doesn't exist but
// just in case...
return;
}
Host realHost = hosts[pos];
Host[] newHosts = new Host[hosts.length + 1];
Host newHost = new Host();
newHost.name = alias;
newHost.contextList = realHost.contextList;
newHost.object = realHost;
if (insertMap(hosts, newHosts, newHost)) {
hosts = newHosts;
}
}
Add an alias to an existing host. |
public void addWrapper(String path,
Object wrapper) {
addWrapper(context, path, wrapper);
}
Add a wrapper to the context associated with this wrapper. |
public void addWrapper(String path,
Object wrapper,
boolean jspWildCard) {
addWrapper(context, path, wrapper, jspWildCard);
}
|
protected void addWrapper(Context context,
String path,
Object wrapper) {
addWrapper(context, path, wrapper, false);
}
|
public void addWrapper(String hostName,
String contextPath,
String path,
Object wrapper) {
addWrapper(hostName, contextPath, path, wrapper, false);
}
Add a new Wrapper to an existing Context. |
protected void addWrapper(Context context,
String path,
Object wrapper,
boolean jspWildCard) {
synchronized (context) {
Wrapper newWrapper = new Wrapper();
newWrapper.object = wrapper;
newWrapper.jspWildCard = jspWildCard;
if (path.endsWith("/*")) {
// Wildcard wrapper
newWrapper.name = path.substring(0, path.length() - 2);
Wrapper[] oldWrappers = context.wildcardWrappers;
Wrapper[] newWrappers =
new Wrapper[oldWrappers.length + 1];
if (insertMap(oldWrappers, newWrappers, newWrapper)) {
context.wildcardWrappers = newWrappers;
int slashCount = slashCount(newWrapper.name);
if (slashCount > context.nesting) {
context.nesting = slashCount;
}
}
} else if (path.startsWith("*.")) {
// Extension wrapper
newWrapper.name = path.substring(2);
Wrapper[] oldWrappers = context.extensionWrappers;
Wrapper[] newWrappers =
new Wrapper[oldWrappers.length + 1];
if (insertMap(oldWrappers, newWrappers, newWrapper)) {
context.extensionWrappers = newWrappers;
}
} else if (path.equals("/")) {
// Default wrapper
newWrapper.name = "";
context.defaultWrapper = newWrapper;
} else {
// Exact wrapper
newWrapper.name = path;
Wrapper[] oldWrappers = context.exactWrappers;
Wrapper[] newWrappers =
new Wrapper[oldWrappers.length + 1];
if (insertMap(oldWrappers, newWrappers, newWrapper)) {
context.exactWrappers = newWrappers;
}
}
}
}
Adds a wrapper to the given context. |
public void addWrapper(String hostName,
String contextPath,
String path,
Object wrapper,
boolean jspWildCard) {
Host[] hosts = this.hosts;
int pos = find(hosts, hostName);
if (pos < 0) {
return;
}
Host host = hosts[pos];
if (host.name.equals(hostName)) {
Context[] contexts = host.contextList.contexts;
int pos2 = find(contexts, contextPath);
if( pos2< 0 ) {
logger.error("No context found: " + contextPath );
return;
}
Context context = contexts[pos2];
if (context.name.equals(contextPath)) {
addWrapper(context, path, wrapper, jspWildCard);
}
}
}
|
public String[] getContextNames() {
List list=new ArrayList();
for( int i=0; i< hosts.length; i++ ) {
for( int j=0; j< hosts[i].contextList.contexts.length; j++ ) {
String cname=hosts[i].contextList.contexts[j].name;
list.add("//" + hosts[i].name +
(cname.startsWith("/") ? cname : "/"));
}
}
String res[] = new String[list.size()];
return (String[])list.toArray(res);
}
Return all contexts, in //HOST/PATH form |
public String getDefaultHostName() {
return defaultHostName;
}
|
public String[] getHosts() {
String hostN[] = new String[hosts.length];
for( int i = 0; i < hosts.length; i++ ) {
hostN[i] = hosts[i].name;
}
return hostN;
}
|
public String[] getWrapperNames(String host,
String context) {
List list=new ArrayList();
if( host==null ) host="";
if( context==null ) context="";
for( int i=0; i< hosts.length; i++ ) {
if( ! host.equals( hosts[i].name ))
continue;
for( int j=0; j< hosts[i].contextList.contexts.length; j++ ) {
if( ! context.equals( hosts[i].contextList.contexts[j].name))
continue;
// found the context
Context ctx=hosts[i].contextList.contexts[j];
list.add( ctx.defaultWrapper.path);
for( int k=0; k< ctx.exactWrappers.length; k++ ) {
list.add( ctx.exactWrappers[k].path);
}
for( int k=0; k< ctx.wildcardWrappers.length; k++ ) {
list.add( ctx.wildcardWrappers[k].path + "*");
}
for( int k=0; k< ctx.extensionWrappers.length; k++ ) {
list.add( "*." + ctx.extensionWrappers[k].path);
}
}
}
String res[]=new String[list.size()];
return (String[])list.toArray(res);
}
|
public String getWrappersString(String host,
String context) {
String names[]=getWrapperNames(host, context);
StringBuffer sb=new StringBuffer();
for( int i=0; i< names.length; i++ ) {
sb.append(names[i]).append(":");
}
return sb.toString();
}
|
public void map(MessageBytes uri,
MappingData mappingData) throws Exception {
uri.toChars();
CharChunk uricc = uri.getCharChunk();
uricc.setLimit(-1);
internalMapWrapper(context, uricc, mappingData);
}
Map the specified URI relative to the context,
mutating the given mapping data. |
public void map(MessageBytes host,
MessageBytes uri,
MappingData mappingData) throws Exception {
if (host.isNull()) {
host.getCharChunk().append(defaultHostName);
}
host.toChars();
uri.toChars();
internalMap(host.getCharChunk(), uri.getCharChunk(), mappingData);
}
Map the specified host name and URI, mutating the given mapping data. |
public void removeContext(String hostName,
String path) {
Host[] hosts = this.hosts;
int pos = find(hosts, hostName);
if (pos < 0) {
return;
}
Host host = hosts[pos];
if (host.name.equals(hostName)) {
synchronized (host) {
Context[] contexts = host.contextList.contexts;
if( contexts.length == 0 ){
return;
}
Context[] newContexts = new Context[contexts.length - 1];
if (removeMap(contexts, newContexts, path)) {
host.contextList.contexts = newContexts;
// Recalculate nesting
host.contextList.nesting = 0;
for (int i = 0; i < newContexts.length; i++) {
int slashCount = slashCount(newContexts[i].name);
if (slashCount > host.contextList.nesting) {
host.contextList.nesting = slashCount;
}
}
}
}
}
}
Remove a context from an existing host. |
public synchronized void removeHost(String name) {
// Find and remove the old host
int pos = find(hosts, name);
if (pos < 0) {
return;
}
Object host = hosts[pos].object;
Host[] newHosts = new Host[hosts.length - 1];
if (removeMap(hosts, newHosts, name)) {
hosts = newHosts;
}
// Remove all aliases (they will map to the same host object)
for (int i = 0; i < newHosts.length; i++) {
if (newHosts[i].object == host) {
Host[] newHosts2 = new Host[hosts.length - 1];
if (removeMap(hosts, newHosts2, newHosts[i].name)) {
hosts = newHosts2;
}
}
}
}
Remove a host from the mapper. |
public synchronized void removeHostAlias(String alias) {
// Find and remove the alias
int pos = find(hosts, alias);
if (pos < 0) {
return;
}
Host[] newHosts = new Host[hosts.length - 1];
if (removeMap(hosts, newHosts, alias)) {
hosts = newHosts;
}
}
|
public void removeWrapper(String path) {
removeWrapper(context, path);
}
Remove a wrapper from the context associated with this wrapper. |
protected void removeWrapper(Context context,
String path) {
synchronized (context) {
if (path.endsWith("/*")) {
// Wildcard wrapper
String name = path.substring(0, path.length() - 2);
Wrapper[] oldWrappers = context.wildcardWrappers;
Wrapper[] newWrappers =
new Wrapper[oldWrappers.length - 1];
if (removeMap(oldWrappers, newWrappers, name)) {
// Recalculate nesting
context.nesting = 0;
for (int i = 0; i < newWrappers.length; i++) {
int slashCount = slashCount(newWrappers[i].name);
if (slashCount > context.nesting) {
context.nesting = slashCount;
}
}
context.wildcardWrappers = newWrappers;
}
} else if (path.startsWith("*.")) {
// Extension wrapper
String name = path.substring(2);
Wrapper[] oldWrappers = context.extensionWrappers;
Wrapper[] newWrappers =
new Wrapper[oldWrappers.length - 1];
if (removeMap(oldWrappers, newWrappers, name)) {
context.extensionWrappers = newWrappers;
}
} else if (path.equals("/")) {
// Default wrapper
context.defaultWrapper = null;
} else {
// Exact wrapper
String name = path;
Wrapper[] oldWrappers = context.exactWrappers;
Wrapper[] newWrappers =
new Wrapper[oldWrappers.length - 1];
if (removeMap(oldWrappers, newWrappers, name)) {
context.exactWrappers = newWrappers;
}
}
}
}
|
public void removeWrapper(String hostName,
String contextPath,
String path) {
Host[] hosts = this.hosts;
int pos = find(hosts, hostName);
if (pos < 0) {
return;
}
Host host = hosts[pos];
if (host.name.equals(hostName)) {
Context[] contexts = host.contextList.contexts;
int pos2 = find(contexts, contextPath);
if (pos2 < 0) {
return;
}
Context context = contexts[pos2];
if (context.name.equals(contextPath)) {
removeWrapper(context, path);
}
}
}
Remove a wrapper from an existing context. |
public void setContext(String path,
String[] welcomeResources,
Context resources) {
context.name = path;
context.welcomeResources = welcomeResources;
context.resources = resources;
}
Set context, used for wrapper mapping (request dispatcher). |
public void setDefaultHostName(String defaultHostName) {
this.defaultHostName = defaultHostName;
}
|