git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894331 13f79535-47bb-0310-9956-ffa450edef68tags/REL_5_2_0
* | * | ||||
* @param file An instance of the File class that encapsulates a handle | * @param file An instance of the File class that encapsulates a handle | ||||
* referring to the CSV file. | * referring to the CSV file. | ||||
* @throws java.io.FileNotFoundException Thrown if the file cannot be found. | |||||
* @throws java.io.IOException Thrown to indicate and error occurred in the | * @throws java.io.IOException Thrown to indicate and error occurred in the | ||||
* underylying file system. | * underylying file system. | ||||
*/ | */ | ||||
private void saveCSVFile(File file) throws FileNotFoundException, IOException { | |||||
private void saveCSVFile(File file) throws IOException { | |||||
ArrayList<String> line; | ArrayList<String> line; | ||||
StringBuilder buffer; | StringBuilder buffer; | ||||
String csvLineElement; | String csvLineElement; | ||||
// set of speech marks. Thus, "Yes" he said would become | // set of speech marks. Thus, "Yes" he said would become | ||||
// """Yes"" he said" | // """Yes"" he said" | ||||
if(field.contains("\"")) { | if(field.contains("\"")) { | ||||
buffer = new StringBuilder(field.replaceAll("\"", "\\\"\\\"")); | |||||
buffer = new StringBuilder(field.replace("\"", "\\\"\\\"")); | |||||
buffer.insert(0, "\""); | buffer.insert(0, "\""); | ||||
buffer.append("\""); | buffer.append("\""); | ||||
} | } | ||||
field = field.replaceAll(this.separator, ("\\\\" + this.separator)); | field = field.replaceAll(this.separator, ("\\\\" + this.separator)); | ||||
} | } | ||||
if(field.contains("\n")) { | if(field.contains("\n")) { | ||||
field = field.replaceAll("\n", "\\\\\n"); | |||||
field = field.replace("\n", "\\\\\n"); | |||||
} | } | ||||
return(field); | return(field); | ||||
} | } |
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; | |||||
import org.apache.logging.log4j.LogManager; | import org.apache.logging.log4j.LogManager; | ||||
import org.apache.logging.log4j.Logger; | import org.apache.logging.log4j.Logger; | ||||
import org.apache.logging.log4j.message.SimpleMessage; | import org.apache.logging.log4j.message.SimpleMessage; | ||||
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(InetAddress.getByName(host), (port == -1 ? 80 : port))); | proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(InetAddress.getByName(host), (port == -1 ? 80 : port))); | ||||
} | } | ||||
UnsynchronizedByteArrayOutputStream bos; | |||||
String contentType; | String contentType; | ||||
HttpURLConnection huc = (HttpURLConnection)new URL(signatureConfig.getTspUrl()).openConnection(proxy); | HttpURLConnection huc = (HttpURLConnection)new URL(signatureConfig.getTspUrl()).openConnection(proxy); | ||||
byte[] responseBytes; | |||||
try { | try { | ||||
if (signatureConfig.getTspUser() != null) { | if (signatureConfig.getTspUser() != null) { | ||||
String userPassword = signatureConfig.getTspUser() + ":" + signatureConfig.getTspPass(); | String userPassword = signatureConfig.getTspUser() + ":" + signatureConfig.getTspPass(); | ||||
throw new RuntimeException("missing Content-Type header"); | throw new RuntimeException("missing Content-Type header"); | ||||
} | } | ||||
bos = new UnsynchronizedByteArrayOutputStream(); | |||||
IOUtils.copy(huc.getInputStream(), bos); | |||||
LOG.atDebug().log(() -> new SimpleMessage("response content: " + HexDump.dump(bos.toByteArray(), 0, 0))); | |||||
responseBytes = IOUtils.toByteArray(huc.getInputStream()); | |||||
LOG.atDebug().log(() -> new SimpleMessage("response content: " + HexDump.dump(responseBytes, 0, 0))); | |||||
} finally { | } finally { | ||||
huc.disconnect(); | huc.disconnect(); | ||||
} | } | ||||
)) { | )) { | ||||
throw new RuntimeException("invalid Content-Type: " + contentType + | throw new RuntimeException("invalid Content-Type: " + contentType + | ||||
// dump the first few bytes | // dump the first few bytes | ||||
": " + HexDump.dump(bos.toByteArray(), 0, 0, 200)); | |||||
": " + HexDump.dump(responseBytes, 0, 0, 200)); | |||||
} | } | ||||
if (bos.size() == 0) { | |||||
if (responseBytes.length == 0) { | |||||
throw new RuntimeException("Content-Length is zero"); | throw new RuntimeException("Content-Length is zero"); | ||||
} | } | ||||
// TSP response parsing and validation | // TSP response parsing and validation | ||||
TimeStampResponse timeStampResponse = new TimeStampResponse(bos.toByteArray()); | |||||
TimeStampResponse timeStampResponse = new TimeStampResponse(responseBytes); | |||||
timeStampResponse.validate(request); | timeStampResponse.validate(request); | ||||
if (0 != timeStampResponse.getStatus()) { | if (0 != timeStampResponse.getStatus()) { |
import java.io.PrintStream; | import java.io.PrintStream; | ||||
import java.text.AttributedCharacterIterator; | import java.text.AttributedCharacterIterator; | ||||
import java.text.AttributedCharacterIterator.Attribute; | import java.text.AttributedCharacterIterator.Attribute; | ||||
import java.text.CharacterIterator; | |||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.LinkedHashMap; | import java.util.LinkedHashMap; | ||||
import java.util.Locale; | import java.util.Locale; | ||||
import java.util.Map; | import java.util.Map; | ||||
import org.apache.poi.util.Internal; | |||||
public class DummyGraphics2d extends Graphics2D { | public class DummyGraphics2d extends Graphics2D { | ||||
private BufferedImage bufimg; | private BufferedImage bufimg; | ||||
private final Graphics2D g2D; | private final Graphics2D g2D; | ||||
this.log = log; | this.log = log; | ||||
} | } | ||||
@Override | |||||
public void addRenderingHints(Map<?,?> hints) { | public void addRenderingHints(Map<?,?> hints) { | ||||
String l = | String l = | ||||
"addRenderingHinds(Map):" + | "addRenderingHinds(Map):" + | ||||
g2D.addRenderingHints( hints ); | g2D.addRenderingHints( hints ); | ||||
} | } | ||||
@Override | |||||
public void clip(Shape s) { | public void clip(Shape s) { | ||||
String l = | String l = | ||||
"clip(Shape):" + | "clip(Shape):" + | ||||
} | } | ||||
private void pathToString(StringBuilder sb, Path2D p) { | private void pathToString(StringBuilder sb, Path2D p) { | ||||
sb.append("Path2D p = new Path2D.Double("+p.getWindingRule()+");\n"); | |||||
sb.append("Path2D p = new Path2D.Double(").append(p.getWindingRule()).append(");\n"); | |||||
double[] coords = new double[6]; | double[] coords = new double[6]; | ||||
for (PathIterator pi = p.getPathIterator(null); !pi.isDone(); pi.next()) { | for (PathIterator pi = p.getPathIterator(null); !pi.isDone(); pi.next()) { | ||||
// Because the Area is composed of straight lines | // Because the Area is composed of straight lines | ||||
switch (pi.currentSegment(coords)) { | switch (pi.currentSegment(coords)) { | ||||
case PathIterator.SEG_MOVETO: | case PathIterator.SEG_MOVETO: | ||||
sb.append("p.moveTo("+coords[0]+","+coords[1]+");\n"); | |||||
sb.append("p.moveTo(").append(coords[0]).append(",").append(coords[1]).append(");\n"); | |||||
break; | break; | ||||
case PathIterator.SEG_LINETO: | case PathIterator.SEG_LINETO: | ||||
sb.append("p.lineTo("+coords[0]+","+coords[1]+");\n"); | |||||
sb.append("p.lineTo(").append(coords[0]).append(",").append(coords[1]).append(");\n"); | |||||
break; | break; | ||||
case PathIterator.SEG_QUADTO: | case PathIterator.SEG_QUADTO: | ||||
sb.append("p.quadTo("+coords[0]+","+coords[1]+","+coords[2]+","+coords[3]+");\n"); | |||||
sb.append("p.quadTo(").append(coords[0]).append(",").append(coords[1]).append(",").append(coords[2]).append(",").append(coords[3]).append(");\n"); | |||||
break; | break; | ||||
case PathIterator.SEG_CUBICTO: | case PathIterator.SEG_CUBICTO: | ||||
sb.append("p.curveTo("+coords[0]+","+coords[1]+","+coords[2]+","+coords[3]+","+coords[4]+","+coords[5]+");\n"); | |||||
sb.append("p.curveTo(").append(coords[0]).append(",").append(coords[1]).append(",").append(coords[2]).append(",").append(coords[3]).append(",").append(coords[4]).append(",").append(coords[5]).append(");\n"); | |||||
break; | break; | ||||
case PathIterator.SEG_CLOSE: | case PathIterator.SEG_CLOSE: | ||||
sb.append("p.closePath();\n"); | sb.append("p.closePath();\n"); | ||||
} | } | ||||
} | } | ||||
@Override | |||||
public void draw(Shape s) { | public void draw(Shape s) { | ||||
if (s instanceof Path2D) { | if (s instanceof Path2D) { | ||||
StringBuilder sb = new StringBuilder(); | StringBuilder sb = new StringBuilder(); | ||||
pathToString(sb, (Path2D)s); | pathToString(sb, (Path2D)s); | ||||
sb.append("g.draw(p);"); | sb.append("g.draw(p);"); | ||||
log.println( sb.toString() ); | |||||
log.println(sb); | |||||
} else { | } else { | ||||
log.println( "g.draw("+ s + ")" ); | log.println( "g.draw("+ s + ")" ); | ||||
} | } | ||||
g2D.draw( s ); | g2D.draw( s ); | ||||
} | } | ||||
@Override | |||||
public void drawGlyphVector(GlyphVector g, float x, float y) { | public void drawGlyphVector(GlyphVector g, float x, float y) { | ||||
String l = | String l = | ||||
"drawGlyphVector(GlyphVector, float, float):" + | "drawGlyphVector(GlyphVector, float, float):" + | ||||
g2D.drawGlyphVector( g, x, y ); | g2D.drawGlyphVector( g, x, y ); | ||||
} | } | ||||
@Override | |||||
public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) { | public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) { | ||||
String l = | String l = | ||||
"drawImage(BufferedImage, BufferedImageOp, x, y):" + | "drawImage(BufferedImage, BufferedImageOp, x, y):" + | ||||
g2D.drawImage( img, op, x, y ); | g2D.drawImage( img, op, x, y ); | ||||
} | } | ||||
@Override | |||||
public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) { | public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) { | ||||
String l = | String l = | ||||
"drawImage(Image,AfflineTransform,ImageObserver):" + | "drawImage(Image,AfflineTransform,ImageObserver):" + | ||||
return g2D.drawImage( img, xform, obs ); | return g2D.drawImage( img, xform, obs ); | ||||
} | } | ||||
@Override | |||||
public void drawRenderableImage(RenderableImage img, AffineTransform xform) { | public void drawRenderableImage(RenderableImage img, AffineTransform xform) { | ||||
String l = | String l = | ||||
"drawRenderableImage(RenderableImage, AfflineTransform):" + | "drawRenderableImage(RenderableImage, AfflineTransform):" + | ||||
g2D.drawRenderableImage( img, xform ); | g2D.drawRenderableImage( img, xform ); | ||||
} | } | ||||
@Override | |||||
public void drawRenderedImage(RenderedImage img, AffineTransform xform) { | public void drawRenderedImage(RenderedImage img, AffineTransform xform) { | ||||
String l = | String l = | ||||
"drawRenderedImage(RenderedImage, AffineTransform):" + | "drawRenderedImage(RenderedImage, AffineTransform):" + | ||||
g2D.drawRenderedImage( img, xform ); | g2D.drawRenderedImage( img, xform ); | ||||
} | } | ||||
@Override | |||||
public void drawString(String s, float x, float y) { | public void drawString(String s, float x, float y) { | ||||
String l = | String l = | ||||
"drawString(s,x,y):" + | "drawString(s,x,y):" + | ||||
g2D.drawString( s, x, y ); | g2D.drawString( s, x, y ); | ||||
} | } | ||||
@Override | |||||
public void fill(Shape s) { | public void fill(Shape s) { | ||||
if (s instanceof Path2D) { | if (s instanceof Path2D) { | ||||
StringBuilder sb = new StringBuilder(); | StringBuilder sb = new StringBuilder(); | ||||
pathToString(sb, (Path2D)s); | pathToString(sb, (Path2D)s); | ||||
sb.append("g.fill(p);"); | sb.append("g.fill(p);"); | ||||
log.println( sb.toString() ); | |||||
log.println(sb); | |||||
} else { | } else { | ||||
log.println( "g.fill("+ s + ")" ); | log.println( "g.fill("+ s + ")" ); | ||||
} | } | ||||
g2D.fill( s ); | g2D.fill( s ); | ||||
} | } | ||||
@Override | |||||
public Color getBackground() { | public Color getBackground() { | ||||
log.println( "getBackground():" ); | log.println( "getBackground():" ); | ||||
return g2D.getBackground(); | return g2D.getBackground(); | ||||
} | } | ||||
@Override | |||||
public Composite getComposite() { | public Composite getComposite() { | ||||
log.println( "getComposite():" ); | log.println( "getComposite():" ); | ||||
return g2D.getComposite(); | return g2D.getComposite(); | ||||
} | } | ||||
@Override | |||||
public GraphicsConfiguration getDeviceConfiguration() { | public GraphicsConfiguration getDeviceConfiguration() { | ||||
log.println( "getDeviceConfiguration():" ); | log.println( "getDeviceConfiguration():" ); | ||||
return g2D.getDeviceConfiguration(); | return g2D.getDeviceConfiguration(); | ||||
} | } | ||||
@Override | |||||
public FontRenderContext getFontRenderContext() { | public FontRenderContext getFontRenderContext() { | ||||
log.println( "getFontRenderContext():" ); | log.println( "getFontRenderContext():" ); | ||||
return g2D.getFontRenderContext(); | return g2D.getFontRenderContext(); | ||||
} | } | ||||
@Override | |||||
public Paint getPaint() { | public Paint getPaint() { | ||||
log.println( "getPaint():" ); | log.println( "getPaint():" ); | ||||
return g2D.getPaint(); | return g2D.getPaint(); | ||||
} | } | ||||
@Override | |||||
public Object getRenderingHint(RenderingHints.Key hintKey) { | public Object getRenderingHint(RenderingHints.Key hintKey) { | ||||
log.println( "getRenderingHint(\""+hintKey+"\")" ); | log.println( "getRenderingHint(\""+hintKey+"\")" ); | ||||
return g2D.getRenderingHint( hintKey ); | return g2D.getRenderingHint( hintKey ); | ||||
} | } | ||||
@Override | |||||
public RenderingHints getRenderingHints() { | public RenderingHints getRenderingHints() { | ||||
log.println( "getRenderingHints():" ); | log.println( "getRenderingHints():" ); | ||||
return g2D.getRenderingHints(); | return g2D.getRenderingHints(); | ||||
} | } | ||||
@Override | |||||
public Stroke getStroke() { | public Stroke getStroke() { | ||||
log.println( "getStroke():" ); | log.println( "getStroke():" ); | ||||
return g2D.getStroke(); | return g2D.getStroke(); | ||||
} | } | ||||
@Override | |||||
public AffineTransform getTransform() { | public AffineTransform getTransform() { | ||||
log.println( "getTransform():" ); | log.println( "getTransform():" ); | ||||
return g2D.getTransform(); | return g2D.getTransform(); | ||||
} | } | ||||
@Override | |||||
public boolean hit(Rectangle rect, Shape s, boolean onStroke) { | public boolean hit(Rectangle rect, Shape s, boolean onStroke) { | ||||
String l = | String l = | ||||
"hit(Rectangle, Shape, onStroke):" + | "hit(Rectangle, Shape, onStroke):" + | ||||
return g2D.hit( rect, s, onStroke ); | return g2D.hit( rect, s, onStroke ); | ||||
} | } | ||||
@Override | |||||
public void rotate(double theta) { | public void rotate(double theta) { | ||||
String l = | String l = | ||||
"rotate(theta):" + | "rotate(theta):" + | ||||
g2D.rotate( theta ); | g2D.rotate( theta ); | ||||
} | } | ||||
@Override | |||||
public void rotate(double theta, double x, double y) { | public void rotate(double theta, double x, double y) { | ||||
String l = | String l = | ||||
"rotate(double,double,double):" + | "rotate(double,double,double):" + | ||||
g2D.rotate( theta, x, y ); | g2D.rotate( theta, x, y ); | ||||
} | } | ||||
@Override | |||||
public void scale(double sx, double sy) { | public void scale(double sx, double sy) { | ||||
log.println( "g.scale("+sx+","+sy+");" ); | log.println( "g.scale("+sx+","+sy+");" ); | ||||
g2D.scale( sx, sy ); | g2D.scale( sx, sy ); | ||||
} | } | ||||
@Override | |||||
public void setBackground(Color color) { | public void setBackground(Color color) { | ||||
log.println(String.format(Locale.ROOT, "setBackground(new Color(0x%08X))", color.getRGB())); | |||||
log.printf(Locale.ROOT, "setBackground(new Color(0x%08X))%n", color.getRGB()); | |||||
g2D.setBackground( color ); | g2D.setBackground( color ); | ||||
} | } | ||||
"CLEAR", "SRC", "SRC_OVER", "DST_OVER", "SRC_IN", "DST_IN", "SRC_OUT", "DST_OUT", "DST", "SRC_ATOP", "DST_ATOP", "XOR" | "CLEAR", "SRC", "SRC_OVER", "DST_OVER", "SRC_IN", "DST_IN", "SRC_OUT", "DST_OUT", "DST", "SRC_ATOP", "DST_ATOP", "XOR" | ||||
}; | }; | ||||
@Override | |||||
public void setComposite(Composite comp) { | public void setComposite(Composite comp) { | ||||
String l = "g.setComposite("; | String l = "g.setComposite("; | ||||
if (comp instanceof AlphaComposite) { | if (comp instanceof AlphaComposite) { | ||||
g2D.setComposite( comp ); | g2D.setComposite( comp ); | ||||
} | } | ||||
@Override | |||||
public void setPaint( Paint paint ) { | public void setPaint( Paint paint ) { | ||||
String l = "g.setPaint("; | String l = "g.setPaint("; | ||||
if (paint instanceof Color) { | if (paint instanceof Color) { | ||||
g2D.setPaint( paint ); | g2D.setPaint( paint ); | ||||
} | } | ||||
@Override | |||||
public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue) { | public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue) { | ||||
log.println( "g.setRenderingHint("+mapHint(hintKey)+", " + mapHint(hintValue) + ");" ); | log.println( "g.setRenderingHint("+mapHint(hintKey)+", " + mapHint(hintValue) + ");" ); | ||||
g2D.setRenderingHint( hintKey, hintValue ); | g2D.setRenderingHint( hintKey, hintValue ); | ||||
return (String)HINTS[i+1]; | return (String)HINTS[i+1]; | ||||
} | } | ||||
} | } | ||||
return "\"" + hint.toString() + "\""; | |||||
return "\"" + hint + "\""; | |||||
} | } | ||||
@Override | |||||
public void setRenderingHints(Map<?,?> hints) { | public void setRenderingHints(Map<?,?> hints) { | ||||
String l = | String l = | ||||
"setRenderingHints(Map):" + | "setRenderingHints(Map):" + | ||||
g2D.setRenderingHints( hints ); | g2D.setRenderingHints( hints ); | ||||
} | } | ||||
@Override | |||||
public void setStroke(Stroke s) { | public void setStroke(Stroke s) { | ||||
String l; | String l; | ||||
if (s instanceof BasicStroke) { | if (s instanceof BasicStroke) { | ||||
: "new AffineTransform("+tx.getScaleX()+"f,"+tx.getShearY()+"f,"+tx.getShearX()+"f,"+tx.getScaleY()+"f,"+tx.getTranslateX()+"f,"+tx.getTranslateY()+"f)"; | : "new AffineTransform("+tx.getScaleX()+"f,"+tx.getShearY()+"f,"+tx.getShearX()+"f,"+tx.getScaleY()+"f,"+tx.getTranslateX()+"f,"+tx.getTranslateY()+"f)"; | ||||
} | } | ||||
@Override | |||||
public void setTransform(AffineTransform Tx) { | public void setTransform(AffineTransform Tx) { | ||||
log.println( "g.setTransform("+mapTransform(Tx)+");" ); | log.println( "g.setTransform("+mapTransform(Tx)+");" ); | ||||
g2D.setTransform( Tx ); | g2D.setTransform( Tx ); | ||||
} | } | ||||
@Override | |||||
public void shear(double shx, double shy) { | public void shear(double shx, double shy) { | ||||
String l = | String l = | ||||
"shear(shx, dhy):" + | "shear(shx, dhy):" + | ||||
g2D.shear( shx, shy ); | g2D.shear( shx, shy ); | ||||
} | } | ||||
@Override | |||||
public void transform(AffineTransform Tx) { | public void transform(AffineTransform Tx) { | ||||
String l = | String l = | ||||
"transform(AffineTransform):" + | "transform(AffineTransform):" + | ||||
g2D.transform( Tx ); | g2D.transform( Tx ); | ||||
} | } | ||||
@Override | |||||
public void translate(double tx, double ty) { | public void translate(double tx, double ty) { | ||||
String l = | String l = | ||||
"translate(double, double):" + | "translate(double, double):" + | ||||
g2D.translate( tx, ty ); | g2D.translate( tx, ty ); | ||||
} | } | ||||
@Override | |||||
public void clearRect(int x, int y, int width, int height) { | public void clearRect(int x, int y, int width, int height) { | ||||
String l = | String l = | ||||
"clearRect(int,int,int,int):" + | "clearRect(int,int,int,int):" + | ||||
g2D.clearRect( x, y, width, height ); | g2D.clearRect( x, y, width, height ); | ||||
} | } | ||||
@Override | |||||
public void clipRect(int x, int y, int width, int height) { | public void clipRect(int x, int y, int width, int height) { | ||||
String l = | String l = | ||||
"clipRect(int, int, int, int):" + | "clipRect(int, int, int, int):" + | ||||
g2D.clipRect( x, y, width, height ); | g2D.clipRect( x, y, width, height ); | ||||
} | } | ||||
@Override | |||||
public void copyArea(int x, int y, int width, int height, int dx, int dy) { | public void copyArea(int x, int y, int width, int height, int dx, int dy) { | ||||
String l = | String l = | ||||
"copyArea(int,int,int,int):" + | "copyArea(int,int,int,int):" + | ||||
g2D.copyArea( x, y, width, height, dx, dy ); | g2D.copyArea( x, y, width, height, dx, dy ); | ||||
} | } | ||||
@Override | |||||
public Graphics create() { | public Graphics create() { | ||||
log.println( "create():" ); | log.println( "create():" ); | ||||
return g2D.create(); | return g2D.create(); | ||||
} | } | ||||
@Override | |||||
public Graphics create(int x, int y, int width, int height) { | public Graphics create(int x, int y, int width, int height) { | ||||
String l = | String l = | ||||
"create(int,int,int,int):" + | "create(int,int,int,int):" + | ||||
return g2D.create( x, y, width, height ); | return g2D.create( x, y, width, height ); | ||||
} | } | ||||
@Override | |||||
public void dispose() { | public void dispose() { | ||||
log.println( "dispose():" ); | log.println( "dispose():" ); | ||||
g2D.dispose(); | g2D.dispose(); | ||||
} | } | ||||
@Override | |||||
public void draw3DRect(int x, int y, int width, int height, boolean raised) { | public void draw3DRect(int x, int y, int width, int height, boolean raised) { | ||||
String l = | String l = | ||||
"draw3DRect(int,int,int,int,boolean):" + | "draw3DRect(int,int,int,int,boolean):" + | ||||
g2D.draw3DRect( x, y, width, height, raised ); | g2D.draw3DRect( x, y, width, height, raised ); | ||||
} | } | ||||
@Override | |||||
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { | public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { | ||||
String l = | String l = | ||||
"drawArc(int,int,int,int,int,int):" + | "drawArc(int,int,int,int,int,int):" + | ||||
g2D.drawArc( x, y, width, height, startAngle, arcAngle ); | g2D.drawArc( x, y, width, height, startAngle, arcAngle ); | ||||
} | } | ||||
@Override | |||||
public void drawBytes(byte[] data, int offset, int length, int x, int y) { | public void drawBytes(byte[] data, int offset, int length, int x, int y) { | ||||
String l = | String l = | ||||
"drawBytes(byte[],int,int,int,int):" + | "drawBytes(byte[],int,int,int,int):" + | ||||
g2D.drawBytes( data, offset, length, x, y ); | g2D.drawBytes( data, offset, length, x, y ); | ||||
} | } | ||||
@Override | |||||
public void drawChars(char[] data, int offset, int length, int x, int y) { | public void drawChars(char[] data, int offset, int length, int x, int y) { | ||||
String l = | String l = | ||||
"drawChars(data,int,int,int,int):" + | "drawChars(data,int,int,int,int):" + | ||||
g2D.drawChars( data, offset, length, x, y ); | g2D.drawChars( data, offset, length, x, y ); | ||||
} | } | ||||
@Override | |||||
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) { | public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) { | ||||
String l = | String l = | ||||
"drawImage(Image,int,int,int,int,int,int,int,int,ImageObserver):" + | "drawImage(Image,int,int,int,int,int,int,int,int,ImageObserver):" + | ||||
return g2D.drawImage( img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer ); | return g2D.drawImage( img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer ); | ||||
} | } | ||||
@Override | |||||
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) { | public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) { | ||||
String l = | String l = | ||||
"drawImage(Image,int,int,int,int,int,int,int,int,Color,ImageObserver):" + | "drawImage(Image,int,int,int,int,int,int,int,int,Color,ImageObserver):" + | ||||
return g2D.drawImage( img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer ); | return g2D.drawImage( img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer ); | ||||
} | } | ||||
@Override | |||||
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) { | public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) { | ||||
String l = | String l = | ||||
"drawImage(Image,int,int,Color,ImageObserver):" + | "drawImage(Image,int,int,Color,ImageObserver):" + | ||||
return g2D.drawImage( img, x, y, bgcolor, observer ); | return g2D.drawImage( img, x, y, bgcolor, observer ); | ||||
} | } | ||||
@Override | |||||
public boolean drawImage(Image img, int x, int y, ImageObserver observer) { | public boolean drawImage(Image img, int x, int y, ImageObserver observer) { | ||||
String l = | String l = | ||||
"drawImage(Image,int,int,observer):" + | "drawImage(Image,int,int,observer):" + | ||||
return g2D.drawImage( img, x, y, observer ); | return g2D.drawImage( img, x, y, observer ); | ||||
} | } | ||||
@Override | |||||
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) { | public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) { | ||||
String l = | String l = | ||||
"drawImage(Image,int,int,int,int,Color,ImageObserver):" + | "drawImage(Image,int,int,int,int,Color,ImageObserver):" + | ||||
return g2D.drawImage( img, x, y, width, height, bgcolor, observer ); | return g2D.drawImage( img, x, y, width, height, bgcolor, observer ); | ||||
} | } | ||||
@Override | |||||
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) { | public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) { | ||||
String l = | String l = | ||||
"drawImage(Image,int,int,width,height,observer):" + | "drawImage(Image,int,int,width,height,observer):" + | ||||
return g2D.drawImage( img, x, y, width, height, observer ); | return g2D.drawImage( img, x, y, width, height, observer ); | ||||
} | } | ||||
@Override | |||||
public void drawLine(int x1, int y1, int x2, int y2) { | public void drawLine(int x1, int y1, int x2, int y2) { | ||||
String l = | String l = | ||||
"drawLine(int,int,int,int):" + | "drawLine(int,int,int,int):" + | ||||
g2D.drawLine( x1, y1, x2, y2 ); | g2D.drawLine( x1, y1, x2, y2 ); | ||||
} | } | ||||
@Override | |||||
public void drawOval(int x, int y, int width, int height) { | public void drawOval(int x, int y, int width, int height) { | ||||
String l = | String l = | ||||
"drawOval(int,int,int,int):" + | "drawOval(int,int,int,int):" + | ||||
g2D.drawOval( x, y, width, height ); | g2D.drawOval( x, y, width, height ); | ||||
} | } | ||||
@Override | |||||
public void drawPolygon(Polygon p) { | public void drawPolygon(Polygon p) { | ||||
String l = | String l = | ||||
"drawPolygon(Polygon):" + | "drawPolygon(Polygon):" + | ||||
g2D.drawPolygon( p ); | g2D.drawPolygon( p ); | ||||
} | } | ||||
@Override | |||||
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) { | public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) { | ||||
String l = | String l = | ||||
"drawPolygon(int[],int[],int):" + | "drawPolygon(int[],int[],int):" + | ||||
g2D.drawPolygon( xPoints, yPoints, nPoints ); | g2D.drawPolygon( xPoints, yPoints, nPoints ); | ||||
} | } | ||||
@Override | |||||
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) { | public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) { | ||||
String l = | String l = | ||||
"drawPolyline(int[],int[],int):" + | "drawPolyline(int[],int[],int):" + | ||||
g2D.drawPolyline( xPoints, yPoints, nPoints ); | g2D.drawPolyline( xPoints, yPoints, nPoints ); | ||||
} | } | ||||
@Override | |||||
public void drawRect(int x, int y, int width, int height) { | public void drawRect(int x, int y, int width, int height) { | ||||
String l = | String l = | ||||
"drawRect(int,int,int,int):" + | "drawRect(int,int,int,int):" + | ||||
g2D.drawRect( x, y, width, height ); | g2D.drawRect( x, y, width, height ); | ||||
} | } | ||||
@Override | |||||
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { | public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { | ||||
String l = | String l = | ||||
"drawRoundRect(int,int,int,int,int,int):" + | "drawRoundRect(int,int,int,int,int,int):" + | ||||
return (String)ATTRS[i+1]; | return (String)ATTRS[i+1]; | ||||
} | } | ||||
} | } | ||||
return "\""+attr.toString()+"\""; | |||||
return "\""+ attr +"\""; | |||||
} | } | ||||
@Override | |||||
public void drawString(AttributedCharacterIterator iterator, float x, float y) { | public void drawString(AttributedCharacterIterator iterator, float x, float y) { | ||||
final int startIdx = iterator.getIndex(); | final int startIdx = iterator.getIndex(); | ||||
final Map<Attribute, Map<Integer,Object>> attMap = new HashMap<>(); | final Map<Attribute, Map<Integer,Object>> attMap = new HashMap<>(); | ||||
StringBuilder sb = new StringBuilder(); | StringBuilder sb = new StringBuilder(); | ||||
for (char ch = iterator.current(); ch != AttributedCharacterIterator.DONE; ch = iterator.next()) { | |||||
for (char ch = iterator.current(); ch != CharacterIterator.DONE; ch = iterator.next()) { | |||||
sb.append(ch); | sb.append(ch); | ||||
iterator.getAttributes().forEach((k,v) -> | iterator.getAttributes().forEach((k,v) -> | ||||
attMap.computeIfAbsent(k, (k2) -> new LinkedHashMap<>()).put(iterator.getIndex(), v) | attMap.computeIfAbsent(k, (k2) -> new LinkedHashMap<>()).put(iterator.getIndex(), v) | ||||
for (Map.Entry<Attribute, Map<Integer,Object>> me : attMap.entrySet()) { | for (Map.Entry<Attribute, Map<Integer,Object>> me : attMap.entrySet()) { | ||||
int startPos = -2, lastPos = -2; | int startPos = -2, lastPos = -2; | ||||
final Attribute at = me.getKey(); | |||||
Object lastObj = null; | Object lastObj = null; | ||||
for (Map.Entry<Integer,Object> mo : me.getValue().entrySet()) { | for (Map.Entry<Integer,Object> mo : me.getValue().entrySet()) { | ||||
int pos = mo.getKey(); | int pos = mo.getKey(); | ||||
Object obj = mo.getValue(); | Object obj = mo.getValue(); | ||||
if (lastPos < pos-1 || obj != lastObj) { | if (lastPos < pos-1 || obj != lastObj) { | ||||
if (startPos >= 0) { | if (startPos >= 0) { | ||||
Attribute at = me.getKey(); | |||||
sb.append("as.addAttribute("+mapAttribute(me.getKey())+","+mapAttribute(lastObj)+","+startPos+","+(lastPos+1)+");\n"); | |||||
sb.append("as.addAttribute(").append(mapAttribute(at)).append(",").append(mapAttribute(lastObj)).append(",").append(startPos).append(",").append(lastPos + 1).append(");\n"); | |||||
} | } | ||||
startPos = pos; | startPos = pos; | ||||
} | } | ||||
lastObj = obj; | lastObj = obj; | ||||
} | } | ||||
if (lastObj != null) { | if (lastObj != null) { | ||||
sb.append("as.addAttribute("+mapAttribute(me.getKey())+","+mapAttribute(lastObj)+","+startPos+","+(lastPos+1)+");\n"); | |||||
sb.append("as.addAttribute(").append(mapAttribute(at)).append(",").append(mapAttribute(lastObj)).append(",").append(startPos).append(",").append(lastPos + 1).append(");\n"); | |||||
} | } | ||||
} | } | ||||
sb.append("g.drawString(as.getIterator(),"+x+"f,"+y+"f);"); | |||||
log.println( sb.toString() ); | |||||
sb.append("g.drawString(as.getIterator(),").append(x).append("f,").append(y).append("f);"); | |||||
log.println(sb); | |||||
iterator.setIndex(startIdx); | iterator.setIndex(startIdx); | ||||
g2D.drawString( iterator, x, y ); | g2D.drawString( iterator, x, y ); | ||||
} | } | ||||
@Override | |||||
public void drawString(AttributedCharacterIterator iterator, int x, int y) { | public void drawString(AttributedCharacterIterator iterator, int x, int y) { | ||||
drawString(iterator, (float)x, (float)y); | drawString(iterator, (float)x, (float)y); | ||||
} | } | ||||
@Override | |||||
public void drawString(String str, int x, int y) { | public void drawString(String str, int x, int y) { | ||||
String l = | String l = | ||||
"drawString(str,int,int):" + | "drawString(str,int,int):" + | ||||
g2D.drawString( str, x, y ); | g2D.drawString( str, x, y ); | ||||
} | } | ||||
@Override | |||||
public void fill3DRect(int x, int y, int width, int height, boolean raised) { | public void fill3DRect(int x, int y, int width, int height, boolean raised) { | ||||
String l = | String l = | ||||
"fill3DRect(int,int,int,int,boolean):" + | "fill3DRect(int,int,int,int,boolean):" + | ||||
g2D.fill3DRect( x, y, width, height, raised ); | g2D.fill3DRect( x, y, width, height, raised ); | ||||
} | } | ||||
@Override | |||||
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { | public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { | ||||
String l = | String l = | ||||
"fillArc(int,int,int,int,int,int):" + | "fillArc(int,int,int,int,int,int):" + | ||||
g2D.fillArc( x, y, width, height, startAngle, arcAngle ); | g2D.fillArc( x, y, width, height, startAngle, arcAngle ); | ||||
} | } | ||||
@Override | |||||
public void fillOval(int x, int y, int width, int height) { | public void fillOval(int x, int y, int width, int height) { | ||||
String l = | String l = | ||||
"fillOval(int,int,int,int):" + | "fillOval(int,int,int,int):" + | ||||
g2D.fillOval( x, y, width, height ); | g2D.fillOval( x, y, width, height ); | ||||
} | } | ||||
@Override | |||||
public void fillPolygon(Polygon p) { | public void fillPolygon(Polygon p) { | ||||
String l = | String l = | ||||
"fillPolygon(Polygon):" + | "fillPolygon(Polygon):" + | ||||
g2D.fillPolygon( p ); | g2D.fillPolygon( p ); | ||||
} | } | ||||
@Override | |||||
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) { | public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) { | ||||
String l = | String l = | ||||
"fillPolygon(int[],int[],int):" + | "fillPolygon(int[],int[],int):" + | ||||
g2D.fillPolygon( xPoints, yPoints, nPoints ); | g2D.fillPolygon( xPoints, yPoints, nPoints ); | ||||
} | } | ||||
@Override | |||||
public void fillRect(int x, int y, int width, int height) { | public void fillRect(int x, int y, int width, int height) { | ||||
log.println( "g.fillRect(" + x + "," + y + "," + width + "," + height + ");" ); | log.println( "g.fillRect(" + x + "," + y + "," + width + "," + height + ");" ); | ||||
g2D.fillRect( x, y, width, height ); | g2D.fillRect( x, y, width, height ); | ||||
} | } | ||||
@Override | |||||
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { | public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { | ||||
log.println( "fillRoundRect(" + x + "," + y + "," + width + "," + height + "," + arcWidth + "," + arcHeight + ")" ); | log.println( "fillRoundRect(" + x + "," + y + "," + width + "," + height + "," + arcWidth + "," + arcHeight + ")" ); | ||||
g2D.fillRoundRect( x, y, width, height, arcWidth, arcHeight ); | g2D.fillRoundRect( x, y, width, height, arcWidth, arcHeight ); | ||||
} | } | ||||
@Override | |||||
public Shape getClip() { | public Shape getClip() { | ||||
log.println( "getClip():" ); | log.println( "getClip():" ); | ||||
return g2D.getClip(); | return g2D.getClip(); | ||||
} | } | ||||
@Override | |||||
public Rectangle getClipBounds() { | public Rectangle getClipBounds() { | ||||
log.println( "getClipBounds():" ); | log.println( "getClipBounds():" ); | ||||
return g2D.getClipBounds(); | return g2D.getClipBounds(); | ||||
} | } | ||||
@Override | |||||
public Rectangle getClipBounds(Rectangle r) { | public Rectangle getClipBounds(Rectangle r) { | ||||
String l = | String l = | ||||
"getClipBounds(Rectangle):" + | "getClipBounds(Rectangle):" + | ||||
return g2D.getClipBounds( r ); | return g2D.getClipBounds( r ); | ||||
} | } | ||||
@Override | |||||
public Color getColor() { | public Color getColor() { | ||||
log.println( "getColor():" ); | log.println( "getColor():" ); | ||||
return g2D.getColor(); | return g2D.getColor(); | ||||
} | } | ||||
@Override | |||||
public Font getFont() { | public Font getFont() { | ||||
log.println( "getFont():" ); | log.println( "getFont():" ); | ||||
return g2D.getFont(); | return g2D.getFont(); | ||||
} | } | ||||
@Override | |||||
public FontMetrics getFontMetrics() { | public FontMetrics getFontMetrics() { | ||||
log.println( "getFontMetrics():" ); | log.println( "getFontMetrics():" ); | ||||
return g2D.getFontMetrics(); | return g2D.getFontMetrics(); | ||||
} | } | ||||
@Override | |||||
public FontMetrics getFontMetrics(Font f) { | public FontMetrics getFontMetrics(Font f) { | ||||
log.println( "getFontMetrics():" ); | log.println( "getFontMetrics():" ); | ||||
return g2D.getFontMetrics( f ); | return g2D.getFontMetrics( f ); | ||||
} | } | ||||
@Override | |||||
public boolean hitClip(int x, int y, int width, int height) { | public boolean hitClip(int x, int y, int width, int height) { | ||||
String l = | String l = | ||||
"hitClip(int,int,int,int):" + | "hitClip(int,int,int,int):" + | ||||
return g2D.hitClip( x, y, width, height ); | return g2D.hitClip( x, y, width, height ); | ||||
} | } | ||||
@Override | |||||
public void setClip(Shape clip) { | public void setClip(Shape clip) { | ||||
String l = | String l = | ||||
"setClip(Shape):" + | "setClip(Shape):" + | ||||
g2D.setClip( clip ); | g2D.setClip( clip ); | ||||
} | } | ||||
@Override | |||||
public void setClip(int x, int y, int width, int height) { | public void setClip(int x, int y, int width, int height) { | ||||
String l = | String l = | ||||
"setClip(int,int,int,int):" + | "setClip(int,int,int,int):" + | ||||
g2D.setClip( x, y, width, height ); | g2D.setClip( x, y, width, height ); | ||||
} | } | ||||
@Override | |||||
public void setColor(Color c) { | public void setColor(Color c) { | ||||
log.println( String.format(Locale.ROOT, "g.setColor(new Color(0x%08X));", c.getRGB())); | |||||
log.printf(Locale.ROOT, "g.setColor(new Color(0x%08X));%n", c.getRGB()); | |||||
g2D.setColor( c ); | g2D.setColor( c ); | ||||
} | } | ||||
@Override | |||||
public void setFont(Font font) { | public void setFont(Font font) { | ||||
String l = | String l = | ||||
"setFont(Font):" + | "setFont(Font):" + | ||||
g2D.setFont( font ); | g2D.setFont( font ); | ||||
} | } | ||||
@Override | |||||
public void setPaintMode() { | public void setPaintMode() { | ||||
log.println( "setPaintMode():" ); | log.println( "setPaintMode():" ); | ||||
g2D.setPaintMode(); | g2D.setPaintMode(); | ||||
} | } | ||||
@Override | |||||
public void setXORMode(Color c1) { | public void setXORMode(Color c1) { | ||||
String l = | String l = | ||||
"setXORMode(Color):" + | "setXORMode(Color):" + | ||||
return g2D.toString(); | return g2D.toString(); | ||||
} | } | ||||
@Override | |||||
public void translate(int x, int y) { | public void translate(int x, int y) { | ||||
String l = | String l = | ||||
"translate(int,int):" + | "translate(int,int):" + |
package org.apache.poi.xssf.usermodel; | package org.apache.poi.xssf.usermodel; | ||||
import java.io.ByteArrayInputStream; | |||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.nio.charset.StandardCharsets; | import java.nio.charset.StandardCharsets; | ||||
import java.util.EnumMap; | import java.util.EnumMap; | ||||
import javax.xml.transform.dom.DOMSource; | import javax.xml.transform.dom.DOMSource; | ||||
import javax.xml.transform.stream.StreamResult; | import javax.xml.transform.stream.StreamResult; | ||||
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream; | |||||
import org.apache.commons.io.output.StringBuilderWriter; | import org.apache.commons.io.output.StringBuilderWriter; | ||||
import org.apache.poi.ooxml.util.DocumentHelper; | import org.apache.poi.ooxml.util.DocumentHelper; | ||||
import org.apache.poi.ss.usermodel.DifferentialStyleProvider; | import org.apache.poi.ss.usermodel.DifferentialStyleProvider; | ||||
import org.apache.poi.ss.usermodel.TableStyle; | import org.apache.poi.ss.usermodel.TableStyle; | ||||
import org.apache.poi.ss.usermodel.TableStyleType; | import org.apache.poi.ss.usermodel.TableStyleType; | ||||
import org.apache.poi.util.IOUtils; | |||||
import org.apache.poi.util.XMLHelper; | import org.apache.poi.util.XMLHelper; | ||||
import org.apache.poi.xssf.model.StylesTable; | import org.apache.poi.xssf.model.StylesTable; | ||||
import org.w3c.dom.Document; | import org.w3c.dom.Document; | ||||
* </tableStyles> | * </tableStyles> | ||||
* </styleName> | * </styleName> | ||||
*/ | */ | ||||
try { | |||||
final InputStream is = XSSFBuiltinTableStyle.class.getResourceAsStream("presetTableStyles.xml"); | |||||
try { | |||||
final Document doc = DocumentHelper.readDocument(is); | |||||
try (InputStream is = XSSFBuiltinTableStyle.class.getResourceAsStream("presetTableStyles.xml")) { | |||||
final Document doc = DocumentHelper.readDocument(is); | |||||
final NodeList styleNodes = doc.getDocumentElement().getChildNodes(); | |||||
for (int i = 0; i < styleNodes.getLength(); i++) { | |||||
final Node node = styleNodes.item(i); | |||||
if (node.getNodeType() != Node.ELEMENT_NODE) continue; // only care about elements | |||||
final Element tag = (Element) node; | |||||
String styleName = tag.getTagName(); | |||||
XSSFBuiltinTableStyle builtIn = XSSFBuiltinTableStyle.valueOf(styleName); | |||||
final NodeList styleNodes = doc.getDocumentElement().getChildNodes(); | |||||
for (int i = 0; i < styleNodes.getLength(); i++) { | |||||
final Node node = styleNodes.item(i); | |||||
if (node.getNodeType() != Node.ELEMENT_NODE) continue; // only care about elements | |||||
final Element tag = (Element) node; | |||||
String styleName = tag.getTagName(); | |||||
XSSFBuiltinTableStyle builtIn = XSSFBuiltinTableStyle.valueOf(styleName); | |||||
Node dxfsNode = tag.getElementsByTagName("dxfs").item(0); | |||||
Node tableStyleNode = tag.getElementsByTagName("tableStyles").item(0); | |||||
Node dxfsNode = tag.getElementsByTagName("dxfs").item(0); | |||||
Node tableStyleNode = tag.getElementsByTagName("tableStyles").item(0); | |||||
// hack because I can't figure out how to get XMLBeans to parse a sub-element in a standalone manner | |||||
// - build a fake styles.xml file with just this built-in | |||||
StylesTable styles = new StylesTable(); | |||||
styles.readFrom(new UnsynchronizedByteArrayInputStream(styleXML(dxfsNode, tableStyleNode).getBytes(StandardCharsets.UTF_8))); | |||||
styleMap.put(builtIn, new XSSFBuiltinTypeStyleStyle(builtIn, styles.getExplicitTableStyle(styleName))); | |||||
} | |||||
} finally { | |||||
IOUtils.closeQuietly(is); | |||||
// hack because I can't figure out how to get XMLBeans to parse a sub-element in a standalone manner | |||||
// - build a fake styles.xml file with just this built-in | |||||
StylesTable styles = new StylesTable(); | |||||
styles.readFrom(new ByteArrayInputStream(styleXML(dxfsNode, tableStyleNode).getBytes(StandardCharsets.UTF_8))); | |||||
styleMap.put(builtIn, new XSSFBuiltinTypeStyleStyle(builtIn, styles.getExplicitTableStyle(styleName))); | |||||
} | } | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
throw new RuntimeException(e); | throw new RuntimeException(e); |
public class OLE2ScratchpadExtractorFactory implements ExtractorProvider { | public class OLE2ScratchpadExtractorFactory implements ExtractorProvider { | ||||
private static final Logger LOG = LogManager.getLogger(OLE2ScratchpadExtractorFactory.class); | private static final Logger LOG = LogManager.getLogger(OLE2ScratchpadExtractorFactory.class); | ||||
private static final String[] OUTLOOK_ENTRY_NAMES = { | |||||
// message bodies, saved as plain text (PtypString) | |||||
// The first short (0x1000, 0x0047, 0x0037) refer to the Property ID (see [MS-OXPROPS].pdf) | |||||
// the second short (0x001e, 0x001f, 0x0102) refer to the type of data stored in this entry | |||||
// https://msdn.microsoft.com/endatatypes.Ex-us/library/cc433490(v=exchg.80).aspx | |||||
// @see org.apache.poi.hsmf.Types.MAPIType | |||||
"__substg1.0_1000001E", //PidTagBody ASCII | |||||
"__substg1.0_1000001F", //PidTagBody Unicode | |||||
"__substg1.0_0047001E", //PidTagMessageSubmissionId ASCII | |||||
"__substg1.0_0047001F", //PidTagMessageSubmissionId Unicode | |||||
"__substg1.0_0037001E", //PidTagSubject ASCII | |||||
"__substg1.0_0037001F", //PidTagSubject Unicode | |||||
}; | |||||
@Override | @Override | ||||
public boolean accepts(FileMagic fm) { | public boolean accepts(FileMagic fm) { | ||||
return FileMagic.OLE2 == fm; | return FileMagic.OLE2 == fm; | ||||
* | * | ||||
* @throws IOException when the format specific extraction fails because of invalid entires | * @throws IOException when the format specific extraction fails because of invalid entires | ||||
*/ | */ | ||||
@SuppressWarnings("java:S2093") | |||||
@Override | |||||
public POITextExtractor create(DirectoryNode poifsDir, String password) throws IOException { | public POITextExtractor create(DirectoryNode poifsDir, String password) throws IOException { | ||||
final String oldPW = Biff8EncryptionKey.getCurrentUserPassword(); | final String oldPW = Biff8EncryptionKey.getCurrentUserPassword(); | ||||
try { | try { | ||||
return new PublisherTextExtractor(poifsDir); | return new PublisherTextExtractor(poifsDir); | ||||
} | } | ||||
final String[] outlookEntryNames = new String[]{ | |||||
// message bodies, saved as plain text (PtypString) | |||||
// The first short (0x1000, 0x0047, 0x0037) refer to the Property ID (see [MS-OXPROPS].pdf) | |||||
// the second short (0x001e, 0x001f, 0x0102) refer to the type of data stored in this entry | |||||
// https://msdn.microsoft.com/endatatypes.Ex-us/library/cc433490(v=exchg.80).aspx | |||||
// @see org.apache.poi.hsmf.Types.MAPIType | |||||
"__substg1.0_1000001E", //PidTagBody ASCII | |||||
"__substg1.0_1000001F", //PidTagBody Unicode | |||||
"__substg1.0_0047001E", //PidTagMessageSubmissionId ASCII | |||||
"__substg1.0_0047001F", //PidTagMessageSubmissionId Unicode | |||||
"__substg1.0_0037001E", //PidTagSubject ASCII | |||||
"__substg1.0_0037001F", //PidTagSubject Unicode | |||||
}; | |||||
for (String entryName : outlookEntryNames) { | |||||
for (String entryName : OUTLOOK_ENTRY_NAMES) { | |||||
if (poifsDir.hasEntry(entryName)) { | if (poifsDir.hasEntry(entryName)) { | ||||
return new OutlookTextExtractor(poifsDir); | return new OutlookTextExtractor(poifsDir); | ||||
} | } |
* | * | ||||
* @return The created SlideShow | * @return The created SlideShow | ||||
*/ | */ | ||||
@Override | |||||
public HSLFSlideShow create() { | public HSLFSlideShow create() { | ||||
return new HSLFSlideShow(); | return new HSLFSlideShow(); | ||||
} | } | ||||
* Note that in order to properly release resources the | * Note that in order to properly release resources the | ||||
* SlideShow should be closed after use. | * SlideShow should be closed after use. | ||||
*/ | */ | ||||
@Override | |||||
@SuppressWarnings("java:S2093") | |||||
public HSLFSlideShow create(final DirectoryNode root, String password) throws IOException { | public HSLFSlideShow create(final DirectoryNode root, String password) throws IOException { | ||||
boolean passwordSet = false; | boolean passwordSet = false; | ||||
if (password != null) { | if (password != null) { | ||||
return create(fs.getRoot(), password); | return create(fs.getRoot(), password); | ||||
} | } | ||||
@SuppressWarnings("java:S2093") | |||||
@Override | @Override | ||||
public HSLFSlideShow create(File file, String password, boolean readOnly) throws IOException { | public HSLFSlideShow create(File file, String password, boolean readOnly) throws IOException { | ||||
boolean passwordSet = false; | boolean passwordSet = false; |
import org.apache.poi.hwpf.model.FieldsDocumentPart; | import org.apache.poi.hwpf.model.FieldsDocumentPart; | ||||
import org.apache.poi.hwpf.model.FileInformationBlock; | import org.apache.poi.hwpf.model.FileInformationBlock; | ||||
import org.apache.poi.hwpf.model.GenericPropertyNode; | import org.apache.poi.hwpf.model.GenericPropertyNode; | ||||
import org.apache.poi.hwpf.model.LFO; | |||||
import org.apache.poi.hwpf.model.LFOData; | |||||
import org.apache.poi.hwpf.model.ListLevel; | |||||
import org.apache.poi.hwpf.model.ListTables; | |||||
import org.apache.poi.hwpf.model.PAPFormattedDiskPage; | import org.apache.poi.hwpf.model.PAPFormattedDiskPage; | ||||
import org.apache.poi.hwpf.model.PAPX; | import org.apache.poi.hwpf.model.PAPX; | ||||
import org.apache.poi.hwpf.model.PlexOfCps; | import org.apache.poi.hwpf.model.PlexOfCps; | ||||
import org.apache.poi.hwpf.usermodel.Field; | import org.apache.poi.hwpf.usermodel.Field; | ||||
import org.apache.poi.hwpf.usermodel.OfficeDrawing; | import org.apache.poi.hwpf.usermodel.OfficeDrawing; | ||||
import org.apache.poi.hwpf.usermodel.Paragraph; | import org.apache.poi.hwpf.usermodel.Paragraph; | ||||
import org.apache.poi.hwpf.usermodel.ParagraphProperties; | |||||
import org.apache.poi.hwpf.usermodel.Picture; | import org.apache.poi.hwpf.usermodel.Picture; | ||||
import org.apache.poi.hwpf.usermodel.Range; | import org.apache.poi.hwpf.usermodel.Range; | ||||
import org.apache.poi.poifs.common.POIFSConstants; | import org.apache.poi.poifs.common.POIFSConstants; | ||||
char c = text.charAt( charIndex ); | char c = text.charAt( charIndex ); | ||||
part.append( c ); | part.append( c ); | ||||
if ( c == 13 || c == 7 || c == 12 ) { | if ( c == 13 || c == 7 || c == 12 ) { | ||||
paragraphs.put( Integer.valueOf( charIndex ), part.toString() ); | |||||
paragraphs.put(charIndex, part.toString() ); | |||||
part.setLength( 0 ); | part.setLength( 0 ); | ||||
} | } | ||||
} | } | ||||
.hasNext(); ) { | .hasNext(); ) { | ||||
Entry entry = iterator.next(); | Entry entry = iterator.next(); | ||||
String entryToString = "\n" + dumpFileSystem( entry ); | String entryToString = "\n" + dumpFileSystem( entry ); | ||||
entryToString = entryToString.replaceAll( "\n", "\n+---" ); | |||||
entryToString = entryToString.replace("\n", "\n+---"); | |||||
result.append( entryToString ); | result.append( entryToString ); | ||||
} | } | ||||
result.append( "\n" ); | result.append( "\n" ); | ||||
} | } | ||||
} | } | ||||
protected void dumpSprms( SprmIterator sprmIt, String linePrefix ) { | |||||
private void dumpSprms(SprmIterator sprmIt, String linePrefix) { | |||||
while ( sprmIt.hasNext() ) { | while ( sprmIt.hasNext() ) { | ||||
SprmOperation sprm = sprmIt.next(); | SprmOperation sprm = sprmIt.next(); | ||||
System.out.println( linePrefix + sprm); | System.out.println( linePrefix + sprm); | ||||
} | } | ||||
} | } | ||||
protected void dumpParagraphLevels( ListTables listTables, | |||||
ParagraphProperties paragraph ) { | |||||
if ( paragraph.getIlfo() != 0 ) { | |||||
final LFO lfo = listTables.getLfo( paragraph.getIlfo() ); | |||||
System.out.println( "PAP's LFO: " + lfo ); | |||||
final LFOData lfoData = listTables.getLfoData( paragraph.getIlfo() ); | |||||
System.out.println( "PAP's LFOData: " + lfoData ); | |||||
if ( lfo != null ) { | |||||
final ListLevel listLevel = listTables.getLevel( lfo.getLsid(), | |||||
paragraph.getIlvl() ); | |||||
System.out.println( "PAP's ListLevel: " + listLevel ); | |||||
if ( listLevel.getGrpprlPapx() != null ) { | |||||
System.out.println( "PAP's ListLevel PAPX:" ); | |||||
dumpSprms( | |||||
new SprmIterator( listLevel.getGrpprlPapx(), 0 ), | |||||
"* " ); | |||||
} | |||||
if ( listLevel.getGrpprlPapx() != null ) { | |||||
System.out.println( "PAP's ListLevel CHPX:" ); | |||||
dumpSprms( | |||||
new SprmIterator( listLevel.getGrpprlChpx(), 0 ), | |||||
"* " ); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
public void dumpTextPieces( boolean withText ) { | public void dumpTextPieces( boolean withText ) { | ||||
for ( TextPiece textPiece : _doc.getTextTable().getTextPieces() ) { | for ( TextPiece textPiece : _doc.getTextTable().getTextPieces() ) { | ||||
System.out.println( textPiece ); | System.out.println( textPiece ); |
* with HWPF. | * with HWPF. | ||||
*/ | */ | ||||
public final class Word6Extractor implements POIOLE2TextExtractor { | public final class Word6Extractor implements POIOLE2TextExtractor { | ||||
private HWPFOldDocument doc; | |||||
private final HWPFOldDocument doc; | |||||
private boolean doCloseFilesystem = true; | private boolean doCloseFilesystem = true; | ||||
/** | /** | ||||
ret[i] = doc.getTextTable().getTextPieces().get(i).getStringBuilder().toString(); | ret[i] = doc.getTextTable().getTextPieces().get(i).getStringBuilder().toString(); | ||||
// Fix the line endings | // Fix the line endings | ||||
ret[i] = ret[i].replaceAll("\r", "\ufffe"); | |||||
ret[i] = ret[i].replaceAll("\ufffe","\r\n"); | |||||
ret[i] = ret[i].replace("\r", "\ufffe"); | |||||
ret[i] = ret[i].replace("\ufffe","\r\n"); | |||||
} | } | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
@Override | |||||
public String getText() { | public String getText() { | ||||
try { | try { | ||||
WordToTextConverter wordToTextConverter = new WordToTextConverter(); | WordToTextConverter wordToTextConverter = new WordToTextConverter(); |
String text = doc.getDocumentText(); | String text = doc.getDocumentText(); | ||||
// Fix line endings (Note - won't get all of them | // Fix line endings (Note - won't get all of them | ||||
text = text.replaceAll( "\r\r\r", "\r\n\r\n\r\n" ); | |||||
text = text.replaceAll( "\r\r", "\r\n\r\n" ); | |||||
text = text.replace( "\r\r\r", "\r\n\r\n\r\n" ); | |||||
text = text.replace( "\r\r", "\r\n\r\n" ); | |||||
if ( text.endsWith( "\r" )) { | if ( text.endsWith( "\r" )) { | ||||
text += "\n"; | text += "\n"; | ||||
* Grab the text, based on the WordToTextConverter. Shouldn't include any | * Grab the text, based on the WordToTextConverter. Shouldn't include any | ||||
* crud, but slower than getTextFromPieces(). | * crud, but slower than getTextFromPieces(). | ||||
*/ | */ | ||||
@Override | |||||
public String getText() { | public String getText() { | ||||
try { | try { | ||||
WordToTextConverter wordToTextConverter = new WordToTextConverter(); | WordToTextConverter wordToTextConverter = new WordToTextConverter(); |
import org.apache.logging.log4j.LogManager; | import org.apache.logging.log4j.LogManager; | ||||
import org.apache.logging.log4j.Logger; | import org.apache.logging.log4j.Logger; | ||||
import org.apache.poi.hwpf.model.types.FibBaseAbstractType; | import org.apache.poi.hwpf.model.types.FibBaseAbstractType; | ||||
import org.apache.poi.hwpf.model.types.FibRgLw97AbstractType; | |||||
import org.apache.poi.hwpf.model.types.FibRgW97AbstractType; | import org.apache.poi.hwpf.model.types.FibRgW97AbstractType; | ||||
import org.apache.poi.util.IOUtils; | import org.apache.poi.util.IOUtils; | ||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
private final FibRgLw _fibRgLw; | private final FibRgLw _fibRgLw; | ||||
private int _cbRgFcLcb; | private int _cbRgFcLcb; | ||||
private FIBFieldHandler _fieldHandler; | private FIBFieldHandler _fieldHandler; | ||||
private int _cswNew; | |||||
private final int _cswNew; | |||||
private final int _nFibNew; | private final int _nFibNew; | ||||
private final byte[] _fibRgCswNew; | private final byte[] _fibRgCswNew; | ||||
if ( _fibBase.getNFib() < 105 ) | if ( _fibBase.getNFib() < 105 ) | ||||
{ | { | ||||
_fibRgLw = new FibRgLw95( mainDocument, offset ); | _fibRgLw = new FibRgLw95( mainDocument, offset ); | ||||
offset += FibRgLw97.getSize(); | |||||
offset += FibRgLw97AbstractType.getSize(); | |||||
// magic number, run tests after changes | // magic number, run tests after changes | ||||
_cbRgFcLcb = 74; | _cbRgFcLcb = 74; | ||||
// skip fibRgFcLcbBlob (read later at fillVariableFields) | // skip fibRgFcLcbBlob (read later at fillVariableFields) | ||||
offset += _cbRgFcLcb * LittleEndianConsts.INT_SIZE * 2; | offset += _cbRgFcLcb * LittleEndianConsts.INT_SIZE * 2; | ||||
_cswNew = LittleEndian.getUShort( mainDocument, offset ); | |||||
offset += LittleEndianConsts.SHORT_SIZE; | |||||
// _cswNew = LittleEndian.getUShort( mainDocument, offset ); | |||||
_cswNew = 0; | _cswNew = 0; | ||||
_nFibNew = -1; | _nFibNew = -1; | ||||
_fibRgCswNew = new byte[0]; | _fibRgCswNew = new byte[0]; | ||||
} | } | ||||
_fibRgLw = new FibRgLw97( mainDocument, offset ); | _fibRgLw = new FibRgLw97( mainDocument, offset ); | ||||
offset += FibRgLw97.getSize(); | |||||
offset += FibRgLw97AbstractType.getSize(); | |||||
assert offset == 152; | assert offset == 152; | ||||
_cbRgFcLcb = LittleEndian.getUShort( mainDocument, offset ); | _cbRgFcLcb = LittleEndian.getUShort( mainDocument, offset ); | ||||
offset += LittleEndianConsts.SHORT_SIZE; | offset += LittleEndianConsts.SHORT_SIZE; | ||||
( (FibRgLw97) _fibRgLw ).serialize( mainStream, offset ); | ( (FibRgLw97) _fibRgLw ).serialize( mainStream, offset ); | ||||
offset += FibRgLw97.getSize(); | |||||
offset += FibRgLw97AbstractType.getSize(); | |||||
LittleEndian.putUShort( mainStream, offset, _cbRgFcLcb ); | LittleEndian.putUShort( mainStream, offset, _cbRgFcLcb ); | ||||
offset += LittleEndianConsts.SHORT_SIZE; | offset += LittleEndianConsts.SHORT_SIZE; | ||||
LittleEndian.putUShort( mainStream, offset, _nFibNew ); | LittleEndian.putUShort( mainStream, offset, _nFibNew ); | ||||
offset += LittleEndianConsts.SHORT_SIZE; | offset += LittleEndianConsts.SHORT_SIZE; | ||||
System.arraycopy( _fibRgCswNew, 0, mainStream, offset, | |||||
_fibRgCswNew.length ); | |||||
offset += _fibRgCswNew.length; | |||||
System.arraycopy( _fibRgCswNew, 0, mainStream, offset, _fibRgCswNew.length ); | |||||
} | } | ||||
} | } | ||||
public int getSize() | public int getSize() | ||||
{ | { | ||||
return FibBaseAbstractType.getSize() + LittleEndianConsts.SHORT_SIZE + FibRgW97AbstractType.getSize() | return FibBaseAbstractType.getSize() + LittleEndianConsts.SHORT_SIZE + FibRgW97AbstractType.getSize() | ||||
+ LittleEndianConsts.SHORT_SIZE + FibRgLw97.getSize() | |||||
+ LittleEndianConsts.SHORT_SIZE + FibRgLw97AbstractType.getSize() | |||||
+ LittleEndianConsts.SHORT_SIZE + _fieldHandler.sizeInBytes(); | + LittleEndianConsts.SHORT_SIZE + _fieldHandler.sizeInBytes(); | ||||
} | } | ||||
offset += _grpprlChpx.length; | offset += _grpprlChpx.length; | ||||
_xst.serialize( buf, offset ); | _xst.serialize( buf, offset ); | ||||
offset += _xst.getSize(); | |||||
return buf; | return buf; | ||||
} | } | ||||
@Override | @Override | ||||
public String toString() | public String toString() | ||||
{ | { | ||||
return "LVL: " + ( "\n" + _lvlf ).replaceAll( "\n", "\n " ) | |||||
return "LVL: " + ( "\n" + _lvlf ).replace( "\n", "\n " ) | |||||
+ "\n" | + "\n" | ||||
+ ( "PAPX's grpprl: " + Arrays.toString( _grpprlPapx ) + "\n" ) | + ( "PAPX's grpprl: " + Arrays.toString( _grpprlPapx ) + "\n" ) | ||||
+ ( "CHPX's grpprl: " + Arrays.toString( _grpprlChpx ) + "\n" ) | + ( "CHPX's grpprl: " + Arrays.toString( _grpprlChpx ) + "\n" ) |
public final class StyleDescription { | public final class StyleDescription { | ||||
private static final Logger LOG = LogManager.getLogger(StyleDescription.class); | private static final Logger LOG = LogManager.getLogger(StyleDescription.class); | ||||
//arbitrarily selected; may need to increase | |||||
private static final int MAX_RECORD_LENGTH = 100_000; | |||||
private static final int PARAGRAPH_STYLE = 1; | private static final int PARAGRAPH_STYLE = 1; | ||||
private static final int CHARACTER_STYLE = 2; | private static final int CHARACTER_STYLE = 2; | ||||
//first byte(s) of variable length section of std is the length of the | //first byte(s) of variable length section of std is the length of the | ||||
//style name and aliases string | //style name and aliases string | ||||
int nameLength = 0; | |||||
int multiplier = 1; | |||||
int nameLength; | |||||
int multiplier; | |||||
if (word9) { | if (word9) { | ||||
nameLength = LittleEndian.getShort(std, nameStart); | nameLength = LittleEndian.getShort(std, nameStart); | ||||
multiplier = 2; | multiplier = 2; | ||||
nameStart += LittleEndianConsts.SHORT_SIZE; | nameStart += LittleEndianConsts.SHORT_SIZE; | ||||
} else { | } else { | ||||
multiplier = 1; | |||||
nameLength = std[nameStart]; | nameLength = std[nameStart]; | ||||
} | } | ||||
result.append("[STD]: '"); | result.append("[STD]: '"); | ||||
result.append(_name); | result.append(_name); | ||||
result.append("'"); | result.append("'"); | ||||
result.append(("\nStdfBase:\t" + _stdfBase).replaceAll("\n", | |||||
"\n ")); | |||||
result.append(("\nStdfPost2000:\t" + _stdfPost2000).replaceAll( | |||||
"\n", "\n ")); | |||||
result.append(("\nStdfBase:\t" + _stdfBase).replace("\n", "\n ")); | |||||
result.append(("\nStdfPost2000:\t" + _stdfPost2000).replace("\n", "\n ")); | |||||
for (UPX upx : _upxs) { | for (UPX upx : _upxs) { | ||||
result.append(("\nUPX:\t" + upx).replaceAll("\n", "\n ")); | |||||
result.append(("\nUPX:\t" + upx).replace("\n", "\n ")); | |||||
} | } | ||||
return result.toString(); | return result.toString(); | ||||
} | } |
field_6_grfhic, field_7_unused3); | field_6_grfhic, field_7_unused3); | ||||
} | } | ||||
public String toString() | |||||
{ | |||||
StringBuilder builder = new StringBuilder(); | |||||
builder.append("[LFO]\n"); | |||||
builder.append( " .lsid = " ); | |||||
builder.append(" ( ").append( field_1_lsid ).append( " )\n" ); | |||||
builder.append( " .unused1 = " ); | |||||
builder.append(" ( ").append( field_2_unused1 ).append( " )\n" ); | |||||
builder.append( " .unused2 = " ); | |||||
builder.append(" ( ").append( field_3_unused2 ).append( " )\n" ); | |||||
builder.append( " .clfolvl = " ); | |||||
builder.append(" ( ").append( field_4_clfolvl ).append( " )\n" ); | |||||
builder.append( " .ibstFltAutoNum = " ); | |||||
builder.append(" ( ").append( field_5_ibstFltAutoNum ).append( " )\n" ); | |||||
builder.append( " .grfhic = " ); | |||||
builder.append(" ( ").append( field_6_grfhic == null ? "null" : field_6_grfhic.toString().replaceAll( "\n", "\n " ) ).append( " )\n" ); | |||||
builder.append( " .unused3 = " ); | |||||
builder.append(" ( ").append( field_7_unused3 ).append( " )\n" ); | |||||
builder.append("[/LFO]"); | |||||
return builder.toString(); | |||||
public String toString() { | |||||
return "[LFO]\n" + | |||||
" .lsid = " + | |||||
" ( " + field_1_lsid + " )\n" + | |||||
" .unused1 = " + | |||||
" ( " + field_2_unused1 + " )\n" + | |||||
" .unused2 = " + | |||||
" ( " + field_3_unused2 + " )\n" + | |||||
" .clfolvl = " + | |||||
" ( " + field_4_clfolvl + " )\n" + | |||||
" .ibstFltAutoNum = " + | |||||
" ( " + field_5_ibstFltAutoNum + " )\n" + | |||||
" .grfhic = " + | |||||
" ( " + (field_6_grfhic == null ? "null" : field_6_grfhic.toString().replace("\n", "\n ")) + " )\n" + | |||||
" .unused3 = " + | |||||
" ( " + field_7_unused3 + " )\n" + | |||||
"[/LFO]"; | |||||
} | } | ||||
/** | /** |
return create(new POIFSFileSystem(inputStream).getRoot(), password); | return create(new POIFSFileSystem(inputStream).getRoot(), password); | ||||
} | } | ||||
@SuppressWarnings("java:S2093") | |||||
@Override | @Override | ||||
public POITextExtractor create(DirectoryNode poifsDir, String password) throws IOException { | public POITextExtractor create(DirectoryNode poifsDir, String password) throws IOException { | ||||
final String oldPW = Biff8EncryptionKey.getCurrentUserPassword(); | final String oldPW = Biff8EncryptionKey.getCurrentUserPassword(); |
open(input); | open(input); | ||||
} | } | ||||
@SuppressWarnings("java:S2093") | |||||
public OldExcelExtractor(File f) throws IOException { | public OldExcelExtractor(File f) throws IOException { | ||||
POIFSFileSystem poifs = null; | POIFSFileSystem poifs = null; | ||||
try { | try { | ||||
open(directory); | open(directory); | ||||
} | } | ||||
@SuppressWarnings("java:S2093") | |||||
private void open(InputStream biffStream) throws IOException { | private void open(InputStream biffStream) throws IOException { | ||||
BufferedInputStream bis = (biffStream instanceof BufferedInputStream) | BufferedInputStream bis = (biffStream instanceof BufferedInputStream) | ||||
? (BufferedInputStream)biffStream | ? (BufferedInputStream)biffStream | ||||
* | * | ||||
* @return the text contents of the file | * @return the text contents of the file | ||||
*/ | */ | ||||
@Override | |||||
public String getText() { | public String getText() { | ||||
StringBuilder text = new StringBuilder(); | StringBuilder text = new StringBuilder(); | ||||
* DConRef records specify a range in a workbook (internal or external) that serves as a data source | * DConRef records specify a range in a workbook (internal or external) that serves as a data source | ||||
* for pivot tables or data consolidation. | * for pivot tables or data consolidation. | ||||
* | * | ||||
* Represents a <code>DConRef</code> Structure | |||||
* Represents a {@code DConRef} Structure | |||||
* <a href="http://msdn.microsoft.com/en-us/library/dd923854(office.12).aspx">[MS-XLS s. | * <a href="http://msdn.microsoft.com/en-us/library/dd923854(office.12).aspx">[MS-XLS s. | ||||
* 2.4.86]</a>, and the contained <code>DConFile</code> structure | |||||
* 2.4.86]</a>, and the contained {@code DConFile} structure | |||||
* <a href="http://msdn.microsoft.com/en-us/library/dd950157(office.12).aspx"> | * <a href="http://msdn.microsoft.com/en-us/library/dd950157(office.12).aspx"> | ||||
* [MS-XLS s. 2.5.69]</a>. This in turn contains a <code>XLUnicodeStringNoCch</code> | |||||
* [MS-XLS s. 2.5.69]</a>. This in turn contains a {@code XLUnicodeStringNoCch} | |||||
* <a href="http://msdn.microsoft.com/en-us/library/dd910585(office.12).aspx"> | * <a href="http://msdn.microsoft.com/en-us/library/dd910585(office.12).aspx"> | ||||
* [MS-XLS s. 2.5.296]</a>. | * [MS-XLS s. 2.5.296]</a>. | ||||
* | * | ||||
* </pre> | * </pre> | ||||
* Where | * Where | ||||
* <ul> | * <ul> | ||||
* <li><code>DConFile.h = 0x00</code> if the characters in<code>rgb</code> are single byte, and | |||||
* <code>DConFile.h = 0x01</code> if they are double byte.<p> | |||||
* <li>{@code DConFile.h = 0x00} if the characters in{@code rgb} are single byte, and | |||||
* {@code DConFile.h = 0x01} if they are double byte.<p> | |||||
* If they are double byte, then | * If they are double byte, then | ||||
* <ul> | * <ul> | ||||
* <li> If it exists, the length of <code>DConRef.un = 2</code>. Otherwise it is 1. | |||||
* <li> The length of <code>DConFile.rgb = (2 * DConRef.cch)</code>. Otherwise it is equal to | |||||
* <code>DConRef.cch</code>. | |||||
* <li> If it exists, the length of {@code DConRef.un = 2}. Otherwise it is 1. | |||||
* <li> The length of {@code DConFile.rgb = (2 * DConRef.cch)}. Otherwise it is equal to | |||||
* {@code DConRef.cch}. | |||||
* </ul> | * </ul> | ||||
* <li><code>DConRef.rgb</code> starts with <code>0x01</code> if it is an external reference, | |||||
* and with <code>0x02</code> if it is a self-reference. | |||||
* <li>{@code DConRef.rgb} starts with {@code 0x01} if it is an external reference, | |||||
* and with {@code 0x02} if it is a self-reference. | |||||
* </ul> | * </ul> | ||||
* | * | ||||
* At the moment this class is read-only. | * At the moment this class is read-only. | ||||
* <a href="http://msdn.microsoft.com/en-us/library/dd920420(office.12).aspx"> | * <a href="http://msdn.microsoft.com/en-us/library/dd920420(office.12).aspx"> | ||||
* [MS XLS s.2.5.211]</a> | * [MS XLS s.2.5.211]</a> | ||||
*/ | */ | ||||
private int firstRow, lastRow, firstCol, lastCol; | |||||
private final int firstRow; | |||||
private final int lastRow; | |||||
private final int firstCol; | |||||
private final int lastCol; | |||||
/** | /** | ||||
* the number of chars in the link | * the number of chars in the link | ||||
*/ | */ | ||||
private int charCount; | |||||
private final int charCount; | |||||
/** | /** | ||||
* the type of characters (single or double byte) | * the type of characters (single or double byte) | ||||
*/ | */ | ||||
private int charType; | |||||
private final int charType; | |||||
/** | /** | ||||
* The link's path string. This is the <code>rgb</code> field of a | |||||
* <code>XLUnicodeStringNoCch</code>. Therefore it will contain at least one leading special | |||||
* The link's path string. This is the {@code rgb} field of a | |||||
* {@code XLUnicodeStringNoCch}. Therefore it will contain at least one leading special | |||||
* character (0x01 or 0x02) and probably other ones.<p> | * character (0x01 or 0x02) and probably other ones.<p> | ||||
* @see <A href="http://msdn.microsoft.com/en-us/library/dd923491(office.12).aspx"> | * @see <A href="http://msdn.microsoft.com/en-us/library/dd923491(office.12).aspx"> | ||||
* DConFile [MS-XLS s. 2.5.77]</A> and | * DConFile [MS-XLS s. 2.5.77]</A> and | ||||
* <A href="http://msdn.microsoft.com/en-us/library/dd950157(office.12).aspx"> | * <A href="http://msdn.microsoft.com/en-us/library/dd950157(office.12).aspx"> | ||||
* VirtualPath [MS-XLS s. 2.5.69]</a> | * VirtualPath [MS-XLS s. 2.5.69]</a> | ||||
* <p> | |||||
*/ | */ | ||||
private byte[] path; | |||||
private final byte[] path; | |||||
/** | /** | ||||
* unused bits at the end, must be set to 0. | * unused bits at the end, must be set to 0. | ||||
*/ | */ | ||||
} | } | ||||
String out = new String(Arrays.copyOfRange(path, offset, path.length), StringUtil.UTF8); | String out = new String(Arrays.copyOfRange(path, offset, path.length), StringUtil.UTF8); | ||||
//UNC paths have \u0003 chars as path separators. | //UNC paths have \u0003 chars as path separators. | ||||
out = out.replaceAll("\u0003", "/"); | |||||
out = out.replace("\u0003", "/"); | |||||
return out; | return out; | ||||
} | } | ||||
return null; | return null; |
* Note that in order to properly release resources the | * Note that in order to properly release resources the | ||||
* Workbook should be closed after use. | * Workbook should be closed after use. | ||||
*/ | */ | ||||
@SuppressWarnings("java:S2093") | |||||
@Override | @Override | ||||
public HSSFWorkbook create(final DirectoryNode root, String password) throws IOException { | public HSSFWorkbook create(final DirectoryNode root, String password) throws IOException { | ||||
boolean passwordSet = false; | boolean passwordSet = false; | ||||
} | } | ||||
@Override | @Override | ||||
@SuppressWarnings("java:S2095") | |||||
@SuppressWarnings({"java:S2095","java:S2093"}) | |||||
public Workbook create(File file, String password, boolean readOnly) throws IOException { | public Workbook create(File file, String password, boolean readOnly) throws IOException { | ||||
boolean passwordSet = false; | boolean passwordSet = false; | ||||
if (password != null) { | if (password != null) { |
} | } | ||||
default double evaluateGuide(Context ctx) { | default double evaluateGuide(Context ctx) { | ||||
Guide.Op op; | |||||
Op op; | |||||
String[] operands = WHITESPACE.split(getFmla()); | String[] operands = WHITESPACE.split(getFmla()); | ||||
switch (operands[0]) { | switch (operands[0]) { | ||||
case "*/": op = Guide.Op.muldiv; break; | |||||
case "+-": op = Guide.Op.addsub; break; | |||||
case "+/": op = Guide.Op.adddiv; break; | |||||
case "?:": op = Guide.Op.ifelse; break; | |||||
default: op = Guide.Op.valueOf(operands[0]); break; | |||||
case "*/": op = Op.muldiv; break; | |||||
case "+-": op = Op.addsub; break; | |||||
case "+/": op = Op.adddiv; break; | |||||
case "?:": op = Op.ifelse; break; | |||||
default: op = Op.valueOf(operands[0]); break; | |||||
} | } | ||||
double x = (operands.length > 1) ? ctx.getValue(operands[1]) : 0; | double x = (operands.length > 1) ? ctx.getValue(operands[1]) : 0; |
int rowIndex, int columnIndex, EvaluationTracker tracker) { | int rowIndex, int columnIndex, EvaluationTracker tracker) { | ||||
// avoid tracking dependencies to cells that have constant definition | // avoid tracking dependencies to cells that have constant definition | ||||
boolean shouldCellDependencyBeRecorded = _stabilityClassifier == null ? true | |||||
: !_stabilityClassifier.isCellFinal(sheetIndex, rowIndex, columnIndex); | |||||
boolean shouldCellDependencyBeRecorded = _stabilityClassifier == null || !_stabilityClassifier.isCellFinal(sheetIndex, rowIndex, columnIndex); | |||||
if (srcCell == null || srcCell.getCellType() != CellType.FORMULA) { | if (srcCell == null || srcCell.getCellType() != CellType.FORMULA) { | ||||
ValueEval result = getValueFromNonFormulaCell(srcCell); | ValueEval result = getValueFromNonFormulaCell(srcCell); | ||||
if (shouldCellDependencyBeRecorded) { | if (shouldCellDependencyBeRecorded) { | ||||
String message = finalDbgIndentStr | String message = finalDbgIndentStr | ||||
+ "- evaluateFormula('" + ec.getRefEvaluatorForCurrentSheet().getSheetNameRange() | + "- evaluateFormula('" + ec.getRefEvaluatorForCurrentSheet().getSheetNameRange() | ||||
+ "'/" + new CellReference(ec.getRowIndex(), ec.getColumnIndex()).formatAsString() | + "'/" + new CellReference(ec.getRowIndex(), ec.getColumnIndex()).formatAsString() | ||||
+ "): " + Arrays.toString(ptgs).replaceAll("\\Qorg.apache.poi.ss.formula.ptg.\\E", ""); | |||||
+ "): " + Arrays.toString(ptgs).replace("\\Qorg.apache.poi.ss.formula.ptg.\\E", ""); | |||||
return new SimpleMessage(message); | return new SimpleMessage(message); | ||||
}); | }); | ||||
dbgEvaluationOutputIndent++; | dbgEvaluationOutputIndent++; | ||||
/** | /** | ||||
* returns an appropriate Eval impl instance for the Ptg. The Ptg must be | * returns an appropriate Eval impl instance for the Ptg. The Ptg must be | ||||
* one of: Area3DPtg, AreaPtg, ReferencePtg, Ref3DPtg, IntPtg, NumberPtg, | * one of: Area3DPtg, AreaPtg, ReferencePtg, Ref3DPtg, IntPtg, NumberPtg, | ||||
* StringPtg, BoolPtg<p> | |||||
* StringPtg, BoolPtg | |||||
* <p> | * <p> | ||||
* special Note: OperationPtg subtypes cannot be passed here! | * special Note: OperationPtg subtypes cannot be passed here! | ||||
*/ | */ | ||||
* @throws IndexOutOfBoundsException if the resulting shifted row/column indexes are over the document format limits | * @throws IndexOutOfBoundsException if the resulting shifted row/column indexes are over the document format limits | ||||
* @throws IllegalArgumentException if target is not within region. | * @throws IllegalArgumentException if target is not within region. | ||||
*/ | */ | ||||
protected boolean adjustRegionRelativeReference(Ptg[] ptgs, CellReference target, CellRangeAddressBase region) { | |||||
private boolean adjustRegionRelativeReference(Ptg[] ptgs, CellReference target, CellRangeAddressBase region) { | |||||
// region may not be the one that contains the target, if a conditional formatting rule applies to multiple regions | // region may not be the one that contains the target, if a conditional formatting rule applies to multiple regions | ||||
int deltaRow = target.getRow() - region.getFirstRow(); | int deltaRow = target.getRow() - region.getFirstRow(); |
if (formatStr.contains("#/") || formatStr.contains("?/")) { | if (formatStr.contains("#/") || formatStr.contains("?/")) { | ||||
String[] chunks = formatStr.split(";"); | String[] chunks = formatStr.split(";"); | ||||
for (String chunk1 : chunks) { | for (String chunk1 : chunks) { | ||||
String chunk = chunk1.replaceAll("\\?", "#"); | |||||
String chunk = chunk1.replace("?", "#"); | |||||
Matcher matcher = fractionStripper.matcher(chunk); | Matcher matcher = fractionStripper.matcher(chunk); | ||||
chunk = matcher.replaceAll(" "); | chunk = matcher.replaceAll(" "); | ||||
chunk = chunk.replaceAll(" +", " "); | chunk = chunk.replaceAll(" +", " "); |