You are viewing a plain text version of this content. The canonical link for it is here.
Posted to droids-commits@incubator.apache.org by to...@apache.org on 2013/02/12 16:27:15 UTC
svn commit: r1445239 - in
/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core:
AbstractData.java AbstractParserData.java ContentEntity.java Data.java
ParserData.java
Author: tobr
Date: Tue Feb 12 16:27:14 2013
New Revision: 1445239
URL: http://svn.apache.org/r1445239
Log:
renamed ParserData to Data to support other data stores like the ContentEntity.
Removed all parsing data from the content entity.
Added:
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractData.java
- copied, changed from r1445215, incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractParserData.java
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/Data.java (with props)
Removed:
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractParserData.java
Modified:
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ContentEntity.java
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ParserData.java
Copied: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractData.java (from r1445215, incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractParserData.java)
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractData.java?p2=incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractData.java&p1=incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractParserData.java&r1=1445215&r2=1445239&rev=1445239&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractParserData.java (original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractData.java Tue Feb 12 16:27:14 2013
@@ -20,16 +20,16 @@ import java.util.HashMap;
import java.util.Map;
/**
- * Abstract class implementing the {@link ParserData} interface methods.
+ * Abstract class implementing the {@link Data} interface methods.
*/
-public abstract class AbstractParserData implements ParserData {
+public abstract class AbstractData implements Data {
private Map<String, String[]> data = null;
/**
* Constructs a new, empty parser data.
*/
- public AbstractParserData() {
+ public AbstractData() {
data = new HashMap<String, String[]>();
}
Modified: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ContentEntity.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ContentEntity.java?rev=1445239&r1=1445238&r2=1445239&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ContentEntity.java (original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ContentEntity.java Tue Feb 12 16:27:14 2013
@@ -18,147 +18,40 @@ package org.apache.droids.core;
import java.io.IOException;
import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
/**
- * ContentEntity stores the data of the retrieved content in a Map.
- * The predefined members are shortcuts to default fields.
- * Otherwise you can put your meta data in the Map using your own key.
*
- * TODO Storing the data in a map does not seem to be the best way.
- * Maybe we should split it up to separate members?
+ * ContentEntity stores the raw data of the retrieved content in a Map.
+ * Commonly this is done by the {@link Fetcher}.
*
- * @version 1.0
*/
-public class ContentEntity {
- private Map<String, Object> data;
-
+public class ContentEntity extends AbstractData {
public final static String CHARSET = "charset";
- public final static String CONTENT = "content";
public final static String CONTENT_TYPE = "content-type";
public final static String CONTENT_LENGTH = "content-length";
- public final static String LINKS = "links";
- public final static String ANCHORTEXT = "hreftitle";
- public final static String DEFAULT_CHARSET = "UTF-8";
+ private InputStream content;
- /**
- * Constructor
- */
public ContentEntity() {
- this.data = new HashMap<String, Object>();
- setCharset(DEFAULT_CHARSET);
- }
-
- /**
- * Put something in the data map.
- *
- * @param key the key to store the data
- * @param value the value for the key
- */
- public void put(String key, Object value) {
- this.data.put(key, value);
- }
-
- /**
- * Getting the value stored under a key
- *
- * @param key the key to the value
- * @return object with the value
- */
- public Object getValue(String key) {
- return data.get(key);
+ super();
}
/**
* Set the content data.
*
- * @param in the content data
+ * @param content the content data
*/
- public void setContent(InputStream in) {
- this.put(CONTENT, in);
+ public void setContent(InputStream content) {
+ this.content = content;
}
/**
* Get the content data.
*
* @return an InputStream containing the data of the content
- * @throws DroidsException
- */
- public InputStream getContent() throws DroidsException {
- if (this.getValue(CONTENT) != null) {
- if (this.getValue(CONTENT) instanceof InputStream) {
- return (InputStream)this.getValue(CONTENT);
- } else {
- throw new DroidsException("no content available");
- }
- } else {
- return null;
- }
- }
-
- /**
- * Close the content stream to release resources.
- *
- * @throws DroidsException
- * @throws IOException
- */
- public void close() throws DroidsException, IOException {
- if (this.getContent() != null) {
- this.getContent().close();
- }
- }
-
- /**
- * TODO should this go to the {@see LinkedTask}
- *
- * Outgoing links from the current document.
- *
- * @param links a set of links
- * @param <T> the Task
- */
- public <T extends Task> void setLinks(Set<T> links) {
- this.put(LINKS, links);
- }
-
- /**
- * Returns the Set of tasks, defining the outgoing links.
- *
- * @param <T> the Task
- * @return a set of tasks
- * @throws DroidsException
- */
- @SuppressWarnings("unchecked")
- public <T extends Task> Set<T> getLinks() throws DroidsException {
- if (this.getValue(LINKS) != null) {
- if (this.getValue(LINKS) instanceof Set) {
- return (Set<T>)this.getValue(LINKS);
- } else {
- throw new DroidsException("no set of links available");
- }
- } else {
- return null;
- }
- }
-
- /**
- * Set the content type of the document.
- *
- * @param contentType the content type
- */
- public void setContentType(String contentType) {
- this.put(CONTENT_TYPE, contentType);
- }
-
- /**
- * Get the charset.
- *
- * @return the charset
*/
- public String getCharset() {
- return this.getValue(CHARSET).toString();
+ public InputStream getContent() {
+ return this.content;
}
/**
@@ -167,26 +60,25 @@ public class ContentEntity {
* @param charset the charset
*/
public void setCharset(String charset) {
- this.put(CHARSET, charset);
+ this.set(CHARSET, charset);
}
/**
- * Get the content type.
+ * Get the charset.
*
- * @return the content type
+ * @return the charset
*/
- public String getContentType() {
- return this.getValue(CONTENT_TYPE).toString();
+ public String getCharset() {
+ return this.get(CHARSET);
}
-
/**
* Set the content length
*
* @param contentLength the length of the content
*/
public void setContentLength(long contentLength) {
- this.put(CONTENT_LENGTH, contentLength);
+ this.set(CONTENT_LENGTH, String.valueOf(contentLength));
}
/**
@@ -194,37 +86,37 @@ public class ContentEntity {
*
* @return the length of the content.
*/
- public long getContentLength() {
- return Long.getLong(this.getValue(CONTENT_LENGTH).toString()).longValue();
+ public long getContentLength() throws NumberFormatException {
+ return Long.parseLong(this.get(CONTENT_LENGTH));
}
-
/**
- * Set the title of an link
+ * Set the content type of the document.
*
- * @param anchorText the text
+ * @param contentType the content type
*/
- public void setAnchorText(String anchorText) {
- this.put(ANCHORTEXT, anchorText);
+ public void setContentType(String contentType) {
+ this.set(CONTENT_TYPE, contentType);
}
/**
- * Get the title of an anchor text
+ * Get the content type.
*
- * @return the Anchor text for this link
+ * @return the content type
*/
- public String getAnchorText() {
- return this.getValue(ANCHORTEXT).toString();
+ public String getContentType() {
+ return this.get(CONTENT_TYPE);
}
/**
- * Returns the data map.
+ * Close the content stream to release resources.
*
- * @return map containing the data
+ * @throws java.io.IOException
*/
- public Map<String, Object> getData() {
- return data;
+ public void close() throws IOException {
+ if (this.getContent() != null) {
+ this.getContent().close();
+ }
}
-
}
Added: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/Data.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/Data.java?rev=1445239&view=auto
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/Data.java (added)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/Data.java Tue Feb 12 16:27:14 2013
@@ -0,0 +1,79 @@
+/*
+ * 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.
+ */
+package org.apache.droids.core;
+
+/**
+ *
+ * A data container interface.
+ *
+ */
+public interface Data {
+
+ /**
+ * Returns an array of the names contained in the data.
+ *
+ * @return data names
+ */
+ public String[] names();
+
+ /**
+ * Set data name/value. Associate the specified value to the specified
+ * data name. If some previous values were associated to this name,
+ * they are removed. If the given value is <code>null</code>, then the
+ * data entry is removed.
+ *
+ * @param name the data name.
+ * @param value the data value, or <code>null</code>
+ */
+ public void set(final String name, final String value);
+
+ /**
+ * Set multiple values for a name.
+ * If the given value is <code>null</code>, then the data entry is removed.
+ *
+ * @param name the data name
+ * @param value the data value
+ */
+ public void set(final String name, final String[] value);
+
+ /**
+ * Add a data name/value mapping. Add the specified value to the list of
+ * values associated to the specified data name.
+ *
+ * @param name the data name.
+ * @param value the data value.
+ */
+ public void add(final String name, final String value);
+
+ /**
+ * Get the value associated to a data name. If many values are associated
+ * to the specified name, then the first one is returned.
+ *
+ * @param name of the data.
+ * @return the value associated to the specified data name.
+ */
+ public String get(final String name);
+
+ /**
+ * Get the values associated to a data name.
+ *
+ * @param name of the data.
+ * @return the values associated to a data name.
+ */
+ public String[] getValues(final String name);
+
+}
Propchange: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/Data.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/Data.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/Data.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ParserData.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ParserData.java?rev=1445239&r1=1445238&r2=1445239&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ParserData.java (original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ParserData.java Tue Feb 12 16:27:14 2013
@@ -18,62 +18,22 @@ package org.apache.droids.core;
/**
*
- * The data retrieved from the parser.
+ * Default implementation container for data extracted by the parser.
*
*/
-public interface ParserData {
+public class ParserData extends AbstractData {
- /**
- * Returns an array of the names contained in the parser data.
- *
- * @return data names
- */
- public String[] names();
+ public final static String TEXT = "text";
- /**
- * Set parser data name/value. Associate the specified value to the specified
- * parser data name. If some previous values were associated to this name,
- * they are removed. If the given value is <code>null</code>, then the
- * parser data entry is removed.
- *
- * @param name the parser data name.
- * @param value the parser data value, or <code>null</code>
- */
- public void set(final String name, final String value);
+ public ParserData() {
+ super();
+ }
- /**
- * Set multiple values for a name.
- * If the given value is <code>null</code>, then the parser data entry is removed.
- *
- * @param name the data name
- * @param value the data value
- */
- public void set(final String name, final String[] value);
-
- /**
- * Add a parser data name/value mapping. Add the specified value to the list of
- * values associated to the specified parser data name.
- *
- * @param name the parser data name.
- * @param value the parser data value.
- */
- public void add(final String name, final String value);
-
- /**
- * Get the value associated to a parser data name. If many values are associated
- * to the specified name, then the first one is returned.
- *
- * @param name of the parser data.
- * @return the value associated to the specified parser data name.
- */
- public String get(final String name);
-
- /**
- * Get the values associated to a parser data name.
- *
- * @param name of the parser data.
- * @return the values associated to a parser data name.
- */
- public String[] getValues(final String name);
+ public void setText(String text) {
+ this.set(TEXT, text);
+ }
+ public String getText() {
+ return this.get(TEXT);
+ }
}