Return-Path: Delivered-To: apmail-xml-cocoon-dev-archive@xml.apache.org Received: (qmail 19895 invoked by uid 500); 5 Feb 2002 12:18:41 -0000 Mailing-List: contact cocoon-dev-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: cocoon-dev@xml.apache.org Delivered-To: mailing list cocoon-dev@xml.apache.org Received: (qmail 19882 invoked from network); 5 Feb 2002 12:18:41 -0000 Message-ID: <5E13A1874524D411A876006008CD059F031A14A4@0-mail-1.hpl.hp.com> From: "Butler, Mark" To: "'cocoon-dev@xml.apache.org'" Subject: RE: cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components /deli DeliImpl.java Date: Tue, 5 Feb 2002 12:18:09 -0000 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C1AE3F.2C519000" X-ECS-MailScanner: Found to be clean X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ------_=_NextPart_000_01C1AE3F.2C519000 Content-Type: text/plain; charset="iso-8859-1" Hi Carsten Is this version better - I've just moved exception handling to cover calls to DELI library? Mark > -----Original Message----- > From: Butler, Mark [mailto:Mark_Butler@hplb.hpl.hp.com] > Sent: 05 February 2002 12:09 > To: 'cocoon-dev@xml.apache.org' > Subject: RE: cvs commit: > xml-cocoon2/src/java/org/apache/cocoon/components /deli DeliImpl.java > > > Hi Carsten > > I was just trying to make sure that DELI doesn't take down > Cocoon if it > encounters an error (Berin's and Stefano's criticism) - > errors should be > logged as well. > > We can reinstate the previous code if you prefer? > > Mark > > > -----Original Message----- > > From: Carsten Ziegeler [mailto:cziegeler@s-und-n.de] > > Sent: 05 February 2002 11:38 > > To: cocoon-dev@xml.apache.org > > Subject: RE: cvs commit: > > xml-cocoon2/src/java/org/apache/cocoon/components/deli DeliImpl.java > > > > > > Hi Mark, > > > > I'm not sure if the exception handling introduced by this > check-in is > > really better. In my eyes its worse as now possible > exceptions during > > configuration and contextualization are ignored. > > What do you think? > > > > Carsten > > > > > -----Original Message----- > > > From: butlermh@apache.org [mailto:butlermh@apache.org] > > > Sent: Tuesday, February 05, 2002 11:11 AM > > > To: xml-cocoon2-cvs@apache.org > > > Subject: cvs commit: > > > xml-cocoon2/src/java/org/apache/cocoon/components/deli > DeliImpl.java > > > > > > > > > butlermh 02/02/05 02:10:45 > > > > > > Modified: src/java/org/apache/cocoon/components/deli > > DeliImpl.java > > > Log: > > > Added better exception handling. > > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org > > For additional commands, email: cocoon-dev-help@xml.apache.org > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org > For additional commands, email: cocoon-dev-help@xml.apache.org > ------_=_NextPart_000_01C1AE3F.2C519000 Content-Type: application/octet-stream; name="DeliImpl.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="DeliImpl.java" * * The Apache Software License, Version 1.1 * * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software = itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache Cocoon" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ package org.apache.cocoon.components.deli; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.component.Composable; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.logger.AbstractLoggable; import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.parameters.Parameterizable; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.environment.http.HttpContext; import org.apache.cocoon.environment.Request; import org.apache.cocoon.Constants; import org.apache.cocoon.xml.dom.DOMFactory; import org.apache.cocoon.components.parser.Parser; import java.util.Vector; import java.util.Iterator; import java.util.TreeSet; import java.util.Enumeration; import java.util.Locale; import java.util.Map; import java.util.Set; import java.io.IOException; import java.io.BufferedReader; import java.net.MalformedURLException; import java.security.Principal; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.Text; import javax.servlet.http.HttpServletRequest; import javax.servlet.ServletRequest; import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.ServletContext; import javax.servlet.ServletInputStream; import javax.servlet.RequestDispatcher; import javax.servlet.http.Cookie; import javax.servlet.http.HttpSession; import com.hp.hpl.deli.Profile; import com.hp.hpl.deli.ProfileAttribute; import com.hp.hpl.deli.Workspace; /** * Allows the use of DELI * to provide CC/PP or * UAProf * support. For more details of DELI see the Technical Report * DEL= I: * A Delivery Context Library for CC/PP and UAProf. * * @author Mark H. Butler * @version CVS $ $ $Date: 2002/02/05 10:10:45 $ */ public final class DeliImpl extends AbstractLoggable implements Parameterizable, Deli, Composable, Disposable, Initializable, ThreadSafe, Contextualizable { /** The path to the Cocoon configuration files */ private String defaultPath =3D null; /** The name of the main DELI configuration file */ private String deliConfig =3D = "resources/deli/config/deliConfig.xml"; /** The DELI workspace */ private Workspace workspace; /** The component manager */ protected ComponentManager manager =3D null; /** Parser used to construct the DOM tree to import the profile to = a stylesheet */ Parser parser; /** A context, used to retrieve the path to the configuration file = */ protected CocoonServletContext servletContext; /** Contextualize this class */ public void contextualize(Context context) throws ContextException { org.apache.cocoon.environment.Context ctx =3D = (org.apache.cocoon.environment.Context) = context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT); try { this.servletContext =3D new CocoonServletContext(ctx); } catch (Exception e) { getLogger().error("DELI Exception while creating ServletContext: ", = e); } } /** Compose this class */ public void compose(ComponentManager manager) throws ComponentException { this.manager =3D manager; try { this.parser =3D (Parser)this.manager.lookup(Parser.ROLE); } catch (Exception e) { getLogger().error("DELI Exception while creating parser: ", e); }=09 } /** Configure this class */ public void parameterize(Parameters params) { this.deliConfig =3D params.getParameter("deli-config-file", = this.deliConfig); } /** * Initialize */ public void initialize() throws Exception { try { this.workspace =3D new Workspace(this.servletContext, = this.deliConfig); } catch (Exception e) { getLogger().error("DELI Exception while creating workspace: ", e); } } /** Dispose of this class */ public void dispose() { if (parser !=3D null) this.manager.release((Component)parser); this.parser =3D null; } /** Process a HttpServletRequest and either extract * CC/PP or UAProf information from it and use this information * to resolve a profile or examine the user agent string, match * this using the DELI legacy device database, and use this * information to retrieve the appropriate CC/PP profile. * *@param theRequest The Request. *@return The profile as a vector of profile attributes. *@exception IOException. *@exception ServletException. *@exception Exception. */ public Profile getProfile(Request theRequest) throws IOException, ServletException, Exception { try { CocoonServletRequest servletRequest =3D new = CocoonServletRequest(theRequest); Profile theProfile =3D new Profile(this.workspace, = (HttpServletRequest) servletRequest); return theProfile; } catch (Exception e) { getLogger().error("DELI Exception while retrieving profile: ", e); return null; } } /** Convert a profile stored as a vector of profile attributes * to a DOM tree. * *@param theProfile The profile as a vector of profile attributes. *@return The DOM tree. */ public Document getUACapabilities(Profile theProfile) { try { Document document; Element rootElement; Element attributeNode; Element complexAttributeNode; Text text; document =3D ((DOMFactory)parser).newDocument(); rootElement =3D document.createElementNS(null, "browser"); document.appendChild(rootElement); Iterator profileIter =3D theProfile.iterator(); while (profileIter.hasNext()) { ProfileAttribute p =3D (ProfileAttribute) = profileIter.next(); attributeNode =3D document.createElementNS(null, = p.getAttribute()); rootElement.appendChild(attributeNode); Vector attributeValue =3D p.get(); Iterator complexValueIter =3D attributeValue.iterator(); if (p.getCollectionType().equals("Simple")) { // Simple attribute String value =3D (String) complexValueIter.next(); text =3D document.createTextNode(value); attributeNode.appendChild(text); } else { // Complex attribute e.g. Seq or Bag while (complexValueIter.hasNext()) { String value =3D (String) complexValueIter.next(); complexAttributeNode =3D = document.createElementNS(null, "li"); attributeNode.appendChild(complexAttributeNode); text =3D document.createTextNode(value); complexAttributeNode.appendChild(text); } } } return document; } catch (Exception e) { getLogger().error("DELI Exception while converting profile to DOM = fragment: ", e); return null; } } public Document getUACapabilities(Request theRequest) throws IOException, Exception { return this.getUACapabilities(this.getProfile(theRequest)); } /** * Stub implementation of Servlet Context */ public class CocoonServletContext implements ServletContext { org.apache.cocoon.environment.Context envContext; public = CocoonServletContext(org.apache.cocoon.environment.Context context) { this.envContext =3D context; } public Object getAttribute(String name) { return = envContext.getAttribute(name); } public void setAttribute(String name, Object value) { = envContext.setAttribute(name, value); } public Enumeration getAttributeNames() { return = envContext.getAttributeNames(); } public java.net.URL getResource(String path) throws = MalformedURLException { return envContext.getResource(path);} public String getRealPath(String path) { return = envContext.getRealPath(path); } public String getMimeType(String file) { return = envContext.getMimeType(file); } public String getInitParameter(String name) { return = envContext.getInitParameter(name); } public java.io.InputStream getResourceAsStream(String path){ = return envContext.getResourceAsStream(path);} public ServletContext getContext(String uripath) { return = (null); } public Enumeration getInitParameterNames() {return (null); } public int getMajorVersion() { return (2); } public int getMinorVersion() { return (3); } public RequestDispatcher getNamedDispatcher(String name) { = return (null); } public RequestDispatcher getRequestDispatcher(String path) { = return (null); } public Set getResourcePaths(String path) { return null; } public String getServerInfo() { return (null); } public Servlet getServlet(String name) throws ServletException = { return (null); } public String getServletContextName() { return (null); } public Enumeration getServletNames() { return (null); } public Enumeration getServlets() { return (null); } public void log(String message) {} public void log(Exception exception, String message) {} public void log(String message, Throwable exception) {} public void removeAttribute(String name) {} } /** * Stub implementation of HttpServletRequest */ public class CocoonServletRequest implements HttpServletRequest { Request request; public CocoonServletRequest(Request request) { this.request =3D request; } public String getAuthType(){ return request.getAuthType(); } public long getDateHeader(String s){ return = request.getDateHeader(s); } public String getHeader(String s){ return request.getHeader(s); = } public Enumeration getHeaders(String s){ return = request.getHeaders(s); } public Enumeration getHeaderNames(){ return = request.getHeaderNames(); } public String getMethod(){ return request.getMethod(); } public String getPathInfo(){ return request.getPathInfo(); } public String getPathTranslated(){ return = request.getPathTranslated(); } public String getContextPath(){ return = request.getContextPath(); } public String getQueryString(){ return = request.getQueryString(); } public String getRemoteUser(){ return request.getRemoteUser(); = } public boolean isUserInRole(String s){ return = request.isUserInRole(s); } public String getRequestedSessionId(){ return = request.getRequestedSessionId(); } public String getRequestURI(){ return request.getRequestURI(); = } public String getServletPath(){ return = request.getServletPath(); } public boolean isRequestedSessionIdValid(){ return = request.isRequestedSessionIdValid(); } public boolean isRequestedSessionIdFromCookie(){ return = request.isRequestedSessionIdFromCookie(); } public Object getAttribute(String s){ return = request.getAttribute(s); } public Enumeration getAttributeNames(){ return = request.getAttributeNames(); } public String getCharacterEncoding(){ return = request.getCharacterEncoding(); } public int getContentLength(){ return = request.getContentLength(); } public String getContentType(){ return = request.getContentType(); } public String getParameter(String s){ return = request.getParameter(s); } public Enumeration getParameterNames(){ return = request.getParameterNames(); } public String[] getParameterValues(String s){ return = request.getParameterValues(s); } public String getProtocol(){ return request.getProtocol(); } public String getScheme(){ return request.getScheme(); } public String getServerName(){ return request.getServerName(); = } public int getServerPort(){ return request.getServerPort(); } public String getRemoteAddr(){ return request.getRemoteAddr(); = } public String getRemoteHost(){ return request.getRemoteHost(); = } public void setAttribute(String s, Object obj){ = request.setAttribute(s,obj); } public void removeAttribute(String s){ = request.removeAttribute(s); } public boolean isSecure(){ return request.isSecure(); } public StringBuffer getRequestURL() { return null; } public Map getParameterMap() { return null; } public void setCharacterEncoding(String s) { } public Principal getUserPrincipal(){ return = request.getUserPrincipal(); } public Locale getLocale(){ return request.getLocale(); } public Enumeration getLocales(){ return request.getLocales(); } public String getRealPath(String s){ return null; } public Cookie[] getCookies(){ return null; } public RequestDispatcher getRequestDispatcher(String s){ return = null; } public BufferedReader getReader() throws IOException{ return = null; } public ServletInputStream getInputStream() throws IOException{ = return null; } public HttpSession getSession(boolean flag){ return null; } public HttpSession getSession(){ return null; } public boolean isRequestedSessionIdFromURL(){ return false; } public boolean isRequestedSessionIdFromUrl(){ return false; } public int getIntHeader(String s){ return 0; } } } ------_=_NextPart_000_01C1AE3F.2C519000 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org For additional commands, email: cocoon-dev-help@xml.apache.org ------_=_NextPart_000_01C1AE3F.2C519000--