ktlili      2005/07/11 17:32:26 CEST

  Modified files:
    war/src/conf         en_US.properties 
    war/src/java/com/jahia/clipping/struts SelectPartAction.java 
                                           SelectPartForm.java 
    war/src/java/com/jahia/clipping/util DomUtilities.java 
    war/src/java/com/jahia/clipping/web/html/Impl/ExtractorFilter 
                                                                  
AbsctractExtractoreFilter.java 
    war/src/java/com/jahia/clipping/web/http/impl 
                                                  HTMLUnitProcessor.java 
    war/src/webapp/jsp/actions selectPartAction.jsp 
  Added files:
    war/src/java/com/jahia/clipping/util Constants.java 
    war/src/java/com/jahia/clipping/web/html/Impl/ExtractorFilter 
                                                                  
XPathExtractorFilter.java 
    war/src/java/com/jahia/clipping/web/http/impl 
                                                  SimpleHTMLUnitProcessor.java 
    war/src/webapp/jsp/templates webBrowser.jsp 
    war/src/webapp/jsp   testHeader.jsp 
  Log:
  - add XPath based filter
  
  Revision  Changes    Path
  1.19      +2 -0      webclip_builder/war/src/conf/en_US.properties
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/conf/en_US.properties.diff?r1=1.18&r2=1.19&f=h
  1.14      +24 -15    
webclip_builder/war/src/java/com/jahia/clipping/struts/SelectPartAction.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/struts/SelectPartAction.java.diff?r1=1.13&r2=1.14&f=h
  1.4       +21 -1     
webclip_builder/war/src/java/com/jahia/clipping/struts/SelectPartForm.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/struts/SelectPartForm.java.diff?r1=1.3&r2=1.4&f=h
  1.1       +101 -0    
webclip_builder/war/src/java/com/jahia/clipping/util/Constants.java (new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/util/Constants.java?rev=1.1&content-type=text/plain
  1.7       +4 -3      
webclip_builder/war/src/java/com/jahia/clipping/util/DomUtilities.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/util/DomUtilities.java.diff?r1=1.6&r2=1.7&f=h
  1.3       +21 -0     
webclip_builder/war/src/java/com/jahia/clipping/web/html/Impl/ExtractorFilter/AbsctractExtractoreFilter.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/web/html/Impl/ExtractorFilter/AbsctractExtractoreFilter.java.diff?r1=1.2&r2=1.3&f=h
  1.1       +113 -0    
webclip_builder/war/src/java/com/jahia/clipping/web/html/Impl/ExtractorFilter/XPathExtractorFilter.java
 (new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/web/html/Impl/ExtractorFilter/XPathExtractorFilter.java?rev=1.1&content-type=text/plain
  1.16      +25 -23    
webclip_builder/war/src/java/com/jahia/clipping/web/http/impl/HTMLUnitProcessor.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/web/http/impl/HTMLUnitProcessor.java.diff?r1=1.15&r2=1.16&f=h
  1.1       +548 -0    
webclip_builder/war/src/java/com/jahia/clipping/web/http/impl/SimpleHTMLUnitProcessor.java
 (new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/web/http/impl/SimpleHTMLUnitProcessor.java?rev=1.1&content-type=text/plain
  1.6       +8 -1      
webclip_builder/war/src/webapp/jsp/actions/selectPartAction.jsp
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/webapp/jsp/actions/selectPartAction.jsp.diff?r1=1.5&r2=1.6&f=h
  1.1       +8 -0      
webclip_builder/war/src/webapp/jsp/templates/webBrowser.jsp (new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/webapp/jsp/templates/webBrowser.jsp?rev=1.1&content-type=text/plain
  1.1       +42 -0     webclip_builder/war/src/webapp/jsp/testHeader.jsp (new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/webapp/jsp/testHeader.jsp?rev=1.1&content-type=text/plain
  
  
  
  Index: en_US.properties
  ===================================================================
  RCS file: /home/cvs/repository/webclip_builder/war/src/conf/en_US.properties,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- en_US.properties  11 Jul 2005 12:31:09 -0000      1.18
  +++ en_US.properties  11 Jul 2005 15:32:24 -0000      1.19
  @@ -151,6 +151,7 @@
   select.clippingMethod = Clipping method
   select.typeContent = Type of content
   select.tagName = Tag name
  +select.xpath.enter = Enter a valid xpath
   select.typeContent.dynamic = Dynamic
   select.typeContent.static = Static
   select.clippingMethod.manual = Manual
  @@ -158,6 +159,7 @@
   select.clippingMethod.rules = Rules
   select.clippingMethod.form = Form extractor
   select.clippingMethod.link = Link ectarctor
  +select.clippingMethod.xPath = XPath
   select.clippingMethod.table = Table extrator
   select.clippingMethod.filter = Filter
   select.changeClippingMethod = changeClippingMethod
  
  
  
  Index: SelectPartAction.java
  ===================================================================
  RCS file: 
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/struts/SelectPartAction.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- SelectPartAction.java     11 Jul 2005 12:31:10 -0000      1.13
  +++ SelectPartAction.java     11 Jul 2005 15:32:24 -0000      1.14
  @@ -14,7 +14,6 @@
   import com.jahia.clipping.web.html.Impl.HTMLParser.*;
   import com.jahia.clipping.web.html.Impl.ExtractorFilter.*;
   
  -
   /**
    *  Description of the Class
    *
  @@ -53,13 +52,23 @@
                return map;
        }
   
  -        public ActionForward view(ActionMapping actionMapping, ActionForm 
actionForm, HttpServletRequest httpServletRequest, HttpServletResponse 
httpServletResponse) {
  -           logger.debug("[ View ]");
  -           AbstractWizardForm form = (AbstractWizardForm) actionForm;
  -           
getWebBrowserForm(httpServletRequest).setShow(Constants.WEB_BROWSER_SHOW_LAST_DOCUMENT);
   
  -           return actionMapping.getInputForward();
  -   }
  +     /**
  +      *  Description of the Method
  +      *
  +      [EMAIL PROTECTED]  actionMapping        Description of Parameter
  +      [EMAIL PROTECTED]  actionForm           Description of Parameter
  +      [EMAIL PROTECTED]  httpServletRequest   Description of Parameter
  +      [EMAIL PROTECTED]  httpServletResponse  Description of Parameter
  +      [EMAIL PROTECTED]                      Description of the Returned 
Value
  +      */
  +     public ActionForward view(ActionMapping actionMapping, ActionForm 
actionForm, HttpServletRequest httpServletRequest, HttpServletResponse 
httpServletResponse) {
  +             logger.debug("[ View ]");
  +             AbstractWizardForm form = (AbstractWizardForm) actionForm;
  +             
getWebBrowserForm(httpServletRequest).setShow(Constants.WEB_BROWSER_SHOW_LAST_DOCUMENT);
  +
  +             return actionMapping.getInputForward();
  +     }
   
   
   
  @@ -112,7 +121,9 @@
                }
                //table
                else if (typeFilter.equalsIgnoreCase("4")) {
  -                     filter = new SimpleExtractorFilter(selectedContent);
  +                     filter = new XPathExtractorFilter();
  +                     String xPath = selectPartForm.getWebClippingXPath();
  +                     ((XPathExtractorFilter) filter).setXPahKey(xPath);
                }
                //link
                else {
  @@ -120,8 +131,8 @@
                }
   
                logger.debug("[ Selected content is " + selectedContent + " ]");
  -              //  int mode = Integer.parseInt(typeContent);
  -              //  filter.setMode(mode);
  +             //  int mode = Integer.parseInt(typeContent);
  +             //  filter.setMode(mode);
                bean.setFilter(filter);
   
                return actionMapping.findForward("preview");
  @@ -150,7 +161,6 @@
                ClipperBean bean = getClipperBean(httpServletRequest);
   
   
  -
                //set the selected part
                String selectedContent = "view filter not available";
                selectPartForm.setSelectedContent(selectedContent);
  @@ -162,9 +172,9 @@
                ChewExtractorFilter filter = new ChewExtractorFilter();
                //set the key of the filter
                String hashKey = hashSelectedPart;
  -                String tagName = selectPartForm.getWebClippingTagName();
  +             String tagName = selectPartForm.getWebClippingTagName();
                filter.setHashKey(hashKey);
  -                filter.setTagNameKey(tagName);
  +             filter.setTagNameKey(tagName);
   
                // set the filter
                bean.setFilter(filter);
  @@ -223,7 +233,7 @@
                // get the document
                //HTMLDocument htmlDocument = 
getHTMLDocument(httpServletRequest, httpServletResponse);
                
//selectPartForm.setBodyContent(htmlDocument.getTransformedDocumentAsString());
  -                
getWebBrowserForm(httpServletRequest).setShow(Constants.WEB_BROWSER_SHOW_LAST_DOCUMENT);
  +             
getWebBrowserForm(httpServletRequest).setShow(Constants.WEB_BROWSER_SHOW_LAST_DOCUMENT);
   
                return actionMapping.getInputForward();
        }
  @@ -289,7 +299,6 @@
   
   
   
  -
        /**
         *  Description of the Method
         *
  
  
  
  Index: SelectPartForm.java
  ===================================================================
  RCS file: 
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/struts/SelectPartForm.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SelectPartForm.java       11 Jul 2005 12:31:10 -0000      1.3
  +++ SelectPartForm.java       11 Jul 2005 15:32:24 -0000      1.4
  @@ -20,6 +20,7 @@
        private String webClippingTypeContent;
        private String webClippingPartHashCode;
        private String webClippingTagName;
  +     private String webClippingXPath;
   
   
        /**
  @@ -94,6 +95,16 @@
   
   
        /**
  +      *  Sets the WebClippingXPath attribute of the SelectPartForm object
  +      *
  +      [EMAIL PROTECTED]  webClippingXPath  The new WebClippingXPath value
  +      */
  +     public void setWebClippingXPath(String webClippingXPath) {
  +             this.webClippingXPath = webClippingXPath;
  +     }
  +
  +
  +     /**
         *  Gets the Id attribute of the SelectPartForm object
         *
         [EMAIL PROTECTED]    The Id value
  @@ -185,6 +196,16 @@
   
   
        /**
  +      *  Gets the WebClippingXPath attribute of the SelectPartForm object
  +      *
  +      [EMAIL PROTECTED]    The WebClippingXPath value
  +      */
  +     public String getWebClippingXPath() {
  +             return webClippingXPath;
  +     }
  +
  +
  +     /**
         *  Description of the Method
         *
         [EMAIL PROTECTED]  actionMapping       Description of Parameter
  @@ -218,5 +239,4 @@
   
        }
   
  -
   }
  
  
  
  Index: Constants.java
  ====================================================================
  package com.jahia.clipping.util;
  
  public class Constants {
      public static final String CLIPPER_BEAN = "clipperBean";
      public static final String URL_MAP = "urlMap";
      public static final String FIRST_URL_HASH = "userHash";
      public static final String FIRST_URL_FROM = "userFrom";
  
      //encoding
      public static String ENCODING_ISO = "ISO-8859-1";
      public static String ENCODING_UTF = "UTF-8";
  
      // Attribut identifier
      public static String TARGET_URL = "targetUrl";
      public static String RECORDING = "recording";
      public static String HTTPSTATE = "webClipping_httpState";
      public static String SIMPLE_WEBCLIENT = "webClipping_webClient";
      public static String ADVANCED_WEBCLIENT = "webClipping_webClient";
      public static String LAST_URL = "webClipping_lastUrl";
      public static String USER = "user";
      public static Boolean TRUE = Boolean.TRUE;
      public static Boolean FALSE = Boolean.FALSE;
  
      public static String JAVASCRIPT_LOCATION = "location";
      public static String[] JAVASCRIPT_EVENT_NAMES_ARRAY = {
              "onAbort",
              // Executes JavaScript code when the user aborts the loading of 
an image.
              "onBlur",
              // Executes JavaScript code when a form element loses focus or 
when a window or frame loses focus.
              "onChange",
              // Executes JavaScript code when a Select, Text, or Textarea 
field loses focus and its value has been modified
              "onClick",
              // Executes JavaScript code when an object on a form is clicked.
              "onDblClick",
              // Executes JavaScript code when the user double-clicks a form 
element or a link.
              "onDragDrop",
              // Executes JavaScript code when the user drops an object onto 
the browser window, such as dropping a file.
              "onError",
              // Executes JavaScript code when the loading of a document or 
image causes an error.
              "onFocus",
              // Executes JavaScript code when a window, frame, or frameset 
receives focus or when a form element receives input focus.
              "onKeyDown",
              // Executes JavaScript code when the user depresses a key.
              "onKeyPress",
              // Executes JavaScript code when the user presses or holds down a 
key.
              "onKeyUp",
              // Executes JavaScript code when the user releases a key.
              "onLoad",
              // Executes JavaScript code when the browser finishes loading a 
window or all frames within a FRAMESET tag.
              "onMouseDown",
              // Executes JavaScript code when the user depresses a mouse 
button.
              "onMouseMove",
              // Executes JavaScript code when the user moves the cursor.
              "onMouseOut",
              // Executes JavaScript code each time the mouse pointer leaves an 
area (client-side image map) or link from inside that area or link.
              "onMouseOver",
              // Executes JavaScript code once each time the mouse pointer 
moves over an object or area from outside that object or area.
              "onMouseUp",
              // Executes JavaScript code when the user releases a mouse button.
              "onMove",
              // Executes JavaScript code when the user or script moves a 
window or frame.
              "onReset",
              // Executes JavaScript code when a user resets a form (clicks a 
Reset button).
              "onResize",
              // Executes JavaScript code when a user or script resizes a 
window or frame.
              "onSelect",
              // Executes JavaScript code when a user selects some of the text 
within a text or textarea field.
              "onSubmit",
              // Executes JavaScript code when a user submits a form.
              "onUnload",
              // Executes JavaScript code when the user exits a document.
      };
  
      public static String NOT_URL[] = {"javascript:", "mailto:";, "about:"};
  
      public static int URLENCODER_TYPE_LINK = 0;
      public static int URLENCODER_TYPE_FORM = 1;
      public static int URLENCODER_TYPE_JAVASCRIPT = 2;
      public static int URLENCODER_TYPE_METALINK = 3;
  
      //Value for from
      public static String FROM_LINK = "link";
      public static String FROM_FORM = "submittedForm";
      public static String FROM_META = "metaLink";
  
      //possible value of type atrtibute of input element
      public static String NO_VALUE_FOUNDED = "no_value_Found";
      public static String TYPE_TEXT = "text";
      public static String TYPE_BUTTON = "text";
      public static String TYPE_PASSWORD = "password";
      public static String TYPE_CHECKBOX = "checkbox";
      public static String TYPE_RADIO = "radio";
      public static String TYPE_SUBMIT = "submit";
      public static String TYPE_RESET = "reset";
      public static String TYPE_FILE = "file";
      public static String TYPE_HIDDEN = "hidden";
      public static String TYPE_IMAGE = "image";
      public static String TYPE_SELECT = "select";
  
  
  }
  
  
  
  Index: DomUtilities.java
  ===================================================================
  RCS file: 
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/util/DomUtilities.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DomUtilities.java 28 Jun 2005 15:42:30 -0000      1.6
  +++ DomUtilities.java 11 Jul 2005 15:32:24 -0000      1.7
  @@ -1,14 +1,15 @@
   package com.jahia.clipping.util;
   
  +import java.io.*;
  +
  +import javax.xml.parsers.*;
   import javax.xml.transform.*;
   import javax.xml.transform.dom.*;
   import javax.xml.transform.stream.*;
   import javax.xml.xpath.*;
  -import org.w3c.dom.*;
  -import javax.xml.parsers.*;
  +
   import org.w3c.dom.*;
   import org.xml.sax.*;
  -import java.io.*;
   
   /**
    *  Utilities for Dom
  
  
  
  Index: XPathExtractorFilter.java
  ====================================================================
  package com.jahia.clipping.web.html.Impl.ExtractorFilter;
  
  import java.io.*;
  
  import com.jahia.clipping.web.html.*;
  import com.jahia.clipping.web.html.Impl.*;
  import org.xml.sax.*;
  import com.jahia.clipping.util.*;
  import javax.xml.parsers.*;
  import javax.xml.transform.*;
  import javax.xml.transform.dom.*;
  import javax.xml.transform.stream.*;
  import javax.xml.xpath.*;
  import org.apache.xerces.dom.*;
  
  import org.w3c.dom.*;
  import org.xml.sax.*;
  
  /**
   *  Description of the Class
   *
   [EMAIL PROTECTED]    Tlili Khaled
   */
  public class XPathExtractorFilter extends AbsctractExtractoreFilter {
        private int mode;
        private static final String XPATH_KEY = "xPathKey";
        private static org.apache.log4j.Logger logger = 
org.apache.log4j.Logger.getLogger(XPathExtractorFilter.class);
  
  
        /**
         *  Sets the Mode attribute of the XPathExtractorFilter object
         *
         [EMAIL PROTECTED]  mode  The new Mode value
         */
        public void setMode(int mode) {
                this.mode = mode;
        }
  
  
  
        /**
         *  Sets the XPahKey attribute of the XPathExtractorFilter object
         *
         [EMAIL PROTECTED]  xPathKey  The new XPahKey value
         */
        public void setXPahKey(String xPathKey) {
                super.addKeyPart(XPATH_KEY, xPathKey);
        }
  
  
        /**
         *  Gets the Mode attribute of the XPathExtractorFilter object
         *
         [EMAIL PROTECTED]    The Mode value
         */
        public int getMode() {
                return mode;
        }
  
  
        /**
         *  Gets the XPahKey attribute of the XPathExtractorFilter object
         *
         [EMAIL PROTECTED]    The XPahKey value
         */
        public String getXPahKey() {
                return super.getKeyPart(XPATH_KEY);
        }
  
  
        /**
         *  Gets the SelectedPart attribute of the XPathExtractorFilter object
         *
         [EMAIL PROTECTED]  doc  Description of Parameter
         [EMAIL PROTECTED]      The SelectedPart value
         */
        public String getSelectedPart(HTMLDocument doc) {
                String html = doc.getUserDocumentAsString();
                try {
                        // Get default parser
                        HTMLParser parser = new DefaultHTMLParser();
  
                        // build the transformed document
                        org.w3c.dom.Document w3cDoc = parser.parse(html);
                        if (w3cDoc == null) {
                                logger.error("[Parsing failed !!!!]");
                        }
                        else {
                                logger.debug("[Parsing finish whith succes 
!!!!]");
                        }
                        NodeList list = DomUtilities.getNodeListByXPath(w3cDoc, 
this.getXPahKey());
                        Document selectedPartDoc = new 
org.apache.xerces.dom.DocumentImpl();
                        Element root = selectedPartDoc.createElement("div");
                        for (int i = 0; i < list.getLength(); i++) {
                                Node node = list.item(i).cloneNode(true);
                                Node clone = selectedPartDoc.importNode(node, 
true);
                                root.appendChild(clone);
                        }
  
                        return 
DomUtilities.getDocumentAsString(selectedPartDoc);
                }
                catch (SAXException ex) {
  
                        ex.printStackTrace();
                        return "Error has occured: " + this.getXPahKey();
                }
                catch (IOException ex) {
                        ex.printStackTrace();
                        return "Error has occured: " + this.getXPahKey();
                }
        }
  
  }
  
  
  
  Index: AbsctractExtractoreFilter.java
  ===================================================================
  RCS file: 
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/web/html/Impl/ExtractorFilter/AbsctractExtractoreFilter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbsctractExtractoreFilter.java    11 Jul 2005 12:31:12 -0000      1.2
  +++ AbsctractExtractoreFilter.java    11 Jul 2005 15:32:25 -0000      1.3
  @@ -10,6 +10,17 @@
    */
   public abstract class AbsctractExtractoreFilter implements ExtractorFilter {
        private Map keyMap = new Hashtable();
  +     private String name;
  +
  +
  +     /**
  +      *  Sets the Name attribute of the AbsctractExtractoreFilter object
  +      *
  +      [EMAIL PROTECTED]  name  The new Name value
  +      */
  +     public void setName(String name) {
  +             this.name = name;
  +     }
   
   
        /**
  @@ -34,6 +45,16 @@
   
   
        /**
  +      *  Gets the Name attribute of the AbsctractExtractoreFilter object
  +      *
  +      [EMAIL PROTECTED]    The Name value
  +      */
  +     public String getName() {
  +             return name;
  +     }
  +
  +
  +     /**
         *  Adds a feature to the Key attribute of the AbsctractExtractoreFilter
         *  object
         *
  
  
  
  Index: SimpleHTMLUnitProcessor.java
  ====================================================================
  package com.jahia.clipping.web.http.impl;
  
  import java.io.*;
  import java.net.*;
  import java.util.*;
  
  import com.gargoylesoftware.htmlunit.*;
  import com.gargoylesoftware.htmlunit.html.*;
  import com.jahia.clipping.Bean.*;
  import com.jahia.clipping.util.*;
  import com.jahia.clipping.web.http.*;
  import org.apache.commons.httpclient.*;
  
  /**
   *  Description of the Class
   *
   [EMAIL PROTECTED]    Tlili Khaled
   */
  public class SimpleHTMLUnitProcessor implements HTMLClient {
        // Url to process
        /**
         *  Description of the Field
         */
        protected UrlBean urlBean;
        /**
         *  Description of the Field
         */
        protected boolean javascriptEnable;
  
        //Proxy
        /**
         *  Description of the Field
         */
        protected String proxyHost;
        /**
         *  Description of the Field
         */
        protected int proxyPort = 0;
  
        // Client to use
        /**
         *  Description of the Field
         */
        protected WebClient webClient = null;
        /**
         *  Description of the Field
         */
        protected RefreshHandler refreshHandler_;
        /**
         *  Description of the Field
         */
        protected Header[] headers;
  
        // Resulting page;
        /**
         *  Description of the Field
         */
        protected HtmlPage currentPage_;
  
        //List of name of the frame includind in the page
        /**
         *  Description of the Field
         */
        protected List allNameFrame = new ArrayList();
  
        //Method to call: Get, post,...
        /**
         *  Description of the Field
         */
        protected SubmitMethod method = null;
  
        // resultiing htmlDocument
        /**
         *  Description of the Field
         */
        protected String finalUrl;
        /**
         *  Description of the Field
         */
        protected String htmlAsString;
        /**
         *  Description of the Field
         */
        protected String responseCharSet;
  
        /**
         *  Description of the Field
         */
        protected boolean errorHasOccured = false;
        /**
         *  Description of the Field
         */
        protected static org.apache.log4j.Logger logger = 
org.apache.log4j.Logger.getLogger(SimpleHTMLUnitProcessor.class);
  
  
        /**
         *  Constructor for the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]  headers     Description of Parameter
         [EMAIL PROTECTED]  httpMethod  Description of Parameter
         [EMAIL PROTECTED]  uBean       Description of Parameter
         */
        public SimpleHTMLUnitProcessor(Header[] headers, String httpMethod, 
UrlBean uBean) {
                this.setHeaders(headers);
                setMethod(httpMethod);
                setUrlBean(uBean);
        }
  
  
        /**
         *  Sets the UrlBean attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]  urlBean  The new UrlBean value
         */
        public void setUrlBean(UrlBean urlBean) {
                this.urlBean = urlBean;
        }
  
  
        /**
         *  Sets the Method attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]  method  The new Method value
         */
        public void setMethod(String method) {
                if (method.equalsIgnoreCase("GET")) {
                        this.method = SubmitMethod.GET;
                }
                else if (method.equalsIgnoreCase("POST")) {
                        this.method = SubmitMethod.POST;
                }
                else {
                        logger.error("[ Method " + method + " unknown]");
                }
  
        }
  
  
        /**
         *  Sets the WebClient attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]  webClient  The new WebClient value
         */
        public void setWebClient(Object webClient) {
                this.webClient = (WebClient) webClient;
        }
  
  
  
        /**
         *  Sets the ProxyPort attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]  proxyPort  The new ProxyPort value
         */
        public void setProxyPort(int proxyPort) {
                this.proxyPort = proxyPort;
        }
  
  
        /**
         *  Sets the Proxy attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]  proxy  The new Proxy value
         */
        public void setProxyHost(String proxy) {
                this.proxyHost = proxy;
        }
  
  
        /**
         *  Sets the HtmlAsString attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]  htmlAsString  The new HtmlAsString value
         */
        public void setHtmlAsString(String htmlAsString) {
                this.htmlAsString = htmlAsString;
  
        }
  
  
        /**
         *  Sets the FinalUrl attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]  finalUrl  The new FinalUrl value
         */
        public void setFinalUrl(String finalUrl) {
                this.finalUrl = finalUrl;
        }
  
  
        /**
         *  Sets the Header attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]  headers  The new Headers value
         */
        public void setHeaders(Header[] headers) {
                this.headers = headers;
        }
  
  
        /**
         *  Sets the ResponseCharSet attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]  responseCharSet  The new ResponseCharSet value
         */
        public void setResponseCharSet(String responseCharSet) {
                this.responseCharSet = responseCharSet;
        }
  
  
        /**
         *  Gets the UrlBean attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]    The UrlBean value
         */
        public UrlBean getUrlBean() {
                return urlBean;
        }
  
  
        /**
         *  Gets the Method attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]    The Method value
         */
        public SubmitMethod getSubmitMethod() {
                return method;
        }
  
  
        /**
         *  Gets the Method attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]    The Method value
         */
        public String getMethod() {
                return method.getName();
        }
  
  
        /**
         *  Gets the WebClient attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]    The WebClient value
         */
        public WebClient getWebClient() {
                return webClient;
        }
  
  
  
        /**
         *  Gets the ProxyPort attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]    The ProxyPort value
         */
        public int getProxyPort() {
                return proxyPort;
        }
  
  
        /**
         *  Gets the Proxy attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]    The Proxy value
         */
        public String getProxyHost() {
                return proxyHost;
        }
  
  
        /**
         *  Gets the AllNameFrame attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]    The AllNameFrame value
         */
        public List getAllNameFrame() {
                return allNameFrame;
        }
  
  
        /**
         *  Gets the HtmlAsString attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]    The HtmlAsString value
         */
        public String getHtmlAsString() {
                return htmlAsString;
        }
  
  
        /**
         *  Gets the FinalUrl attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]    The FinalUrl value
         */
        public String getFinalUrl() {
                return finalUrl;
        }
  
  
        /**
         *  Gets the RequestedUrlFromUrlBean attribute of the HTMLUnitProcessor
         *  object
         *
         [EMAIL PROTECTED]    The RequestedUrlFromUrlBean value
         */
        public String getRequestedUrlFromUrlBean() {
                return getUrlBean().getRelativeUrlValue();
        }
  
  
        /**
         *  Gets the JavascriptEnable attribute of the HTMLClient object
         *
         [EMAIL PROTECTED]    The JavascriptEnable value
         */
        public boolean isJavascriptEnable() {
                return this.javascriptEnable;
        }
  
  
        /**
         *  Gets the ResponseCharSet attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]    The ResponseCharSet value
         */
        public String getResponseCharSet() {
                return responseCharSet;
        }
  
  
        /**
         *  Gets the Header attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]    The Header value
         */
        public Header[] getHeader() {
                return headers;
        }
  
  
        /**
         *  Adds a feature to the NameFrame attribute of the HTMLUnitProcessor 
object
         *
         [EMAIL PROTECTED]  name  The feature to be added to the NameFrame 
attribute
         */
        public void addNameFrame(String name) {
                getAllNameFrame().add(name);
        }
  
  
        /**
         *  Description of the Method
         *
         [EMAIL PROTECTED]  WebClippingException  Description of Exception
         */
        public void execute() throws WebClippingException {
                String html = "";
                try {
                        // Assert a non null webClient
                        assertNotNullWebClient();
  
                        //Get the requested url
                        URL url = new URL(getRequestedUrlFromUrlBean());
  
                        //set cookies
                        webClient.getWebConnection().getStateForUrl(url);
  
                        // add header
                        //addHeaders();
  
                        // Get the paramter
                        SubmitMethod httpMethod = getSubmitMethod();
                        ArrayList paramsList = 
getNameValuePairListFromURLBean();
  
                        // execute
                        currentPage_ = (HtmlPage) webClient.getPage(url, 
httpMethod, paramsList);
  
                        // Get the response
                        WebResponse response = currentPage_.getWebResponse();
                        String charSet = response.getContentCharSet();
                        logger.debug("CharSet: " + charSet);
  
                        // update url after all redirections
                        logger.debug("[ URL before process is: " + 
getUrlBean().getAbsoluteURL().toExternalForm() + " ]");
                        setFinalUrl(response.getUrl().toExternalForm());
                        
getUrlBean().setRedirectUrl(URLUtilities.getURL(getFinalUrl()));
  
                        logger.debug("[ URL after process is: " + 
getUrlBean().getAbsoluteURL().toExternalForm() + " ]");
  
                        // set the reponse as string
                        html = response.getContentAsString();
                        logger.debug("[ HTML :\n " + html + " ]");
                        logger.debug("[ Encoding of the response is: " + 
response.getContentCharSet() + " ]");
  
                        // set the html
                        setHtmlAsString(html);
  
                }
  
                catch (FailingHttpStatusCodeException ex) {
                        logger.error("[ FailingHttpStatusCodeException: " + 
ex.getMessage() + " ]");
                        ex.printStackTrace();
                        throw new WebClippingException("Failing Http Status 
Code", ex);
                }
                catch (MalformedURLException ex) {
                        logger.error("[ MalformedURLException: " + 
ex.getMessage() + " ]");
                        ex.printStackTrace();
                        throw new WebClippingException("Malformed URL", ex);
                }
                catch (IOException ex) {
                        logger.error("[ IOException occured: " + 
ex.getMessage() + " ]");
                        ex.printStackTrace();
                        throw new WebClippingException("IOException", ex);
                }
                catch (Exception ex) {
                        logger.debug("[ Exception occured: " + ex.getMessage() 
+ " ]");
                        throw new WebClippingException("Exception", ex);
                }
  
        }
  
  
  
        /**
         *  Allow to know if there is frame on the taget file.
         *
         [EMAIL PROTECTED]    Description of the Returned Value
         */
        public boolean foundFrame() {
  
                HtmlPage htmlPage = (HtmlPage) currentPage_;
                List frameList = htmlPage.getFrames();
                return !frameList.isEmpty();
        }
  
  
        /**
         *  Enable/disable javascript processing
         *
         [EMAIL PROTECTED]  enable  Description of Parameter
         */
        public void enabledJavascript(boolean enable) {
                javascriptEnable = enable;
                //update the refesh handler of the web client
                WebClient webClient = this.getWebClient();
                  webClient.setJavaScriptEnabled(isJavascriptEnable());
        }
  
  
        /**
         *  Remove the last recorded url
         */
        public void removeLastUrl() {
              // do nothing.
        }
  
  
        /**
         *  Gets the NameValuePairListFromURLBean attribute of the 
HTMLUnitProcessor
         *  object
         *
         [EMAIL PROTECTED]    The NameValuePairListFromURLBean value
         */
        private ArrayList getNameValuePairListFromURLBean() {
                logger.debug("[ Convert Map To List NameValuePair ]");
                // retrieve the query  parameters
                if (getUrlBean() == null) {
                        logger.error("[ URL is not set]");
                        return null;
                }
                List queryParamBeanList = getUrlBean().getQueryParamBeanList();
  
                //build list
                ArrayList listNamePairAndValue = new ArrayList();
                for (int i = 0; i < queryParamBeanList.size(); i++) {
                        QueryParamBean qBean = (QueryParamBean) 
queryParamBeanList.get(i);
                        String name = qBean.getName();
                        String value = qBean.getDefaultValue();
                        logger.debug("[ Found Param: " + name + " with value " 
+ value + " ]");
                        NameValuePair paramAndValue = new NameValuePair(name, 
value);
                        listNamePairAndValue.add(paramAndValue);
                }
  
                return listNamePairAndValue;
        }
  
  
        /**
         *  Gets a default WebClient attribute of the HTMLUnitProcessor object
         *
         [EMAIL PROTECTED]    The NewWebClient value
         */
        private WebClient getNewWebClient() {
                //Get Proxy parameter
                String proxyHost = getProxyHost();
                int proxyPort = getProxyPort();
  
                // build the webClient
                WebClient webClient = null;
                if (proxyHost != null && (proxyPort != 0)) {
                        webClient = new 
WebClient(BrowserVersion.INTERNET_EXPLORER_6_0, proxyHost, proxyPort);
                }
                else {
                        webClient = new 
WebClient(BrowserVersion.INTERNET_EXPLORER_6_0);
                }
  
                // disable throws exception when there is javacscript error
                webClient.setThrowExceptionOnScriptError(false);
                webClient.setThrowExceptionOnFailingStatusCode(false);
  
                // Disable validation. It will be done by the HTMLParser
                webClient.setRedirectEnabled(true);
                webClient.setJavaScriptEnabled(isJavascriptEnable());
  
                return webClient;
        }
  
  
        /**
         *  Adds a feature to the Headers attribute of the HTMLUnitProcessor 
object
         */
        private void addHeaders() {
                logger.debug("[ Add headers ]");
                Header[] header = this.getHeader();
                if (header != null) {
                        for (int i = 0; i < header.length; i++) {
                                Header h = header[i];
                                if (h != null) {
                                        webClient.addRequestHeader(h.getName(), 
h.getValue());
                                }
                        }
                }
        }
  
  
        /**
         *  Build a defaultClient if webClient is null
         */
        private void assertNotNullWebClient() {
                if (webClient == null) {
                        setWebClient(getNewWebClient());
                }
  
        }
  
  }
  
  
  
  Index: HTMLUnitProcessor.java
  ===================================================================
  RCS file: 
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/web/http/impl/HTMLUnitProcessor.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- HTMLUnitProcessor.java    11 Jul 2005 09:15:00 -0000      1.15
  +++ HTMLUnitProcessor.java    11 Jul 2005 15:32:25 -0000      1.16
  @@ -86,7 +86,10 @@
                                }
                        }
                        else {
  +                             logger.debug("Simlpe HtmlUnit client was 
executed");
                                super.execute();
  +                             addPage(currentPage_);
  +                                return;
                        }
   
                        // Get the response
  @@ -225,31 +228,30 @@
         [EMAIL PROTECTED]                               The SubmittedForm value
         [EMAIL PROTECTED]  ElementNotFoundException  Description of Exception
         */
  -        private HtmlForm getSubmittedForm() throws ElementNotFoundException {
  -                String fromHash = getUrlBean().getHash();
  -                logger.debug("From Hash: " + fromHash);
  -                HtmlForm form = null;
  -                String submittedFormName = 
HashUtilities.getFormNameFromHash(fromHash);
  -                String submittedFormId = 
HashUtilities.getFormIdFromHash(fromHash);
  -                // get the submiited form
  -                if (submittedFormName == null || 
submittedFormName.equalsIgnoreCase("")) {
  -                        if (submittedFormId == null || 
submittedFormId.equalsIgnoreCase("")) {
  -                                List formList = currentPage_.getForms();
  -                                int pos = 
Integer.parseInt(HashUtilities.getFormPositionFromHash(fromHash));
  -                                form = (HtmlForm) formList.get(pos);
  -
  -                        }
  -                        else {
  -                                form = (HtmlForm) 
currentPage_.getHtmlElementById(submittedFormId);
  -                        }
  -                }
  -                else {
  -                        form = (HtmlForm) 
currentPage_.getFormByName(submittedFormName);
  -                }
  +     private HtmlForm getSubmittedForm() throws ElementNotFoundException {
  +             String fromHash = getUrlBean().getHash();
  +             logger.debug("From Hash: " + fromHash);
  +             HtmlForm form = null;
  +             String submittedFormName = 
HashUtilities.getFormNameFromHash(fromHash);
  +             String submittedFormId = 
HashUtilities.getFormIdFromHash(fromHash);
  +             // get the submiited form
  +             if (submittedFormName == null || 
submittedFormName.equalsIgnoreCase("")) {
  +                     if (submittedFormId == null || 
submittedFormId.equalsIgnoreCase("")) {
  +                             List formList = currentPage_.getForms();
  +                             int pos = 
Integer.parseInt(HashUtilities.getFormPositionFromHash(fromHash));
  +                             form = (HtmlForm) formList.get(pos);
   
  -                return form;
  -        }
  +                     }
  +                     else {
  +                             form = (HtmlForm) 
currentPage_.getHtmlElementById(submittedFormId);
  +                     }
  +             }
  +             else {
  +                     form = (HtmlForm) 
currentPage_.getFormByName(submittedFormName);
  +             }
   
  +             return form;
  +     }
   
   
   
  
  
  
  Index: selectPartAction.jsp
  ===================================================================
  RCS file: 
/home/cvs/repository/webclip_builder/war/src/webapp/jsp/actions/selectPartAction.jsp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- selectPartAction.jsp      11 Jul 2005 12:31:13 -0000      1.5
  +++ selectPartAction.jsp      11 Jul 2005 15:32:25 -0000      1.6
  @@ -105,7 +105,7 @@
                 <bean:message key="select.clippingMethod.form"/>
               </html:option>
               <html:option value="4">
  -              <bean:message key="select.clippingMethod.link"/>
  +              <bean:message key="select.clippingMethod.xPath"/>
               </html:option>
               <html:option value="5">
                 <bean:message key="select.clippingMethod.table"/>
  @@ -136,6 +136,13 @@
               </html:select>
             </td>
           </logic:equal>
  +         <logic:equal name="selectPartForm" value="4" 
property="clippingMethod">
  +          <!-- case: chew-->
  +          <td class="topmenugreen bold waBG">
  +            <bean:message key="select.xpath.enter"/>
  +            <html:text property="webClippingXPath" size="1" value="0"/>
  +          </td>
  +        </logic:equal>
         </tr>
       </table>
     </html:form>
  
  
  
  Index: webBrowser.jsp
  ====================================================================
  <[EMAIL PROTECTED] uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
  <[EMAIL PROTECTED] uri="/WEB-INF/struts-nested.tld" prefix="nested"%>
  <[EMAIL PROTECTED] uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
  <[EMAIL PROTECTED] uri="/WEB-INF/struts-template.tld" prefix="template"%>
  <[EMAIL PROTECTED] uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
  <[EMAIL PROTECTED] uri="/WEB-INF/struts-html.tld" prefix="html"%>
  <bean:write name="webBrowserForm" property="content" filter="false"/>
  
  
  
  
  Index: testHeader.jsp
  ====================================================================
  <[EMAIL PROTECTED] uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
  <[EMAIL PROTECTED] uri="/WEB-INF/struts-nested.tld" prefix="nested"%>
  <[EMAIL PROTECTED] uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
  <[EMAIL PROTECTED] uri="/WEB-INF/struts-template.tld" prefix="template"%>
  <[EMAIL PROTECTED] uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
  <[EMAIL PROTECTED] uri="/WEB-INF/struts-html.tld" prefix="html"%>
  <table align="center" width="100%">
    <!-- Head wizard-->
  
      <tr valign="middle">
        <td class="boxtitlecolor1">
          <bean:message key="test.title"/>
        </td>
        <td class="boxtitleborder1" width="10%">
          <html:link action="/manageAction.do?webClippingAction=init">
            <bean:message key="test.quit"/>
          </html:link>
        </td>
      </tr>
  
      <!-- Wizar action-->
      <tr valign="middle">
        <td>
          <table>
            <!-- Show only the step that has been performed -->
            <tr>
              <!-- Preview -->
              <logic:present name="previewForm">
                <td>
                  <html:form action="saveClipper" method="post">
                    <html:image styleClass="wizard" pageKey="image.preview"/>
                    <html:hidden property="webClippingAction" value="wizard"/>
                  </html:form>
                </td>
              </logic:present>
            </tr>
          </table>
        </td>
      </tr>
  
  </table>
  <br/>
  

Reply via email to