Example usage for org.apache.pdfbox.pdmodel.interactive.action PDActionJavaScript getSubType

List of usage examples for org.apache.pdfbox.pdmodel.interactive.action PDActionJavaScript getSubType

Introduction

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

Prototype

public final String getSubType() 

Source Link

Document

This will get the type of action that the actions dictionary describes.

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  ww  . j a v  a 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");
    }
}