/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.pdfbox.pdmodel.fdf;

import java.io.IOException;

import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
import org.w3c.dom.Element;

/**
 * This represents a FreeText FDF annotation.
 *
 * @author Ben Litchfield
 */
public class FDFAnnotationFreeText extends FDFAnnotation
{
    /**
     * COS Model value for SubType entry.
     */
    public static final String SUBTYPE = "FreeText";

    /**
     * Default constructor.
     */
    public FDFAnnotationFreeText()
    {
        super();
        annot.setName(COSName.SUBTYPE, SUBTYPE);
    }

    /**
     * Constructor.
     *
     * @param a An existing FDF Annotation.
     */
    public FDFAnnotationFreeText(COSDictionary a)
    {
        super(a);
    }

    /**
     * Constructor.
     *
     * @param element An XFDF element.
     *
     * @throws IOException If there is an error extracting information from the element.
     */
    public FDFAnnotationFreeText(Element element) throws IOException
    {
        super(element);
        annot.setName(COSName.SUBTYPE, SUBTYPE);

        setJustification(element.getAttribute("justification"));
        String rotation = element.getAttribute("rotation");
        if (rotation != null && !rotation.isEmpty())
        {
            setRotation(Integer.parseInt(rotation));
        }
    }

    /**
     * This will set the form of quadding (justification) of the annotation text.
     * 
     * @param justification The quadding of the text.
     */
    public void setJustification(String justification)
    {
        int quadding = 0;
        if ("centered".equals(justification))
        {
            quadding = 1;
        }
        else if ("right".equals(justification))
        {
            quadding = 2;
        }
        annot.setInt(COSName.Q, quadding);
    }

    /**
     * This will get the form of quadding (justification) of the annotation text.
     * 
     * @return The quadding of the text.
     */
    public String getJustification()
    {
        return "" + annot.getInt(COSName.Q, 0);
    }

    /**
     * This will set the clockwise rotation in degrees.
     * 
     * @param rotation The number of degrees of clockwise rotation.
     */
    public void setRotation(int rotation)
    {
        annot.setInt(COSName.ROTATE, rotation);
    }

    /**
     * This will get the clockwise rotation in degrees.
     * 
     * @return The number of degrees of clockwise rotation.
     */
    public String getRotation()
    {
        return annot.getString(COSName.ROTATE);
    }

}

@@ -864,16 +864,217 @@
 eption;%0A
+import javax.xml.xpath.XPath;%0Aimport javax.xml.xpath.XPathExpressionException;%0Aimport javax.xml.xpath.XPathFactory;%0A%0Aimport org.apache.commons.logging.Log;%0Aimport org.apache.commons.logging.LogFactory;
 %0Aimport 
@@ -1319,16 +1319,101 @@
 ation%0A%7B%0A
+    private static final Log LOG = LogFactory.getLog(FDFAnnotationFreeText.class);%0A %0A
     /**%0A
@@ -2230,24 +2230,406 @@
 ication%22));%0A
+        %0A        XPath xpath = XPathFactory.newInstance().newXPath();%0A        try%0A        %7B%0A            setDefaultAppearance(xpath.evaluate(%22defaultappearance%22, element));%0A            setDefaultStyle(xpath.evaluate(%22defaultstyle%22, element));%0A        %7D%0A        catch (XPathExpressionException ex)%0A        %7B%0A            LOG.debug(%22Error while evaluating XPath expression%22);%0A        %7D%0A
         Stri
@@ -2972,32 +2972,38 @@
   */%0A    public 
+final 
 void setJustific
@@ -3702,16 +3702,22 @@
  public 
+final 
 void set
@@ -4033,10 +4033,904 @@
 %0A    %7D%0A%0A
+    /**%0A     * Set the default appearance string.%0A     *%0A     * @param appearance The new default appearance string.%0A     */%0A    public final void setDefaultAppearance(String appearance)%0A    %7B%0A        annot.setString(COSName.DA, appearance);%0A    %7D%0A%0A    /**%0A     * Get the default appearance string.%0A     *%0A     * @return The default appearance of the annotation.%0A     */%0A    public String getDefaultAppearance()%0A    %7B%0A        return annot.getString(COSName.DA);%0A%0A    %7D%0A%0A    /**%0A     * Set the default style string.%0A     *%0A     * @param style The new default style string.%0A     */%0A    public final void setDefaultStyle(String style)%0A    %7B%0A        annot.setString(COSName.DS, style);%0A    %7D%0A%0A    /**%0A     * Get the default style string.%0A     *%0A     * @return The default style of the annotation.%0A     */%0A    public String getDefaultStyle()%0A    %7B%0A        return annot.getString(COSName.DS);%0A    %7D%0A%0A
 %7D%0A

add /DA and /DS