]> source.dussan.org Git - poi.git/commitdiff
continue making progress with hslf hyperlinks
authorYegor Kozlov <yegor@apache.org>
Tue, 2 Sep 2008 10:03:11 +0000 (10:03 +0000)
committerYegor Kozlov <yegor@apache.org>
Tue, 2 Sep 2008 10:03:11 +0000 (10:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@691182 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java
src/scratchpad/src/org/apache/poi/hslf/model/Hyperlink.java
src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java
src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java

index 6b39768c0de867cc510641b1f54ecb3769c4d696..9aa5336749d5cdb960bb0f40b15d8957f57cba6b 100644 (file)
@@ -37,6 +37,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.1.1-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">Initial support for embedded movies and controls in HSLF</action>
            <action dev="POI-DEVELOPERS" type="fix">45358 - signed/unsigned error when parsing 3-d area refs, performance problem evaluating area refs, and ClassCastExcecption in IF()</action>
            <action dev="POI-DEVELOPERS" type="add">Support for HPBF Publisher hyperlinks, including during text extraction</action>
            <action dev="POI-DEVELOPERS" type="fix">26321 and 44958 - preserve position of ArrayRecords and TableRecords among cell value records</action>
index b35d611b46f25d1bdd64e6d40e7e25e13da72d56..8d2dacca0cea485c5e6777067a6433825f3bb72a 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.1.1-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">Initial support for embedded movies and controls in HSLF</action>
            <action dev="POI-DEVELOPERS" type="fix">45358 - signed/unsigned error when parsing 3-d area refs, performance problem evaluating area refs, and ClassCastExcecption in IF()</action>
            <action dev="POI-DEVELOPERS" type="add">Support for HPBF Publisher hyperlinks, including during text extraction</action>
            <action dev="POI-DEVELOPERS" type="fix">26321 and 44958 - preserve position of ArrayRecords and TableRecords among cell value records</action>
index d02c4928ebad0b496d5c42d904b8911746ae2205..8a68f8b37bd9c1e1ea9c37c5a840d75fef1cbb71 100644 (file)
@@ -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, "</"+recname + ">" + CR, padding);
index 21a4dc59c425d2968921c022aff3d9b4fe87eea8..f0691c45c799fc73d207f4b251be941bed31eb1e 100644 (file)
@@ -34,7 +34,14 @@ import java.util.Iterator;
  * @author Yegor Kozlov\r
  */\r
 public class Hyperlink {\r
-\r
+    public static final byte LINK_NEXTSLIDE = InteractiveInfoAtom.LINK_NextSlide;\r
+    public static final byte LINK_PREVIOUSSLIDE = InteractiveInfoAtom.LINK_PreviousSlide;\r
+    public static final byte LINK_FIRSTSLIDE = InteractiveInfoAtom.LINK_FirstSlide;\r
+    public static final byte LINK_LASTSLIDE = InteractiveInfoAtom.LINK_LastSlide;\r
+    public static final byte LINK_URL = InteractiveInfoAtom.LINK_Url;\r
+    public static final byte LINK_NULL = InteractiveInfoAtom.LINK_NULL;\r
+\r
+    private int id=-1;\r
     private int type;\r
     private String address;\r
     private String title;\r
@@ -42,7 +49,7 @@ public class Hyperlink {
 \r
     /**\r
      * Gets the type of the hyperlink action.\r
-     * Must be a <code>ACTION_*</code>  constant defined in <code>InteractiveInfoAtom</code>\r
+     * Must be a <code>LINK_*</code>  constant</code>\r
      *\r
      * @return the hyperlink URL\r
      * @see InteractiveInfoAtom\r
@@ -51,6 +58,32 @@ public class Hyperlink {
         return type;\r
     }\r
 \r
+    public void setType(int val) {\r
+        type = val;\r
+        switch(type){\r
+            case LINK_NEXTSLIDE:\r
+                title = "NEXT";\r
+                address = "1,-1,NEXT";\r
+                break;\r
+            case LINK_PREVIOUSSLIDE:\r
+                title = "PREV";\r
+                address = "1,-1,PREV";\r
+                break;\r
+            case LINK_FIRSTSLIDE:\r
+                title = "FIRST";\r
+                address = "1,-1,FIRST";\r
+                break;\r
+            case LINK_LASTSLIDE:\r
+                title = "LAST";\r
+                address = "1,-1,LAST";\r
+                break;\r
+            default:\r
+                title = "";\r
+                address = "";\r
+                break;\r
+        }\r
+    }\r
+\r
     /**\r
      * Gets the hyperlink URL\r
      *\r
@@ -60,6 +93,18 @@ public class Hyperlink {
         return address;\r
     }\r
 \r
+    public void setAddress(String str) {\r
+        address = str;\r
+    }\r
+\r
+    public int getId() {\r
+        return id;\r
+    }\r
+\r
+    public void setId(int id) {\r
+        this.id = id;\r
+    }\r
+\r
     /**\r
      * Gets the hyperlink user-friendly title (if different from URL)\r
      *\r
@@ -69,6 +114,10 @@ public class Hyperlink {
         return title;\r
     }\r
 \r
+    public void setTitle(String str) {\r
+        title = str;\r
+    }\r
+\r
     /**\r
      * Gets the beginning character position\r
      *\r
index 71d10948c5bc52f236758cc5b6b3d73b30a5071a..d5816b0aad09ee2a78d6167fde741c85ae50fbb1 100644 (file)
@@ -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());
+
+    }
+
 }
index b0bc1e191fbc6b5d583ab4c0ffd2fe4bbda8ea30..3ea5b0159ded8ddb63a7eea205429119e9579484 100644 (file)
@@ -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)
         */
index f480a30aa5632a053abb9e8e7a2fb0ce2e6a2917..80bc2e855aeaa4add319d34c2567c2ef8a356425 100644 (file)
@@ -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;
+    }
 }