Package org.apache.marmotta.platform.core.api.content

Examples of org.apache.marmotta.platform.core.api.content.ContentReader


            String writerClass = configurationService.getStringConfiguration("content."+configName+".writer");
            String patternStr  = configurationService.getStringConfiguration("content."+configName+".pattern");
            String enabledStr  = configurationService.getStringConfiguration("content."+configName+".enabled");

            if(Boolean.parseBoolean(enabledStr)) {
                ContentReader reader = null;
                ContentWriter writer = null;
                Pattern pattern = null;
                if(readerClass != null) {
                    for(ContentReader r : readers) {
                        if(r.getClass().getCanonicalName().startsWith(readerClass)) {
                            reader = r;
                            break;
                        }
                    }
                }

                if(writerClass != null) {
                    for(ContentWriter w : writers) {
                        if(w.getClass().getCanonicalName().startsWith(writerClass)) {
                            writer = w;
                            break;
                        }
                    }
                }

                try {
                    pattern = Pattern.compile(patternStr);
                } catch(Exception ex) {
                    log.warn("pattern {} is not a valid regular expression; disabling reader/writer {} (message was {})", patternStr,configName,ex.getMessage());
                    continue;
                }

                if(pattern != null && reader != null) {
                    readerMap.put(pattern,reader);
                    log.info("enabled content reader '{}' for pattern {}",reader.getName(), pattern);
                }
                if(pattern != null && writer != null) {
                    writerMap.put(pattern,writer);
                    log.info("enabled content writer '{}' for pattern {}", writer.getName(), pattern);
                }
View Full Code Here


    @Override
    public byte[] getContentData(Resource resource, String mimetype) {
        // iterate over all possible writers; if the pattern matches, try to store the content and return
        for(Pattern p : readerMap.keySet()) {
            if(p.matcher(resource.toString()).matches()) {
                ContentReader reader = readerMap.get(p);
                log.debug("reading content for resource {} using reader {}",resource,reader.getName());
                try {
                    return reader.getContentData(resource, mimetype);
                } catch(IOException ex) {
                    log.error("could not read content, reader threw an IO Exception",ex);
                    return null;
                }
            }
View Full Code Here

    @Override
    public InputStream getContentStream(Resource resource, String mimetype) throws IOException {
        // iterate over all possible writers; if the pattern matches, try to store the content and return
        for(Pattern p : readerMap.keySet()) {
            if(p.matcher(resource.toString()).matches()) {
                ContentReader reader = readerMap.get(p);
                log.debug("reading content for resource {} using reader {}",resource,reader.getName());
                try {
                    return reader.getContentStream(resource, mimetype);
                } catch(IOException ex) {
                    log.error("could not read content for resource {}, reader threw an IO Exception (message: {})",resource,ex.getMessage());
                    return null;
                }
            }
View Full Code Here

    @Override
    public boolean hasContent(Resource resource, String mimetype) {
        // iterate over all possible writers; if the pattern matches, try to store the content and return
        for(Pattern p : readerMap.keySet()) {
            if(p.matcher(resource.toString()).matches()) {
                ContentReader reader = readerMap.get(p);
                return reader.hasContent(resource, mimetype);
            }
        }
        return false;
    }
View Full Code Here

    @Override
    public String getContentType(Resource resource) {
        // iterate over all possible writers; if the pattern matches, try to store the content and return
        for(Pattern p : readerMap.keySet()) {
            if(p.matcher(resource.stringValue()).matches()) {
                ContentReader reader = readerMap.get(p);
                return reader.getContentType(resource);
            }
        }
        return null;
    }
View Full Code Here

    @Override
    public long getContentLength(Resource resource, String mimetype) {
        // iterate over all possible writers; if the pattern matches, try to store the content and return
        for(Pattern p : readerMap.keySet()) {
            if(p.matcher(resource.toString()).matches()) {
                ContentReader reader = readerMap.get(p);
                return reader.getContentLength(resource,mimetype);
            }
        }
        return 0;
    }
View Full Code Here

TOP

Related Classes of org.apache.marmotta.platform.core.api.content.ContentReader

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.