ktlili      2005/06/06 19:04:23 CEST

  Modified files:
    war/MavenWebClipping MavenWebClipping.jpx 
                         MavenWebClipping.refactor 
    war/src/java/com/jahia/clipping/struts SelectPartAction.java 
    war/src/java/com/jahia/clipping/util StringUtilities.java 
    war/src/java/com/jahia/clipping/web/Url/Impl URLUtilities.java 
    war/src/java/com/jahia/clipping/web/html/Impl 
                                                  DefaultHTMLTransformer.java 
                                                  
StringTreeExtractorFilter.java 
    war/src/webapp/jsp/actions previewAction.jsp 
  Log:
  Optimize StringFilter
  Fix Bug StringFilter
  Fix Bug img
  Optimize HTMLParser
  
  Revision  Changes    Path
  1.6       +10 -1     webclip_builder/war/MavenWebClipping/MavenWebClipping.jpx
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/MavenWebClipping/MavenWebClipping.jpx.diff?r1=1.5&r2=1.6&f=h
  1.2       +4 -0      
webclip_builder/war/MavenWebClipping/MavenWebClipping.refactor
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/MavenWebClipping/MavenWebClipping.refactor.diff?r1=1.1&r2=1.2&f=h
  1.3       +1 -1      
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.2&r2=1.3&f=h
  1.2       +1 -1      
webclip_builder/war/src/java/com/jahia/clipping/util/StringUtilities.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/util/StringUtilities.java.diff?r1=1.1&r2=1.2&f=h
  1.5       +1 -1      
webclip_builder/war/src/java/com/jahia/clipping/web/Url/Impl/URLUtilities.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/web/Url/Impl/URLUtilities.java.diff?r1=1.4&r2=1.5&f=h
  1.6       +14 -6     
webclip_builder/war/src/java/com/jahia/clipping/web/html/Impl/DefaultHTMLTransformer.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/web/html/Impl/DefaultHTMLTransformer.java.diff?r1=1.5&r2=1.6&f=h
  1.3       +244 -199  
webclip_builder/war/src/java/com/jahia/clipping/web/html/Impl/StringTreeExtractorFilter.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/web/html/Impl/StringTreeExtractorFilter.java.diff?r1=1.2&r2=1.3&f=h
  1.2       +38 -38    
webclip_builder/war/src/webapp/jsp/actions/previewAction.jsp
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/webapp/jsp/actions/previewAction.jsp.diff?r1=1.1&r2=1.2&f=h
  
  
  
  Index: MavenWebClipping.jpx
  ===================================================================
  RCS file: 
/home/cvs/repository/webclip_builder/war/MavenWebClipping/MavenWebClipping.jpx,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MavenWebClipping.jpx      6 Jun 2005 11:34:52 -0000       1.5
  +++ MavenWebClipping.jpx      6 Jun 2005 17:04:21 -0000       1.6
  @@ -31,6 +31,7 @@
     <property category="module" 
name="ProjectConvertedToUseProperModuleDefaults" value="1"/>
     <property category="module" name="last.wizard.module.name" value="webapp"/>
     <property category="module" 
name="projectConvertedFromModuleExtensionsToModuleFileTypes" value="1"/>
  +  <property category="runtime" name="ConfigurationCount" value="1"/>
     <property category="runtime" name="DefaultConfiguration" value="-1"/>
     <property category="runtime.0" name="BuildTargetOnRun" 
value="com.borland.jbuilder.build.ExternalTaskBuilder;MavenBuild"/>
     <property category="runtime.0" name="ConfigurationName" value="Tomcat 
4.1"/>
  @@ -44,6 +45,10 @@
     <property category="runtime.0" name="server.instance.name" value=""/>
     <property category="runtime.0" name="server.name" value="Tomcat 4.1"/>
     <property category="runtime.0" name="server.vmparameters" value=""/>
  +  <property category="runtime.1" name="ConfigurationName" 
value="TestStringTreeExtractorFilter"/>
  +  <property category="runtime.1" name="RunnableType" 
value="com.borland.jbuilder.runtime.TestRunner"/>
  +  <property category="runtime.1" name="test.class" 
value="com.jahia.clipping.web.html.Impl.TestStringTreeExtractorFilter"/>
  +  <property category="runtime.1" name="test.harness" 
value="com.borland.jbuilder.unittest.JBTestRunner"/>
     <property category="serverservices" name="disabled.services" 
value="jdatastore;sqlj"/>
     <property category="serverservices" name="single.server.name" 
value="Tomcat 4.1"/>
     <property category="sys" name="AuthorLabel" value="@author"/>
  @@ -65,7 +70,7 @@
     <property category="sys" name="JDK" value="java version 1.5.0_02-b09"/>
     <property category="sys" name="JvmVersion" value="1.2"/>
     <property category="sys" name="LastTag" value="0"/>
  -  <property category="sys" name="Libraries" 
value="MavenAutoUpdated;WebClipper;Tomcat 4.1 Servlet;Servlet;Struts"/>
  +  <property category="sys" name="Libraries" 
value="MavenAutoUpdated;WebClipper;Tomcat 4.1 Servlet;Servlet;Struts;JUnit"/>
     <property category="sys" name="MakeStable" value="0"/>
     <property category="sys" name="OutPath" value="classes"/>
     <property category="sys" name="ShowWarnings" value="0"/>
  @@ -78,6 +83,10 @@
     <property category="sys" name="WorkingDirectory" value="."/>
     <property category="team" name="ignorePath.0" value="Tomcat"/>
     <property category="webModule" name="last.wizard.module.name" 
value="webapp"/>
  +  <node name="webapp" type="NavigationDirectory">
  +    <property category="directorynode" name="showSubdirectories" value="1"/>
  +    <property category="directorynode" name="url" value="C%%|/Documents and 
Settings/jahia/jbproject/webclip_builder/war/src/webapp"/>
  +  </node>
     <node name="MavenBuild" type="ExternalTask">
       <property category="external" name="executable" value="C:\Documents and 
Settings\jahia\jbproject\webclip_builder\mavenBuild.bat"/>
       <property category="external" name="phase" value="compile"/>
  
  
  
  Index: MavenWebClipping.refactor
  ===================================================================
  RCS file: 
/home/cvs/repository/webclip_builder/war/MavenWebClipping/MavenWebClipping.refactor,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MavenWebClipping.refactor 3 Mar 2005 18:03:49 -0000       1.1
  +++ MavenWebClipping.refactor 6 Jun 2005 17:04:21 -0000       1.2
  @@ -13,4 +13,8 @@
       <declared-field-type>Ljava/lang/String;</declared-field-type>
       <new-field-name>DIV_CLASS</new-field-name>
     </rename-field>
  +  <rename-class id="XYB0K0A3EM9ECW268KJ0QKH0" creation-time="Mon Jun 06 
17:04:43.359 CEST 2005">
  +    
<old-class-name>com.jahia.clipping.web.html.Impl.StringTreeExtractorFilter$MyVisitor</old-class-name>
  +    
<new-class-name>com.jahia.clipping.web.html.Impl.StringTreeExtractorFilter$BuildKeyVisitor</new-class-name>
  +  </rename-class>
   </refactor>
  
  
  
  Index: SelectPartAction.java
  ===================================================================
  RCS file: 
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/struts/SelectPartAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SelectPartAction.java     14 Mar 2005 16:29:34 -0000      1.2
  +++ SelectPartAction.java     6 Jun 2005 17:04:22 -0000       1.3
  @@ -76,7 +76,7 @@
   
                //set the HTMLFilter
                   ExtractorFilter filter = null;
  -             // 0 = dynamic, 1 = staticz
  +             // 0 = dynamic, 1 = static
                if 
(selectPartForm.getWebClippingTypeContent().equalsIgnoreCase("0")) {
                        filter = new StringTreeExtractorFilter(doc, 
selectedContent);
                }
  
  
  
  Index: StringUtilities.java
  ===================================================================
  RCS file: 
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/util/StringUtilities.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StringUtilities.java      3 Mar 2005 18:03:55 -0000       1.1
  +++ StringUtilities.java      6 Jun 2005 17:04:22 -0000       1.2
  @@ -166,7 +166,7 @@
                        if (i == -1) {
                                break;
                        }
  -                     logger.debug("[ Next index is " + i + "]");
  +                     //logger.debug("[ Next index is " + i + "]");
                }
   
                Object[] res = new Object[3];
  
  
  
  Index: URLUtilities.java
  ===================================================================
  RCS file: 
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/web/Url/Impl/URLUtilities.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- URLUtilities.java 6 Jun 2005 13:14:10 -0000       1.4
  +++ URLUtilities.java 6 Jun 2005 17:04:22 -0000       1.5
  @@ -114,7 +114,7 @@
   
   
        /**
  -      *  Gets the Relatif attribute of the JDomHTMLTransformer object
  +      *  test if its a relatif url or not
         *
         [EMAIL PROTECTED]  url  Description of Parameter
         [EMAIL PROTECTED]      The Relatif value
  
  
  
  Index: DefaultHTMLTransformer.java
  ===================================================================
  RCS file: 
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/web/html/Impl/DefaultHTMLTransformer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultHTMLTransformer.java       6 Jun 2005 13:14:10 -0000       1.5
  +++ DefaultHTMLTransformer.java       6 Jun 2005 17:04:22 -0000       1.6
  @@ -138,10 +138,16 @@
         [EMAIL PROTECTED]  Exception  Description of Exception
         */
        public String getRewritedHrefValue(String href) throws Exception {
  -             href = 
URLUtilities.getHrefAbsoluteValue(getUrlBean().getUrlValue(), href);
  -             String[] params = {href};
  -             UrlEncoder encoder = new UrlEncoder(getHttpServletRequest(), 
getHttpServletResponse(), "browse", params);
  -             return encoder.getEncodedUrl();
  +             //test if its a relatif url.
  +             if (URLUtilities.isRelatif(href)) {
  +                     href = 
URLUtilities.getHrefAbsoluteValue(getUrlBean().getUrlValue(), href);
  +                     String[] params = {href};
  +                     UrlEncoder encoder = new 
UrlEncoder(getHttpServletRequest(),getHttpServletResponse(), "browse", params);
  +                     return encoder.getEncodedUrl();
  +             }
  +             else {
  +                     return href;
  +             }
        }
   
   
  @@ -221,7 +227,6 @@
   
   
   
  -
        /**
         *  Description of the Method
         *
  @@ -310,7 +315,10 @@
                                        return false;
                                }
                        }
  -             }
  +             }else{
  +                    // if type is null then type is submit
  +                    return false;
  +                }
                return true;
        }
   
  
  
  
  Index: StringTreeExtractorFilter.java
  ===================================================================
  RCS file: 
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/web/html/Impl/StringTreeExtractorFilter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StringTreeExtractorFilter.java    14 Mar 2005 16:29:35 -0000      1.2
  +++ StringTreeExtractorFilter.java    6 Jun 2005 17:04:22 -0000       1.3
  @@ -1,17 +1,21 @@
   package com.jahia.clipping.web.html.Impl;
   
   import com.jahia.clipping.web.html.*;
  -import org.w3c.dom.Document;
  -import org.jdom.*;
  -import org.jdom.input.*;
   import java.io.*;
  -import org.xml.sax.*;
   import java.util.*;
   import java.io.*;
   import com.jahia.clipping.util.*;
   import javax.swing.text.html.HTML;
   import com.jahia.clipping.web.html.Impl.*;
   import com.jahia.clipping.util.*;
  +import org.apache.commons.lang.*;
  +import org.htmlparser.*;
  +import org.htmlparser.*;
  +import org.htmlparser.*;
  +import org.htmlparser.util.*;
  +import org.htmlparser.*;
  +import org.htmlparser.visitors.*;
  +import org.jdom.Element;
   
   /**
    *  JDom implementation of HTMLFilter
  @@ -26,11 +30,10 @@
         [EMAIL PROTECTED]  ele  Description of Parameter
         [EMAIL PROTECTED]      Description of the Returned Value
         */
  -     private String concat = "";
        private HTMLDocument doc;
        private String selectedPart = "<p> Can't retrieve the selected part 
</p>";
        private String keyPart;
  -     private Hashtable stringElementHash = new Hashtable();
  +     private Hashtable stringTagHash = new Hashtable();
        private static org.apache.log4j.Logger logger = 
org.apache.log4j.Logger.getLogger(StringTreeExtractorFilter.class);
   
   
  @@ -59,6 +62,7 @@
         [EMAIL PROTECTED]  originalSelectedPart  Description of Parameter
         */
        public StringTreeExtractorFilter(HTMLDocument doc, String 
originalSelectedPart) {
  +             this(originalSelectedPart);
                setDoc(doc);
                buildKeySelectedPart(originalSelectedPart);
        }
  @@ -85,12 +89,12 @@
   
   
        /**
  -      *  Sets the StringElementHash attribute of the StringTreeHTMLFilter 
object
  +      *  Sets the StringTagHash attribute of the StringTreeHTMLFilter object
         *
  -      [EMAIL PROTECTED]  stringElementHash  The new StringElementHash value
  +      [EMAIL PROTECTED]  stringTagHash  The new StringTagHash value
         */
  -     public void setStringElementHash(Hashtable stringElementHash) {
  -             this.stringElementHash = stringElementHash;
  +     public void setStringTagHash(Hashtable stringTagHash) {
  +             this.stringTagHash = stringTagHash;
        }
   
   
  @@ -145,12 +149,12 @@
   
   
        /**
  -      *  Gets the StringElementHash attribute of the StringTreeHTMLFilter 
object
  +      *  Gets the StringTagHash attribute of the StringTreeHTMLFilter object
         *
  -      [EMAIL PROTECTED]    The StringElementHash value
  +      [EMAIL PROTECTED]    The StringTagHash value
         */
  -     public Hashtable getStringElementHash() {
  -             return stringElementHash;
  +     public Hashtable getStringTagHash() {
  +             return stringTagHash;
        }
   
   
  @@ -168,35 +172,6 @@
        }
   
   
  -     /**
  -      *  Gets the BodyDiv attribute of the StringTreeExtractorFilter object
  -      *
  -      [EMAIL PROTECTED]  jDoc  Description of Parameter
  -      [EMAIL PROTECTED]       The BodyDiv value
  -      */
  -     public Element getBodyDiv(org.jdom.Document jDoc) {
  -             logger.debug("[ Looking for body div class]");
  -             Element root = jDoc.getRootElement();
  -             List children = root.getChildren();
  -             for (int i = 0; i < children.size(); i++) {
  -                     Element ele = (Element) children.get(i);
  -                     if 
(ele.getName().equalsIgnoreCase(HTML.Tag.DIV.toString())) {
  -                             logger.debug("[ It as a div element ]");
  -                             String classAtt = 
ele.getAttributeValue(HTML.Attribute.CLASS.toString());
  -                             logger.debug("[ class attribute value  is: " + 
classAtt + "]");
  -                             if (classAtt != null) {
  -                                     logger.debug("[ class attribute value  
is: " + classAtt + ", " + 
classAtt.indexOf(com.jahia.clipping.util.CssUtilities.BODY_CLASS) + "]");
  -                                     if 
(classAtt.indexOf(com.jahia.clipping.util.CssUtilities.BODY_CLASS) > -1) {
  -                                             logger.debug("[ bodyDiv element 
founded ]");
  -                                             return ele;
  -                                     }
  -                             }
  -
  -                     }
  -             }
  -             return null;
  -     }
  -
   
        /**
         *  Description of the Method
  @@ -204,63 +179,88 @@
         [EMAIL PROTECTED]  originalSelectedPart  Description of Parameter
         */
        public void buildKeySelectedPart(String originalSelectedPart) {
  -             try {
  -                     //build a jdom document of the selected part
  -                     DefaultHTMLParser parser = new DefaultHTMLParser();
   
  -                     // get the HTMLDocument
  -                     org.jdom.Document jdoc = new 
DOMBuilder().build(parser.parse(originalSelectedPart));
  -                     Element body = 
jdoc.getRootElement().getChild(HTML.Tag.BODY.toString());
  -                     setKeyPart(buildStringMapFromHTMLDocument(body));
  -             }
  -             catch (IOException ex) {
  -                     logger.error("[IOException has occured while building 
kef for selected part]");
  -                     ex.printStackTrace();
  +             //build a jdom document of the selected part
  +             String charSet = "";
  +             Parser parser = Parser.createParser(originalSelectedPart, 
charSet);
  +             BuildKeyVisitor visitor = new BuildKeyVisitor();
  +             try {
  +                     parser.visitAllNodesWith(visitor);
  +                     logger.debug("key part is: " + visitor.getBuildedKey());
                }
  -             catch (SAXException ex) {
  -                     logger.error("[IOException has occured while building 
kef for selected part]");
  +             catch (ParserException ex) {
                        ex.printStackTrace();
  +                     logger.error("buldKeySelectedPart error " + 
ex.getMessage());
                }
  +             setKeyPart(visitor.getBuildedKey());
   
        }
   
   
        /**
  -      *  Gets the ElementFromStringKey attribute of the StringTreeHTMLFilter
  -      *  object
  +      *  Gets the TagFromStringKey attribute of the StringTreeHTMLFilter 
object
         *
         [EMAIL PROTECTED]  key  Description of Parameter
  -      [EMAIL PROTECTED]      The ElementFromStringKey value
  +      [EMAIL PROTECTED]      The TagFromStringKey value
  +      */
  +     private Tag getTagFromStringKey(String key) {
  +             return (Tag) getStringTagHash().get(key);
  +     }
  +
  +
  +
  +     /**
  +      *  Best match = v:br: --> :div:br:
  +      *
  +      [EMAIL PROTECTED]  where      Description of Parameter
  +      [EMAIL PROTECTED]  bestMatch  Description of Parameter
  +      [EMAIL PROTECTED]            The ValidBestMatch value
         */
  -     private Element getElementFromStringKey(String key) {
  -             return (Element) getStringElementHash().get(key);
  +     private String getValidBestMatch(String where, String bestMatch) {
  +             // bestMatch is null or empty
  +             if (bestMatch == null || bestMatch.length() == 0) {
  +                     return bestMatch;
  +             }
  +             if (bestMatch.charAt(0) == ':') {
  +                     return bestMatch;
  +             }
  +             int position = where.indexOf(bestMatch);
  +
  +             String toAppend = "";
  +             while (where.charAt(position) != ':') {
  +                     toAppend = toAppend + where.charAt(position);
  +                     position--;
  +             }
  +             logger.debug("[ Append ]" + toAppend);
  +             return toAppend + bestMatch;
        }
   
   
        /**
  -      *  Gets a list whith all the element that are included in the best 
match
  +      *  Gets the AllElementsFromBestMatch attribute of the
  +      *  StringTreeExtractorFilter object
         *
         [EMAIL PROTECTED]  docString  Description of Parameter
         [EMAIL PROTECTED]  bestMatch  Description of Parameter
  -      [EMAIL PROTECTED]            The AllElementsFormBestMatch value
  +      [EMAIL PROTECTED]            The AllElementsFromBestMatch value
         */
        private ArrayList getAllElementsFromBestMatch(String docString, String 
bestMatch) {
  -             ArrayList eleList = new ArrayList();
  +             ArrayList tagList = new ArrayList();
   
                //Retrieve the first elemeent
                int indexBestMatch = docString.indexOf(bestMatch);
                logger.debug("[Best match is " + bestMatch + " ]");
                String key = docString.substring(0, indexBestMatch);
  -             Element firtsEle = getElementFromStringKey(key);
  +             Tag firtsTag = getTagFromStringKey(key);
   
                // add the first ele to the list
  -             if (firtsEle == null) {
  +             if (firtsTag == null) {
                        logger.error("[No element whith key " + key + " 
founded]");
                }
                else {
  -                     logger.debug("[Element --" + firtsEle.getName() + "-- 
whith key " + key +
  +                     logger.debug("[Element --" + firtsTag.getTagName() + 
"-- whith key " + key +
                                        " added]");
  -                     eleList.add(firtsEle);
  +                     tagList.add(firtsTag);
                }
   
                //Retreive and add of the rest of element
  @@ -275,14 +275,13 @@
                        String newKey = keyElementJustBefore + ":" + 
nameElementJustBefore;
   
                        //add element
  -                     Element currentEle = getElementFromStringKey(newKey);
  +                     Tag currentEle = getTagFromStringKey(newKey);
                        if (currentEle == null) {
                                logger.error("[No element whith key " + newKey 
+ " founded]");
                        }
                        else {
  -                             logger.debug("[Element <" + 
currentEle.getName() + "> whith key " +
  -                                             newKey + " added]");
  -                             eleList.add(currentEle);
  +                             logger.debug("[Element <" + 
currentEle.getTagName() + "> whith key " + newKey + " added]");
  +                             tagList.add(currentEle);
   
                        }
   
  @@ -290,182 +289,228 @@
                        keyElementJustBefore = newKey;
   
                }
  -             return eleList;
  +             return tagList;
        }
   
   
        /**
  -      *  Best match = v:br: --> :div:br:
  +      *  Gets the RealSelectedPart attribute of the StringTreeExtractorFilter
  +      *  object
         *
  -      [EMAIL PROTECTED]  where      Description of Parameter
  -      [EMAIL PROTECTED]  bestMatch  Description of Parameter
  -      [EMAIL PROTECTED]            The ValidBestMatch value
  +      [EMAIL PROTECTED]  originalSelectedPart  Description of Parameter
  +      [EMAIL PROTECTED]                       The RealSelectedPart value
         */
  -     private String getValidBestMatch(String where, String bestMatch) {
  -             // bestMatch is null or empty
  -             if (bestMatch == null || bestMatch.length() == 0) {
  -                     return bestMatch;
  -             }
  -             if (bestMatch.charAt(0) == ':') {
  -                     return bestMatch;
  -             }
  -             int position = where.indexOf(bestMatch);
  -
  -             String toAppend = "";
  -             while (where.charAt(position) != ':') {
  -                     toAppend = toAppend + where.charAt(position);
  -                     position--;
  -             }
  -             logger.debug("[ Append ]" + toAppend);
  -             return toAppend + bestMatch;
  +     private String refactorKey(String originalSelectedPart) {
  +             String realSelectedPart = originalSelectedPart;
  +             return realSelectedPart;
        }
   
   
  +
        /**
  -      *  Description of the Method
  +      *  Adds a feature to the ElemenWhitKey attribute of the 
StringTreeHTMLFilter
  +      *  object
         *
  -      [EMAIL PROTECTED]  ele  Description of Parameter
  -      [EMAIL PROTECTED]      Description of the Returned Value
  +      [EMAIL PROTECTED]  key  The feature to be added to the ElemenWhitKey 
attribute
  +      [EMAIL PROTECTED]  ele  The feature to be added to the ElemenWhitKey 
attribute
         */
  -     private String buildStringMapFromHTMLDocument(Element ele) {
  -             // init concat value
  -             concat = "";
  -
  -             //build the key from the body element
  -
  -             //Element body = 
jDoc.getRootElement().getChild(HTML.Tag.BODY.toString());
  -             /*
  -              *  Element body = getBodyDiv(jDoc);
  -              *  // test that there is body element
  -              *  if (body == null) {
  -              *  String error = "BodyDiv is null: Enable to build String 
Map";
  -              *  logger.error(error);
  -              *  
logger.error(com.jahia.clipping.util.JDomUtilities.getDocumentAsString(jDoc));
  -              *  return error;
  -              *  }
  -              */
  -             concatAllChildrenName(ele);
  -             logger.debug("[ End building map for documen ]");
  -             return concat;
  +     private void addElemenWhitKey(String key, Tag ele) {
  +             getStringTagHash().put(key, ele);
  +             //logger.debug("Tag " + ele + "whith key " + key + " added");
        }
   
   
        /**
  -      *  Description of the Method
  +      *  Extract the selected part of the document
         *
  -      [EMAIL PROTECTED]  ele  Description of Parameter
  +      [EMAIL PROTECTED]  htmlDoc  Description of Parameter
         */
  -     private void concatAllChildrenName(Element ele) {
  -             // set the key for the hastable
  -             addElemenWhitKey(concat, ele);
  -
  -             //concat it's name if its not body
  -             String name = ele.getName();
  -             if (!name.equalsIgnoreCase(HTML.Tag.BODY.toString())) {
  -                     if (!name.equalsIgnoreCase("tbody")) {
  -                             concat = concat + ":" + ele.getName();
  -                     }
  -                     else if (!name.equalsIgnoreCase("body")) {
  -                             // due to rule transformation (body --> div)
  -                             concat = concat + ":" + "div";
  -                     }
  +     private void processFiltering(HTMLDocument htmlDoc) {
  +             //build key of the html document
  +             String charSet = "";
  +             Parser parser = 
Parser.createParser(htmlDoc.getOriginalDocumentAsString(), charSet);
  +             BuildKeyVisitor visitor = new BuildKeyVisitor();
  +             String docString = "";
  +             try {
  +                     parser.visitAllNodesWith(visitor);
  +                     docString = visitor.getBuildedKey();
  +                     logger.debug("pattern of the documnet part is: " + 
docString);
  +             }
  +             catch (ParserException ex) {
  +                     ex.printStackTrace();
  +                     logger.error("buldKeySelectedPart error " + 
ex.getMessage());
                }
  -             List children = ele.getChildren();
   
  -             for (int i = 0; i < children.size(); i++) {
  -                     Element child = (Element) children.get(i);
  -                     concatAllChildrenName(child);
  +             //Compute best match
  +             String bestMatch = 
StringUtilities.getBestMatchString(docString, getKeyPart(), ':');
  +             bestMatch = getValidBestMatch(docString, bestMatch);
  +
  +             logger.debug("[KeyPart is  : " + getKeyPart() + " ]");
  +             logger.debug("[BestPart is : " + bestMatch + " ]");
   
  +             //build hashtable
  +
  +             //Build the supposed selected part
  +             BuildSelectedPartVisitor bspv = new 
BuildSelectedPartVisitor(docString, bestMatch);
  +             try {
  +                     parser.reset();
  +                     parser.visitAllNodesWith(bspv);
  +                     docString = visitor.getBuildedKey();
  +                     logger.debug("pattern of the documnet part is: " + 
docString);
  +             }
  +             catch (ParserException ex) {
  +                     ex.printStackTrace();
  +                     logger.error("Selectet part error " + ex.getMessage());
                }
  -     }
   
  +             //Rebuild the document
  +             setSelectedPart(bspv.getSelectedPart());
   
  -     /**
  -      *  Adds a feature to the ElemenWhitKey attribute of the 
StringTreeHTMLFilter
  -      *  object
  -      *
  -      [EMAIL PROTECTED]  key  The feature to be added to the ElemenWhitKey 
attribute
  -      [EMAIL PROTECTED]  ele  The feature to be added to the ElemenWhitKey 
attribute
  -      */
  -     private void addElemenWhitKey(String key, Element ele) {
  -             getStringElementHash().put(key, ele);
  -             //logger.debug("Element " + ele + "whith key " + key + " 
added");
        }
   
   
  +
        /**
  -      *  Extract the selected part of the document
  +      *  Description of the Class
         *
  -      [EMAIL PROTECTED]  htmlDoc  Description of Parameter
  +      [EMAIL PROTECTED]    Tlili Khaled
         */
  -     private void processFiltering(HTMLDocument htmlDoc) {
  -             //Compute best match
  -             org.jdom.Document jDoc = htmlDoc.getJDOMTransformedDocument();
  +     public class BuildKeyVisitor extends NodeVisitor {
  +             private String key = "";
  +
   
  -             Element bodyDiv = getBodyDiv(jDoc);
  -             // test that there is body element
  -             if (bodyDiv == null) {
  -                     String error = "BodyDiv is null: Enable to build String 
Map";
  -                     logger.error(error);
  -                     
logger.error(com.jahia.clipping.util.JDomUtilities.getDocumentAsString(jDoc));
  -                     return;
  +             /**
  +              *  Constructor for the MyVisitor object
  +              */
  +             public BuildKeyVisitor() {
  +                     key = "";
                }
   
   
  -             String docString = buildStringMapFromHTMLDocument(bodyDiv);
  -             String bestMatch = 
StringUtilities.getBestMatchString(docString, getKeyPart(), ':');
  -             bestMatch = getValidBestMatch(docString, bestMatch);
  +             /**
  +              *  Gets the BuildedKey attribute of the BuildKeyVisitor object
  +              *
  +              [EMAIL PROTECTED]    The BuildedKey value
  +              */
  +             public String getBuildedKey() {
  +                     return key;
  +             }
   
  -             logger.debug("[KeyPart is  : " + getKeyPart() + " ]");
  -             logger.debug("[BestPart is : " + bestMatch + " ]");
   
  -             //Get list of all the element included in the bestMatch
  -             ArrayList allEle = getAllElementsFromBestMatch(docString, 
bestMatch);
  +             /**
  +              *  Description of the Method
  +              *
  +              [EMAIL PROTECTED]  tag  Description of Parameter
  +              */
  +             public void visitTag(Tag tag) {
  +                     key = key + ":" + tag.getTagName();
  +                     addElemenWhitKey(key, tag);
  +                     //logger.debug("added key: " + key);
   
  -             if (allEle.isEmpty()) {
  -                     logger.error("[Can't find anyElement ]");
  -                     return;
  +                     //logger.debug("\n" + tag.getTagName() + 
tag.getStartPosition());
                }
   
  -             logger.debug("[At least one element is retrieved ]");
   
  -             //Rebuild the document
  -             org.jdom.Document selectedPartDoc = builPartDocument(allEle);
  -             
setSelectedPart(JDomUtilities.getDocumentAsString(selectedPartDoc));
  -     }
  +             /**
  +              *  Description of the Method
  +              *
  +              [EMAIL PROTECTED]  string  Description of Parameter
  +              */
  +             public void visitStringNode(Text string) {
  +                     //logger.debug(string);
  +             }
   
  +     }
   
   
        /**
  -      *  Description of the Method
  +      *  Description of the Class
         *
  -      [EMAIL PROTECTED]  eleList  Description of Parameter
  -      [EMAIL PROTECTED]          Description of the Returned Value
  +      [EMAIL PROTECTED]    Tlili Khaled
         */
  -     private org.jdom.Document builPartDocument(ArrayList eleList) {
  -             //init
  -             org.jdom.Document doc = new org.jdom.Document();
  -             Element pEle = new Element(HTML.Tag.P.toString());
  -             doc.setRootElement(pEle);
  -             Element firstEle = (Element) (Element) eleList.get(0);
  -             pEle.addContent((Element) firstEle.clone());
  -
  -             // reconstruct the document
  -             for (int i = 1; i < eleList.size(); i++) {
  -                     Element currentEle = (Element) eleList.get(i);
  -                     //add only the element at the firts level. The others 
will be automatically added
  -                     if (JDomUtilities.isSibling(currentEle, firstEle)) {
  -                             Element clone = (Element) (currentEle.clone());
  -                             pEle.addContent(clone);
  -                             logger.debug("[element " + 
currentEle.toString() + " is  added ]");
  -                     }
  -                     else {
  -                             logger.debug("[element " + 
currentEle.toString() + " is not sibling of " + firstEle.toString() + "]");
  -                             logger.debug("[element " + 
currentEle.toString() + " is not added ]");
  +     public class BuildSelectedPartVisitor extends NodeVisitor {
  +             private String key = "";
  +             private String selectedPart = "<p> empty </p>";
  +             private boolean findOne = false;
  +             private List tagList;
  +
  +
  +             /**
  +              *  Constructor for the MyVisitor object
  +              *
  +              [EMAIL PROTECTED]  docString  Description of Parameter
  +              [EMAIL PROTECTED]  bestMatch  Description of Parameter
  +              */
  +             public BuildSelectedPartVisitor(String docString, String 
bestMatch) {
  +                     key = "";
  +                     tagList = getAllElementsFromBestMatch(docString, 
bestMatch);
  +             }
  +
  +
  +             /**
  +              *  Gets the BuildedKey attribute of the BuildKeyVisitor object
  +              *
  +              [EMAIL PROTECTED]    The BuildedKey value
  +              */
  +             public String getBuildedKey() {
  +                     return key;
  +             }
  +
  +
  +             /**
  +              *  Gets the SelectedPart attribute of the 
BuildSelectedPartVisitor object
  +              *
  +              [EMAIL PROTECTED]    The SelectedPart value
  +              */
  +             public String getSelectedPart() {
  +                     return selectedPart;
  +             }
  +
  +
  +             /**
  +              *  Description of the Method
  +              *
  +              [EMAIL PROTECTED]  tag  Description of Parameter
  +              */
  +             public void visitTag(Tag tag) {
  +                     if (!findOne) {
  +                             try {
  +                                     key = key + ":" + tag.getTagName();
  +                                     //logger.debug("key of the current tag 
is: " + key);
  +                                     // test if the tag is in the
  +                                     Tag result = getTagFromStringKey(key);
  +                                     Tag cloneTag = (Tag) tag.clone();
  +                                     logger.debug(cloneTag.getTagName());
  +                                     if (result == null) {
  +                                             // remoce text
  +                                             logger.debug("No selected tag");
  +                                             //cloneTag.setText("");
  +
  +                                     }
  +                                     else {
  +                                             findOne = true;
  +                                             selectedPart = selectedPart + 
cloneTag.toHtml();
  +                                             logger.debug("Selected tag");
  +                                     }
  +                             }
  +                             catch (CloneNotSupportedException ex) {
  +                                     ex.printStackTrace();
  +                                     logger.error("Enable to clone tag: " +
  +                                                     tag.getTagName());
  +                             }
                        }
  +             }
   
  +
  +             /**
  +              *  Description of the Method
  +              *
  +              [EMAIL PROTECTED]  string  Description of Parameter
  +              */
  +             public void visitStringNode(Text string) {
  +                     //logger.debug(string);
                }
  -             return doc;
  +
        }
   
   }
  
  
  
  Index: previewAction.jsp
  ===================================================================
  RCS file: 
/home/cvs/repository/webclip_builder/war/src/webapp/jsp/actions/previewAction.jsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- previewAction.jsp 3 Mar 2005 18:04:10 -0000       1.1
  +++ previewAction.jsp 6 Jun 2005 17:04:23 -0000       1.2
  @@ -1,44 +1,44 @@
  -<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
  -<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
  -<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
  -<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
  -<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
  -<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
  +<[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" class="principal" width="100%">
     <html:form action="saveClipper" method="post">
  -  <!-- Header -->
  -  <table align="center" class="principal" width="100%">
  -    <!-- Title -->
  +    <!-- Header -->
  +    <table align="center" class="principal" width="100%">
  +      <!-- Title -->
  +      <tr>
  +        <td class="boxtitleborder1">
  +          <bean:message key="preview.title"/>
  +        </td>
  +      </tr>
  +      <!-- Buttons -->
  +      <tr>
  +        <td class="topmenubuttons">
  +          <logic:equal name="previewForm" property="from" value="wizard">
  +            <!-- Done -->
  +            <html:submit property="webClippingAction">
  +              <bean:message key="button.done"/>
  +            </html:submit>
  +          </logic:equal>
  +          <logic:equal name="previewForm" property="from" value="test">
  +            <!-- Previous -->
  +            <html:submit property="webClippingAction">
  +              <bean:message key="button.previous"/>
  +            </html:submit>
  +          </logic:equal>
  +        </td>
  +      </tr>
  +    </table>
  +  </html:form>
  +  <!-- HTML page -->
  +  <table class="webClipping" style="position: relative; ">
       <tr>
  -      <td class="boxtitleborder1">
  -        <bean:message key="preview.title"/>
  +      <td>
  +        <bean:write name="previewForm" property="selectedPart" 
filter="false"/>
         </td>
       </tr>
  -    <!-- Buttons -->
  -    <tr>
  -      <td class="topmenubuttons">
  -        <logic:equal name="previewForm" property="from" value="wizard">
  -        <!-- Done -->
  -        <html:submit property="webClippingAction">
  -          <bean:message key="button.done"/>
  -        </html:submit>
  -      </logic:equal>
  -      <logic:equal name="previewForm" property="from" value="test">
  -      <!-- Previous -->
  -      <html:submit property="webClippingAction">
  -        <bean:message key="button.previous"/>
  -      </html:submit>
  -    </logic:equal>
  -  </td>
  -</tr>
  -</table>
  -</html:form>
  -<!-- HTML page -->
  -<table>
  -<tr>
  -<td>
  -  <bean:write name="previewForm" property="selectedPart" filter="false"/>
  -</td>
  -</tr>
  -</table>
  +  </table>
   </table>
  

Reply via email to