Examples of XmlDocument


Examples of com.lightcrafts.utils.xml.XmlDocument

        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

Examples of com.lightcrafts.utils.xml.XmlDocument

            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

Examples of com.lightcrafts.utils.xml.XmlDocument

        }
        // Loop until a unique name is selected or the dialog is cancelled:
        boolean done = false;
        TemplateKey key;
        do {
            XmlDocument xml = new XmlDocument("Template")// See Document()
            XmlNode root = xml.getRoot();
            doc.saveTemplate(root);

            SaveTemplateDialog dialog = new SaveTemplateDialog();
            ImageMetadata meta = doc.getMetadata();
            key = dialog.showDialog(meta, xml, namespace, frame);
            if (key == null) {
                // Dialog was disposed, or the user cancelled.
                return null;
            }
            // First check if a template with this name already exists:
            XmlDocument conflict = null;
            try {
                conflict = TemplateDatabase.getTemplateDocument(key);
            }
            catch (TemplateDatabase.TemplateException e) {
                // Interpret as no preexisting template with this name.
View Full Code Here

Examples of com.lightcrafts.utils.xml.XmlDocument

        Document doc = frame.getDocument();
        if (doc == null) {
            return;
        }
        try {
            XmlDocument template = TemplateDatabase.getTemplateDocument(key);
            if (template != null) {
                XmlNode root = template.getRoot();
                doc.applyTemplate(root);
            }
            else {
                showError(
                    LOCALE.get("TemplateNameError", key.toString()), null, frame
View Full Code Here

Examples of com.lightcrafts.utils.xml.XmlDocument

     * Apply the named template from TemplateDocuments to the File[].
     */
    public static void applyTemplate(
        ComboFrame frame, File[] files, TemplateKey key
    ) {
        XmlDocument template;
        try {
            template = TemplateDatabase.getTemplateDocument(key);
        }
        catch (TemplateDatabase.TemplateException e) {
            showError(
View Full Code Here

Examples of com.lightcrafts.utils.xml.XmlDocument

        conf.name = "";
        conf.export = (ImageFileExportOptions)
            SaveOptions.getExportOptions(SaveOptions.getDefaultSaveOptions());

        try {
            XmlDocument template = interp.xml;
            BatchProcessor.process(frame, files, template, conf);
        }
        catch (RuntimeException e) {
            showError(
                "An error occurred during batch processing.", e, frame
View Full Code Here

Examples of com.lightcrafts.utils.xml.XmlDocument

        if (LastSaveOptions != null) {
            // We're remembering the whole SaveOptions object, but
            // SaveOptions.getDefaultSaveOptions() is the authoritative
            // reposity for sticky options.  The LastSaveOptions is only
            // used to remember the recent folder.
            XmlDocument doc = new XmlDocument(SaveTag);
            LastSaveOptions.save(doc.getRoot());
            saveXmlPrefs(SaveTag, doc);
        }
        if (LastPrintLayout != null) {
            XmlDocument doc = new XmlDocument(PrintTag);
            LastPrintLayout.save(doc.getRoot());
            saveXmlPrefs(PrintTag, doc);
        }
        if (LastExportOptions != null) {
            XmlDocument doc = new XmlDocument(ExportTag);
            LastExportOptions.write(doc.getRoot());
            saveXmlPrefs(ExportTag, doc);
        }
        try {
            prefs.sync();
        }
View Full Code Here

Examples of com.lightcrafts.utils.xml.XmlDocument

            path = prefs.get(OpenTag, null);
            if (path != null) {
                LastOpenPath = new File(path);
            }
            // Restore default save options:
            XmlDocument doc;
            doc = restoreXmlPrefs(SaveTag);
            if (doc != null) {
                try {
                    LastSaveOptions = SaveOptions.restore(doc.getRoot());
                }
                catch (XMLException e) {
                    System.err.println(
                        "Malformed save preferences: " + e.getMessage()
                    );
                    LastSaveOptions = null;
                }
            }
            // Restore default print settings:
            doc = restoreXmlPrefs(PrintTag);
            if (doc != null) {
                try {
                    LastPrintLayout = new PrintLayoutModel(0, 0);
                    LastPrintLayout.restore(doc.getRoot());
                }
                catch (XMLException e) {
                    System.err.println(
                        "Malformed print preferences: " + e.getMessage()
                    );
                    LastPrintLayout = null;
                }
            }
            // Restore default export options:
            doc = restoreXmlPrefs(ExportTag);
            if (doc != null) {
                try {
                    LastExportOptions = ImageExportOptions.read(doc.getRoot());
                }
                catch (XMLException e) {
                    System.err.println(
                        "Malformed export preferences: " + e.getMessage()
                    );
View Full Code Here

Examples of com.lightcrafts.utils.xml.XmlDocument

        if (text != null) {
            try {
                InputStream in = new ByteArrayInputStream(
                    text.getBytes("UTF-8")
                );
                XmlDocument doc = new XmlDocument(in);
                return doc;
            }
            catch (Exception e) {   // IOException, XMLException
                System.err.print("Error reading preferences: ");
                System.err.print(e.getClass().getName() + " ");
View Full Code Here

Examples of com.lightcrafts.utils.xml.XmlDocument

        }

        try {
            final Document lznDoc = getLZNDocumentImpl( imageInfo );
            if ( lznDoc != null ) {
                final XmlDocument xmlDoc =
                    new XmlDocument( lznDoc.getDocumentElement() );
                // The original image may be in the same file,
                // or referenced through a path pointer:
                final XmlNode root = xmlDoc.getRoot();
                // (tag copied from ui.editor.Document)
                final XmlNode imageNode = root.getChild( "Image" );
                // (tag written in export())
                if ( imageNode.hasAttribute( "self" ) )
                    return MultipageTIFFImageType.INSTANCE;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.