Package org.artofsolving.jodconverter.document

Examples of org.artofsolving.jodconverter.document.DocumentFormat


    private void readJsonArray(String source) throws JSONException {
        JSONArray array = new JSONArray(source);
        for (int i = 0; i < array.length(); i++) {
            JSONObject jsonFormat = array.getJSONObject(i);
            DocumentFormat format = new DocumentFormat();
            format.setName(jsonFormat.getString("name"));
            format.setExtension(jsonFormat.getString("extension"));
            format.setMediaType(jsonFormat.getString("mediaType"));
            if (jsonFormat.has("inputFamily")) {
                format.setInputFamily(DocumentFamily.valueOf(jsonFormat.getString("inputFamily")));
            }
            if (jsonFormat.has("loadProperties")) {
                format.setLoadProperties(toJavaMap(jsonFormat.getJSONObject("loadProperties")));
            }
            if (jsonFormat.has("storePropertiesByFamily")) {
                JSONObject jsonStorePropertiesByFamily = jsonFormat.getJSONObject("storePropertiesByFamily");
                for (String key : JSONObject.getNames(jsonStorePropertiesByFamily)) {
                    Map<String, ?> storeProperties = toJavaMap(jsonStorePropertiesByFamily.getJSONObject(key));
                    format.setStoreProperties(DocumentFamily.valueOf(key), storeProperties);
                }
            }
            addFormat(format);
        }
    }
View Full Code Here


    public static String getExtension(String fileName) {
        return FilenameUtils.getExtension(fileName);
    }

    public static String getExtensionFromMimeType(String mimeType) {
        DocumentFormat df = formatRegistry.getFormatByMediaType(mimeType);
        if (df == null) {
            return null;
        }
        return df.getExtension();
    }
View Full Code Here

        return icon != null ? icon : mappings.get("unknown");
    }

    public static String getFileIconFromMimetype(String mimeType) {
        DocumentFormat df = formatRegistry.getFormatByMediaType(mimeType);
        if (df == null) {
            return null;
        }
        Map<String, String> mappings = getFileExtensionIcons();
        if (mappings == null) {
            return "file";
        }

        String icon = mappings.get(df.getExtension());

        return icon != null ? icon : mappings.get("unknown");
    }
View Full Code Here

        // todo: use fileCleaningTracker
        return File.createTempFile("doc-converter", null);
    }

    public String getMimeType(String extension) {
        DocumentFormat df = formatRegistry.getFormatByExtension(extension);
        if (df == null) {
            return null;
        }
        return df.getMediaType();
    }
View Full Code Here

        }
        return df.getMediaType();
    }

    public String getExtension(String mimeType) {
        DocumentFormat df = formatRegistry.getFormatByMediaType(mimeType);
        if (df == null) {
            return null;
        }
        return df.getExtension();
    }
View Full Code Here

            return;
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Converting node " + nodeFact.getPath() + " into target MIME type '" + targetMimeType + "'");
        }
        DocumentFormat format = converterService.getFormatByMimeType(targetMimeType);
        if (format == null) {
            logger.warn("Unsupported target MIME type '" + targetMimeType + "'. Skip converting file "
                    + nodeFact.getPath());
            return;
        }

        InputStream is = null;
        try {
            JCRNodeWrapper node = nodeFact.getNode();
            if (node.isNodeType("nt:file")) {
                is = node.getFileContent().downloadFile();
                File temp = File.createTempFile("doc-converter-rule", null);
                FileOutputStream os = new FileOutputStream(temp);
                try {
                    converterService.convert(is, nodeFact.getMimeType(), os, targetMimeType);
                    os.close();

                    JCRNodeWrapper folder = node.getParent();
                    String newName = StringUtils.substringBeforeLast(node.getName(), ".") + "." + format.getExtension();

                    if (!overwriteIfExists) {
                        newName = JCRContentUtils.findAvailableNodeName(folder, newName);
                    }

                    FileInputStream convertedStream = new FileInputStream(temp);
                    try {
                        folder.uploadFile(newName, convertedStream, format.getMediaType());
                        logger.info("Converted node " + nodeFact.getPath() + " to type " + format.getMediaType());
                    } finally {
                        IOUtils.closeQuietly(convertedStream);
                    }
                } finally {
                    IOUtils.closeQuietly(os);
View Full Code Here

TOP

Related Classes of org.artofsolving.jodconverter.document.DocumentFormat

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.