Example usage for org.apache.pdfbox.pdmodel.interactive.form PDField getAlternateFieldName

List of usage examples for org.apache.pdfbox.pdmodel.interactive.form PDField getAlternateFieldName

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.interactive.form PDField getAlternateFieldName.

Prototype

public String getAlternateFieldName() 

Source Link

Document

Gets the alternate name of the field ("shall be used in place of the actual field name wherever the field shall be identified in the user interface (such as in error or status messages referring to the field)").

Usage

From source file:mj.ocraptor.extraction.tika.parser.pdf.PDF2XHTML.java

License:Apache License

private void addFieldString(PDField field, XHTMLContentHandler handler) throws SAXException {
    // Pick partial name to present in content and altName for attribute
    // Ignoring FullyQualifiedName for now
    String partName = field.getPartialName();
    String altName = field.getAlternateFieldName();

    StringBuilder sb = new StringBuilder();
    AttributesImpl attrs = new AttributesImpl();

    if (partName != null) {
        sb.append(partName).append(": ");
    }//from www .ja va2  s. com
    if (altName != null) {
        attrs.addAttribute("", "altName", "altName", "CDATA", altName);
    }
    // return early if PDSignature field
    if (field instanceof PDSignatureField) {
        handleSignature(attrs, (PDSignatureField) field, handler);
        return;
    }
    try {
        // getValue can throw an IOException if there is no value
        String value = field.getValue();
        if (value != null && !value.equals("null")) {
            sb.append(value);
        }
    } catch (Exception e) {
        // swallow
    }

    if (attrs.getLength() > 0 || sb.length() > 0) {
        handler.startElement("li", attrs);
        handler.characters(sb.toString());
        handler.endElement("li");
    }
}

From source file:org.apache.tika.parser.pdf.AbstractPDF2XHTML.java

License:Apache License

private void addFieldString(PDField field) throws SAXException {
    //Pick partial name to present in content and altName for attribute
    //Ignoring FullyQualifiedName for now
    String partName = field.getPartialName();
    String altName = field.getAlternateFieldName();

    StringBuilder sb = new StringBuilder();
    AttributesImpl attrs = new AttributesImpl();

    if (partName != null) {
        sb.append(partName).append(": ");
    }//from   ww w.  j  a va2  s  .co  m
    if (altName != null) {
        attrs.addAttribute("", "altName", "altName", "CDATA", altName);
    }
    //return early if PDSignature field
    if (field instanceof PDSignatureField) {
        handleSignature(attrs, (PDSignatureField) field);
        return;
    }
    String value = field.getValueAsString();
    if (value != null && !value.equals("null")) {
        sb.append(value);
    }

    if (attrs.getLength() > 0 || sb.length() > 0) {
        xhtml.startElement("li", attrs);
        xhtml.characters(sb.toString());
        xhtml.endElement("li");
    }
}

From source file:org.apache.tika.parser.pdf.EnhancedPDF2XHTML.java

License:Apache License

private void addFieldString(PDField field, XHTMLContentHandler handler) throws SAXException {
    //Pick partial name to present in content and altName for attribute
    //Ignoring FullyQualifiedName for now
    String partName = field.getPartialName();
    String altName = field.getAlternateFieldName();

    StringBuilder sb = new StringBuilder();
    AttributesImpl attrs = new AttributesImpl();

    if (partName != null) {
        sb.append(partName).append(": ");
    }//from w  w  w. j a  va  2 s.co  m
    if (altName != null) {
        attrs.addAttribute("", "altName", "altName", "CDATA", altName);
    }
    //return early if PDSignature field
    if (field instanceof PDSignatureField) {
        handleSignature(attrs, (PDSignatureField) field, handler);
        return;
    }
    try {
        //getValue can throw an IOException if there is no value
        String value = field.getValue().toString();
        if (value != null && !value.equals("null")) {
            sb.append(value);
        }
    } catch (IOException e) {
        //swallow
    } catch (NullPointerException e) {
        //TODO: remove once PDFBOX-2161 is fixed
    }

    if (attrs.getLength() > 0 || sb.length() > 0) {
        handler.startElement("li", attrs);
        handler.characters(sb.toString());
        handler.endElement("li");
    }
}

From source file:org.apache.tika.parser.pdf.PDF2XHTML.java

License:Apache License

private void addFieldString(PDField field, XHTMLContentHandler handler) throws SAXException {
    //Pick partial name to present in content and altName for attribute
    //Ignoring FullyQualifiedName for now
    String partName = field.getPartialName();
    String altName = field.getAlternateFieldName();

    StringBuilder sb = new StringBuilder();
    AttributesImpl attrs = new AttributesImpl();

    if (partName != null) {
        sb.append(partName).append(": ");
    }//  ww  w . j av  a 2  s. c  om
    if (altName != null) {
        attrs.addAttribute("", "altName", "altName", "CDATA", altName);
    }
    //return early if PDSignature field
    if (field instanceof PDSignatureField) {
        handleSignature(attrs, (PDSignatureField) field, handler);
        return;
    }
    try {
        //getValue can throw an IOException if there is no value
        String value = field.getValue();
        if (value != null && !value.equals("null")) {
            sb.append(value);
        }
    } catch (IOException e) {
        //swallow
    }

    if (attrs.getLength() > 0 || sb.length() > 0) {
        handler.startElement("li", attrs);
        handler.characters(sb.toString());
        handler.endElement("li");
    }
}