Package com.lightcrafts.utils.xml

Examples of com.lightcrafts.utils.xml.XMLException


            if (intentName.equals(i.toString())) {
                intent = i;
            }
        }
        if (intent == null) {
            throw new XMLException("Invalid rendering intent: " + intentName);
        }
        if (root.hasAttribute(PpiTag)) {
            // ppi attribute added in LZN version 6
            pixelsPerInch = Integer.parseInt(root.getAttribute(PpiTag));
        }
        else {
            // arbitrary but sensible default, mostly backwards compatible
            pixelsPerInch = 300;
        }
        profile = null;
        XmlNode profileNode = null;
        try {
            profileNode = root.getChild(ProfileTag);
        }
        catch (XMLException e) {
            // OK, color profile is optional.
        }
        if (profileNode != null) {
            String profileName = profileNode.getAttribute(ProfileNameTag);
            String profilePath = profileNode.getAttribute(ProfilePathTag);
            profile = new ColorProfileInfo(profileName, profilePath);
        }
        XmlNode pageNode = root.getChild(PageTag);
        restorePageFormat(pageNode);

        XmlNode imageRectNode = root.getChild(ImageRectTag);
        try {
            double x = Double.valueOf(imageRectNode.getAttribute("x"));
            double y = Double.valueOf(imageRectNode.getAttribute("y"));
            double w = Double.valueOf(imageRectNode.getAttribute("w"));
            double h =
                Double.valueOf(imageRectNode.getAttribute("h"));
            imageRect = new Rectangle2D.Double(x, y, w, h);

            // The restored imageRect may not make sense with the current
            // imageWidth and imageHeight.
            // If the saved aspect ratio is far off, then we scaleToFit().
            // Otherwise we allow a little mismatch, to preserve the printed
            // image bounds.
            double restoredAspect =
                imageRect.getWidth() / imageRect.getHeight();
            double currentAspect = (imageWidth > 0 && imageHeight > 0) ?
                imageWidth / (double) imageHeight : restoredAspect;
            if (Math.abs(restoredAspect / currentAspect - 1) > 0.01) {
                scaleToFit();
            }
        }
        catch (NumberFormatException e) {
            throw new XMLException(
                "Can't interpret image bounds: " + e.getMessage()
            );
        }
    }
View Full Code Here


                x = Double.parseDouble(lrNode.getAttribute(Xtag));
                y = Double.parseDouble(lrNode.getAttribute(Ytag));
                lr = new Point2D.Double(x, y);
            }
            catch (NumberFormatException e) {
                throw new XMLException("Invalid crop coordinates", e);
            }
            bounds = new CropBounds(ul, ur, ll, lr);
        }
        catch (XMLException e1) {
            try {
                double angle = Double.parseDouble(node.getAttribute(AngleTag));

                Dimension size = engine.getNaturalSize();
                Rectangle2D imageBounds = new Rectangle2D.Double(0, 0, size.width, size.height);

                bounds = new CropBounds(imageBounds, angle);
                // bounds = new CropBounds(angle);
            }
            catch (XMLException e2) {
                throw new XMLException(
                    "No valid crop or rotate data: " +
                    e1.getMessage() + ", " + e2.getMessage()
                );
            }
        }
View Full Code Here

    {
        node = node.getChild( ExportOptionsTag );
        final String typeName = node.getAttribute( TypeTag );
        final ImageType type = ImageType.getImageTypeByName( typeName );
        if ( type == null ) {
            throw new XMLException( "Unrecognized image export type" );
        }
        final ImageExportOptions options = type.newExportOptions();
        options.restore( node );
        if ( node.hasAttribute( FileTag ) ) {
            options.m_exportFile = new File( node.getAttribute( FileTag ) );
View Full Code Here

               ImagingException
    {
        XmlNode root = doc.getRoot();
        int version = root.getVersion();
        if (version > SavedDocVersion) {
            throw new XMLException(LOCALE.get("FutureLznError"));
        }
        if (version < 0) {
            throw new XMLException(LOCALE.get("MissingLznVersionError"));
        }
        if (meta == null) {

            // Find the original image:
            XmlNode node = root.getChild(ImageTag);
            String path = node.getAttribute(ImagePathTag);
            File file = new File(path);
            if (! file.isFile()) {
                throw new MissingImageFileException(file);
            }
            // Override with a relative path, if one was defined:
            if (node.hasAttribute(ImageRelativePathTag)) {
                path = node.getAttribute(ImageRelativePathTag);
                File relativeFile = new File(path);
                if (relativeFile.isFile()) {
                    file = relativeFile;
                }
            }
            ImageInfo info = ImageInfo.getInstanceFor(file);
            try {
                meta = info.getMetadata();
            }
            catch (FileNotFoundException e) {
                throw new MissingImageFileException(file);
            }
        }
        this.meta = meta;

        // Enforce the saved original image orientation, which defines the
        // coordinate system used for regions and crop bounds:
        XmlNode imageNode = root.getChild(ImageTag);
        if (imageNode.hasAttribute(ImageOrientationTag)) {
            String value = imageNode.getAttribute(ImageOrientationTag);
            try {
                ImageOrientation oldOrientation =
                    ImageOrientation.getOrientationFor(Short.parseShort(value));
                ImageOrientation newOrientation = meta.getOrientation();
                if (oldOrientation != newOrientation) {
                    meta.setOrientation(oldOrientation);
                }
            }
            catch (NumberFormatException e) {
                throw new XMLException(
                    "Image orientation \"" + value + "\" is not a number", e
                );
            }
        }
        // Backwards compatibility: before XMP support, the convention in LZN
View Full Code Here

                        control = addGenericControl(type);
                        break;
                    }
                }
                if (control == null) {
                    throw new XMLException(
                        "Unrecognized GenericOperationType \"" + typeTag + "\""
                    );
                }
            }
            if (control != null) {
View Full Code Here

    void restore(XmlNode node) throws XMLException {
        XmlNode ptsNode = node.getChild(PointsTag);
        try {
            int s = Integer.parseInt(ptsNode.getAttribute(SizeTag));
            if (s != size) {
                throw new XMLException("Unsupported size change");
            }
            reset();
        }
        catch (NumberFormatException e) {
            throw new XMLException(
                "Not an integer: \"" + ptsNode.getAttribute(SizeTag) + "\"", e
            );
        }
        XmlNode[] ptNodes = ptsNode.getChildren(PointTag);
        for (XmlNode ptNode : ptNodes) {
            Integer key;
            Double value;
            try {
                key = Integer.valueOf(ptNode.getAttribute(XTag));
            }
            catch (NumberFormatException e) {
                throw new XMLException(
                    "Not an integer: \"" + ptNode.getAttribute(XTag) + "\"", e
                );
            }
            try {
                value = Double.valueOf(ptNode.getAttribute(YTag));
            }
            catch (NumberFormatException e) {
                throw new XMLException(
                    "Not a number: \"" + ptNode.getAttribute(YTag) + "\"", e
                );
            }
            try {
                setPoint(key, value);
            }
            catch (IllegalArgumentException e) {
                throw new XMLException(
                    "Invalid zone mapping: (" + key + ", " + value + ")"
                );
            }
        }
        notifyListenersChanged();
View Full Code Here

                        int value = Integer.parseInt(sliderNode.getAttribute(key));
                        slider.setSliderPosition(value);
                    }
                }
                catch (NumberFormatException e) {
                    throw new XMLException(
                        "Value at attribute \"" + key + "\" is not a number", e
                    );
                }
            }
        }
View Full Code Here

        final Node node = XMLUtil.getFirstChildOf(
            parent,
            new ElementFilter( ImageExportOptionXMLWriter.ExportOptionsTag )
        );
        if ( node == null )
            throw new XMLException( ImageExportOptionXMLWriter.ExportOptionsTag + "\" expected" );
        m_parent = (Element)node;
    }
View Full Code Here

    public ImageExportOptions readAll() throws IOException {
        final String typeName =
            m_parent.getAttribute( ImageExportOptionXMLWriter.TypeTag );
        final ImageType type = ImageType.getImageTypeByName( typeName );
        if ( type == null )
            throw new XMLException(
                "Unrecognized image export type: \"" + typeName + '"'
            );
        final ImageExportOptions options = type.newExportOptions();
        if ( m_parent.hasAttribute( ImageExportOptionXMLWriter.FileTag ) ) {
            final String exportFileName =
View Full Code Here

    public void applyTemplate(XmlNode node)
        throws XMLException
    {
        int version = node.getVersion();
        if (version > SavedDocVersion) {
            throw new XMLException(LOCALE.get("FutureTemplateError"));
        }
        if (version < 0) {
            throw new XMLException(LOCALE.get("MissingTemplateVersionError"));
        }
        // Ignore the scale factor under ScaleTag.

        XmlNode controlNode = node.getChild(ControlTag);
        editor.addControls(controlNode);
View Full Code Here

TOP

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

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.