constructing it every time it is needed.
import org.apache.xml.serialize.XMLSerializer;
import org.w3c.dom.Document;
import org.w3c.tidy.Tidy;
-import org.wamblee.xml.ClasspathUriResolver;
import org.wamblee.xml.DOMUtility;
import org.wamblee.xml.XslTransformer;
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);
- XslTransformer xsltProcessor = new XslTransformer(new ClasspathUriResolver());
- Document transformed = xsltProcessor.transform(xhtmlData,
- xsltProcessor.resolve(_xslt));
+ Document transformed = _transformer.transform(xhtmlData,
+ _transformer.resolve(_xslt));
ByteArrayOutputStream os = new ByteArrayOutputStream();
Transformer transformer = TransformerFactory.newInstance()
.newTransformer();
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.w3c.dom.Document;
+import org.wamblee.xml.XslTransformer;
/**
* Gets a page by issueing a get request.
* @param aParams Request parameters to use.
* @param aXslt XSLT to use.
*/
- public GetPageRequest(int aMaxTries, int aMaxDelay, NameValuePair[] aParams, String aXslt) {
- super(aMaxTries, aMaxDelay, aParams, aXslt);
+ public GetPageRequest(int aMaxTries, int aMaxDelay, NameValuePair[] aParams, String aXslt, XslTransformer aTransformer) {
+ super(aMaxTries, aMaxDelay, aParams, aXslt, aTransformer);
}
/*
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.w3c.dom.Document;
+import org.wamblee.xml.XslTransformer;
/**
* Retrieving pages using the post method.
* @param aParams Request parameters to use.
* @param aXslt XSLT to use.
*/
- public PostPageRequest(int aMaxTries, int aMaxDelay, NameValuePair[] aParams, String aXslt) {
- super(aMaxTries, aMaxDelay, aParams, aXslt);
+ public PostPageRequest(int aMaxTries, int aMaxDelay, NameValuePair[] aParams, String aXslt, XslTransformer aTransformer) {
+ super(aMaxTries, aMaxDelay, aParams, aXslt, aTransformer);
}
/*
import org.wamblee.crawler.Crawler;
import org.wamblee.crawler.Page;
import org.wamblee.crawler.PageException;
+import org.wamblee.xml.XslTransformer;
/*
* Copyright 2005 the original author or authors.
String configFileName = aArgs[0];
String starturl = aArgs[1];
- ConfigurationParser parser = new ConfigurationParser();
+ ConfigurationParser parser = new ConfigurationParser(new XslTransformer());
InputStream configFile = new FileInputStream(new File(configFileName));
Configuration config = parser.parse(configFile);
import org.wamblee.crawler.GetPageRequest;
import org.wamblee.crawler.PageRequest;
import org.wamblee.crawler.PostPageRequest;
+import org.wamblee.xml.XslTransformer;
/**
* Parsing of the configuration from an XML file.
private static final int MAX_TRIES = 3;
private static final int MAX_DELAY = 100;
+
+ private XslTransformer _transformer;
/**
* Constructs the configuration parser.
*/
- public ConfigurationParser() {
- // Empty
+ public ConfigurationParser(XslTransformer aTransformer) {
+ _transformer = aTransformer;
}
/**
PageRequest request;
if (METHOD_POST.equals(method)) {
request = new PostPageRequest(MAX_TRIES, MAX_DELAY, paramsArray,
- xslt);
+ xslt, _transformer);
} else if (METHOD_GET.equals(method) || method == null) {
request = new GetPageRequest(MAX_TRIES, MAX_DELAY, paramsArray,
- xslt);
+ xslt, _transformer);
} else {
throw new RuntimeException("Unknown request method '" + method
+ "'. Only " + METHOD_GET + " and " + METHOD_POST
import org.wamblee.crawler.kiss.guide.TimeInterval;
import org.wamblee.crawler.kiss.notification.NotificationException;
import org.wamblee.crawler.kiss.notification.Notifier;
+import org.wamblee.xml.ClasspathUriResolver;
+import org.wamblee.xml.XslTransformer;
/**
* The KiSS crawler for automatic recording of interesting TV shows.
try {
HttpClient client = new HttpClient();
// client.getHostConfiguration().setProxy("127.0.0.1", 3128);
+
+ XslTransformer transformer = new XslTransformer(new ClasspathUriResolver());
- Crawler crawler = createCrawler(aCrawlerConfig, client);
+ Crawler crawler = createCrawler(aCrawlerConfig, client, transformer);
InputStream programConfigFile = new FileInputStream(new File(
aProgramConfig));
- ProgramConfigurationParser parser = new ProgramConfigurationParser();
+ ProgramConfigurationParser parser = new ProgramConfigurationParser(transformer);
parser.parse(programConfigFile);
List<ProgramFilter> programFilters = parser.getFilters();
* In case configuration files cannot be found.
*/
private Crawler createCrawler(String aCrawlerConfig,
- HttpClient aClient) throws FileNotFoundException {
- ConfigurationParser parser = new ConfigurationParser();
+ HttpClient aClient, XslTransformer aTransformer) throws FileNotFoundException {
+ ConfigurationParser parser = new ConfigurationParser(aTransformer);
InputStream crawlerConfigFile = new FileInputStream(new File(
aCrawlerConfig));
Configuration config = parser.parse(crawlerConfigFile);
import org.wamblee.crawler.kiss.notification.MailNotifier;
import org.wamblee.crawler.kiss.notification.MailServer;
import org.wamblee.crawler.kiss.notification.Notifier;
+import org.wamblee.xml.XslTransformer;
/**
* Parse the configuration of desired programs.
private static final String ACTION_NOTIFY = "notify";
private List<ProgramFilter> _filters;
+
+ private XslTransformer _transformer;
private Notifier _notifier;
- ProgramConfigurationParser() {
+ ProgramConfigurationParser(XslTransformer aTransformer) {
_filters = null;
_notifier = null;
+ _transformer = aTransformer;
}
/**
String htmlXslt = format.elementTextTrim(ELEM_HTML);
String textXslt = format.elementTextTrim(ELEM_TEXT);
- return new MailNotifier(from, to, subject, htmlXslt, textXslt, server);
+ return new MailNotifier(from, to, subject, htmlXslt, textXslt, server, _transformer);
}
/**
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.dom4j.Element;
-import org.wamblee.xml.ClasspathUriResolver;
import org.wamblee.xml.XslTransformer;
/**
private String _textXslt;
private MailServer _server;
+
+ private XslTransformer _transformer;
/**
* Constructs the notifier.
* XSLT file to transform the report into text.
* @param aServer
* Mail server to use.
+ * @param aTransformer Transformer to use.
*/
public MailNotifier(String aFrom, String aTo, String aSubject,
- String aHtmlXslt, String aTextXslt, MailServer aServer) {
+ String aHtmlXslt, String aTextXslt, MailServer aServer, XslTransformer aTransformer) {
_from = aFrom;
_to = aTo;
_subject = aSubject;
_htmlXslt = aHtmlXslt;
_textXslt = aTextXslt;
_server = aServer;
+ _transformer = aTransformer;
}
/*
private String transformReport(Element aReport, String aXslt)
throws IOException, TransformerException {
String reportXmlText = aReport.asXML();
- XslTransformer xsltProcessor = new XslTransformer(new ClasspathUriResolver());
- return xsltProcessor.textTransform(reportXmlText.getBytes(), xsltProcessor.resolve(aXslt));
+ return _transformer.textTransform(reportXmlText.getBytes(), _transformer.resolve(aXslt));
}
}