public void setPictureData(byte[] pictureData) {
if (pictureData == null) {
- throw new NullPointerException("picture data can't be null");
+ throw new IllegalArgumentException("picture data can't be null");
}
field_pictureData = pictureData.clone();
}
/**
* Any data recording this record.
*/
- public void setRemainingData( byte[] remainingData )
- {
- this.remainingData = remainingData;
+ public void setRemainingData( byte[] remainingData ) {
+ this.remainingData = (remainingData == null)
+ ? new byte[0]
+ : remainingData.clone();
}
}
* A complex property differs from a simple property in that the data can not fit inside a 32 bit
* integer. See the specification for more detailed information regarding exactly what is
* stored here.
- *
- * @author Glen Stampoultzis
*/
public class EscherComplexProperty extends EscherProperty {
// TODO - make private and final
*/
public EscherComplexProperty(short id, byte[] complexData) {
super(id);
- _complexData = complexData;
+ if (complexData == null) {
+ throw new IllegalArgumentException("complexData can't be null");
+ }
+ _complexData = complexData.clone();
}
/**
*/
public EscherComplexProperty(short propertyNumber, boolean isBlipId, byte[] complexData) {
super(propertyNumber, true, isBlipId);
- _complexData = complexData;
+ if (complexData == null) {
+ throw new IllegalArgumentException("complexData can't be null");
+ }
+ _complexData = complexData.clone();
}
/**
public String toString() {
- StringBuffer field_5_string = new StringBuffer();
+ StringBuilder field_5_string = new StringBuilder();
if(field_5_fileIdClusters != null) for (int i = 0; i < field_5_fileIdClusters.length; i++) {
field_5_string.append(" DrawingGroupId").append(i+1).append(": ");
field_5_string.append(field_5_fileIdClusters[i].field_1_drawingGroupId);
}
public void setFileIdClusters(FileIdCluster[] fileIdClusters) {
- this.field_5_fileIdClusters = fileIdClusters;
+ this.field_5_fileIdClusters = fileIdClusters.clone();
}
public void addCluster(int dgId, int numShapedUsed) {
String result = "";
result += (short) ( n32 >> 16 );
result += '.';
- result += (short) ( n32 & (short) 0xFFFF );
+ result += (short) ( n32 & 0xFFFF );
return result;
}
private static final int HEADER_SIZE = 8;
- private byte[] field_1_UID;
+ private final byte[] field_1_UID = new byte[16];
/**
* The primary UID is only saved to disk if (blip_instance ^ blip_signature == 1)
*/
- private byte[] field_2_UID;
+ private final byte[] field_2_UID = new byte[16];
private int field_2_cb;
private int field_3_rcBounds_x1;
private int field_3_rcBounds_y1;
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
int bytesAfterHeader = readHeader( data, offset );
int pos = offset + HEADER_SIZE;
- field_1_UID = new byte[16];
System.arraycopy( data, pos, field_1_UID, 0, 16 ); pos += 16;
if((getOptions() ^ getSignature()) == 0x10){
- field_2_UID = new byte[16];
System.arraycopy( data, pos, field_2_UID, 0, 16 ); pos += 16;
}
}
public void setUID(byte[] uid) {
- field_1_UID = uid;
+ if (uid == null || uid.length != 16) {
+ throw new IllegalArgumentException("uid must be byte[16]");
+ }
+ System.arraycopy(uid, 0, field_1_UID, 0, field_1_UID.length);
}
- public byte[] getPrimaryUID()
- {
+ public byte[] getPrimaryUID() {
return field_2_UID;
}
public void setPrimaryUID(byte[] primaryUID) {
- field_2_UID = primaryUID;
+ if (primaryUID == null || primaryUID.length != 16) {
+ throw new IllegalArgumentException("primaryUID must be byte[16]");
+ }
+ System.arraycopy(primaryUID, 0, field_2_UID, 0, field_2_UID.length);
}
public int getUncompressedSize() {
private static final int HEADER_SIZE = 8;
- private byte[] field_1_UID;
+ private final byte[] field_1_UID = new byte[16];
private int field_2_cb;
private int field_3_rcBounds_x1;
private int field_3_rcBounds_y1;
int bytesAfterHeader = readHeader(data, offset);
int pos = offset + HEADER_SIZE;
- field_1_UID = new byte[16];
System.arraycopy( data, pos, field_1_UID, 0, 16 ); pos += 16;
field_2_cb = LittleEndian.getInt( data, pos ); pos += 4;
field_3_rcBounds_x1 = LittleEndian.getInt( data, pos ); pos += 4;
}
public void setUID(byte[] uid) {
- this.field_1_UID = uid;
+ if (uid == null || uid.length != 16) {
+ throw new IllegalArgumentException("uid must be byte[16]");
+ }
+ System.arraycopy(uid, 0, field_1_UID, 0, field_1_UID.length);
}
public int getUncompressedSize() {
package org.apache.poi.dev;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.InputStreamReader;
-import java.io.Reader;
import java.util.Locale;
import java.util.Properties;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
-import org.apache.poi.util.StringUtil;
import org.apache.poi.util.XMLHelper;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
private static void generateRecords(String defintionsDir, String recordStyleDir, String destSrcPathDir, String testSrcPathDir)
throws Exception {
- File definitionsFile = new File(defintionsDir);
+ File definitionsFiles[] = new File(defintionsDir).listFiles();
+ if (definitionsFiles == null) {
+ System.err.println(defintionsDir+" is not a directory.");
+ return;
+ }
- for (int i = 0; i < definitionsFile.listFiles().length; i++) {
- File file = definitionsFile.listFiles()[i];
+ for (File file : definitionsFiles) {
if (file.isFile() &&
(file.getName().endsWith("_record.xml") ||
file.getName().endsWith("_type.xml")
private static void transform(final File in, final File out, final File xslt)
throws FileNotFoundException, TransformerException
{
- final Reader r = new InputStreamReader(new FileInputStream(xslt), StringUtil.UTF8);
- final StreamSource ss = new StreamSource(r);
+ final StreamSource ss = new StreamSource(xslt);
final TransformerFactory tf = TransformerFactory.newInstance();
final Transformer t;
try
\r
package org.apache.poi.sl.usermodel;\r
\r
-import java.awt.Insets;\r
-\r
/**\r
* This is a replacement for {@link java.awt.Insets} which works on doubles\r
* instead of ints\r
* @since JDK1.1\r
*/\r
public boolean equals(Object obj) {\r
- if (obj instanceof Insets) {\r
- Insets insets = (Insets)obj;\r
+ if (obj instanceof Insets2D) {\r
+ Insets2D insets = (Insets2D)obj;\r
return ((top == insets.top) && (left == insets.left) &&\r
(bottom == insets.bottom) && (right == insets.right));\r
}\r
* Parser for java dates.
*/
public class DateParser {
- public DateParser instance = new DateParser();
-
private DateParser() {
// enforcing singleton
}
if (d==0) {
return 1;
}
- if (d>0) {
- return calcOdd(d);
- }
- return -calcOdd(-d);
+ return (d>0) ? calcOdd(d) : -calcOdd(-d);
}
private static long calcOdd(double d) {
double dpm1 = d+1;
long x = ((long) dpm1) & PARITY_MASK;
- if (x == dpm1) {
- return x-1;
- }
- return x + 1;
+ return ( Double.compare(x, dpm1) == 0 ) ? x-1 : x+1;
}
}
}
public int getIndentFromLeft() {
- return getIndentFromLeft();
+ return getIndentationLeft();
}
public void setIndentFromLeft(int dxaLeft) {
}
public int getIndentFromRight() {
- return getIndentFromRight();
+ return getIndentationRight();
}
public void setIndentFromRight(int dxaRight) {
{
_listener = listener;
}
- public void mainDocument(byte[] mainDocument)
- {
- _mainDocument = mainDocument;
+ public void mainDocument(byte[] mainDocument) {
+ if (mainDocument == null) {
+ throw new IllegalArgumentException("mainDocument is null.");
+ }
+ _mainDocument = mainDocument.clone();
}
- public void tableStream(byte[] tableStream)
- {
- _tableStream = tableStream;
+ public void tableStream(byte[] tableStream) {
+ if (tableStream == null) {
+ throw new IllegalArgumentException("tableStream is null.");
+ }
+ _tableStream = tableStream.clone();
}
public void miscellaneous(int fcMin, int ccpText, int ccpFtn, int fcPlcfhdd, int lcbPlcfhdd)
{
System.arraycopy(std, grupxStart + offset + 2, _chpx, 0, upxSize);
}
- if(upxSize % 2 == 1)
+ if((upxSize & 2) == 1)
{
++upxSize;
}