import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.usermodel.CellType;
-import org.apache.poi.util.BitField;
-import org.apache.poi.util.BitFieldFactory;
-import org.apache.poi.util.HexDump;
-import org.apache.poi.util.LittleEndianInput;
-import org.apache.poi.util.LittleEndianOutput;
+import org.apache.poi.util.*;
/**
* Formula Record (0x0006).
private SpecialCachedValue(byte[] data) {
_variableData = data;
}
+
public int getTypeCode() {
return _variableData[0];
}
case EMPTY:
break;
default:
- throw new RecordFormatException("Bad special value code (" + result[0] + ")");
+ throw new org.apache.poi.util.RecordFormatException("Bad special value code (" + result[0] + ")");
}
return new SpecialCachedValue(result);
}
+
public void serialize(LittleEndianOutput out) {
out.write(_variableData);
out.writeShort(0xFFFF);
}
+
public String formatDebugString() {
return formatValue() + ' ' + HexDump.toHex(_variableData);
}
+
private String formatValue() {
int typeCode = getTypeCode();
switch (typeCode) {
- case STRING: return "<string>";
- case BOOLEAN: return getDataValue() == 0 ? "FALSE" : "TRUE";
- case ERROR_CODE: return ErrorEval.getText(getDataValue());
- case EMPTY: return "<empty>";
+ case STRING:
+ return "<string>";
+ case BOOLEAN:
+ return getDataValue() == 0 ? "FALSE" : "TRUE";
+ case ERROR_CODE:
+ return ErrorEval.getText(getDataValue());
+ case EMPTY:
+ return "<empty>";
}
return "#error(type=" + typeCode + ")#";
}
+
private int getDataValue() {
return _variableData[DATA_INDEX];
}
+
public static SpecialCachedValue createCachedEmptyValue() {
return create(EMPTY, 0);
}
+
public static SpecialCachedValue createForString() {
return create(STRING, 0);
}
+
public static SpecialCachedValue createCachedBoolean(boolean b) {
return create(BOOLEAN, b ? 1 : 0);
}
+
public static SpecialCachedValue createCachedErrorCode(int errorCode) {
return create(ERROR_CODE, errorCode);
}
+
private static SpecialCachedValue create(int code, int data) {
byte[] vd = {
(byte) code,
};
return new SpecialCachedValue(vd);
}
+
@Override
public String toString() {
- StringBuffer sb = new StringBuffer(64);
- sb.append(getClass().getName());
- sb.append('[').append(formatValue()).append(']');
- return sb.toString();
+ return getClass().getName() + '[' + formatValue() + ']';
}
+
public int getValueType() {
int typeCode = getTypeCode();
switch (typeCode) {
}
throw new IllegalStateException("Unexpected type id (" + typeCode + ")");
}
+
public boolean getBooleanValue() {
if (getTypeCode() != BOOLEAN) {
throw new IllegalStateException("Not a boolean cached value - " + formatValue());
}
return getDataValue() != 0;
}
+
public int getErrorValue() {
if (getTypeCode() != ERROR_CODE) {
throw new IllegalStateException("Not an error cached value - " + formatValue());
public FormulaRecord(RecordInputStream ris) {
super(ris);
- LittleEndianInput in = ris;
- long valueLongBits = in.readLong();
- field_5_options = in.readShort();
+ long valueLongBits = ris.readLong();
+ field_5_options = ris.readShort();
specialCachedValue = SpecialCachedValue.create(valueLongBits);
if (specialCachedValue == null) {
field_4_value = Double.longBitsToDouble(valueLongBits);
}
- field_6_zero = in.readInt();
+ field_6_zero = ris.readInt();
- int field_7_expression_len = in.readShort(); // this length does not include any extra array data
- int nBytesAvailable = in.available();
- field_8_parsed_expr = Formula.read(field_7_expression_len, in, nBytesAvailable);
+ int field_7_expression_len = ris.readShort(); // this length does not include any extra array data
+ int nBytesAvailable = ris.available();
+ field_8_parsed_expr = Formula.read(field_7_expression_len, ris, nBytesAvailable);
}
/**
* evaluation.
*/
public boolean hasCachedResultString() {
- if (specialCachedValue == null) {
- return false;
- }
- return specialCachedValue.getTypeCode() == SpecialCachedValue.STRING;
+ return specialCachedValue != null &&
+ specialCachedValue.getTypeCode() == SpecialCachedValue.STRING;
}
public int getCachedResultType() {
protected List<DrawTextFragment> lines = new ArrayList<DrawTextFragment>();\r
protected String rawText;\r
protected DrawTextFragment bullet;\r
- protected int autoNbrIdx = 0;\r
+ protected int autoNbrIdx;\r
\r
/**\r
* the highest line in this paragraph. Used for line spacing.\r
/**\r
* break text into lines, each representing a line of text that fits in the wrapping width\r
*\r
- * @param graphics\r
+ * @param graphics The drawing context for computing text-lengths.\r
*/\r
protected void breakText(Graphics2D graphics){\r
lines.clear();\r
*/\r
@SuppressWarnings("rawtypes")\r
private PlaceableShape<?,?> getParagraphShape() {\r
- PlaceableShape<?,?> ps = new PlaceableShape(){\r
+ return new PlaceableShape(){\r
public ShapeContainer<?,?> getParent() { return null; }\r
public Rectangle2D getAnchor() { return paragraph.getParentShape().getAnchor(); }\r
public void setAnchor(Rectangle2D anchor) {}\r
public boolean getFlipVertical() { return false; }\r
public Sheet<?,?> getSheet() { return paragraph.getParentShape().getSheet(); }\r
};\r
- return ps;\r
}\r
\r
protected AttributedString getAttributedString(Graphics2D graphics, StringBuilder text){\r
\r
return string;\r
}\r
- \r
+\r
protected boolean isHSLF() {\r
return paragraph.getClass().getName().contains("HSLF");\r
}\r
/**
* Creates a new document builder, with sensible defaults
+ *
+ * @throws IllegalStateException If creating the DocumentBuilder fails, e.g.
+ * due to {@link ParserConfigurationException}.
*/
public static synchronized DocumentBuilder newDocumentBuilder() {
try {
/**
* Raw picture data, normally attached to a WordprocessingML Drawing.
* As a rule, pictures are stored in the /word/media/ part of a WordprocessingML package.
- */
-
-/**
+ *
* @author Philipp Epp
*/
public class XWPFPictureData extends POIXMLDocumentPart {
/**
- * Relationships for each known picture type\r
- */\r
- protected static final POIXMLRelation[] RELATIONS;\r
-\r
- static {\r
- RELATIONS = new POIXMLRelation[13];\r
- RELATIONS[Document.PICTURE_TYPE_EMF] = XWPFRelation.IMAGE_EMF;\r
+ * Relationships for each known picture type
+ */
+ protected static final POIXMLRelation[] RELATIONS;
+
+ static {
+ RELATIONS = new POIXMLRelation[13];
+ RELATIONS[Document.PICTURE_TYPE_EMF] = XWPFRelation.IMAGE_EMF;
RELATIONS[Document.PICTURE_TYPE_WMF] = XWPFRelation.IMAGE_WMF;
RELATIONS[Document.PICTURE_TYPE_PICT] = XWPFRelation.IMAGE_PICT;
RELATIONS[Document.PICTURE_TYPE_JPEG] = XWPFRelation.IMAGE_JPEG;
RELATIONS[Document.PICTURE_TYPE_WPG] = XWPFRelation.IMAGE_WPG;
}
- private Long checksum = null;
-\r
- /**\r
- * Create a new XWPFGraphicData node\r
- */\r
- protected XWPFPictureData() {\r
- super();\r
+ private Long checksum;
+
+ /**
+ * Create a new XWPFGraphicData node
+ */
+ protected XWPFPictureData() {
+ super();
}
/**
* You can grab the picture data directly from the underlying package part as follows:
* <br/>
* <code>
- * InputStream is = getPackagePart().getInputStream();\r
- * </code>\r
- * </p>\r
- *\r
- * @return the Picture data.\r
- */\r
- public byte[] getData() {\r
+ * InputStream is = getPackagePart().getInputStream();
+ * </code>
+ * </p>
+ *
+ * @return the Picture data.
+ */
+ public byte[] getData() {
try {
return IOUtils.toByteArray(getPackagePart().getInputStream());
} catch (IOException e) {
String name = getPackagePart().getPartName().getName();
return name.substring(name.lastIndexOf('/') + 1);
}
-\r
- /**\r
- * Suggests a file extension for this image.\r
- *\r
- * @return the file extension.\r
- */\r
- public String suggestFileExtension() {\r
+
+ /**
+ * Suggests a file extension for this image.
+ *
+ * @return the file extension.
+ */
+ public String suggestFileExtension() {
return getPackagePart().getPartName().getExtension();
}
-\r
- /**\r
- * Return an integer constant that specifies type of this picture\r
- *\r
- * @return an integer constant that specifies type of this picture\r
- * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_EMF\r
- * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_WMF\r
+
+ /**
+ * Return an integer constant that specifies type of this picture
+ *
+ * @return an integer constant that specifies type of this picture
+ * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_EMF
+ * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_WMF
* @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_PICT
* @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_JPEG
* @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_PNG
@Override
public boolean equals(Object obj) {
- /**
+ /*
* In case two objects ARE equal, but its not the same instance, this
* implementation will always run through the whole
* byte-array-comparison before returning true. If this will turn into a
if (!ownPackage.equals(foreignPackage)) {
return false;
- }\r
- }\r
- }\r
-\r
- Long foreignChecksum = picData.getChecksum();\r
- Long localChecksum = getChecksum();\r
-\r
+ }
+ }
+ }
+
+ Long foreignChecksum = picData.getChecksum();
+ Long localChecksum = getChecksum();
+
if (!(localChecksum.equals(foreignChecksum))) {
return false;
}
@Override
public int hashCode() {
return getChecksum().hashCode();
- }\r
-\r
- /**\r
- * *PictureData objects store the actual content in the part directly without keeping a\r
- * copy like all others therefore we need to handle them differently.\r
- */\r
- @Override\r
+ }
+
+ /**
+ * *PictureData objects store the actual content in the part directly without keeping a
+ * copy like all others therefore we need to handle them differently.
+ */
+ @Override
protected void prepareForCommit() {
// do not clear the part here
}
limitations under the License.
====================================================================
-->
+<!--suppress DeprecatedClassUsageInspection -->
<FindBugsFilter>
<Match>
<Bug code="EI,EI2" pattern="CN_IMPLEMENTS_CLONE_BUT_NOT_CLONEABLE,MS_PKGPROTECT,MS_MUTABLE_ARRAY"/>