Package org.apache.chemistry.opencmis.client.parser

Examples of org.apache.chemistry.opencmis.client.parser.MetadataParser


        this.properties = props;
    }
   
   
    public PropertyMapper getPropertyMapper(String contentType) {
        MetadataParser parser = getParser(contentType);
        return parser.getMapper();
    }
View Full Code Here


        MetadataParser parser = getParser(contentType);
        return parser.getMapper();
    }
   
    public MetadataParser getParser(String contentType) {
        MetadataParser parser = parserMap.get(contentType);
        if (null == parser) {
            // if not found try a more generic one
            String genericContentType = contentType.substring(0, contentType.indexOf('/')) + "/*";
            for (String key: parserMap.keySet()) {
                if (key.equals(genericContentType))
View Full Code Here

    }
   
    void createParsers() {
        String[] typeKeys = getTypeKeys();
        for (String typeKey : typeKeys) {
            MetadataParser parser = loadParserClass(typeKey);
            String contentType = properties.getProperty(PREFIX + "." + typeKey);
            if (null == contentType)
                throw new MapperException("Missing content type in properties: " + PREFIX + "." + contentType);
           
            PropertyMapper mapper = contentTypeMapperMap.get(typeKey);

            parser.initialize(mapper, contentType);
            String[] contentTypes = parser.getContentTypes();
            for (String ct : contentTypes)
                parserMap.put(ct, parser);
        }               
    }
View Full Code Here

            Tika tika = new Tika();    
            String mimeType = tika.detect(f);
            LOG.info("Detected MIME type: "+ mimeType);
           
            // extract metadata: first get a parser
            MetadataParser parser = CFG.getParser(mimeType);
            if (null == parser) {
                properties.put(PropertyIds.NAME, f.getName());
                properties.put(PropertyIds.OBJECT_TYPE_ID, CFG.getDefaultDocumentType());
            } else {
                parser.reset();
                PropertyMapper mapper = CFG.getPropertyMapper(mimeType);
                if (null == mapper)
                    throw new MapperException("Unknown mime type (no configuration): " + mimeType);
                String typeId = mapper.getMappedTypeId();
                if (null == typeId)
                    throw new MapperException("No CMIS type configured for mime type" + mimeType);
                TypeDefinition td = session.getTypeDefinition(typeId);
                if (null == td)
                    throw new MapperException("CMIS type " + typeId + " does not exist on server.");

                LOG.info("Detected MIME type: "+ mimeType + " is mapped to CMIS type id: " + td.getId());
                parser.extractMetadata(f, td);
                properties = parser.getCmisProperties();
            }
                       
            // check if there is an overridden content type configured
            int posLastDot = f.getName().indexOf('.');
            String ext = posLastDot < 0 ? null : f.getName().substring(posLastDot+1, f.getName().length());
View Full Code Here

            Tika tika = new Tika();    
            String mimeType = tika.detect(f);
            LOG.info("Detected MIME type: "+ mimeType);
           
            // extract metadata: first get a parser
            MetadataParser parser = CFG.getParser(mimeType);
            if (null == parser) {
                LOG.warn("Unknown content type " + mimeType + " no metadata found, listing all tags found in file.");
                MetadataParserTika mpt = new MetadataParserTika();
                mpt.listMetadata(f);
            } else {
                PropertyMapper mapper = CFG.getPropertyMapper(mimeType);
                if (null == mapper)
                    throw new MapperException("Unknown mime type (no configuration): " + mimeType);
                String typeId = mapper.getMappedTypeId();
                if (null == typeId)
                    throw new MapperException("No CMIS type configured for mime type" + mimeType);
               
                // Session available? if yes do conversion
                TypeDefinition td = null;
                if (null!= session) {
                    session.getTypeDefinition(typeId);
                    if (null == td)
                        throw new MapperException("CMIS type " + typeId + " does not exist on server.");
                }
                LOG.info("Detected MIME type: "+ mimeType + " is mapped to CMIS type id: " + td.getId());
               
                parser.extractMetadata(f, td);
                Map<String, Object> properties = parser.getCmisProperties();
                for (String key : properties.keySet()) {
                    LOG.info("Found metadata tag " + key + "mapped to " + properties.get(key));
                }
            }                       
        } catch (Exception e) {
View Full Code Here

    @Test
    public void testParserMap() {
        Configurator cfg = new Configurator(properties);
        cfg.buildMapperMap();
        cfg.createParsers();
        MetadataParser parser = cfg.getParser("image/jpeg");
        assertNotNull(parser);
        assertEquals(MetadataParserExif.class, parser.getClass());
       
        parser = cfg.getParser("audio/mp3");
        assertNotNull(parser);
        assertEquals(MetadataParserTika.class, parser.getClass());
    }
View Full Code Here

TOP

Related Classes of org.apache.chemistry.opencmis.client.parser.MetadataParser

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.