FileDocCategorySizeDatePackage
Hyperlink.javaAPI DocApache Poi 3.0.15866Thu May 31 18:45:28 BST 2007org.apache.poi.hslf.model

Hyperlink

public class Hyperlink extends Object
Represents a hyperlink in a PowerPoint document
author
Yegor Kozlov

Fields Summary
private int
type
private String
address
private String
title
private int
startIndex
private int
endIndex
Constructors Summary
Methods Summary
protected static org.apache.poi.hslf.model.Hyperlink[]find(org.apache.poi.hslf.model.TextRun run)
Find hyperlinks in a text run

param
run TextRun to lookup hyperlinks in
return
found hyperlinks or null if not found

        ArrayList lst = new ArrayList();
        SlideShow ppt = run.getSheet().getSlideShow();
        //document-level container which stores info about all links in a presentation
        ExObjList exobj = ppt.getDocumentRecord().getExObjList();
        if (exobj == null) {
            return null;
        }
        Record[] records = run._records;
        if(records != null) find(records, exobj, lst);

        Hyperlink[] links = null;
        if (lst.size() > 0){
            links = new Hyperlink[lst.size()];
            lst.toArray(links);
        }
        return links;
    
protected static org.apache.poi.hslf.model.Hyperlinkfind(org.apache.poi.hslf.model.Shape shape)
Find hyperlink assigned to the supplied shape

param
shape Shape to lookup hyperlink in
return
found hyperlink or null

        ArrayList lst = new ArrayList();
        SlideShow ppt = shape.getSheet().getSlideShow();
        //document-level container which stores info about all links in a presentation
        ExObjList exobj = ppt.getDocumentRecord().getExObjList();
        if (exobj == null) {
            return null;
        }

        EscherContainerRecord spContainer = shape.getSpContainer();
        List spchild = spContainer.getChildRecords();
        for (Iterator it = spchild.iterator(); it.hasNext(); ) {
            EscherRecord obj = (EscherRecord)it.next();
            if (obj.getRecordId() ==  EscherClientDataRecord.RECORD_ID){
                byte[] data = ((EscherContainerRecord)obj).serialize();
                Record[] records = Record.findChildRecords(data, 8, data.length-8);
                if(records != null) find(records, exobj, lst);
            }
        }

        return lst.size() == 1 ? (Hyperlink)lst.get(0) : null;
    
private static voidfind(org.apache.poi.hslf.record.Record[] records, org.apache.poi.hslf.record.ExObjList exobj, java.util.List out)

        for (int i = 0; i < records.length; i++) {
            //see if we have InteractiveInfo in the textrun's records
            if( records[i] instanceof InteractiveInfo){
                InteractiveInfo hldr = (InteractiveInfo)records[i];
                InteractiveInfoAtom info = hldr.getInteractiveInfoAtom();
                int id = info.getHyperlinkID();
                ExHyperlink linkRecord = exobj.get(id);
                if (linkRecord != null){
                    Hyperlink link = new Hyperlink();
                    link.title = linkRecord.getLinkTitle();
                    link.address = linkRecord.getLinkURL();
                    link.type = info.getAction();

                    if (++i < records.length && records[i] instanceof TxInteractiveInfoAtom){
                        TxInteractiveInfoAtom txinfo = (TxInteractiveInfoAtom)records[i];
                        link.startIndex = txinfo.getStartIndex();
                        link.endIndex = txinfo.getEndIndex();
                    }
                    out.add(link);
                }
            }
        }
    
public java.lang.StringgetAddress()
Gets the hyperlink URL

return
the hyperlink URL

        return address;
    
public intgetEndIndex()
Gets the ending character position

return
the ending character position

        return endIndex;
    
public intgetStartIndex()
Gets the beginning character position

return
the beginning character position

        return startIndex;
    
public java.lang.StringgetTitle()
Gets the hyperlink user-friendly title (if different from URL)

return
the hyperlink user-friendly title

        return title;
    
public intgetType()
Gets the type of the hyperlink action. Must be a ACTION_* constant defined in InteractiveInfoAtom

return
the hyperlink URL
see
InteractiveInfoAtom

        return type;