package org.wamblee.crawler;
import java.io.ByteArrayOutputStream;
-import java.io.File;
import java.io.IOException;
import javax.xml.transform.OutputKeys;
import org.apache.xml.serialize.XMLSerializer;
import org.w3c.dom.Document;
import org.w3c.tidy.Tidy;
-import org.wamblee.io.FileResource;
-import org.wamblee.xml.DOMUtility;
-import org.wamblee.xml.XSLT;
+import org.wamblee.xml.DomUtils;
+import org.wamblee.xml.XslTransformer;
/**
* General support claas for all kinds of requests.
private NameValuePair[] _params;
private String _xslt;
+
+ private XslTransformer _transformer;
/**
* Constructs the request.
* XSLT used to convert the response.
*/
protected AbstractPageRequest(int aMaxTries, int aMaxDelay,
- NameValuePair[] aParams, String aXslt) {
+ NameValuePair[] aParams, String aXslt, XslTransformer aTransformer) {
if (aParams == null) {
throw new IllegalArgumentException("aParams is null");
}
_maxDelay = aMaxDelay;
_params = aParams;
_xslt = aXslt;
+ _transformer = aTransformer;
}
/*
aMethod = executeWithRedirects(aClient, aMethod);
byte[] xhtmlData = getXhtml(aMethod);
- Document transformed = new XSLT().transform(xhtmlData,
- new FileResource(new File(_xslt)));
+ Document transformed = _transformer.transform(xhtmlData,
+ _transformer.resolve(_xslt));
ByteArrayOutputStream os = new ByteArrayOutputStream();
Transformer transformer = TransformerFactory.newInstance()
.newTransformer();
LOG.debug("Transformed result is \n" + os.toString());
return transformed;
} catch (TransformerConfigurationException e) {
- throw new RuntimeException(e.getMessage(), e);
+ throw new TransformerException("Transformer configuration problem", e);
} finally {
// Release the connection.
aMethod.releaseConnection();
// in a system wide way.
ByteArrayOutputStream os = new ByteArrayOutputStream();
Document w3cDoc = tidy.parseDOM(aMethod.getResponseBodyAsStream(), os);
- DOMUtility.removeDuplicateAttributes(w3cDoc);
+ DomUtils.removeDuplicateAttributes(w3cDoc);
LOG.debug("Content of response is \n" + os.toString());
ByteArrayOutputStream xhtml = new ByteArrayOutputStream();
// recursion.
}
default: {
- throw new RuntimeException("Method failed: "
+ throw new IOException("Method failed: "
+ aMethod.getStatusLine());
}
}