You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by df...@apache.org on 2004/05/24 15:52:45 UTC
cvs commit: jakarta-slide/proposals/projector/src/java/org/apache/slide/projector AbstractContext.java
dflorey 2004/05/24 06:52:45
Modified: proposals/projector/src/java/org/apache/slide/projector/engine
SystemContext.java HttpContext.java Scheduler.java
Process.java ProcessorManager.java Cache.java
ProcessServlet.java
proposals/projector/src/java/org/apache/slide/projector/processor/form
ControlComposer.java ClearForm.java Test.java
proposals/projector/src/java/org/apache/slide/projector/i18n
MessageManager.java
proposals/projector/src/java/org/apache/slide/projector
AbstractContext.java
Added: proposals/projector/src/java/org/apache/slide/projector/application
ApplicationListener.java ApplicationManager.java
Application.java
proposals/projector/src/java/org/apache/slide/projector/store
RequestParameterStore.java FormStore.java
RequestHeaderStore.java SessionStore.java
RequestAttributeStore.java CookieStore.java
RepositoryStore.java AbstractStore.java
ProcessStore.java
Removed: proposals/projector/src/java/org/apache/slide/projector/engine
AbstractStore.java ApplicationManager.java
ApplicationListener.java Application.java
Log:
Moved store impls to store package
Revision Changes Path
1.4 +3 -1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/SystemContext.java
Index: SystemContext.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/SystemContext.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SystemContext.java 15 May 2004 09:37:20 -0000 1.3
+++ SystemContext.java 24 May 2004 13:52:43 -0000 1.4
@@ -7,13 +7,15 @@
import org.apache.slide.projector.Store;
import org.apache.slide.projector.AbstractContext;
import org.apache.slide.projector.URI;
+import org.apache.slide.projector.store.ProcessStore;
+import org.apache.slide.projector.store.RepositoryStore;
public class SystemContext extends AbstractContext {
private final static String BOOKMARK = "_bookmark_";
private final static String FORM_MAP = "_form_map_";
- private RepositoryStore repositoryStore = new RepositoryStore();
private Cache contextStore = new Cache();
+ private RepositoryStore repositoryStore = new RepositoryStore(this);
private ProcessStore transientProcessStore = new ProcessStore(Cache.getInstance());
private ProcessStore persistentProcessStore = new ProcessStore(repositoryStore);
1.4 +2 -181 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/HttpContext.java
Index: HttpContext.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/HttpContext.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- HttpContext.java 10 May 2004 16:54:24 -0000 1.3
+++ HttpContext.java 24 May 2004 13:52:43 -0000 1.4
@@ -3,13 +3,11 @@
import org.apache.commons.httpclient.Credentials;
import org.apache.slide.projector.Constants;
import org.apache.slide.projector.Store;
-import org.apache.slide.projector.resource.MapResource;
import org.apache.slide.projector.resource.StreamableResource;
+import org.apache.slide.projector.store.*;
-import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
public class HttpContext extends SystemContext {
private final static String CREDENTIALS = "credentials";
@@ -26,7 +24,7 @@
public HttpContext(HttpServletRequest request, HttpServletResponse response) {
this.contextPath = request.getContextPath()+Constants.PROCESS_SERVLET_PATH;
sessionStore = new SessionStore(request);
- formStore = new FormStore(sessionStore);
+ formStore = new FormStore(this, sessionStore);
requestAttributeStore = new RequestAttributeStore(request);
requestParameterStore = new RequestParameterStore(request);
requestHeaderStore = new RequestHeaderStore(request);
@@ -82,182 +80,5 @@
public StreamableResource getPresentableResource() {
return resource;
- }
-
- class SessionStore extends AbstractStore {
- protected HttpServletRequest request;
-
- public SessionStore(HttpServletRequest request) {
- this.request = request;
- }
-
- public void put(String key, Object value) {
- request.getSession().setAttribute(key, value);
- }
-
- public Object get(String key) {
- return request.getSession().getAttribute(key);
- }
-
- public void dispose(String key) {
- request.getSession().removeAttribute(key);
- }
- }
-
- class CookieStore implements Store {
- protected HttpServletRequest request;
- protected HttpServletResponse response;
-
- public CookieStore(HttpServletRequest request, HttpServletResponse response) {
- this.request = request;
- this.response = response;
- }
-
- public void put(String key, Object value, long timeout) {
- Cookie cookie = null;
- if ( value instanceof Cookie ) {
- cookie = (Cookie)value;
- }
- if ( value instanceof String ) {
- cookie = new Cookie(key, (String)value);
- }
- if ( cookie != null ) {
- cookie.setMaxAge((int) (timeout/1000));
- response.addCookie(cookie);
- }
- }
-
- public void put(String key, Object value) {
- Cookie cookie = null;
- if ( value instanceof Cookie ) {
- cookie = (Cookie)value;
- }
- if ( value instanceof String ) {
- cookie = new Cookie(key, (String)value);
- }
- if ( cookie != null ) {
- response.addCookie(cookie);
- }
- }
-
- public Object get(String key) {
- Cookie[] cookies = request.getCookies();
- for ( int i = 0; i < cookies.length; i++ ) {
- if ( cookies[i].getName().equals(key) ) {
- return cookies[i].getValue();
- }
- }
- return null;
- }
-
- public void dispose(String key) {
- request.removeAttribute(key);
- }
- }
-
- class RequestParameterStore implements Store {
- protected HttpServletRequest request;
-
- public RequestParameterStore(HttpServletRequest request) {
- this.request = request;
- }
-
- public void put(String key, Object value, long timeout) throws IOException {
- throw new IOException("Put operation is not supported by request-parameter store!");
- }
-
- public void put(String key, Object value) throws IOException {
- throw new IOException("Put operation is not supported by request-parameter store!");
- }
-
- public Object get(String key) {
- return request.getParameterValues(key);
- }
-
- public void dispose(String key) throws IOException {
- throw new IOException("Dispose operation is not supported by request-parameter store!");
- }
- }
-
- class RequestHeaderStore implements Store {
- protected HttpServletRequest request;
-
- public RequestHeaderStore(HttpServletRequest request) {
- this.request = request;
- }
-
- public void put(String key, Object value, long timeout) throws IOException {
- throw new IOException("Put operation is not supported by request-header store!");
- }
-
- public void put(String key, Object value) throws IOException {
- throw new IOException("Put operation is not supported by request-header store!");
- }
-
- public Object get(String key) {
- return request.getHeader(key);
- }
-
- public void dispose(String key) throws IOException {
- throw new IOException("Dispose operation is not supported by request-header store!");
- }
- }
-
- class RequestAttributeStore extends AbstractStore {
- protected HttpServletRequest request;
-
- public RequestAttributeStore(HttpServletRequest request) {
- this.request = request;
- }
-
- public void put(String key, Object value) {
- request.setAttribute(key, value);
- }
-
- public Object get(String key) {
- return request.getAttribute(key);
- }
-
- public void dispose(String key) {
- request.removeAttribute(key);
- }
- }
-
- public class FormStore extends AbstractStore {
- private Store store;
-
- public FormStore(Store store) {
- this.store = store;
- }
-
- public void put(String key, Object value) throws IOException {
- MapResource domain = getDomain();
- domain.getMap().put(key, value);
- }
-
- public Object get(String key) throws IOException {
- return getDomain().getMap().get(key);
- }
-
- public void dispose(String key) throws IOException {
- getDomain().getMap().remove(key);
- }
-
- public void clear() throws IOException {
- String domain = getProcess().toString();
- store.dispose(domain);
- }
-
- public MapResource getDomain() throws IOException {
- String domain = getProcess().toString();
- MapResource mapResource = (MapResource)store.get(domain);
- if ( mapResource == null ) {
- mapResource = new MapResource();
- store.put(domain, mapResource);
- return mapResource;
- } else {
- return mapResource;
- }
- }
}
}
1.4 +1 -0 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/Scheduler.java
Index: Scheduler.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/Scheduler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Scheduler.java 24 May 2004 12:33:41 -0000 1.3
+++ Scheduler.java 24 May 2004 13:52:43 -0000 1.4
@@ -3,6 +3,7 @@
import de.zeigermann.xml.XMLStringWriter;
import de.zeigermann.xml.XMLWriter;
import org.apache.slide.projector.*;
+import org.apache.slide.projector.application.*;
import org.apache.slide.projector.connector.ConnectorFactory;
import org.apache.slide.projector.connector.Subscriber;
import org.apache.slide.projector.expression.Expression;
1.6 +1 -0 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/Process.java
Index: Process.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/Process.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Process.java 24 May 2004 12:33:41 -0000 1.5
+++ Process.java 24 May 2004 13:52:43 -0000 1.6
@@ -9,6 +9,7 @@
import org.apache.slide.projector.resource.DocumentResource;
import org.apache.slide.projector.resource.StreamableResource;
import org.apache.slide.projector.resource.StringResource;
+import org.apache.slide.projector.store.*;
import org.apache.slide.projector.util.StoreHelper;
import org.jdom.Document;
import org.jdom.Element;
1.11 +1 -0 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/ProcessorManager.java
Index: ProcessorManager.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/ProcessorManager.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ProcessorManager.java 24 May 2004 13:33:13 -0000 1.10
+++ ProcessorManager.java 24 May 2004 13:52:43 -0000 1.11
@@ -4,6 +4,7 @@
import de.zeigermann.xml.simpleImporter.SimpleImporter;
import de.zeigermann.xml.simpleImporter.SimplePath;
import org.apache.slide.projector.*;
+import org.apache.slide.projector.application.*;
import org.apache.slide.projector.connector.ConnectorFactory;
import org.apache.slide.projector.connector.Subscriber;
import org.apache.slide.projector.descriptor.ParameterDescriptor;
1.3 +2 -0 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/Cache.java
Index: Cache.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/Cache.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Cache.java 3 May 2004 14:28:36 -0000 1.2
+++ Cache.java 24 May 2004 13:52:43 -0000 1.3
@@ -4,6 +4,8 @@
import java.util.HashMap;
import java.util.Map;
+import org.apache.slide.projector.store.*;
+
public class Cache extends AbstractStore {
private static Cache cache = new Cache();
1.6 +1 -0 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/ProcessServlet.java
Index: ProcessServlet.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/ProcessServlet.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ProcessServlet.java 17 May 2004 15:22:03 -0000 1.5
+++ ProcessServlet.java 24 May 2004 13:52:43 -0000 1.6
@@ -1,6 +1,7 @@
package org.apache.slide.projector.engine;
import org.apache.slide.projector.*;
+import org.apache.slide.projector.application.*;
import org.apache.slide.projector.descriptor.ParameterDescriptor;
import org.apache.slide.projector.descriptor.StringValueDescriptor;
import org.apache.slide.projector.processor.ExceptionRenderer;
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/application/ApplicationListener.java
Index: ApplicationListener.java
===================================================================
package org.apache.slide.projector.application;
import org.apache.slide.projector.URI;
public interface ApplicationListener {
public void install(String type, URI application, URI configuration);
public void uninstall(String type, URI application, URI configuration);
public void update(String type, URI application, URI configuration);
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/application/ApplicationManager.java
Index: ApplicationManager.java
===================================================================
package org.apache.slide.projector.application;
import de.zeigermann.xml.simpleImporter.DefaultSimpleImportHandler;
import de.zeigermann.xml.simpleImporter.SimpleImporter;
import de.zeigermann.xml.simpleImporter.SimplePath;
import org.apache.slide.projector.*;
import org.apache.slide.projector.connector.ConnectorFactory;
import org.apache.slide.projector.connector.Subscriber;
import org.apache.slide.projector.descriptor.AbstractValueDescriptorFactory;
import org.apache.slide.projector.descriptor.ValueDescriptorManager;
import org.apache.slide.projector.engine.ProcessorManager;
import org.apache.slide.projector.engine.ProjectorClassLoader;
import org.apache.slide.projector.engine.SystemContext;
import org.apache.slide.projector.i18n.MessageManager;
import org.apache.slide.projector.resource.ArrayResource;
import org.apache.slide.projector.resource.StreamableResource;
import org.apache.slide.projector.resource.URIResource;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
public class ApplicationManager {
private final static Logger logger = Logger.getLogger(ApplicationManager.class.getName());
private final static String APPLICATION_CONFIG = "application.xml";
private final static Context context = new SystemContext();
private static ApplicationManager applicationManager;
private List applicationListeners = new ArrayList();
private Map installedApplications = new HashMap(); // URI -> Application
private ProjectorClassLoader factoryClassLoader = new ProjectorClassLoader(this.getClass().getClassLoader(), new URIResource(Constants.CLASSES_DIR));
private ApplicationManager() {
logger.log(Level.INFO, "Starting projector...");
ConnectorFactory.getConnector().subscribe("Update/newmember", new URIResource(Constants.APPLICATIONS_DIR), 1, Constants.SUBSCRIPTION_LIFETIME, Constants.NOTIFICATION_DELAY,
new Subscriber() {
public void notify(URI uri, Map information) {
logger.log(Level.INFO, "Package manager received add event");
applicationManager.installApplications();
}
}, context.getCredentials());
ConnectorFactory.getConnector().subscribe("Delete", new URIResource(Constants.APPLICATIONS_DIR), 1, Constants.SUBSCRIPTION_LIFETIME, Constants.NOTIFICATION_DELAY,
new Subscriber() {
public void notify(URI uri, Map information) {
logger.log(Level.INFO, "Package manager received delete event");
applicationManager.installApplications();
}
}, context.getCredentials());
applicationListeners.add(ProcessorManager.getInstance());
applicationListeners.add(MessageManager.getInstance());
installApplications();
}
private synchronized void installApplications() {
Resource[] applicationUris;
try {
List removedApplications = new ArrayList();
removedApplications.addAll(installedApplications.keySet());
applicationUris = ((ArrayResource)ConnectorFactory.getConnector().getChildren(new URIResource(Constants.APPLICATIONS_DIR), context.getCredentials())).getArray();
for ( int i = 0; i < applicationUris.length; i++ ) {
String applicationUri = applicationUris[i].toString();
if ( !applicationUri.endsWith("/") ) {
applicationUri = applicationUri + "/";
}
if ( applicationUri.startsWith(Constants.REPOSITORY_DOMAIN) ) {
applicationUri = applicationUri.substring(Constants.REPOSITORY_DOMAIN.length());
}
if ( !installedApplications.containsKey(applicationUri) ) {
Application installedApplication = parseApplication(new URIResource(applicationUri));
if ( installedApplication != null ) install(installedApplication);
} else {
logger.log(Level.INFO, "Application '"+applicationUri+"' already installed");
removedApplications.remove(applicationUri);
}
}
for ( Iterator i = removedApplications.iterator(); i.hasNext(); ) {
Application removedApplication = (Application)installedApplications.get((URI)i.next());
uninstall(removedApplication);
}
} catch (IOException e) {
logger.log(Level.SEVERE, "Could not determine installed applications!", e);
}
}
public static ApplicationManager getInstance() {
if ( applicationManager == null ) {
applicationManager = new ApplicationManager();
}
return applicationManager;
}
private Application parseApplication(URI applicationUri) {
try {
SimpleImporter importer = new SimpleImporter();
URI applicationDefinition = new URIResource(applicationUri.toString()+APPLICATION_CONFIG);
StreamableResource applicationDefinitionResouce = ((StreamableResource)ConnectorFactory.getConnector().getResource(new URIResource(Constants.REPOSITORY_DOMAIN+applicationDefinition), context.getCredentials()));
if ( applicationDefinitionResouce != null ) {
InputStream configuration = applicationDefinitionResouce.getInputStream();
ConfigurationHandler handler = new ConfigurationHandler(applicationUri);
importer.addSimpleImportHandler(handler);
importer.parse(new InputSource(configuration));
return handler.getApplication();
} else {
logger.log(Level.SEVERE, "Application definition (application.xml) not found in directory '"+applicationUri+"'. Application will not be installed!");
}
} catch (ParserConfigurationException e) {
logger.log(Level.SEVERE, "Exception while parsing application configuration. Skipping installation...", e);
} catch (SAXException e) {
logger.log(Level.SEVERE, "Exception while parsing application configuration. Skipping installation...", e);
} catch (IOException e) {
logger.log(Level.SEVERE, "Could not get application information. Skipping installation...", e);
}
return null;
}
private Application getApplication(List applications, URI applicationUri) {
for ( Iterator i = applications.iterator(); i.hasNext(); ) {
Application application = (Application)i.next();
if ( application.getUri().equals(applicationUri) ) return application;
}
return null;
}
private synchronized void updateApplication(URI applicationUri) {
logger.log(Level.INFO, "Updating application '"+applicationUri+"'");
// Compare newly parsed application with previously installed and send diffs
Application installedApplication = (Application)installedApplications.get(applicationUri);
Application updatedApplication = parseApplication(applicationUri);
for ( Iterator i = installedApplication.getContent().entrySet().iterator(); i.hasNext(); ) {
Map.Entry entry = (Map.Entry)i.next();
List removed = new ArrayList();
removed.addAll((List)entry.getValue());
List updated = updatedApplication.getContent((String)entry.getKey());
if ( updated != null ) {
removed.removeAll(updated);
}
for ( Iterator j = removed.iterator(); j.hasNext(); ) {
for ( Iterator k = applicationListeners.iterator(); k.hasNext(); ) {
((ApplicationListener)k.next()).uninstall((String)entry.getKey(), updatedApplication.getUri(), (URI)j.next());
}
}
}
for ( Iterator i = updatedApplication.getContent().entrySet().iterator(); i.hasNext(); ) {
Map.Entry entry = (Map.Entry)i.next();
List added = new ArrayList();
added.addAll((List)entry.getValue());
List installed = installedApplication.getContent((String)entry.getKey());
if ( installed != null ) {
added.removeAll(installed);
}
for ( Iterator j = added.iterator(); j.hasNext(); ) {
for ( Iterator k = applicationListeners.iterator(); k.hasNext(); ) {
((ApplicationListener)k.next()).install((String)entry.getKey(), updatedApplication.getUri(), (URI)j.next());
}
}
}
}
private void install(Application application) {
logger.log(Level.INFO, "Installing application '"+application.getUri()+"'");
ConnectorFactory.getConnector().subscribe("Update", new URIResource(Constants.REPOSITORY_DOMAIN+application.getUri().toString()), 0, Constants.SUBSCRIPTION_LIFETIME, Constants.NOTIFICATION_DELAY,
new Subscriber() {
public void notify(URI uri, Map information) {
applicationManager.updateApplication(uri);
}
}, context.getCredentials());
for ( Iterator i = application.getContent().entrySet().iterator(); i.hasNext(); ) {
Map.Entry entry = (Map.Entry)i.next();
for ( Iterator j = ((List)entry.getValue()).iterator(); j.hasNext(); ) {
URI uri = (URI)j.next();
for ( Iterator k = applicationListeners.iterator(); k.hasNext(); ) {
((ApplicationListener)k.next()).install((String)entry.getKey(), application.getUri(), uri);
}
}
}
installedApplications.put(application.getUri(), application);
}
private void uninstall(Application application) {
logger.log(Level.INFO, "Uninstall application '"+application.getUri()+"'");
for ( Iterator i = application.getContent().entrySet().iterator(); i.hasNext(); ) {
Map.Entry entry = (Map.Entry)i.next();
for ( Iterator j = ((List)entry.getValue()).iterator(); j.hasNext(); ) {
URI uri = (URI)j.next();
for ( Iterator k = applicationListeners.iterator(); k.hasNext(); ) {
((ApplicationListener)k.next()).uninstall((String)entry.getKey(), application.getUri(), uri);
}
}
}
// FIXME: Remove subscriber
installedApplications.remove(application.getUri());
}
private final class ConfigurationHandler extends DefaultSimpleImportHandler {
private Application application;
private URI applicationUri;
private ConfigurationHandler(URI applicationUri) {
this.applicationUri = applicationUri;
}
private Application getApplication() {
return application;
}
public void startElement(SimplePath path, String name, AttributesImpl attributes, String leadingCDdata) {
if (path.matches("application")) {
application = new Application(applicationUri);
} else if ( path.matches("display-name") ) {
application.setDisplayName(leadingCDdata);
} else if ( path.matches("vendor") ) {
application.setVendor(leadingCDdata);
} else if ( path.matches("description") ) {
application.setDescription(leadingCDdata);
} else if ( path.matches("resource-types/resource-type") ) {
String resourceTypeName = attributes.getValue("name");
String clazz = attributes.getValue("class");
try {
AbstractValueDescriptorFactory descriptorFactory = (AbstractValueDescriptorFactory)factoryClassLoader.loadClass(clazz).getConstructor(new Class[0]).newInstance(new Object[0]);
ValueDescriptorManager.getInstance().registerDescriptorFactory(descriptorFactory);
logger.log(Level.INFO, "Successfully registered descriptor factory " + clazz);
} catch (Exception e) {
logger.log(Level.SEVERE, "Descriptor factory " + clazz + " could not loaded!", e);
}
} else if ( path.matches("content/processors") ) {
String uri = attributes.getValue("uri");
application.addContent(Application.PROCESSORS, new URIResource(applicationUri+attributes.getValue("uri")));
} else if ( path.matches("content/messages") ) {
application.addContent(Application.MESSAGES, new URIResource(applicationUri+attributes.getValue("uri")));
} else if ( path.matches("content/jobs") ) {
application.addContent(Application.JOBS, new URIResource(applicationUri+attributes.getValue("uri")));
}
}
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/application/Application.java
Index: Application.java
===================================================================
package org.apache.slide.projector.application;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.slide.projector.URI;
public final class Application {
public final static String PROCESSORS = "processors";
public final static String MESSAGES = "messages";
public final static String JOBS = "jobs";
private URI uri;
private String displayName, vendor, description;
private Map content = new HashMap();
Application(URI applicationUri) {
this.uri = applicationUri;
}
public URI getUri() {
return uri;
}
String getDescription() {
return description;
}
void setDescription(String description) {
this.description = description;
}
String getDisplayName() {
return displayName;
}
void setDisplayName(String displayName) {
this.displayName = displayName;
}
String getVendor() {
return vendor;
}
void setVendor(String vendor) {
this.vendor = vendor;
}
void addContent(String type, URI contentUri) {
List contentUris = (List)content.get(type);
if ( contentUris == null ) {
contentUris = new ArrayList();
content.put(type, contentUris);
}
contentUris.add(contentUri);
}
List getContent(String type) {
return (List)content.get(type);
}
Map getContent() {
return content;
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/store/RequestParameterStore.java
Index: RequestParameterStore.java
===================================================================
/*
*
* ====================================================================
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.slide.projector.store;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import org.apache.slide.projector.Store;
public class RequestParameterStore implements Store {
protected HttpServletRequest request;
public RequestParameterStore(HttpServletRequest request) {
this.request = request;
}
public void put(String key, Object value, long timeout) throws IOException {
throw new IOException("Put operation is not supported by request-parameter store!");
}
public void put(String key, Object value) throws IOException {
throw new IOException("Put operation is not supported by request-parameter store!");
}
public Object get(String key) {
return request.getParameterValues(key);
}
public void dispose(String key) throws IOException {
throw new IOException("Dispose operation is not supported by request-parameter store!");
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/store/FormStore.java
Index: FormStore.java
===================================================================
/*
*
* ====================================================================
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.slide.projector.store;
import java.io.IOException;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.Store;
import org.apache.slide.projector.resource.MapResource;
public class FormStore extends AbstractStore {
private Context context;
private Store store;
public FormStore(Context context, Store store) {
this.context = context;
this.store = store;
}
public void put(String key, Object value) throws IOException {
MapResource domain = getDomain();
domain.getMap().put(key, value);
}
public Object get(String key) throws IOException {
return getDomain().getMap().get(key);
}
public void dispose(String key) throws IOException {
getDomain().getMap().remove(key);
}
public void clear() throws IOException {
String domain = context.getProcess().toString();
store.dispose(domain);
}
public MapResource getDomain() throws IOException {
String domain = context.getProcess().toString();
MapResource mapResource = (MapResource)store.get(domain);
if ( mapResource == null ) {
mapResource = new MapResource();
store.put(domain, mapResource);
return mapResource;
} else {
return mapResource;
}
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/store/RequestHeaderStore.java
Index: RequestHeaderStore.java
===================================================================
/*
*
* ====================================================================
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.slide.projector.store;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import org.apache.slide.projector.Store;
public class RequestHeaderStore implements Store {
protected HttpServletRequest request;
public RequestHeaderStore(HttpServletRequest request) {
this.request = request;
}
public void put(String key, Object value, long timeout) throws IOException {
throw new IOException("Put operation is not supported by request-header store!");
}
public void put(String key, Object value) throws IOException {
throw new IOException("Put operation is not supported by request-header store!");
}
public Object get(String key) {
return request.getHeader(key);
}
public void dispose(String key) throws IOException {
throw new IOException("Dispose operation is not supported by request-header store!");
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/store/SessionStore.java
Index: SessionStore.java
===================================================================
/*
*
* ====================================================================
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.slide.projector.store;
import javax.servlet.http.HttpServletRequest;
public class SessionStore extends AbstractStore {
protected HttpServletRequest request;
public SessionStore(HttpServletRequest request) {
this.request = request;
}
public void put(String key, Object value) {
request.getSession().setAttribute(key, value);
}
public Object get(String key) {
return request.getSession().getAttribute(key);
}
public void dispose(String key) {
request.getSession().removeAttribute(key);
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/store/RequestAttributeStore.java
Index: RequestAttributeStore.java
===================================================================
/*
*
* ====================================================================
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.slide.projector.store;
import javax.servlet.http.HttpServletRequest;
public class RequestAttributeStore extends AbstractStore {
protected HttpServletRequest request;
public RequestAttributeStore(HttpServletRequest request) {
this.request = request;
}
public void put(String key, Object value) {
request.setAttribute(key, value);
}
public Object get(String key) {
return request.getAttribute(key);
}
public void dispose(String key) {
request.removeAttribute(key);
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/store/CookieStore.java
Index: CookieStore.java
===================================================================
/*
*
* ====================================================================
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.slide.projector.store;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.slide.projector.Store;
public class CookieStore implements Store {
protected HttpServletRequest request;
protected HttpServletResponse response;
public CookieStore(HttpServletRequest request, HttpServletResponse response) {
this.request = request;
this.response = response;
}
public void put(String key, Object value, long timeout) {
Cookie cookie = null;
if ( value instanceof Cookie ) {
cookie = (Cookie)value;
}
if ( value instanceof String ) {
cookie = new Cookie(key, (String)value);
}
if ( cookie != null ) {
cookie.setMaxAge((int) (timeout/1000));
response.addCookie(cookie);
}
}
public void put(String key, Object value) {
Cookie cookie = null;
if ( value instanceof Cookie ) {
cookie = (Cookie)value;
}
if ( value instanceof String ) {
cookie = new Cookie(key, (String)value);
}
if ( cookie != null ) {
response.addCookie(cookie);
}
}
public Object get(String key) {
Cookie[] cookies = request.getCookies();
for ( int i = 0; i < cookies.length; i++ ) {
if ( cookies[i].getName().equals(key) ) {
return cookies[i].getValue();
}
}
return null;
}
public void dispose(String key) {
request.removeAttribute(key);
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/store/RepositoryStore.java
Index: RepositoryStore.java
===================================================================
/*
*
* ====================================================================
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.slide.projector.store;
import java.io.IOException;
import org.apache.slide.projector.Constants;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.connector.ConnectorFactory;
import org.apache.slide.projector.resource.StreamableResource;
import org.apache.slide.projector.resource.URIResource;
public class RepositoryStore extends AbstractStore {
private Context context;
public RepositoryStore(Context context) {
this.context = context;
}
public void put(String key, Object value) throws IOException {
if ( value instanceof StreamableResource) {
ConnectorFactory.getConnector().setResource(new URIResource(Constants.REPOSITORY_DOMAIN+key), (StreamableResource)value, context.getCredentials());
} else {
throw new IOException("Only values of type StreamableResource can be stored to repository! Given value is '"+value+"'");
}
}
public Object get(String key) throws IOException {
return ConnectorFactory.getConnector().getResource(new URIResource(Constants.REPOSITORY_DOMAIN+key), context.getCredentials());
}
public void dispose(String key) throws IOException {
ConnectorFactory.getConnector().removeResource(new URIResource(Constants.REPOSITORY_DOMAIN+key), context.getCredentials());
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/store/AbstractStore.java
Index: AbstractStore.java
===================================================================
package org.apache.slide.projector.store;
import java.io.IOException;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.slide.projector.Store;
import org.apache.slide.projector.engine.Scheduler;
public abstract class AbstractStore implements Store {
private final static Logger logger = Logger.getLogger(AbstractStore.class.getName());
public void put(final String key, Object value, long timeout) throws IOException {
put(key, value);
Scheduler.getTimer().schedule(new TimerTask() {
public void run() {
try {
dispose(key);
} catch ( IOException exception ) {
logger.log(Level.SEVERE, "Could not dispose object with key="+key, exception);
}
}
}, timeout);
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/store/ProcessStore.java
Index: ProcessStore.java
===================================================================
/*
*
* ====================================================================
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.slide.projector.store;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.slide.projector.Constants;
import org.apache.slide.projector.Store;
import org.apache.slide.projector.resource.MapResource;
public class ProcessStore extends AbstractStore {
private Store store;
private String processId, storageKey;
private Map map;
private MapResource mapResource;
public ProcessStore(Store store) {
this.store = store;
}
public String getProcessId() {
return processId;
}
public void setProcessId(String processId) {
this.processId = processId;
this.storageKey = Constants.PROCESS_STORAGE_PREFIX+processId;
}
public void put(String key, Object value) throws IOException {
getMap().put(key, value);
store.put(storageKey, mapResource);
}
public Object get(String key) throws IOException {
return getMap().get(key);
}
public void dispose(String key) throws IOException {
getMap().remove(key);
store.put(storageKey, mapResource);
}
private Map getMap() throws IOException {
if ( mapResource != null ) return mapResource.getMap();
mapResource = (MapResource)store.get(storageKey);
if ( mapResource == null ) {
map = new HashMap();
mapResource = new MapResource(map);
return map;
} else {
return mapResource.getMap();
}
}
}
1.7 +2 -2 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/ControlComposer.java
Index: ControlComposer.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/ControlComposer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ControlComposer.java 10 May 2004 16:54:24 -0000 1.6
+++ ControlComposer.java 24 May 2004 13:52:44 -0000 1.7
@@ -2,7 +2,6 @@
import org.apache.slide.projector.*;
import org.apache.slide.projector.descriptor.*;
-import org.apache.slide.projector.engine.HttpContext;
import org.apache.slide.projector.engine.Process;
import org.apache.slide.projector.engine.ProcessorManager;
import org.apache.slide.projector.i18n.DefaultMessage;
@@ -12,6 +11,7 @@
import org.apache.slide.projector.processor.SimpleProcessor;
import org.apache.slide.projector.processor.TemplateRenderer;
import org.apache.slide.projector.resource.*;
+import org.apache.slide.projector.store.FormStore;
import org.apache.slide.projector.util.ProcessorHelper;
import java.util.*;
@@ -145,7 +145,7 @@
Locale locale = ((LocaleResource)parameter.get(LOCALE)).getLocale();
String state = DEFAULT_STATE;
List informations = context.getInformations();
- MapResource mapResource = (MapResource)((HttpContext.FormStore)context.getStore(Store.FORM)).getDomain();
+ MapResource mapResource = (MapResource)((FormStore)context.getStore(Store.FORM)).getDomain();
List generatedControls = new ArrayList();
List involvedParameters = new ArrayList();
for (int i = 0; i < controlDescriptions.length; i++ ) {
1.2 +2 -2 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/ClearForm.java
Index: ClearForm.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/ClearForm.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ClearForm.java 11 May 2004 10:07:33 -0000 1.1
+++ ClearForm.java 24 May 2004 13:52:44 -0000 1.2
@@ -9,13 +9,13 @@
import org.apache.slide.projector.descriptor.ParameterDescriptor;
import org.apache.slide.projector.descriptor.ResultDescriptor;
import org.apache.slide.projector.descriptor.StateDescriptor;
-import org.apache.slide.projector.engine.HttpContext;
+import org.apache.slide.projector.store.FormStore;
public class ClearForm implements Processor {
public Result process(Map parameter, Context context) throws Exception {
Store formStore = context.getStore(Store.FORM);
if ( formStore != null ) {
- ((HttpContext.FormStore)formStore).clear();
+ ((FormStore)formStore).clear();
}
return new Result(StateDescriptor.OK);
}
1.3 +5 -5 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/Test.java
Index: Test.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/Test.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Test.java 24 May 2004 12:33:41 -0000 1.2
+++ Test.java 24 May 2004 13:52:44 -0000 1.3
@@ -15,7 +15,6 @@
import org.apache.slide.projector.descriptor.ParameterDescriptor;
import org.apache.slide.projector.descriptor.ResultDescriptor;
import org.apache.slide.projector.descriptor.URIValueDescriptor;
-import org.apache.slide.projector.engine.HttpContext;
import org.apache.slide.projector.engine.Process;
import org.apache.slide.projector.engine.ProcessorManager;
import org.apache.slide.projector.i18n.ParameterMessage;
@@ -24,6 +23,7 @@
import org.apache.slide.projector.resource.NullResource;
import org.apache.slide.projector.resource.StringResource;
import org.apache.slide.projector.resource.URIResource;
+import org.apache.slide.projector.store.FormStore;
import org.apache.slide.projector.util.ProcessorHelper;
public class Test implements Processor {
@@ -65,22 +65,22 @@
if ( step.equals(FORM_STEP) ) {
result = formProcessor.process(parameter, context);
} else if ( step.equals(PROCESS_STEP) ) {
- parameter.putAll(((MapResource)((HttpContext.FormStore)context.getStore(Store.FORM)).getDomain()).getMap());
+ parameter.putAll(((MapResource)((FormStore)context.getStore(Store.FORM)).getDomain()).getMap());
ProcessorHelper.validate(processor.getParameterDescriptors(), parameter, context);
Result processorResult = processor.process(parameter, context);
if ( hasErrors(context.getInformations()) ) {
context.setStep(FORM_STEP);
- ((HttpContext.FormStore)context.getStore(Store.FORM)).put(ControlComposer.VALIDATE, BooleanResource.TRUE);
+ ((FormStore)context.getStore(Store.FORM)).put(ControlComposer.VALIDATE, BooleanResource.TRUE);
result = formProcessor.process(parameter, context);
} else {
Map resultParameters = new HashMap();
resultParameters.put("state", new StringResource(processorResult.getState()));
ProcessorHelper.validate(resultRenderer.getParameterDescriptors(), resultParameters, context);
result = resultRenderer.process(resultParameters, context);
- ((HttpContext.FormStore)context.getStore(Store.FORM)).clear();
+ ((FormStore)context.getStore(Store.FORM)).clear();
}
} else {
- ((HttpContext.FormStore)context.getStore(Store.FORM)).clear();
+ ((FormStore)context.getStore(Store.FORM)).clear();
return Result.OK;
}
return result;
1.5 +2 -2 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/i18n/MessageManager.java
Index: MessageManager.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/i18n/MessageManager.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MessageManager.java 17 May 2004 15:22:04 -0000 1.4
+++ MessageManager.java 24 May 2004 13:52:45 -0000 1.5
@@ -5,10 +5,10 @@
import de.zeigermann.xml.simpleImporter.SimplePath;
import org.apache.slide.projector.Constants;
import org.apache.slide.projector.URI;
+import org.apache.slide.projector.application.Application;
+import org.apache.slide.projector.application.ApplicationListener;
import org.apache.slide.projector.connector.ConnectorFactory;
import org.apache.slide.projector.connector.Subscriber;
-import org.apache.slide.projector.engine.Application;
-import org.apache.slide.projector.engine.ApplicationListener;
import org.apache.slide.projector.resource.StreamableResource;
import org.apache.slide.projector.resource.URIResource;
import org.xml.sax.InputSource;
1.3 +1 -74 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/AbstractContext.java
Index: AbstractContext.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/AbstractContext.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractContext.java 6 May 2004 12:54:11 -0000 1.2
+++ AbstractContext.java 24 May 2004 13:52:45 -0000 1.3
@@ -1,16 +1,7 @@
package org.apache.slide.projector;
-import org.apache.slide.projector.resource.MapResource;
-import org.apache.slide.projector.resource.StreamableResource;
-import org.apache.slide.projector.resource.URIResource;
-import org.apache.slide.projector.connector.ConnectorFactory;
-import org.apache.slide.projector.engine.AbstractStore;
-
-import java.io.IOException;
-import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
-import java.util.Map;
/**
* @author <a href="mailto:dflorey@c1-fse.de">Daniel Florey</a>
@@ -49,69 +40,5 @@
public String getStep() {
return step;
- }
-
- public class RepositoryStore extends AbstractStore {
- public void put(String key, Object value) throws IOException {
- if ( value instanceof StreamableResource) {
- ConnectorFactory.getConnector().setResource(new URIResource(Constants.REPOSITORY_DOMAIN+key), (StreamableResource)value, getCredentials());
- } else {
- throw new IOException("Only values of type StreamableResource can be stored to repository! Given value is '"+value+"'");
- }
- }
-
- public Object get(String key) throws IOException {
- return ConnectorFactory.getConnector().getResource(new URIResource(Constants.REPOSITORY_DOMAIN+key), getCredentials());
- }
-
- public void dispose(String key) throws IOException {
- ConnectorFactory.getConnector().removeResource(new URIResource(Constants.REPOSITORY_DOMAIN+key), getCredentials());
- }
- }
-
- public class ProcessStore extends AbstractStore {
- private Store store;
- private String processId, storageKey;
- private Map map;
- private MapResource mapResource;
-
- public ProcessStore(Store store) {
- this.store = store;
- }
-
- public String getProcessId() {
- return processId;
- }
-
- public void setProcessId(String processId) {
- this.processId = processId;
- this.storageKey = Constants.PROCESS_STORAGE_PREFIX+processId;
- }
-
- public void put(String key, Object value) throws IOException {
- getMap().put(key, value);
- store.put(storageKey, mapResource);
- }
-
- public Object get(String key) throws IOException {
- return getMap().get(key);
- }
-
- public void dispose(String key) throws IOException {
- getMap().remove(key);
- store.put(storageKey, mapResource);
- }
-
- private Map getMap() throws IOException {
- if ( mapResource != null ) return mapResource.getMap();
- mapResource = (MapResource)store.get(storageKey);
- if ( mapResource == null ) {
- map = new HashMap();
- mapResource = new MapResource(map);
- return map;
- } else {
- return mapResource.getMap();
- }
- }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org