Examples of ContentSource


Examples of com.marklogic.xcc.ContentSource

        }

        XdmNode queryDocument = source.read();
        String queryString = queryDocument.getStringValue();

        ContentSource contentSource;

        try {
            if ("".equals(contentBase)) {
                contentSource = ContentSourceFactory.newContentSource(host, port, user, password);
            } else {
                contentSource = ContentSourceFactory.newContentSource(host, port, user, password, contentBase);
            }
        } catch (Exception e) {
            throw new XProcException(e);
        }

        if ("basic".equals(getOption(_auth_method, ""))) {
            contentSource.setAuthenticationPreemptive(true);
        }

        Session session;

        try {
            session = contentSource.newSession ();
            Request request = session.newAdhocQuery (queryString);

            for (QName name : params.keySet()) {
                XSString value = ValueFactory.newXSString (params.get(name));
                XName xname = new XName(name.getNamespaceURI(), name.getLocalName());
View Full Code Here

Examples of org.apache.lucene.benchmark.byTask.feeds.ContentSource

    properties.setProperty("docs.file", wikipedia.getAbsolutePath());
    properties.setProperty("content.source.forever", "false");
    properties.setProperty("keep.image.only.docs", String.valueOf(keepImageOnlyDocs));
    Config config = new Config(properties);

    ContentSource source = new EnwikiContentSource();
    source.setConfig(config);
   
    DocMaker docMaker = new DocMaker();
    docMaker.setConfig(config, source);
    docMaker.resetInputs();
    if (wikipedia.exists()) {
View Full Code Here

Examples of org.apache.stanbol.enhancer.servicesapi.ContentSource

    @Test
    public void testString() throws IOException{
        String test = "Exámplê";

        //first via a StringSource
        ContentSource cs = new StringSource(test);
        Blob blob = createBlob(cs);
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals(UTF8.name(), blob.getParameter().get("charset"));
View Full Code Here

Examples of org.apache.stanbol.enhancer.servicesapi.ContentSource

    @Test
    public void testStringWithCustomCharset() throws IOException{
        String test = "Exámplê";
        Charset ISO8859_4 = Charset.forName("ISO-8859-4");
        //first via a StringSource
        ContentSource cs = new StringSource(test,ISO8859_4,"text/plain");
        Blob blob = createBlob(cs);
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals(ISO8859_4.name(), blob.getParameter().get("charset"));
        //2nd via a ByteArray
View Full Code Here

Examples of org.apache.stanbol.enhancer.servicesapi.ContentSource

        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());
    }
View Full Code Here

Examples of org.apache.stanbol.enhancer.servicesapi.ContentSource

        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"));
    }
View Full Code Here

Examples of org.apache.stanbol.enhancer.servicesapi.ContentSource

        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());
       
    }
View Full Code Here

Examples of org.apache.stanbol.enhancer.servicesapi.ContentSource

       
    }

    @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());
    }
View Full Code Here

Examples of org.apache.stanbol.enhancer.servicesapi.ContentSource

    @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);
    }
View Full Code Here

Examples of org.apache.stanbol.enhancer.servicesapi.ContentSource

    /*
     * 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);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.