You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by th...@apache.org on 2008/06/06 14:58:47 UTC
svn commit: r663920 - in
/labs/droids/trunk/src/core/java/org/apache/droids/parse: Outlink.java
ParseData.java ParseImpl.java html/HtmlParser.java html/package-info.java
package-info.java
Author: thorsten
Date: Fri Jun 6 05:58:47 2008
New Revision: 663920
URL: http://svn.apache.org/viewvc?rev=663920&view=rev
Log:
Adding more java documentation and fixing code regarding the output from an Enerjy Code Analysis. Further adding missing license headers.
Added:
labs/droids/trunk/src/core/java/org/apache/droids/parse/html/package-info.java (with props)
labs/droids/trunk/src/core/java/org/apache/droids/parse/package-info.java (with props)
Modified:
labs/droids/trunk/src/core/java/org/apache/droids/parse/Outlink.java
labs/droids/trunk/src/core/java/org/apache/droids/parse/ParseData.java
labs/droids/trunk/src/core/java/org/apache/droids/parse/ParseImpl.java
labs/droids/trunk/src/core/java/org/apache/droids/parse/html/HtmlParser.java
Modified: labs/droids/trunk/src/core/java/org/apache/droids/parse/Outlink.java
URL: http://svn.apache.org/viewvc/labs/droids/trunk/src/core/java/org/apache/droids/parse/Outlink.java?rev=663920&r1=663919&r2=663920&view=diff
==============================================================================
--- labs/droids/trunk/src/core/java/org/apache/droids/parse/Outlink.java (original)
+++ labs/droids/trunk/src/core/java/org/apache/droids/parse/Outlink.java Fri Jun 6 05:58:47 2008
@@ -21,32 +21,69 @@
import org.apache.droids.api.Task;
+/**
+ * An outlink that implements the task interface.
+ * @author thorsten
+ * @version 1.0
+ *
+ */
public class Outlink implements Task {
- private String toUrl;
- private String anchor;
- private int depth;
+ private String toUrl=null;
+ private String anchor=null;
+ private int depth=0;
private String taskDate=new SimpleDateFormat("yyyyMMddHHmmss").format(new Date(System
.currentTimeMillis()));
+ /**
+ *Create a new instance for the given parameters.
+ * @param toUrl the destination url
+ * @param anchor the anchor
+ * @param depth2 the depth of the link
+ */
public Outlink(String toUrl, String anchor, int depth2){
this.toUrl=toUrl;
this.anchor = anchor;
this.depth= depth2;
}
+ /**
+ *Create a new instance for the given parameters.
+ * @param toUrl the destination url
+ * @param depth2 the depth of the link
+ */
public Outlink(String toUrl, int depth2) {
this.toUrl=toUrl;
this.depth= depth2;
}
+ /**
+ * Get the destination url.
+ * @return the destination url.
+ */
public String getToUrl() { return toUrl; }
+ /**
+ * Get the anchor url.
+ * @return the anchor url.
+ */
public String getAnchor() { return anchor; }
+ /* (non-Javadoc)
+ * @see org.apache.droids.api.Task#getId()
+ */
public String getId() {
return toUrl;
}
+ /* (non-Javadoc)
+ * @see org.apache.droids.api.Task#getTaskDate()
+ */
public String getTaskDate() {
return taskDate;
}
+ /* (non-Javadoc)
+ * @see org.apache.droids.api.Task#getDepth()
+ */
public int getDepth() {
return depth;
}
+ /* (non-Javadoc)
+ * @see org.apache.droids.api.Task#setDepth(int)
+ */
public void setDepth(int depth) {
this.depth = depth;
}
Modified: labs/droids/trunk/src/core/java/org/apache/droids/parse/ParseData.java
URL: http://svn.apache.org/viewvc/labs/droids/trunk/src/core/java/org/apache/droids/parse/ParseData.java?rev=663920&r1=663919&r2=663920&view=diff
==============================================================================
--- labs/droids/trunk/src/core/java/org/apache/droids/parse/ParseData.java (original)
+++ labs/droids/trunk/src/core/java/org/apache/droids/parse/ParseData.java Fri Jun 6 05:58:47 2008
@@ -16,11 +16,24 @@
*/
package org.apache.droids.parse;
+/**
+ * The result object that are filled by a parser
+ * @author thorsten
+ * @version 1.0
+ *
+ */
public class ParseData {
private Outlink[] outlinks;
+ /**
+ * Create a new instance of Parse data for the given outlinks
+ * @param outlinks the array of outgoing links
+ */
public ParseData(Outlink[] outlinks) {
- this.outlinks=outlinks;
+ this.outlinks=outlinks.clone();
}
- /** The outlinks of the page. */
- public Outlink[] getOutlinks() { return outlinks; }
+ /**
+ * Get the outlinks of the page.
+ * @return
+ */
+ public Outlink[] getOutlinks() { return outlinks.clone(); }
}
Modified: labs/droids/trunk/src/core/java/org/apache/droids/parse/ParseImpl.java
URL: http://svn.apache.org/viewvc/labs/droids/trunk/src/core/java/org/apache/droids/parse/ParseImpl.java?rev=663920&r1=663919&r2=663920&view=diff
==============================================================================
--- labs/droids/trunk/src/core/java/org/apache/droids/parse/ParseImpl.java (original)
+++ labs/droids/trunk/src/core/java/org/apache/droids/parse/ParseImpl.java Fri Jun 6 05:58:47 2008
@@ -18,21 +18,38 @@
import org.apache.droids.api.Parse;
+/**
+ * Default implementation of Parse
+ * @author thorsten
+ * @version 1.0
+ *
+ */
public class ParseImpl implements Parse {
private ParseData parseData;
private String text;
+ /**
+ * Create a new instance of a Parse for the given text and ParseData
+ * @param text the textual representation of the task
+ * @param parseData
+ */
public ParseImpl(String text, ParseData parseData) {
this.text = text;
this.parseData = parseData;
}
+ /* (non-Javadoc)
+ * @see org.apache.droids.api.Parse#getData()
+ */
public ParseData getData() {
return parseData;
}
+ /* (non-Javadoc)
+ * @see org.apache.droids.api.Parse#getText()
+ */
public String getText() {
return text;
}
Modified: labs/droids/trunk/src/core/java/org/apache/droids/parse/html/HtmlParser.java
URL: http://svn.apache.org/viewvc/labs/droids/trunk/src/core/java/org/apache/droids/parse/html/HtmlParser.java?rev=663920&r1=663919&r2=663920&view=diff
==============================================================================
--- labs/droids/trunk/src/core/java/org/apache/droids/parse/html/HtmlParser.java (original)
+++ labs/droids/trunk/src/core/java/org/apache/droids/parse/html/HtmlParser.java Fri Jun 6 05:58:47 2008
@@ -22,13 +22,10 @@
import java.util.ArrayList;
import java.util.HashSet;
-import javax.xml.stream.XMLInputFactory;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.droids.api.Parse;
import org.apache.droids.api.Parser;
import org.apache.droids.api.Task;
+import org.apache.droids.helper.Loggable;
import org.apache.droids.parse.Outlink;
import org.apache.droids.parse.ParseData;
import org.apache.droids.parse.ParseImpl;
@@ -43,23 +40,23 @@
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
-public class HtmlParser implements Parser {
- protected final Log log = LogFactory.getLog(this.getClass()
- .getCanonicalName());
-
- private XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+/**
+ * @author thorsten
+ * @version 1.0
+ *
+ */
+public class HtmlParser extends Loggable implements Parser {
- private URL base;
+ private URL base=null;
- private Task link;
+ private Task link=null;
- public Parse getParse(InputStream stream, Task link) {
- this.link = link;
+ public Parse getParse(InputStream stream, Task newLink) {
+ this.link = newLink;
try {
- this.base = new URL(link.getId());
+ this.base = new URL(newLink.getId());
} catch (MalformedURLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
+ log.fatal(e1);
}
ParseData parseData = null;
// setup filter chain
@@ -73,8 +70,7 @@
parser.parse(base.toExternalForm(), node);
parseData = extract(node);
} catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.fatal(e);
return new ParseImpl(stream.toString(), null);
}
return new ParseImpl(stream.toString(), parseData);
@@ -85,10 +81,10 @@
try {
extractLinks(node, links, new HashSet<String>());
} catch (MalformedURLException e) {
- e.printStackTrace();
+ log.fatal(e);
}
Outlink[] outlinks = new Outlink[0];
- outlinks = (Outlink[]) links.toArray(new Outlink[links.size()]);
+ outlinks =links.toArray(new Outlink[links.size()]);
return new ParseData(outlinks);
}
@@ -107,16 +103,14 @@
parser.setFeature("http://cyberneko.org/html/features/report-errors",
false);
} catch (SAXNotRecognizedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.fatal(e);
} catch (SAXNotSupportedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.fatal(e);
}
return parser;
}
- private ElementRemover getRemover() {
+ private static ElementRemover getRemover() {
// create element remover filter
ElementRemover remover = new ElementRemover();
// set which elements to accept
@@ -132,7 +126,7 @@
if (node.getNodeType() == Node.ELEMENT_NODE) {
if ("a".equalsIgnoreCase(node.getNodeName())) {
NamedNodeMap attrs = node.getAttributes();
- String target;
+ String target=null;
for (int i = 0; i < attrs.getLength(); i++) {
Node attr = attrs.item(i);
String attrName = attr.getNodeName();
@@ -147,6 +141,7 @@
links.add(outlink);
}
} catch (Exception e) {
+ log.fatal(e);
}
}
}
Added: labs/droids/trunk/src/core/java/org/apache/droids/parse/html/package-info.java
URL: http://svn.apache.org/viewvc/labs/droids/trunk/src/core/java/org/apache/droids/parse/html/package-info.java?rev=663920&view=auto
==============================================================================
--- labs/droids/trunk/src/core/java/org/apache/droids/parse/html/package-info.java (added)
+++ labs/droids/trunk/src/core/java/org/apache/droids/parse/html/package-info.java Fri Jun 6 05:58:47 2008
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * This package contains various parser.
+ */
+package org.apache.droids.parse.html;
+
Propchange: labs/droids/trunk/src/core/java/org/apache/droids/parse/html/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: labs/droids/trunk/src/core/java/org/apache/droids/parse/package-info.java
URL: http://svn.apache.org/viewvc/labs/droids/trunk/src/core/java/org/apache/droids/parse/package-info.java?rev=663920&view=auto
==============================================================================
--- labs/droids/trunk/src/core/java/org/apache/droids/parse/package-info.java (added)
+++ labs/droids/trunk/src/core/java/org/apache/droids/parse/package-info.java Fri Jun 6 05:58:47 2008
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * This package contains various helper and implementations around parsing.
+ */
+package org.apache.droids.parse;
+
Propchange: labs/droids/trunk/src/core/java/org/apache/droids/parse/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org