You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2012/04/08 17:14:54 UTC
svn commit: r1311021 [1/2] - in /incubator/stanbol/trunk/enhancer/generic:
core/src/main/resources/OSGI-INF/metatype/
core/src/test/java/org/apache/stanbol/enhancer/contentitem/inmemory/
rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities...
Author: rwesten
Date: Sun Apr 8 15:14:53 2012
New Revision: 1311021
URL: http://svn.apache.org/viewvc?rev=1311021&view=rev
Log:
Implementation for the following Issues:
STANBOL-573 (and sub-tasks STANBOL-579, STANBOL-577): Implementation of the ContentItemFactory and refactoring all components to use the new factory
STANBOL-575: added an enhancer test module
STANBOL-576: refactored the servicesapi module
* moved all implementation of the servicesapi module form .helper to .impl
* moved rdfentities to an own module (this was only used by some unit tests)
* moved in-memory ContentItem/Blob implementation to the new enhancer.core module
* also moved the EnhancementEngineManager and ChainManager implementations from their own module to the new enhancer.core
STANBOL-574: added implementation of an File based ContentItem/Blob
STANBOL-562: Changed the default home directory for the Stanbol launchers (framework, stable, full, full-war) from /sling to /stanbol.
* also added a common.properties file that defines a stanbol.home property set to "${sling.home}"
* Note that the common.properties file can be used to define any additional environment property. However it CAN NOT override properties already defined by the sling.properties file.
Note: this does not yet fix all that issues as some minor things like (metatype.properties, adding apache headers to files, license information for dependencies ...) are still missing.
Added:
incubator/stanbol/trunk/enhancer/generic/core/src/main/resources/OSGI-INF/metatype/metatype.properties
incubator/stanbol/trunk/enhancer/generic/core/src/test/java/org/apache/stanbol/enhancer/contentitem/inmemory/InMemoryBlobTest.java
incubator/stanbol/trunk/enhancer/generic/core/src/test/java/org/apache/stanbol/enhancer/contentitem/inmemory/InMemoryContentItemFactoryTest.java
incubator/stanbol/trunk/enhancer/generic/core/src/test/java/org/apache/stanbol/enhancer/contentitem/inmemory/InMemoryContentItemTest.java
incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/Rdf.java (with props)
incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/RdfEntity.java (with props)
incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/RdfEntityFactory.java (with props)
incubator/stanbol/trunk/enhancer/generic/rdfentities/src/test/java/org/apache/stanbol/enhancer/rdfentities/fise/TestEnhancementInterfaces.java (with props)
incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractChain.java (contents, props changed)
- copied, changed from r1306967, incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/AbstractChain.java
incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractContentItemFactory.java (with props)
incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractEnhancementEngine.java (contents, props changed)
- copied, changed from r1306967, incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/AbstractEnhancementEngine.java
incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ByteArraySource.java (with props)
incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ChainsTracker.java (contents, props changed)
- copied, changed from r1306967, incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ChainsTracker.java
incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ContentItemImpl.java
- copied, changed from r1306967, incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemImpl.java
incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/EnginesTracker.java (contents, props changed)
- copied, changed from r1306967, incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/EnginesTracker.java
incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/NameBasedServiceTrackingState.java (contents, props changed)
- copied, changed from r1306967, incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/NameBasedServiceTrackingState.java
incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ServiceReferenceRankingComparator.java (contents, props changed)
- copied, changed from r1306967, incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ServiceReferenceRankingComparator.java
incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/SingleEngineChain.java (contents, props changed)
- copied, changed from r1306967, incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/SingleEngineChain.java
incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/StreamSource.java (with props)
incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/StringSource.java (with props)
incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/UrlReference.java (with props)
incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/package.html (with props)
incubator/stanbol/trunk/enhancer/generic/test/src/main/java/org/apache/stanbol/enhancer/test/BlobTest.java (with props)
incubator/stanbol/trunk/enhancer/generic/test/src/main/java/org/apache/stanbol/enhancer/test/ContentItemFactoryTest.java (with props)
incubator/stanbol/trunk/enhancer/generic/test/src/main/java/org/apache/stanbol/enhancer/test/ContentItemTest.java (with props)
Added: incubator/stanbol/trunk/enhancer/generic/core/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/core/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1311021&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/core/src/main/resources/OSGI-INF/metatype/metatype.properties (added)
+++ incubator/stanbol/trunk/enhancer/generic/core/src/main/resources/OSGI-INF/metatype/metatype.properties Sun Apr 8 15:14:53 2012
@@ -0,0 +1,40 @@
+# 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.
+
+#===============================================================================
+#The name and ServiceRankin property as defined for EnhancementEngine and Ranking
+#===============================================================================
+
+stanbol.enhancer.chain.name.name=Name
+stanbol.enhancer.chain.name.description=The name of the enhancement chain. \
+The RESFful API of this chain will be accessible at /enhancer/chain/<name>
+
+
+#===============================================================================
+#EnhancementEngineManagerImpl
+#===============================================================================
+
+org.apache.stanbol.enhancer.enginemanager.impl.EnhancementEngineManagerImpl.name=Apache Stanbol Enhancement Engine Manager
+org.apache.stanbol.enhancer.enginemanager.impl.EnhancementEngineManagerImpl.description=Service that allows to retrieve active \
+EnhancementEngines by name.
+
+#===============================================================================
+# ChainManagerImpl
+#===============================================================================
+
+org.apache.stanbol.enhancer.chainmanager.impl.ChainManagerImpl.name=Stanbol Enhancer Enhancement Chain Manager
+org.apache.stanbol.enhancer.chainmanager.impl.ChainManagerImpl.description=Service that allows to retrieve active \
+enhancement Chains by name.
+
Added: incubator/stanbol/trunk/enhancer/generic/core/src/test/java/org/apache/stanbol/enhancer/contentitem/inmemory/InMemoryBlobTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/core/src/test/java/org/apache/stanbol/enhancer/contentitem/inmemory/InMemoryBlobTest.java?rev=1311021&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/core/src/test/java/org/apache/stanbol/enhancer/contentitem/inmemory/InMemoryBlobTest.java (added)
+++ incubator/stanbol/trunk/enhancer/generic/core/src/test/java/org/apache/stanbol/enhancer/contentitem/inmemory/InMemoryBlobTest.java Sun Apr 8 15:14:53 2012
@@ -0,0 +1,38 @@
+/*
+* 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.stanbol.enhancer.contentitem.inmemory;
+
+import java.io.IOException;
+
+import org.apache.stanbol.enhancer.servicesapi.Blob;
+import org.apache.stanbol.enhancer.servicesapi.ContentItemFactory;
+import org.apache.stanbol.enhancer.servicesapi.ContentSource;
+import org.apache.stanbol.enhancer.test.BlobTest;
+
+public class InMemoryBlobTest extends BlobTest {
+
+ private static final ContentItemFactory factory = InMemoryContentItemFactory.getInstance();
+ /*
+ * Override to test InMemoryBlob instead of AbstractBlob
+ * @see org.apache.stanbol.enhancer.serviceapi.helper.BlobMimeTypeHandlingTest#getBlobToTestMimetypeHandling(java.lang.String)
+ */
+ @Override
+ protected Blob createBlob(ContentSource cs) throws IOException {
+ return factory.createBlob(cs);
+ }
+
+}
Added: incubator/stanbol/trunk/enhancer/generic/core/src/test/java/org/apache/stanbol/enhancer/contentitem/inmemory/InMemoryContentItemFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/core/src/test/java/org/apache/stanbol/enhancer/contentitem/inmemory/InMemoryContentItemFactoryTest.java?rev=1311021&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/core/src/test/java/org/apache/stanbol/enhancer/contentitem/inmemory/InMemoryContentItemFactoryTest.java (added)
+++ incubator/stanbol/trunk/enhancer/generic/core/src/test/java/org/apache/stanbol/enhancer/contentitem/inmemory/InMemoryContentItemFactoryTest.java Sun Apr 8 15:14:53 2012
@@ -0,0 +1,13 @@
+package org.apache.stanbol.enhancer.contentitem.inmemory;
+
+import org.apache.stanbol.enhancer.servicesapi.ContentItemFactory;
+import org.apache.stanbol.enhancer.test.ContentItemFactoryTest;
+
+public class InMemoryContentItemFactoryTest extends ContentItemFactoryTest {
+
+ @Override
+ protected ContentItemFactory createContentItemFactory() {
+ return InMemoryContentItemFactory.getInstance();
+ }
+
+}
Added: incubator/stanbol/trunk/enhancer/generic/core/src/test/java/org/apache/stanbol/enhancer/contentitem/inmemory/InMemoryContentItemTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/core/src/test/java/org/apache/stanbol/enhancer/contentitem/inmemory/InMemoryContentItemTest.java?rev=1311021&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/core/src/test/java/org/apache/stanbol/enhancer/contentitem/inmemory/InMemoryContentItemTest.java (added)
+++ incubator/stanbol/trunk/enhancer/generic/core/src/test/java/org/apache/stanbol/enhancer/contentitem/inmemory/InMemoryContentItemTest.java Sun Apr 8 15:14:53 2012
@@ -0,0 +1,25 @@
+package org.apache.stanbol.enhancer.contentitem.inmemory;
+
+import java.io.IOException;
+
+import org.apache.stanbol.enhancer.servicesapi.Blob;
+import org.apache.stanbol.enhancer.servicesapi.ContentItem;
+import org.apache.stanbol.enhancer.servicesapi.ContentItemFactory;
+import org.apache.stanbol.enhancer.servicesapi.ContentSource;
+import org.apache.stanbol.enhancer.test.ContentItemTest;
+
+public class InMemoryContentItemTest extends ContentItemTest {
+
+ private static final ContentItemFactory factory = InMemoryContentItemFactory.getInstance();
+
+ @Override
+ protected ContentItem createContentItem(ContentSource source) throws IOException {
+ return factory.createContentItem(source);
+ }
+
+ @Override
+ protected Blob createBlob(ContentSource source) throws IOException {
+ return factory.createBlob(source);
+ }
+
+}
Added: incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/Rdf.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/Rdf.java?rev=1311021&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/Rdf.java (added)
+++ incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/Rdf.java Sun Apr 8 15:14:53 2012
@@ -0,0 +1,31 @@
+/*
+* 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.stanbol.enhancer.rdfentities;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+
+/**
+ * Annotation used to define the RDF concept/property represented
+ * by an Java class/method
+ * @author Rupert Westenthaler
+ *
+ */
+@Retention(RUNTIME)
+public @interface Rdf {
+ String id();
+}
Propchange: incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/Rdf.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/RdfEntity.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/RdfEntity.java?rev=1311021&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/RdfEntity.java (added)
+++ incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/RdfEntity.java Sun Apr 8 15:14:53 2012
@@ -0,0 +1,39 @@
+/*
+* 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.stanbol.enhancer.rdfentities;
+
+import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.NonLiteral;
+import org.apache.clerezza.rdf.core.UriRef;
+
+/**
+ * Super interface for all interfaces using the {@link RdfEntityFactory} to
+ * create proxy objects.
+ *
+ * @author Rupert Westenthaler
+ */
+public interface RdfEntity {
+
+ /**
+ * Getter for the RDF node represented by the Proxy.
+ *
+ * @return the node representing the proxy. Typically an {@link UriRef} but
+ * could be also a {@link BNode}
+ */
+ NonLiteral getId();
+
+}
Propchange: incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/RdfEntity.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/RdfEntityFactory.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/RdfEntityFactory.java?rev=1311021&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/RdfEntityFactory.java (added)
+++ incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/RdfEntityFactory.java Sun Apr 8 15:14:53 2012
@@ -0,0 +1,91 @@
+/*
+* 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.stanbol.enhancer.rdfentities;
+
+import java.util.Collection;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.NonLiteral;
+import org.apache.stanbol.enhancer.rdfentities.impl.SimpleRdfEntityFactory;
+
+
+/**
+ * A Factory that creates proxies over rdf nodes - so called RDF facades.
+ *
+ * @author Rupert Westenthaler
+ */
+public abstract class RdfEntityFactory {
+
+ /**
+ * Creates a new factory for the parsed {@link MGraph} instance.
+ *
+ * @param graph the graph used by the proxies created by this factory to
+ * read/write there data
+ * @return the created factory
+ */
+ public static RdfEntityFactory createInstance(MGraph graph){
+ return new SimpleRdfEntityFactory(graph);
+ }
+
+ /**
+ * Getter for a proxy for the parsed rdf node that implements all the parsed
+ * Interfaces. The interface parsed as type must extend {@link RdfEntity}.
+ * Additional interfaces must not extend this interface.
+ * <p>
+ * Interfaces parsed as parameter:
+ * <ul>
+ * <li> SHOULD have an {@link Rdf} annotation. If that is the case, than the
+ * according rdf:type statements are checks/added when the proxy is created
+ * <li> all methods of the parsed interfaces MUST HAVE {@link Rdf}
+ * annotations. Calling methods with missing annotations causes an
+ * {@link IllegalStateException} at runtime
+ * <li> all methods of the parsed interface MUST HAVE a return type or a
+ * single parameter (e.g. void setSomething(String value) or String
+ * getSomething). Methods with a parameter do set the parsed data. Methods
+ * with a return type do read the data.
+ * </ul>
+ *
+ * Proxies returned by this Factory:
+ * <ul>
+ * <li> MUST NOT have an internal state. They need to represent a view over
+ * the current data within the {@link MGraph} instance. Direct changes to
+ * the graph need to be reflected in calls to proxies.
+ * <li> Implementations need to support {@link Collection} as parameter.
+ * Collections need to represent a live view over the triples within the
+ * {@link MGraph}. However iterators may throw a
+ * {@link ConcurrentModificationException} if the graph changes while using
+ * the iterator.
+ * </ul>
+ *
+ * @param <T> The interface implemented by the returned proxy
+ * @param rdfNode the rdfNode represented by the proxy (created if not
+ * present in the Graph)
+ * @param type The interface for the proxy. Needs to extend {@link RdfEntity}
+ * @param additionalInterfaces Additional interfaces the proxy needs to
+ * implement.
+ *
+ * @return A proxy representing the parsed rdf node and implementing all the
+ * parsed interfaces
+ * @throws IllegalArgumentException if the node is <code>null</code> or the
+ * parsed interfaces do not fulfil the requirements as stated.
+ * @throws NullPointerException if the parameter type, additionalInterfaces
+ * or any entry of additionalInterfaces is <code>null</code>.
+ */
+ public abstract <T extends RdfEntity> T getProxy(NonLiteral rdfNode,
+ Class<T> type, Class<?>... additionalInterfaces) throws IllegalArgumentException;
+
+}
Propchange: incubator/stanbol/trunk/enhancer/generic/rdfentities/src/main/java/org/apache/stanbol/enhancer/rdfentities/RdfEntityFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/enhancer/generic/rdfentities/src/test/java/org/apache/stanbol/enhancer/rdfentities/fise/TestEnhancementInterfaces.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/rdfentities/src/test/java/org/apache/stanbol/enhancer/rdfentities/fise/TestEnhancementInterfaces.java?rev=1311021&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/rdfentities/src/test/java/org/apache/stanbol/enhancer/rdfentities/fise/TestEnhancementInterfaces.java (added)
+++ incubator/stanbol/trunk/enhancer/generic/rdfentities/src/test/java/org/apache/stanbol/enhancer/rdfentities/fise/TestEnhancementInterfaces.java Sun Apr 8 15:14:53 2012
@@ -0,0 +1,266 @@
+/*
+* 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.stanbol.enhancer.rdfentities.fise;
+
+import static org.apache.stanbol.enhancer.servicesapi.rdf.Properties.*;
+import static org.apache.stanbol.enhancer.servicesapi.rdf.TechnicalClasses.ENHANCER_TEXTANNOTATION;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Iterator;
+
+import org.apache.clerezza.rdf.core.Literal;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.stanbol.enhancer.contentitem.inmemory.InMemoryContentItem;
+import org.apache.stanbol.enhancer.contentitem.inmemory.InMemoryContentItemFactory;
+import org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory;
+import org.apache.stanbol.enhancer.rdfentities.fise.EntityAnnotation;
+import org.apache.stanbol.enhancer.rdfentities.fise.TextAnnotation;
+import org.apache.stanbol.enhancer.servicesapi.ContentItem;
+import org.apache.stanbol.enhancer.servicesapi.ContentItemFactory;
+import org.apache.stanbol.enhancer.servicesapi.ContentSource;
+import org.apache.stanbol.enhancer.servicesapi.helper.EnhancementEngineHelper;
+import org.apache.stanbol.enhancer.servicesapi.impl.StringSource;
+import org.apache.stanbol.enhancer.servicesapi.rdf.TechnicalClasses;
+import org.junit.Test;
+
+
+/**
+ * Tests if the FISE enhancement structure RDF facades
+ *
+ * @author Rupert Westenthaler
+ */
+public class TestEnhancementInterfaces {
+
+ public static final String SINGLE_SENTENCE = "Dr. Patrick Marshall (1869 - November 1950) was a"
+ + " geologist who lived in New Zealand and worked at the University of Otago.";
+ protected static final ContentSource SINGLE_SENTENCE_SOURCE = new StringSource(SINGLE_SENTENCE);
+ public static final UriRef TEST_ENHANCEMENT_ENGINE_URI = new UriRef("urn:test:dummyEnhancementEngine");
+ private static ContentItemFactory ciFactory = InMemoryContentItemFactory.getInstance();
+ public static ContentItem createContentItem(ContentSource cs) throws IOException {
+ return ciFactory.createContentItem(cs);
+ }
+
+ @Test
+ public void testEnhancementInterfaces() throws Exception {
+ ContentItem ci = createContentItem(SINGLE_SENTENCE_SOURCE);
+ UriRef ciUri = new UriRef(ci.getUri().getUnicodeString());
+ RdfEntityFactory factory = RdfEntityFactory.createInstance(ci.getMetadata());
+ long start = System.currentTimeMillis();
+ //create an Text Annotation representing an extracted Person
+ TextAnnotation personAnnotation = factory.getProxy(
+ createEnhancementURI(), TextAnnotation.class);
+ personAnnotation.setCreator(TEST_ENHANCEMENT_ENGINE_URI);
+ personAnnotation.setCreated(new Date());
+ personAnnotation.setExtractedFrom(ciUri);
+ personAnnotation.getDcType().add(new UriRef("http://www.example.org/cv/annotatation-types/text#Person"));
+ personAnnotation.setConfidence(0.8);
+ personAnnotation.setSelectedText("Patrick Marshall");
+ personAnnotation.setStart(SINGLE_SENTENCE.indexOf(personAnnotation.getSelectedText()));
+ personAnnotation.setEnd(personAnnotation.getStart()+personAnnotation.getSelectedText().length());
+ personAnnotation.setSelectionContext(SINGLE_SENTENCE);
+
+ //create an Text Annotation representing an extracted Location
+ TextAnnotation locationAnnotation = factory.getProxy(
+ createEnhancementURI(), TextAnnotation.class);
+ locationAnnotation.setCreator(TEST_ENHANCEMENT_ENGINE_URI);
+ locationAnnotation.setCreated(new Date());
+ locationAnnotation.setExtractedFrom(ciUri);
+ locationAnnotation.getDcType().add(new UriRef("http://www.example.org/cv/annotatation-types/text#Location"));
+ locationAnnotation.setConfidence(0.78);
+ locationAnnotation.setSelectedText("New Zealand");
+ locationAnnotation.setStart(SINGLE_SENTENCE.indexOf(locationAnnotation.getSelectedText()));
+ locationAnnotation.setEnd(locationAnnotation.getStart()+locationAnnotation.getSelectedText().length());
+ locationAnnotation.setSelectionContext(SINGLE_SENTENCE);
+
+ //create an Text Annotation representing an extracted Organisation
+ TextAnnotation orgAnnotation = factory.getProxy(
+ createEnhancementURI(), TextAnnotation.class);
+ orgAnnotation.setCreator(TEST_ENHANCEMENT_ENGINE_URI);
+ orgAnnotation.setCreated(new Date());
+ orgAnnotation.setExtractedFrom(ciUri);
+ orgAnnotation.getDcType().add(new UriRef("http://www.example.org/cv/annotatation-types/text#Organisation"));
+ orgAnnotation.setConfidence(0.78);
+ orgAnnotation.setSelectedText("University of Otago");
+ orgAnnotation.setStart(SINGLE_SENTENCE.indexOf(orgAnnotation.getSelectedText()));
+ orgAnnotation.setEnd(orgAnnotation.getStart()+orgAnnotation.getSelectedText().length());
+ orgAnnotation.setSelectionContext(SINGLE_SENTENCE);
+
+ // create an Entity Annotation for the person TextAnnotation
+ EntityAnnotation patrickMarshall = factory.getProxy(
+ createEnhancementURI(), EntityAnnotation.class);
+ patrickMarshall.setCreator(TEST_ENHANCEMENT_ENGINE_URI);
+ patrickMarshall.setCreated(new Date());
+ patrickMarshall.setExtractedFrom(ciUri);
+ patrickMarshall.getDcType().add(new UriRef("http://www.example.org/cv/annotatation-types/entity#Entity"));
+ patrickMarshall.setConfidence(0.56);
+ patrickMarshall.getRelations().add(personAnnotation);
+ patrickMarshall.setEntityLabel("Patrick Marshall");
+ patrickMarshall.setEntityReference(new UriRef("http://rdf.freebase.com/rdf/en/patrick_marshall"));
+ patrickMarshall.getEntityTypes().addAll(Arrays.asList(
+ new UriRef("http://rdf.freebase.com/ns/people.person"),
+ new UriRef("http://rdf.freebase.com/ns/common.topic"),
+ new UriRef("http://rdf.freebase.com/ns/education.academic")));
+ // and an other for New Zealand
+ EntityAnnotation newZealand = factory.getProxy(
+ createEnhancementURI(), EntityAnnotation.class);
+ newZealand.setCreator(TEST_ENHANCEMENT_ENGINE_URI);
+ newZealand.setCreated(new Date());
+ newZealand.setExtractedFrom(ciUri);
+ newZealand.getDcType().add(new UriRef("http://www.example.org/cv/annotatation-types/entity#Entity"));
+ newZealand.setConfidence(0.98);
+ newZealand.getRelations().add(locationAnnotation);
+ newZealand.setEntityLabel("New Zealand");
+ newZealand.setEntityReference(new UriRef("http://rdf.freebase.com/rdf/en/new_zealand"));
+ newZealand.getEntityTypes().addAll(Arrays.asList(
+ new UriRef("http://rdf.freebase.com/ns/location.location"),
+ new UriRef("http://rdf.freebase.com/ns/common.topic"),
+ new UriRef("http://rdf.freebase.com/ns/location.country")));
+
+ // and an other option for New Zealand
+ EntityAnnotation airNewZealand = factory.getProxy(
+ createEnhancementURI(), EntityAnnotation.class);
+ airNewZealand.setCreator(TEST_ENHANCEMENT_ENGINE_URI);
+ airNewZealand.setCreated(new Date());
+ airNewZealand.setExtractedFrom(ciUri);
+ airNewZealand.getDcType().add(new UriRef("http://www.example.org/cv/annotatation-types/entity#Entity"));
+ airNewZealand.setConfidence(0.36);
+ airNewZealand.getRelations().add(locationAnnotation);
+ airNewZealand.setEntityLabel("New Zealand");
+ airNewZealand.setEntityReference(new UriRef("http://rdf.freebase.com/rdf/en/air_new_zealand"));
+ airNewZealand.getEntityTypes().addAll(Arrays.asList(
+ new UriRef("http://rdf.freebase.com/ns/business.sponsor"),
+ new UriRef("http://rdf.freebase.com/ns/common.topic"),
+ new UriRef("http://rdf.freebase.com/ns/travel.transport_operator"),
+ new UriRef("http://rdf.freebase.com/ns/aviation.airline"),
+ new UriRef("http://rdf.freebase.com/ns/aviation.aircraft_owner"),
+ new UriRef("http://rdf.freebase.com/ns/business.employer"),
+ new UriRef("http://rdf.freebase.com/ns/freebase.apps.hosts.com.appspot.acre.juggle.juggle"),
+ new UriRef("http://rdf.freebase.com/ns/business.company")));
+ System.out.println("creation time "+(System.currentTimeMillis()-start)+"ms");
+
+ //now test the enhancement
+ int numberOfTextAnnotations = checkAllTextAnnotations(ci.getMetadata());
+ assertEquals(3, numberOfTextAnnotations);
+
+ int numberOfEntityAnnotations = checkAllEntityAnnotations(ci.getMetadata());
+ assertEquals(3, numberOfEntityAnnotations);
+ }
+
+ private static UriRef createEnhancementURI() {
+ //TODO: add some Utility to create Instances to the RdfEntityFactory
+ // this should create a new URI by some default Algorithm
+ return new UriRef("urn:enhancement-" + EnhancementEngineHelper.randomUUID());
+ }
+
+ /*
+ * -----------------------------------------------------------------------
+ * Helper Methods to check Text and EntityAnnotations
+ * -----------------------------------------------------------------------
+ */
+
+ private int checkAllEntityAnnotations(MGraph g) {
+ Iterator<Triple> entityAnnotationIterator = g.filter(null,
+ RDF_TYPE, TechnicalClasses.ENHANCER_ENTITYANNOTATION);
+ int entityAnnotationCount = 0;
+ while (entityAnnotationIterator.hasNext()) {
+ UriRef entityAnnotation = (UriRef) entityAnnotationIterator.next().getSubject();
+ // test if selected Text is added
+ checkEntityAnnotation(g, entityAnnotation);
+ entityAnnotationCount++;
+ }
+ return entityAnnotationCount;
+ }
+
+ private int checkAllTextAnnotations(MGraph g) {
+ Iterator<Triple> textAnnotationIterator = g.filter(null,
+ RDF_TYPE, ENHANCER_TEXTANNOTATION);
+ // test if a textAnnotation is present
+ assertTrue("Expecting non-empty textAnnotationIterator", textAnnotationIterator.hasNext());
+ int textAnnotationCount = 0;
+ while (textAnnotationIterator.hasNext()) {
+ UriRef textAnnotation = (UriRef) textAnnotationIterator.next().getSubject();
+ // test if selected Text is added
+ checkTextAnnotation(g, textAnnotation);
+ textAnnotationCount++;
+ }
+ return textAnnotationCount;
+ }
+
+ /**
+ * Checks if a text annotation is valid.
+ */
+ private void checkTextAnnotation(MGraph g, UriRef textAnnotation) {
+ Iterator<Triple> selectedTextIterator = g.filter(textAnnotation,
+ ENHANCER_SELECTED_TEXT, null);
+ // check if the selected text is added
+ assertTrue(selectedTextIterator.hasNext());
+ // test if the selected text is part of the TEXT_TO_TEST
+ Resource object = selectedTextIterator.next().getObject();
+ assertTrue(object instanceof Literal);
+ assertTrue(SINGLE_SENTENCE.contains(((Literal) object).getLexicalForm()));
+ // test if context is added
+ Iterator<Triple> selectionContextIterator = g.filter(textAnnotation,
+ ENHANCER_SELECTION_CONTEXT, null);
+ assertTrue(selectionContextIterator.hasNext());
+ // test if the selected text is part of the TEXT_TO_TEST
+ object = selectionContextIterator.next().getObject();
+ assertTrue(object instanceof Literal);
+ assertTrue(SINGLE_SENTENCE.contains(((Literal) object).getLexicalForm()));
+ }
+
+ /**
+ * Checks if an entity annotation is valid.
+ */
+ private void checkEntityAnnotation(MGraph g, UriRef entityAnnotation) {
+ Iterator<Triple> relationToTextAnnotationIterator = g.filter(
+ entityAnnotation, DC_RELATION, null);
+ // check if the relation to the text annotation is set
+ assertTrue(relationToTextAnnotationIterator.hasNext());
+ while (relationToTextAnnotationIterator.hasNext()) {
+ // test if the referred annotations are text annotations
+ UriRef referredTextAnnotation = (UriRef) relationToTextAnnotationIterator.next().getObject();
+ assertTrue(g.filter(referredTextAnnotation, RDF_TYPE,
+ ENHANCER_TEXTANNOTATION).hasNext());
+ }
+
+ // test if an entity is referred
+ Iterator<Triple> entityReferenceIterator = g.filter(entityAnnotation,
+ ENHANCER_ENTITY_REFERENCE, null);
+ assertTrue(entityReferenceIterator.hasNext());
+ // test if the reference is an URI
+ assertTrue(entityReferenceIterator.next().getObject() instanceof UriRef);
+ // test if there is only one entity referred
+ assertFalse(entityReferenceIterator.hasNext());
+
+ // finally test if the entity label is set
+ Iterator<Triple> entityLabelIterator = g.filter(entityAnnotation,
+ ENHANCER_ENTITY_LABEL, null);
+ assertTrue(entityLabelIterator.hasNext());
+ }
+
+}
Propchange: incubator/stanbol/trunk/enhancer/generic/rdfentities/src/test/java/org/apache/stanbol/enhancer/rdfentities/fise/TestEnhancementInterfaces.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractChain.java (from r1306967, incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/AbstractChain.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractChain.java?p2=incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractChain.java&p1=incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/AbstractChain.java&r1=1306967&r2=1311021&rev=1311021&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/AbstractChain.java (original)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractChain.java Sun Apr 8 15:14:53 2012
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.stanbol.enhancer.servicesapi.helper;
+package org.apache.stanbol.enhancer.servicesapi.impl;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractChain.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractContentItemFactory.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractContentItemFactory.java?rev=1311021&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractContentItemFactory.java (added)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractContentItemFactory.java Sun Apr 8 15:14:53 2012
@@ -0,0 +1,218 @@
+package org.apache.stanbol.enhancer.servicesapi.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.enhancer.servicesapi.Blob;
+import org.apache.stanbol.enhancer.servicesapi.ContentItem;
+import org.apache.stanbol.enhancer.servicesapi.ContentItemFactory;
+import org.apache.stanbol.enhancer.servicesapi.ContentReference;
+import org.apache.stanbol.enhancer.servicesapi.ContentSink;
+import org.apache.stanbol.enhancer.servicesapi.ContentSource;
+import org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper;
+
+/**
+ * Abstract implementation of the {@link ContentItemFactory} that requires only
+ * the three abstract methods <ul>
+ * <li> {@link #createBlob(ContentSource)}
+ * <li> {@link #createContentItem(String, Blob, MGraph)}
+ * <li> {@link #createContentItem(UriRef, Blob, MGraph)}
+ * </ul> to be overridden.<p>
+ * Implementers should NOTE that {@link #createBlob(ContentSource)} will be
+ * called to create the main {@link Blob} instance for a contentItem before
+ * the {@link ContentItem} itself is instantiated. If this is a problem, than
+ * this abstract super class can not be used.
+ *
+ * @author Rupert Westenthaler
+ * @since 0.9.1-incubating
+ */
+@Component(componentAbstract=true,immediate=true,policy=ConfigurationPolicy.OPTIONAL)
+@Service(value=ContentItemFactory.class)
+public abstract class AbstractContentItemFactory implements ContentItemFactory {
+
+ /**
+ * State if {@link LazyDereferencingBlob}s are used for {@link Blob}s
+ * created for {@link ContentReference}s
+ */
+ private final boolean lazyLoadingBlobsEnabled;
+ /**
+ * Default constructor setting {@link #isLazyDereferenceing()} to <code>false</code>
+ */
+ protected AbstractContentItemFactory(){
+ this(false);
+ }
+ /**
+ * Creates a AbstractContentItemFactory and sets the state for the usage
+ * of {@link LazyDereferencingBlob}s.
+ * @param enableLazyDereferencingBlobs if {@link Blob}s generated for
+ * {@link ContentReference}s should dereference the content during the
+ * construction or lazily on the first access to the content.
+ */
+ protected AbstractContentItemFactory(boolean enableLazyDereferencingBlobs){
+ this.lazyLoadingBlobsEnabled = enableLazyDereferencingBlobs;
+ }
+
+ @Override
+ public final ContentItem createContentItem(ContentSource source) throws IOException {
+ return createContentItem((UriRef)null, source, null);
+ }
+
+ @Override
+ public final ContentItem createContentItem(String prefix, ContentSource source) throws IOException {
+ return createContentItem(prefix,source,null);
+ }
+
+ @Override
+ public final ContentItem createContentItem(UriRef id, ContentSource source) throws IOException {
+ return createContentItem(id, source, null);
+ }
+
+ @Override
+ public final ContentItem createContentItem(ContentReference reference) throws IOException {
+ return createContentItem(reference, null);
+ }
+
+ @Override
+ public final ContentItem createContentItem(ContentReference reference, MGraph metadata) throws IOException {
+ if(reference == null){
+ throw new IllegalArgumentException("The parsed ContentReference MUST NOT be NULL!");
+ }
+ return createContentItem(new UriRef(reference.getReference()),createBlob(reference),metadata);
+ }
+ @Override
+ public final ContentItem createContentItem(String prefix, ContentSource source,MGraph metadata) throws IOException {
+ if(prefix == null){
+ throw new IllegalArgumentException("The parsed prefix MUST NOT be NULL!");
+ }
+ if(source == null){
+ throw new IllegalArgumentException("The parsed ContentSource MUST NOT be NULL!");
+ }
+ return createContentItem(prefix, createBlob(source), metadata);
+ }
+
+ @Override
+ public final ContentItem createContentItem(UriRef id, ContentSource source, MGraph metadata) throws IOException {
+ if(source == null){
+ throw new IllegalArgumentException("The parsed ContentSource MUST NOT be NULL!");
+ }
+ return createContentItem(id, createBlob(source), metadata);
+ }
+
+
+
+ /**
+ * Creates a ContentItem for the parsed parameters
+ * @param id the ID or <code>null</code>. Implementors might want to use
+ * {@link ContentItemHelper#streamDigest(InputStream, java.io.OutputStream, String)
+ * for generating an ID while reading the data from the ContentSource
+ * @param blob the Blob
+ * @param metadata the metadata or <code>null</code> if none. Implementation
+ * are free to use the passed instance or to generate a new one. However
+ * they MUST ensure that all {@link Triple}s contained by the passed graph
+ * are also added to the {@link ContentItem#getMetadata() metadata} of the
+ * returned ContentItem.
+ * @return the created content item
+ */
+ protected abstract ContentItem createContentItem(UriRef id, Blob blob, MGraph metadata);
+
+ /**
+ * Creates a ContentItem for the parsed parameters
+ * @param prefix the prefix for the ID of the contentItem. Guaranteed to be
+ * NOT <code>null</code>. Implementors might want to use
+ * {@link ContentItemHelper#streamDigest(InputStream, java.io.OutputStream, String)
+ * for generating an ID while reading the data from the ContentSource
+ * @param blob the Blob
+ * @param metadata the metadata or <code>null</code> if none. Implementation
+ * are free to use the passed instance or to generate a new one. However
+ * they MUST ensure that all {@link Triple}s contained by the passed graph
+ * are also added to the {@link ContentItem#getMetadata() metadata} of the
+ * returned ContentItem.
+ * @return the created content item
+ */
+ protected abstract ContentItem createContentItem(String prefix, Blob blob, MGraph metadata);
+
+ @Override
+ public abstract Blob createBlob(ContentSource source) throws IOException;
+
+ @Override
+ public abstract ContentSink createContentSink(String mediaType) throws IOException;
+ /**
+ * Getter for the state if the content from {@link ContentReference} used
+ * to create {@link ContentItem}s and Blobs is dereferenced immediately or
+ * - lazily - on the first usage.
+ * @return the lazy dereferencing state.
+ */
+ public boolean isLazyDereferenceing(){
+ return lazyLoadingBlobsEnabled;
+ }
+
+ @Override
+ public final Blob createBlob(ContentReference reference) throws IOException {
+ if(reference == null){
+ throw new IllegalArgumentException("The passed ContentReference MUST NOT be NULL!");
+ }
+ if(lazyLoadingBlobsEnabled){
+ return new LazyDereferencingBlob(reference);
+ } else {
+ return createBlob(reference.dereference());
+ }
+ }
+
+ /**
+ * If {@link AbstractContentItemFactory#isLazyDereferenceing}
+ * @author westei
+ *
+ */
+ protected class LazyDereferencingBlob implements Blob {
+
+ private final ContentReference contentReference;
+ private Blob _blob;
+
+ protected LazyDereferencingBlob(ContentReference contentReference){
+ this.contentReference = contentReference;
+ }
+
+ @Override
+ public String getMimeType() {
+ return getLazy().getMimeType();
+ }
+
+ @Override
+ public InputStream getStream() {
+ return getLazy().getStream();
+ }
+
+ @Override
+ public Map<String,String> getParameter() {
+ return getLazy().getParameter();
+ }
+
+ @Override
+ public long getContentLength() {
+ if(_blob == null){ //do not dereference for calls on getContentLength
+ return -1;
+ } else {
+ return _blob.getContentLength();
+ }
+ }
+ public Blob getLazy() {
+ if(_blob == null){
+ try {
+ _blob = createBlob(contentReference.dereference());
+ } catch (IOException e) {
+ throw new IllegalStateException("Unable to derefernece content reference '"
+ + contentReference.getReference()+" (Message: "+e.getMessage()+")!",e);
+ }
+ }
+ return _blob;
+ }
+
+ }
+}
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractContentItemFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractEnhancementEngine.java (from r1306967, incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/AbstractEnhancementEngine.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractEnhancementEngine.java?p2=incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractEnhancementEngine.java&p1=incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/AbstractEnhancementEngine.java&r1=1306967&r2=1311021&rev=1311021&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/AbstractEnhancementEngine.java (original)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractEnhancementEngine.java Sun Apr 8 15:14:53 2012
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.stanbol.enhancer.servicesapi.helper;
+package org.apache.stanbol.enhancer.servicesapi.impl;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractEnhancementEngine.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ByteArraySource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ByteArraySource.java?rev=1311021&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ByteArraySource.java (added)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ByteArraySource.java Sun Apr 8 15:14:53 2012
@@ -0,0 +1,113 @@
+package org.apache.stanbol.enhancer.servicesapi.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.stanbol.enhancer.servicesapi.Blob;
+import org.apache.stanbol.enhancer.servicesapi.ContentSource;
+
+/**
+ * Allows to use a byte array as {@link ContentSource}. If the content is
+ * already stored in an byte array this implementation is preferable over the
+ * {@link StreamSource} as it does not require to copy the content to yet an
+ * other byte array when creating an in-memory content item when using the
+ * {@link #getData()} method.
+ *
+ * @author Rupert Westenthaler
+ *
+ */
+public class ByteArraySource implements ContentSource {
+
+ private static final Map<String,List<String>> NO_HEADERS = Collections.emptyMap();
+
+ private byte[] content;
+ private String mt;
+ private String name;
+ private Map<String,List<String>> headers;
+
+ /**
+ * Constructs a {@link ContentSource} for the passed byte array. The mime type will
+ * be set to "<code>application/octet-stream</code>"
+ * @param content the array containing the content
+ */
+ public ByteArraySource(byte[] content) {
+ this(content,null,null,null);
+ }
+ /**
+ * Constructs a {@link ContentSource} for the passed byte array and mime type.
+ * When parsing text the charset should be set as mime type parameter (e.g.
+ * "<code>text/plain; charset=UTF-8</code>". UTF-8 is assumed as default if
+ * missing.
+ * @param content the array containing the content
+ * @param mt the media type or <code>null</code> if unknown
+ */
+ public ByteArraySource(byte[] content,String mt) {
+ this(content,mt,null,null);
+ }
+ /**
+ * Constructs a {@link ContentSource} for the passed byte array and mime type.
+ * When parsing text the charset should be set as mime type parameter (e.g.
+ * "<code>text/plain; charset=UTF-8</code>". UTF-8 is assumed as default if
+ * missing. <p>
+ * This allows in addition to pass the file name or the original file.<br>
+ * NOTE however this information is currently not used
+ * as the {@link Blob} interface does not support those information
+ * @param content the array containing the content
+ * @param mt the media type or <code>null</code> if unknown
+ * @param fileName the file name or <code>null</code> if unknown
+ */
+ public ByteArraySource(byte[] content,String mt, String fileName) {
+ this(content,mt,fileName,null);
+ }
+ /**
+ * Constructs a {@link ContentSource} for the passed byte array and mime type.
+ * When parsing text the charset should be set as mime type parameter (e.g.
+ * "<code>text/plain; charset=UTF-8</code>". UTF-8 is assumed as default if
+ * missing. <p>
+ * This allows in addition to pass the file name and a map with
+ * additional header fields (e.g. HTTP headers). <br>
+ * NOTE however this information is currently not used
+ * as the {@link Blob} interface does not support those information
+ * @param content the array containing the content
+ * @param mt the media type or <code>null</code> if unknown
+ * @param fileName the file name or <code>null</code> if unknown
+ * @param headers additional headers or <code>null</code>/empty map if none.
+ */
+ public ByteArraySource(byte[] content,String mt, String fileName,Map<String,List<String>> headers) {
+ if(content == null){
+ throw new IllegalArgumentException("The parsed byte array MUST NOT be NULL!");
+ }
+ this.content = content;
+ this.mt = mt == null ? "application/octet-stream" : mt;
+ this.name = fileName;
+ this.headers = headers == null ? NO_HEADERS : headers;
+ }
+
+ @Override
+ public InputStream getStream() {
+ return new ByteArrayInputStream(content);
+ }
+ @Override
+ public byte[] getData() throws IOException {
+ return content;
+ }
+ @Override
+ public String getMediaType() {
+ return mt;
+ }
+
+ @Override
+ public String getFileName() {
+ return name;
+ }
+
+ @Override
+ public Map<String,List<String>> getHeaders() {
+ return headers;
+ }
+
+}
\ No newline at end of file
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ByteArraySource.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ChainsTracker.java (from r1306967, incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ChainsTracker.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ChainsTracker.java?p2=incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ChainsTracker.java&p1=incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ChainsTracker.java&r1=1306967&r2=1311021&rev=1311021&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ChainsTracker.java (original)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ChainsTracker.java Sun Apr 8 15:14:53 2012
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.stanbol.enhancer.servicesapi.helper;
+package org.apache.stanbol.enhancer.servicesapi.impl;
import static org.apache.stanbol.enhancer.servicesapi.Chain.PROPERTY_NAME;
import static org.osgi.framework.Constants.OBJECTCLASS;
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ChainsTracker.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ContentItemImpl.java (from r1306967, incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemImpl.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ContentItemImpl.java?p2=incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ContentItemImpl.java&p1=incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemImpl.java&r1=1306967&r2=1311021&rev=1311021&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemImpl.java (original)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ContentItemImpl.java Sun Apr 8 15:14:53 2012
@@ -14,14 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.stanbol.enhancer.servicesapi.helper;
+package org.apache.stanbol.enhancer.servicesapi.impl;
import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
import java.util.LinkedHashMap;
-import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
Copied: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/EnginesTracker.java (from r1306967, incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/EnginesTracker.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/EnginesTracker.java?p2=incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/EnginesTracker.java&p1=incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/EnginesTracker.java&r1=1306967&r2=1311021&rev=1311021&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/EnginesTracker.java (original)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/EnginesTracker.java Sun Apr 8 15:14:53 2012
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.stanbol.enhancer.servicesapi.helper;
+package org.apache.stanbol.enhancer.servicesapi.impl;
import static org.apache.stanbol.enhancer.servicesapi.EnhancementEngine.PROPERTY_NAME;
import static org.osgi.framework.Constants.OBJECTCLASS;
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/EnginesTracker.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/NameBasedServiceTrackingState.java (from r1306967, incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/NameBasedServiceTrackingState.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/NameBasedServiceTrackingState.java?p2=incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/NameBasedServiceTrackingState.java&p1=incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/NameBasedServiceTrackingState.java&r1=1306967&r2=1311021&rev=1311021&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/NameBasedServiceTrackingState.java (original)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/NameBasedServiceTrackingState.java Sun Apr 8 15:14:53 2012
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.stanbol.enhancer.servicesapi.helper;
+package org.apache.stanbol.enhancer.servicesapi.impl;
import java.util.ArrayList;
import java.util.Collections;
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/NameBasedServiceTrackingState.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ServiceReferenceRankingComparator.java (from r1306967, incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ServiceReferenceRankingComparator.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ServiceReferenceRankingComparator.java?p2=incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ServiceReferenceRankingComparator.java&p1=incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ServiceReferenceRankingComparator.java&r1=1306967&r2=1311021&rev=1311021&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ServiceReferenceRankingComparator.java (original)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ServiceReferenceRankingComparator.java Sun Apr 8 15:14:53 2012
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.stanbol.enhancer.servicesapi.helper;
+package org.apache.stanbol.enhancer.servicesapi.impl;
import java.util.Comparator;
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/ServiceReferenceRankingComparator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/SingleEngineChain.java (from r1306967, incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/SingleEngineChain.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/SingleEngineChain.java?p2=incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/SingleEngineChain.java&p1=incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/SingleEngineChain.java&r1=1306967&r2=1311021&rev=1311021&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/SingleEngineChain.java (original)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/SingleEngineChain.java Sun Apr 8 15:14:53 2012
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.stanbol.enhancer.servicesapi.helper;
+package org.apache.stanbol.enhancer.servicesapi.impl;
import static org.apache.stanbol.enhancer.servicesapi.helper.ExecutionPlanHelper.createExecutionPlan;
import static org.apache.stanbol.enhancer.servicesapi.helper.ExecutionPlanHelper.writeExecutionNode;
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/SingleEngineChain.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/StreamSource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/StreamSource.java?rev=1311021&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/StreamSource.java (added)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/StreamSource.java Sun Apr 8 15:14:53 2012
@@ -0,0 +1,146 @@
+package org.apache.stanbol.enhancer.servicesapi.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.stanbol.enhancer.servicesapi.Blob;
+import org.apache.stanbol.enhancer.servicesapi.ContentSource;
+
+/**
+ * Allows to use a {@link InputStream} as {@link ContentSource}. This is the
+ * most common case, that all the contents passed via the RESTful interface of
+ * the Stanbol Enhancer will be passed as {@link InputStream}.
+ * @author Rupert Westenthaler
+ *
+ */
+public class StreamSource implements ContentSource {
+
+ private static final Map<String,List<String>> NO_HEADERS = Collections.emptyMap();
+
+ private final InputStream in;
+ private final String mt;
+ private final String name;
+ private final Map<String,List<String>> headers;
+ private boolean consumed = false;
+ private byte[] data;
+ /**
+ * Constructs a StreamSource for the passed InputStream. The mime type will
+ * be set to "<code>application/octet-stream</code>"
+ * @param in the stream
+ */
+ public StreamSource(InputStream in) {
+ this(in,null,null,null);
+ }
+ /**
+ * Constructs a stream source for the passed stream and mime type. When
+ * parsing text the charset should be set as mime type parameter (e.g.
+ * "<code>text/plain; charset=UTF-8</code>". UTF-8 is assumed as default if
+ * missing.
+ * @param in the stream
+ * @param mt the media type or <code>null</code> if unknown
+ */
+ public StreamSource(InputStream in, String mt) {
+ this(in,mt,null,null);
+ }
+ /**
+ * Constructs a stream source for the passed stream and mime type. When
+ * parsing text the charset should be set as mime type parameter (e.g.
+ * "<code>text/plain; charset=UTF-8</code>". UTF-8 is assumed as default if
+ * missing. <p>
+ * This allows in addition to pass the file name of the original file.
+ * NOTE however this information is currently not used as the {@link Blob}
+ * interface does not support those information
+ * @param in the stream
+ * @param mt the media type or <code>null</code> if unknown
+ * @param fileName the file name or <code>null</code> if unknown
+ */
+ public StreamSource(InputStream in, String mt,String fileName) {
+ this(in,mt,fileName,null);
+ }
+ /**
+ * Constructs a stream source for the passed stream and mime type. When
+ * parsing text the charset should be set as mime type parameter (e.g.
+ * "<code>text/plain; charset=UTF-8</code>". UTF-8 is assumed as default if
+ * missing. <p>
+ * This allows in addition to pass a map with additional header filds
+ * (e.g. HTTP headers). <br>
+ * NOTE however this information is currently not used
+ * as the {@link Blob} interface does not support those information
+ * @param in the stream
+ * @param mt the media type or <code>null</code> if unknown
+ * @param headers additional headers or <code>null</code>/empty map if none.
+ */
+ public StreamSource(InputStream in, String mt,Map<String,List<String>> headers) {
+ this(in,mt,null,headers);
+ }
+ /**
+ * Constructs a stream source for the passed stream and mime type. When
+ * parsing text the charset should be set as mime type parameter (e.g.
+ * "<code>text/plain; charset=UTF-8</code>". UTF-8 is assumed as default if
+ * missing. <p>
+ * This allows in addition to pass the file name and a map with
+ * additional header fields (e.g. HTTP headers). <br>
+ * NOTE however this information is currently not used
+ * as the {@link Blob} interface does not support those information
+ * @param in the stream
+ * @param mt the media type or <code>null</code> if unknown
+ * @param fileName the file name or <code>null</code> if unknown
+ * @param headers additional headers or <code>null</code>/empty map if none.
+ */
+ public StreamSource(InputStream in, String mt,String fileName,Map<String,List<String>> headers) {
+ if(in == null){
+ throw new IllegalArgumentException("The passed InputStream MUST NOT be NULL!");
+ }
+ this.in = in;
+ this.mt = mt == null ? "application/octet-stream" : mt;
+ this.name = fileName;
+ this.headers = headers == null ? NO_HEADERS : headers;
+ }
+ @Override
+ public synchronized InputStream getStream() {
+ if(data != null){
+ return new ByteArrayInputStream(data);
+ }
+ if(consumed){
+ throw new IllegalStateException("This InputStream of this ContentSource is already consumed!");
+ }
+ consumed = true;
+ return in;
+ }
+ @Override
+ public byte[] getData() throws IOException {
+ if(data == null){
+ InputStream in = getStream();
+ try {
+ data = IOUtils.toByteArray(in);
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ }
+ return data;
+ }
+
+ @Override
+ public String getMediaType() {
+ return mt;
+ }
+
+ @Override
+ public String getFileName() {
+ return name;
+ }
+ @Override
+ public Map<String,List<String>> getHeaders() {
+ return headers;
+ }
+ @Override
+ protected void finalize() throws Throwable {
+ IOUtils.closeQuietly(in);
+ }
+
+}
\ No newline at end of file
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/StreamSource.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/StringSource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/StringSource.java?rev=1311021&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/StringSource.java (added)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/StringSource.java Sun Apr 8 15:14:53 2012
@@ -0,0 +1,52 @@
+package org.apache.stanbol.enhancer.servicesapi.impl;
+
+import java.nio.charset.Charset;
+
+import org.apache.stanbol.enhancer.servicesapi.ContentSource;
+
+/**
+ * Allows to use a String as a Source for Content.
+ * @author Rupert Westenthaler
+ *
+ */
+public class StringSource extends ByteArraySource implements ContentSource {
+ //TODO: validate that parsed MediaTypes to NOT contain the charset parameter
+ public static final Charset UTF8 = Charset.forName("UTF-8");
+ public static final String TEXT_PLAIN = "text/plain";
+ /**
+ * Creates a String source with the content type "text/plain".
+ * @param value
+ */
+ public StringSource(String value) {
+ this(value,null);
+ }
+ /**
+ * Allows to creates a StringSource with an other media type that text/plain
+ * @param value the value
+ * @param mt the MediaType. Do not use the "charset" parameter as this will
+ * be set to the internally used charset used to convert the parsed value
+ * to an byte array.
+ */
+ public StringSource(String value, String mt){
+ super(value == null ? null : value.getBytes(UTF8),
+ (mt != null ? mt : TEXT_PLAIN)+"; charset="+UTF8.name());
+ }
+ /**
+ * Allows to creates a StringSource with an other media type that text/plain
+ * and an custom {@link Charset} used to encode the String
+ * @param value the value
+ * @param charset the charset or <code>null</code> to use the default
+ * "UTF-8". To use the System default parse
+ * <code>{@link Charset#defaultCharset()}</code>
+ * @param mt the MediaType. Do not use the "charset" parameter as this will
+ * be set to the internally used charset used to convert the parsed value
+ * to an byte array.
+ */
+ public StringSource(String value, Charset charset, String mt){
+ super(value == null ? null : value.getBytes(charset == null ? UTF8 : charset),
+ (mt != null ? mt : TEXT_PLAIN)+"; charset="+(charset == null ?
+ UTF8 : charset).name());
+ }
+
+
+}
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/StringSource.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/UrlReference.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/UrlReference.java?rev=1311021&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/UrlReference.java (added)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/UrlReference.java Sun Apr 8 15:14:53 2012
@@ -0,0 +1,54 @@
+package org.apache.stanbol.enhancer.servicesapi.impl;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+
+import org.apache.stanbol.enhancer.servicesapi.ContentReference;
+import org.apache.stanbol.enhancer.servicesapi.ContentSource;
+
+
+/**
+ * Allows to use a URL for referencing a content.
+ */
+public class UrlReference implements ContentReference {
+
+ final URL url;
+ /**
+ * Uses the passed URI string to parse the URL.
+ * @param uri an absolute URI that can be converted to an URL
+ * @throws IllegalArgumentException if the passed URI string is <code>null</code>
+ * or can not be converted to an {@link URL}
+ */
+ public UrlReference(String uri) {
+ if(uri == null){
+ throw new IllegalArgumentException("The parsed URI reference MUST NOT be NULL!");
+ }
+ try {
+ this.url = URI.create(uri).toURL();
+ } catch (MalformedURLException e) {
+ throw new IllegalArgumentException("the passed URI can not be converted to an URL",e);
+ }
+ }
+ public UrlReference(URL url) {
+ if(url == null){
+ throw new IllegalArgumentException("The parsed URL MUST NOT be NULL!");
+ }
+ this.url = url;
+ }
+
+ @Override
+ public String getReference() {
+ return url.toString();
+ }
+
+ @Override
+ public ContentSource dereference() throws IOException {
+ URLConnection uc = url.openConnection();
+ return new StreamSource(uc.getInputStream(),
+ uc.getContentType(), uc.getHeaderFields());
+ }
+
+}
\ No newline at end of file
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/UrlReference.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/package.html
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/package.html?rev=1311021&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/package.html (added)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/package.html Sun Apr 8 15:14:53 2012
@@ -0,0 +1,28 @@
+<!--
+ 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.
+-->
+<body>
+<h1>Stanbol Enhancer services API implementation</h1>
+<p>
+This package contains implementations of the Stanbol Enhancer services API that
+are of common interest to Components using or implementing the Stanbol Enhancer
+API.
+</p>
+<p>
+This includes general purpose implementations of some interfaces as well as
+abstract implementations of the main interfaces.
+</p>
+</body>
\ No newline at end of file
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/package.html
------------------------------------------------------------------------------
svn:mime-type = text/plain