Package com.lightcrafts.utils.xml

Examples of com.lightcrafts.utils.xml.XmlDocument


        Error = false;

        // This procedure should parallel Application.open():
        try {
            InputStream in = new FileInputStream(file);
            XmlDocument xmlDoc;
            try {
                xmlDoc = new XmlDocument(in);
            }
            catch (IOException e) {
                // Maybe it's an image:
                try {
                    ImageInfo info = ImageInfo.getInstanceFor(file);
View Full Code Here


            Document doc = null;
            try {
                // First try as a saved-document:
                InputStream in = new FileInputStream(file);
                XmlDocument xmlDoc = null;
                try {
                    xmlDoc = new XmlDocument(in);
                }
                catch (IOException e) {
                    // If xmlDoc is null, we fall back to image-import.
                }
                if (xmlDoc != null) {
View Full Code Here

     * cache node, and interpreting the cache contents as image data.
     */
    public PlanarImage getImage( ImageInfo imageInfo, ProgressThread thread )
        throws BadImageFileException, IOException, UserCanceledException
    {
        final XmlDocument xml = getDocument( imageInfo );
        final XmlNode cache = getCacheNode( xml );
        final byte[] bytes = cache.getData();
        if (bytes == null) {
            // no cache data in the file
            throw new BadImageFileException( imageInfo.getFile() );
View Full Code Here

                CS_RGB,
                90
            );
            writer.putImage( image );

            final XmlDocument xml = getDocument( imageInfo );
            final XmlNode cache = getCacheNode( xml );
            cache.setData( buf.toByteArray() );

            final OutputStream out =
                new FileOutputStream( imageInfo.getFile() );
            try {
                xml.write( out );
            }
            finally {
                out.close();
            }
        }
View Full Code Here

     */
    private static XmlDocument getDocument( ImageInfo info )
        throws IOException
    {
        final InputStream in = new FileInputStream( info.getFile() );
        return new XmlDocument( in );
    }
View Full Code Here

        TemplateNamespaceTreeNode parent, TemplateKey key
    ) throws TemplateDatabase.TemplateException, XMLException {
        this.key = key;
        this.parent = parent;
        this.key = key;
        XmlDocument xml = TemplateDatabase.getTemplateDocument(key);
        XmlNode root = xml.getRoot();
        // Tag name copied from Document.ControlTag:
        node = root.getChild("Controls");
    }
View Full Code Here

        }
        return keys;
    }

    private void importTemplate(File file) {
        XmlDocument doc;
        try {
            InputStream in = new FileInputStream(file);
            doc = new XmlDocument(in);
        }
        catch (IOException e) {
            showError(
                LOCALE.get("TemplateImportError", file.getName()), e
            );
View Full Code Here

        if (dir.isFile()) {
            dir = dir.getParentFile();
        }
        List<TemplateKey> keys = getSelectedTemplateKeys();
        for (TemplateKey key : keys) {
            XmlDocument doc;
            try {
                doc = TemplateDatabase.getTemplateDocument(key);
            }
            catch (TemplateDatabase.TemplateException e) {
                showError(
                    LOCALE.get("TemplateAccessSpecificError", key.toString()), e
                );
                continue;
            }
            File file = new File(dir, key + ".lzt");
            try {
                OutputStream out = new FileOutputStream(file);
                doc.write(out);
                out.close();
            }
            catch (IOException e) {
                showError(
                    LOCALE.get(
View Full Code Here

        DocumentReader.Interpretation interp = DocumentReader.read(file);

        // If it's somehow a saved document:
        if (interp != null) {

            XmlDocument xml = interp.xml;
            File imageFile = interp.imageFile;
            ImageInfo info = interp.info;

            if (imageFile == null) {
                // This is a symptom of a template file.
                if (file.getName().endsWith(".lzt")) {
                    int option = Env.getAlertDialog().showAlert(
                        frame,
                        LOCALE.get("TemplateQuestionMajor"),
                        LOCALE.get("TemplateQuestionMinor"),
                        AlertDialog.WARNING_ALERT,
                        LOCALE.get("TemplateImportOption"),
                        LOCALE.get("TemplateOpenOption"),
                        LOCALE.get("TemplateCancelOption")
                    );
                    if (option == 0) {
                        try {
                            InputStream in = new FileInputStream(file);
                            XmlDocument template = new XmlDocument(in);
                            TemplateKey key = TemplateKey.importKey(file);
                            TemplateDatabase.addTemplateDocument(
                                template, key, true
                            );
                            TemplateList.showDialog(frame);
                        }
                        catch (Throwable t) {
                            showError(
                                LOCALE.get(
                                    "TemplateImportError", file.getName()
                                ),
                                t, frame
                            );
                        }
                        return null;
                    }
                    else if (option == 2) {
                        return null;
                    }
                    // option == 1, let the initialization continue...
                }
                // LightweightDocument couldn't figure out the original image
                // path, so let Document throw its MissingImageFileException:
                doc = new Document(xml, null, info, cancel);
            }
            else {
                // Check for a missing image file:
                boolean hunted = false;
                if (! imageFile.exists()) {
                    // Isolate the image file name, admitting both unix and
                    // windows path syntax:
                    String imageFileName =
                        imageFile.getAbsolutePath().replaceAll(
                            ".*[/\\\\]", ""
                        );
                    // Try the DocumentDatabase:
                    File[] files =
                        DocumentDatabase.findImageFiles(imageFileName);

                    // Maybe check the Document file's directory directly,
                    // since DocumentDatabase is sometimes disabled:
                    if (files.length == 0) {
                        File docDir = file.getParentFile();
                        File altImageFile = new File(docDir, imageFileName);
                        if (altImageFile.isFile()) {
                            files = new File[1];
                            files[0] = altImageFile;
                        }
                    }
                    imageFile = DocumentImageSelector.chooseImageFile(
                        file, imageFile, files, LastOpenPath, frame
                    );
                    if (imageFile == null) {
                        // User cancelled.
                        return null;
                    }
                    hunted = true;
                }
                ImageInfo imageFileInfo = ImageInfo.getInstanceFor(imageFile);
                ImageMetadata meta = imageFileInfo.getMetadata();

                // Read the saved document:
                doc = new Document(xml, meta, info, cancel);
                if (hunted) {
                    doc.markDirty();
                }
            }
            DocumentDatabase.addDocumentFile(file);
        }
        else {
            // Maybe it's an image:
            ImageInfo info = ImageInfo.getInstanceFor(file);
            ImageMetadata meta = info.getMetadata();
            ImageType type = info.getImageType();

            // Maybe set up a template with default tools:
            XmlDocument xml = null;

            // First look for default settings in the user-defined templates:
            TemplateKey template = TemplateDatabase.getDefaultTemplate(meta);
            if (template != null) {
                try {
View Full Code Here

            ImageInfo info = ImageInfo.getInstanceFor(file);
            ImageMetadata meta = info.getMetadata();
            ImageType type = info.getImageType();

            // Maybe set up a template with default tools:
            XmlDocument xml = null;

            // First look for default settings in the user-defined templates:
            TemplateKey template = TemplateDatabase.getDefaultTemplate(meta);
            if (template != null) {
                try {
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.