cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From giac...@locus.apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/selection BrowserSelectorFactory.java
Date Thu, 07 Sep 2000 21:38:41 GMT
giacomo     00/09/07 14:38:40

  Modified:    src/org/apache/cocoon/selection Tag: xml-cocoon2
                        BrowserSelectorFactory.java
  Log:
  Added BrowserSelectorFactory contributed by Carsten Ziegeler.
  Some optimizing has been applied by me :)
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.6   +49 -16    xml-cocoon/src/org/apache/cocoon/selection/Attic/BrowserSelectorFactory.java
  
  Index: BrowserSelectorFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/selection/Attic/BrowserSelectorFactory.java,v
  retrieving revision 1.1.2.5
  retrieving revision 1.1.2.6
  diff -u -r1.1.2.5 -r1.1.2.6
  --- BrowserSelectorFactory.java	2000/07/27 21:49:03	1.1.2.5
  +++ BrowserSelectorFactory.java	2000/09/07 21:38:37	1.1.2.6
  @@ -1,33 +1,66 @@
  -/***************************************************************************** 
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        * 
  - * ------------------------------------------------------------------------- * 
  - * This software is published under the terms of the Apache Software License * 
  - * version 1.1, a copy of which has been included  with this distribution in * 
  - * the LICENSE file.                                                         * 
  - *****************************************************************************/ 
  -package org.apache.cocoon.selection; 
  +/*****************************************************************************
  + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  + * ------------------------------------------------------------------------- *
  + * This software is published under the terms of the Apache Software License *
  + * version 1.1, a copy of which has been included  with this distribution in *
  + * the LICENSE file.                                                         *
  + *****************************************************************************/
  +package org.apache.cocoon.selection;
   
   import org.apache.avalon.ConfigurationException;
   
   import org.w3c.dom.DocumentFragment;
  - 
  -/** 
  +import org.w3c.dom.traversal.TreeWalker;
  +import org.w3c.dom.traversal.NodeFilter;
  +import org.w3c.dom.Node;
  +import org.w3c.dom.NamedNodeMap;
  +import org.apache.xerces.dom.TreeWalkerImpl;
  +
  +/**
    * This class generates source code which tests a specific browser pattern
    * agains the requesting user-agent
  - * 
  - * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a> 
  - * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/07/27 21:49:03 $ 
  - */ 
  + *
  + * @author <a href="mailto:cziegeler@sundn.de">Carsten Ziegeler</a>
  + * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  + * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/09/07 21:38:37 $
  +*/
  +
   
   public class BrowserSelectorFactory implements SelectorFactory {
   
  -    public String generateClassSource (String test, String prefix, DocumentFragment conf)

  +    public String generateClassSource (String test, String prefix, DocumentFragment conf)
       throws ConfigurationException {
           return "";
       }
   
       public String generateMethodSource (String test, String prefix, DocumentFragment conf)
       throws ConfigurationException {
  -        return "return true;";
  +        TreeWalker tw = new TreeWalkerImpl (conf, NodeFilter.SHOW_ALL, null, false);
  +        Node node = null;
  +        Node nodeattrname  = null;
  +        Node nodeattruseragent = null;
  +        NamedNodeMap nm = null;
  +
  +        StringBuffer sb = new StringBuffer();
  +         sb.append("if (pattern != null && objectModel.get(\"request\") != null)
{")
  +          .append("javax.servlet.http.HttpServletRequest request = (javax.servlet.http.HttpServletRequest)
objectModel.get(\"request\");")
  +          .append("String userAgent = request.getHeader(\"User-Agent\");");
  +        while ((node = tw.nextNode()) != null) {
  +            if (node.getNodeName().equals("browser") &&
  +                node.getNodeType() == Node.ELEMENT_NODE) {
  +                nm = node.getAttributes();
  +                if (nm != null) {
  +                    nodeattrname = nm.getNamedItem("name");
  +                    nodeattruseragent = nm.getNamedItem("useragent");
  +                    if (nodeattrname != null && nodeattruseragent != null
  +                            && nodeattrname.getNodeValue().equals(test)) {
  +                        sb.append("if (userAgent.indexOf(\"")
  +                          .append(nodeattruseragent.getNodeValue())
  +                          .append("\") != -1) return true;");
  +                    }
  +                }
  +            }
  +        }
  +        return sb.append("} return false;").toString();
       }
   }
  
  
  

Mime
View raw message