protected FDFAnnotation()

in pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotation.java [130:314]


    protected FDFAnnotation(Element element) throws IOException
    {
        this();

        String page = element.getAttribute("page");
        if (page == null || page.isEmpty())
        {
            throw new IOException("Error: missing required attribute 'page'");
        }
        setPage(Integer.parseInt(page));

        String color = element.getAttribute("color");
        if (color != null && color.length() == 7 && color.charAt(0) == '#')
        {
            int colorValue = Integer.parseInt(color.substring(1, 7), 16);
            setColor(new Color(colorValue));
        }

        setDate(element.getAttribute("date"));

        String flags = element.getAttribute("flags");
        if (flags != null)
        {
            String[] flagTokens = flags.split(",");
            for (String flagToken : flagTokens)
            {
                switch (flagToken)
                {
                    case "invisible":
                        setInvisible(true);
                        break;
                    case "hidden":
                        setHidden(true);
                        break;
                    case "print":
                        setPrinted(true);
                        break;
                    case "nozoom":
                        setNoZoom(true);
                        break;
                    case "norotate":
                        setNoRotate(true);
                        break;
                    case "noview":
                        setNoView(true);
                        break;
                    case "readonly":
                        setReadOnly(true);
                        break;
                    case "locked":
                        setLocked(true);
                        break;
                    case "togglenoview":
                        setToggleNoView(true);
                        break;
                    default:
                        break;
                }
            }
        }

        setName(element.getAttribute("name"));

        String rect = element.getAttribute("rect");
        if (rect == null)
        {
            throw new IOException("Error: missing attribute 'rect'");
        }
        String[] rectValues = rect.split(",");
        if (rectValues.length != 4)
        {
            throw new IOException("Error: wrong amount of numbers in attribute 'rect'");
        }
        float[] values = new float[4];
        for (int i = 0; i < 4; i++)
        {
            values[i] = Float.parseFloat(rectValues[i]);
        }
        setRectangle(new PDRectangle(COSArray.of(values)));

        setTitle(element.getAttribute("title"));

        /*
         * Set the markup annotation attributes
         */
        setCreationDate(DateConverter.toCalendar(element.getAttribute("creationdate")));
        String opac = element.getAttribute("opacity");
        if (opac != null && !opac.isEmpty())
        {
            setOpacity(Float.parseFloat(opac));
        }
        setSubject(element.getAttribute("subject"));

        String intent = element.getAttribute("intent");
        if (intent.isEmpty())
        {
            // not conforming to spec, but qoppa produces it and Adobe accepts it
            intent = element.getAttribute("IT");
        }
        if (!intent.isEmpty())
        {
            setIntent(intent);
        }

        XPath xpath = XPathFactory.newInstance().newXPath();
        try
        {
            setContents(xpath.evaluate("contents[1]", element));
        }
        catch (XPathExpressionException e)
        {
            LOG.debug("Error while evaluating XPath expression for richtext contents", e);
        }

        try
        {
            Node richContents = (Node) xpath.evaluate("contents-richtext[1]", element,
                    XPathConstants.NODE);
            if (richContents != null)
            {
                setRichContents(richContentsToString(richContents, true));
                setContents(richContents.getTextContent().trim());
            }
        }
        catch (XPathExpressionException e)
        {
            LOG.debug("Error while evaluating XPath expression for richtext contents", e);
        }

        PDBorderStyleDictionary borderStyle = new PDBorderStyleDictionary();
        String width = element.getAttribute("width");
        if (width != null && !width.isEmpty())
        {
            borderStyle.setWidth(Float.parseFloat(width));
        }
        if (borderStyle.getWidth() > 0)
        {
            String style = element.getAttribute("style");
            if (style != null && !style.isEmpty())
            {
                switch (style)
                {
                    case "dash":
                        borderStyle.setStyle(PDBorderStyleDictionary.STYLE_DASHED);
                        break;
                    case "bevelled":
                        borderStyle.setStyle(PDBorderStyleDictionary.STYLE_BEVELED);
                        break;
                    case "inset":
                        borderStyle.setStyle(PDBorderStyleDictionary.STYLE_INSET);
                        break;
                    case "underline":
                        borderStyle.setStyle(PDBorderStyleDictionary.STYLE_SOLID);
                        break;
                    case "cloudy":
                        borderStyle.setStyle(PDBorderStyleDictionary.STYLE_SOLID);
                        PDBorderEffectDictionary borderEffect = new PDBorderEffectDictionary();
                        borderEffect.setStyle(PDBorderEffectDictionary.STYLE_CLOUDY);
                        String intensity = element.getAttribute("intensity");
                        if (intensity != null && !intensity.isEmpty())
                        {
                            borderEffect.setIntensity(Float.parseFloat(element
                                    .getAttribute("intensity")));
                        }
                        setBorderEffect(borderEffect);
                        break;
                    default:
                        borderStyle.setStyle(PDBorderStyleDictionary.STYLE_SOLID);
                        break;
                }
            }
            String dashes = element.getAttribute("dashes");
            if (dashes != null && !dashes.isEmpty())
            {
                String[] dashesValues = dashes.split(",");
                COSArray dashPattern = new COSArray();
                for (String dashesValue : dashesValues)
                {
                    dashPattern.add(COSNumber.get(dashesValue));
                }
                borderStyle.setDashStyle(dashPattern);
            }
            setBorderStyle(borderStyle);
        }
    }