You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/07/19 21:00:38 UTC
svn commit: r1691843 [6/30] - in /poi/branches/common_sl: ./ .settings/
legal/ osgi/ osgi/src/ src/examples/src/org/apache/poi/hpsf/examples/
src/examples/src/org/apache/poi/hssf/usermodel/examples/
src/examples/src/org/apache/poi/ss/examples/ src/exam...
Modified: poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java Sun Jul 19 19:00:32 2015
@@ -17,382 +17,388 @@
package org.apache.poi.hssf.usermodel;
-import org.apache.poi.hssf.record.CFRuleRecord;
+import org.apache.poi.hssf.record.CFRuleBase;
import org.apache.poi.hssf.record.cf.FontFormatting;
+import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.ss.usermodel.Color;
/**
* High level representation for Font Formatting component
* of Conditional Formatting settings
*/
-public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.FontFormatting
-{
-
- /** Underline type - None */
- public final static byte U_NONE = FontFormatting.U_NONE;
- /** Underline type - Single */
- public final static byte U_SINGLE = FontFormatting.U_SINGLE;
- /** Underline type - Double */
- public final static byte U_DOUBLE = FontFormatting.U_DOUBLE;
- /** Underline type - Single Accounting */
- public final static byte U_SINGLE_ACCOUNTING = FontFormatting.U_SINGLE_ACCOUNTING;
- /** Underline type - Double Accounting */
- public final static byte U_DOUBLE_ACCOUNTING = FontFormatting.U_DOUBLE_ACCOUNTING;
-
- private final FontFormatting fontFormatting;
-
- protected HSSFFontFormatting(CFRuleRecord cfRuleRecord)
- {
- this.fontFormatting = cfRuleRecord.getFontFormatting();
- }
-
- protected FontFormatting getFontFormattingBlock()
- {
- return fontFormatting;
- }
-
- /**
- * get the type of super or subscript for the font
- *
- * @return super or subscript option
- * @see #SS_NONE
- * @see #SS_SUPER
- * @see #SS_SUB
- */
- public short getEscapementType()
- {
- return fontFormatting.getEscapementType();
- }
-
- /**
- * @return font color index
- */
- public short getFontColorIndex()
- {
- return fontFormatting.getFontColorIndex();
- }
-
- /**
- * gets the height of the font in 1/20th point units
- *
- * @return fontheight (in points/20); or -1 if not modified
- */
- public int getFontHeight()
- {
- return fontFormatting.getFontHeight();
- }
-
- /**
- * get the font weight for this font (100-1000dec or 0x64-0x3e8). Default is
- * 0x190 for normal and 0x2bc for bold
- *
- * @return bw - a number between 100-1000 for the fonts "boldness"
- */
-
- public short getFontWeight()
- {
- return fontFormatting.getFontWeight();
- }
-
- /**
- * @see org.apache.poi.hssf.record.cf.FontFormatting#getRawRecord()
- */
- protected byte[] getRawRecord()
- {
- return fontFormatting.getRawRecord();
- }
-
- /**
- * get the type of underlining for the font
- *
- * @return font underlining type
- *
- * @see #U_NONE
- * @see #U_SINGLE
- * @see #U_DOUBLE
- * @see #U_SINGLE_ACCOUNTING
- * @see #U_DOUBLE_ACCOUNTING
- */
- public short getUnderlineType()
- {
- return fontFormatting.getUnderlineType();
- }
-
- /**
- * get whether the font weight is set to bold or not
- *
- * @return bold - whether the font is bold or not
- */
- public boolean isBold()
- {
- return fontFormatting.isFontWeightModified() && fontFormatting.isBold();
- }
-
- /**
- * @return true if escapement type was modified from default
- */
- public boolean isEscapementTypeModified()
- {
- return fontFormatting.isEscapementTypeModified();
- }
-
- /**
- * @return true if font cancellation was modified from default
- */
- public boolean isFontCancellationModified()
- {
- return fontFormatting.isFontCancellationModified();
- }
-
- /**
- * @return true if font outline type was modified from default
- */
- public boolean isFontOutlineModified()
- {
- return fontFormatting.isFontOutlineModified();
- }
-
- /**
- * @return true if font shadow type was modified from default
- */
- public boolean isFontShadowModified()
- {
- return fontFormatting.isFontShadowModified();
- }
-
- /**
- * @return true if font style was modified from default
- */
- public boolean isFontStyleModified()
- {
- return fontFormatting.isFontStyleModified();
- }
-
- /**
- * @return true if font style was set to <i>italic</i>
- */
- public boolean isItalic()
- {
- return fontFormatting.isFontStyleModified() && fontFormatting.isItalic();
- }
-
- /**
- * @return true if font outline is on
- */
- public boolean isOutlineOn()
- {
- return fontFormatting.isFontOutlineModified() && fontFormatting.isOutlineOn();
- }
-
- /**
- * @return true if font shadow is on
- */
- public boolean isShadowOn()
- {
- return fontFormatting.isFontOutlineModified() && fontFormatting.isShadowOn();
- }
-
- /**
- * @return true if font strikeout is on
- */
- public boolean isStruckout()
- {
- return fontFormatting.isFontCancellationModified() && fontFormatting.isStruckout();
- }
-
- /**
- * @return true if font underline type was modified from default
- */
- public boolean isUnderlineTypeModified()
- {
- return fontFormatting.isUnderlineTypeModified();
- }
-
- /**
- * @return true if font weight was modified from default
- */
- public boolean isFontWeightModified()
- {
- return fontFormatting.isFontWeightModified();
- }
-
- /**
- * set font style options.
- *
- * @param italic - if true, set posture style to italic, otherwise to normal
- * @param bold if true, set font weight to bold, otherwise to normal
- */
-
- public void setFontStyle(boolean italic, boolean bold)
- {
- boolean modified = italic || bold;
- fontFormatting.setItalic(italic);
- fontFormatting.setBold(bold);
- fontFormatting.setFontStyleModified(modified);
- fontFormatting.setFontWieghtModified(modified);
- }
-
- /**
- * set font style options to default values (non-italic, non-bold)
- */
- public void resetFontStyle()
- {
- setFontStyle(false,false);
- }
-
- /**
- * set the escapement type for the font
- *
- * @param escapementType super or subscript option
- * @see #SS_NONE
- * @see #SS_SUPER
- * @see #SS_SUB
- */
- public void setEscapementType(short escapementType)
- {
- switch(escapementType)
- {
- case HSSFFontFormatting.SS_SUB:
- case HSSFFontFormatting.SS_SUPER:
- fontFormatting.setEscapementType(escapementType);
- fontFormatting.setEscapementTypeModified(true);
- break;
- case HSSFFontFormatting.SS_NONE:
- fontFormatting.setEscapementType(escapementType);
- fontFormatting.setEscapementTypeModified(false);
- break;
- default:
- }
- }
-
- /**
- * @param modified
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setEscapementTypeModified(boolean)
- */
- public void setEscapementTypeModified(boolean modified)
- {
- fontFormatting.setEscapementTypeModified(modified);
- }
-
- /**
- * @param modified
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontCancellationModified(boolean)
- */
- public void setFontCancellationModified(boolean modified)
- {
- fontFormatting.setFontCancellationModified(modified);
- }
-
- /**
- * @param fci
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontColorIndex(short)
- */
- public void setFontColorIndex(short fci)
- {
- fontFormatting.setFontColorIndex(fci);
- }
-
- /**
- * @param height
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontHeight(int)
- */
- public void setFontHeight(int height)
- {
- fontFormatting.setFontHeight(height);
- }
-
- /**
- * @param modified
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontOutlineModified(boolean)
- */
- public void setFontOutlineModified(boolean modified)
- {
- fontFormatting.setFontOutlineModified(modified);
- }
-
- /**
- * @param modified
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontShadowModified(boolean)
- */
- public void setFontShadowModified(boolean modified)
- {
- fontFormatting.setFontShadowModified(modified);
- }
-
- /**
- * @param modified
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontStyleModified(boolean)
- */
- public void setFontStyleModified(boolean modified)
- {
- fontFormatting.setFontStyleModified(modified);
- }
-
- /**
- * @param on
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setOutline(boolean)
- */
- public void setOutline(boolean on)
- {
- fontFormatting.setOutline(on);
- fontFormatting.setFontOutlineModified(on);
- }
-
- /**
- * @param on
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setShadow(boolean)
- */
- public void setShadow(boolean on)
- {
- fontFormatting.setShadow(on);
- fontFormatting.setFontShadowModified(on);
- }
-
- /**
- * @param strike
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setStrikeout(boolean)
- */
- public void setStrikeout(boolean strike)
- {
- fontFormatting.setStrikeout(strike);
- fontFormatting.setFontCancellationModified(strike);
- }
-
- /**
- * set the type of underlining type for the font
- *
- * @param underlineType super or subscript option
- *
- * @see #U_NONE
- * @see #U_SINGLE
- * @see #U_DOUBLE
- * @see #U_SINGLE_ACCOUNTING
- * @see #U_DOUBLE_ACCOUNTING
- */
- public void setUnderlineType(short underlineType)
- {
- switch(underlineType)
- {
- case HSSFFontFormatting.U_SINGLE:
- case HSSFFontFormatting.U_DOUBLE:
- case HSSFFontFormatting.U_SINGLE_ACCOUNTING:
- case HSSFFontFormatting.U_DOUBLE_ACCOUNTING:
- fontFormatting.setUnderlineType(underlineType);
- setUnderlineTypeModified(true);
- break;
-
- case HSSFFontFormatting.U_NONE:
- fontFormatting.setUnderlineType(underlineType);
- setUnderlineTypeModified(false);
- break;
- default:
- }
- }
-
- /**
- * @param modified
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setUnderlineTypeModified(boolean)
- */
- public void setUnderlineTypeModified(boolean modified)
- {
- fontFormatting.setUnderlineTypeModified(modified);
- }
+public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.FontFormatting {
+ /** Underline type - None */
+ public final static byte U_NONE = FontFormatting.U_NONE;
+ /** Underline type - Single */
+ public final static byte U_SINGLE = FontFormatting.U_SINGLE;
+ /** Underline type - Double */
+ public final static byte U_DOUBLE = FontFormatting.U_DOUBLE;
+ /** Underline type - Single Accounting */
+ public final static byte U_SINGLE_ACCOUNTING = FontFormatting.U_SINGLE_ACCOUNTING;
+ /** Underline type - Double Accounting */
+ public final static byte U_DOUBLE_ACCOUNTING = FontFormatting.U_DOUBLE_ACCOUNTING;
+
+ private final FontFormatting fontFormatting;
+ private final HSSFWorkbook workbook;
+
+ protected HSSFFontFormatting(CFRuleBase cfRuleRecord, HSSFWorkbook workbook) {
+ this.fontFormatting = cfRuleRecord.getFontFormatting();
+ this.workbook = workbook;
+ }
+
+ protected FontFormatting getFontFormattingBlock() {
+ return fontFormatting;
+ }
+
+ /**
+ * get the type of super or subscript for the font
+ *
+ * @return super or subscript option
+ * @see #SS_NONE
+ * @see #SS_SUPER
+ * @see #SS_SUB
+ */
+ public short getEscapementType()
+ {
+ return fontFormatting.getEscapementType();
+ }
+
+ /**
+ * @return font color index
+ */
+ public short getFontColorIndex()
+ {
+ return fontFormatting.getFontColorIndex();
+ }
+
+ public HSSFColor getFontColor() {
+ return workbook.getCustomPalette().getColor(
+ getFontColorIndex()
+ );
+ }
+
+ public void setFontColor(Color color) {
+ HSSFColor hcolor = HSSFColor.toHSSFColor(color);
+ if (hcolor == null) {
+ fontFormatting.setFontColorIndex((short)0);
+ } else {
+ fontFormatting.setFontColorIndex(hcolor.getIndex());
+ }
+ }
+
+ /**
+ * gets the height of the font in 1/20th point units
+ *
+ * @return fontheight (in points/20); or -1 if not modified
+ */
+ public int getFontHeight() {
+ return fontFormatting.getFontHeight();
+ }
+
+ /**
+ * get the font weight for this font (100-1000dec or 0x64-0x3e8). Default is
+ * 0x190 for normal and 0x2bc for bold
+ *
+ * @return bw - a number between 100-1000 for the fonts "boldness"
+ */
+ public short getFontWeight() {
+ return fontFormatting.getFontWeight();
+ }
+
+ /**
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#getRawRecord()
+ */
+ protected byte[] getRawRecord() {
+ return fontFormatting.getRawRecord();
+ }
+
+ /**
+ * get the type of underlining for the font
+ *
+ * @return font underlining type
+ *
+ * @see #U_NONE
+ * @see #U_SINGLE
+ * @see #U_DOUBLE
+ * @see #U_SINGLE_ACCOUNTING
+ * @see #U_DOUBLE_ACCOUNTING
+ */
+ public short getUnderlineType()
+ {
+ return fontFormatting.getUnderlineType();
+ }
+
+ /**
+ * get whether the font weight is set to bold or not
+ *
+ * @return bold - whether the font is bold or not
+ */
+ public boolean isBold()
+ {
+ return fontFormatting.isFontWeightModified() && fontFormatting.isBold();
+ }
+
+ /**
+ * @return true if escapement type was modified from default
+ */
+ public boolean isEscapementTypeModified()
+ {
+ return fontFormatting.isEscapementTypeModified();
+ }
+
+ /**
+ * @return true if font cancellation was modified from default
+ */
+ public boolean isFontCancellationModified()
+ {
+ return fontFormatting.isFontCancellationModified();
+ }
+
+ /**
+ * @return true if font outline type was modified from default
+ */
+ public boolean isFontOutlineModified()
+ {
+ return fontFormatting.isFontOutlineModified();
+ }
+
+ /**
+ * @return true if font shadow type was modified from default
+ */
+ public boolean isFontShadowModified()
+ {
+ return fontFormatting.isFontShadowModified();
+ }
+
+ /**
+ * @return true if font style was modified from default
+ */
+ public boolean isFontStyleModified()
+ {
+ return fontFormatting.isFontStyleModified();
+ }
+
+ /**
+ * @return true if font style was set to <i>italic</i>
+ */
+ public boolean isItalic()
+ {
+ return fontFormatting.isFontStyleModified() && fontFormatting.isItalic();
+ }
+
+ /**
+ * @return true if font outline is on
+ */
+ public boolean isOutlineOn()
+ {
+ return fontFormatting.isFontOutlineModified() && fontFormatting.isOutlineOn();
+ }
+
+ /**
+ * @return true if font shadow is on
+ */
+ public boolean isShadowOn()
+ {
+ return fontFormatting.isFontOutlineModified() && fontFormatting.isShadowOn();
+ }
+
+ /**
+ * @return true if font strikeout is on
+ */
+ public boolean isStruckout()
+ {
+ return fontFormatting.isFontCancellationModified() && fontFormatting.isStruckout();
+ }
+
+ /**
+ * @return true if font underline type was modified from default
+ */
+ public boolean isUnderlineTypeModified()
+ {
+ return fontFormatting.isUnderlineTypeModified();
+ }
+
+ /**
+ * @return true if font weight was modified from default
+ */
+ public boolean isFontWeightModified()
+ {
+ return fontFormatting.isFontWeightModified();
+ }
+
+ /**
+ * set font style options.
+ *
+ * @param italic - if true, set posture style to italic, otherwise to normal
+ * @param bold if true, set font weight to bold, otherwise to normal
+ */
+
+ public void setFontStyle(boolean italic, boolean bold)
+ {
+ boolean modified = italic || bold;
+ fontFormatting.setItalic(italic);
+ fontFormatting.setBold(bold);
+ fontFormatting.setFontStyleModified(modified);
+ fontFormatting.setFontWieghtModified(modified);
+ }
+
+ /**
+ * set font style options to default values (non-italic, non-bold)
+ */
+ public void resetFontStyle()
+ {
+ setFontStyle(false,false);
+ }
+
+ /**
+ * set the escapement type for the font
+ *
+ * @param escapementType super or subscript option
+ * @see #SS_NONE
+ * @see #SS_SUPER
+ * @see #SS_SUB
+ */
+ public void setEscapementType(short escapementType) {
+ switch(escapementType) {
+ case HSSFFontFormatting.SS_SUB:
+ case HSSFFontFormatting.SS_SUPER:
+ fontFormatting.setEscapementType(escapementType);
+ fontFormatting.setEscapementTypeModified(true);
+ break;
+ case HSSFFontFormatting.SS_NONE:
+ fontFormatting.setEscapementType(escapementType);
+ fontFormatting.setEscapementTypeModified(false);
+ break;
+ default:
+ }
+ }
+
+ /**
+ * @param modified
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setEscapementTypeModified(boolean)
+ */
+ public void setEscapementTypeModified(boolean modified) {
+ fontFormatting.setEscapementTypeModified(modified);
+ }
+
+ /**
+ * @param modified
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontCancellationModified(boolean)
+ */
+ public void setFontCancellationModified(boolean modified)
+ {
+ fontFormatting.setFontCancellationModified(modified);
+ }
+
+ /**
+ * @param fci
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontColorIndex(short)
+ */
+ public void setFontColorIndex(short fci)
+ {
+ fontFormatting.setFontColorIndex(fci);
+ }
+
+ /**
+ * @param height
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontHeight(int)
+ */
+ public void setFontHeight(int height)
+ {
+ fontFormatting.setFontHeight(height);
+ }
+
+ /**
+ * @param modified
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontOutlineModified(boolean)
+ */
+ public void setFontOutlineModified(boolean modified)
+ {
+ fontFormatting.setFontOutlineModified(modified);
+ }
+
+ /**
+ * @param modified
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontShadowModified(boolean)
+ */
+ public void setFontShadowModified(boolean modified)
+ {
+ fontFormatting.setFontShadowModified(modified);
+ }
+
+ /**
+ * @param modified
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontStyleModified(boolean)
+ */
+ public void setFontStyleModified(boolean modified)
+ {
+ fontFormatting.setFontStyleModified(modified);
+ }
+
+ /**
+ * @param on
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setOutline(boolean)
+ */
+ public void setOutline(boolean on)
+ {
+ fontFormatting.setOutline(on);
+ fontFormatting.setFontOutlineModified(on);
+ }
+
+ /**
+ * @param on
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setShadow(boolean)
+ */
+ public void setShadow(boolean on)
+ {
+ fontFormatting.setShadow(on);
+ fontFormatting.setFontShadowModified(on);
+ }
+
+ /**
+ * @param strike
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setStrikeout(boolean)
+ */
+ public void setStrikeout(boolean strike)
+ {
+ fontFormatting.setStrikeout(strike);
+ fontFormatting.setFontCancellationModified(strike);
+ }
+
+ /**
+ * set the type of underlining type for the font
+ *
+ * @param underlineType super or subscript option
+ *
+ * @see #U_NONE
+ * @see #U_SINGLE
+ * @see #U_DOUBLE
+ * @see #U_SINGLE_ACCOUNTING
+ * @see #U_DOUBLE_ACCOUNTING
+ */
+ public void setUnderlineType(short underlineType) {
+ switch(underlineType) {
+ case HSSFFontFormatting.U_SINGLE:
+ case HSSFFontFormatting.U_DOUBLE:
+ case HSSFFontFormatting.U_SINGLE_ACCOUNTING:
+ case HSSFFontFormatting.U_DOUBLE_ACCOUNTING:
+ fontFormatting.setUnderlineType(underlineType);
+ setUnderlineTypeModified(true);
+ break;
+
+ case HSSFFontFormatting.U_NONE:
+ fontFormatting.setUnderlineType(underlineType);
+ setUnderlineTypeModified(false);
+ break;
+ default:
+ }
+ }
+
+ /**
+ * @param modified
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setUnderlineTypeModified(boolean)
+ */
+ public void setUnderlineTypeModified(boolean modified)
+ {
+ fontFormatting.setUnderlineTypeModified(modified);
+ }
}
Modified: poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java Sun Jul 19 19:00:32 2015
@@ -45,7 +45,6 @@ import org.apache.poi.hssf.record.ObjRec
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DirectoryNode;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Chart;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Drawing;
Modified: poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFPatternFormatting.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFPatternFormatting.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFPatternFormatting.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFPatternFormatting.java Sun Jul 19 19:00:32 2015
@@ -17,88 +17,116 @@
package org.apache.poi.hssf.usermodel;
-import org.apache.poi.hssf.record.CFRuleRecord;
+import org.apache.poi.hssf.record.CFRuleBase;
import org.apache.poi.hssf.record.cf.PatternFormatting;
+import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.ss.usermodel.Color;
/**
* High level representation for Conditional Formatting settings
*/
-public class HSSFPatternFormatting implements org.apache.poi.ss.usermodel.PatternFormatting
-{
- private final CFRuleRecord cfRuleRecord;
- private final PatternFormatting patternFormatting;
-
- protected HSSFPatternFormatting(CFRuleRecord cfRuleRecord)
- {
- this.cfRuleRecord = cfRuleRecord;
- this.patternFormatting = cfRuleRecord.getPatternFormatting();
- }
-
- protected PatternFormatting getPatternFormattingBlock()
- {
- return patternFormatting;
- }
-
- /**
- * @see org.apache.poi.hssf.record.cf.PatternFormatting#getFillBackgroundColor()
- */
- public short getFillBackgroundColor()
- {
- return (short)patternFormatting.getFillBackgroundColor();
- }
-
- /**
- * @see org.apache.poi.hssf.record.cf.PatternFormatting#getFillForegroundColor()
- */
- public short getFillForegroundColor()
- {
- return (short)patternFormatting.getFillForegroundColor();
- }
-
- /**
- * @see org.apache.poi.hssf.record.cf.PatternFormatting#getFillPattern()
- */
- public short getFillPattern()
- {
- return (short)patternFormatting.getFillPattern();
- }
-
- /**
- * @param bg
- * @see org.apache.poi.hssf.record.cf.PatternFormatting#setFillBackgroundColor(int)
- */
- public void setFillBackgroundColor(short bg)
- {
- patternFormatting.setFillBackgroundColor(bg);
- if( bg != 0)
- {
- cfRuleRecord.setPatternBackgroundColorModified(true);
- }
- }
-
- /**
- * @param fg
- * @see org.apache.poi.hssf.record.cf.PatternFormatting#setFillForegroundColor(int)
- */
- public void setFillForegroundColor(short fg)
- {
- patternFormatting.setFillForegroundColor(fg);
- if( fg != 0)
- {
- cfRuleRecord.setPatternColorModified(true);
- }
- }
-
- /**
- * @param fp
- * @see org.apache.poi.hssf.record.cf.PatternFormatting#setFillPattern(int)
- */
- public void setFillPattern(short fp)
- {
- patternFormatting.setFillPattern(fp);
- if( fp != 0)
- {
- cfRuleRecord.setPatternStyleModified(true);
- }
- }
+public class HSSFPatternFormatting implements org.apache.poi.ss.usermodel.PatternFormatting {
+ private final HSSFWorkbook workbook;
+ private final CFRuleBase cfRuleRecord;
+ private final PatternFormatting patternFormatting;
+
+ protected HSSFPatternFormatting(CFRuleBase cfRuleRecord, HSSFWorkbook workbook) {
+ this.workbook = workbook;
+ this.cfRuleRecord = cfRuleRecord;
+ this.patternFormatting = cfRuleRecord.getPatternFormatting();
+ }
+
+ protected PatternFormatting getPatternFormattingBlock()
+ {
+ return patternFormatting;
+ }
+
+ public HSSFColor getFillBackgroundColorColor() {
+ return workbook.getCustomPalette().getColor(getFillBackgroundColor());
+ }
+
+ public HSSFColor getFillForegroundColorColor() {
+ return workbook.getCustomPalette().getColor(getFillForegroundColor());
+ }
+
+ /**
+ * @see org.apache.poi.hssf.record.cf.PatternFormatting#getFillBackgroundColor()
+ */
+ public short getFillBackgroundColor()
+ {
+ return (short)patternFormatting.getFillBackgroundColor();
+ }
+
+ /**
+ * @see org.apache.poi.hssf.record.cf.PatternFormatting#getFillForegroundColor()
+ */
+ public short getFillForegroundColor()
+ {
+ return (short)patternFormatting.getFillForegroundColor();
+ }
+
+ /**
+ * @see org.apache.poi.hssf.record.cf.PatternFormatting#getFillPattern()
+ */
+ public short getFillPattern()
+ {
+ return (short)patternFormatting.getFillPattern();
+ }
+
+ public void setFillBackgroundColor(Color bg) {
+ HSSFColor hcolor = HSSFColor.toHSSFColor(bg);
+ if (hcolor == null) {
+ setFillBackgroundColor((short)0);
+ } else {
+ setFillBackgroundColor(hcolor.getIndex());
+ }
+ }
+
+ public void setFillForegroundColor(Color fg) {
+ HSSFColor hcolor = HSSFColor.toHSSFColor(fg);
+ if (hcolor == null) {
+ setFillForegroundColor((short)0);
+ } else {
+ setFillForegroundColor(hcolor.getIndex());
+ }
+ }
+
+ /**
+ * @param bg
+ * @see org.apache.poi.hssf.record.cf.PatternFormatting#setFillBackgroundColor(int)
+ */
+ public void setFillBackgroundColor(short bg)
+ {
+ patternFormatting.setFillBackgroundColor(bg);
+ if( bg != 0)
+ {
+ cfRuleRecord.setPatternBackgroundColorModified(true);
+ }
+ }
+
+ /**
+ * @param fg
+ * @see org.apache.poi.hssf.record.cf.PatternFormatting#setFillForegroundColor(int)
+ */
+ public void setFillForegroundColor(short fg)
+ {
+ patternFormatting.setFillForegroundColor(fg);
+ if( fg != 0)
+ {
+ cfRuleRecord.setPatternColorModified(true);
+ }
+ }
+
+ /**
+ * @param fp
+ * @see org.apache.poi.hssf.record.cf.PatternFormatting#setFillPattern(int)
+ */
+ public void setFillPattern(short fp)
+ {
+ patternFormatting.setFillPattern(fp);
+ if( fp != 0)
+ {
+ cfRuleRecord.setPatternStyleModified(true);
+ }
+ }
}
Modified: poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java Sun Jul 19 19:00:32 2015
@@ -29,13 +29,6 @@ import java.util.Map;
* Factory class for producing Excel Shapes from Escher records
*/
public class HSSFShapeFactory {
-
- private final static short OBJECT_TYPE_LINE = 1;
- private final static short OBJECT_TYPE_RECTANGLE = 2;
- private final static short OBJECT_TYPE_OVAL = 3;
- private final static short OBJECT_TYPE_ARC = 4;
- private final static short OBJECT_TYPE_PICTURE = 8;
-
/**
* build shape tree from escher container
* @param container root escher container from which escher records must be taken
@@ -81,7 +74,7 @@ public class HSSFShapeFactory {
return;
}
CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord) objRecord.getSubRecords().get(0);
- HSSFShape shape;
+ final HSSFShape shape;
switch (cmo.getObjectType()) {
case CommonObjectDataSubRecord.OBJECT_TYPE_PICTURE:
shape = new HSSFPicture(container, objRecord);
@@ -97,11 +90,15 @@ public class HSSFShapeFactory {
break;
case CommonObjectDataSubRecord.OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING:
EscherOptRecord optRecord = container.getChildById(EscherOptRecord.RECORD_ID);
- EscherProperty property = optRecord.lookup(EscherProperties.GEOMETRY__VERTICES);
- if (null != property) {
- shape = new HSSFPolygon(container, objRecord, txtRecord);
+ if(optRecord == null) {
+ shape = new HSSFSimpleShape(container, objRecord, txtRecord);
} else {
- shape = new HSSFSimpleShape(container, objRecord, txtRecord);
+ EscherProperty property = optRecord.lookup(EscherProperties.GEOMETRY__VERTICES);
+ if (null != property) {
+ shape = new HSSFPolygon(container, objRecord, txtRecord);
+ } else {
+ shape = new HSSFSimpleShape(container, objRecord, txtRecord);
+ }
}
break;
case CommonObjectDataSubRecord.OBJECT_TYPE_TEXT:
Modified: poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Sun Jul 19 19:00:32 2015
@@ -868,6 +868,17 @@ public final class HSSFSheet implements
}
/**
+ * @return the list of merged regions
+ */
+ public List<CellRangeAddress> getMergedRegions() {
+ List<CellRangeAddress> addresses = new ArrayList<CellRangeAddress>();
+ for (int i=0; i < _sheet.getNumMergedRegions(); i++) {
+ addresses.add(_sheet.getMergedRegionAt(i));
+ }
+ return addresses;
+ }
+
+ /**
* @return an iterator of the PHYSICAL rows. Meaning the 3rd element may not
* be the third row if say for instance the second row is undefined.
* Call getRowNum() on each row if you care which one it is.
Modified: poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java Sun Jul 19 19:00:32 2015
@@ -17,142 +17,156 @@
package org.apache.poi.hssf.usermodel;
+import org.apache.poi.hssf.record.CFRule12Record;
+import org.apache.poi.hssf.record.CFRuleBase;
import org.apache.poi.hssf.record.CFRuleRecord;
import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
import org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable;
+import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.ConditionalFormatting;
import org.apache.poi.ss.usermodel.ConditionalFormattingRule;
+import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet;
import org.apache.poi.ss.usermodel.SheetConditionalFormatting;
import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.ss.SpreadsheetVersion;
/**
* The 'Conditional Formatting' facet of <tt>HSSFSheet</tt>
*/
public final class HSSFSheetConditionalFormatting implements SheetConditionalFormatting {
+ private final HSSFSheet _sheet;
+ private final ConditionalFormattingTable _conditionalFormattingTable;
- private final HSSFSheet _sheet;
- private final ConditionalFormattingTable _conditionalFormattingTable;
+ /* package */ HSSFSheetConditionalFormatting(HSSFSheet sheet) {
+ _sheet = sheet;
+ _conditionalFormattingTable = sheet.getSheet().getConditionalFormattingTable();
+ }
- /* package */ HSSFSheetConditionalFormatting(HSSFSheet sheet) {
- _sheet = sheet;
- _conditionalFormattingTable = sheet.getSheet().getConditionalFormattingTable();
- }
-
- /**
- * A factory method allowing to create a conditional formatting rule
- * with a cell comparison operator<p/>
- * TODO - formulas containing cell references are currently not parsed properly
- *
- * @param comparisonOperation - a constant value from
- * <tt>{@link org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator}</tt>: <p>
- * <ul>
- * <li>BETWEEN</li>
- * <li>NOT_BETWEEN</li>
- * <li>EQUAL</li>
- * <li>NOT_EQUAL</li>
- * <li>GT</li>
- * <li>LT</li>
- * <li>GE</li>
- * <li>LE</li>
- * </ul>
- * </p>
- * @param formula1 - formula for the valued, compared with the cell
- * @param formula2 - second formula (only used with
- * {@link org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator#BETWEEN}) and
- * {@link org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator#NOT_BETWEEN} operations)
- */
- public HSSFConditionalFormattingRule createConditionalFormattingRule(
- byte comparisonOperation,
- String formula1,
- String formula2) {
-
- HSSFWorkbook wb = _sheet.getWorkbook();
- CFRuleRecord rr = CFRuleRecord.create(_sheet, comparisonOperation, formula1, formula2);
- return new HSSFConditionalFormattingRule(wb, rr);
- }
+ /**
+ * A factory method allowing to create a conditional formatting rule
+ * with a cell comparison operator<p/>
+ * TODO - formulas containing cell references are currently not parsed properly
+ *
+ * @param comparisonOperation - a constant value from
+ * <tt>{@link org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator}</tt>: <p>
+ * <ul>
+ * <li>BETWEEN</li>
+ * <li>NOT_BETWEEN</li>
+ * <li>EQUAL</li>
+ * <li>NOT_EQUAL</li>
+ * <li>GT</li>
+ * <li>LT</li>
+ * <li>GE</li>
+ * <li>LE</li>
+ * </ul>
+ * </p>
+ * @param formula1 - formula for the valued, compared with the cell
+ * @param formula2 - second formula (only used with
+ * {@link org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator#BETWEEN}) and
+ * {@link org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator#NOT_BETWEEN} operations)
+ */
+ public HSSFConditionalFormattingRule createConditionalFormattingRule(
+ byte comparisonOperation,
+ String formula1,
+ String formula2) {
+ CFRuleRecord rr = CFRuleRecord.create(_sheet, comparisonOperation, formula1, formula2);
+ return new HSSFConditionalFormattingRule(_sheet, rr);
+ }
public HSSFConditionalFormattingRule createConditionalFormattingRule(
byte comparisonOperation,
String formula1) {
-
- HSSFWorkbook wb = _sheet.getWorkbook();
CFRuleRecord rr = CFRuleRecord.create(_sheet, comparisonOperation, formula1, null);
- return new HSSFConditionalFormattingRule(wb, rr);
+ return new HSSFConditionalFormattingRule(_sheet, rr);
}
- /**
- * A factory method allowing to create a conditional formatting rule with a formula.<br>
- *
- * The formatting rules are applied by Excel when the value of the formula not equal to 0.<p/>
- * TODO - formulas containing cell references are currently not parsed properly
- * @param formula - formula for the valued, compared with the cell
- */
- public HSSFConditionalFormattingRule createConditionalFormattingRule(String formula) {
- HSSFWorkbook wb = _sheet.getWorkbook();
- CFRuleRecord rr = CFRuleRecord.create(_sheet, formula);
- return new HSSFConditionalFormattingRule(wb, rr);
- }
-
- /**
- * Adds a copy of HSSFConditionalFormatting object to the sheet
- * <p>This method could be used to copy HSSFConditionalFormatting object
- * from one sheet to another. For example:
- * <pre>
- * HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index);
- * newSheet.addConditionalFormatting(cf);
- * </pre>
- *
- * @param cf HSSFConditionalFormatting object
- * @return index of the new Conditional Formatting object
- */
- public int addConditionalFormatting( HSSFConditionalFormatting cf ) {
- CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate();
+ /**
+ * A factory method allowing to create a conditional formatting rule with a formula.<br>
+ *
+ * The formatting rules are applied by Excel when the value of the formula not equal to 0.<p/>
+ * TODO - formulas containing cell references are currently not parsed properly
+ * @param formula - formula for the valued, compared with the cell
+ */
+ public HSSFConditionalFormattingRule createConditionalFormattingRule(String formula) {
+ CFRuleRecord rr = CFRuleRecord.create(_sheet, formula);
+ return new HSSFConditionalFormattingRule(_sheet, rr);
+ }
- return _conditionalFormattingTable.add(cfraClone);
- }
+ /**
+ * A factory method allowing the creation of conditional formatting
+ * rules using an Icon Set / Multi-State formatting.
+ * The thresholds for it will be created, but will be empty
+ * and require configuring with
+ * {@link HSSFConditionalFormattingRule#getMultiStateFormatting()}
+ * then
+ * {@link HSSFIconMultiStateFormatting#getThresholds()}
+ */
+ public HSSFConditionalFormattingRule createConditionalFormattingRule(
+ IconSet iconSet) {
+ CFRule12Record rr = CFRule12Record.create(_sheet, iconSet);
+ return new HSSFConditionalFormattingRule(_sheet, rr);
+ }
+
+ // TODO Support types beyond CELL_VALUE_IS and FORMULA and ICONs
+
+ /**
+ * Adds a copy of HSSFConditionalFormatting object to the sheet
+ * <p>This method could be used to copy HSSFConditionalFormatting object
+ * from one sheet to another. For example:
+ * <pre>
+ * HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index);
+ * newSheet.addConditionalFormatting(cf);
+ * </pre>
+ *
+ * @param cf HSSFConditionalFormatting object
+ * @return index of the new Conditional Formatting object
+ */
+ public int addConditionalFormatting( HSSFConditionalFormatting cf ) {
+ CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate();
+
+ return _conditionalFormattingTable.add(cfraClone);
+ }
public int addConditionalFormatting( ConditionalFormatting cf ) {
return addConditionalFormatting((HSSFConditionalFormatting)cf);
}
- /**
- * @deprecated use <tt>CellRangeAddress</tt> instead of <tt>Region</tt>
- */
- public int addConditionalFormatting(org.apache.poi.ss.util.Region[] regions, HSSFConditionalFormattingRule[] cfRules) {
- return addConditionalFormatting(org.apache.poi.ss.util.Region.convertRegionsToCellRanges(regions), cfRules);
- }
- /**
- * Allows to add a new Conditional Formatting set to the sheet.
- *
- * @param regions - list of rectangular regions to apply conditional formatting rules
- * @param cfRules - set of up to three conditional formatting rules
- *
- * @return index of the newly created Conditional Formatting object
- */
- public int addConditionalFormatting(CellRangeAddress[] regions, HSSFConditionalFormattingRule[] cfRules) {
- if (regions == null) {
- throw new IllegalArgumentException("regions must not be null");
- }
- for(CellRangeAddress range : regions) range.validate(SpreadsheetVersion.EXCEL97);
-
- if (cfRules == null) {
- throw new IllegalArgumentException("cfRules must not be null");
- }
- if (cfRules.length == 0) {
- throw new IllegalArgumentException("cfRules must not be empty");
- }
- if (cfRules.length > 3) {
- throw new IllegalArgumentException("Number of rules must not exceed 3");
- }
-
- CFRuleRecord[] rules = new CFRuleRecord[cfRules.length];
- for (int i = 0; i != cfRules.length; i++) {
- rules[i] = cfRules[i].getCfRuleRecord();
- }
- CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules);
- return _conditionalFormattingTable.add(cfra);
- }
+ /**
+ * @deprecated use <tt>CellRangeAddress</tt> instead of <tt>Region</tt>
+ */
+ public int addConditionalFormatting(org.apache.poi.ss.util.Region[] regions, HSSFConditionalFormattingRule[] cfRules) {
+ return addConditionalFormatting(org.apache.poi.ss.util.Region.convertRegionsToCellRanges(regions), cfRules);
+ }
+ /**
+ * Allows to add a new Conditional Formatting set to the sheet.
+ *
+ * @param regions - list of rectangular regions to apply conditional formatting rules
+ * @param cfRules - set of up to three conditional formatting rules
+ *
+ * @return index of the newly created Conditional Formatting object
+ */
+ public int addConditionalFormatting(CellRangeAddress[] regions, HSSFConditionalFormattingRule[] cfRules) {
+ if (regions == null) {
+ throw new IllegalArgumentException("regions must not be null");
+ }
+ for(CellRangeAddress range : regions) range.validate(SpreadsheetVersion.EXCEL97);
+
+ if (cfRules == null) {
+ throw new IllegalArgumentException("cfRules must not be null");
+ }
+ if (cfRules.length == 0) {
+ throw new IllegalArgumentException("cfRules must not be empty");
+ }
+ if (cfRules.length > 3) {
+ throw new IllegalArgumentException("Number of rules must not exceed 3");
+ }
+
+ CFRuleBase[] rules = new CFRuleBase[cfRules.length];
+ for (int i = 0; i != cfRules.length; i++) {
+ rules[i] = cfRules[i].getCfRuleRecord();
+ }
+ CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules);
+ return _conditionalFormattingTable.add(cfra);
+ }
public int addConditionalFormatting(CellRangeAddress[] regions, ConditionalFormattingRule[] cfRules) {
HSSFConditionalFormattingRule[] hfRules;
@@ -164,70 +178,61 @@ public final class HSSFSheetConditionalF
return addConditionalFormatting(regions, hfRules);
}
- public int addConditionalFormatting(CellRangeAddress[] regions,
- HSSFConditionalFormattingRule rule1)
- {
- return addConditionalFormatting(regions,
- rule1 == null ? null : new HSSFConditionalFormattingRule[]
- {
- rule1
- });
- }
+ public int addConditionalFormatting(CellRangeAddress[] regions,
+ HSSFConditionalFormattingRule rule1) {
+ return addConditionalFormatting(regions, rule1 == null ?
+ null : new HSSFConditionalFormattingRule[] { rule1 }
+ );
+ }
public int addConditionalFormatting(CellRangeAddress[] regions,
- ConditionalFormattingRule rule1)
- {
+ ConditionalFormattingRule rule1) {
return addConditionalFormatting(regions, (HSSFConditionalFormattingRule)rule1);
}
- public int addConditionalFormatting(CellRangeAddress[] regions,
- HSSFConditionalFormattingRule rule1,
- HSSFConditionalFormattingRule rule2)
- {
- return addConditionalFormatting(regions,
- new HSSFConditionalFormattingRule[]
- {
- rule1, rule2
- });
- }
+ public int addConditionalFormatting(CellRangeAddress[] regions,
+ HSSFConditionalFormattingRule rule1,
+ HSSFConditionalFormattingRule rule2) {
+ return addConditionalFormatting(regions,
+ new HSSFConditionalFormattingRule[] { rule1, rule2 });
+ }
public int addConditionalFormatting(CellRangeAddress[] regions,
ConditionalFormattingRule rule1,
- ConditionalFormattingRule rule2)
- {
+ ConditionalFormattingRule rule2) {
return addConditionalFormatting(regions,
(HSSFConditionalFormattingRule)rule1,
(HSSFConditionalFormattingRule)rule2
- );
+ );
+ }
+
+ /**
+ * gets Conditional Formatting object at a particular index
+ *
+ * @param index
+ * of the Conditional Formatting object to fetch
+ * @return Conditional Formatting object
+ */
+ public HSSFConditionalFormatting getConditionalFormattingAt(int index) {
+ CFRecordsAggregate cf = _conditionalFormattingTable.get(index);
+ if (cf == null) {
+ return null;
+ }
+ return new HSSFConditionalFormatting(_sheet, cf);
+ }
+
+ /**
+ * @return number of Conditional Formatting objects of the sheet
+ */
+ public int getNumConditionalFormattings() {
+ return _conditionalFormattingTable.size();
}
- /**
- * gets Conditional Formatting object at a particular index
- *
- * @param index
- * of the Conditional Formatting object to fetch
- * @return Conditional Formatting object
- */
- public HSSFConditionalFormatting getConditionalFormattingAt(int index) {
- CFRecordsAggregate cf = _conditionalFormattingTable.get(index);
- if (cf == null) {
- return null;
- }
- return new HSSFConditionalFormatting(_sheet.getWorkbook(), cf);
- }
-
- /**
- * @return number of Conditional Formatting objects of the sheet
- */
- public int getNumConditionalFormattings() {
- return _conditionalFormattingTable.size();
- }
-
- /**
- * removes a Conditional Formatting object by index
- * @param index of a Conditional Formatting object to remove
- */
- public void removeConditionalFormatting(int index) {
- _conditionalFormattingTable.remove(index);
- }
+ /**
+ * removes a Conditional Formatting object by index
+ * @param index of a Conditional Formatting object to remove
+ */
+ public void removeConditionalFormatting(int index) {
+ _conditionalFormattingTable.remove(index);
+ }
}
Modified: poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Sun Jul 19 19:00:32 2015
@@ -65,6 +65,7 @@ import org.apache.poi.hssf.record.Unknow
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
import org.apache.poi.hssf.record.common.UnicodeString;
import org.apache.poi.hssf.util.CellReference;
+import org.apache.poi.poifs.crypt.Decryptor;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.EntryUtils;
@@ -205,6 +206,19 @@ public final class HSSFWorkbook extends
public HSSFWorkbook(POIFSFileSystem fs) throws IOException {
this(fs,true);
}
+ /**
+ * Given a POI POIFSFileSystem object, read in its Workbook along
+ * with all related nodes, and populate the high and low level models.
+ * <p>This calls {@link #HSSFWorkbook(POIFSFileSystem, boolean)} with
+ * preserve nodes set to true.
+ *
+ * @see #HSSFWorkbook(POIFSFileSystem, boolean)
+ * @see org.apache.poi.poifs.filesystem.POIFSFileSystem
+ * @exception IOException if the stream cannot be read
+ */
+ public HSSFWorkbook(NPOIFSFileSystem fs) throws IOException {
+ this(fs.getRoot(),true);
+ }
/**
* Given a POI POIFSFileSystem object, read in its Workbook and populate
@@ -248,7 +262,7 @@ public final class HSSFWorkbook extends
// check for an encrypted .xlsx file - they get OLE2 wrapped
try {
- directory.getEntry("EncryptedPackage");
+ directory.getEntry(Decryptor.DEFAULT_POIFS_ENTRY);
throw new EncryptedDocumentException("The supplied spreadsheet seems to be an Encrypted .xlsx file. " +
"It must be decrypted before use by XSSF, it cannot be used by HSSF");
} catch (FileNotFoundException e) {
@@ -378,7 +392,7 @@ public final class HSSFWorkbook extends
public HSSFWorkbook(InputStream s, boolean preserveNodes)
throws IOException
{
- this(new POIFSFileSystem(s), preserveNodes);
+ this(new NPOIFSFileSystem(s).getRoot(), preserveNodes);
}
/**
@@ -1276,7 +1290,7 @@ public final class HSSFWorkbook extends
throws IOException
{
byte[] bytes = getBytes();
- POIFSFileSystem fs = new POIFSFileSystem();
+ NPOIFSFileSystem fs = new NPOIFSFileSystem();
// For tracking what we've written out, used if we're
// going to be preserving nodes
@@ -1843,7 +1857,7 @@ public final class HSSFWorkbook extends
throws IOException {
// check if we were created by POIFS otherwise create a new dummy POIFS for storing the package data
if (directory == null) {
- directory = new POIFSFileSystem().getRoot();
+ directory = new NPOIFSFileSystem().getRoot();
preserveNodes = true;
}
Modified: poi/branches/common_sl/src/java/org/apache/poi/hssf/util/HSSFColor.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/hssf/util/HSSFColor.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/hssf/util/HSSFColor.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/hssf/util/HSSFColor.java Sun Jul 19 19:00:32 2015
@@ -204,6 +204,13 @@ public class HSSFColor implements Color
{
return BLACK.hexString;
}
+
+ public static HSSFColor toHSSFColor(Color color) {
+ if (color != null && !(color instanceof HSSFColor)) {
+ throw new IllegalArgumentException("Only HSSFColor objects are supported");
+ }
+ return (HSSFColor)color;
+ }
/**
* Class BLACK
Modified: poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java Sun Jul 19 19:00:32 2015
@@ -16,6 +16,8 @@
==================================================================== */
package org.apache.poi.poifs.crypt;
+import static org.apache.poi.poifs.crypt.Decryptor.DEFAULT_POIFS_ENTRY;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -132,8 +134,8 @@ public abstract class ChunkedCipherOutpu
super.close();
int oleStreamSize = (int)(fileOut.length()+LittleEndianConsts.LONG_SIZE);
- calculateChecksum(fileOut, oleStreamSize);
- dir.createDocument("EncryptedPackage", oleStreamSize, new EncryptedPackageWriter());
+ calculateChecksum(fileOut, (int)_pos);
+ dir.createDocument(DEFAULT_POIFS_ENTRY, oleStreamSize, new EncryptedPackageWriter());
createEncryptionInfoEntry(dir, fileOut);
} catch (GeneralSecurityException e) {
throw new IOException(e);
Modified: poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java Sun Jul 19 19:00:32 2015
@@ -36,7 +36,7 @@ public class DataSpaceMapUtils {
public static void addDefaultDataSpace(DirectoryEntry dir) throws IOException {
DataSpaceMapEntry dsme = new DataSpaceMapEntry(
new int[]{ 0 }
- , new String[]{ "EncryptedPackage" }
+ , new String[]{ Decryptor.DEFAULT_POIFS_ENTRY }
, "StrongEncryptionDataSpace"
);
DataSpaceMap dsm = new DataSpaceMap(new DataSpaceMapEntry[]{dsme});
Modified: poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/Decryptor.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/Decryptor.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/Decryptor.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/Decryptor.java Sun Jul 19 19:00:32 2015
@@ -25,10 +25,12 @@ import javax.crypto.SecretKey;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public abstract class Decryptor {
public static final String DEFAULT_PASSWORD="VelvetSweatshop";
+ public static final String DEFAULT_POIFS_ENTRY="EncryptedPackage";
protected final EncryptionInfoBuilder builder;
private SecretKey secretKey;
@@ -83,7 +85,9 @@ public abstract class Decryptor {
public InputStream getDataStream(NPOIFSFileSystem fs) throws IOException, GeneralSecurityException {
return getDataStream(fs.getRoot());
}
-
+ public InputStream getDataStream(OPOIFSFileSystem fs) throws IOException, GeneralSecurityException {
+ return getDataStream(fs.getRoot());
+ }
public InputStream getDataStream(POIFSFileSystem fs) throws IOException, GeneralSecurityException {
return getDataStream(fs.getRoot());
}
Modified: poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java Sun Jul 19 19:00:32 2015
@@ -26,6 +26,7 @@ import java.io.IOException;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
@@ -68,14 +69,27 @@ public class EncryptionInfo {
public static BitField flagAES = BitFieldFactory.getInstance(0x20);
+ /**
+ * Opens for decryption
+ */
public EncryptionInfo(POIFSFileSystem fs) throws IOException {
this(fs.getRoot());
}
-
+ /**
+ * Opens for decryption
+ */
+ public EncryptionInfo(OPOIFSFileSystem fs) throws IOException {
+ this(fs.getRoot());
+ }
+ /**
+ * Opens for decryption
+ */
public EncryptionInfo(NPOIFSFileSystem fs) throws IOException {
this(fs.getRoot());
}
-
+ /**
+ * Opens for decryption
+ */
public EncryptionInfo(DirectoryNode dir) throws IOException {
this(dir.createDocumentInputStream("EncryptionInfo"), false);
}
@@ -131,7 +145,7 @@ public class EncryptionInfo {
}
/**
- * @deprecated use constructor without fs parameter
+ * @deprecated Use {@link #EncryptionInfo(EncryptionMode)} (fs parameter no longer required)
*/
@Deprecated
public EncryptionInfo(POIFSFileSystem fs, EncryptionMode encryptionMode) {
@@ -139,7 +153,7 @@ public class EncryptionInfo {
}
/**
- * @deprecated use constructor without fs parameter
+ * @deprecated Use {@link #EncryptionInfo(EncryptionMode)} (fs parameter no longer required)
*/
@Deprecated
public EncryptionInfo(NPOIFSFileSystem fs, EncryptionMode encryptionMode) {
@@ -147,7 +161,7 @@ public class EncryptionInfo {
}
/**
- * @deprecated use constructor without dir parameter
+ * @deprecated Use {@link #EncryptionInfo(EncryptionMode)} (dir parameter no longer required)
*/
@Deprecated
public EncryptionInfo(DirectoryNode dir, EncryptionMode encryptionMode) {
@@ -155,7 +169,7 @@ public class EncryptionInfo {
}
/**
- * @deprecated use constructor without fs parameter
+ * @deprecated use {@link #EncryptionInfo(EncryptionMode, CipherAlgorithm, HashAlgorithm, int, int, ChainingMode)}
*/
@Deprecated
public EncryptionInfo(
@@ -171,7 +185,7 @@ public class EncryptionInfo {
}
/**
- * @deprecated use constructor without fs parameter
+ * @deprecated use {@link #EncryptionInfo(EncryptionMode, CipherAlgorithm, HashAlgorithm, int, int, ChainingMode)}
*/
@Deprecated
public EncryptionInfo(
@@ -187,7 +201,7 @@ public class EncryptionInfo {
}
/**
- * @deprecated use constructor without dir parameter
+ * @deprecated use {@link #EncryptionInfo(EncryptionMode, CipherAlgorithm, HashAlgorithm, int, int, ChainingMode)}
*/
@Deprecated
public EncryptionInfo(
@@ -202,6 +216,11 @@ public class EncryptionInfo {
this(encryptionMode, cipherAlgorithm, hashAlgorithm, keyBits, blockSize, chainingMode);
}
+ /**
+ * Prepares for encryption, using the given Encryption Mode, and
+ * all other parameters as default.
+ * @see #EncryptionInfo(EncryptionMode, CipherAlgorithm, HashAlgorithm, int, int, ChainingMode)
+ */
public EncryptionInfo(EncryptionMode encryptionMode) {
this(encryptionMode, null, null, -1, -1, null);
}
Modified: poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/Encryptor.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/Encryptor.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/Encryptor.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/Encryptor.java Sun Jul 19 19:00:32 2015
@@ -24,9 +24,11 @@ import javax.crypto.SecretKey;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public abstract class Encryptor {
+ protected static final String DEFAULT_POIFS_ENTRY = Decryptor.DEFAULT_POIFS_ENTRY;
private SecretKey secretKey;
/**
@@ -50,7 +52,9 @@ public abstract class Encryptor {
public OutputStream getDataStream(NPOIFSFileSystem fs) throws IOException, GeneralSecurityException {
return getDataStream(fs.getRoot());
}
-
+ public OutputStream getDataStream(OPOIFSFileSystem fs) throws IOException, GeneralSecurityException {
+ return getDataStream(fs.getRoot());
+ }
public OutputStream getDataStream(POIFSFileSystem fs) throws IOException, GeneralSecurityException {
return getDataStream(fs.getRoot());
}
Modified: poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java Sun Jul 19 19:00:32 2015
@@ -118,7 +118,7 @@ public class BinaryRC4Decryptor extends
public InputStream getDataStream(DirectoryNode dir) throws IOException,
GeneralSecurityException {
- DocumentInputStream dis = dir.createDocumentInputStream("EncryptedPackage");
+ DocumentInputStream dis = dir.createDocumentInputStream(DEFAULT_POIFS_ENTRY);
_length = dis.readLong();
BinaryRC4CipherInputStream cipherStream = new BinaryRC4CipherInputStream(dis, _length);
return cipherStream;
@@ -131,4 +131,4 @@ public class BinaryRC4Decryptor extends
return _length;
}
-}
\ No newline at end of file
+}
Modified: poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java Sun Jul 19 19:00:32 2015
@@ -40,7 +40,7 @@ import org.apache.poi.poifs.crypt.HashAl
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
import org.apache.poi.poifs.filesystem.DocumentNode;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.BoundedInputStream;
@@ -200,7 +200,7 @@ public class CryptoAPIDecryptor extends
@SuppressWarnings("unused")
public InputStream getDataStream(DirectoryNode dir)
throws IOException, GeneralSecurityException {
- POIFSFileSystem fsOut = new POIFSFileSystem();
+ NPOIFSFileSystem fsOut = new NPOIFSFileSystem();
DocumentNode es = (DocumentNode) dir.getEntry("EncryptedSummary");
DocumentInputStream dis = dir.createDocumentInputStream(es);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -240,6 +240,7 @@ public class CryptoAPIDecryptor extends
sbis = null;
bos.reset();
fsOut.writeFilesystem(bos);
+ fsOut.close();
_length = bos.size();
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
return bis;
Modified: poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/standard/StandardDecryptor.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/standard/StandardDecryptor.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/standard/StandardDecryptor.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/standard/StandardDecryptor.java Sun Jul 19 19:00:32 2015
@@ -123,7 +123,7 @@ public class StandardDecryptor extends D
}
public InputStream getDataStream(DirectoryNode dir) throws IOException {
- DocumentInputStream dis = dir.createDocumentInputStream("EncryptedPackage");
+ DocumentInputStream dis = dir.createDocumentInputStream(DEFAULT_POIFS_ENTRY);
_length = dis.readLong();
Modified: poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java Sun Jul 19 19:00:32 2015
@@ -166,7 +166,7 @@ public class StandardEncryptor extends E
void writeToPOIFS() throws IOException {
int oleStreamSize = (int)(fileOut.length()+LittleEndianConsts.LONG_SIZE);
- dir.createDocument("EncryptedPackage", oleStreamSize, this);
+ dir.createDocument(DEFAULT_POIFS_ENTRY, oleStreamSize, this);
// TODO: any properties???
}
Modified: poi/branches/common_sl/src/java/org/apache/poi/poifs/dev/POIFSDump.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/poifs/dev/POIFSDump.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/poifs/dev/POIFSDump.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/poifs/dev/POIFSDump.java Sun Jul 19 19:00:32 2015
@@ -16,27 +16,54 @@
==================================================================== */
package org.apache.poi.poifs.dev;
-import org.apache.poi.poifs.filesystem.*;
-
-import java.io.FileInputStream;
import java.io.File;
-import java.io.IOException;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.Field;
+import java.nio.ByteBuffer;
import java.util.Iterator;
+import org.apache.poi.poifs.common.POIFSConstants;
+import org.apache.poi.poifs.filesystem.DirectoryEntry;
+import org.apache.poi.poifs.filesystem.DocumentInputStream;
+import org.apache.poi.poifs.filesystem.DocumentNode;
+import org.apache.poi.poifs.filesystem.Entry;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.poifs.filesystem.NPOIFSStream;
+import org.apache.poi.poifs.property.NPropertyTable;
+import org.apache.poi.poifs.storage.HeaderBlock;
+
/**
- *
* Dump internal structure of a OLE2 file into file system
- *
- * @author Yegor Kozlov
*/
public class POIFSDump {
-
public static void main(String[] args) throws Exception {
+ if (args.length == 0) {
+ System.err.println("Must specify at least one file to dump");
+ System.exit(1);
+ }
+
+ boolean dumpProps = false, dumpMini = false;
for (int i = 0; i < args.length; i++) {
+ if (args[i].equalsIgnoreCase("-dumprops") ||
+ args[i].equalsIgnoreCase("-dump-props") ||
+ args[i].equalsIgnoreCase("-dump-properties")) {
+ dumpProps = true;
+ continue;
+ }
+ if (args[i].equalsIgnoreCase("-dumpmini") ||
+ args[i].equalsIgnoreCase("-dump-mini") ||
+ args[i].equalsIgnoreCase("-dump-ministream") ||
+ args[i].equalsIgnoreCase("-dump-mini-stream")) {
+ dumpMini = true;
+ continue;
+ }
+
System.out.println("Dumping " + args[i]);
FileInputStream is = new FileInputStream(args[i]);
- POIFSFileSystem fs = new POIFSFileSystem(is);
+ NPOIFSFileSystem fs = new NPOIFSFileSystem(is);
is.close();
DirectoryEntry root = fs.getRoot();
@@ -44,13 +71,39 @@ public class POIFSDump {
file.mkdir();
dump(root, file);
+
+ if (dumpProps) {
+ HeaderBlock header = getHeaderBlock(fs);
+ dump(fs, header.getPropertyStart(), "properties", file);
+ }
+ if (dumpMini) {
+ NPropertyTable props = getPropertyTable(fs);
+ int startBlock = props.getRoot().getStartBlock();
+ if (startBlock == POIFSConstants.END_OF_CHAIN) {
+ System.err.println("No Mini Stream in file");
+ } else {
+ dump(fs, startBlock, "mini-stream", file);
+ }
+ }
}
}
-
+
+ protected static HeaderBlock getHeaderBlock(NPOIFSFileSystem fs) throws Exception {
+ Field headerF = NPOIFSFileSystem.class.getDeclaredField("_header");
+ headerF.setAccessible(true);
+ HeaderBlock header = (HeaderBlock)headerF.get(fs);
+ return header;
+ }
+ protected static NPropertyTable getPropertyTable(NPOIFSFileSystem fs) throws Exception {
+ Field ptF = NPOIFSFileSystem.class.getDeclaredField("_property_table");
+ ptF.setAccessible(true);
+ NPropertyTable table = (NPropertyTable)ptF.get(fs);
+ return table;
+ }
public static void dump(DirectoryEntry root, File parent) throws IOException {
- for(Iterator it = root.getEntries(); it.hasNext();){
- Entry entry = (Entry)it.next();
+ for(Iterator<Entry> it = root.getEntries(); it.hasNext();){
+ Entry entry = it.next();
if(entry instanceof DocumentNode){
DocumentNode node = (DocumentNode)entry;
DocumentInputStream is = new DocumentInputStream(node);
@@ -58,9 +111,12 @@ public class POIFSDump {
is.read(bytes);
is.close();
- FileOutputStream out = new FileOutputStream(new File(parent, node.getName().trim()));
- out.write(bytes);
- out.close();
+ OutputStream out = new FileOutputStream(new File(parent, node.getName().trim()));
+ try {
+ out.write(bytes);
+ } finally {
+ out.close();
+ }
} else if (entry instanceof DirectoryEntry){
DirectoryEntry dir = (DirectoryEntry)entry;
File file = new File(parent, entry.getName());
@@ -71,4 +127,17 @@ public class POIFSDump {
}
}
}
+ public static void dump(NPOIFSFileSystem fs, int startBlock, String name, File parent) throws IOException {
+ File file = new File(parent, name);
+ FileOutputStream out = new FileOutputStream(file);
+ NPOIFSStream stream = new NPOIFSStream(fs, startBlock);
+
+ byte[] b = new byte[fs.getBigBlockSize()];
+ for (ByteBuffer bb : stream) {
+ int len = bb.remaining();
+ bb.get(b);
+ out.write(b, 0, len);
+ }
+ out.close();
+ }
}
Modified: poi/branches/common_sl/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java Sun Jul 19 19:00:32 2015
@@ -24,9 +24,10 @@ import java.lang.reflect.Method;
import org.apache.poi.poifs.common.POIFSBigBlockSize;
import org.apache.poi.poifs.common.POIFSConstants;
+import org.apache.poi.poifs.property.DirectoryProperty;
+import org.apache.poi.poifs.property.Property;
import org.apache.poi.poifs.property.PropertyTable;
import org.apache.poi.poifs.storage.BlockAllocationTableReader;
-import org.apache.poi.poifs.storage.BlockList;
import org.apache.poi.poifs.storage.HeaderBlock;
import org.apache.poi.poifs.storage.ListManagedBlock;
import org.apache.poi.poifs.storage.RawDataBlockList;
@@ -42,111 +43,146 @@ import org.apache.poi.util.IntList;
* down the source of corruption in a file.
*/
public class POIFSHeaderDumper {
- /**
- * Display the entries of multiple POIFS files
- *
- * @param args the names of the files to be displayed
- */
- public static void main(final String args[]) throws Exception {
- if (args.length == 0) {
- System.err.println("Must specify at least one file to view");
- System.exit(1);
- }
-
- for (int j = 0; j < args.length; j++) {
- viewFile(args[j]);
- }
- }
-
- public static void viewFile(final String filename) throws Exception {
- InputStream inp = new FileInputStream(filename);
-
- // Header
- HeaderBlock header_block = new HeaderBlock(inp);
- displayHeader(header_block);
-
- // Raw blocks
- POIFSBigBlockSize bigBlockSize = header_block.getBigBlockSize();
- RawDataBlockList data_blocks = new RawDataBlockList(inp, bigBlockSize);
- displayRawBlocksSummary(data_blocks);
-
- // Main FAT Table
- BlockAllocationTableReader batReader =
- new BlockAllocationTableReader(
- header_block.getBigBlockSize(),
- header_block.getBATCount(),
- header_block.getBATArray(),
- header_block.getXBATCount(),
- header_block.getXBATIndex(),
- data_blocks);
- displayBATReader(batReader);
-
- // Properties Table
- PropertyTable properties =
- new PropertyTable(header_block, data_blocks);
-
- // Mini Fat
- BlockList sbat =
- SmallBlockTableReader.getSmallDocumentBlocks(
- bigBlockSize, data_blocks, properties.getRoot(),
- header_block.getSBATStart()
- );
- }
-
- public static void displayHeader(HeaderBlock header_block) throws Exception {
- System.out.println("Header Details:");
- System.out.println(" Block size: " + header_block.getBigBlockSize().getBigBlockSize());
- System.out.println(" BAT (FAT) header blocks: " + header_block.getBATArray().length);
- System.out.println(" BAT (FAT) block count: " + header_block.getBATCount());
- System.out.println(" XBAT (FAT) block count: " + header_block.getXBATCount());
- System.out.println(" XBAT (FAT) block 1 at: " + header_block.getXBATIndex());
- System.out.println(" SBAT (MiniFAT) block count: " + header_block.getSBATCount());
- System.out.println(" SBAT (MiniFAT) block 1 at: " + header_block.getSBATStart());
- System.out.println(" Property table at: " + header_block.getPropertyStart());
- System.out.println("");
- }
-
- public static void displayRawBlocksSummary(RawDataBlockList data_blocks) throws Exception {
- System.out.println("Raw Blocks Details:");
- System.out.println(" Number of blocks: " + data_blocks.blockCount());
-
- Method gbm = data_blocks.getClass().getSuperclass().getDeclaredMethod("get", int.class);
- gbm.setAccessible(true);
-
- for(int i=0; i<Math.min(16, data_blocks.blockCount()); i++) {
- ListManagedBlock block = (ListManagedBlock)gbm.invoke(data_blocks, Integer.valueOf(i));
- byte[] data = new byte[Math.min(48, block.getData().length)];
- System.arraycopy(block.getData(), 0, data, 0, data.length);
-
- System.out.println(" Block #" + i + ":");
- System.out.println(HexDump.dump(data, 0, 0));
- }
-
- System.out.println("");
- }
-
- public static void displayBATReader(BlockAllocationTableReader batReader) throws Exception {
- System.out.println("Sectors, as referenced from the FAT:");
- Field entriesF = batReader.getClass().getDeclaredField("_entries");
- entriesF.setAccessible(true);
- IntList entries = (IntList)entriesF.get(batReader);
-
- for(int i=0; i<entries.size(); i++) {
- int bn = entries.get(i);
- String bnS = Integer.toString(bn);
- if(bn == POIFSConstants.END_OF_CHAIN) {
- bnS = "End Of Chain";
- } else if(bn == POIFSConstants.DIFAT_SECTOR_BLOCK) {
- bnS = "DI Fat Block";
- } else if(bn == POIFSConstants.FAT_SECTOR_BLOCK) {
- bnS = "Normal Fat Block";
- } else if(bn == POIFSConstants.UNUSED_BLOCK) {
- bnS = "Block Not Used (Free)";
- }
-
- System.out.println(" Block # " + i + " -> " + bnS);
- }
-
- System.out.println("");
- }
+ /**
+ * Display the entries of multiple POIFS files
+ *
+ * @param args the names of the files to be displayed
+ */
+ public static void main(final String args[]) throws Exception {
+ if (args.length == 0) {
+ System.err.println("Must specify at least one file to view");
+ System.exit(1);
+ }
+
+ for (int j = 0; j < args.length; j++) {
+ viewFile(args[j]);
+ }
+ }
+
+ public static void viewFile(final String filename) throws Exception {
+ System.out.println("Dumping headers from: " + filename);
+ InputStream inp = new FileInputStream(filename);
+
+ // Header
+ HeaderBlock header_block = new HeaderBlock(inp);
+ displayHeader(header_block);
+
+ // Raw blocks
+ POIFSBigBlockSize bigBlockSize = header_block.getBigBlockSize();
+ RawDataBlockList data_blocks = new RawDataBlockList(inp, bigBlockSize);
+ displayRawBlocksSummary(data_blocks);
+
+ // Main FAT Table
+ BlockAllocationTableReader batReader =
+ new BlockAllocationTableReader(
+ header_block.getBigBlockSize(),
+ header_block.getBATCount(),
+ header_block.getBATArray(),
+ header_block.getXBATCount(),
+ header_block.getXBATIndex(),
+ data_blocks);
+ displayBATReader("Big Blocks", batReader);
+
+ // Properties Table
+ PropertyTable properties =
+ new PropertyTable(header_block, data_blocks);
+
+ // Mini Fat
+ BlockAllocationTableReader sbatReader =
+ SmallBlockTableReader._getSmallDocumentBlockReader(
+ bigBlockSize, data_blocks, properties.getRoot(),
+ header_block.getSBATStart()
+ );
+ displayBATReader("Small Blocks", sbatReader);
+
+ // Summary of the properties
+ displayPropertiesSummary(properties);
+ }
+
+ public static void displayHeader(HeaderBlock header_block) throws Exception {
+ System.out.println("Header Details:");
+ System.out.println(" Block size: " + header_block.getBigBlockSize().getBigBlockSize());
+ System.out.println(" BAT (FAT) header blocks: " + header_block.getBATArray().length);
+ System.out.println(" BAT (FAT) block count: " + header_block.getBATCount());
+ if (header_block.getBATCount() > 0)
+ System.out.println(" BAT (FAT) block 1 at: " + header_block.getBATArray()[0]);
+ System.out.println(" XBAT (FAT) block count: " + header_block.getXBATCount());
+ System.out.println(" XBAT (FAT) block 1 at: " + header_block.getXBATIndex());
+ System.out.println(" SBAT (MiniFAT) block count: " + header_block.getSBATCount());
+ System.out.println(" SBAT (MiniFAT) block 1 at: " + header_block.getSBATStart());
+ System.out.println(" Property table at: " + header_block.getPropertyStart());
+ System.out.println("");
+ }
+
+ public static void displayRawBlocksSummary(RawDataBlockList data_blocks) throws Exception {
+ System.out.println("Raw Blocks Details:");
+ System.out.println(" Number of blocks: " + data_blocks.blockCount());
+
+ Method gbm = data_blocks.getClass().getSuperclass().getDeclaredMethod("get", int.class);
+ gbm.setAccessible(true);
+
+ for(int i=0; i<Math.min(16, data_blocks.blockCount()); i++) {
+ ListManagedBlock block = (ListManagedBlock)gbm.invoke(data_blocks, Integer.valueOf(i));
+ byte[] data = new byte[Math.min(48, block.getData().length)];
+ System.arraycopy(block.getData(), 0, data, 0, data.length);
+
+ System.out.println(" Block #" + i + ":");
+ System.out.println(HexDump.dump(data, 0, 0));
+ }
+
+ System.out.println("");
+ }
+
+ public static void displayBATReader(String type, BlockAllocationTableReader batReader) throws Exception {
+ System.out.println("Sectors, as referenced from the "+type+" FAT:");
+ Field entriesF = batReader.getClass().getDeclaredField("_entries");
+ entriesF.setAccessible(true);
+ IntList entries = (IntList)entriesF.get(batReader);
+
+ for(int i=0; i<entries.size(); i++) {
+ int bn = entries.get(i);
+ String bnS = Integer.toString(bn);
+ if(bn == POIFSConstants.END_OF_CHAIN) {
+ bnS = "End Of Chain";
+ } else if(bn == POIFSConstants.DIFAT_SECTOR_BLOCK) {
+ bnS = "DI Fat Block";
+ } else if(bn == POIFSConstants.FAT_SECTOR_BLOCK) {
+ bnS = "Normal Fat Block";
+ } else if(bn == POIFSConstants.UNUSED_BLOCK) {
+ bnS = "Block Not Used (Free)";
+ }
+
+ System.out.println(" Block # " + i + " -> " + bnS);
+ }
+
+ System.out.println("");
+ }
+
+ public static void displayPropertiesSummary(PropertyTable properties) {
+ System.out.println("Mini Stream starts at " + properties.getRoot().getStartBlock());
+ System.out.println("Mini Stream length is " + properties.getRoot().getSize());
+ System.out.println();
+
+ System.out.println("Properties and their block start:");
+ displayProperties(properties.getRoot(), "");
+ System.out.println("");
+ }
+ public static void displayProperties(DirectoryProperty prop, String indent) {
+ String nextIndent = indent + " ";
+ System.out.println(indent + "-> " + prop.getName());
+ for (Property cp : prop) {
+ if (cp instanceof DirectoryProperty) {
+ displayProperties((DirectoryProperty)cp, nextIndent);
+ } else {
+ System.out.println(nextIndent + "=> " + cp.getName());
+ System.out.print(nextIndent + " " + cp.getSize() + " bytes in ");
+ if (cp.shouldUseSmallBlocks()) {
+ System.out.print("mini");
+ } else {
+ System.out.print("main");
+ }
+ System.out.println(" stream, starts at " + cp.getStartBlock());
+ }
+ }
+ }
}
Modified: poi/branches/common_sl/src/java/org/apache/poi/poifs/dev/POIFSViewer.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/poifs/dev/POIFSViewer.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/poifs/dev/POIFSViewer.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/poifs/dev/POIFSViewer.java Sun Jul 19 19:00:32 2015
@@ -19,12 +19,12 @@
package org.apache.poi.poifs.dev;
-import java.io.FileInputStream;
+import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
/**
* A simple viewer for POIFS files
@@ -76,10 +76,10 @@ public class POIFSViewer
try
{
POIFSViewable fs =
- new POIFSFileSystem(new FileInputStream(filename));
- List<String> strings = POIFSViewEngine.inspectViewable(fs, true,
+ new NPOIFSFileSystem(new File(filename));
+ List<String> strings = POIFSViewEngine.inspectViewable(fs, true,
0, " ");
- Iterator<String> iter = strings.iterator();
+ Iterator<String> iter = strings.iterator();
while (iter.hasNext())
{
Modified: poi/branches/common_sl/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReader.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReader.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReader.java (original)
+++ poi/branches/common_sl/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReader.java Sun Jul 19 19:00:32 2015
@@ -24,7 +24,7 @@ import java.io.*;
import java.util.*;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
-import org.apache.poi.poifs.filesystem.POIFSDocument;
+import org.apache.poi.poifs.filesystem.OPOIFSDocument;
import org.apache.poi.poifs.filesystem.POIFSDocumentPath;
import org.apache.poi.poifs.property.DirectoryProperty;
import org.apache.poi.poifs.property.Property;
@@ -240,19 +240,19 @@ public class POIFSReader
if (listeners.hasNext())
{
- int size = property.getSize();
- POIFSDocument document = null;
+ int size = property.getSize();
+ OPOIFSDocument document = null;
if (property.shouldUseSmallBlocks())
{
document =
- new POIFSDocument(name, small_blocks
+ new OPOIFSDocument(name, small_blocks
.fetchBlocks(startBlock, -1), size);
}
else
{
document =
- new POIFSDocument(name, big_blocks
+ new OPOIFSDocument(name, big_blocks
.fetchBlocks(startBlock, -1), size);
}
while (listeners.hasNext())
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org