Example usage for org.apache.pdfbox.pdmodel.interactive.action PDActionLaunch getP

List of usage examples for org.apache.pdfbox.pdmodel.interactive.action PDActionLaunch getP

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.interactive.action PDActionLaunch getP.

Prototype

public String getP() 

Source Link

Document

This will get a parameter string to be passed to the application designated by the F entry.

Usage

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

License:Apache License

private void handleDestinationOrAction(PDDestinationOrAction action, ActionTrigger actionTrigger)
        throws IOException, SAXException, TikaException {
    if (action == null || !config.getExtractActions()) {
        return;/*from w  w w.  j  a va  2  s.  co  m*/
    }
    AttributesImpl attributes = new AttributesImpl();
    String actionOrDestString = (action instanceof PDAction) ? "action" : "destination";

    addNonNullAttribute("class", actionOrDestString, attributes);
    addNonNullAttribute("type", action.getClass().getSimpleName(), attributes);
    addNonNullAttribute("trigger", actionTrigger.name(), attributes);

    if (action instanceof PDActionImportData) {
        processDoc("", ((PDActionImportData) action).getFile(), attributes);
    } else if (action instanceof PDActionLaunch) {
        PDActionLaunch pdActionLaunch = (PDActionLaunch) action;
        addNonNullAttribute("id", pdActionLaunch.getF(), attributes);
        addNonNullAttribute("defaultDirectory", pdActionLaunch.getD(), attributes);
        addNonNullAttribute("operation", pdActionLaunch.getO(), attributes);
        addNonNullAttribute("parameters", pdActionLaunch.getP(), attributes);
        processDoc(pdActionLaunch.getF(), pdActionLaunch.getFile(), attributes);
    } else if (action instanceof PDActionRemoteGoTo) {
        PDActionRemoteGoTo remoteGoTo = (PDActionRemoteGoTo) action;
        processDoc("", remoteGoTo.getFile(), attributes);
    } else if (action instanceof PDActionJavaScript) {
        PDActionJavaScript jsAction = (PDActionJavaScript) action;
        Metadata m = new Metadata();
        m.set(Metadata.CONTENT_TYPE, "application/javascript");
        m.set(Metadata.CONTENT_ENCODING, StandardCharsets.UTF_8.toString());
        m.set(PDF.ACTION_TRIGGER, actionTrigger.toString());
        m.set(TikaCoreProperties.EMBEDDED_RESOURCE_TYPE, TikaCoreProperties.EmbeddedResourceType.MACRO.name());
        String js = jsAction.getAction();
        js = (js == null) ? "" : js;
        if (embeddedDocumentExtractor.shouldParseEmbedded(m)) {
            try (InputStream is = TikaInputStream.get(js.getBytes(StandardCharsets.UTF_8))) {
                embeddedDocumentExtractor.parseEmbedded(is, xhtml, m, false);
            }
        }
        addNonNullAttribute("class", "javascript", attributes);
        addNonNullAttribute("type", jsAction.getType(), attributes);
        addNonNullAttribute("subtype", jsAction.getSubType(), attributes);
        xhtml.startElement("div", attributes);
        xhtml.endElement("div");
    } else {
        xhtml.startElement("div", attributes);
        xhtml.endElement("div");
    }
}