Merge branch 'master' of github.com:p3k/helma

This commit is contained in:
Tobi Schäfer 2012-03-22 18:23:09 +01:00
commit e28ad52e80
27 changed files with 133 additions and 89 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
lib/servlet-api-2.5.jar Normal file

Binary file not shown.

Binary file not shown.

View file

@ -64,6 +64,9 @@ public final class Application implements Runnable {
// embedded db directory
File dbDir;
// false if hopobjects are case sensitive (default)
public boolean caseInsensitive;
// this application's node manager
protected NodeManager nmgr;
@ -224,6 +227,8 @@ public final class Application implements Runnable {
}
this.name = name;
this.caseInsensitive = "true".equalsIgnoreCase(server.getAppsProperties(name).getProperty("caseInsensitive"));
this.repositories = new ArrayList();
this.repositories.addAll(Arrays.asList(repositories));
@ -432,7 +437,7 @@ public final class Application implements Runnable {
nmgr.init(dbDir.getAbsoluteFile(), props);
// create the app cache node exposed as app.data
cachenode = new TransientNode("app");
cachenode = new TransientNode(Application.this, "app");
// create and init session manager
String sessionMgrImpl = props.getProperty("sessionManagerImpl",
@ -1384,6 +1389,19 @@ public final class Application implements Runnable {
}
return null;
}
/**
* Returns the correct property name which is either case sensitive or case insensitive
* @param propName the raw property name
* @return the correct property name
*/
public String correctPropertyName(String propName) {
if (propName == null)
return null;
if (caseInsensitive)
return propName.toLowerCase();
return propName;
}
/**
* Return the application's classloader

View file

@ -73,7 +73,7 @@ public class Session implements Serializable {
this.app = app;
this.uid = null;
this.userHandle = null;
cacheNode = new TransientNode("session");
cacheNode = new TransientNode(app, "session");
cacheLastModified = cacheNode.lastModified();
// HACK - decrease timestamp by 1 to notice modifications
// taking place immediately after object creation

View file

@ -22,11 +22,12 @@ import helma.framework.repository.FileRepository;
import helma.util.StringUtils;
import org.apache.xmlrpc.XmlRpcHandler;
import org.apache.commons.logging.Log;
import org.mortbay.jetty.handler.ContextHandler;
import org.mortbay.jetty.handler.ContextHandlerCollection;
import org.mortbay.jetty.handler.ResourceHandler;
import org.mortbay.jetty.servlet.ServletHandler;
import org.mortbay.jetty.servlet.ServletHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import java.io.*;
import java.util.*;
@ -304,7 +305,7 @@ public class ApplicationManager implements XmlRpcHandler {
Application app;
private ContextHandler staticContext = null;
private ContextHandler appContext = null;
private ServletContextHandler appContext = null;
String appName;
File appDir;
@ -489,28 +490,25 @@ public class ApplicationManager implements XmlRpcHandler {
getLogger().info("Serving static from " + staticContent.getPath());
getLogger().info("Mounting static at " + staticMountpoint);
ResourceHandler rhandler = new ResourceHandler();
rhandler.setResourceBase(staticContent.getPath());
rhandler.setWelcomeFiles(staticHome);
staticContext = context.addContext(staticMountpoint, "");
staticContext.setHandler(rhandler);
staticContext.start();
}
appContext = context.addContext(pathPattern, "");
ServletHandler handler = new ServletHandler();
appContext = new ServletContextHandler(context, pathPattern);
Class servletClass = servletClassName == null ?
EmbeddedServletClient.class : Class.forName(servletClassName);
ServletHolder holder = new ServletHolder(servletClass);
handler.addServletWithMapping(holder, "/*");
appContext.addServlet(holder, "/*");
holder.setInitParameter("application", appName);
// holder.setInitParameter("mountpoint", mountpoint);
if (cookieDomain != null) {
holder.setInitParameter("cookieDomain", cookieDomain);
@ -535,8 +533,6 @@ public class ApplicationManager implements XmlRpcHandler {
if (debug != null) {
holder.setInitParameter("debug", debug);
}
appContext.setHandler(handler);
if (protectedStaticDir != null) {
File protectedContent = getAbsoluteFile(protectedStaticDir);
@ -578,7 +574,7 @@ public class ApplicationManager implements XmlRpcHandler {
staticContext.destroy();
staticContext = null;
}
context.mapContexts();
context.mapContexts();
}
// unregister as XML-RPC handler

View file

@ -17,11 +17,11 @@
package helma.main;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.ajp.Ajp13SocketConnector;
import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.xml.XmlConfiguration;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.ajp.Ajp13SocketConnector;
import org.eclipse.jetty.server.bio.SocketConnector;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.xml.XmlConfiguration;
import java.net.URL;
import java.net.InetSocketAddress;
@ -31,7 +31,7 @@ import java.io.File;
public class JettyServer {
// the embedded web server
protected org.mortbay.jetty.Server http;
protected org.eclipse.jetty.server.Server http;
// the AJP13 Listener, used for connecting from external webserver to servlet via JK
protected Ajp13SocketConnector ajp13;
@ -47,7 +47,7 @@ public class JettyServer {
}
private JettyServer(URL url) throws IOException {
http = new org.mortbay.jetty.Server();
http = new org.eclipse.jetty.server.Server();
try {
XmlConfiguration config = new XmlConfiguration(url);
@ -64,7 +64,7 @@ public class JettyServer {
private JettyServer(InetSocketAddress webPort, InetSocketAddress ajpPort, Server server)
throws IOException {
http = new org.mortbay.jetty.Server();
http = new org.eclipse.jetty.server.Server();
http.setServer(http);
// start embedded web server if port is specified
@ -99,7 +99,7 @@ public class JettyServer {
openListeners();
}
public org.mortbay.jetty.Server getHttpServer() {
public org.eclipse.jetty.server.Server getHttpServer() {
return http;
}

View file

@ -78,7 +78,7 @@ public class Server implements Runnable {
// the XML-RPC server
protected WebServer xmlrpc;
Thread shutdownhook;
@ -512,18 +512,18 @@ public class Server implements Runnable {
// exception in xmlrpc server shutdown, ignore.
}
}
if (helmaLogging) {
Logging.shutdown();
}
server = null;
try {
Runtime.getRuntime().removeShutdownHook(shutdownhook);
// HACK: running the shutdownhook seems to be necessary in order
// to prevent it from blocking garbage collection of helma
// classes/classloaders. Since we already set server to null it
// to prevent it from blocking garbage collection of helma
// classes/classloaders. Since we already set server to null it
// won't do anything anyhow.
shutdownhook.start();
shutdownhook = null;
@ -598,6 +598,9 @@ public class Server implements Runnable {
logger.error("Error setting security manager", x);
}
// start applications
appManager.startAll();
// start embedded web server
if (jetty != null) {
try {
@ -607,9 +610,6 @@ public class Server implements Runnable {
}
}
// start applications
appManager.startAll();
while (Thread.currentThread() == mainThread) {
try {
Thread.sleep(3000L);

View file

@ -35,14 +35,17 @@ import java.util.ArrayList;
*/
public class Main {
public static final String[] jars = {
"helma.jar", "rhino.jar", "jetty.jar",
"jetty-util.jar", "jetty-ajp.jar",
"helma.jar", "rhino.jar",
"commons-logging.jar", "crimson.jar",
"xmlrpc.jar", "servlet.jar",
"mail.jar", "activation.jar",
"xmlrpc.jar", "mail.jar", "activation.jar",
"commons-fileupload.jar", "commons-codec.jar",
"commons-io.jar", "commons-net.jar",
"tagsoup.jar"
"commons-io.jar", "commons-net.jar",
"tagsoup.jar", "servlet-api-2.5.jar",
"jetty-ajp-7.6.2.v20120308.jar", "jetty-continuation-7.6.2.v20120308.jar",
"jetty-http-7.6.2.v20120308.jar", "jetty-io-7.6.2.v20120308.jar",
"jetty-security-7.6.2.v20120308.jar", "jetty-server-7.6.2.v20120308.jar",
"jetty-servlet-7.6.2.v20120308.jar", "jetty-util-7.6.2.v20120308.jar",
"jetty-xml-7.6.2.v20120308.jar",
};
private Class serverClass;
@ -122,8 +125,8 @@ public class Main {
}
/**
* Create a server-wide ClassLoader from our install directory.
* This will be used as parent ClassLoader for all application
* Create a server-wide ClassLoader from our install directory.
* This will be used as parent ClassLoader for all application
* ClassLoaders.
*
* @param installDir

View file

@ -17,6 +17,8 @@
package helma.objectmodel;
import helma.framework.IPathElement;
import helma.framework.core.Application;
import helma.framework.core.RequestEvaluator;
import helma.objectmodel.db.DbMapping;
import helma.objectmodel.db.Relation;
import helma.objectmodel.db.Node;
@ -44,6 +46,7 @@ public class TransientNode implements INode, Serializable {
protected long lastmodified;
protected String id;
protected String name;
private final Application app;
// is the main identity a named property or an anonymous node in a collection?
protected boolean anonymous = false;
@ -53,21 +56,27 @@ public class TransientNode implements INode, Serializable {
/**
* Creates a new TransientNode object.
*/
public TransientNode() {
public TransientNode(Application app) {
id = generateID();
name = id;
created = lastmodified = System.currentTimeMillis();
this.app=app;
}
private TransientNode() {
app=null;
}
/**
* Make a new TransientNode object with a given name
*/
public TransientNode(String n) {
public TransientNode(Application app, String n) {
id = generateID();
name = (n == null || n.length() == 0) ? id : n;
// HACK - decrease creation and last-modified timestamp by 1 so we notice
// modifications that take place immediately after object creation
created = lastmodified = System.currentTimeMillis() - 1;
this.app = app;
}
public static String generateID() {
@ -236,7 +245,7 @@ public class TransientNode implements INode, Serializable {
anon = true;
}
INode n = new TransientNode(nm);
INode n = new TransientNode(app, nm);
if (anon) {
addNode(n, where);
@ -367,7 +376,8 @@ public class TransientNode implements INode, Serializable {
}
private TransientProperty getProperty(String propname) {
TransientProperty prop = (propMap == null) ? null : (TransientProperty) propMap.get(propname);
TransientProperty prop = (propMap == null) ? null
: (TransientProperty) propMap.get(correctPropertyName(propname));
// check if we have to create a virtual node
if ((prop == null) && (dbmap != null)) {
@ -388,7 +398,7 @@ public class TransientNode implements INode, Serializable {
node.setDbMapping(rel.getVirtualMapping());
setNode(propname, node);
return (TransientProperty) propMap.get(propname);
return (TransientProperty) propMap.get(correctPropertyName(propname));
}
public IProperty get(String propname) {
@ -485,11 +495,12 @@ public class TransientNode implements INode, Serializable {
}
propname = propname.trim();
TransientProperty prop = (TransientProperty) propMap.get(propname);
String cpn = correctPropertyName(propname);
TransientProperty prop = (TransientProperty) propMap.get(cpn);
if (prop == null) {
prop = new TransientProperty(propname, this);
propMap.put(propname, prop);
propMap.put(cpn, prop);
}
return prop;
@ -552,7 +563,7 @@ public class TransientNode implements INode, Serializable {
public void unset(String propname) {
if (propMap != null && propname != null) {
propMap.remove(propname);
propMap.remove(correctPropertyName(propname));
lastmodified = System.currentTimeMillis();
}
}
@ -576,7 +587,7 @@ public class TransientNode implements INode, Serializable {
*/
public synchronized INode getCacheNode() {
if (cacheNode == null) {
cacheNode = new TransientNode();
cacheNode = new TransientNode(app);
}
return cacheNode;
@ -588,4 +599,8 @@ public class TransientNode implements INode, Serializable {
public synchronized void clearCacheNode() {
cacheNode = null;
}
private String correctPropertyName(String propname) {
return app.correctPropertyName(propname);
}
}

View file

@ -315,6 +315,7 @@ public final class DbMapping {
// ignore internal properties (starting with "_") and sub-options (containing a ".")
if (!propName.startsWith("_") && propName.indexOf(".") < 0) {
Object propValue = entry.getValue();
propName = app.correctPropertyName(propName);
// check if a relation for this propery already exists. If so, reuse it
Relation rel = (Relation) prop2db.get(propName);
@ -637,7 +638,7 @@ public final class DbMapping {
}
private String _propertyToColumnName(final String propName) {
Relation rel = (Relation) prop2db.get(propName);
Relation rel = (Relation) prop2db.get(app.correctPropertyName(propName));
if ((rel == null) && (parentMapping != null)) {
return parentMapping._propertyToColumnName(propName);
@ -683,7 +684,7 @@ public final class DbMapping {
}
private Relation _propertyToRelation(String propName) {
Relation rel = (Relation) prop2db.get(propName);
Relation rel = (Relation) prop2db.get(app.correctPropertyName(propName));
if ((rel == null) && (parentMapping != null)) {
return parentMapping._propertyToRelation(propName);
@ -866,7 +867,7 @@ public final class DbMapping {
return null;
}
Relation rel = (Relation) prop2db.get(propname);
Relation rel = (Relation) prop2db.get(app.correctPropertyName(propname));
if ((rel == null) && (parentMapping != null)) {
rel = parentMapping.getExactPropertyRelation(propname);

View file

@ -1602,7 +1602,8 @@ public final class Node implements INode {
null : dbmap.getExactPropertyRelation(propname);
// 1) check if the property is contained in the propMap
Property prop = propMap == null ? null : (Property) propMap.get(propname);
Property prop = propMap == null ? null :
(Property) propMap.get(correctPropertyName(propname));
if (prop != null) {
if (rel != null) {
@ -1631,7 +1632,7 @@ public final class Node implements INode {
n.setDbMapping(rel.getVirtualMapping());
n.setParent(this);
setNode(propname, n);
return (Property) propMap.get(propname);
return (Property) propMap.get(correctPropertyName(propname));
}
// 2) check if this is a create-on-demand node property
@ -1798,14 +1799,15 @@ public final class Node implements INode {
}
propname = propname.trim();
Property prop = (Property) propMap.get(propname);
String p2 = correctPropertyName(propname);
Property prop = (Property) propMap.get(p2);
if (prop != null) {
prop.setValue(value, type);
} else {
prop = new Property(propname, this);
prop.setValue(value, type);
propMap.put(propname, prop);
propMap.put(p2, prop);
}
lastmodified = System.currentTimeMillis();
@ -1833,7 +1835,8 @@ public final class Node implements INode {
}
propname = propname.trim();
Property prop = (Property) propMap.get(propname);
String p2 = correctPropertyName(propname);
Property prop = (Property) propMap.get(p2);
String oldvalue = null;
if (prop != null) {
@ -1848,7 +1851,7 @@ public final class Node implements INode {
} else {
prop = new Property(propname, this);
prop.setStringValue(value);
propMap.put(propname, prop);
propMap.put(p2, prop);
}
if (dbmap != null) {
@ -1944,14 +1947,15 @@ public final class Node implements INode {
}
propname = propname.trim();
Property prop = (Property) propMap.get(propname);
String p2 = correctPropertyName(propname);
Property prop = (Property) propMap.get(p2);
if (prop != null) {
prop.setIntegerValue(value);
} else {
prop = new Property(propname, this);
prop.setIntegerValue(value);
propMap.put(propname, prop);
propMap.put(p2, prop);
}
notifyPropertyChange(propname);
@ -1981,14 +1985,15 @@ public final class Node implements INode {
}
propname = propname.trim();
Property prop = (Property) propMap.get(propname);
String p2 = correctPropertyName(propname);
Property prop = (Property) propMap.get(p2);
if (prop != null) {
prop.setFloatValue(value);
} else {
prop = new Property(propname, this);
prop.setFloatValue(value);
propMap.put(propname, prop);
propMap.put(p2, prop);
}
notifyPropertyChange(propname);
@ -2018,14 +2023,15 @@ public final class Node implements INode {
}
propname = propname.trim();
Property prop = (Property) propMap.get(propname);
String p2 = correctPropertyName(propname);
Property prop = (Property) propMap.get(p2);
if (prop != null) {
prop.setBooleanValue(value);
} else {
prop = new Property(propname, this);
prop.setBooleanValue(value);
propMap.put(propname, prop);
propMap.put(p2, prop);
}
notifyPropertyChange(propname);
@ -2055,14 +2061,15 @@ public final class Node implements INode {
}
propname = propname.trim();
Property prop = (Property) propMap.get(propname);
String p2 = correctPropertyName(propname);
Property prop = (Property) propMap.get(p2);
if (prop != null) {
prop.setDateValue(value);
} else {
prop = new Property(propname, this);
prop.setDateValue(value);
propMap.put(propname, prop);
propMap.put(p2, prop);
}
notifyPropertyChange(propname);
@ -2092,14 +2099,15 @@ public final class Node implements INode {
}
propname = propname.trim();
Property prop = (Property) propMap.get(propname);
String p2 = correctPropertyName(propname);
Property prop = (Property) propMap.get(p2);
if (prop != null) {
prop.setJavaObjectValue(value);
} else {
prop = new Property(propname, this);
prop.setJavaObjectValue(value);
propMap.put(propname, prop);
propMap.put(p2, prop);
}
notifyPropertyChange(propname);
@ -2177,6 +2185,7 @@ public final class Node implements INode {
}
propname = propname.trim();
String p2 = correctPropertyName(propname);
if (rel == null && dbmap != null) {
// widen relation to non-exact (collection) mapping
rel = dbmap.getPropertyRelation(propname);
@ -2191,7 +2200,7 @@ public final class Node implements INode {
}
}
Property prop = (propMap == null) ? null : (Property) propMap.get(propname);
Property prop = (propMap == null) ? null : (Property) propMap.get(p2);
if (prop != null) {
if ((prop.getType() == IProperty.NODE) &&
@ -2223,7 +2232,7 @@ public final class Node implements INode {
propMap = new Hashtable();
}
propMap.put(propname, prop);
propMap.put(p2, prop);
if (state == CLEAN && isPersistable) {
markAs(MODIFIED);
@ -2273,9 +2282,9 @@ public final class Node implements INode {
if (propMap != null) {
if (relational) {
p = (Property) propMap.get(propname);
p = (Property) propMap.get(correctPropertyName(propname));
} else {
p = (Property) propMap.remove(propname);
p = (Property) propMap.remove(correctPropertyName(propname));
}
}
@ -2477,7 +2486,7 @@ public final class Node implements INode {
*/
public synchronized INode getCacheNode() {
if (cacheNode == null) {
cacheNode = new TransientNode();
cacheNode = new TransientNode(this.getApp());
}
return cacheNode;
@ -2558,4 +2567,8 @@ public final class Node implements INode {
private Application getApp() {
return nmgr.nmgr.app;
}
private String correctPropertyName(String propname) {
return getApp().correctPropertyName(propname);
}
}

View file

@ -144,7 +144,7 @@ public final class XmlDatabaseReader extends DefaultHandler implements XmlConsta
currentNode.setPropMap(propMap);
}
propMap.put(propName, prop);
propMap.put(correctPropertyName(propName), prop);
}
} else {
// a primitive property
@ -170,6 +170,10 @@ public final class XmlDatabaseReader extends DefaultHandler implements XmlConsta
}
}
private String correctPropertyName(String propName) {
return this.currentNode.getDbMapping().getApplication().correctPropertyName(propName);
}
/**
*
*
@ -233,7 +237,7 @@ public final class XmlDatabaseReader extends DefaultHandler implements XmlConsta
currentNode.setPropMap(propMap);
}
propMap.put(elementName, prop);
propMap.put(correctPropertyName(elementName), prop);
elementName = null;
elementType = null;
charValue = null;

View file

@ -1133,7 +1133,7 @@ public class HopObject extends ScriptableObject implements Wrapper, PropertyReco
if (node == null || node.getState() == Node.INVALID) {
// We probably have a deleted node.
// Replace with empty transient node to avoid throwing an exception.
node = new TransientNode();
node = new TransientNode(core.app);
}
}
return node;

View file

@ -66,15 +66,9 @@ public class Logging extends LogFactory {
// normalize log name
logname = logname.replaceAll("[^\\w\\d\\.]", "");
if ("console".equals(logdir)) {
if (logname.startsWith("org.mortbay."))
return getConsoleLog().getSedatedLog();
else
return getConsoleLog();
return getConsoleLog();
} else {
if (logname.startsWith("org.mortbay."))
return getFileLog(logname).getSedatedLog();
else
return getFileLog(logname);
return getFileLog(logname);
}
}