Initial checkin
This commit is contained in:
parent
9edd9cf670
commit
15cdc42eab
1 changed files with 102 additions and 0 deletions
102
src/helma/servlet/StandaloneServletClient.java
Normal file
102
src/helma/servlet/StandaloneServletClient.java
Normal file
|
@ -0,0 +1,102 @@
|
|||
// StandaloneServletClient.java
|
||||
// Copyright (c) Hannes Wallnöfer, 2001
|
||||
|
||||
package helma.servlet;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import helma.framework.*;
|
||||
import helma.framework.core.Application;
|
||||
import helma.objectmodel.*;
|
||||
import helma.util.*;
|
||||
|
||||
/**
|
||||
* This is a standalone Hop servlet client, running a Hop application by itself.
|
||||
*/
|
||||
|
||||
public class StandaloneServletClient extends AbstractServletClient {
|
||||
|
||||
private IRemoteApp app = null;
|
||||
private String appName;
|
||||
private String serverProps;
|
||||
|
||||
public void init (ServletConfig init) {
|
||||
|
||||
appName = init.getInitParameter ("application");
|
||||
serverProps = init.getInitParameter ("serverprops");
|
||||
|
||||
super.init (init);
|
||||
}
|
||||
|
||||
IRemoteApp getApp (String appID) throws Exception {
|
||||
if (app != null)
|
||||
return app;
|
||||
|
||||
File propfile = new File (serverProps);
|
||||
File hopHome = new File (propfile.getParent());
|
||||
SystemProperties sysProps = new SystemProperties (propfile.getAbsolutePath());
|
||||
app = new Application (appName, sysProps, hopHome);
|
||||
return app;
|
||||
}
|
||||
|
||||
void invalidateApp (String appID) {
|
||||
// app = null;
|
||||
}
|
||||
|
||||
String getAppID (String path) {
|
||||
return appName;
|
||||
}
|
||||
|
||||
String getRequestPath (String path) {
|
||||
// get request path
|
||||
if (path != null)
|
||||
return trim (path);
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
String trim (String str) {
|
||||
char[] val = str.toCharArray ();
|
||||
int len = val.length;
|
||||
int st = 0;
|
||||
|
||||
while ((st < len) && (val[st] <= ' ' || val[st] == '/'))
|
||||
st++;
|
||||
|
||||
while ((st < len) && (val[len - 1] <= ' ' || val[len - 1] == '/'))
|
||||
len--;
|
||||
|
||||
return ((st > 0) || (len < val.length)) ? new String (val, st, len-st) : str;
|
||||
}
|
||||
|
||||
// for testing
|
||||
public static void main (String args[]) {
|
||||
AbstractServletClient client = new ServletClient ();
|
||||
String path = "///appname/do/it/for/me///";
|
||||
System.out.println (client.getAppID (path));
|
||||
System.out.println (client.getRequestPath (path));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Add table
Reference in a new issue