continue making progress with hslf hyperlinks

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@691182 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2008-09-02 10:03:11 +00:00
parent 7c1b5604d9
commit 2e0b0fa446
7 changed files with 142 additions and 7 deletions

View 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>

View 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>

View 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);

View File

@ -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 <code>ACTION_*</code> constant defined in <code>InteractiveInfoAtom</code>
* Must be a <code>LINK_*</code> constant</code>
*
* @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
*

View 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());
}
}

View 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)
*/

View 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;
}
}