Package com.lightcrafts.utils.xml

Examples of com.lightcrafts.utils.xml.XmlDocument


     * <p>
     * It is possible that LZN data exists but no image file can be found.
     * This is typical in "LZT" (template) files, for instance.
     */
    public static Interpretation read(File file) {
        XmlDocument xmlDoc = null;
        File imageFile = null;

        ImageInfo info = ImageInfo.getInstanceFor(file);
        ImageType type;
        try {
            type = info.getImageType();
        }
        catch (IOException e) {
            return null;
        }
        catch (LightCraftsException e) {
            if (file.getName().endsWith(".lzt")) {
                // This is a symptom of a template file, which does have an
                // Interpretation.  So we continue.
                type = LZNImageType.INSTANCE;
            }
            else {
                return null;
            }
        }
        if (type == LZNImageType.INSTANCE) {
            try {
                InputStream in = new FileInputStream(file);
                xmlDoc = new XmlDocument(in);
                LightweightDocument lwDoc = new LightweightDocument(file);
                imageFile = lwDoc.getImageFile();
            }
            catch (IOException e) {
                // Fall back to the embedded document test.
            }
        }
        // Second try as an image with embedded document metadata:
        if (xmlDoc == null) {
            try {
                if (type instanceof LZNDocumentProvider) {
                    final LZNDocumentProvider p = (LZNDocumentProvider)type;
                    Document lznDoc = p.getLZNDocument(info);
                    if (lznDoc != null) {
                        xmlDoc = new XmlDocument(lznDoc.getDocumentElement());
                        if (xmlDoc != null) {
                            // The original image may be in the same file,
                            // or referenced through a path pointer:
                            XmlNode root = xmlDoc.getRoot();
                            // (tag copied from ui.editor.Document)
                            XmlNode imageNode = root.getChild("Image");
                            // (tag written in export())
                            if ( imageNode.hasAttribute("self")) {
                                imageFile = file;
View Full Code Here


        String key = getPresetsKey();
        String text = Prefs.get(key, "");
        try {
            ByteArrayInputStream in =
                new ByteArrayInputStream(text.getBytes("UTF-8"));
            return new XmlDocument(in);
        }
        catch (Exception e) {   // IOException or XMLException
            return null;
        }
    }
View Full Code Here

    }

    // Get a Template that matches the original Template with unsselected tools
    // omitted.
    XmlDocument getModifiedTemplate() {
        XmlDocument clone = new XmlDocument(xml);
        try {
            TemplateJig jig = new TemplateJig(clone);
            for (int n=checks.length-1; n>=0; n--) {
                JCheckBox check = checks[n];
                if (! check.isSelected()) {
                    jig.removeTool(n);
                }
            }
        }
        catch (XMLException e) {
            // Assume no modifications
            return new XmlDocument(xml);
        }
        return clone;
    }
View Full Code Here

        }
        return clone;
    }

    XmlDocument getOriginalTemplate() {
        return new XmlDocument(xml);
    }
View Full Code Here

    XmlDocument getModifiedTemplate() {
        if (selector != null) {
            return selector.getModifiedTemplate();
        }
        else {
            return new XmlDocument(originalTemplate);
        }
    }
View Full Code Here

    }

    public static void main(String[] args) throws Exception {
        UIManager.setLookAndFeel(Platform.getPlatform().getLookAndFeel());

        XmlDocument doc = new XmlDocument(
            new FileInputStream(
                "/Users/anton/test/1/test.lzn"
            )
        );
        ImageInfo info = ImageInfo.getInstanceFor(
View Full Code Here

        if ( m_originalImageFile == null ) {
            final ImageType t = getImageType();
            if ( t instanceof LZNDocumentProvider ) {
                final Document lznDoc =
                    ((LZNDocumentProvider)t).getLZNDocument( this );
                final XmlDocument xmlDocument = new XmlDocument( lznDoc );
                final LightweightDocument lwDoc =
                    new LightweightDocument( m_imageFile, xmlDocument );
                final File originalFile = lwDoc.getImageFile();
                if ( !m_imageFile.equals( originalFile ) )
                    m_originalImageFile = originalFile;
View Full Code Here

        dispose();
    }

    public static void main(String[] args) throws Exception {
        InputStream in = new FileInputStream(args[0]);
        XmlDocument xml = new XmlDocument(in);
        Document doc = new Document(xml, null);
        RenderedImage image = doc.engine.getRendering(new Dimension(100, 100));
        ImageIO.write(image, "jpeg", new File("out.jpg"));
    }
View Full Code Here

        PrintWriter printer = new PrintWriter(out);
        printer.println("batch name: " + name);
        printer.println("output folder: " + directory.getAbsolutePath());
        printer.println("export options:");
        printer.flush();
        XmlDocument doc = new XmlDocument("Export");
        XmlNode root = doc.getRoot();
        export.write(root);
        try {
            doc.write(out);
        }
        catch (IOException e) {
            e.printStackTrace(printer);
        }
    }
View Full Code Here

        String path = directory.getAbsolutePath();
        Prefs.put(DirectoryKey + context, path);

        try {
            XmlDocument doc = new XmlDocument(ExportKey);
            export.write(doc.getRoot());
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            doc.write(out);
            out.close();
            String text = out.toString("UTF-8");
            Prefs.put(ExportKey + context, text);
        }
        catch (IOException e) {
View Full Code Here

TOP

Related Classes of com.lightcrafts.utils.xml.XmlDocument

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.