Example usage for org.apache.poi.xslf.usermodel XSLFRelation HYPERLINK

List of usage examples for org.apache.poi.xslf.usermodel XSLFRelation HYPERLINK

Introduction

In this page you can find the example usage for org.apache.poi.xslf.usermodel XSLFRelation HYPERLINK.

Prototype

XSLFRelation HYPERLINK

To view the source code for org.apache.poi.xslf.usermodel XSLFRelation HYPERLINK.

Click Source Link

Usage

From source file:de.kiwiwings.jasperreports.exporter.PptxShapeExporter.java

License:Open Source License

protected void setHyperlinkURL(JRCommonElement jrShape, XSLFShape hyperlinkTarget) {
    if (hyperlinkTarget == null || !(jrShape instanceof JRPrintHyperlink))
        return;//  w  w w.java 2s.com

    // http://openxmldeveloper.org/discussions/formats/f/15/t/304.aspx

    JRPrintHyperlink link = (JRPrintHyperlink) jrShape;
    JRHyperlinkProducer customHandler = getHyperlinkProducer(link);
    PackageRelationship rel = null;
    String action = null;

    if (customHandler != null) {
        String href = customHandler.getHyperlink(link);
        if (href != null) {
            rel = slide.getPackagePart().addExternalRelationship(href, XSLFRelation.HYPERLINK.getRelation());
        }
    }

    switch (link.getHyperlinkTypeValue()) {
    case REFERENCE: {
        String href = link.getHyperlinkReference();
        if (href != null) {
            rel = slide.getPackagePart().addExternalRelationship(href, XSLFRelation.HYPERLINK.getRelation());
        }
        break;
    }
    case LOCAL_PAGE: {
        XSLFSheet targetSlide = slideList.get(link.getHyperlinkPage());
        rel = slide.getPackagePart().addRelationship(targetSlide.getPackagePart().getPartName(),
                TargetMode.INTERNAL, XSLFRelation.SLIDE.getRelation());
        action = "ppaction://hlinksldjump";
        break;
    }
    case REMOTE_PAGE: {
        String href = link.getHyperlinkReference();
        if (href != null) {
            rel = slide.getPackagePart().addExternalRelationship(href, XSLFRelation.HYPERLINK.getRelation());
        }
        Integer page = link.getHyperlinkPage();
        if (page != null) {
            action = "ppaction://hlinkpres?slideindex=" + page;
            if (link.getHyperlinkParameters() != null) {
                List<JRPrintHyperlinkParameter> plist = link.getHyperlinkParameters().getParameters();
                if (plist != null) {
                    for (JRPrintHyperlinkParameter p : plist) {
                        if ("slidetitle".equals(p.getName())) {
                            action += "&slidetitle=" + p.getValue().toString();
                            break;
                        }
                    }
                }
            }
        }
        break;
    }

    case NONE:
    default:
    case LOCAL_ANCHOR:
    case REMOTE_ANCHOR:
        // not implemented ... only pages (not elements) can be referenced in powerpoint
        break;
    }

    if (rel != null) {
        CTHyperlink hlink = XSLFSimpleShapeHelper.addHyperlink(hyperlinkTarget);
        if (hlink == null) {
            slide.getPackagePart().removeRelationship(rel.getId());
        } else {
            hlink.setId(rel.getId());
            if (action != null) {
                hlink.setAction(action);
            }
        }
    }
}