ktlili 2005/07/06 12:48:57 CEST
Modified files:
war/src/java/com/jahia/clipping/struts BrowseAction.java
WebBrowserAction.java
war/src/java/com/jahia/clipping/struts/Util Constants.java
war/src/java/com/jahia/clipping/util URLUtilities.java
war/src/java/com/jahia/clipping/web HTMLDocumentBuilder.java
war/src/java/com/jahia/clipping/web/http/impl
HTMLUnitProcessor.java
Removed files:
war/src/java/com/jahia/clipping/struts DefaultErrorAction.java
DefaultErrorForm.java
Log:
- Fix remove bug whith HTMLUnitProcessor
- Remove DefaultError actions
Revision Changes Path
1.14 +10 -6
webclip_builder/war/src/java/com/jahia/clipping/struts/BrowseAction.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/struts/BrowseAction.java.diff?r1=1.13&r2=1.14&f=h
1.4 +0 -25
webclip_builder/war/src/java/com/jahia/clipping/struts/DefaultErrorAction.java
(dead)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/struts/DefaultErrorAction.java?rev=1.3&content-type=text/plain
1.3 +0 -65
webclip_builder/war/src/java/com/jahia/clipping/struts/DefaultErrorForm.java
(dead)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/struts/DefaultErrorForm.java?rev=1.2&content-type=text/plain
1.5 +1 -0
webclip_builder/war/src/java/com/jahia/clipping/struts/Util/Constants.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/struts/Util/Constants.java.diff?r1=1.4&r2=1.5&f=h
1.13 +42 -16
webclip_builder/war/src/java/com/jahia/clipping/struts/WebBrowserAction.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/struts/WebBrowserAction.java.diff?r1=1.12&r2=1.13&f=h
1.6 +16 -10
webclip_builder/war/src/java/com/jahia/clipping/util/URLUtilities.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/util/URLUtilities.java.diff?r1=1.5&r2=1.6&f=h
1.13 +75 -19
webclip_builder/war/src/java/com/jahia/clipping/web/HTMLDocumentBuilder.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclip_builder/war/src/java/com/jahia/clipping/web/HTMLDocumentBuilder.java.diff?r1=1.12&r2=1.13&f=h
1.13 +17 -18
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.12&r2=1.13&f=h
Index: BrowseAction.java
===================================================================
RCS file:
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/struts/BrowseAction.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- BrowseAction.java 5 Jul 2005 15:44:08 -0000 1.13
+++ BrowseAction.java 6 Jul 2005 10:48:56 -0000 1.14
@@ -8,6 +8,7 @@
import com.jahia.clipping.Bean.*;
import java.util.*;
import com.jahia.clipping.web.*;
+import com.jahia.clipping.web.http.*;
/**
* Description of the Class
@@ -337,7 +338,6 @@
removeLastUrlandSetHTMLContent(httpServletRequest,
httpServletResponse, browseForm);
getWebBrowserForm(httpServletRequest).setShow(Constants.WEB_BROWSER_SHOW_LAST_DOCUMENT);
-
//logger.debug("[
"+uBean.getDocument().getTransformedDocumentAsString()+" ]");
return actionMapping.getInputForward();
}
@@ -404,7 +404,7 @@
[EMAIL PROTECTED] The RequestedAndTransformedDocument
value
[EMAIL PROTECTED] Exception Description of Exception
*/
- private HTMLDocument getRequestedDocument(HttpServletRequest request,
HttpServletResponse response, UrlBean uBean, String httpMethod) throws
Exception {
+/* private HTMLDocument getRequestedDocument(HttpServletRequest request,
HttpServletResponse response, UrlBean uBean, String httpMethod) throws
Exception {
// Get a HMTLDocument builder
HTMLDocumentBuilder builder = new HTMLDocumentBuilder(uBean,
httpMethod);
@@ -468,9 +468,9 @@
* //logger.debug("[ ERROR ]"+error);
* }
* addErrors(request, actionErrors);
- */
+
return doc;
- }
+ }*/
@@ -500,8 +500,12 @@
}
- //update browser form
-
getWebBrowserForm(httpServletRequest).setShow(Constants.WEB_BROWSER_SHOW_LAST_DOCUMENT);
+ // get the client
+ HttpSession session = httpServletRequest.getSession();
+ HTMLClient client = (HTMLClient)
session.getAttribute(com.jahia.clipping.web.Constant.WebConstants.ADVANCED_WEBCLIENT);
+ if (client != null) {
+ client.removeLastUrl();
+ }
}
Index: WebBrowserAction.java
===================================================================
RCS file:
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/struts/WebBrowserAction.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- WebBrowserAction.java 5 Jul 2005 15:44:08 -0000 1.12
+++ WebBrowserAction.java 6 Jul 2005 10:48:56 -0000 1.13
@@ -54,6 +54,17 @@
/**
+ * Sets the HTMLDocumentBuilder attribute of the WebBrowserAction
object
+ *
+ [EMAIL PROTECTED] request The new HTMLDocumentBuilder value
+ [EMAIL PROTECTED] h The new HTMLDocumentBuilder value
+ */
+ public void setHTMLDocumentBuilder(HttpServletRequest request,
HTMLDocumentBuilder h) {
+
request.getSession().setAttribute(Constants.HTMLDOCUMENT_BUILDER, h);
+ }
+
+
+ /**
* Gets the ClipperBean attribute of the ClipperAction object
*
[EMAIL PROTECTED] httpServletRequest Description of Parameter
@@ -119,6 +130,29 @@
/**
+ * Gets the HTMLDocumentBuilder attribute of the WebBrowserAction
object
+ *
+ [EMAIL PROTECTED] request Description of Parameter
+ [EMAIL PROTECTED] The HTMLDocumentBuilder value
+ */
+ public HTMLDocumentBuilder getHTMLDocumentBuilder(HttpServletRequest
request) {
+ return (HTMLDocumentBuilder)
request.getSession().getAttribute(Constants.HTMLDOCUMENT_BUILDER);
+ }
+
+
+ /**
+ * Description of the Method
+ *
+ [EMAIL PROTECTED] request Description of Parameter
+ [EMAIL PROTECTED] h Description of Parameter
+ */
+ public void removeHTMLDocumentBuilder(HttpServletRequest request,
HTMLDocumentBuilder h) {
+
request.getSession().removeAttribute(Constants.HTMLDOCUMENT_BUILDER);
+ }
+
+
+
+ /**
* Description of the Method
*
[EMAIL PROTECTED] request Description of Parameter
@@ -351,9 +385,9 @@
com.jahia.clipping.web.RegisterSSLProctocol.registerSSLProtocol();
}
- //get browser javascript configuration
- int browserJavascriptEvent =
Integer.parseInt(configBean.getBrowserJavascriptEvent());
- int browserJavascriptCode =
Integer.parseInt(configBean.getBrowserJavascriptCode());
+ //get browser javascript configuration
+ int browserJavascriptEvent =
Integer.parseInt(configBean.getBrowserJavascriptEvent());
+ int browserJavascriptCode =
Integer.parseInt(configBean.getBrowserJavascriptCode());
// get the type of the client and the parser
int clientType = Integer.parseInt(configBean.getClient());
@@ -382,23 +416,14 @@
//headers[0] = new
org.apache.commons.httpclient.Header("Content-Type", "text/html;
charset="+encodingValue);
//configure the builder
- builder.configure(clientType,
parserType,browserJavascriptEvent,browserJavascriptCode, javascriptBool,
cssBool, headers);
+ builder.configure(clientType, parserType,
browserJavascriptEvent, browserJavascriptCode, javascriptBool, cssBool,
headers);
+
// execute
HTMLDocument doc = builder.execute(request, response);
- //Get and save all errors that's occured during execution
- /*
- * List errors = builder.getParsingErrors();
- * ActionErrors actionErrors = new ActionErrors();
- * for (int i = 0; i < errors.size(); i++) {
- * String error = errors.get(i).toString();
- * ActionError e = new ActionError("errors.message", error);
- * actionErrors.add("errors.message", e);
- * //logger.debug("[ ERROR ]"+error);
- * }
- * saveErrors(request, actionErrors);
- */
+ //set in the session
+ setHTMLDocumentBuilder(request, builder);
return doc;
}
@@ -528,6 +553,7 @@
URLWrapper uw =
getURLMap(httpServletRequest).getSourceUrl(hash);
if (uw == null) {
logger.error("URLWrapper not found");
+ logger.debug("Key = " + hash);
}
String relativeURL = uw.getSourceUrl();
Index: Constants.java
===================================================================
RCS file:
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/struts/Util/Constants.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Constants.java 23 Jun 2005 16:15:47 -0000 1.4
+++ Constants.java 6 Jul 2005 10:48:56 -0000 1.5
@@ -15,6 +15,7 @@
public static final String WEB_BROWSER_SHOW_PREVIEW = "preview";
public static final String WEB_BROWSER_SHOW_TEST = "test";
public static final String WEB_BROWSER_SIMULATOR =
"WebBrowserSimulator";
+ public static final String HTMLDOCUMENT_BUILDER = "HTMLDocumentBuilder";
//test
public static final int TEST = -1;
Index: URLUtilities.java
===================================================================
RCS file:
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/util/URLUtilities.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- URLUtilities.java 4 Jul 2005 12:52:18 -0000 1.5
+++ URLUtilities.java 6 Jul 2005 10:48:57 -0000 1.6
@@ -4,6 +4,7 @@
import java.io.*;
import java.util.*;
+import org.apache.commons.lang.StringUtils;
/**
* Description of the Class
@@ -155,14 +156,16 @@
int queryIndex = url.indexOf('?');
if (queryIndex > 1) {
//rsplit in to part
- result[0] = url.substring(0,queryIndex);
- result[1] = url.substring(queryIndex+1);
- /*StringTokenizer st = new StringTokenizer(url, "?");
- int i = 0;
- while (st.hasMoreTokens()) {
- result[i] = st.nextToken();
- i++;
- }*/
+ result[0] = url.substring(0, queryIndex);
+ result[1] = url.substring(queryIndex + 1);
+ /*
+ * StringTokenizer st = new StringTokenizer(url, "?");
+ * int i = 0;
+ * while (st.hasMoreTokens()) {
+ * result[i] = st.nextToken();
+ * i++;
+ * }
+ */
}
else {
// there is no query
@@ -183,7 +186,11 @@
[EMAIL PROTECTED] Description of the Returned Value
*/
public static String encode(String url) {
- return url.replaceAll("/", "_").replaceAll("&", "_");
+ url = StringUtils.replaceChars(url, "/", "_");
+ url = StringUtils.replaceChars(url, "&", "_");
+ url = StringUtils.replaceChars(url, "+", "_");
+ url = StringUtils.replaceChars(url, "#", "_");
+ return url;
}
@@ -251,5 +258,4 @@
return path;
}
-
}
Index: HTMLDocumentBuilder.java
===================================================================
RCS file:
/home/cvs/repository/webclip_builder/war/src/java/com/jahia/clipping/web/HTMLDocumentBuilder.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- HTMLDocumentBuilder.java 5 Jul 2005 15:44:09 -0000 1.12
+++ HTMLDocumentBuilder.java 6 Jul 2005 10:48:57 -0000 1.13
@@ -1,18 +1,19 @@
package com.jahia.clipping.web;
+import java.io.*;
+
import javax.servlet.http.*;
+
import com.jahia.clipping.Bean.*;
import com.jahia.clipping.util.*;
+import com.jahia.clipping.web.html.*;
import com.jahia.clipping.web.html.Impl.*;
+import com.jahia.clipping.web.html.Impl.HTMLParser.*;
import com.jahia.clipping.web.html.Impl.JDom.*;
import com.jahia.clipping.web.html.Impl.Neko.*;
-import com.jahia.clipping.web.html.Impl.HTMLParser.*;
import com.jahia.clipping.web.http.impl.*;
-import java.io.*;
-import org.xml.sax.*;
-import com.jahia.clipping.web.html.*;
import org.apache.commons.httpclient.*;
-import java.util.*;
+import org.xml.sax.*;
/**
* Description of the Class
@@ -21,8 +22,8 @@
*/
public class HTMLDocumentBuilder {
boolean enableCSS_ = true;
- private String httpMethod_;
- private UrlBean uBean_;
+ private String httpMethod;
+ private UrlBean uBean;
//configuration
private int typeClient_ = CLIENT_HTMLUNIT;
@@ -31,6 +32,7 @@
private int browserJavascriptEvent_;
private int browserJavascriptCode_;
private Header[] headers_ = null;
+ private UrlBean UBean;
/**
* Description of the Field
@@ -70,7 +72,6 @@
private static org.apache.log4j.Logger logger =
org.apache.log4j.Logger.getLogger(HTMLDocumentBuilder.class);
-
/**
* Constructor for the HTMLDocumentBuilder object
*
@@ -78,8 +79,48 @@
[EMAIL PROTECTED] httpMethod Description of Parameter
*/
public HTMLDocumentBuilder(UrlBean uBean, String httpMethod) {
- this.uBean_ = uBean;
- this.httpMethod_ = httpMethod;
+ this.uBean = uBean;
+ this.httpMethod = httpMethod;
+ }
+
+
+ /**
+ * Sets the UBean attribute of the HTMLDocumentBuilder object
+ *
+ [EMAIL PROTECTED] UBean The new UBean value
+ */
+ public void setUBean(UrlBean UBean) {
+ this.UBean = UBean;
+ }
+
+
+ /**
+ * Sets the HttpMethod attribute of the HTMLDocumentBuilder object
+ *
+ [EMAIL PROTECTED] httpMethod The new HttpMethod value
+ */
+ public void setHttpMethod(String httpMethod) {
+ this.httpMethod = httpMethod;
+ }
+
+
+ /**
+ * Gets the UBean attribute of the HTMLDocumentBuilder object
+ *
+ [EMAIL PROTECTED] The UBean value
+ */
+ public UrlBean getUBean() {
+ return UBean;
+ }
+
+
+ /**
+ * Gets the HttpMethod attribute of the HTMLDocumentBuilder object
+ *
+ [EMAIL PROTECTED] The HttpMethod value
+ */
+ public String getHttpMethod() {
+ return httpMethod;
}
@@ -131,6 +172,21 @@
}
+ /**
+ * Description of the Method
+ *
+ [EMAIL PROTECTED] request Description of Parameter
+ */
+ public void removeUrl(HttpServletRequest request) {
+ HttpSession session = request.getSession();
+ HTMLUnitProcessor client = (HTMLUnitProcessor)
session.getAttribute(com.jahia.clipping.web.Constant.WebConstants.ADVANCED_WEBCLIENT);
+ if (client != null) {
+ client.removeLastUrl();
+ }
+
+ }
+
+
/**
* Gets the HtmlAsString attribute of the HTMLDocumentBuilder object
@@ -189,7 +245,7 @@
[EMAIL PROTECTED] Exception Description of Exception
*/
private HTMLDocument buildHtmlDocument(HttpServletRequest request,
HttpServletResponse response, String html) throws Exception {
- HTMLDocument htmlDocument = new EmptyHTMLDocument(uBean_);
+ HTMLDocument htmlDocument = new EmptyHTMLDocument(uBean);
try {
switch (typeParser_) {
@@ -311,7 +367,7 @@
[EMAIL PROTECTED] Exception Description of Exception
*/
private String[] executeWhithSimpleHTMLUnitClient(HttpServletRequest
request) throws Exception {
- HTMLUnitProcessor client = new HTMLUnitProcessor(headers_,
httpMethod_, uBean_);
+ HTMLUnitProcessor client = new HTMLUnitProcessor(headers_,
httpMethod, uBean);
//set WebClient
HttpSession session = request.getSession();
@@ -346,12 +402,12 @@
// get the client
HTMLUnitProcessor client = (HTMLUnitProcessor)
session.getAttribute(com.jahia.clipping.web.Constant.WebConstants.ADVANCED_WEBCLIENT);
if (client == null) {
- client = new HTMLUnitProcessor(headers_, httpMethod_,
uBean_);
+ client = new HTMLUnitProcessor(headers_, httpMethod,
uBean);
}
else {
- client.setUrlBean(uBean_);
+ client.setUrlBean(uBean);
client.setHeaders(headers_);
- client.setMethod(httpMethod_);
+ client.setMethod(httpMethod);
}
// set javascript
@@ -378,7 +434,7 @@
[EMAIL PROTECTED] Exception Description of Exception
*/
private String executeWhithHttpClient(HttpServletRequest request)
throws Exception {
- HttpProcessor client = new HttpProcessor(httpMethod_, uBean_);
+ HttpProcessor client = new HttpProcessor(httpMethod, uBean);
//set HttpState
HttpSession session = request.getSession();
@@ -428,7 +484,7 @@
}
//convert to JDomHTML document
- jDoc = new JDomHTMLDocument(uBean_, w3cDoc);
+ jDoc = new JDomHTMLDocument(uBean, w3cDoc);
if (jDoc == null) {
logger.error("[Get HTMLDocument failed !!!!]");
}
@@ -459,7 +515,7 @@
HTMLParserDocument doc = null;
//convert to JDomHTML document
- doc = new HTMLParserDocument(uBean_, html);
+ doc = new HTMLParserDocument(uBean, html);
if (doc == null) {
logger.error("[Get HTMLDocument failed !!!!]");
}
@@ -505,7 +561,7 @@
}
//convert to XercesHTMLDocument
- xDoc = new DomHTMLDocument(uBean_, w3cDoc, html);
+ xDoc = new DomHTMLDocument(uBean, w3cDoc, html);
if (xDoc == null) {
logger.error("[Get HTMLDocument failed !!!!]");
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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- HTMLUnitProcessor.java 5 Jul 2005 08:57:07 -0000 1.12
+++ HTMLUnitProcessor.java 6 Jul 2005 10:48:57 -0000 1.13
@@ -45,12 +45,11 @@
String html = "";
try {
// first page
- HtmlPage page = getLastPage();
- if (page == null) {
+ if (currentPage_ == null) {
logger.debug("First page");
setWebClient(getNewWebClient());
super.execute();
- addPage(page_);
+ addPage(currentPage_);
return;
}
@@ -63,8 +62,8 @@
if (from.equalsIgnoreCase(WebConstants.FROM_LINK)) {
logger.debug("It's a link");
String url = getRequestedUrlFromUrlBean();
- HtmlAnchor anchor = page_.getAnchorByHref(url);
- page_ = (HtmlPage) anchor.click();
+ HtmlAnchor anchor =
currentPage_.getAnchorByHref(url);
+ currentPage_ = (HtmlPage) anchor.click();
}
else if (from.equalsIgnoreCase(WebConstants.FROM_FORM))
{
@@ -80,10 +79,10 @@
HtmlInput submitButton =
getSubmittedButton(form);
if (submitButton == null) {
- page_ = (HtmlPage) form.submit();
+ currentPage_ = (HtmlPage) form.submit();
}
else {
- page_ = (HtmlPage) submitButton.click();
+ currentPage_ = (HtmlPage)
submitButton.click();
}
}
else {
@@ -96,7 +95,7 @@
}
// Get the response
- WebResponse response = page_.getWebResponse();
+ WebResponse response = currentPage_.getWebResponse();
String charSet = response.getContentCharSet();
logger.debug("CharSet: " + charSet);
@@ -114,7 +113,7 @@
logger.debug("[ HTML: " + html + " ]");
//add page
- addPage(page_);
+ addPage(currentPage_);
// set the html
setHtmlAsString(html);
@@ -151,12 +150,11 @@
public void removeLastUrl() {
super.removeLastUrl();
int lastIndex = pageList.size() - 1;
- if (lastIndex > 0) {
+ if (!pageList.isEmpty()) {
// remove the page from the page list
pageList.remove(lastIndex);
-
//update page_ var
- page_ = getLastPage();
+ currentPage_ = getLastPage();
}
else {
logger.debug("Error: page list is already Empty");
@@ -171,12 +169,13 @@
*/
private HtmlPage getLastPage() {
int lastIndex = pageList.size() - 1;
- if (lastIndex > 0) {
+ if (!pageList.isEmpty()) {
+ logger.debug("Get last page");
HtmlPage page = (HtmlPage) pageList.remove(lastIndex);
return page;
}
else {
- logger.debug("Error: page list is Empty");
+ logger.error("Error: page list is Empty");
return null;
}
}
@@ -213,10 +212,10 @@
}
if (submitButton == null) {
- page_ = (HtmlPage) form.submit();
+ currentPage_ = (HtmlPage) form.submit();
}
else {
- page_ = (HtmlPage) submitButton.click();
+ currentPage_ = (HtmlPage) submitButton.click();
}
}
@@ -238,11 +237,11 @@
String submittedFormId =
HashUtilities.getFormIdFromHash(fromHash);
// get the submiited form
if (submittedFormName == null ||
submittedFormName.equalsIgnoreCase("")) {
- form = (HtmlForm)
page_.getHtmlElementById(submittedFormId);
+ form = (HtmlForm)
currentPage_.getHtmlElementById(submittedFormId);
}
else {
- form = (HtmlForm)
page_.getFormByName(submittedFormName);
+ form = (HtmlForm)
currentPage_.getFormByName(submittedFormName);
}
return form;
}