Search in sources :

Example 1 with AttachResource

use of com.agiletec.plugins.jacms.aps.system.services.resource.model.AttachResource in project entando-core by entando.

the class ResourceManagerIntegrationTest method testLoadResource.

public void testLoadResource() throws Throwable {
    try {
        ResourceInterface resource = this._resourceManager.loadResource("44");
        assertTrue(resource instanceof ImageResource);
        assertTrue(resource.isMultiInstance());
        assertEquals(resource.getDescription(), "logo");
        assertEquals(resource.getCategories().size(), 1);
        resource = this._resourceManager.loadResource("7");
        assertTrue(resource instanceof AttachResource);
        assertFalse(resource.isMultiInstance());
        assertEquals(resource.getDescription(), "configurazione");
        assertEquals(resource.getCategories().size(), 0);
    } catch (Throwable t) {
        throw t;
    }
}
Also used : ImageResource(com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) AttachResource(com.agiletec.plugins.jacms.aps.system.services.resource.model.AttachResource)

Example 2 with AttachResource

use of com.agiletec.plugins.jacms.aps.system.services.resource.model.AttachResource in project entando-core by entando.

the class AttachAttribute method getIndexeableFieldValue.

@Override
public String getIndexeableFieldValue() {
    StringBuilder buffer = new StringBuilder();
    if (null != super.getIndexeableFieldValue()) {
        buffer.append(super.getIndexeableFieldValue());
    }
    String extraValue = null;
    ResourceInterface resource = this.getResource();
    if (resource != null) {
        InputStream is = ((AttachResource) resource).getResourceStream();
        if (null != is) {
            AutoDetectParser parser = new AutoDetectParser();
            BodyContentHandler handler = new BodyContentHandler(-1);
            Metadata metadata = new Metadata();
            try {
                parser.parse(is, handler, metadata);
                extraValue = handler.toString();
            } catch (Throwable t) {
                _logger.error("Error while processing the parsing", t);
            } finally {
                try {
                    is.close();
                } catch (IOException ex) {
                    _logger.error("Error closing stream", ex);
                }
            }
        }
    }
    if (null != extraValue) {
        buffer.append(" ").append(extraValue);
    }
    return buffer.toString();
}
Also used : BodyContentHandler(org.apache.tika.sax.BodyContentHandler) InputStream(java.io.InputStream) Metadata(org.apache.tika.metadata.Metadata) AutoDetectParser(org.apache.tika.parser.AutoDetectParser) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) IOException(java.io.IOException) AttachResource(com.agiletec.plugins.jacms.aps.system.services.resource.model.AttachResource)

Aggregations

AttachResource (com.agiletec.plugins.jacms.aps.system.services.resource.model.AttachResource)2 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)2 ImageResource (com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Metadata (org.apache.tika.metadata.Metadata)1 AutoDetectParser (org.apache.tika.parser.AutoDetectParser)1 BodyContentHandler (org.apache.tika.sax.BodyContentHandler)1