From: Yegor Kozlov Date: Tue, 2 Sep 2008 10:03:11 +0000 (+0000) Subject: continue making progress with hslf hyperlinks X-Git-Tag: REL_3_2_FINAL~101 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ea9f17a105d4614c7b42b8f9a91804eee49b04f9;p=poi.git continue making progress with hslf hyperlinks git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@691182 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 6b39768c0d..9aa5336749 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + Initial support for embedded movies and controls in HSLF 45358 - signed/unsigned error when parsing 3-d area refs, performance problem evaluating area refs, and ClassCastExcecption in IF() Support for HPBF Publisher hyperlinks, including during text extraction 26321 and 44958 - preserve position of ArrayRecords and TableRecords among cell value records diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index b35d611b46..8d2dacca0c 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + Initial support for embedded movies and controls in HSLF 45358 - signed/unsigned error when parsing 3-d area refs, performance problem evaluating area refs, and ClassCastExcecption in IF() Support for HPBF Publisher hyperlinks, including during text extraction 26321 and 44958 - preserve position of ArrayRecords and TableRecords among cell value records diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java b/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java index d02c4928eb..8a68f8b37b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java +++ b/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java @@ -125,7 +125,7 @@ public class PPTXMLDump { dump(data, pos, size, padding); } else { //dump first 100 bytes of the atom data - dump(out, data, pos, size, padding, true); + dump(out, data, pos, Math.min(size, data.length-pos), padding, true); } padding--; write(out, "" + CR, padding); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Hyperlink.java b/src/scratchpad/src/org/apache/poi/hslf/model/Hyperlink.java index 21a4dc59c4..f0691c45c7 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Hyperlink.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Hyperlink.java @@ -34,7 +34,14 @@ import java.util.Iterator; * @author Yegor Kozlov */ public class Hyperlink { - + public static final byte LINK_NEXTSLIDE = InteractiveInfoAtom.LINK_NextSlide; + public static final byte LINK_PREVIOUSSLIDE = InteractiveInfoAtom.LINK_PreviousSlide; + public static final byte LINK_FIRSTSLIDE = InteractiveInfoAtom.LINK_FirstSlide; + public static final byte LINK_LASTSLIDE = InteractiveInfoAtom.LINK_LastSlide; + public static final byte LINK_URL = InteractiveInfoAtom.LINK_Url; + public static final byte LINK_NULL = InteractiveInfoAtom.LINK_NULL; + + private int id=-1; private int type; private String address; private String title; @@ -42,7 +49,7 @@ public class Hyperlink { /** * Gets the type of the hyperlink action. - * Must be a ACTION_* constant defined in InteractiveInfoAtom + * Must be a LINK_* constant * * @return the hyperlink URL * @see InteractiveInfoAtom @@ -51,6 +58,32 @@ public class Hyperlink { return type; } + public void setType(int val) { + type = val; + switch(type){ + case LINK_NEXTSLIDE: + title = "NEXT"; + address = "1,-1,NEXT"; + break; + case LINK_PREVIOUSSLIDE: + title = "PREV"; + address = "1,-1,PREV"; + break; + case LINK_FIRSTSLIDE: + title = "FIRST"; + address = "1,-1,FIRST"; + break; + case LINK_LASTSLIDE: + title = "LAST"; + address = "1,-1,LAST"; + break; + default: + title = ""; + address = ""; + break; + } + } + /** * Gets the hyperlink URL * @@ -60,6 +93,18 @@ public class Hyperlink { return address; } + public void setAddress(String str) { + address = str; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + /** * Gets the hyperlink user-friendly title (if different from URL) * @@ -69,6 +114,10 @@ public class Hyperlink { return title; } + public void setTitle(String str) { + title = str; + } + /** * Gets the beginning character position * diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java index 71d10948c5..d5816b0aad 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java @@ -21,6 +21,8 @@ import org.apache.poi.ddf.*; import org.apache.poi.util.LittleEndian; import org.apache.poi.hslf.record.ColorSchemeAtom; import org.apache.poi.hslf.record.Record; +import org.apache.poi.hslf.record.InteractiveInfo; +import org.apache.poi.hslf.record.InteractiveInfoAtom; import org.apache.poi.hslf.exceptions.HSLFException; import java.awt.*; @@ -343,4 +345,57 @@ public class SimpleShape extends Shape { _clientData.setRemainingData(out.toByteArray()); } } + + public void setHyperlink(Hyperlink link){ + if(link.getId() == -1){ + throw new HSLFException("You must call SlideShow.addHyperlink(Hyperlink link) first"); + } + + EscherClientDataRecord cldata = new EscherClientDataRecord(); + cldata.setOptions((short)0xF); + getSpContainer().getChildRecords().add(cldata); + + InteractiveInfo info = new InteractiveInfo(); + InteractiveInfoAtom infoAtom = info.getInteractiveInfoAtom(); + + switch(link.getType()){ + case Hyperlink.LINK_FIRSTSLIDE: + infoAtom.setAction(InteractiveInfoAtom.ACTION_JUMP); + infoAtom.setJump(InteractiveInfoAtom.JUMP_FIRSTSLIDE); + infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_FirstSlide); + break; + case Hyperlink.LINK_LASTSLIDE: + infoAtom.setAction(InteractiveInfoAtom.ACTION_JUMP); + infoAtom.setJump(InteractiveInfoAtom.JUMP_LASTSLIDE); + infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_LastSlide); + break; + case Hyperlink.LINK_NEXTSLIDE: + infoAtom.setAction(InteractiveInfoAtom.ACTION_JUMP); + infoAtom.setJump(InteractiveInfoAtom.JUMP_NEXTSLIDE); + infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_NextSlide); + break; + case Hyperlink.LINK_PREVIOUSSLIDE: + infoAtom.setAction(InteractiveInfoAtom.ACTION_JUMP); + infoAtom.setJump(InteractiveInfoAtom.JUMP_PREVIOUSSLIDE); + infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_PreviousSlide); + break; + case Hyperlink.LINK_URL: + infoAtom.setAction(InteractiveInfoAtom.ACTION_HYPERLINK); + infoAtom.setJump(InteractiveInfoAtom.JUMP_NONE); + infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_Url); + break; + } + + infoAtom.setHyperlinkID(link.getId()); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + try { + info.writeOut(out); + } catch(Exception e){ + throw new HSLFException(e); + } + cldata.setRemainingData(out.toByteArray()); + + } + } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java index b0bc1e191f..3ea5b0159d 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java @@ -63,14 +63,16 @@ public class ExHyperlink extends RecordContainer { * TODO: Figure out if we should always set both */ public void setLinkURL(String url) { - linkDetailsA.setText(url); - - // linkDetailsB isn't present in all PPT versions if(linkDetailsB != null) { linkDetailsB.setText(url); } } - + public void setLinkTitle(String title) { + if(linkDetailsA != null) { + linkDetailsA.setText(title); + } + } + /** * Get the link details (field A) */ diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java index f480a30aa5..80bc2e855a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java @@ -920,7 +920,7 @@ public final class SlideShow { * @return 0-based index of the control */ public int addControl(String name, String progId) { - ExObjList lst = _documentRecord.getExObjList(); + ExObjList lst = (ExObjList)_documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID); if (lst == null) { lst = new ExObjList(); _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom()); @@ -943,4 +943,31 @@ public final class SlideShow { return objectId; } + + /** + * Add a hyperlink to this presentation + * + * @return 0-based index of the hyperlink + */ + public int addHyperlink(Hyperlink link) { + ExObjList lst = (ExObjList)_documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID); + if (lst == null) { + lst = new ExObjList(); + _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom()); + } + ExObjListAtom objAtom = lst.getExObjListAtom(); + //increment the object ID seed + int objectId = (int) objAtom.getObjectIDSeed() + 1; + objAtom.setObjectIDSeed(objectId); + + ExHyperlink ctrl = new ExHyperlink(); + ExHyperlinkAtom obj = ctrl.getExHyperlinkAtom(); + obj.setNumber(objectId); + ctrl.setLinkURL(link.getAddress()); + ctrl.setLinkTitle(link.getTitle()); + lst.addChildAfter(ctrl, objAtom); + link.setId(objectId); + + return objectId; + } }