Package org.apache.stanbol.enhancer.servicesapi

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


            includedContentPartList = new ArrayList<Map.Entry<UriRef,Blob>>();
            Set<String> ignoreContentPartUris = getIgnoredContentURIs(properties);
            nextContentPartEntry:
            for(Entry<UriRef,Blob> entry : getContentParts(ci,Blob.class).entrySet()){
                if(!ignoreContentPartUris.contains(entry.getKey().getUnicodeString())){
                    Blob blob = entry.getValue();
                    MediaType blobMediaType = MediaType.valueOf(blob.getMimeType());
                    for(MediaType included : includeMediaTypes) {
                        if(blobMediaType.isCompatible(included)){
                            includedContentPartList.add(entry);
                            continue nextContentPartEntry;
                        }
View Full Code Here


     */
    protected abstract Blob getBlobToTestMimetypeHandling(String mimeType);

    @Test
    public void testNullWildCard(){
        Blob blob;
        try {
            blob = getBlobToTestMimetypeHandling(null);
        } catch (IllegalArgumentException e) {
            //if no detection of the mimeType is supported this is expected
            return;
        }
        //if autodetection is supported, check that the mimetype is not null
        Assert.assertNotNull(blob.getMimeType());
        Assert.assertFalse(blob.getMimeType().isEmpty());
    }
View Full Code Here

        getBlobToTestMimetypeHandling("text/;charset=UTF-8");
    }
   
    @Test
    public void testMimeType(){
        Blob blob = getBlobToTestMimetypeHandling("text/plain;charset=UTF-8");
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
       
        blob = getBlobToTestMimetypeHandling("text/plain;charset=UTF-8;other=test");
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
        Assert.assertTrue(blob.getParameter().containsKey("other"));
        Assert.assertEquals("test", blob.getParameter().get("other"));
    }
View Full Code Here

                        id,content.getContentType());
                    contentItem = new InMemoryContentItem(id,
                        IOUtils.toByteArray(fis.openStream()),
                        fis.getContentType(), metadata);
                } else {
                    Blob blob = new InMemoryBlob(fis.openStream(), fis.getContentType());
                    UriRef contentPartId = null;
                    if(fis.getFieldName() != null && !fis.getFieldName().isEmpty()){
                        contentPartId = new UriRef(fis.getFieldName());
                    } else {
                        //generating a random ID might break metadata
View Full Code Here

        Assert.assertTrue(blob.getParameter().containsKey("other"));
        Assert.assertEquals("test", blob.getParameter().get("other"));
    }
    @Test
    public void testMultipleSeparators(){
        Blob blob = getBlobToTestMimetypeHandling("text/plain;;charset=UTF-8");
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
       
        blob = getBlobToTestMimetypeHandling("text/plain;charset=UTF-8;;other=test");
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
        Assert.assertTrue(blob.getParameter().containsKey("other"));
        Assert.assertEquals("test", blob.getParameter().get("other"));
    }
View Full Code Here

        Assert.assertTrue(blob.getParameter().containsKey("other"));
        Assert.assertEquals("test", blob.getParameter().get("other"));
    }
    @Test
    public void testIllegalFormatedParameter(){
        Blob blob = getBlobToTestMimetypeHandling("text/plain;=UTF-8");
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().isEmpty());
       
        blob = getBlobToTestMimetypeHandling("text/plain;charset=UTF-8;=illegal");
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertEquals(blob.getParameter().size(),1);
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));

        blob = getBlobToTestMimetypeHandling("text/plain;=illegal;charset=UTF-8");
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertEquals(blob.getParameter().size(),1);
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));

        blob = getBlobToTestMimetypeHandling("text/plain;charset=");
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().isEmpty());
        blob = getBlobToTestMimetypeHandling("text/plain;charset");
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().isEmpty());
       
        blob = getBlobToTestMimetypeHandling("text/plain;charset=UTF-8;test=");
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertEquals(blob.getParameter().size(),1);
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));

        blob = getBlobToTestMimetypeHandling("text/plain;charset=UTF-8;test");
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertEquals(blob.getParameter().size(),1);
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
   
        blob = getBlobToTestMimetypeHandling("text/plain;test;charset=UTF-8;");
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertEquals(blob.getParameter().size(),1);
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
    }
View Full Code Here

        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
    }
    @Test(expected=UnsupportedOperationException.class)
    public void testReadOnlyParameter(){
        Blob blob = getBlobToTestMimetypeHandling("text/plain;test;charset=UTF-8");
        blob.getParameter().put("test", "dummy");
    }
View Full Code Here

            do {
                try {
                    cpUri = ci.getPartUri(index);
                    index++;
                    try {
                        Blob blob = ci.getPart(cpUri, Blob.class);
                        if(mimeTypes.contains(blob.getMimeType().toLowerCase())){
                            return Collections.singletonMap(cpUri, blob)
                                    .entrySet().iterator().next();
                        } // else no match
                    } catch (ClassCastException e) {
                        // not a Blob -> ignore!
View Full Code Here

        assertFalse(engine.canEnhance(ci) == CANNOT_ENHANCE);
        engine.computeEnhancements(ci);
        Entry<UriRef,Blob> contentPart = ContentItemHelper.getBlob(ci,
            singleton("text/plain"));
        assertNotNull(contentPart);
        Blob plainTextBlob = contentPart.getValue();
        assertNotNull(plainTextBlob);
        assertContentRegexp(plainTextBlob,
            "The Apache Stanbol Enhancer",
            "The Stanbol enhancer can detect famous cities such as Paris and people such as Bob Marley.");
        //validate XHTML results
        contentPart = ContentItemHelper.getBlob(ci,
            singleton("application/xhtml+xml"));
        assertNotNull(contentPart);
        Blob xhtmlBlob = contentPart.getValue();
        assertNotNull(xhtmlBlob);
        assertContentRegexp(xhtmlBlob,
            "<html xmlns=\"http://www.w3.org/1999/xhtml\">",
            "<head>",
            "<meta name=",
View Full Code Here

        assertFalse(engine.canEnhance(ci) == CANNOT_ENHANCE);
        engine.computeEnhancements(ci);
        Entry<UriRef,Blob> contentPart = ContentItemHelper.getBlob(ci,
            singleton("text/plain"));
        assertNotNull(contentPart);
        Blob plainTextBlob = contentPart.getValue();
        assertNotNull(plainTextBlob);
        assertContentRegexp(plainTextBlob,
            "The Apache Stanbol Enhancer",
            "The Stanbol enhancer can detect famous cities ");       
        //validate XHTML results
        contentPart = ContentItemHelper.getBlob(ci,
            singleton("application/xhtml+xml"));
        assertNotNull(contentPart);
        Blob xhtmlBlob = contentPart.getValue();
        assertNotNull(xhtmlBlob);
        assertContentRegexp(xhtmlBlob,
            "<html xmlns=\"http://www.w3.org/1999/xhtml\">",
            "<head>",
            "<meta name=",
View Full Code Here

TOP

Related Classes of org.apache.stanbol.enhancer.servicesapi.Blob

Copyright © 2018 www.massapicom. 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.