ktlili      2005/06/10 11:05:08 CEST

  Modified files:
    war/src/java/com/jahia/clipping/Bean UrlBean.java 
    war/src/java/com/jahia/clipping/struts SelectPartAction.java 
    war/src/java/com/jahia/clipping/web/Url/Impl UrlEncoder.java 
  Added files:
    war/src/java/com/jahia/clipping/util URLUtilities.java 
  Removed files:
    war/src/java/com/jahia/clipping/web/Url/Impl QueryWrapper.java 
                                                 QueryWrapperManager.java 
                                                 URLParser.java 
                                                 URLUtilities.java 
  Log:
  Refactoring
  Removing bad files
  
  Revision  Changes    Path
  1.5       +1 -1      
webclip_builder/war/src/java/com/jahia/clipping/Bean/UrlBean.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/Bean/UrlBean.java.diff?r1=1.4&r2=1.5&f=h
  1.6       +11 -39    
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.5&r2=1.6&f=h
  1.1       +319 -0    
webclip_builder/war/src/java/com/jahia/clipping/util/URLUtilities.java (new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/util/URLUtilities.java?rev=1.1&content-type=text/plain
  1.2       +0 -60     
webclip_builder/war/src/java/com/jahia/clipping/web/Url/Impl/QueryWrapper.java 
(dead)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/web/Url/Impl/QueryWrapper.java?rev=1.1&content-type=text/plain
  1.2       +0 -60     
webclip_builder/war/src/java/com/jahia/clipping/web/Url/Impl/QueryWrapperManager.java
 (dead)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/web/Url/Impl/QueryWrapperManager.java?rev=1.1&content-type=text/plain
  1.3       +0 -98     
webclip_builder/war/src/java/com/jahia/clipping/web/Url/Impl/URLParser.java 
(dead)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/web/Url/Impl/URLParser.java?rev=1.2&content-type=text/plain
  1.6       +0 -237    
webclip_builder/war/src/java/com/jahia/clipping/web/Url/Impl/URLUtilities.java 
(dead)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/web/Url/Impl/URLUtilities.java?rev=1.5&content-type=text/plain
  1.2       +1 -0      
webclip_builder/war/src/java/com/jahia/clipping/web/Url/Impl/UrlEncoder.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/web/Url/Impl/UrlEncoder.java.diff?r1=1.1&r2=1.2&f=h
  
  
  
  Index: UrlBean.java
  ===================================================================
  RCS file: 
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/Bean/UrlBean.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- UrlBean.java      9 Jun 2005 16:46:12 -0000       1.4
  +++ UrlBean.java      10 Jun 2005 09:05:07 -0000      1.5
  @@ -3,7 +3,7 @@
   import java.net.*;
   import java.util.*;
   
  -import com.jahia.clipping.web.Url.Impl.*;
  +import com.jahia.clipping.util.*;
   import com.jahia.clipping.web.html.*;
   
   /**
  
  
  
  Index: SelectPartAction.java
  ===================================================================
  RCS file: 
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/struts/SelectPartAction.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SelectPartAction.java     9 Jun 2005 16:46:13 -0000       1.5
  +++ SelectPartAction.java     10 Jun 2005 09:05:07 -0000      1.6
  @@ -131,21 +131,13 @@
                selectPartForm.setSelectedContent(selectedContent);
   
                //set the HTMLFilter
  -             ExtractorFilterBuilder filterBuilder = null;
  -             // 0 = dynamic, 1 = static
  -             if 
(selectPartForm.getWebClippingTypeContent().equalsIgnoreCase("0")) {
  -                     filterBuilder = new 
ExtractoFilterBuilderImpl(StringTreeExtractorFilter.class);
  -             }
  -             else if 
(selectPartForm.getWebClippingTypeContent().equalsIgnoreCase("1")) {
  -                     filterBuilder = new 
ExtractoFilterBuilderImpl(SimpleExtractorFilter.class);
  -             }
  -             else {
  -                     logger.error("[Unexpected value " +
  -                                     
selectPartForm.getWebClippingTypeContent() + " ]");
  -             }
  +             ExtractorFilter filter = new SimpleExtractorFilter();
  +
  +             //set the key of the filter
  +             String key = hashSelectedPart;
  +             filter.setKeyPart(key);
   
  -             logger.debug("[ Selected content is " + selectedContent + " ]");
  -             ExtractorFilter filter = filterBuilder.build(doc, 
selectedContent);
  +             // set the filter
                bean.setFilter(filter);
   
                return actionMapping.findForward("preview");
  @@ -161,10 +153,7 @@
         [EMAIL PROTECTED]  httpServletResponse  Description of Parameter
         [EMAIL PROTECTED]                      Description of the Returned 
Value
         */
  -     public ActionForward chewCut(ActionMapping actionMapping,
  -                     ActionForm actionForm,
  -                     HttpServletRequest httpServletRequest,
  -                     HttpServletResponse httpServletResponse) {
  +     public ActionForward chewCut(ActionMapping actionMapping, ActionForm 
actionForm, HttpServletRequest httpServletRequest, HttpServletResponse 
httpServletResponse) {
                logger.debug("[ Action = chew cut ]");
                SelectPartForm selectPartForm = (SelectPartForm) actionForm;
   
  @@ -176,10 +165,10 @@
                }
   
                // process the source url in and print the document
  -             HTMLDocument jdoc = getHTMLDocument(httpServletRequest);
  +             HTMLDocument doc = getHTMLDocument(httpServletRequest);
   
                // set the content
  -             selectPartForm.setBodyContent(jdoc.getChewDocumentAsString());
  +             selectPartForm.setBodyContent(doc.getChewDocumentAsString());
   
                return actionMapping.getInputForward();
        }
  @@ -221,10 +210,7 @@
         [EMAIL PROTECTED]  httpServletResponse  Description of Parameter
         [EMAIL PROTECTED]                      Description of the Returned 
Value
         */
  -     public ActionForward rulesConfig(ActionMapping actionMapping,
  -                     ActionForm actionForm,
  -                     HttpServletRequest httpServletRequest,
  -                     HttpServletResponse httpServletResponse) {
  +     public ActionForward rulesConfig(ActionMapping actionMapping, 
ActionForm actionForm, HttpServletRequest httpServletRequest, 
HttpServletResponse httpServletResponse) {
                SelectPartForm selectPartForm = (SelectPartForm) actionForm;
                //Get the ClipperBean object
                HttpSession session = httpServletRequest.getSession();
  @@ -252,22 +238,8 @@
                                        
selectPartForm.getWebClippingTypeContent() + " ]");
                }
   
  -             //set the HTMLFilter
  -             ExtractorFilterBuilder filterBuilder = null;
  -             // 0 = dynamic, 1 = static
  -             if 
(selectPartForm.getWebClippingTypeContent().equalsIgnoreCase("0")) {
  -                     filterBuilder = new 
ExtractoFilterBuilderImpl(StringTreeExtractorFilter.class);
  -             }
  -             else if 
(selectPartForm.getWebClippingTypeContent().equalsIgnoreCase("1")) {
  -                     filterBuilder = new 
ExtractoFilterBuilderImpl(SimpleExtractorFilter.class);
  -             }
  -             else {
  -                     logger.error("[Unexpected value " +
  -                                     
selectPartForm.getWebClippingTypeContent() + " ]");
  -             }
  -
                //  logger.debug("[ Selected content is "+selectedContent+" ]");
  -             ExtractorFilter filter = filterBuilder.build(doc, 
selectedContent);
  +             ExtractorFilter filter = new SimpleExtractorFilter();
                bean.setFilter(filter);
   
                return actionMapping.findForward("preview");
  
  
  
  Index: UrlEncoder.java
  ===================================================================
  RCS file: 
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/web/Url/Impl/UrlEncoder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- UrlEncoder.java   3 Mar 2005 18:03:56 -0000       1.1
  +++ UrlEncoder.java   10 Jun 2005 09:05:07 -0000      1.2
  @@ -1,6 +1,7 @@
   package com.jahia.clipping.web.Url.Impl;
   
   import javax.servlet.http.*;
  +import com.jahia.clipping.util.*;
   
   /**
    *  Object that perform the encoding of the url
  
  
  
  Index: URLUtilities.java
  ====================================================================
  package com.jahia.clipping.util;
  
  import java.net.*;
  
  import java.io.*;
  import java.util.*;
  
  /**
   *  Description of the Class
   *
   [EMAIL PROTECTED]    Tlili Khaled
   */
  public abstract class URLUtilities {
        private static org.apache.log4j.Logger logger = 
org.apache.log4j.Logger.getLogger(URLUtilities.class);
  
  
        /**
         *  Gets the URL attribute of the URLUtilities object
         *
         [EMAIL PROTECTED]  url  Description of Parameter
         [EMAIL PROTECTED]      The URL value
         */
        public static URL getURL(String url) {
                URL uurl = null;
                try {
                        uurl = new URL(url);
  
                }
                catch (MalformedURLException ex) {
                        logger.error(" [ Url " + url + " malformed ] ");
                }
                return uurl;
        }
  
  
        /**
         *  Constructor for the URLUtilities object
         *
         */
        /*
         *  public static String getRessourceAbsoluteUrl(String baseUrl, String 
url) throws WebClippingException {
         *  if (url == null || url.length() == 0) {
         *  logger.warn("[ Url is null or empty string !!]");
         *  throw new WebClippingException("Url to rewrite is null", new 
Exception("Kind of null exception"));
         *  }
         *  // if relatif --> absolute
         *  if (isRelatif(url)) {
         *  //logger.debug("[ Old Url is: " + url + " ]");
         *  try {
         *  URL baseURL = new URL(baseUrl);
         *  //logger.debug("[ Base Url is: " + baseURL.toString() + " ]");
         *  // add '/'
         *  if (url.charAt(0) != '/') {
         *  url = '/' + url;
         *  }
         *  // set the base
         *  URL u = new URL(baseURL, url);
         *  url = u.toString();
         *  }
         *  catch (MalformedURLException ex) {
         *  logger.error("[Relatif url" + url + " ]");
         *  ex.printStackTrace();
         *  }
         *  }
         *  else {
         *  //logger.debug("[ URL " + url + " is an absolute url ]");
         *  }
         *  //logger.debug("[ New url " + url + " ]");
         *  return url;
         *  }
         */
  
        /**
         *  Gets the HrefAbsoluteValue attribute of the URLUtilities class
         *
         [EMAIL PROTECTED]  baseURL  Description of Parameter
         [EMAIL PROTECTED]  url      Description of Parameter
         [EMAIL PROTECTED]          The HrefAbsoluteValue value
         */
        public static String getHrefAbsoluteValue(URL baseURL, String url) {
  
                //logger.debug("[ Get absolute url of: " + url + " ]");
                try {
                        return getAbsolutURL(baseURL, url).toExternalForm();
                }
                catch (MalformedURLException ex) {
                        logger.error("[ Malformed url ]");
                        return url;
                }
        }
  
  
        /**
         *  Gets the HrefAbsoluteValue attribute of the URLUtilities class
         *
         [EMAIL PROTECTED]  baseUrl  Description of Parameter
         [EMAIL PROTECTED]  url      Description of Parameter
         [EMAIL PROTECTED]          The HrefAbsoluteValue value
         */
        public static String getHrefAbsoluteValue(String baseUrl, String url) {
                //logger.debug("[ Get absolute url of: " + url + " ]");
                try {
                        return getAbsolutURL(getURL(baseUrl), 
url).toExternalForm();
                }
                catch (MalformedURLException ex) {
                        logger.error("[ Malformed url ]");
                        return url;
                }
        }
  
  
        /**
         *  test if its a relatif url or not
         *
         [EMAIL PROTECTED]  url  Description of Parameter
         [EMAIL PROTECTED]      The Relatif value
         */
        public static boolean isRelatif(String url) {
                try {
                        new URL(url);
                        return false;
                }
                catch (MalformedURLException ex) {
                        return true;
                }
  
        }
  
  
        /**
         *  relative Url --> absolute URL
         *
         [EMAIL PROTECTED]  baseURL                    Description of Parameter
         [EMAIL PROTECTED]  relativeUrl                Description of Parameter
         [EMAIL PROTECTED]                            Description of the 
Returned Value
         [EMAIL PROTECTED]  MalformedURLException  Description of Exception
         */
        public static URL getAbsolutURL(final URL baseURL, String relativeUrl) 
throws MalformedURLException {
                return 
com.gargoylesoftware.htmlunit.WebClient.expandUrl(baseURL, relativeUrl);
        }
  
  
        /**
         *  Url --> {path of the url , uery of the url}
         *
         [EMAIL PROTECTED]  url  Description of Parameter
         [EMAIL PROTECTED]      Description of the Returned Value
         */
        public static String[] splitQuery(String url) {
                String[] result = {"", ""};
  
                // looking gor the query
                int queryIndex = url.indexOf('?');
                if (queryIndex > 0) {
                        //rsplit in to part
                        StringTokenizer st = new StringTokenizer(url, "?");
                        int i = 0;
                        while (st.hasMoreTokens()) {
                                result[i] = st.nextToken();
                                i++;
                        }
                }
                else {
                        // there is no query
                        result[0] = url;
                }
                //logger.debug("[ URL is: " + url + " ]");
                //logger.debug("[ Path is: " + result[0] + " ]");
                //logger.debug("[ Query is: " + result[1] + " ]");
  
                return result;
        }
  
  
        /**
         *  Description of the Method
         *
         [EMAIL PROTECTED]  url  Description of Parameter
         [EMAIL PROTECTED]      Description of the Returned Value
         */
        public static String encode(String url) {
                String result = null;
                try {
                        result = URLEncoder.encode(url, "UTF-8");
                        //logger.debug("[ Succes Encode ]");
                }
                catch (UnsupportedEncodingException ex) {
                        logger.error("[ Enable to encode url: " + url + " ]");
                }
                finally {
                        return result;
                }
        }
  
  
        /**
         *  Description of the Method
         *
         [EMAIL PROTECTED]  url  Description of Parameter
         [EMAIL PROTECTED]      Description of the Returned Value
         */
        public static String decode(String url) {
                String result = null;
                try {
                        result = URLDecoder.decode(url, "UTF-8");
                        //logger.debug("[ Succes decoding ]");
                }
                catch (UnsupportedEncodingException ex) {
                        logger.error("[ Enable to decode url: " + url + " ]");
                }
                finally {
                        return result;
                }
        }
  
  
        /**
         *  Extract the parameters from an url
         *
         [EMAIL PROTECTED]  urlValue         Description of Parameter
         [EMAIL PROTECTED]                  Description of the Returned Value
         [EMAIL PROTECTED]  IOException  Description of Exception
         */
        public static ArrayList parseUrl(String urlValue) throws IOException {
                //Set the parameter from the Url
                ArrayList param = new ArrayList();
                URL url = null;
                try {
                        url = new URL(urlValue);
                }
                catch (IOException ex) {
                        ex.printStackTrace();
                }
  
                //Determine the uri part
                String uri = url.getFile();
  
                //the query part
                String query = replaceSpecialGraphics(url.getQuery());
  
                if (query != null) {
                        //param1=value1&param2=value2...
                        String[] queryParam = query.split("&");
                        for (int i = 0; i < queryParam.length; i++) {
                                // param1=value1
                                String nameAndValue = queryParam[i];
                                int indexEqual = nameAndValue.indexOf('=');
                                try {
                                        String name = 
URLDecoder.decode(nameAndValue.substring(0, indexEqual), "UTF-8");
                                        String value = 
URLDecoder.decode(nameAndValue.substring(indexEqual +
                                                        1), "UTF-8");
                                        String[] p = {name, value};
                                        param.add(p);
                                }
                                catch (UnsupportedEncodingException exc) {
                                        exc.printStackTrace();
                                }
                        }
                }
                return param;
        }
  
  
        /**
         *  Gets the Path attribute of the URLUtilities class
         *
         [EMAIL PROTECTED]  url  Description of Parameter
         [EMAIL PROTECTED]      The Path value
         */
        private static String getPath(String url) {
                String path = url;
                int lastIndexSeparator = url.lastIndexOf('/');
                if (lastIndexSeparator > 0) {
                        path = url.substring(0, lastIndexSeparator);
                }
                logger.debug("[ Path is: " + path + " ]");
                return path;
        }
  
  
        /**
         *  Description of the Method
         *
         [EMAIL PROTECTED]  query  Description of Parameter
         [EMAIL PROTECTED]        Description of the Returned Value
         */
        private static String replaceSpecialGraphics(String query) {
                if (query == null) {
                        return null;
                }
                Object[][] specialGraphic = {
                                {
                                "&lt;", "<"}
                                , {
                                "&gt;", ">"}
                                , {
                                "&amp;", "&"}
                                , {
                                "&quot;", "\""}
                                , {
                                "nbsp;", ""}
                                , {
                                "&reg;", ""}
                                , {
                                "copy;", ""}
                                , {
                                "&ensp;", ""}
                                , {
                                "&emsp", ""}
                                };
  
                for (int i = 0; i < specialGraphic.length; i++) {
                        query = query.replaceAll((String) specialGraphic[i][0],
                                        (String) specialGraphic[i][1]);
                }
                return query;
        }
  
  }
  

Reply via email to