001: /**
002: * Generic XSLT Pre Processor
003: */package org.enhydra.util.xsl;
004:
005: import java.util.Enumeration;
006:
007: import org.enhydra.util.RequestPreProcessor;
008:
009: import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
010: import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
011: import com.lutris.appserver.server.httpPresentation.PageRedirectException;
012: import com.lutris.logging.LogChannel;
013: import com.lutris.logging.Logger;
014: import com.lutris.util.Config;
015: import com.lutris.util.ConfigException;
016: import com.lutris.util.KeywordValueException;
017:
018: /**
019: * @author Slobodan Vujasinovic
020: *
021: */
022: public class GenericXSLTPreProcessor implements RequestPreProcessor {
023:
024: /**
025: * Pre Processor Name
026: */
027: private String name = null;
028:
029: private String PROPERTY_PREFIX_PARAM_NAME = "Prefix";
030: private String DEFAULT_PROPERTY_PREFIX_PARAM_VALUE = "style";
031: private String propsPrefix = DEFAULT_PROPERTY_PREFIX_PARAM_VALUE;
032:
033: /**
034: * LogChannel used by ResponsePostProcessor
035: */
036: private LogChannel logChannel;
037:
038: public GenericXSLTPreProcessor() {
039: super ();
040: }
041:
042: public GenericXSLTPreProcessor(LogChannel logChannel) {
043: super ();
044: this .logChannel = logChannel;
045: }
046:
047: /*
048: * (non-Javadoc)
049: *
050: * @see org.enhydra.util.RequestPreProcessor#configure(com.lutris.util.Config)
051: */
052: public void configure(Config config) {
053: try {
054: propsPrefix = config.getString(PROPERTY_PREFIX_PARAM_NAME,
055: DEFAULT_PROPERTY_PREFIX_PARAM_VALUE);
056: } catch (ConfigException e) {
057: propsPrefix = DEFAULT_PROPERTY_PREFIX_PARAM_VALUE;
058: logChannel
059: .write(
060: Logger.WARNING,
061: "Generic XSLT Pre Processor ("
062: + name
063: + ") - configured with default parameter settings!",
064: e);
065: }
066: }
067:
068: /*
069: * (non-Javadoc)
070: *
071: * @see org.enhydra.util.RequestPreProcessor#process(com.lutris.appserver.server.httpPresentation.HttpPresentationComms)
072: */
073: public boolean process(HttpPresentationComms comms)
074: throws PageRedirectException {
075:
076: try {
077: try {
078: Enumeration en = comms.request.getParameterNames();
079: while (en.hasMoreElements()) {
080: String paramName = (String) en.nextElement();
081: if (paramName != null
082: && paramName.startsWith(propsPrefix + ".")) {
083: String paramValue = comms.request
084: .getParameter(paramName);
085: if (paramValue != null)
086: comms.sessionData
087: .set(paramName, paramValue);
088: }
089: }
090: } catch (HttpPresentationException e) {
091: // TODO Auto-generated catch block
092: e.printStackTrace();
093: }
094: } catch (KeywordValueException e) {
095: // TODO Auto-generated catch block
096: e.printStackTrace();
097: }
098: return false;
099: }
100:
101: /*
102: * (non-Javadoc)
103: *
104: * @see org.enhydra.util.RequestPreProcessor#setName(java.lang.String)
105: */
106: public void setName(String name) {
107: this .name = name;
108: }
109:
110: /*
111: * (non-Javadoc)
112: *
113: * @see org.enhydra.util.RequestPreProcessor#getName()
114: */
115: public String getName() {
116: return name;
117: }
118:
119: /*
120: * (non-Javadoc)
121: *
122: * @see org.enhydra.util.RequestPreProcessor#setLogChannel()
123: */
124: public void setLogChannel(LogChannel logChannel) {
125: this .logChannel = logChannel;
126: }
127:
128: /*
129: * (non-Javadoc)
130: *
131: * @see org.enhydra.util.RequestPreProcessor#getLogChannel()
132: */
133: public LogChannel getLogChannel() {
134: return logChannel;
135: }
136:
137: /*
138: * (non-Javadoc)
139: *
140: * @see java.lang.Object#clone()
141: */
142: public Object clone() {
143: GenericXSLTPreProcessor gxpp = new GenericXSLTPreProcessor(this
144: .getLogChannel());
145: gxpp.propsPrefix = this.propsPrefix;
146: gxpp.name = this.name;
147: return gxpp;
148: }
149:
150: }
|