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:12:46 UTC
svn commit: r1311019 [4/5] - in /incubator/stanbol/trunk: ./
contenthub/search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/
contenthub/search/related/src/main/java/org/apache/stanbol/contenthub/search/related/
contenthub/store/...
Added: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/ContentSource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/ContentSource.java?rev=1311019&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/ContentSource.java (added)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/ContentSource.java Sun Apr 8 15:12:40 2012
@@ -0,0 +1,65 @@
+package org.apache.stanbol.enhancer.servicesapi;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The content source representing the data and optionally the media type
+ * and file name. This interface is only used to parse the content
+ * when creating a {@link ContentItem}. To obtain the content of a
+ * ContentItem the {@link Blob} interface is used<p>
+ * NOTE that {@link #getStream()} can typically only be called a single time.
+ * Multiple calls will throw an {@link IllegalArgumentException}.
+ * @see Blob
+ */
+public interface ContentSource {
+ /**
+ * Getter for the data as stream. This method might only work a single time so
+ * multiple calls might result in {@link IllegalStateException}s.<p>
+ * {@link ContentItem}/{@link Blob} implementations that keep the
+ * content in memory should preferable use {@link #getData()} to
+ * obtain the content from the source.
+ * @return the data.
+ * @throws IllegalStateException if the stream is already consumed and
+ * can not be re-created.
+ * @see #getStream()
+ */
+ InputStream getStream();
+ /**
+ * Getter for the data as byte array. <p>
+ * NOTE that his method will load
+ * the content in-memory. However using this method instead of
+ * {@link #getStream()} might preserve holding multiple in-memory version
+ * of the same content in cases where both the {@link ContentSource}
+ * and the {@link ContentItem} are internally using an byte array to
+ * hold the content. <p>
+ * As a rule of thumb this method should only be
+ * used by in-memory {@link ContentItem}/{@link Blob} implementations.
+ * @return the content as byte array.
+ * @throws IOException On any error while reading the data from the source.
+ * @throws IllegalStateException If the {@link #getStream()} was already
+ * consumed when calling this method.
+ * @see #getStream()
+ */
+ byte[] getData() throws IOException;
+ /**
+ * An valid media type as defined by
+ * <a href="http://tools.ietf.org/html/rfc2046">RFC2046</a>.
+ * "application/octet-stream" if unknown
+ * @return The media type or <code>null</code> if unknown
+ */
+ String getMediaType();
+ /**
+ * The original file name.
+ * @return the name of the file or <code>null</code> if not known
+ */
+ String getFileName();
+ /**
+ * Getter for additional header information about the ContentSource. The
+ * returned Map MUST NOT be <code>null</code> and MAY be read-only.
+ * @return additional header information.
+ */
+ Map<String,List<String>> getHeaders();
+}
\ No newline at end of file
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/ContentSource.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemHelper.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemHelper.java?rev=1311019&r1=1311018&r2=1311019&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemHelper.java (original)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemHelper.java Sun Apr 8 15:12:40 2012
@@ -49,6 +49,8 @@ import org.apache.stanbol.enhancer.servi
*/
public class ContentItemHelper {
+ public static final String DEFAULT_CONTENT_ITEM_PREFIX = "urn:content-item-";
+
public static final String SHA1 = "SHA1";
public static final int MIN_BUF_SIZE = 8 * 1024; // 8 kB
@@ -141,13 +143,13 @@ public class ContentItemHelper {
}
public static UriRef makeDefaultUrn(Blob blob) {
- return makeDefaultUri("urn:content-item-", blob.getStream());
+ return makeDefaultUri(DEFAULT_CONTENT_ITEM_PREFIX, blob.getStream());
}
public static UriRef makeDefaultUrn(InputStream in) {
- return makeDefaultUri("urn:content-item-", in);
+ return makeDefaultUri(DEFAULT_CONTENT_ITEM_PREFIX, in);
}
public static UriRef makeDefaultUrn(byte[] data){
- return makeDefaultUri("urn:content-item-", new ByteArrayInputStream(data));
+ return makeDefaultUri(DEFAULT_CONTENT_ITEM_PREFIX, new ByteArrayInputStream(data));
}
public static UriRef makeDefaultUri(String baseUri, Blob blob) {
return makeDefaultUri(baseUri, blob.getStream());
Modified: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ExecutionPlanHelper.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ExecutionPlanHelper.java?rev=1311019&r1=1311018&r2=1311019&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ExecutionPlanHelper.java (original)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ExecutionPlanHelper.java Sun Apr 8 15:12:40 2012
@@ -20,8 +20,6 @@ import static org.apache.stanbol.enhance
import static org.apache.stanbol.enhancer.servicesapi.helper.EnhancementEngineHelper.get;
import static org.apache.stanbol.enhancer.servicesapi.helper.EnhancementEngineHelper.getEngineOrder;
import static org.apache.stanbol.enhancer.servicesapi.helper.EnhancementEngineHelper.getString;
-import static org.apache.stanbol.enhancer.servicesapi.helper.ExecutionPlanHelper.getExecutable;
-import static org.apache.stanbol.enhancer.servicesapi.helper.ExecutionPlanHelper.writeExecutionNode;
import static org.apache.stanbol.enhancer.servicesapi.rdf.ExecutionPlan.CHAIN;
import static org.apache.stanbol.enhancer.servicesapi.rdf.ExecutionPlan.DEPENDS_ON;
import static org.apache.stanbol.enhancer.servicesapi.rdf.ExecutionPlan.ENGINE;
@@ -31,7 +29,6 @@ import static org.apache.stanbol.enhance
import static org.apache.stanbol.enhancer.servicesapi.rdf.ExecutionPlan.OPTIONAL;
import static org.apache.stanbol.enhancer.servicesapi.rdf.Properties.RDF_TYPE;
-import java.awt.peer.LightweightPeer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -51,15 +48,14 @@ import org.apache.clerezza.rdf.core.NonL
import org.apache.clerezza.rdf.core.Resource;
import org.apache.clerezza.rdf.core.Triple;
import org.apache.clerezza.rdf.core.TripleCollection;
-import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
import org.apache.clerezza.rdf.core.impl.TripleImpl;
import org.apache.stanbol.commons.indexedgraph.IndexedMGraph;
import org.apache.stanbol.enhancer.servicesapi.ChainException;
import org.apache.stanbol.enhancer.servicesapi.EnhancementEngine;
import org.apache.stanbol.enhancer.servicesapi.EnhancementEngineManager;
import org.apache.stanbol.enhancer.servicesapi.ServiceProperties;
+import org.apache.stanbol.enhancer.servicesapi.impl.EnginesTracker;
import org.apache.stanbol.enhancer.servicesapi.rdf.ExecutionPlan;
public final class ExecutionPlanHelper {
Added: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/package.html
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/package.html?rev=1311019&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/package.html (added)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/package.html Sun Apr 8 15:12:40 2012
@@ -0,0 +1,23 @@
+<!--
+ 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 Helper</h1>
+<p>
+This package contains helper and utilities for using/implementing the Apache
+Stanbol Enhancer services API.
+</p>
+</body>
\ No newline at end of file
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/package.html
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/rdf/Enhancer.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/rdf/Enhancer.java?rev=1311019&r1=1311018&r2=1311019&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/rdf/Enhancer.java (original)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/rdf/Enhancer.java Sun Apr 8 15:12:40 2012
@@ -20,6 +20,7 @@ import org.apache.clerezza.rdf.core.UriR
public class Enhancer {
+ public static final UriRef CONTENT_ITEM = new UriRef(NamespaceEnum.enhancer+"ContentItem");
public static final UriRef ENHANCEMENT_ENGINE = new UriRef(NamespaceEnum.enhancer+"EnhancementEngine");
public static final UriRef ENHANCEMENT_CHAIN = new UriRef(NamespaceEnum.enhancer+"EnhancementChain");
public static final UriRef ENHANCER = new UriRef(NamespaceEnum.enhancer+"Enhancer");
Added: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/rdf/package.html
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/rdf/package.html?rev=1311019&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/rdf/package.html (added)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/rdf/package.html Sun Apr 8 15:12:40 2012
@@ -0,0 +1,23 @@
+<!--
+ 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 RDF</h1>
+<p>
+This package defines constants for the different Ontoloties used by the
+Stanbol Enhancer.
+</p>
+</body>
\ No newline at end of file
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/rdf/package.html
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/helper/EnhancementEngineHelperTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/helper/EnhancementEngineHelperTest.java?rev=1311019&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/helper/EnhancementEngineHelperTest.java (added)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/helper/EnhancementEngineHelperTest.java Sun Apr 8 15:12:40 2012
@@ -0,0 +1,24 @@
+/*
+* 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.serviceapi.helper;
+
+
+public class EnhancementEngineHelperTest {
+
+//TODO:
+
+}
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/helper/EnhancementEngineHelperTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/impl/ContentReferenceTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/impl/ContentReferenceTest.java?rev=1311019&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/impl/ContentReferenceTest.java (added)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/impl/ContentReferenceTest.java Sun Apr 8 15:12:40 2012
@@ -0,0 +1,83 @@
+package org.apache.stanbol.enhancer.serviceapi.impl;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.stanbol.enhancer.servicesapi.ContentReference;
+import org.apache.stanbol.enhancer.servicesapi.ContentSource;
+import org.apache.stanbol.enhancer.servicesapi.impl.UrlReference;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ContentReferenceTest {
+
+ private static final String TEST_RESOURCE_NAME = "contentReferece_test.txt";
+ private static final String TEST_RESOURCE_CONTENT = "Used to test ContentReference!";
+ private static URL testURL;
+
+ @BeforeClass
+ public static void initURL(){
+ testURL = ContentReferenceTest.class.getClassLoader().getResource(TEST_RESOURCE_NAME);
+ assertNotNull("Unable to load test resource '"
+ +TEST_RESOURCE_NAME+" via Classpath!",testURL);
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void missingReferenceString(){
+ new UrlReference((String)null);
+ }
+ @Test(expected=IllegalArgumentException.class)
+ public void missingReferenceURL(){
+ new UrlReference((URL)null);
+ }
+ @Test(expected=IllegalArgumentException.class)
+ public void emptyReferenceString(){
+ new UrlReference("");
+ }
+ @Test(expected=IllegalArgumentException.class)
+ public void relativeReferenceString(){
+ new UrlReference("relative/path/to/some.resource");
+ }
+ @Test(expected=IllegalArgumentException.class)
+ public void unknownProtocolReferenceString(){
+ new UrlReference("unknownProt://test.example.org/some.resource");
+ }
+
+ @Test
+ public void testUrlReference() throws IOException{
+ ContentReference ref = new UrlReference(testURL);
+ assertNotNull(ref);
+ assertEquals(ref.getReference(), testURL.toString());
+ ContentSource source = ref.dereference();
+ assertNotNull(source);
+ String content = IOUtils.toString(source.getStream(), "UTF-8");
+ assertNotNull(content);
+ assertEquals(TEST_RESOURCE_CONTENT, content);
+
+ //same as above, but by using ContentSource.getData() instead of
+ //ContentSource.getStream()
+ ref = new UrlReference(testURL);
+ assertNotNull(ref);
+ assertEquals(ref.getReference(), testURL.toString());
+ source = ref.dereference();
+ assertNotNull(source);
+ content = new String(source.getData(),"UTF-8");
+ assertNotNull(content);
+ assertEquals(TEST_RESOURCE_CONTENT, content);
+
+ //test the constructor that takes a String
+ ref = new UrlReference(testURL.toString());
+ assertNotNull(ref);
+ assertEquals(ref.getReference(), testURL.toString());
+ source = ref.dereference();
+ assertNotNull(source);
+ content = IOUtils.toString(source.getStream(), "UTF-8");
+ assertNotNull(content);
+ assertEquals(TEST_RESOURCE_CONTENT, content);
+ }
+
+}
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/impl/ContentReferenceTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/impl/ContentSourceTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/impl/ContentSourceTest.java?rev=1311019&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/impl/ContentSourceTest.java (added)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/impl/ContentSourceTest.java Sun Apr 8 15:12:40 2012
@@ -0,0 +1,299 @@
+package org.apache.stanbol.enhancer.serviceapi.impl;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
+import static junit.framework.Assert.assertSame;
+import static junit.framework.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.stanbol.enhancer.servicesapi.ContentSource;
+import org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper;
+import org.apache.stanbol.enhancer.servicesapi.impl.ByteArraySource;
+import org.apache.stanbol.enhancer.servicesapi.impl.StreamSource;
+import org.apache.stanbol.enhancer.servicesapi.impl.StringSource;
+import org.junit.Test;
+
+public class ContentSourceTest {
+
+ protected static final Charset UTF8 = Charset.forName("UTF-8");
+ protected static final String TEST_STRING = "Thîs áre têst dà tá!";
+ protected static final String DEFAULT_MT = "application/octet-stream";
+ protected static final String STRING_DEFAULT_MT = "text/plain; charset=UTF-8";
+ protected static final String MT = "text/plain";
+ protected static final String FILE_NAME = "test.txt";
+ protected static final Map<String,List<String>> HEADERS = new HashMap<String,List<String>>();
+ static {
+ HEADERS.put("Accept", Arrays.asList("application/rdf+xml"));
+ HEADERS.put("Accept-Language", Arrays.asList("en","de"));
+ }
+ protected static final String MT_WITH_PARAM = "text/plain; charset=UTF-8";
+ protected static final byte[] DATA = new String(TEST_STRING).getBytes(UTF8);
+
+ /*
+ * Tests ensuring the IllegalArgumentExceptions if null is parsed as stream
+ */
+ @Test(expected=IllegalArgumentException.class)
+ public void missingStream(){
+ new StreamSource(null);
+ }
+ @Test(expected=IllegalArgumentException.class)
+ public void missingStream1(){
+ new StreamSource(null,MT);
+ }
+ @Test(expected=IllegalArgumentException.class)
+ public void missingStream2(){
+ new StreamSource(null,MT,FILE_NAME);
+ }
+ @Test(expected=IllegalArgumentException.class)
+ public void missingStream3(){
+ new StreamSource(null,MT,HEADERS);
+ }
+ @Test(expected=IllegalArgumentException.class)
+ public void missingStream4(){
+ new StreamSource(null,MT,FILE_NAME,HEADERS);
+ }
+ /*
+ * Tests ensuring the IllegalArgumentExceptions if null is parsed as
+ * byte array to
+ */
+ @Test(expected=IllegalArgumentException.class)
+ public void missingByteArray(){
+ new ByteArraySource(null);
+ }
+ @Test(expected=IllegalArgumentException.class)
+ public void missingByteArray1(){
+ new ByteArraySource(null,MT);
+ }
+ @Test(expected=IllegalArgumentException.class)
+ public void missingByteArray2(){
+ new ByteArraySource(null,MT,FILE_NAME);
+ }
+ @Test(expected=IllegalArgumentException.class)
+ public void missingByteArray3(){
+ new ByteArraySource(null,MT,FILE_NAME,HEADERS);
+ }
+ /*
+ * Tests ensuring the IllegalArgumentExceptions if null is parsed as
+ * String to
+ */
+ @Test(expected=IllegalArgumentException.class)
+ public void missingString(){
+ new StringSource(null);
+ }
+ @Test(expected=IllegalArgumentException.class)
+ public void missingString1(){
+ new StringSource(null,MT);
+ }
+ @Test(expected=IllegalArgumentException.class)
+ public void missingString2(){
+ new StringSource(null,UTF8,MT);
+ }
+
+ /*
+ * Tests checking correct handling of data
+ */
+ @Test
+ public void checkStreamFromStreamSource() throws IOException {
+ ContentSource source = new StreamSource(new ByteArrayInputStream(DATA));
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ IOUtils.copy(source.getStream(), out);
+ Assert.assertTrue(Arrays.equals(DATA, out.toByteArray()));
+ try {
+ source.getStream();
+ //multiple calls are supported -> is OK
+ } catch (RuntimeException e) {
+ //multiple calls are not supported -> illegal state
+ Assert.assertTrue(e instanceof IllegalStateException);
+ }
+ }
+ @Test
+ public void checkDataFromStreamSource() throws IOException {
+ ContentSource source = new StreamSource(new ByteArrayInputStream(DATA));
+ Assert.assertTrue(Arrays.equals(DATA, source.getData()));
+ //multiple calls must work
+ source.getData();
+ }
+
+ @Test
+ public void checkStreamFromByteArraySource() throws IOException {
+ ContentSource source = new ByteArraySource(DATA);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ IOUtils.copy(source.getStream(), out);
+ Assert.assertTrue(Arrays.equals(DATA, out.toByteArray()));
+ try {
+ source.getStream();
+ //multiple calls are supported -> is OK
+ } catch (RuntimeException e) {
+ //multiple calls are not supported -> illegal state
+ Assert.assertTrue(e instanceof IllegalStateException);
+ }
+ }
+ @Test
+ public void checkDataFromByteArraySource() throws IOException {
+ ContentSource source = new ByteArraySource(DATA);
+ assertTrue(Arrays.equals(DATA, source.getData()));
+ //also check that the array is not copied
+ //Also checks multiple calls to getData MUST work
+ assertSame(DATA, source.getData());
+ }
+
+ @Test
+ public void checkStreamFromStringSource() throws IOException {
+ ContentSource source = new StringSource(TEST_STRING);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ IOUtils.copy(source.getStream(), out);
+ Assert.assertTrue(Arrays.equals(DATA, out.toByteArray()));
+ try {
+ source.getStream();
+ //multiple calls are supported -> is OK
+ } catch (RuntimeException e) {
+ //multiple calls are not supported -> illegal state
+ Assert.assertTrue(e instanceof IllegalStateException);
+ }
+ //test different encoding
+ Charset ISO8859_4 = Charset.forName("ISO-8859-4");
+ byte[] iso8859_4_data = TEST_STRING.getBytes(ISO8859_4);
+ source = new StringSource(TEST_STRING,ISO8859_4,null);
+ out = new ByteArrayOutputStream();
+ IOUtils.copy(source.getStream(), out);
+ Assert.assertTrue(Arrays.equals(iso8859_4_data, out.toByteArray()));
+
+ }
+ @Test
+ public void checkDataFromStringSource() throws IOException {
+ ContentSource source = new ByteArraySource(DATA);
+ Assert.assertTrue(Arrays.equals(DATA, source.getData()));
+ //multiple calls must work
+ source.getData();
+ }
+
+
+ /*
+ * Tests checking correct handling of parameters and default values
+ */
+
+ @Test
+ public void checkMediaTypeForStreamSource() throws IOException {
+ ContentSource source = new StreamSource(new ByteArrayInputStream(DATA));
+ assertEquals(DEFAULT_MT, source.getMediaType());
+ source = new StreamSource(new ByteArrayInputStream(DATA),null);
+ assertEquals(DEFAULT_MT, source.getMediaType());
+ source = new StreamSource(new ByteArrayInputStream(DATA),null,HEADERS);
+ assertEquals(DEFAULT_MT, source.getMediaType());
+ source = new StreamSource(new ByteArrayInputStream(DATA),null,FILE_NAME,HEADERS);
+ assertEquals(DEFAULT_MT, source.getMediaType());
+
+ source = new StreamSource(new ByteArrayInputStream(DATA),MT);
+ assertEquals(MT, source.getMediaType());
+ source = new StreamSource(new ByteArrayInputStream(DATA),MT,HEADERS);
+ assertEquals(MT, source.getMediaType());
+ source = new StreamSource(new ByteArrayInputStream(DATA),MT,FILE_NAME,HEADERS);
+ assertEquals(MT, source.getMediaType());
+ //Parameters MUST BE preserved!
+ source = new StreamSource(new ByteArrayInputStream(DATA),MT_WITH_PARAM);
+ assertEquals(MT_WITH_PARAM, source.getMediaType());
+ source = new StreamSource(new ByteArrayInputStream(DATA),MT_WITH_PARAM,HEADERS);
+ assertEquals(MT_WITH_PARAM, source.getMediaType());
+ source = new StreamSource(new ByteArrayInputStream(DATA),MT_WITH_PARAM,FILE_NAME,HEADERS);
+ assertEquals(MT_WITH_PARAM, source.getMediaType());
+ }
+ @Test
+ public void checkMediaTypeForByteArraySource() throws IOException {
+ ContentSource source = new ByteArraySource(DATA);
+ assertEquals(DEFAULT_MT, source.getMediaType());
+ source = new ByteArraySource(DATA,null);
+ assertEquals(DEFAULT_MT, source.getMediaType());
+ source = new ByteArraySource(DATA,null,FILE_NAME,HEADERS);
+ assertEquals(DEFAULT_MT, source.getMediaType());
+
+ source = new ByteArraySource(DATA,MT);
+ assertEquals(MT, source.getMediaType());
+ source = new ByteArraySource(DATA,MT,FILE_NAME,HEADERS);
+ assertEquals(MT, source.getMediaType());
+ //Parameters MUST BE preserved!
+ source = new ByteArraySource(DATA,MT_WITH_PARAM);
+ assertEquals(MT_WITH_PARAM, source.getMediaType());
+ source = new ByteArraySource(DATA,MT_WITH_PARAM,FILE_NAME);
+ assertEquals(MT_WITH_PARAM, source.getMediaType());
+ source = new ByteArraySource(DATA,MT_WITH_PARAM,FILE_NAME,HEADERS);
+ assertEquals(MT_WITH_PARAM, source.getMediaType());
+ }
+ @Test
+ public void checkMediaTypeForStringSource() throws IOException {
+ ContentSource source = new StringSource(TEST_STRING);
+ assertEquals(STRING_DEFAULT_MT, source.getMediaType());
+ source = new StringSource(TEST_STRING,null);
+ assertEquals(STRING_DEFAULT_MT, source.getMediaType());
+ source = new StringSource(TEST_STRING,UTF8,null);
+ assertEquals(STRING_DEFAULT_MT, source.getMediaType());
+ source = new StringSource(TEST_STRING,null,null);
+ assertEquals(STRING_DEFAULT_MT, source.getMediaType());
+
+ //this can be used to force the system default
+ source = new StringSource(TEST_STRING,Charset.defaultCharset(),null);
+ Map<String,String> mt = ContentItemHelper.parseMimeType(source.getMediaType());
+ assertEquals("text/plain", mt.get(null));
+ assertEquals(Charset.defaultCharset().name(), mt.get("charset"));
+
+ String OTHER_MT = "text/rtf";
+ source = new StringSource(TEST_STRING,OTHER_MT);
+ mt = ContentItemHelper.parseMimeType(source.getMediaType());
+ assertEquals(OTHER_MT, mt.get(null));
+ assertEquals(UTF8.name(), mt.get("charset"));
+
+ source = new StringSource(TEST_STRING, null,OTHER_MT);
+ mt = ContentItemHelper.parseMimeType(source.getMediaType());
+ assertEquals(OTHER_MT, mt.get(null));
+ assertEquals(UTF8.name(), mt.get("charset"));
+
+ Charset ISO8859_4 = Charset.forName("ISO-8859-4");
+ source = new StringSource(TEST_STRING, ISO8859_4,OTHER_MT);
+ mt = ContentItemHelper.parseMimeType(source.getMediaType());
+ assertEquals(OTHER_MT, mt.get(null));
+ assertEquals(ISO8859_4.name(), mt.get("charset"));
+ }
+
+ @Test
+ public void checkFileName() throws IOException{
+ ContentSource source = new StreamSource(new ByteArrayInputStream(DATA),null,null,null);
+ assertNull(source.getFileName());
+
+ source = new StreamSource(new ByteArrayInputStream(DATA),null,FILE_NAME,null);
+ assertEquals(FILE_NAME, source.getFileName());
+
+ source = new ByteArraySource(DATA,null,FILE_NAME);
+ assertEquals(FILE_NAME, source.getFileName());
+
+ source = new ByteArraySource(DATA,null,FILE_NAME,null);
+ assertEquals(FILE_NAME, source.getFileName());
+
+ }
+
+ @Test
+ public void checkHeaders() throws IOException{
+ ContentSource source = new StreamSource(new ByteArrayInputStream(DATA),null,null,null);
+ assertNotNull(source.getHeaders());
+ assertTrue(source.getHeaders().isEmpty());
+ source = new StreamSource(new ByteArrayInputStream(DATA),null,null,HEADERS);
+ assertEquals(HEADERS, source.getHeaders());
+
+ source = new ByteArraySource(DATA,null,null,null);
+ assertNotNull(source.getHeaders());
+ assertTrue(source.getHeaders().isEmpty());
+ source = new ByteArraySource(DATA,null,null,HEADERS);
+ assertEquals(HEADERS, source.getHeaders());
+ }
+
+}
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/impl/ContentSourceTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/resources/contentReferece_test.txt
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/resources/contentReferece_test.txt?rev=1311019&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/resources/contentReferece_test.txt (added)
+++ incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/resources/contentReferece_test.txt Sun Apr 8 15:12:40 2012
@@ -0,0 +1 @@
+Used to test ContentReference!
\ No newline at end of file
Propchange: incubator/stanbol/trunk/enhancer/generic/servicesapi/src/test/resources/contentReferece_test.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Propchange: incubator/stanbol/trunk/enhancer/generic/test/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Apr 8 15:12:40 2012
@@ -0,0 +1,7 @@
+target
+
+.classpath
+
+.project
+
+.settings
Added: incubator/stanbol/trunk/enhancer/generic/test/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/generic/test/pom.xml?rev=1311019&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/generic/test/pom.xml (added)
+++ incubator/stanbol/trunk/enhancer/generic/test/pom.xml Sun Apr 8 15:12:40 2012
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.enhancer.parent</artifactId>
+ <version>0.9.0-incubating-SNAPSHOT</version>
+ <relativePath>../../parent</relativePath>
+ </parent>
+
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.enhancer.test</artifactId>
+ <packaging>jar</packaging>
+
+ <name>Apache Stanbol Enhancer Test framework</name>
+ <description>Provides Unit Tests for the Interfaces of the
+ Stanbol Enhancer Services API.
+ </description>
+
+ <inceptionYear>2012</inceptionYear>
+
+ <scm>
+ <connection>
+ scm:svn:http://svn.apache.org/repos/asf/incubator/stanbol/trunk/enhancer/generic/test/
+ </connection>
+ <developerConnection>
+ scm:svn:https://svn.apache.org/repos/asf/incubator/stanbol/trunk/enhancer/generic/test/
+ </developerConnection>
+ <url>http://incubator.apache.org/stanbol/</url>
+ </scm>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.stanbol.enhancer.servicesapi;version=${project.version},
+ org.apache.stanbol.enhancer.servicesapi.helper;version=${project.version},
+ org.apache.stanbol.enhancer.servicesapi.rdf;version=${project.version}
+ </Export-Package>
+ <Private-Package>
+ org.apache.stanbol.enhancer.servicesapi.helper.impl;version=${project.version}
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.enhancer.servicesapi</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Propchange: incubator/stanbol/trunk/enhancer/generic/test/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/stanbol/trunk/enhancer/jersey/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/jersey/pom.xml?rev=1311019&r1=1311018&r2=1311019&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/jersey/pom.xml (original)
+++ incubator/stanbol/trunk/enhancer/jersey/pom.xml Sun Apr 8 15:12:40 2012
@@ -115,14 +115,6 @@
</dependency>
<dependency>
<groupId>org.apache.clerezza</groupId>
- <artifactId>rdf.jena.serializer</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.clerezza</groupId>
- <artifactId>rdf.jena.parser</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.clerezza</groupId>
<artifactId>rdf.rdfjson</artifactId>
</dependency>
@@ -204,6 +196,21 @@
<!-- for tests -->
<dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.enhancer.core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.jena.serializer</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.jena.parser</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
Modified: incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/reader/ContentItemReader.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/reader/ContentItemReader.java?rev=1311019&r1=1311018&r2=1311019&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/reader/ContentItemReader.java (original)
+++ incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/reader/ContentItemReader.java Sun Apr 8 15:12:40 2012
@@ -47,7 +47,6 @@ import javax.ws.rs.ext.Provider;
import org.apache.clerezza.rdf.core.MGraph;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.core.serializedform.Parser;
-import org.apache.clerezza.rdf.jena.parser.JenaParserProvider;
import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.FileUpload;
@@ -56,17 +55,13 @@ import org.apache.commons.fileupload.Req
import org.apache.commons.io.IOUtils;
import org.apache.stanbol.commons.indexedgraph.IndexedMGraph;
import org.apache.stanbol.commons.web.base.ContextHelper;
-import org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper;
import org.apache.stanbol.enhancer.servicesapi.Blob;
import org.apache.stanbol.enhancer.servicesapi.ContentItem;
-import org.apache.stanbol.enhancer.servicesapi.helper.InMemoryBlob;
-import org.apache.stanbol.enhancer.servicesapi.helper.InMemoryContentItem;
+import org.apache.stanbol.enhancer.servicesapi.ContentItemFactory;
+import org.apache.stanbol.enhancer.servicesapi.impl.StreamSource;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
-import org.codehaus.jettison.mapped.SimpleConverter;
-import org.mortbay.log.Log;
-import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -77,6 +72,7 @@ public class ContentItemReader implement
FileUpload fu = new FileUpload();
private Parser __parser;
private ServletContext context;
+ private ContentItemFactory __ciFactory;
public static final MediaType MULTIPART = MediaType.valueOf(MediaType.MULTIPART_FORM_DATA_TYPE.getType()+"/*");
@@ -87,7 +83,7 @@ public class ContentItemReader implement
* Lazy initialisation for the parser.
* @return teh parser
*/
- protected final Parser getParser(){
+ protected Parser getParser(){
/*
* Needed because Jersey tries to create an instance
* during initialisation. At that time the {@link BundleContext} required
@@ -97,13 +93,30 @@ public class ContentItemReader implement
if(__parser == null){
if(context != null){
__parser = ContextHelper.getServiceFromContext(Parser.class, context);
- } else { //mainly for unit tests we want also allow initialisation without context
- __parser = new Parser();
- __parser.bindParsingProvider(new JenaParserProvider());
+ } else {
+ throw new IllegalStateException("ServletContext is not NULL!");
+ }
+ if(__parser == null){
+ throw new IllegalStateException("Clerezza RDF parser service is not available(service class:"
+ + Parser.class + ")!");
}
}
return __parser;
}
+ protected ContentItemFactory getContentItemFactory(){
+ if(__ciFactory == null){
+ if(context != null){
+ __ciFactory = ContextHelper.getServiceFromContext(ContentItemFactory.class, context);
+ } else {
+ throw new IllegalStateException("ServletContext is not NULL!");
+ }
+ if(__ciFactory == null){
+ throw new IllegalStateException("ContentItemFactory service is not available (service class:"
+ + ContentItemFactory.class + ")!");
+ }
+ }
+ return __ciFactory;
+ }
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
@@ -237,8 +250,9 @@ public class ContentItemReader implement
throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
}
} else { //normal content
- contentItem = new InMemoryContentItem(
- IOUtils.toByteArray(entityStream), mediaType.toString());
+ ContentItemFactory ciFactory = getContentItemFactory();
+ contentItem = ciFactory.createContentItem(
+ new StreamSource(entityStream, mediaType.toString()));
//add the URI of the main content
parsedContentIds.add(contentItem.getPartUri(0).getUnicodeString());
}
@@ -269,6 +283,7 @@ public class ContentItemReader implement
private ContentItem createContentItem(String id, MGraph metadata, FileItemStream content,Set<String> parsedContentParts) throws IOException, FileUploadException {
MediaType partContentType = MediaType.valueOf(content.getContentType());
ContentItem contentItem = null;
+ ContentItemFactory ciFactory = getContentItemFactory();
if(MULTIPART.isCompatible(partContentType)){
//multiple contentParts are parsed
FileItemIterator contentPartIterator = fu.getItemIterator(
@@ -279,11 +294,11 @@ public class ContentItemReader implement
if(contentItem == null){
log.debug("create ContentItem {} for content (type:{})",
id,content.getContentType());
- contentItem = new InMemoryContentItem(id,
- IOUtils.toByteArray(fis.openStream()),
- fis.getContentType(), metadata);
+ contentItem = ciFactory.createContentItem(id != null ? new UriRef(id) : (UriRef)null,
+ new StreamSource(fis.openStream(),fis.getContentType()),
+ metadata);
} else {
- Blob blob = new InMemoryBlob(fis.openStream(), fis.getContentType());
+ Blob blob = ciFactory.createBlob(new StreamSource(fis.openStream(), fis.getContentType()));
UriRef contentPartId = null;
if(fis.getFieldName() != null && !fis.getFieldName().isEmpty()){
contentPartId = new UriRef(fis.getFieldName());
@@ -301,9 +316,9 @@ public class ContentItemReader implement
} else {
log.debug("create ContentItem {} for content (type:{})",
id,content.getContentType());
- contentItem = new InMemoryContentItem(id,
- IOUtils.toByteArray(content.openStream()),
- content.getContentType(), metadata);
+ contentItem = ciFactory.createContentItem(new UriRef(id),
+ new StreamSource(content.openStream(),content.getContentType()),
+ metadata);
}
//add the URI of the main content to the parsed contentParts
parsedContentParts.add(contentItem.getPartUri(0).getUnicodeString());
Modified: incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerResource.java?rev=1311019&r1=1311018&r2=1311019&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerResource.java (original)
+++ incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerResource.java Sun Apr 8 15:12:40 2012
@@ -66,6 +66,7 @@ import org.apache.stanbol.enhancer.servi
import org.apache.stanbol.enhancer.servicesapi.ChainException;
import org.apache.stanbol.enhancer.servicesapi.ChainManager;
import org.apache.stanbol.enhancer.servicesapi.ContentItem;
+import org.apache.stanbol.enhancer.servicesapi.ContentItemFactory;
import org.apache.stanbol.enhancer.servicesapi.EngineException;
import org.apache.stanbol.enhancer.servicesapi.EnhancementEngineManager;
import org.apache.stanbol.enhancer.servicesapi.EnhancementException;
@@ -87,13 +88,32 @@ public abstract class AbstractEnhancerRe
protected final EnhancementJobManager jobManager;
protected final EnhancementEngineManager engineManager;
protected final ChainManager chainManager;
+ protected final ContentItemFactory ciFactory;
public AbstractEnhancerResource(@Context ServletContext context) {
super();
// bind the job manager by looking it up from the servlet request context
+ // also throw exception if not available to make debugging easier!
jobManager = ContextHelper.getServiceFromContext(EnhancementJobManager.class, context);
+ if(jobManager == null){
+ throw new IllegalStateException("Unable to get "+EnhancementJobManager.class.getSimpleName()
+ + "service via ServletContext!");
+ }
chainManager = ContextHelper.getServiceFromContext(ChainManager.class, context);
+ if(jobManager == null){
+ throw new IllegalStateException("Unable to get "+ChainManager.class.getSimpleName()
+ + "service via ServletContext!");
+ }
engineManager = ContextHelper.getServiceFromContext(EnhancementEngineManager.class, context);
+ if(jobManager == null){
+ throw new IllegalStateException("Unable to get "+EnhancementEngineManager.class.getSimpleName()
+ + "service via ServletContext!");
+ }
+ ciFactory = ContextHelper.getServiceFromContext(ContentItemFactory.class, context);
+ if(jobManager == null){
+ throw new IllegalStateException("Unable to get "+ContentItemFactory.class.getSimpleName()
+ + "service via ServletContext!");
+ }
}
/**
* Getter for the Enhancement {@link Chain}
Modified: incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerUiResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerUiResource.java?rev=1311019&r1=1311018&r2=1311019&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerUiResource.java (original)
+++ incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerUiResource.java Sun Apr 8 15:12:40 2012
@@ -48,11 +48,12 @@ import org.apache.stanbol.commons.web.ba
import org.apache.stanbol.enhancer.servicesapi.Chain;
import org.apache.stanbol.enhancer.servicesapi.ChainException;
import org.apache.stanbol.enhancer.servicesapi.ContentItem;
+import org.apache.stanbol.enhancer.servicesapi.ContentItemFactory;
import org.apache.stanbol.enhancer.servicesapi.EngineException;
import org.apache.stanbol.enhancer.servicesapi.EnhancementEngine;
import org.apache.stanbol.enhancer.servicesapi.EnhancementException;
import org.apache.stanbol.enhancer.servicesapi.helper.ExecutionPlanHelper;
-import org.apache.stanbol.enhancer.servicesapi.helper.InMemoryContentItem;
+import org.apache.stanbol.enhancer.servicesapi.impl.StringSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -74,7 +75,7 @@ public abstract class AbstractEnhancerUi
private LinkedHashSet<ExecutionNode> _executionNodes;
private LinkedHashSet<ExecutionNode> _activeNodes;
protected final Chain chain;
-
+
public AbstractEnhancerUiResource(String chainName,ServletContext context) {
super(context);
serializer = ContextHelper.getServiceFromContext(Serializer.class, context);
@@ -110,24 +111,27 @@ public abstract class AbstractEnhancerUi
*/
@POST
@Consumes(APPLICATION_FORM_URLENCODED)
- public Response enhanceFromForm(@FormParam("content") String content, @FormParam("format") String format, @FormParam("ajax") boolean buildAjaxview, @Context HttpHeaders headers) throws EnhancementException,
- IOException {
- log.info("enhance from From: " + content);
- ContentItem ci = new InMemoryContentItem(content.getBytes("UTF-8"), TEXT_PLAIN);
- if(!buildAjaxview){ //rewrite to a normal EnhancementRequest
- return enhanceFromData(ci, null, false, null, false, null, false, null, headers);
- } else { //enhance and build the AJAX response
- enhance(ci);
- ContentItemResource contentItemResource = new ContentItemResource(null, ci, uriInfo, "",
- tcManager, serializer, servletContext);
- contentItemResource.setRdfSerializationFormat(format);
- Viewable ajaxView = new Viewable("/ajax/contentitem", contentItemResource);
- ResponseBuilder rb = Response.ok(ajaxView);
- rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=UTF-8");
- addCORSOrigin(servletContext, rb, headers);
- return rb.build();
- }
- }
+ public Response enhanceFromForm(@FormParam("content") String content,
+ @FormParam("format") String format,
+ @FormParam("ajax") boolean buildAjaxview,
+ @Context HttpHeaders headers) throws EnhancementException,
+ IOException {
+ log.info("enhance from From: " + content);
+ ContentItem ci = ciFactory.createContentItem(new StringSource(content));
+ if(!buildAjaxview){ //rewrite to a normal EnhancementRequest
+ return enhanceFromData(ci, null, false, null, false, null, false, null, headers);
+ } else { //enhance and build the AJAX response
+ enhance(ci);
+ ContentItemResource contentItemResource = new ContentItemResource(null, ci, uriInfo, "",
+ tcManager, serializer, servletContext);
+ contentItemResource.setRdfSerializationFormat(format);
+ Viewable ajaxView = new Viewable("/ajax/contentitem", contentItemResource);
+ ResponseBuilder rb = Response.ok(ajaxView);
+ rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=UTF-8");
+ addCORSOrigin(servletContext, rb, headers);
+ return rb.build();
+ }
+ }
public boolean isEngineActive(String name) {
return engineManager.isEngine(name);
Modified: incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnhancementEngineResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnhancementEngineResource.java?rev=1311019&r1=1311018&r2=1311019&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnhancementEngineResource.java (original)
+++ incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnhancementEngineResource.java Sun Apr 8 15:12:40 2012
@@ -50,7 +50,7 @@ import org.apache.stanbol.enhancer.servi
import org.apache.stanbol.enhancer.servicesapi.EnhancementEngineManager;
import org.apache.stanbol.enhancer.servicesapi.EnhancementJobManager;
import org.apache.stanbol.enhancer.servicesapi.ServiceProperties;
-import org.apache.stanbol.enhancer.servicesapi.helper.SingleEngineChain;
+import org.apache.stanbol.enhancer.servicesapi.impl.SingleEngineChain;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
Modified: incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnhancerRootResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnhancerRootResource.java?rev=1311019&r1=1311018&r2=1311019&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnhancerRootResource.java (original)
+++ incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnhancerRootResource.java Sun Apr 8 15:12:40 2012
@@ -53,7 +53,6 @@ import org.apache.clerezza.rdf.core.spar
import org.apache.clerezza.rdf.core.sparql.query.DescribeQuery;
import org.apache.clerezza.rdf.core.sparql.query.Query;
import org.apache.clerezza.rdf.ontologies.RDF;
-import org.apache.stanbol.enhancer.servicesapi.SparqlQueryEngine.SparqlQueryEngineException;
import org.apache.stanbol.enhancer.servicesapi.rdf.Enhancer;
import com.sun.jersey.api.view.Viewable;
@@ -100,8 +99,7 @@ public final class EnhancerRootResource
@Path("/sparql")
@Consumes(APPLICATION_FORM_URLENCODED)
@Produces({TEXT_HTML + ";qs=2", "application/sparql-results+xml", "application/rdf+xml", APPLICATION_XML})
- public Object sparql(@QueryParam(value = "query") String sparqlQuery) throws SparqlQueryEngineException,
- ParseException {
+ public Object sparql(@QueryParam(value = "query") String sparqlQuery) throws ParseException {
if (sparqlQuery == null) {
return Response.ok(new Viewable("sparql", this), TEXT_HTML).build();
}
@@ -118,8 +116,7 @@ public final class EnhancerRootResource
@Path("/sparql")
@Consumes(APPLICATION_FORM_URLENCODED)
@Produces({"application/sparql-results+xml", "application/rdf+xml", APPLICATION_XML})
- public Object postSparql(@FormParam("query") String sparqlQuery) throws SparqlQueryEngineException,
- ParseException {
+ public Object postSparql(@FormParam("query") String sparqlQuery) throws ParseException {
return sparql(sparqlQuery);
}
Modified: incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/writers/ContentItemWriter.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/writers/ContentItemWriter.java?rev=1311019&r1=1311018&r2=1311019&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/writers/ContentItemWriter.java (original)
+++ incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/writers/ContentItemWriter.java Sun Apr 8 15:12:40 2012
@@ -16,12 +16,9 @@
*/
package org.apache.stanbol.enhancer.jersey.writers;
-import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
-import static javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM;
import static javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM_TYPE;
import static javax.ws.rs.core.MediaType.MULTIPART_FORM_DATA_TYPE;
-import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE;
import static javax.ws.rs.core.MediaType.WILDCARD_TYPE;
import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.ENHANCEMENT_PROPERTIES_URI;
@@ -33,7 +30,6 @@ import static org.apache.stanbol.enhance
import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.isOmitParsedContent;
import static org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper.getBlob;
import static org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper.getContentParts;
-import static org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper.getMimeTypeWithParameters;
import java.io.IOException;
import java.io.InputStream;
@@ -48,7 +44,6 @@ import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -68,8 +63,6 @@ import javax.ws.rs.ext.Provider;
import org.apache.clerezza.rdf.core.TripleCollection;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.core.serializedform.Serializer;
-import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
-import org.apache.clerezza.rdf.jena.serializer.JenaSerializerProvider;
import org.apache.commons.io.IOUtils;
import org.apache.http.entity.mime.FormBodyPart;
import org.apache.http.entity.mime.HttpMultipart;
@@ -79,11 +72,9 @@ import org.apache.http.entity.mime.conte
import org.apache.http.entity.mime.content.ContentDescriptor;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.stanbol.commons.web.base.ContextHelper;
-import org.apache.stanbol.commons.web.base.writers.JsonLdSerializerProvider;
import org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper;
import org.apache.stanbol.enhancer.servicesapi.Blob;
import org.apache.stanbol.enhancer.servicesapi.ContentItem;
-import org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
@@ -113,7 +104,7 @@ public class ContentItemWriter implement
* Lazzy initialisation for the {@link Serializer}
* @return the {@link Serializer}
*/
- protected final Serializer getSerializer(){
+ protected Serializer getSerializer(){
/*
* Needed because Jersey tries to create an instance
* during initialisation. At that time the {@link BundleContext} required
@@ -124,9 +115,11 @@ public class ContentItemWriter implement
if(context != null){
__serializer = ContextHelper.getServiceFromContext(Serializer.class, context);
} else {
- __serializer = new Serializer();
- __serializer.bindSerializingProvider(new JenaSerializerProvider());
- __serializer.bindSerializingProvider(new JsonLdSerializerProvider());
+ throw new IllegalStateException("ServletContext is NULL!");
+ }
+ if(__serializer == null){
+ throw new IllegalStateException("Clerezza RDF Serializer service is not available(service class:"
+ + Serializer.class + ")!");
}
}
return __serializer;
Modified: incubator/stanbol/trunk/enhancer/jersey/src/test/java/org/apache/stanbol/enhancer/jersey/ContentItemReaderWriterTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/jersey/src/test/java/org/apache/stanbol/enhancer/jersey/ContentItemReaderWriterTest.java?rev=1311019&r1=1311018&r2=1311019&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/jersey/src/test/java/org/apache/stanbol/enhancer/jersey/ContentItemReaderWriterTest.java (original)
+++ incubator/stanbol/trunk/enhancer/jersey/src/test/java/org/apache/stanbol/enhancer/jersey/ContentItemReaderWriterTest.java Sun Apr 8 15:12:40 2012
@@ -23,7 +23,6 @@ import static org.apache.stanbol.enhance
import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.RDF_FORMAT;
import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.getEnhancementProperties;
import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.getOutputContent;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.getOutputContentParts;
import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.getParsedContentURIs;
import static org.apache.stanbol.enhancer.servicesapi.helper.ExecutionMetadataHelper.initExecutionMetadata;
import static org.apache.stanbol.enhancer.servicesapi.helper.ExecutionMetadataHelper.initExecutionMetadataContentPart;
@@ -36,12 +35,10 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
@@ -52,23 +49,24 @@ import javax.ws.rs.core.MultivaluedMap;
import org.apache.clerezza.rdf.core.MGraph;
import org.apache.clerezza.rdf.core.NonLiteral;
-import org.apache.clerezza.rdf.core.TripleCollection;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.core.serializedform.Parser;
+import org.apache.clerezza.rdf.core.serializedform.Serializer;
+import org.apache.clerezza.rdf.jena.parser.JenaParserProvider;
+import org.apache.clerezza.rdf.jena.serializer.JenaSerializerProvider;
import org.apache.clerezza.rdf.ontologies.RDF;
import org.apache.commons.io.IOUtils;
-import org.apache.stanbol.commons.indexedgraph.IndexedMGraph;
+import org.apache.stanbol.commons.web.base.writers.JsonLdSerializerProvider;
+import org.apache.stanbol.enhancer.contentitem.inmemory.InMemoryContentItemFactory;
import org.apache.stanbol.enhancer.jersey.reader.ContentItemReader;
-import org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper;
import org.apache.stanbol.enhancer.jersey.writers.ContentItemWriter;
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.helper.ContentItemHelper;
-import org.apache.stanbol.enhancer.servicesapi.helper.ExecutionMetadataHelper;
-import org.apache.stanbol.enhancer.servicesapi.helper.ExecutionPlanHelper;
-import org.apache.stanbol.enhancer.servicesapi.helper.InMemoryBlob;
-import org.apache.stanbol.enhancer.servicesapi.helper.InMemoryContentItem;
+import org.apache.stanbol.enhancer.servicesapi.impl.StringSource;
import org.apache.stanbol.enhancer.servicesapi.rdf.ExecutionMetadata;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -84,19 +82,25 @@ public class ContentItemReaderWriterTest
private static ContentItem contentItem;
private static ContentItemWriter ciWriter;
private static ContentItemReader ciReader;
+
+ private static ContentItemFactory ciFactory = InMemoryContentItemFactory.getInstance();
+
+
/**
* @return
*/
@BeforeClass
- public static void createTestContentItem() {
- contentItem = new InMemoryContentItem("urn:test",
- "<html>\n" +
- " <body>\n" +
- " This is a <b>ContentItem</b> to <i>Mime Multipart</i> test!\n" +
- " </body>\n" +
- "</html>","text/html");
- contentItem.addPart(new UriRef("run:text:text"), new InMemoryBlob(
- "This is a ContentItem to Mime Multipart test!", "text/plain"));
+ public static void createTestContentItem() throws IOException {
+ contentItem = ciFactory.createContentItem(new UriRef("urn:test"),
+ new StringSource(
+ "<html>\n" +
+ " <body>\n" +
+ " This is a <b>ContentItem</b> to <i>Mime Multipart</i> test!\n" +
+ " </body>\n" +
+ "</html>","text/html"));
+ contentItem.addPart(new UriRef("run:text:text"),
+ ciFactory.createBlob(new StringSource(
+ "This is a ContentItem to Mime Multipart test!")));
contentItem.getMetadata().add(new TripleImpl(
new UriRef("urn:test"), RDF.type, new UriRef("urn:types:Document")));
//mark the main content as parsed and also that all
@@ -110,8 +114,27 @@ public class ContentItemReaderWriterTest
NonLiteral ep = createExecutionPlan(em, "testChain");
writeExecutionNode(em, ep, "testEngine", true, null);
initExecutionMetadata(em, em, contentItem.getUri(), "testChain", false);
- ciWriter = new ContentItemWriter(null);
- ciReader = new ContentItemReader(null);
+ final Serializer serializer = new Serializer();
+ serializer.bindSerializingProvider(new JenaSerializerProvider());
+ serializer.bindSerializingProvider(new JsonLdSerializerProvider());
+ ciWriter = new ContentItemWriter(null) {
+ protected org.apache.clerezza.rdf.core.serializedform.Serializer getSerializer() {
+ return serializer;
+ };
+ };
+
+ final Parser parser = new Parser();
+ parser.bindParsingProvider(new JenaParserProvider());
+ ciReader = new ContentItemReader(null){
+ @Override
+ protected Parser getParser() {
+ return parser;
+ }
+ @Override
+ protected ContentItemFactory getContentItemFactory() {
+ return ciFactory;
+ }
+ };
}
/**
* @param out
Modified: incubator/stanbol/trunk/enhancer/ldpath/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/ldpath/pom.xml?rev=1311019&r1=1311018&r2=1311019&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/ldpath/pom.xml (original)
+++ incubator/stanbol/trunk/enhancer/ldpath/pom.xml Sun Apr 8 15:12:40 2012
@@ -106,10 +106,12 @@
<dependency>
<groupId>at.newmedialab.ldpath</groupId>
<artifactId>ldpath-api</artifactId>
+ <version>0.9.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>at.newmedialab.ldpath</groupId>
<artifactId>ldpath-core-bundle</artifactId>
+ <version>0.9.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.stanbol</groupId>
@@ -124,6 +126,11 @@
<!-- for tests -->
<dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.enhancer.core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
Modified: incubator/stanbol/trunk/enhancer/ldpath/src/main/java/org/apache/stanbol/enhancer/ldpath/function/ContentFunction.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/ldpath/src/main/java/org/apache/stanbol/enhancer/ldpath/function/ContentFunction.java?rev=1311019&r1=1311018&r2=1311019&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/ldpath/src/main/java/org/apache/stanbol/enhancer/ldpath/function/ContentFunction.java (original)
+++ incubator/stanbol/trunk/enhancer/ldpath/src/main/java/org/apache/stanbol/enhancer/ldpath/function/ContentFunction.java Sun Apr 8 15:12:40 2012
@@ -56,7 +56,7 @@ public class ContentFunction extends Con
}
@Override
- public Collection<Resource> apply(ContentItemBackend backend, Collection<Resource>... args) throws IllegalArgumentException {
+ public Collection<Resource> apply(ContentItemBackend backend, Resource context, Collection<Resource>... args) throws IllegalArgumentException {
ContentItem ci = ((ContentItemBackend)backend).getContentItem();
// Collection<Resource> contexts = args[0];
Set<String> mimeTypes;
Modified: incubator/stanbol/trunk/enhancer/ldpath/src/main/java/org/apache/stanbol/enhancer/ldpath/function/ContentItemFunction.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/ldpath/src/main/java/org/apache/stanbol/enhancer/ldpath/function/ContentItemFunction.java?rev=1311019&r1=1311018&r2=1311019&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/ldpath/src/main/java/org/apache/stanbol/enhancer/ldpath/function/ContentItemFunction.java (original)
+++ incubator/stanbol/trunk/enhancer/ldpath/src/main/java/org/apache/stanbol/enhancer/ldpath/function/ContentItemFunction.java Sun Apr 8 15:12:40 2012
@@ -44,10 +44,10 @@ public abstract class ContentItemFunctio
}
this.name = name;
}
-
- public final Collection<Resource> apply(RDFBackend<Resource> backend, Collection<Resource>... args) throws IllegalArgumentException {
+ @Override
+ public final Collection<Resource> apply(RDFBackend<Resource> backend, Resource context, Collection<Resource>... args) throws IllegalArgumentException {
if(backend instanceof ContentItemBackend){
- return apply((ContentItemBackend)backend, args);
+ return apply((ContentItemBackend)backend, context, args);
} else {
throw new IllegalArgumentException("This ContentFunction can only be " +
"used in combination with an RDFBackend of type '"+
@@ -56,7 +56,7 @@ public abstract class ContentItemFunctio
}
};
- public abstract Collection<Resource> apply(ContentItemBackend backend,Collection<Resource>... args);
+ public abstract Collection<Resource> apply(ContentItemBackend backend,Resource context,Collection<Resource>... args);
@Override
public String getPathExpression(RDFBackend<Resource> backend) {
Modified: incubator/stanbol/trunk/enhancer/ldpath/src/main/java/org/apache/stanbol/enhancer/ldpath/function/PathFunction.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/ldpath/src/main/java/org/apache/stanbol/enhancer/ldpath/function/PathFunction.java?rev=1311019&r1=1311018&r2=1311019&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/ldpath/src/main/java/org/apache/stanbol/enhancer/ldpath/function/PathFunction.java (original)
+++ incubator/stanbol/trunk/enhancer/ldpath/src/main/java/org/apache/stanbol/enhancer/ldpath/function/PathFunction.java Sun Apr 8 15:12:40 2012
@@ -17,9 +17,13 @@
package org.apache.stanbol.enhancer.ldpath.function;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import at.newmedialab.ldpath.api.backend.RDFBackend;
import at.newmedialab.ldpath.api.functions.SelectorFunction;
import at.newmedialab.ldpath.api.selectors.NodeSelector;
@@ -33,6 +37,8 @@ import at.newmedialab.ldpath.api.selecto
*/
public class PathFunction<Node> implements SelectorFunction<Node> {
+ private final static Logger log = LoggerFactory.getLogger(PathFunction.class);
+
private final String name;
private final NodeSelector<Node> selector;
@@ -56,15 +62,18 @@ public class PathFunction<Node> implemen
}
@Override
- public Collection<Node> apply(RDFBackend<Node> backend, Collection<Node>... args) throws IllegalArgumentException {
- if(args == null || args.length < 1 || args[0] == null || args[0].isEmpty()){
- throw new IllegalArgumentException("The 'fn:"+name+"' function " +
- "requires at least a single none empty parameter (the context). Use 'fn:" +
- name+"(.)' to execute it on the path context!");
+ public Collection<Node> apply(RDFBackend<Node> backend, Node context, Collection<Node>... args) throws IllegalArgumentException {
+ final Collection<Node> nodes;
+ if(args == null || args.length < 1 || args[0] == null){
+ nodes = Collections.singleton(context);
+ log.debug("no arguments - use context {}",context);
+ } else {
+ nodes = args[0];
+ log.debug("use parsed context {}",nodes);
}
Set<Node> selected = new HashSet<Node>();
- for(Node context : args[0]){
- selected.addAll(selector.select(backend, context));
+ for(Node node : nodes){
+ selected.addAll(selector.select(backend, node));
}
return selected;
}
Modified: incubator/stanbol/trunk/enhancer/ldpath/src/main/java/org/apache/stanbol/enhancer/ldpath/function/SuggestionFunction.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/ldpath/src/main/java/org/apache/stanbol/enhancer/ldpath/function/SuggestionFunction.java?rev=1311019&r1=1311018&r2=1311019&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/ldpath/src/main/java/org/apache/stanbol/enhancer/ldpath/function/SuggestionFunction.java (original)
+++ incubator/stanbol/trunk/enhancer/ldpath/src/main/java/org/apache/stanbol/enhancer/ldpath/function/SuggestionFunction.java Sun Apr 8 15:12:40 2012
@@ -91,13 +91,27 @@ public class SuggestionFunction implemen
}
@Override
- public Collection<Resource> apply(final RDFBackend<Resource> backend, Collection<Resource>... args) throws IllegalArgumentException {
- Integer limit = parseParamLimit(backend, args,1);
+ public Collection<Resource> apply(final RDFBackend<Resource> backend, Resource context,Collection<Resource>... args) throws IllegalArgumentException {
+ final Collection<Resource> contexts;
+ final int paramOffset;
+ if(args == null || args.length<1 || args[0] == null){
+ contexts = Collections.singleton(context);
+ paramOffset = 0;
+ } else if(args[0].isEmpty()){
+ return Collections.emptyList(); //empty context -> empty result
+ } else if(!backend.isLiteral(args[0].iterator().next())){
+ contexts = args[0]; //param[0] contains references -> use this as context
+ paramOffset = 1; //start parsing parameters at position 1
+ } else { //literal parameter at param index 0 ->
+ contexts = Collections.singleton(context); //use context
+ paramOffset = 0; //start parsing parameters at position 0
+ }
+ Integer limit = parseParamLimit(backend, args,paramOffset+0);
// final String processingMode = parseParamProcessingMode(backend, args,2);
- final int missingConfidenceMode = parseParamMissingConfidenceMode(backend, args,2);
+ final int missingConfidenceMode = parseParamMissingConfidenceMode(backend, args,paramOffset+1);
List<Resource> result = new ArrayList<Resource>();
// if(processingMode.equals(ANNOTATION_PROCESSING_MODE_UNION)){
- processAnnotations(backend, args[0], limit, missingConfidenceMode, result);
+ processAnnotations(backend, contexts, limit, missingConfidenceMode, result);
// } else {
// for(Resource context : args[0]){
// processAnnotations(backend, singleton(context),