vgritsenko 01/12/13 08:56:53 Modified: src/org/apache/cocoon/generation Tag: cocoon_20_branch RequestGenerator.java Log: Applied patch from MIYABE Tatsuhiko [[EMAIL PROTECTED]] Added configuration-time parameters Updated code to not use deprecated methods Revision Changes Path No revision No revision 1.3.2.5 +58 -12 xml-cocoon2/src/org/apache/cocoon/generation/RequestGenerator.java Index: RequestGenerator.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/generation/RequestGenerator.java,v retrieving revision 1.3.2.4 retrieving revision 1.3.2.5 diff -u -r1.3.2.4 -r1.3.2.5 --- RequestGenerator.java 2001/10/11 08:56:12 1.3.2.4 +++ RequestGenerator.java 2001/12/13 16:56:53 1.3.2.5 @@ -8,45 +8,82 @@ package org.apache.cocoon.generation; import org.apache.avalon.excalibur.pool.Recyclable; +import org.apache.avalon.framework.parameters.Parameterizable; +import org.apache.avalon.framework.parameters.Parameters; +import org.apache.avalon.framework.parameters.ParameterException; import org.apache.cocoon.Constants; +import org.apache.cocoon.ProcessingException; import org.apache.cocoon.environment.Request; +import org.apache.cocoon.environment.SourceResolver; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; +import java.io.IOException; import java.util.Enumeration; import java.util.Iterator; +import java.util.Map; /** + * Generates an XML representation of the incoming request. + * <p> + * <b>Configuration options:</b> + * <dl> + * <dt> <i>container-encoding</i> (optional) + * <dd> The encoding used by container. Default value is ISO-8859-1. + * <dt> <i>form-encoding</i> (optional) + * <dd> The supposed encoding of the request parameter. Default is null. + * </dl> + * These configuration options supported in both declaration and use time. * * @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a> * (Apache Software Foundation, Exoffice Technologies) * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a> - * @version CVS $Revision: 1.3.2.4 $ $Date: 2001/10/11 08:56:12 $ + * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> + * @version CVS $Revision: 1.3.2.5 $ $Date: 2001/12/13 16:56:53 $ */ -public class RequestGenerator extends ServletGenerator implements Recyclable { +public class RequestGenerator extends ServletGenerator implements Parameterizable, Recyclable { /** The URI of the namespace of this generator. */ private String URI="http://xml.apache.org/cocoon/requestgenerator/2.0"; + private String global_container_encoding; + private String global_form_encoding; + private String container_encoding; + private String form_encoding; + + public void parameterize(Parameters parameters) + throws ParameterException { + // super.parameterize(parameters); + + global_container_encoding = parameters.getParameter("container-encoding", "ISO-8859-1"); + global_form_encoding = parameters.getParameter("form-encoding", null); + } + + public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) + throws ProcessingException, SAXException, IOException { + super.setup(resolver, objectModel, src, par); + + container_encoding = par.getParameter("container-encoding", global_container_encoding); + form_encoding = par.getParameter("form-encoding", global_form_encoding); + } /** * Generate XML data. */ public void generate() throws SAXException { - Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT); this.contentHandler.startDocument(); this.contentHandler.startPrefixMapping("",URI); AttributesImpl attr=new AttributesImpl(); - this.attribute(attr,"target",request.getRequestURI()); + this.attribute(attr,"target", request.getRequestURI()); this.attribute(attr,"source", (this.source != null ? this.source : "")); - this.start("request",attr); + this.start("request", attr); this.data("\n"); this.data("\n"); this.data(" "); - this.start("requestHeaders",attr); + this.start("requestHeaders", attr); this.data("\n"); Enumeration headers=request.getHeaderNames(); while (headers.hasMoreElements()) { @@ -77,7 +114,17 @@ if (values!=null) for (int x=0; x<values.length; x++) { this.data(" "); this.start("value",attr); - this.data(values[x]); + if (form_encoding != null) { + try { + this.data(new String(values[x].getBytes(container_encoding), + form_encoding)); + } catch(java.io.UnsupportedEncodingException uee) { + throw new RuntimeException("Unsupported Encoding Exception: " + + uee.getMessage()); + } + } else { + this.data(values[x]); + } this.end("value"); this.data("\n"); } @@ -93,13 +140,12 @@ this.data(" "); this.start("configurationParameters",attr); this.data("\n"); - Iterator confparams=super.parameters.getParameterNames(); - while (confparams.hasNext()) { - String parameter=(String)confparams.next(); - this.attribute(attr,"name",parameter); + String[] confparams=super.parameters.getNames(); + for (int i=0; i<confparams.length; i++) { + this.attribute(attr, "name", confparams[i]); this.data(" "); this.start("parameter",attr); - this.data(super.parameters.getParameter(parameter,"")); + this.data(super.parameters.getParameter(confparams[i], "")); this.end("parameter"); this.data("\n"); }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]