Return-Path: Mailing-List: contact cocoon-dev-help@xml.apache.org; run by ezmlm Delivered-To: mailing list cocoon-dev@xml.apache.org Received: (qmail 33215 invoked from network); 21 Sep 2000 16:10:31 -0000 Received: from unknown (HELO onclave.com) (208.249.126.103) by locus.apache.org with SMTP; 21 Sep 2000 16:10:31 -0000 Received: from vader [151.204.68.155] by onclave.com with ESMTP (SMTPD32-6.00) id A42730530146; Thu, 21 Sep 2000 12:15:35 -0400 From: "Per Kreipke" To: Subject: Request taglib... Date: Thu, 21 Sep 2000 12:08:17 -0400 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0014_01C023C4.A0609420" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 Importance: Normal X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. ------=_NextPart_000_0014_01C023C4.A0609420 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Attached is some code to add missing functionality to the request taglib in XSPRequestLibrary.java. It includes the following to return a node set of all parameters. public static Element getAllParameterValues( HttpServletRequest request, Document document ) { String[] parameterNames = XSPRequestLibrary.getParameterNames(request); Element newElement = document.createElement("request:all-parameter-values"); for (int i = 0; i < parameterNames.length; i++) { Element paramElement = XSPRequestLibrary.getParameterValues(request, parameterNames[i], document); newElement.appendChild(paramElement); } return(newElement); } It also includes additional functions which might make life easier and the XML produced by the request taglib a little more terse for some applications. I'm sorry, I couldn't actually test a taglib snippet in request.xsl because I haven't built my own taglibs yet. But it should look like somethign like the following (only 'node' return types allowed): XSPRequestLibrary.getAllParameterValues( request, document ) Hope this helps someone. It helped me get request params into my XSL style sheets. Per. ------=_NextPart_000_0014_01C023C4.A0609420 Content-Type: application/octet-stream; name="request.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="request.java" /** Output all the request parameters as an element set, using 'request:all-parameter-values' as the top element name. Example: given request 'page.xml?test=3Dfoo&test=3Dbar&fix=3Dno', = returns element set foo bar no **/ public static Element getAllParameterValues( HttpServletRequest request,=20 Document document ) { String[] parameterNames =3D = XSPRequestLibrary.getParameterNames(request); Element newElement =3D = document.createElement("request:all-parameter-values"); =09 for (int i =3D 0; i < parameterNames.length; i++) { Element paramElement =3D XSPRequestLibrary.getParameterValues(request, = parameterNames[i], document); newElement.appendChild(paramElement); } =09 return(newElement); } =09 /** Output all the request parameters as an element set, using the arg 'topTag' as the name of the enclosing element and = 'valueTag' as the name of the value element if parameters have multiple values. Example: given request 'page.xml?test=3Dfoo&test=3Dbar&fix=3Dno', and = the call 'getAllParameters(request, document, "request", "val")', returns element = set foo bar no **/ public static Element getAllParameters( HttpServletRequest request,=20 Document document, String topTag, String valueTag ) { if (null =3D=3D topTag) topTag =3D "parameters"; =09 if (null =3D=3D valueTag) valueTag =3D "value"; =09 String[] parameterNames =3D = XSPRequestLibrary.getParameterNames(request); Element newElement =3D document.createElement(topTag); =09 for (int i =3D 0; i < parameterNames.length; i++) { Element nameElement; // Handle invalid tag names. HACK! if (!Character.isLetter(parameterNames[i].charAt(0))) nameElement =3D document.createElement("_" + parameterNames[i]); else nameElement =3D document.createElement(parameterNames[i]); =09 String[] values =3D request.getParameterValues(parameterNames[i]); if (values !=3D null) { if (1 < values.length) { for (int j =3D 0; j < values.length; j++) { Element valueElement; if (null =3D=3D valueTag) valueElement =3D = document.createElement("request:parameter-value"); else valueElement =3D document.createElement(valueTag); valueElement.appendChild(document.createTextNode(values[j])); nameElement.appendChild(valueElement); } } else nameElement.appendChild(document.createTextNode(values[0])); } =20 // Build output node hierarchy newElement.appendChild(nameElement); } =09 return(newElement); } /** Shortcut for using default names for top and value elements **/ public static Element getAllParameters( HttpServletRequest request,=20 Document document ) { return(getAllParameters(request, document, null, null)); } /** Shortcut for using default names for value elements **/ public static Element getAllParameters( HttpServletRequest request,=20 Document document, String topTag ) { return(getAllParameters(request, document, topTag, null)); } ------=_NextPart_000_0014_01C023C4.A0609420--