svn commit: r617035 [18/22] - in /lenya/branches/revolution/1.3.x: ./ src/java/org/apache/lenya/ac/ src/java/org/apache/lenya/ac/cache/ src/java/org/apache/lenya/ac/cifs/ src/java/org/apache/lenya/ac/file/ src/java/org/apache/lenya/ac/impl/ src/java/or...
[email protected] Thu, 31 Jan 2008 07:44:36 -0000
Newsgroups
gmane.comp.cms.lenya.cvs
Message-ID
<[email protected] >
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/ProxyManager.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/ProxyManager.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/ProxyManager.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/ProxyManager.java Wed Jan 30 23:44:03 2008
@@ -14,151 +14,125 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.net;
-
import java.io.File;
import java.util.Properties;
import java.util.Vector;
-
import org.apache.lenya.xml.DocumentHelper;
import org.apache.lenya.xml.XPointerFactory;
-import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-
-
/**
- * The <code>ProxyManager</code> Class is used to set or unset the java systems proxy settings
- * based on the hostname of the host that want to be reached.
+ * The <code>ProxyManager</code> Class is used to set or unset the java systems proxy settings based on the hostname of the host that want to be reached.
*/
public class ProxyManager {
- static Category log = Category.getInstance(ProxyManager.class);
- Vector proxies = null;
-
- /**
- * Creating an instance of ProxyManager without argurments reads the configuration from the
- * default configuration file ($XPS_HOME/xml/xps/proxyconf.xml)
- */
- public ProxyManager() {
- log.debug("" + new Configuration().configurationPath);
- proxies = readConfig(new Configuration().configurationPath);
- }
-
- /**
- * The <code>ProxyManager</code> is created using the customized <code>conffile</code>
- *
- * @param conffile configuration file to use
- */
- public ProxyManager(String conffile) {
- proxies = readConfig(conffile);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param args DOCUMENT ME!
- */
- public static void main(String[] args) {
- if ((args.length > 2) || (args.length < 1)) {
- System.err.println(
- "Usage: java org.apache.lenya.net.ProxyManager host [configfile.xml]");
-
- return;
- }
-
- ProxyManager pm = null;
-
- if (args.length > 1) {
- pm = new ProxyManager(args[1]);
- } else {
- pm = new ProxyManager();
- }
-
- if (pm.set(args[0])) {
- System.out.println("Proxy set: ");
- } else {
- System.out.println("No proxy set.");
- }
- }
-
- /**
- * Check if one of the configured proxies is appropriate for this host and setup the system
- * configuration accordingly.
- *
- * @param host name of the host the connection should be initiated to
- *
- * @return DOCUMENT ME!
- */
- public boolean set(String host) {
- Properties sp = System.getProperties();
-
- for (int i = 0; i < proxies.size(); i++) {
- ProxyConf proxy = (ProxyConf) proxies.elementAt(i);
-
- if (proxy.check(host)) {
- sp.put("proxySet", "true");
- sp.put("proxyHost", proxy.getHostName());
- sp.put("proxyPort", proxy.getHostPort());
- System.setProperties(sp);
-
- return true;
- }
- }
-
- sp.remove("proxySet");
- sp.put("proxyHost", "");
- sp.put("proxyPort", "");
- System.setProperties(sp);
-
- return false;
- }
-
- /**
- * Read proxy configuration
- *
- * @param fname Filename of proxy configuration
- *
- * @return proxies
- */
- public Vector readConfig(String fname) {
- Document document = null;
- File configFile = null;
-
- try {
- configFile = new File(new java.net.URI(ProxyManager.class.getClassLoader().getResource(fname).toString()));
- if (configFile.exists()) {
- document = DocumentHelper.readDocument(configFile);
- } else {
- log.warn("No such file or directory: " + configFile.getAbsolutePath());
- return null;
- }
- } catch (Exception e) {
- log.error(e);
+ private static Logger log = Logger.getLogger(ProxyManager.class);
+ Vector proxies = null;
+ /**
+ * Creating an instance of ProxyManager without argurments reads the configuration from the default configuration file ($XPS_HOME/xml/xps/proxyconf.xml)
+ */
+ public ProxyManager() {
+ log.debug("" + new Configuration().configurationPath);
+ proxies = readConfig(new Configuration().configurationPath);
+ }
+ /**
+ * The <code>ProxyManager</code> is created using the customized <code>conffile</code>
+ *
+ * @param conffile
+ * configuration file to use
+ */
+ public ProxyManager(String conffile) {
+ proxies = readConfig(conffile);
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param args
+ * DOCUMENT ME!
+ */
+ public static void main(String[] args) {
+ if((args.length > 2) || (args.length < 1)){
+ System.err.println("Usage: java org.apache.lenya.net.ProxyManager host [configfile.xml]");
+ return;
+ }
+ ProxyManager pm = null;
+ if(args.length > 1){
+ pm = new ProxyManager(args[1]);
+ }else{
+ pm = new ProxyManager();
+ }
+ if(pm.set(args[0])){
+ System.out.println("Proxy set: ");
+ }else{
+ System.out.println("No proxy set.");
+ }
+ }
+ /**
+ * Check if one of the configured proxies is appropriate for this host and setup the system configuration accordingly.
+ *
+ * @param host
+ * name of the host the connection should be initiated to
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean set(String host) {
+ Properties sp = System.getProperties();
+ for(int i = 0; i < proxies.size(); i++){
+ ProxyConf proxy = (ProxyConf) proxies.elementAt(i);
+ if(proxy.check(host)){
+ sp.put("proxySet", "true");
+ sp.put("proxyHost", proxy.getHostName());
+ sp.put("proxyPort", proxy.getHostPort());
+ System.setProperties(sp);
+ return true;
+ }
+ }
+ sp.remove("proxySet");
+ sp.put("proxyHost", "");
+ sp.put("proxyPort", "");
+ System.setProperties(sp);
+ return false;
+ }
+ /**
+ * Read proxy configuration
+ *
+ * @param fname
+ * Filename of proxy configuration
+ *
+ * @return proxies
+ */
+ public Vector readConfig(String fname) {
+ Document document = null;
+ File configFile = null;
+ try{
+ configFile = new File(new java.net.URI(ProxyManager.class.getClassLoader().getResource(fname).toString()));
+ if(configFile.exists()){
+ document = DocumentHelper.readDocument(configFile);
+ }else{
+ log.warn("No such file or directory: " + configFile.getAbsolutePath());
return null;
- }
-
-
- Vector proxyElements = null;
- XPointerFactory xpf = new XPointerFactory();
-
- try {
- proxyElements = xpf.select(document.getDocumentElement(), "xpointer(/conf/Proxy)");
- if (proxyElements.size() == 0) log.info("No proxy defined (" + configFile + ")");
- } catch (Exception e) {
- log.error(e);
- return null;
- }
-
- Vector proxies = new Vector();
- for (int i = 0; i < proxyElements.size(); i++) {
- ProxyConf proxy = new ProxyConf((Element) proxyElements.elementAt(i));
-
- proxies.addElement(proxy);
- }
-
- return proxies;
- }
+ }
+ }catch(Exception e){
+ log.error(e);
+ return null;
+ }
+ Vector proxyElements = null;
+ XPointerFactory xpf = new XPointerFactory();
+ try{
+ proxyElements = xpf.select(document.getDocumentElement(), "xpointer(/conf/Proxy)");
+ if(proxyElements.size() == 0)
+ log.info("No proxy defined (" + configFile + ")");
+ }catch(Exception e){
+ log.error(e);
+ return null;
+ }
+ Vector proxies = new Vector();
+ for(int i = 0; i < proxyElements.size(); i++){
+ ProxyConf proxy = new ProxyConf((Element) proxyElements.elementAt(i));
+ proxies.addElement(proxy);
+ }
+ return proxies;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/SMTP.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/SMTP.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/SMTP.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/SMTP.java Wed Jan 30 23:44:03 2008
@@ -14,11 +14,8 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.net;
-
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
@@ -29,329 +26,279 @@
import java.net.ConnectException;
import java.net.Socket;
import java.util.StringTokenizer;
-
import org.apache.commons.codec.net.BCodec;
import org.apache.log4j.Category;
-
-
-
/**
* DOCUMENT ME!
+ *
* @deprecated use cocoon mail block
*/
public class SMTP {
- private static Category log = Category.getInstance(SMTP.class);
- String host = null;
- int port;
- String domain = null;
- Socket socket = null;
- PrintWriter out = null;
- DataInputStream in = null;
- String errlog = null;
- String from = null;
- String to = null;
- String reply_to = null;
- String cc = null;
- String[] ccs = null;
- String bcc = null;
- String[] bccs = null;
- String subject = null;
- String data = null;
- String charset ="ISO-8859-1";
-
- /**
- *
- */
- public SMTP() {
-
- Configuration conf = new Configuration();
- host = conf.smtpHost;
- port = new Integer(conf.smtpPort).intValue();
- domain = conf.smtpDomain;
- log.debug(host + ":" + port + " (" + domain + ")");
- }
-
-
- /**
- * DOCUMENT ME!
- *
- * @param from DOCUMENT ME!
- * @param to DOCUMENT ME!
- * @param cc DOCUMENT ME!
- * @param bcc DOCUMENT ME!
- * @param subject DOCUMENT ME!
- * @param body DOCUMENT ME!
- */
- public void send(String from, String to, String cc, String bcc, String subject, String body) {
- From(from);
- Reply_To(from);
- To(to);
- Cc(cc);
- Bcc(bcc);
- Subject(subject);
- DATA(body);
- send();
- }
-
- /**
- * DOCUMENT ME!
- */
- public void send() {
- errlog = "";
-
- try {
- socket = new Socket(host, port);
- out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), charset)), true);
- in = new DataInputStream(socket.getInputStream());
-
- errlog = errlog + getResponse(220);
-
- errlog = errlog + "HELO " + domain + "\n";
- out.println("HELO " + domain);
+ private static Category log = Category.getInstance(SMTP.class);
+ String host = null;
+ int port;
+ String domain = null;
+ Socket socket = null;
+ PrintWriter out = null;
+ DataInputStream in = null;
+ String errlog = null;
+ String from = null;
+ String to = null;
+ String reply_to = null;
+ String cc = null;
+ String[] ccs = null;
+ String bcc = null;
+ String[] bccs = null;
+ String subject = null;
+ String data = null;
+ String charset = "ISO-8859-1";
+ /**
+ *
+ */
+ public SMTP() {
+ Configuration conf = new Configuration();
+ host = conf.smtpHost;
+ port = new Integer(conf.smtpPort).intValue();
+ domain = conf.smtpDomain;
+ log.debug(host + ":" + port + " (" + domain + ")");
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param from
+ * DOCUMENT ME!
+ * @param to
+ * DOCUMENT ME!
+ * @param cc
+ * DOCUMENT ME!
+ * @param bcc
+ * DOCUMENT ME!
+ * @param subject
+ * DOCUMENT ME!
+ * @param body
+ * DOCUMENT ME!
+ */
+ public void send(String from, String to, String cc, String bcc, String subject, String body) {
+ From(from);
+ Reply_To(from);
+ To(to);
+ Cc(cc);
+ Bcc(bcc);
+ Subject(subject);
+ DATA(body);
+ send();
+ }
+ /**
+ * DOCUMENT ME!
+ */
+ public void send() {
+ errlog = "";
+ try{
+ socket = new Socket(host, port);
+ out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), charset)), true);
+ in = new DataInputStream(socket.getInputStream());
+ errlog = errlog + getResponse(220);
+ errlog = errlog + "HELO " + domain + "\n";
+ out.println("HELO " + domain);
+ errlog = errlog + getResponse(250);
+ errlog = errlog + "MAIL FROM:<" + from + ">\n";
+ out.println("MAIL FROM:<" + from + ">");
+ errlog = errlog + getResponse(250);
+ errlog = errlog + "RCPT TO:<" + to + ">\n";
+ out.println("RCPT TO:<" + to + ">");
+ errlog = errlog + getResponse(250);
+ for(int i = 0; i < ccs.length; i++){
+ errlog = errlog + "RCPT TO:<" + ccs[i] + ">\n";
+ out.println("RCPT TO:<" + ccs[i] + ">");
errlog = errlog + getResponse(250);
-
- errlog = errlog + "MAIL FROM:<" + from + ">\n";
- out.println("MAIL FROM:<" + from + ">");
+ }
+ for(int i = 0; i < bccs.length; i++){
+ errlog = errlog + "RCPT TO:<" + bccs[i] + ">\n";
+ out.println("RCPT TO:<" + bccs[i] + ">");
errlog = errlog + getResponse(250);
-
- errlog = errlog + "RCPT TO:<" + to + ">\n";
- out.println("RCPT TO:<" + to + ">");
- errlog = errlog + getResponse(250);
-
- for (int i = 0; i < ccs.length; i++) {
- errlog = errlog + "RCPT TO:<" + ccs[i] + ">\n";
- out.println("RCPT TO:<" + ccs[i] + ">");
- errlog = errlog + getResponse(250);
- }
-
- for (int i = 0; i < bccs.length; i++) {
- errlog = errlog + "RCPT TO:<" + bccs[i] + ">\n";
- out.println("RCPT TO:<" + bccs[i] + ">");
- errlog = errlog + getResponse(250);
- }
-
- errlog = errlog + "DATA\n";
- out.println("DATA");
- errlog = errlog + getResponse(354);
-
- errlog = errlog + "From: " + from + "\n";
- out.println("From: " + from);
- errlog = errlog + "To: " + to + "\n";
- out.println("To: " + to);
- errlog = errlog + "Reply-To: " + reply_to + "\n";
- out.println("Reply-To: " + reply_to);
-
- if (cc != null) {
- errlog = errlog + "Cc: " + cc + "\n";
- out.println("Cc: " + cc);
- }
-
- if (bcc != null) {
- errlog = errlog + "Bcc: " + bcc + "\n";
- out.println("Bcc: " + bcc);
- }
-
- BCodec encoder = new BCodec(charset);
- String base64Subject = encoder.encode(subject);
- errlog = errlog +"Subject: " + base64Subject + "\n";
- out.println("Subject: " + base64Subject);
-
- errlog = errlog + "MIME-Version: 1.0\n";
- out.println("MIME-Version: 1.0");
-
- errlog = errlog + "Content-Type: text/plain; charset=" + charset +"; format=flowed\n";
- out.println("Content-Type: text/plain; charset=" + charset +"; format=flowed");
-
- errlog = errlog + "Content-Transfer-Encoding: quoted-printable\n";
- out.println("Content-Transfer-Encoding: quoted-printable");
-
- errlog = errlog + data + "\n.\n";
- out.println(data + "\n.");
- errlog = errlog + getResponse(250);
-
- errlog = errlog + "QUIT\n";
- out.println("QUIT");
- errlog = errlog + getResponse(221);
- log.debug(errlog);
- } catch (ConnectException e) {
- log.error(".send(): " + e + " (sendmail is probably not running)");
-
- return;
- } catch (Exception e) {
- log.error(".send(): " + e);
- }
-
- try {
- in.close();
- out.close();
- socket.close();
- } catch (IOException e) {
- log.error(this.getClass().getName() + ".send(): " + e);
- }
- }
-
- private String getResponse(int value) throws IOException {
- try {
- Thread.sleep(200);
- } catch (InterruptedException e) {
- }
-
- return readLine(in);
- }
-
- private String readLine(DataInputStream in) throws IOException {
- StringBuffer line = new StringBuffer("");
-
- while (in.available() > 0) {
- char character = (char) in.read();
- line.append(character);
- }
-
- String response = new String(line);
-
- return response;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param data DOCUMENT ME!
- */
- public void DATA(String data) {
- this.data = data;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param from DOCUMENT ME!
- */
- public void From(String from) {
- this.from = from;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param to DOCUMENT ME!
- */
- public void To(String to) {
- this.to = to;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param reply_to DOCUMENT ME!
- */
- public void Reply_To(String reply_to) {
- this.reply_to = reply_to;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param cc DOCUMENT ME!
- */
- public void Cc(String cc) {
- if (cc == null) {
- ccs = new String[0];
-
- return;
- }
-
- this.cc = cc;
-
- StringTokenizer st = new StringTokenizer(cc, ",");
- ccs = new String[st.countTokens()];
-
- for (int i = 0; i < ccs.length; i++) {
- ccs[i] = st.nextToken();
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param bcc DOCUMENT ME!
- */
- public void Bcc(String bcc) {
- if (bcc == null) {
- bccs = new String[0];
-
- return;
- }
-
- this.bcc = bcc;
-
- StringTokenizer st = new StringTokenizer(bcc, ",");
- bccs = new String[st.countTokens()];
-
- for (int i = 0; i < bccs.length; i++) {
- bccs[i] = st.nextToken();
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param subject DOCUMENT ME!
- */
- public void Subject(String subject) {
- this.subject = subject;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param filename DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int numberOfLines(String filename) {
- String string = "";
- int nlines = 0;
-
- try {
- BufferedReader reader = new BufferedReader(new FileReader(filename));
-
- while (in.available() != 0) {
- string = reader.readLine();
- nlines++;
- }
-
- in.close();
- } catch (Exception e) {
- System.out.println(e);
- }
-
- return nlines;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param filename DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String[] loadLines(String filename) {
- String[] string = new String[numberOfLines(filename)];
- int nlines = 0;
-
- try {
- BufferedReader reader = new BufferedReader(new FileReader(filename));
-
- while (in.available() != 0) {
- string[nlines] = reader.readLine();
- nlines++;
- }
-
- in.close();
- } catch (Exception e) {
- System.out.println(e);
- }
-
- return string;
- }
+ }
+ errlog = errlog + "DATA\n";
+ out.println("DATA");
+ errlog = errlog + getResponse(354);
+ errlog = errlog + "From: " + from + "\n";
+ out.println("From: " + from);
+ errlog = errlog + "To: " + to + "\n";
+ out.println("To: " + to);
+ errlog = errlog + "Reply-To: " + reply_to + "\n";
+ out.println("Reply-To: " + reply_to);
+ if(cc != null){
+ errlog = errlog + "Cc: " + cc + "\n";
+ out.println("Cc: " + cc);
+ }
+ if(bcc != null){
+ errlog = errlog + "Bcc: " + bcc + "\n";
+ out.println("Bcc: " + bcc);
+ }
+ BCodec encoder = new BCodec(charset);
+ String base64Subject = encoder.encode(subject);
+ errlog = errlog + "Subject: " + base64Subject + "\n";
+ out.println("Subject: " + base64Subject);
+ errlog = errlog + "MIME-Version: 1.0\n";
+ out.println("MIME-Version: 1.0");
+ errlog = errlog + "Content-Type: text/plain; charset=" + charset + "; format=flowed\n";
+ out.println("Content-Type: text/plain; charset=" + charset + "; format=flowed");
+ errlog = errlog + "Content-Transfer-Encoding: quoted-printable\n";
+ out.println("Content-Transfer-Encoding: quoted-printable");
+ errlog = errlog + data + "\n.\n";
+ out.println(data + "\n.");
+ errlog = errlog + getResponse(250);
+ errlog = errlog + "QUIT\n";
+ out.println("QUIT");
+ errlog = errlog + getResponse(221);
+ log.debug(errlog);
+ }catch(ConnectException e){
+ log.error(".send(): " + e + " (sendmail is probably not running)");
+ return;
+ }catch(Exception e){
+ log.error(".send(): " + e);
+ }
+ try{
+ in.close();
+ out.close();
+ socket.close();
+ }catch(IOException e){
+ log.error(this.getClass().getName() + ".send(): " + e);
+ }
+ }
+ private String getResponse(int value) throws IOException {
+ try{
+ Thread.sleep(200);
+ }catch(InterruptedException e){
+ }
+ return readLine(in);
+ }
+ private String readLine(DataInputStream in) throws IOException {
+ StringBuffer line = new StringBuffer("");
+ while(in.available() > 0){
+ char character = (char) in.read();
+ line.append(character);
+ }
+ String response = new String(line);
+ return response;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param data
+ * DOCUMENT ME!
+ */
+ public void DATA(String data) {
+ this.data = data;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param from
+ * DOCUMENT ME!
+ */
+ public void From(String from) {
+ this.from = from;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param to
+ * DOCUMENT ME!
+ */
+ public void To(String to) {
+ this.to = to;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param reply_to
+ * DOCUMENT ME!
+ */
+ public void Reply_To(String reply_to) {
+ this.reply_to = reply_to;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param cc
+ * DOCUMENT ME!
+ */
+ public void Cc(String cc) {
+ if(cc == null){
+ ccs = new String[0];
+ return;
+ }
+ this.cc = cc;
+ StringTokenizer st = new StringTokenizer(cc, ",");
+ ccs = new String[st.countTokens()];
+ for(int i = 0; i < ccs.length; i++){
+ ccs[i] = st.nextToken();
+ }
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param bcc
+ * DOCUMENT ME!
+ */
+ public void Bcc(String bcc) {
+ if(bcc == null){
+ bccs = new String[0];
+ return;
+ }
+ this.bcc = bcc;
+ StringTokenizer st = new StringTokenizer(bcc, ",");
+ bccs = new String[st.countTokens()];
+ for(int i = 0; i < bccs.length; i++){
+ bccs[i] = st.nextToken();
+ }
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param subject
+ * DOCUMENT ME!
+ */
+ public void Subject(String subject) {
+ this.subject = subject;
+ }
+ public int numberOfLines(String filename) {
+ // String string = "";
+ int nlines = 0;
+ try{
+ BufferedReader reader = new BufferedReader(new FileReader(filename));
+ while(in.available() != 0){
+ // string =
+ reader.readLine();
+ nlines++;
+ }
+ in.close();
+ }catch(Exception e){
+ System.out.println(e);
+ }
+ return nlines;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param filename
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String[] loadLines(String filename) {
+ String[] string = new String[numberOfLines(filename)];
+ int nlines = 0;
+ try{
+ BufferedReader reader = new BufferedReader(new FileReader(filename));
+ while(in.available() != 0){
+ string[nlines] = reader.readLine();
+ nlines++;
+ }
+ in.close();
+ }catch(Exception e){
+ System.out.println(e);
+ }
+ return string;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/WGet.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/WGet.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/WGet.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/WGet.java Wed Jan 30 23:44:03 2008
@@ -14,11 +14,8 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.net;
-
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
@@ -30,286 +27,239 @@
import java.net.URL;
import java.util.Iterator;
import java.util.List;
-
-import org.apache.log4j.Category;
-
-
+import org.apache.log4j.Logger;
/**
* Similar to the UNIX wget
*/
public class WGet {
- static Category log = Category.getInstance(WGet.class);
- String directory_prefix = null;
-
- /**
- * Creates a new WGet object.
- */
- public WGet() {
- directory_prefix = System.getProperty("user.dir");
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param args DOCUMENT ME!
- */
- public static void main(String[] args) {
- if (args.length == 0) {
- System.out.println("Usage: org.apache.lenya.net.WGet [URL] -P/home/lenya/download");
-
- return;
- }
-
- try {
- WGet wget = new WGet();
-
- for (int i = 0; i < args.length; i++) {
- if (args[i].indexOf("-P") == 0) {
- wget.setDirectoryPrefix(args[i].substring(2)); // -P/home/lenya/download, 2: remove "-P"
- }
+ private static Logger log = Logger.getLogger(WGet.class);
+ String directory_prefix = null;
+ /**
+ * Creates a new WGet object.
+ */
+ public WGet() {
+ directory_prefix = System.getProperty("user.dir");
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param args
+ * DOCUMENT ME!
+ */
+ public static void main(String[] args) {
+ if(args.length == 0){
+ System.out.println("Usage: org.apache.lenya.net.WGet [URL] -P/home/lenya/download");
+ return;
+ }
+ try{
+ WGet wget = new WGet();
+ for(int i = 0; i < args.length; i++){
+ if(args[i].indexOf("-P") == 0){
+ wget.setDirectoryPrefix(args[i].substring(2)); // -P/home/lenya/download, 2: remove "-P"
}
-
- byte[] response = wget.download(new URL(args[0]), "s/\\/lenya\\/oscom//g", "");
- } catch (MalformedURLException e) {
- System.err.println(e);
- } catch (Exception e) {
- System.err.println(e);
- }
- }
-
- /**
- * -P
- *
- * @param directory_prefix DOCUMENT ME!
- */
- public void setDirectoryPrefix(String directory_prefix) {
- this.directory_prefix = directory_prefix;
- }
-
- /**
- * @param url The url of the resource to download
- * @param prefixSubstitute Regexp which shall be replaced
- * @param substituteReplacement Replacement of the regexp
- *
- * @return bytes of downloaded resource
- *
- * @throws IOException URL might not exist
- */
- public byte[] download(URL url, String prefixSubstitute, String substituteReplacement)
- throws IOException {
- log.debug(".download(): " + url + " " + prefixSubstitute + " " + substituteReplacement);
-
- return downloadUsingHttpClient(url, prefixSubstitute, substituteReplacement);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param url DOCUMENT ME!
- * @param prefixSubstitute DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public byte[] downloadUsingHttpClient(URL url, String prefixSubstitute,
- String substituteReplacement) {
- log.debug(".downloadUsingHttpClient(): " + url);
-
- byte[] sresponse = null;
-
- try {
- sresponse = getResource(url);
-
- File file = new File(createFileName(url, prefixSubstitute, substituteReplacement));
-
- saveToFile(file.getAbsolutePath(), sresponse);
-
- substitutePrefix(file.getAbsolutePath(), prefixSubstitute, substituteReplacement);
- } catch (MalformedURLException e) {
- log.error(".downloadUsingHttpClient(): ", e);
- } catch (FileNotFoundException e) {
- log.error(".downloadUsingHttpClient(): ", e);
- } catch (IOException e) {
- log.error(".downloadUsingHttpClient(): ", e);
- }
-
- List links = null;
-
- try {
- links = getLinks(url);
- } catch (IOException ioe) {
- log.error(".downloadUsingHttpClient(): ", ioe);
- }
-
- if (links != null) {
- Iterator iterator = links.iterator();
-
- while (iterator.hasNext()) {
- String link = (String) iterator.next();
-
- try {
- URL child_url = new URL(org.apache.lenya.util.URLUtil.complete(url.toString(),
- link));
-
- byte[] child_sresponse = getResource(child_url);
- saveToFile(createFileName(child_url, prefixSubstitute, substituteReplacement),
- child_sresponse);
- } catch (Exception e) {
- log.error(".downloadUsingHttpClient(): ", e);
- }
+ }
+ // byte[] response =
+ wget.download(new URL(args[0]), "s/\\/lenya\\/oscom//g", "");
+ }catch(MalformedURLException e){
+ System.err.println(e);
+ }catch(Exception e){
+ System.err.println(e);
+ }
+ }
+ /**
+ * -P
+ *
+ * @param directory_prefix
+ * DOCUMENT ME!
+ */
+ public void setDirectoryPrefix(String directory_prefix) {
+ this.directory_prefix = directory_prefix;
+ }
+ /**
+ * @param url
+ * The url of the resource to download
+ * @param prefixSubstitute
+ * Regexp which shall be replaced
+ * @param substituteReplacement
+ * Replacement of the regexp
+ *
+ * @return bytes of downloaded resource
+ *
+ * @throws IOException
+ * URL might not exist
+ */
+ public byte[] download(URL url, String prefixSubstitute, String substituteReplacement) throws IOException {
+ log.debug(".download(): " + url + " " + prefixSubstitute + " " + substituteReplacement);
+ return downloadUsingHttpClient(url, prefixSubstitute, substituteReplacement);
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param url
+ * DOCUMENT ME!
+ * @param prefixSubstitute
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public byte[] downloadUsingHttpClient(URL url, String prefixSubstitute, String substituteReplacement) {
+ log.debug(".downloadUsingHttpClient(): " + url);
+ byte[] sresponse = null;
+ try{
+ sresponse = getResource(url);
+ File file = new File(createFileName(url, prefixSubstitute, substituteReplacement));
+ saveToFile(file.getAbsolutePath(), sresponse);
+ substitutePrefix(file.getAbsolutePath(), prefixSubstitute, substituteReplacement);
+ }catch(MalformedURLException e){
+ log.error(".downloadUsingHttpClient(): ", e);
+ }catch(FileNotFoundException e){
+ log.error(".downloadUsingHttpClient(): ", e);
+ }catch(IOException e){
+ log.error(".downloadUsingHttpClient(): ", e);
+ }
+ List links = null;
+ try{
+ links = getLinks(url);
+ }catch(IOException ioe){
+ log.error(".downloadUsingHttpClient(): ", ioe);
+ }
+ if(links != null){
+ Iterator iterator = links.iterator();
+ while(iterator.hasNext()){
+ String link = (String) iterator.next();
+ try{
+ URL child_url = new URL(org.apache.lenya.util.URLUtil.complete(url.toString(), link));
+ byte[] child_sresponse = getResource(child_url);
+ saveToFile(createFileName(child_url, prefixSubstitute, substituteReplacement), child_sresponse);
+ }catch(Exception e){
+ log.error(".downloadUsingHttpClient(): ", e);
}
- }
-
- return sresponse;
- }
-
- /**
- *
- */
- public byte[] getResource(URL url) throws IOException {
- log.debug(".getResource(): " + url);
-
- HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
- InputStream in = httpConnection.getInputStream();
- byte[] buffer = new byte[1024];
- int bytes_read;
- ByteArrayOutputStream bufferOut = new ByteArrayOutputStream();
-
- while ((bytes_read = in.read(buffer)) != -1) {
- bufferOut.write(buffer, 0, bytes_read);
- }
-
- byte[] sresponse = bufferOut.toByteArray();
- httpConnection.disconnect();
-
- return sresponse;
- }
-
- /**
- *
- */
- public List getLinks(URL url) throws IOException {
- log.debug(".getLinks(): Get links from " + url);
-
- List links = null;
-
- try {
- org.apache.lenya.util.HTML html = new org.apache.lenya.util.HTML(url.toString());
- links = html.getImageSrcs(false);
- links.addAll(html.getLinkHRefs(false));
- } catch (Exception e) {
- log.error(".getLinks() Exception 423432: ", e);
- }
-
- if (links != null) {
- log.debug(".getLinks(): Number of links found: " + links.size());
- }
-
- return links;
- }
-
- /**
- * Substitute prefix, e.g. "/lenya/blog/live/" by "/"
- *
- * @param filename Filename
- * @param prefixSubstitute Prefix which shall be replaced
- * @param substituteReplacement Prefix which is going to replace the original
- *
- * @throws IOException DOCUMENT ME!
- */
- public void substitutePrefix(String filename, String prefixSubstitute, String substituteReplacement) throws IOException {
- log.debug("Replace " + prefixSubstitute + " by " + substituteReplacement);
-
- org.apache.lenya.util.SED.replaceAll(new File(filename), escapeSlashes(prefixSubstitute), escapeSlashes(substituteReplacement));
- }
-
- /**
- * Escape slashes
- *
- * @return String with escaped slashes
- */
- public String escapeSlashes(String string) {
- StringBuffer buffer = new StringBuffer("");
-
- for (int i = 0; i < string.length(); i++) {
- if (string.charAt(i) == '/') {
- buffer.append("\\/");
- } else {
- buffer.append(string.charAt(i));
- }
- }
-
- return buffer.toString();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String toString() {
- return "-P: " + directory_prefix;
- }
-
- /**
- *
- */
- public void saveToFile(String filename, byte[] bytes)
- throws FileNotFoundException, IOException {
- File file = new File(filename);
- File parent = new File(file.getParent());
-
- if (!parent.exists()) {
- log.warn(".saveToFile(): Directory will be created: " + parent.getAbsolutePath());
- parent.mkdirs();
- }
-
- FileOutputStream out = new FileOutputStream(file.getAbsolutePath());
- out.write(bytes);
- out.close();
- }
-
- /**
- * @param url URL of resource, which has been downloaded and shall be saved
- * @return Absolute substituted filename
- */
- public String createFileName(URL url, String prefixSubstitute, String substituteReplacement) {
- File file = new File(directory_prefix + File.separator + url.getFile());
-
- return file.getAbsolutePath().replaceAll(prefixSubstitute, substituteReplacement);
- }
-
- /**
- *
- */
- public byte[] runProcess(String command) throws Exception {
- Process process = Runtime.getRuntime().exec(command);
-
- java.io.InputStream in = process.getInputStream();
- byte[] buffer = new byte[1024];
- int bytes_read = 0;
- java.io.ByteArrayOutputStream baout = new java.io.ByteArrayOutputStream();
-
- while ((bytes_read = in.read(buffer)) != -1) {
- baout.write(buffer, 0, bytes_read);
- }
-
- if (baout.toString().length() > 0) {
- log.debug(".runProcess(): %%%InputStream:START" + baout.toString() +
- "END:InputStream%%%");
- }
-
- java.io.InputStream in_e = process.getErrorStream();
- java.io.ByteArrayOutputStream baout_e = new java.io.ByteArrayOutputStream();
-
- while ((bytes_read = in_e.read(buffer)) != -1) {
- baout_e.write(buffer, 0, bytes_read);
- }
-
- if (baout_e.toString().length() > 0) {
- log.error(".runProcess(): ###ErrorStream:START" + baout_e.toString() +
- "END:ErrorStream###");
- }
-
- return baout.toByteArray();
- }
+ }
+ }
+ return sresponse;
+ }
+ /**
+ *
+ */
+ public byte[] getResource(URL url) throws IOException {
+ log.debug(".getResource(): " + url);
+ HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
+ InputStream in = httpConnection.getInputStream();
+ byte[] buffer = new byte[1024];
+ int bytes_read;
+ ByteArrayOutputStream bufferOut = new ByteArrayOutputStream();
+ while((bytes_read = in.read(buffer)) != -1){
+ bufferOut.write(buffer, 0, bytes_read);
+ }
+ byte[] sresponse = bufferOut.toByteArray();
+ httpConnection.disconnect();
+ return sresponse;
+ }
+ /**
+ *
+ */
+ public List getLinks(URL url) throws IOException {
+ log.debug(".getLinks(): Get links from " + url);
+ List links = null;
+ try{
+ org.apache.lenya.util.HTML html = new org.apache.lenya.util.HTML(url.toString());
+ links = html.getImageSrcs(false);
+ links.addAll(html.getLinkHRefs(false));
+ }catch(Exception e){
+ log.error(".getLinks() Exception 423432: ", e);
+ }
+ if(links != null){
+ log.debug(".getLinks(): Number of links found: " + links.size());
+ }
+ return links;
+ }
+ /**
+ * Substitute prefix, e.g. "/lenya/blog/live/" by "/"
+ *
+ * @param filename
+ * Filename
+ * @param prefixSubstitute
+ * Prefix which shall be replaced
+ * @param substituteReplacement
+ * Prefix which is going to replace the original
+ *
+ * @throws IOException
+ * DOCUMENT ME!
+ */
+ public void substitutePrefix(String filename, String prefixSubstitute, String substituteReplacement) throws IOException {
+ log.debug("Replace " + prefixSubstitute + " by " + substituteReplacement);
+ org.apache.lenya.util.SED.replaceAll(new File(filename), escapeSlashes(prefixSubstitute), escapeSlashes(substituteReplacement));
+ }
+ /**
+ * Escape slashes
+ *
+ * @return String with escaped slashes
+ */
+ public String escapeSlashes(String string) {
+ StringBuffer buffer = new StringBuffer("");
+ for(int i = 0; i < string.length(); i++){
+ if(string.charAt(i) == '/'){
+ buffer.append("\\/");
+ }else{
+ buffer.append(string.charAt(i));
+ }
+ }
+ return buffer.toString();
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String toString() {
+ return "-P: " + directory_prefix;
+ }
+ /**
+ *
+ */
+ public void saveToFile(String filename, byte[] bytes) throws FileNotFoundException, IOException {
+ File file = new File(filename);
+ File parent = new File(file.getParent());
+ if(!parent.exists()){
+ log.warn(".saveToFile(): Directory will be created: " + parent.getAbsolutePath());
+ parent.mkdirs();
+ }
+ FileOutputStream out = new FileOutputStream(file.getAbsolutePath());
+ out.write(bytes);
+ out.close();
+ }
+ /**
+ * @param url
+ * URL of resource, which has been downloaded and shall be saved
+ * @return Absolute substituted filename
+ */
+ public String createFileName(URL url, String prefixSubstitute, String substituteReplacement) {
+ File file = new File(directory_prefix + File.separator + url.getFile());
+ return file.getAbsolutePath().replaceAll(prefixSubstitute, substituteReplacement);
+ }
+ /**
+ *
+ */
+ public byte[] runProcess(String command) throws Exception {
+ Process process = Runtime.getRuntime().exec(command);
+ java.io.InputStream in = process.getInputStream();
+ byte[] buffer = new byte[1024];
+ int bytes_read = 0;
+ java.io.ByteArrayOutputStream baout = new java.io.ByteArrayOutputStream();
+ while((bytes_read = in.read(buffer)) != -1){
+ baout.write(buffer, 0, bytes_read);
+ }
+ if(baout.toString().length() > 0){
+ log.debug(".runProcess(): %%%InputStream:START" + baout.toString() + "END:InputStream%%%");
+ }
+ java.io.InputStream in_e = process.getErrorStream();
+ java.io.ByteArrayOutputStream baout_e = new java.io.ByteArrayOutputStream();
+ while((bytes_read = in_e.read(buffer)) != -1){
+ baout_e.write(buffer, 0, bytes_read);
+ }
+ if(baout_e.toString().length() > 0){
+ log.error(".runProcess(): ###ErrorStream:START" + baout_e.toString() + "END:ErrorStream###");
+ }
+ return baout.toByteArray();
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/search/crawler/CrawlerConfiguration.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/search/crawler/CrawlerConfiguration.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/search/crawler/CrawlerConfiguration.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/search/crawler/CrawlerConfiguration.java Wed Jan 30 23:44:03 2008
@@ -14,270 +14,225 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.search.crawler;
-
import java.io.File;
-import java.io.IOException;
-
import org.apache.lenya.xml.DOMUtil;
import org.apache.lenya.xml.DocumentHelper;
import org.apache.lenya.xml.XPath;
-import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-
-
/**
* Web-Crawler (it might make sense to replace this by Nutch)
*/
public class CrawlerConfiguration {
- static Category log = Category.getInstance(CrawlerConfiguration.class);
- private String configurationFilePath;
- private String base_url;
- private String user_agent;
- private String scope_url;
- private String uri_list;
- private String htdocs_dump_dir;
- private String robots_file;
- private String robots_domain;
-
- /**
- * Creates a new CrawlerConfiguration object.
- *
- * @param configurationFilePath DOCUMENT ME!
- */
- public CrawlerConfiguration(String configurationFilePath) {
- this.configurationFilePath = configurationFilePath;
-
- File configurationFile = new File(configurationFilePath);
-
- try {
- Document document = DocumentHelper.readDocument(configurationFile);
- configure(document.getDocumentElement());
- } catch (Exception e) {
- log.error("Cannot load publishing configuration! ", e);
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param args DOCUMENT ME!
- */
- public static void main(String[] args) {
- if (args.length == 0) {
- System.err.println(
- "Usage: org.apache.lenya.search.crawler.CrawlerConfiguration crawler.xconf [-name <name>]");
-
- return;
- }
-
- CrawlerConfiguration ce = new CrawlerConfiguration(args[0]);
- String parameter;
-
- String name = null;
-
- for (int i = 0; i < args.length; i++) {
- if (args[i].equals("-name")) {
- if ((i + 1) < args.length) {
- name = args[i + 1];
- }
+ private static Logger log = Logger.getLogger(CrawlerConfiguration.class);
+ private String configurationFilePath;
+ private String base_url;
+ private String user_agent;
+ private String scope_url;
+ private String uri_list;
+ private String htdocs_dump_dir;
+ private String robots_file;
+ private String robots_domain;
+ /**
+ * Creates a new CrawlerConfiguration object.
+ *
+ * @param configurationFilePath
+ * DOCUMENT ME!
+ */
+ public CrawlerConfiguration(String configurationFilePath) {
+ this.configurationFilePath = configurationFilePath;
+ File configurationFile = new File(configurationFilePath);
+ try{
+ Document document = DocumentHelper.readDocument(configurationFile);
+ configure(document.getDocumentElement());
+ }catch(Exception e){
+ log.error("Cannot load publishing configuration! ", e);
+ }
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param args
+ * DOCUMENT ME!
+ */
+ public static void main(String[] args) {
+ if(args.length == 0){
+ System.err.println("Usage: org.apache.lenya.search.crawler.CrawlerConfiguration crawler.xconf [-name <name>]");
+ return;
+ }
+ CrawlerConfiguration ce = new CrawlerConfiguration(args[0]);
+ String parameter;
+ String name = null;
+ for(int i = 0; i < args.length; i++){
+ if(args[i].equals("-name")){
+ if((i + 1) < args.length){
+ name = args[i + 1];
}
- }
-
- if (name != null) {
- if (name.equals("htdocs-dump-dir")) {
- parameter = ce.getHTDocsDumpDir();
- System.out.println(ce.resolvePath(parameter));
- } else {
- System.out.println("No such element: " + name);
- }
- } else {
- parameter = ce.getBaseURL();
- System.out.println("Crawler Config: Base URL: " + parameter);
-
- parameter = ce.getScopeURL();
- System.out.println("Crawler Config: Scope URL: " + parameter);
-
- parameter = ce.getUserAgent();
- System.out.println("Crawler Config: User Agent: " + parameter);
-
- parameter = ce.getURIList();
- System.out.println("Crawler Config: URI List: " + ce.resolvePath(parameter) + " (" + parameter + ")");
-
+ }
+ }
+ if(name != null){
+ if(name.equals("htdocs-dump-dir")){
parameter = ce.getHTDocsDumpDir();
- System.out.println("Crawler Config: HTDocs Dump Dir: " + ce.resolvePath(parameter) + " (" + parameter + ")");
-
- parameter = ce.getRobotsFile();
- if (parameter != null) {
- System.out.println("Crawler Config: Robots File: " + ce.resolvePath(parameter + " (" + parameter + ")"));
- }
-
- parameter = ce.getRobotsDomain();
- if (parameter != null) {
- System.out.println("Crawler Config: Robots Domain: " + parameter);
- }
- }
- }
-
- /**
- * Extract parameters from configuration
- *
- * @param configuration DOCUMENT ME!
- *
- * @throws Exception DOCUMENT ME!
- */
- public void configure(Element root) throws Exception {
- DOMUtil du = new DOMUtil();
-
- base_url = du.getAttributeValue(root, new XPath("base-url/@href"));
- scope_url = du.getAttributeValue(root, new XPath("scope-url/@href"));
- user_agent = du.getElementValue(root, new XPath("user-agent"));
- uri_list = du.getAttributeValue(root, new XPath("uri-list/@src"));
- htdocs_dump_dir = du.getAttributeValue(root, new XPath("htdocs-dump-dir/@src"));
- if (du.elementExists(root, new XPath("robots"))) {
- robots_file = du.getAttributeValue(root, new XPath("robots/@src"));
- robots_domain = du.getAttributeValue(root, new XPath("robots/@domain"));
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getBaseURL() {
- log.debug(".getBaseURL(): " + base_url);
-
- return base_url;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getScopeURL() {
- log.debug(".getScopeURL(): " + scope_url);
-
- return scope_url;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getUserAgent() {
- log.debug(".getUserAgent(): " + user_agent);
-
- return user_agent;
- }
-
- /**
- * Get URI list path
- *
- * @return URI list path
- */
- public String getURIList() {
- log.debug(".getURIList(): " + uri_list);
-
- return uri_list;
- }
-
- /**
- * Get URI list path as absolute path
- *
- * @return URI list path
- */
- public String getURIListResolved() {
- log.debug(".getURIList(): " + uri_list);
-
- return resolvePath(uri_list);
- }
-
- /**
- * Get htdocs-dump-dir/@src
- *
- * @return htdocs-dump-dir/@src
- */
- public String getHTDocsDumpDir() {
- log.debug(".getHTDocsDumpDir(): " + htdocs_dump_dir);
-
- return htdocs_dump_dir;
- }
-
- /**
- * Get htdocs-dump-dir/@src as absolute path
- *
- * @return htdocs-dump-dir/@src
- */
- public String getHTDocsDumpDirResolved() {
-
- return resolvePath(htdocs_dump_dir);
- }
-
- /**
- * Get robots/@src
- *
- * @return robots/@src
- */
- public String getRobotsFile() {
- log.debug(robots_file);
-
- return robots_file;
- }
-
- /**
- * Get robots/@src as absolute path
- *
- * @return robots/@src
- */
- public String getRobotsFileResolved() {
- log.debug(robots_file);
-
- return resolvePath(robots_file);
- }
-
- /**
- * Get robots/@domain
- *
- * @return robots/@domain
- */
- public String getRobotsDomain() {
- log.debug(robots_domain);
-
- return robots_domain;
- }
-
- /**
- * Resolve path
- *
- * @param path Original path
- *
- * @return Resolved path
- */
- public String resolvePath(String path) {
-
- // nothing to do if we already have an absolute pathname
- if ( new File(path) .isAbsolute() ) {
- return path;
- }
-
- // from the Java API doc: "A canonical pathname is both absolute and unique."
- // however we may get an exception while converting a path to it's canonical form
- try {
- String configDir = new File(configurationFilePath) .getAbsoluteFile() .getParent();
- return new File(configDir, path) .getCanonicalPath();
-
- } catch (java.io.IOException e) {
- // FIXME: maybe this Exception should be thrown to the caller ?
- e.printStackTrace();
- return null;
- }
-
- }
+ System.out.println(ce.resolvePath(parameter));
+ }else{
+ System.out.println("No such element: " + name);
+ }
+ }else{
+ parameter = ce.getBaseURL();
+ System.out.println("Crawler Config: Base URL: " + parameter);
+ parameter = ce.getScopeURL();
+ System.out.println("Crawler Config: Scope URL: " + parameter);
+ parameter = ce.getUserAgent();
+ System.out.println("Crawler Config: User Agent: " + parameter);
+ parameter = ce.getURIList();
+ System.out.println("Crawler Config: URI List: " + ce.resolvePath(parameter) + " (" + parameter + ")");
+ parameter = ce.getHTDocsDumpDir();
+ System.out.println("Crawler Config: HTDocs Dump Dir: " + ce.resolvePath(parameter) + " (" + parameter + ")");
+ parameter = ce.getRobotsFile();
+ if(parameter != null){
+ System.out.println("Crawler Config: Robots File: " + ce.resolvePath(parameter + " (" + parameter + ")"));
+ }
+ parameter = ce.getRobotsDomain();
+ if(parameter != null){
+ System.out.println("Crawler Config: Robots Domain: " + parameter);
+ }
+ }
+ }
+ /**
+ * Extract parameters from configuration
+ *
+ * @param configuration
+ * DOCUMENT ME!
+ *
+ * @throws Exception
+ * DOCUMENT ME!
+ */
+ public void configure(Element root) throws Exception {
+ DOMUtil du = new DOMUtil();
+ base_url = du.getAttributeValue(root, new XPath("base-url/@href"));
+ scope_url = du.getAttributeValue(root, new XPath("scope-url/@href"));
+ user_agent = du.getElementValue(root, new XPath("user-agent"));
+ uri_list = du.getAttributeValue(root, new XPath("uri-list/@src"));
+ htdocs_dump_dir = du.getAttributeValue(root, new XPath("htdocs-dump-dir/@src"));
+ if(du.elementExists(root, new XPath("robots"))){
+ robots_file = du.getAttributeValue(root, new XPath("robots/@src"));
+ robots_domain = du.getAttributeValue(root, new XPath("robots/@domain"));
+ }
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getBaseURL() {
+ log.debug(".getBaseURL(): " + base_url);
+ return base_url;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getScopeURL() {
+ log.debug(".getScopeURL(): " + scope_url);
+ return scope_url;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getUserAgent() {
+ log.debug(".getUserAgent(): " + user_agent);
+ return user_agent;
+ }
+ /**
+ * Get URI list path
+ *
+ * @return URI list path
+ */
+ public String getURIList() {
+ log.debug(".getURIList(): " + uri_list);
+ return uri_list;
+ }
+ /**
+ * Get URI list path as absolute path
+ *
+ * @return URI list path
+ */
+ public String getURIListResolved() {
+ log.debug(".getURIList(): " + uri_list);
+ return resolvePath(uri_list);
+ }
+ /**
+ * Get htdocs-dump-dir/@src
+ *
+ * @return htdocs-dump-dir/@src
+ */
+ public String getHTDocsDumpDir() {
+ log.debug(".getHTDocsDumpDir(): " + htdocs_dump_dir);
+ return htdocs_dump_dir;
+ }
+ /**
+ * Get htdocs-dump-dir/@src as absolute path
+ *
+ * @return htdocs-dump-dir/@src
+ */
+ public String getHTDocsDumpDirResolved() {
+ return resolvePath(htdocs_dump_dir);
+ }
+ /**
+ * Get robots/@src
+ *
+ * @return robots/@src
+ */
+ public String getRobotsFile() {
+ log.debug(robots_file);
+ return robots_file;
+ }
+ /**
+ * Get robots/@src as absolute path
+ *
+ * @return robots/@src
+ */
+ public String getRobotsFileResolved() {
+ log.debug(robots_file);
+ return resolvePath(robots_file);
+ }
+ /**
+ * Get robots/@domain
+ *
+ * @return robots/@domain
+ */
+ public String getRobotsDomain() {
+ log.debug(robots_domain);
+ return robots_domain;
+ }
+ /**
+ * Resolve path
+ *
+ * @param path
+ * Original path
+ *
+ * @return Resolved path
+ */
+ public String resolvePath(String path) {
+ // nothing to do if we already have an absolute pathname
+ if(new File(path).isAbsolute()){
+ return path;
+ }
+ // from the Java API doc: "A canonical pathname is both absolute and unique."
+ // however we may get an exception while converting a path to it's canonical form
+ try{
+ String configDir = new File(configurationFilePath).getAbsoluteFile().getParent();
+ return new File(configDir, path).getCanonicalPath();
+ }catch(java.io.IOException e){
+ // FIXME: maybe this Exception should be thrown to the caller ?
+ e.printStackTrace();
+ return null;
+ }
+ }
}