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/06/08 11:10:53 UTC
cvs commit: jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine ProcessServlet.java
dflorey 2004/06/08 02:10:53
Modified: proposals/projector/src/java/org/apache/slide/projector/engine
ProcessServlet.java
Added: proposals/projector/src/java/org/apache/slide/projector/processor/core
Dispose.java MapEntry.java Content.java Event.java
CachedContent.java ExceptionRenderer.java Link.java
Echo.java Thread.java Exists.java
StringArrayRenderer.java URL.java
Removed: proposals/projector/src/java/org/apache/slide/projector/processor
Content.java StringArrayRenderer.java Dispose.java
ExceptionRenderer.java CachedContent.java
Exists.java MapEntry.java Thread.java URL.java
Echo.java Event.java Link.java
Log:
Revision Changes Path
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/core/Dispose.java
Index: Dispose.java
===================================================================
package org.apache.slide.projector.processor.core;
import org.apache.slide.projector.*;
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.descriptor.StringValueDescriptor;
import org.apache.slide.projector.i18n.ErrorMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.util.StoreHelper;
import org.apache.slide.projector.value.StringValue;
import java.util.Map;
import java.util.logging.Logger;
public class Dispose implements Processor {
private static Logger logger = Logger.getLogger(Dispose.class.getName());
public final static String STORE = "store";
public final static String KEY = "key";
private final static ParameterDescriptor[] parameterDescriptor = new ParameterDescriptor[]{
new ParameterDescriptor(STORE, new ParameterMessage("dispose/parameter/store"), new StringValueDescriptor(Store.stores)),
new ParameterDescriptor(KEY, new ParameterMessage("dispose/parameter/key"), new StringValueDescriptor())
};
private final static ResultDescriptor resultDescriptor = new ResultDescriptor(new StateDescriptor[]{ StateDescriptor.OK_DESCRIPTOR });
public Result process(Map parameter, Context context) throws Exception {
String name = ((StringValue)parameter.get(STORE)).toString();
String key = ((StringValue)parameter.get(KEY)).toString();
Store store = context.getStore(StoreHelper.getStoreByName(name));
if ( store == null ) {
throw new ProcessException(new ErrorMessage("storeNotAvailable", new String[] {name}));
}
store.dispose(key);
return new Result( StateDescriptor.OK );
}
public ParameterDescriptor[] getParameterDescriptors() {
return parameterDescriptor;
}
public ResultDescriptor getResultDescriptor() {
return resultDescriptor;
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/core/MapEntry.java
Index: MapEntry.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/core/MapEntry.java,v 1.1 2004/06/08 09:10:53 dflorey Exp $
* $Revision: 1.1 $
* $Date: 2004/06/08 09:10:53 $
*
* ====================================================================
*
* 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.processor.core;
import org.apache.slide.projector.ContentType;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.Processor;
import org.apache.slide.projector.Result;
import org.apache.slide.projector.descriptor.*;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.processor.SimpleProcessor;
import org.apache.slide.projector.value.MapValue;
import org.apache.slide.projector.value.StringValue;
import org.apache.slide.projector.value.Value;
import java.util.Map;
/**
* The MapEntry class
*
* @author <a href="mailto:dflorey@c1-fse.de">Daniel Florey</a>
*/
public class MapEntry implements Processor {
private final static String MAP = "map";
private final static String KEY = "key";
private final static String KEY_NOT_FOUND = "keyNotFound";
private final static ParameterDescriptor[] parameterDescriptors = new ParameterDescriptor[] {
new ParameterDescriptor(MAP, new ParameterMessage("mapEntry/map"), new MapValueDescriptor()),
new ParameterDescriptor(KEY, new ParameterMessage("mapEntry/key"), new StringValueDescriptor())
};
private final static ResultDescriptor resultDescriptor = new ResultDescriptor(
new StateDescriptor[] {
StateDescriptor.OK_DESCRIPTOR,
new StateDescriptor(KEY_NOT_FOUND, new DefaultMessage("mapEntry/state/keyNotFound"))},
new ResultEntryDescriptor[] {
new ResultEntryDescriptor(SimpleProcessor.OUTPUT, new DefaultMessage("mapEntry/output"), ContentType.DYNAMIC, false)
});
public Result process(Map parameter, Context context) throws Exception {
Map map = ((MapValue)parameter.get(MAP)).getMap();
String key = ((StringValue)parameter.get(KEY)).toString();
Value entry = (Value)map.get(key);
if ( entry == null ) return new Result(KEY_NOT_FOUND);
return new Result(StateDescriptor.OK, SimpleProcessor.OUTPUT, entry);
}
public ParameterDescriptor[] getParameterDescriptors() {
return parameterDescriptors;
}
public ResultDescriptor getResultDescriptor() {
return resultDescriptor;
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/core/Content.java
Index: Content.java
===================================================================
package org.apache.slide.projector.processor.core;
import org.apache.slide.projector.Constants;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.URI;
import org.apache.slide.projector.connector.ConnectorFactory;
import org.apache.slide.projector.descriptor.ParameterDescriptor;
import org.apache.slide.projector.descriptor.ResultEntryDescriptor;
import org.apache.slide.projector.descriptor.URIValueDescriptor;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.processor.SimpleProcessor;
import org.apache.slide.projector.value.URIValue;
import org.apache.slide.projector.value.Value;
public class Content extends SimpleProcessor {
public Value process(Value input, Context context) throws Exception {
URI uri = new URIValue(Constants.REPOSITORY_DOMAIN+input.toString());
return ConnectorFactory.getConnector().getResource(uri, context.getCredentials());
}
public ParameterDescriptor getParameterDescriptor() {
return new ParameterDescriptor(INPUT, new ParameterMessage("simpleProcessor/parameter/input"), new URIValueDescriptor());
}
public ResultEntryDescriptor getResultEntryDescriptor() {
return new ResultEntryDescriptor(OUTPUT, new DefaultMessage("simpleProcessor/result/output"), "*", true);
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/core/Event.java
Index: Event.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/core/Event.java,v 1.1 2004/06/08 09:10:53 dflorey Exp $
* $Revision: 1.1 $
* $Date: 2004/06/08 09:10:53 $
*
* ====================================================================
*
* 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.processor.core;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.Processor;
import org.apache.slide.projector.Result;
import org.apache.slide.projector.connector.ConnectorFactory;
import org.apache.slide.projector.descriptor.*;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.value.BooleanValue;
import org.apache.slide.projector.value.MapValue;
import java.util.Map;
/**
* The Event class
*
* @author <a href="mailto:dflorey@c1-fse.de">Daniel Florey</a>
*/
public class Event implements Processor {
public final static String INFORMATION = "information";
public final static String VETOABLE = "vetoable";
private final static ParameterDescriptor[] parameterDescriptors = new ParameterDescriptor[] {
new ParameterDescriptor(INFORMATION, new ParameterMessage("event/information"), new MapValueDescriptor()),
new ParameterDescriptor(VETOABLE, new ParameterMessage("event/vetoable"), new BooleanValueDescriptor(), new BooleanValue(false))
};
private final static ResultDescriptor resultDescriptor = new ResultDescriptor(new StateDescriptor[] { StateDescriptor.OK_DESCRIPTOR });
public Result process(Map parameter, Context context) throws Exception {
Map information = ((MapValue)parameter.get(INFORMATION)).getMap();
boolean vetoable = ((BooleanValue)parameter.get(VETOABLE)).booleanValue();
if ( vetoable ) {
ConnectorFactory.getConnector().fireVetoableEvent(information, context.getCredentials());
} else {
ConnectorFactory.getConnector().fireEvent(information, context.getCredentials());
}
return new Result(StateDescriptor.OK);
}
public ParameterDescriptor[] getParameterDescriptors() {
return parameterDescriptors;
}
public ResultDescriptor getResultDescriptor() {
return resultDescriptor;
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/core/CachedContent.java
Index: CachedContent.java
===================================================================
package org.apache.slide.projector.processor.core;
import org.apache.slide.projector.*;
import org.apache.slide.projector.connector.ConnectorFactory;
import org.apache.slide.projector.descriptor.*;
import org.apache.slide.projector.engine.Job;
import org.apache.slide.projector.engine.ProcessorManager;
import org.apache.slide.projector.engine.Scheduler;
import org.apache.slide.projector.expression.EventExpression;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.processor.SimpleProcessor;
import org.apache.slide.projector.value.*;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
/**
* @author <a href="mailto:dflorey@c1-fse.de">Daniel Florey</a>
* @version $Revision: 1.1 $
*/
public class CachedContent implements Processor {
private static Logger logger = Logger.getLogger(CachedContent.class.getName());
public final static String URL = "url";
public Result process(Map parameter, Context context) throws Exception {
URI uri = (URI)parameter.get(SimpleProcessor.INPUT);
String url = "";
if ( context instanceof HttpContext ) {
url = ((HttpContext)context).getContextPath()+ProcessorManager.getInstance().getURI(this)+"?input="+uri;
}
// check for cached result
Map resultEntries = new HashMap();
Value output = (Value)context.getStore(Store.CACHE).get(uri.toString());
if ( output == null ) {
output = ConnectorFactory.getConnector().getResource(new URIValue(Constants.REPOSITORY_DOMAIN+uri.toString()), context.getCredentials());
if ( output instanceof InputStreamValue ) {
output = new MultipleStreamableValue((StreamableValue)output);
}
// cache result...
context.getStore(Store.CACHE).put(uri.toString(), output);
// ...and add dispose condition
Map jobParameter = new HashMap();
jobParameter.put(Dispose.STORE, Store.stores[Store.CACHE]);
jobParameter.put(Dispose.KEY, uri.toString());
EventExpression expression = new EventExpression("Update");
expression.addProperty(EventExpression.DEPTH, "0");
expression.addProperty(EventExpression.URI, uri.toString());
Scheduler.getInstance().activateJob(new Job(expression, new URIValue("dispose"), jobParameter, false, false));
}
resultEntries.put(SimpleProcessor.OUTPUT, output);
// build url to activate this processor on top level
resultEntries.put(URL, new StringValue(url));
return new Result(StateDescriptor.OK, resultEntries);
}
public ParameterDescriptor[] getParameterDescriptors() {
return new ParameterDescriptor[]{ new ParameterDescriptor(SimpleProcessor.INPUT, new ParameterMessage("cachedContent/parameter/input"), new URIValueDescriptor()) }; }
public ResultDescriptor getResultDescriptor() {
return new ResultDescriptor(new StateDescriptor[]{ StateDescriptor.OK_DESCRIPTOR },
new ResultEntryDescriptor[] {
new ResultEntryDescriptor(SimpleProcessor.OUTPUT, new DefaultMessage("cachedContent/result/output"), "*", true),
new ResultEntryDescriptor(URL, new DefaultMessage("cachedContent/result/url"), "text/url", true), }
);
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/core/ExceptionRenderer.java
Index: ExceptionRenderer.java
===================================================================
package org.apache.slide.projector.processor.core;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.ProcessException;
import org.apache.slide.projector.Processor;
import org.apache.slide.projector.Result;
import org.apache.slide.projector.descriptor.*;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ErrorMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.i18n.MessageNotFoundException;
import org.apache.slide.projector.value.LocaleValue;
import org.apache.slide.projector.value.ObjectValue;
import org.apache.slide.projector.value.StringValue;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Logger;
public class ExceptionRenderer implements Processor {
private static Logger logger = Logger.getLogger(ExceptionRenderer.class.getName());
final static String OK = "ok";
public final static String EXCEPTION = "exception";
public final static String CLASS = "class";
public final static String TITLE = "title";
public final static String STACK_TRACE = "stackTrace";
public final static String TEXT = "text";
public final static String SUMMARY = "summary";
public final static String DETAILS = "details";
public final static String LOCALE = "locale";
public Result process(Map parameter, Context context) throws Exception {
Locale locale = (((LocaleValue)parameter.get(LOCALE)).getLocale());
ObjectValue exception = (ObjectValue)parameter.get(EXCEPTION);
Throwable throwable = (Throwable)exception.getObject();
Result result = new Result(OK);
String title = null, text = null, summary = null;
StringBuffer details = new StringBuffer();
if ( throwable instanceof ProcessException ) {
try {
title = ((ProcessException)throwable).getErrorMessage().getTitle(locale);
text = ((ProcessException)throwable).getErrorMessage().getText(locale);
summary = ((ProcessException)throwable).getErrorMessage().getSummary(locale);
} catch ( MessageNotFoundException e ) {
title = ((ProcessException)throwable).getErrorMessage().getId();
text = ((ProcessException)throwable).getErrorMessage().getId();
summary = ((ProcessException)throwable).getErrorMessage().getId();
}
appendNestedDetails(details, throwable, locale);
} else {
title = throwable.getLocalizedMessage();
text = throwable.getLocalizedMessage();
summary = throwable.getLocalizedMessage();
appendNestedDetails(details, throwable, locale);
}
if ( title == null ) title = "";
if ( text == null ) text = "";
if ( summary == null ) summary = "";
result.addResultEntry(TITLE, new StringValue(title));
result.addResultEntry(TEXT, new StringValue(text));
result.addResultEntry(SUMMARY, new StringValue(summary));
result.addResultEntry(DETAILS, new StringValue(details.toString()));
result.addResultEntry(CLASS, new StringValue(throwable.getClass().getName()));
StackTraceElement []trace = throwable.getStackTrace();
StringBuffer buffer = new StringBuffer(256);
for ( int i = 0; i < trace.length; i++ ) {
buffer.append(trace[i].toString());
buffer.append(" ");
}
result.addResultEntry(STACK_TRACE, new StringValue(buffer.toString()));
return result;
}
private void appendNestedDetails(StringBuffer details, Throwable throwable, Locale locale) {
if ( details.length() > 0 ) details.append(' ');
if ( throwable instanceof ProcessException ) {
ErrorMessage message = ((ProcessException)throwable).getErrorMessage();
details.append(message.getDetails(locale, ""));
} else {
details.append(throwable.getMessage());
}
if ( throwable.getCause() != null ) appendNestedDetails(details, throwable.getCause(), locale);
}
public ParameterDescriptor[] getParameterDescriptors() {
return new ParameterDescriptor[]{
new ParameterDescriptor(EXCEPTION, new ParameterMessage("exceptionRenderer/exception"), new ResourceValueDescriptor()),
new ParameterDescriptor(LOCALE, new ParameterMessage("exceptionRenderer/locale"), new LocaleValueDescriptor(), new LocaleValue(Locale.getDefault()))
};
}
public ResultDescriptor getResultDescriptor() {
return new ResultDescriptor(new StateDescriptor[]{ StateDescriptor.OK_DESCRIPTOR },
new ResultEntryDescriptor[]{
new ResultEntryDescriptor(TITLE, new DefaultMessage("exceptionRenderer/result/title"), "text/plain", true),
new ResultEntryDescriptor(TEXT, new DefaultMessage("exceptionRenderer/result/text"), "text/plain", true),
new ResultEntryDescriptor(SUMMARY, new DefaultMessage("exceptionRenderer/result/summary"), "text/plain", true),
new ResultEntryDescriptor(DETAILS, new DefaultMessage("exceptionRenderer/result/details"), "text/plain", true),
new ResultEntryDescriptor(CLASS, new DefaultMessage("exceptionRenderer/result/class"), "text/plain", true),
new ResultEntryDescriptor(STACK_TRACE, new DefaultMessage("exceptionRenderer/result/stackTrace"), "text/plain", true)
});
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/core/Link.java
Index: Link.java
===================================================================
package org.apache.slide.projector.processor.core;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.slide.projector.Constants;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.HttpContext;
import org.apache.slide.projector.ProcessException;
import org.apache.slide.projector.Processor;
import org.apache.slide.projector.Result;
import org.apache.slide.projector.URI;
import org.apache.slide.projector.descriptor.BooleanValueDescriptor;
import org.apache.slide.projector.descriptor.MapValueDescriptor;
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.descriptor.StringValueDescriptor;
import org.apache.slide.projector.descriptor.URIValueDescriptor;
import org.apache.slide.projector.i18n.ErrorMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.processor.SimpleProcessor;
import org.apache.slide.projector.processor.process.Process;
import org.apache.slide.projector.value.BooleanValue;
import org.apache.slide.projector.value.MapValue;
import org.apache.slide.projector.value.NullValue;
import org.apache.slide.projector.value.StringValue;
import org.apache.slide.projector.value.Value;
public class Link implements Processor {
private final static String PROCESSOR = "processor";
private final static String CONTINUE = "continue";
private final static String PARAMETER = "parameter";
private final static ParameterDescriptor[] parameterDescriptors = new ParameterDescriptor[] {
new ParameterDescriptor(PROCESSOR, new ParameterMessage("link/parameter/processor"), new URIValueDescriptor()),
new ParameterDescriptor(Process.STEP, new ParameterMessage("link/parameter/step"), new StringValueDescriptor(), new NullValue()),
new ParameterDescriptor(CONTINUE, new ParameterMessage("link/parameter/continue"), new BooleanValueDescriptor(), BooleanValue.TRUE),
new ParameterDescriptor(PARAMETER, new ParameterMessage("link/parameter/parameter"), new MapValueDescriptor(), new MapValue(new HashMap()))
};
private final static ResultDescriptor resultDescriptor = new ResultDescriptor(new StateDescriptor[] { StateDescriptor.OK_DESCRIPTOR });
public Result process(Map parameter, Context context) throws Exception {
URI uri = (URI)parameter.get(PROCESSOR);
boolean continueProcess = ((BooleanValue)parameter.get(CONTINUE)).booleanValue();
MapValue parameterMap = (MapValue)parameter.get(PARAMETER);
Value step = (Value)parameter.get(Process.STEP);
StringBuffer linkBuffer = new StringBuffer(128);
if ( context instanceof HttpContext ) {
linkBuffer.append(((HttpContext)context).getContextPath()).append(uri);
boolean first = true;
if ( continueProcess ) {
parameterMap.getMap().put(Constants.PROCESS_ID_PARAMETER, context.getProcessId());
}
if ( step != null ) {
parameterMap.getMap().put(Process.STEP, step);
}
for ( Iterator i = parameterMap.getMap().entrySet().iterator(); i.hasNext(); ) {
Map.Entry entry = (Map.Entry)i.next();
if ( first ) {
linkBuffer.append('?');
first = false;
} else {
linkBuffer.append('&');
}
linkBuffer.append(entry.getKey());
linkBuffer.append('=');
linkBuffer.append(entry.getValue());
}
} else {
throw new ProcessException(new ErrorMessage("httpContextRequired"));
}
return new Result(StateDescriptor.OK, SimpleProcessor.OUTPUT, new StringValue(linkBuffer.toString()));
}
public ParameterDescriptor[] getParameterDescriptors() {
return parameterDescriptors;
}
public ResultDescriptor getResultDescriptor() {
return resultDescriptor;
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/core/Echo.java
Index: Echo.java
===================================================================
package org.apache.slide.projector.processor.core;
import org.apache.slide.projector.ContentType;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.descriptor.ParameterDescriptor;
import org.apache.slide.projector.descriptor.ResourceValueDescriptor;
import org.apache.slide.projector.descriptor.ResultEntryDescriptor;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.processor.SimpleProcessor;
import org.apache.slide.projector.value.Value;
public class Echo extends SimpleProcessor {
public Value process(Value input, Context context) throws Exception {
return input;
}
public ParameterDescriptor getParameterDescriptor() {
return new ParameterDescriptor(INPUT, new ParameterMessage("echo/parameter/input"), new ResourceValueDescriptor());
}
public ResultEntryDescriptor getResultEntryDescriptor() {
return new ResultEntryDescriptor(OUTPUT, new DefaultMessage("echo/result/output"), ContentType.DYNAMIC, true);
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/core/Thread.java
Index: Thread.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.processor.core;
import java.util.Map;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.Processor;
import org.apache.slide.projector.Result;
import org.apache.slide.projector.URI;
import org.apache.slide.projector.descriptor.BooleanValueDescriptor;
import org.apache.slide.projector.descriptor.MapValueDescriptor;
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.descriptor.URIValueDescriptor;
import org.apache.slide.projector.descriptor.XMLValueDescriptor;
import org.apache.slide.projector.engine.Job;
import org.apache.slide.projector.engine.ProcessorManager;
import org.apache.slide.projector.engine.Scheduler;
import org.apache.slide.projector.expression.Expression;
import org.apache.slide.projector.expression.ExpressionFactory;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.util.ProcessorHelper;
import org.apache.slide.projector.value.BooleanValue;
import org.apache.slide.projector.value.MapValue;
import org.apache.slide.projector.value.URIValue;
import org.apache.slide.projector.value.XMLValue;
/**
* @author dflorey
*/
public class Thread implements Processor {
// parameters
public final static String PROCESSOR = "processor";
public final static String REPEAT = "repeat";
public final static String CONDITION = "condition";
public final static String PARAMETERS = "parameters";
public final static String PERSISTENT = "persistent";
private final static ParameterDescriptor[] parameterDescriptors = new ParameterDescriptor[] {
new ParameterDescriptor(PROCESSOR, new ParameterMessage("job/parameter/processor"), new URIValueDescriptor()),
new ParameterDescriptor(REPEAT, new ParameterMessage("job/parameter/repeat"), new BooleanValueDescriptor(), BooleanValue.FALSE),
new ParameterDescriptor(PERSISTENT, new ParameterMessage("job/parameter/persistent"), new BooleanValueDescriptor(), BooleanValue.TRUE),
new ParameterDescriptor(CONDITION, new ParameterMessage("job/parameter/condition"), new XMLValueDescriptor()),
new ParameterDescriptor(PARAMETERS, new ParameterMessage("job/parameter/parameters"), new MapValueDescriptor())
};
private final static ResultDescriptor resultDescriptor = new ResultDescriptor(new StateDescriptor[] {
StateDescriptor.OK_DESCRIPTOR
});
public Result process(Map parameters, Context context) throws Exception {
Map jobParameters = ((MapValue)parameters.get(PARAMETERS)).getMap();
URI jobUri = (URIValue)parameters.get(PROCESSOR);
XMLValue condition = (XMLValue)parameters.get(CONDITION);
boolean repeatJob = ((BooleanValue)parameters.get(REPEAT)).booleanValue();
boolean persistentJob = ((BooleanValue)parameters.get(PERSISTENT)).booleanValue();
Expression expression = ExpressionFactory.create(condition.getRootElement());
Processor jobProcessor = ProcessorManager.getInstance().getProcessor(jobUri);
ProcessorHelper.validate(jobProcessor.getParameterDescriptors(), jobParameters, context);
Job job = new Job(expression, jobUri, jobParameters, repeatJob, persistentJob);
Scheduler.getInstance().activateJob(job);
return Result.OK;
}
public ParameterDescriptor[] getParameterDescriptors() {
return parameterDescriptors;
}
public ResultDescriptor getResultDescriptor() {
return resultDescriptor;
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/core/Exists.java
Index: Exists.java
===================================================================
package org.apache.slide.projector.processor.core;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.Processor;
import org.apache.slide.projector.Result;
import org.apache.slide.projector.descriptor.ParameterDescriptor;
import org.apache.slide.projector.descriptor.ResourceValueDescriptor;
import org.apache.slide.projector.descriptor.ResultDescriptor;
import org.apache.slide.projector.descriptor.StateDescriptor;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.value.ObjectValue;
import org.apache.slide.projector.value.Value;
import java.util.Map;
import java.util.logging.Logger;
public class Exists implements Processor {
private static Logger logger = Logger.getLogger(Exists.class.getName());
public final static String INPUT = "input";
public final static String TRUE = "true";
public final static String FALSE = "false";
private final static ResultDescriptor resultDescriptor = new ResultDescriptor(new StateDescriptor[]{
new StateDescriptor(TRUE, new DefaultMessage("exists/state/true")),
new StateDescriptor(FALSE, new DefaultMessage("exists/state/false"))
});
public Result process(Map parameter, Context context) throws Exception {
Value input = (Value)parameter.get(INPUT);
if ( input instanceof ObjectValue && ((ObjectValue)input).getObject() == null ) {
return new Result(FALSE);
}
return new Result(TRUE);
}
public ParameterDescriptor[] getParameterDescriptors() {
return new ParameterDescriptor[]{ new ParameterDescriptor(INPUT, new ParameterMessage("exists/input"), new ResourceValueDescriptor()) }; }
public ResultDescriptor getResultDescriptor() {
return resultDescriptor;
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/core/StringArrayRenderer.java
Index: StringArrayRenderer.java
===================================================================
package org.apache.slide.projector.processor.core;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.descriptor.ArrayValueDescriptor;
import org.apache.slide.projector.descriptor.ParameterDescriptor;
import org.apache.slide.projector.descriptor.ResultEntryDescriptor;
import org.apache.slide.projector.descriptor.StringValueDescriptor;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.processor.SimpleProcessor;
import org.apache.slide.projector.value.ArrayValue;
import org.apache.slide.projector.value.PrintableValue;
import org.apache.slide.projector.value.StringValue;
import org.apache.slide.projector.value.Value;
public class StringArrayRenderer extends SimpleProcessor {
public Value process(Value input, Context context) throws Exception {
Value []array = ((ArrayValue)input).getArray();
StringBuffer buffer = new StringBuffer(1024);
for ( int i = 0; i < array.length; i++ ) {
if ( array[i] instanceof PrintableValue ) {
((PrintableValue)array[i]).print(buffer);
}
}
return new StringValue(buffer.toString());
}
public ParameterDescriptor getParameterDescriptor() {
return new ParameterDescriptor(INPUT, new ParameterMessage("arrayRenderer/input"), new ArrayValueDescriptor(new StringValueDescriptor()));
}
public ResultEntryDescriptor getResultEntryDescriptor() {
return new ResultEntryDescriptor(OUTPUT, new DefaultMessage("arrayRenderer/output"), "*", true);
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/core/URL.java
Index: URL.java
===================================================================
package org.apache.slide.projector.processor.core;
import org.apache.slide.projector.ContentType;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.HttpContext;
import org.apache.slide.projector.ProcessException;
import org.apache.slide.projector.descriptor.ParameterDescriptor;
import org.apache.slide.projector.descriptor.ResultEntryDescriptor;
import org.apache.slide.projector.descriptor.StringValueDescriptor;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ErrorMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.processor.SimpleProcessor;
import org.apache.slide.projector.value.StringValue;
import org.apache.slide.projector.value.Value;
public class URL extends SimpleProcessor {
public Value process(Value input, Context context) throws Exception {
Value output;
if ( context instanceof HttpContext ) {
output = new StringValue(((HttpContext)context).getContextPath() + "/" + ((StringValue)input).toString());
} else {
throw new ProcessException(new ErrorMessage("httpContextRequired"));
}
return output;
}
public ParameterDescriptor getParameterDescriptor() {
return new ParameterDescriptor(INPUT, new ParameterMessage("url/parameter/input"), new StringValueDescriptor());
}
public ResultEntryDescriptor getResultEntryDescriptor() {
return new ResultEntryDescriptor(OUTPUT, new DefaultMessage("url/result/output"), ContentType.DYNAMIC, true);
}
}
1.9 +1 -1 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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ProcessServlet.java 2 Jun 2004 15:35:39 -0000 1.8
+++ ProcessServlet.java 8 Jun 2004 09:10:53 -0000 1.9
@@ -4,8 +4,8 @@
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;
import org.apache.slide.projector.processor.SimpleProcessor;
+import org.apache.slide.projector.processor.core.ExceptionRenderer;
import org.apache.slide.projector.util.ProcessorHelper;
import org.apache.slide.projector.util.StreamHelper;
import org.apache.slide.projector.value.ObjectValue;
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org