private static final POILogger logger = POILogFactory.getLogger(VariantSupport.class);
- private static boolean logUnsupportedTypes = false;
+ private static boolean logUnsupportedTypes;
/**
* Keeps a list of the variant types an "unsupported" message has already
return uniString.toJavaString();
// if(l1 < 0) {
- /**
+ /*
* YK: reading the ClipboardData packet (VT_CF) is not quite
* correct. The size of the data is determined by the first four
* bytes of the packet while the current implementation calculates
private void checkNotPresent(Record rec) {
if (rec != null) {
- throw new RecordFormatException("Duplicate PageSettingsBlock record (sid=0x"
+ throw new org.apache.poi.util.RecordFormatException("Duplicate PageSettingsBlock record (sid=0x"
+ Integer.toHexString(rec.getSid()) + ")");
}
}
throw new IllegalStateException("This page settings block already has a header/footer record");
}
if (rec.getSid() != HeaderFooterRecord.sid) {
- throw new RecordFormatException("Unexpected header-footer record sid: 0x" + Integer.toHexString(rec.getSid()));
+ throw new org.apache.poi.util.RecordFormatException("Unexpected header-footer record sid: 0x" + Integer.toHexString(rec.getSid()));
}
_headerFooter = rec;
}
*
* @param rs the RecordStream to read from
*
- * @throws RecordFormatException if any PSB record encountered has the same type (sid) as
+ * @throws org.apache.poi.util.RecordFormatException if any PSB record encountered has the same type (sid) as
* a record that is already part of this PageSettingsBlock
*/
public void addLateRecords(RecordStream rs) {
* unless you're comparing which one is which)
*/
@Override
- public short getIndex()
- {
+ public short getIndex() {
return _index;
}
@Deprecated
@Removal(version="3.17")
@Override
- public void setBorderLeft(short border)
- {
+ public void setBorderLeft(short border) {
_format.setIndentNotParentBorder(true);
_format.setBorderLeft(border);
}
/**
* Predefined HSSFColors with their given palette index (and an optional 2nd index)
- *
+ *
* @since POI 3.16 beta 2
*/
public enum HSSFColorPredefined {
public String getHexString() {
return color.getHexString();
}
-
+
/**
* @return (a copy of) the HSSFColor assigned to the enum
*/
*
* @return a Map containing all colors keyed by String gnumeric-like triplets
*/
- public final static Map<String,HSSFColor> getTripletHash()
+ public static Map<String,HSSFColor> getTripletHash()
{
return createColorsByHexStringMap();
}
/**
* Maps the Enums to the HSSFColor subclasses, in cases of user code evaluating the classname
- *
+ *
* @deprecated in 3.16 - remove mapping when subclasses are removed and access
* HSSFColorPredfined.values() directly (but exclude AUTOMATIC)
*/
public class HexRead {
/**
* This method reads hex data from a filename and returns a byte array.
- * The file may contain line comments that are preceeded with a # symbol.
+ * The file may contain line comments that are preceded with a # symbol.
*
* @param filename The filename to read
* @return The bytes read from the file.
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
+import java.io.*;
import javax.imageio.ImageIO;
graphics.dispose();
- FileOutputStream out = new FileOutputStream(outFile);
+ OutputStream out = new FileOutputStream(outFile);
try {
ImageIO.write(img, "png", out);
} finally {
/**
* whether temp files should be compressed.
*/
- private boolean _compressTmpFiles = false;
+ private boolean _compressTmpFiles;
/**
* shared string table - a cache of strings in this workbook
@Removal(version="3.17")
public Font findFont(short boldWeight, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline)
{
+ //noinspection deprecation
return _wb.findFont(boldWeight, color, fontHeight, name, italic, strikeout, typeOffset, underline);
}
@Override
@Deprecated
@Removal(version="3.18")
- public Name getNameAt(int nameIndex)
- {
+ public Name getNameAt(int nameIndex) {
+ //noinspection deprecation
return _wb.getNameAt(nameIndex);
}
@Override
@Deprecated
@Removal(version="3.18")
- public int getNameIndex(String name)
- {
+ public int getNameIndex(String name) {
+ //noinspection deprecation
return _wb.getNameIndex(name);
}
@Override
@Deprecated
@Removal(version="3.18")
- public void removeName(int index)
- {
+ public void removeName(int index) {
+ //noinspection deprecation
_wb.removeName(index);
}
@Override
@Deprecated
@Removal(version="3.18")
- public void removeName(String name)
- {
+ public void removeName(String name) {
+ //noinspection deprecation
_wb.removeName(name);
}
* formulas such as "[MyOtherWorkbook]Sheet3!$A$5" to be added to the
* file, for workbooks not already referenced.
*
+ * Note: this is not implemented and thus currently throws an Exception stating this.
+ *
* @param name The name the workbook will be referenced as in formulas
* @param workbook The open workbook to fetch the link required information from
+ *
+ * @throws RuntimeException stating that this method is not implemented yet.
*/
@Override
@NotImplemented
* formulas such as "[MyOtherWorkbook.xlsx]Sheet3!$A$5" to be added to the
* file, for workbooks not already linked / referenced.
*
+ * Note: this is not implemented and thus currently throws an Exception stating this.
+ *
* @param name The name the workbook will be referenced as in formulas
* @param workbook The open workbook to fetch the link required information from
+ *
+ * @throws RuntimeException stating that this method is not implemented yet.
*/
@Override
@NotImplemented
processEndnoteAutonumbered( doc, noteIndex, block,
noteTextRange );
- return;
}
}
}
private final HtmlDocumentFacade htmlDocumentFacade;
- private Element notes = null;
+ private Element notes;
/**
* Creates new instance of {@link WordToHtmlConverter}. Can be used for
for ( char c : text.toCharArray() )
{
if ( c < 30 )
- stringBuilder
- .append( "\\0x" + Integer.toHexString( c ) );
+ stringBuilder.append("\\0x").append(Integer.toHexString(c));
else
stringBuilder.append( c );
}
}
// Process the first argument as a file
- FileInputStream fin = new FileInputStream( args[0] );
+ InputStream fin = new FileInputStream( args[0] );
WordExtractor extractor = new WordExtractor( fin );
try {
System.out.println( extractor.getText() );
/**
* Represents embedded picture extracted from Word Document
*/
-public final class Picture
-{
+public final class Picture {
+ private static final POILogger log = POILogFactory
+ .getLogger( Picture.class );
+
public static final byte[] COMPRESSED1 = { (byte) 0xFE, 0x78, (byte) 0xDA };
public static final byte[] COMPRESSED2 = { (byte) 0xFE, 0x78, (byte) 0x9C };
public static final byte[] IHDR = new byte[] { 'I', 'H', 'D', 'R' };
- private static final POILogger log = POILogFactory
- .getLogger( Picture.class );
+
@Deprecated
private static final byte[] PNG = new byte[] { (byte) 0x89, 0x50, 0x4E,
0x47, 0x0D, 0x0A, 0x1A, 0x0A };
}
/**
- * Returns picture's content as it stored in Word file, i.e. possibly in
+ * Returns picture's content as stored in the Word file, i.e. possibly in
* compressed form.
*
- * @return picture's content as it stored in Word file
+ * @return picture's content as it stored in Word file or an empty byte array
+ * if it cannot be read.
*/
public byte[] getRawContent()
{
new DOMSource( wordToHtmlConverter.getDocument() ),
new StreamResult( stringWriter ));
- String result = stringWriter.toString();
- return result;
+ return stringWriter.toString();
}
@Test
* was added while fixing bug 47199. All existing POI test samples comply with this requirement.
*/
public void testDuplicatePSBRecord_bug47199() {
-
// Hypothetical setup of PSB records which should cause POI to crash
Record[] recs = {
new HeaderRecord("&LSales Figures"),
try {
new PageSettingsBlock(rs);
throw new AssertionFailedError("Identified bug 47199b - duplicate PSB records should not be allowed");
- } catch (RecordFormatException e) {
- if (e.getMessage().equals("Duplicate PageSettingsBlock record (sid=0x14)")) {
- // expected during successful test
- } else {
+ } catch (org.apache.poi.util.RecordFormatException e) {
+ if (!e.getMessage().equals("Duplicate PageSettingsBlock record (sid=0x14)")) {
throw new AssertionFailedError("Expected RecordFormatException due to duplicate PSB record");
}
}
PageSettingsBlock psb;
try {
psb = new PageSettingsBlock(rs);
- } catch (RecordFormatException e) {
+ } catch (org.apache.poi.util.RecordFormatException e) {
if ("Duplicate PageSettingsBlock record (sid=0x4d)".equals(e.getMessage())) {
throw new AssertionFailedError("Identified bug 47415");
}