* Returns all the ExHyperlinks
*/
public ExHyperlink[] getExHyperlinks() {
- ArrayList links = new ArrayList();
+ ArrayList<ExHyperlink> links = new ArrayList<ExHyperlink>();
for(int i=0; i<_children.length; i++) {
if(_children[i] instanceof ExHyperlink) {
- links.add(_children[i]);
+ links.add( (ExHyperlink)_children[i] );
}
}
- return (ExHyperlink[])links.toArray(new ExHyperlink[links.size()]);
+ return links.toArray(new ExHyperlink[links.size()]);
}
/**
myLastOnDiskOffset = offset;
}
- public void updateOtherRecordReferences(Hashtable oldToNewReferencesLookup) {
+ public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup) {
return;
}
*/
public final class FontCollection extends RecordContainer {
- private List fonts;
- private byte[] _header;
+ private List<String> fonts;
+ private byte[] _header;
protected FontCollection(byte[] source, int start, int len) {
// Grab the header
_children = Record.findChildRecords(source,start+8,len-8);
// Save font names into <code>List</code>
- fonts = new ArrayList();
+ fonts = new ArrayList<String>();
for (int i = 0; i < _children.length; i++){
if(_children[i] instanceof FontEntityAtom) {
FontEntityAtom atom = (FontEntityAtom)_children[i];
// No font with that id
return null;
}
- return (String)fonts.get(id);
+ return fonts.get(id);
}
}
// Find our children
_children = Record.findChildRecords(source,start+8,len-8);
- ArrayList tx = new ArrayList();
- ArrayList clr = new ArrayList();
+ ArrayList<TxMasterStyleAtom> tx = new ArrayList<TxMasterStyleAtom>();
+ ArrayList<ColorSchemeAtom> clr = new ArrayList<ColorSchemeAtom>();
// Find the interesting ones in there
for(int i=0; i<_children.length; i++) {
if(_children[i] instanceof SlideAtom) {
} else if(_children[i] instanceof PPDrawing) {
ppDrawing = (PPDrawing)_children[i];
} else if(_children[i] instanceof TxMasterStyleAtom) {
- tx.add(_children[i]);
+ tx.add( (TxMasterStyleAtom)_children[i] );
} else if(_children[i] instanceof ColorSchemeAtom) {
- clr.add(_children[i]);
+ clr.add( (ColorSchemeAtom)_children[i] );
}
if(ppDrawing != null && _children[i] instanceof ColorSchemeAtom) {
}
}
- txmasters = (TxMasterStyleAtom[])tx.toArray(new TxMasterStyleAtom[tx.size()]);
- clrscheme = (ColorSchemeAtom[])clr.toArray(new ColorSchemeAtom[clr.size()]);
+ txmasters = tx.toArray(new TxMasterStyleAtom[tx.size()]);
+ clrscheme = clr.toArray(new ColorSchemeAtom[clr.size()]);
}
/**
* Since we're a container, we don't mind if other records move about.
* If we're told they have, just return straight off.
*/
- public void updateOtherRecordReferences(Hashtable oldToNewReferencesLookup) {
+ public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup) {
return;
}
}
import java.io.IOException;
import java.io.OutputStream;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.POILogFactory;
-import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
+import org.apache.poi.util.POILogger;
/**
* This abstract class represents a record in the PowerPoint document.
* Default method for finding child records of a container record
*/
public static Record[] findChildRecords(byte[] b, int start, int len) {
- Vector children = new Vector(5);
+ List<Record> children = new ArrayList<Record>(5);
// Jump our little way along, creating records as we go
int pos = start;
}
// Turn the vector into an array, and return
- Record[] cRecords = new Record[children.size()];
- for(int i=0; i < children.size(); i++) {
- cRecords[i] = (Record)children.get(i);
- }
+ Record[] cRecords = children.toArray( new Record[children.size()] );
return cRecords;
}
// A spot of reflection gets us the (byte[],int,int) constructor
// From there, we instanciate the class
// Any special record handling occurs once we have the class
- Class c = null;
+ Class<? extends Record> c = null;
try {
c = RecordTypes.recordHandlingClass((int)type);
if(c == null) {
}
// Grab the right constructor
- java.lang.reflect.Constructor con = c.getDeclaredConstructor(new Class[] { byte[].class, Integer.TYPE, Integer.TYPE });
+ java.lang.reflect.Constructor<? extends Record> con = c.getDeclaredConstructor(new Class[] { byte[].class, Integer.TYPE, Integer.TYPE });
// Instantiate
- toReturn = (Record)(con.newInstance(new Object[] { b, Integer.valueOf(start), Integer.valueOf(len) }));
+ toReturn = con.newInstance(new Object[] { b, Integer.valueOf(start), Integer.valueOf(len) });
} catch(InstantiationException ie) {
throw new RuntimeException("Couldn't instantiate the class for type with id " + type + " on class " + c + " : " + ie, ie);
} catch(java.lang.reflect.InvocationTargetException ite) {
* @author Nick Burch
*/
public final class RecordTypes {
- public static HashMap typeToName;
- public static HashMap typeToClass;
+ public static HashMap<Integer,String> typeToName;
+ public static HashMap<Integer,Class<? extends Record>> typeToClass;
public static final Type Unknown = new Type(0,null);
public static final Type Document = new Type(1000,Document.class);
* @return name of the record
*/
public static String recordName(int type) {
- String name = (String)typeToName.get(Integer.valueOf(type));
+ String name = typeToName.get(Integer.valueOf(type));
if (name == null) name = "Unknown" + type;
return name;
}
* @param type section of the record header
* @return class to handle the record, or null if an unknown (eg Escher) record
*/
- public static Class recordHandlingClass(int type) {
- Class c = (Class)typeToClass.get(Integer.valueOf(type));
+ public static Class<? extends Record> recordHandlingClass(int type) {
+ Class<? extends Record> c = typeToClass.get(Integer.valueOf(type));
return c;
}
static {
- typeToName = new HashMap();
- typeToClass = new HashMap();
+ typeToName = new HashMap<Integer,String>();
+ typeToClass = new HashMap<Integer,Class<? extends Record>>();
try {
Field[] f = RecordTypes.class.getFields();
for (int i = 0; i < f.length; i++){
- Object val = f[i].get(null);
+ Object val = f[i].get(null);
- // Escher record, only store ID -> Name
- if (val instanceof Integer) {
- typeToName.put(val, f[i].getName());
- }
- // PowerPoint record, store ID -> Name and ID -> Class
- if (val instanceof Type) {
- Type t = (Type)val;
- Class c = t.handlingClass;
- Integer id = Integer.valueOf(t.typeID);
- if(c == null) { c = UnknownRecordPlaceholder.class; }
+ // Escher record, only store ID -> Name
+ if (val instanceof Integer) {
+ typeToName.put((Integer)val, f[i].getName());
+ }
+ // PowerPoint record, store ID -> Name and ID -> Class
+ if (val instanceof Type) {
+ Type t = (Type)val;
+ Class<? extends Record> c = t.handlingClass;
+ Integer id = Integer.valueOf(t.typeID);
+ if(c == null) { c = UnknownRecordPlaceholder.class; }
- typeToName.put(id, f[i].getName());
- typeToClass.put(id, c);
- }
+ typeToName.put(id, f[i].getName());
+ typeToClass.put(id, c);
+ }
}
} catch (IllegalAccessException e){
throw new RuntimeException("Failed to initialize records types");
*/
public static class Type {
public int typeID;
- public Class handlingClass;
- public Type(int typeID, Class handlingClass) {
+ public Class<? extends Record> handlingClass;
+ public Type(int typeID, Class<? extends Record> handlingClass) {
this.typeID = typeID;
this.handlingClass = handlingClass;
}
// Group our children together into SlideAtomsSets
// That way, model layer code can just grab the sets to use,
// without having to try to match the children together
- Vector sets = new Vector();
+ Vector<SlideAtomsSet> sets = new Vector<SlideAtomsSet>();
for(int i=0; i<_children.length; i++) {
if(_children[i] instanceof SlidePersistAtom) {
// Find where the next SlidePersistAtom is
}
// Turn the vector into an array
- slideAtomsSets = new SlideAtomsSet[sets.size()];
- for(int i=0; i<slideAtomsSets.length; i++) {
- slideAtomsSets[i] = (SlideAtomsSet)sets.get(i);
- }
+ slideAtomsSets = sets.toArray( new SlideAtomsSet[sets.size()] );
}
/**
}
public TextSpecInfoRun[] getTextSpecInfoRuns(){
- ArrayList lst = new ArrayList();
+ ArrayList<TextSpecInfoRun> lst = new ArrayList<TextSpecInfoRun>();
int pos = 0;
int[] bits = {1, 0, 2};
while(pos < _data.length) {
}
lst.add(run);
}
- return (TextSpecInfoRun[])lst.toArray(new TextSpecInfoRun[lst.size()]);
-
+ return lst.toArray(new TextSpecInfoRun[lst.size()]);
}
public static class TextSpecInfoRun {
* At write-out time, update the references to PersistPtrs and
* other UserEditAtoms to point to their new positions
*/
- public void updateOtherRecordReferences(Hashtable oldToNewReferencesLookup) {
+ public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup) {
// Look up the new positions of our preceding UserEditAtomOffset
if(lastUserEditAtomOffset != 0) {
- Integer newLocation = (Integer)oldToNewReferencesLookup.get(Integer.valueOf(lastUserEditAtomOffset));
+ Integer newLocation = oldToNewReferencesLookup.get(Integer.valueOf(lastUserEditAtomOffset));
if(newLocation == null) {
throw new RuntimeException("Couldn't find the new location of the UserEditAtom that used to be at " + lastUserEditAtomOffset);
}
}
// Ditto for our PersistPtr
- Integer newLocation = (Integer)oldToNewReferencesLookup.get(Integer.valueOf(persistPointersOffset));
+ Integer newLocation = oldToNewReferencesLookup.get(Integer.valueOf(persistPointersOffset));
if(newLocation == null) {
throw new RuntimeException("Couldn't find the new location of the PersistPtr that used to be at " + persistPointersOffset);
}