git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894331 13f79535-47bb-0310-9956-ffa450edef68tags/REL_5_2_0
@@ -425,11 +425,10 @@ public class ToCSV { | |||
* | |||
* @param file An instance of the File class that encapsulates a handle | |||
* 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 | |||
* underylying file system. | |||
*/ | |||
private void saveCSVFile(File file) throws FileNotFoundException, IOException { | |||
private void saveCSVFile(File file) throws IOException { | |||
ArrayList<String> line; | |||
StringBuilder buffer; | |||
String csvLineElement; | |||
@@ -584,7 +583,7 @@ public class ToCSV { | |||
// set of speech marks. Thus, "Yes" he said would become | |||
// """Yes"" he said" | |||
if(field.contains("\"")) { | |||
buffer = new StringBuilder(field.replaceAll("\"", "\\\"\\\"")); | |||
buffer = new StringBuilder(field.replace("\"", "\\\"\\\"")); | |||
buffer.insert(0, "\""); | |||
buffer.append("\""); | |||
} | |||
@@ -609,7 +608,7 @@ public class ToCSV { | |||
field = field.replaceAll(this.separator, ("\\\\" + this.separator)); | |||
} | |||
if(field.contains("\n")) { | |||
field = field.replaceAll("\n", "\\\\\n"); | |||
field = field.replace("\n", "\\\\\n"); | |||
} | |||
return(field); | |||
} |
@@ -45,7 +45,6 @@ import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; | |||
import org.apache.logging.log4j.LogManager; | |||
import org.apache.logging.log4j.Logger; | |||
import org.apache.logging.log4j.message.SimpleMessage; | |||
@@ -125,9 +124,9 @@ public class TSPTimeStampService implements TimeStampService { | |||
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(InetAddress.getByName(host), (port == -1 ? 80 : port))); | |||
} | |||
UnsynchronizedByteArrayOutputStream bos; | |||
String contentType; | |||
HttpURLConnection huc = (HttpURLConnection)new URL(signatureConfig.getTspUrl()).openConnection(proxy); | |||
byte[] responseBytes; | |||
try { | |||
if (signatureConfig.getTspUser() != null) { | |||
String userPassword = signatureConfig.getTspUser() + ":" + signatureConfig.getTspPass(); | |||
@@ -164,9 +163,8 @@ public class TSPTimeStampService implements TimeStampService { | |||
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 { | |||
huc.disconnect(); | |||
} | |||
@@ -177,15 +175,15 @@ public class TSPTimeStampService implements TimeStampService { | |||
)) { | |||
throw new RuntimeException("invalid Content-Type: " + contentType + | |||
// 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"); | |||
} | |||
// TSP response parsing and validation | |||
TimeStampResponse timeStampResponse = new TimeStampResponse(bos.toByteArray()); | |||
TimeStampResponse timeStampResponse = new TimeStampResponse(responseBytes); | |||
timeStampResponse.validate(request); | |||
if (0 != timeStampResponse.getStatus()) { |
@@ -48,14 +48,13 @@ import java.awt.image.renderable.RenderableImage; | |||
import java.io.PrintStream; | |||
import java.text.AttributedCharacterIterator; | |||
import java.text.AttributedCharacterIterator.Attribute; | |||
import java.text.CharacterIterator; | |||
import java.util.Arrays; | |||
import java.util.HashMap; | |||
import java.util.LinkedHashMap; | |||
import java.util.Locale; | |||
import java.util.Map; | |||
import org.apache.poi.util.Internal; | |||
public class DummyGraphics2d extends Graphics2D { | |||
private BufferedImage bufimg; | |||
private final Graphics2D g2D; | |||
@@ -76,6 +75,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
this.log = log; | |||
} | |||
@Override | |||
public void addRenderingHints(Map<?,?> hints) { | |||
String l = | |||
"addRenderingHinds(Map):" + | |||
@@ -84,6 +84,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.addRenderingHints( hints ); | |||
} | |||
@Override | |||
public void clip(Shape s) { | |||
String l = | |||
"clip(Shape):" + | |||
@@ -93,7 +94,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
} | |||
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]; | |||
for (PathIterator pi = p.getPathIterator(null); !pi.isDone(); pi.next()) { | |||
@@ -101,16 +102,16 @@ public class DummyGraphics2d extends Graphics2D { | |||
// Because the Area is composed of straight lines | |||
switch (pi.currentSegment(coords)) { | |||
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; | |||
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; | |||
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; | |||
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; | |||
case PathIterator.SEG_CLOSE: | |||
sb.append("p.closePath();\n"); | |||
@@ -119,18 +120,20 @@ public class DummyGraphics2d extends Graphics2D { | |||
} | |||
} | |||
@Override | |||
public void draw(Shape s) { | |||
if (s instanceof Path2D) { | |||
StringBuilder sb = new StringBuilder(); | |||
pathToString(sb, (Path2D)s); | |||
sb.append("g.draw(p);"); | |||
log.println( sb.toString() ); | |||
log.println(sb); | |||
} else { | |||
log.println( "g.draw("+ s + ")" ); | |||
} | |||
g2D.draw( s ); | |||
} | |||
@Override | |||
public void drawGlyphVector(GlyphVector g, float x, float y) { | |||
String l = | |||
"drawGlyphVector(GlyphVector, float, float):" + | |||
@@ -141,6 +144,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.drawGlyphVector( g, x, y ); | |||
} | |||
@Override | |||
public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) { | |||
String l = | |||
"drawImage(BufferedImage, BufferedImageOp, x, y):" + | |||
@@ -152,6 +156,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.drawImage( img, op, x, y ); | |||
} | |||
@Override | |||
public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) { | |||
String l = | |||
"drawImage(Image,AfflineTransform,ImageObserver):" + | |||
@@ -162,6 +167,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
return g2D.drawImage( img, xform, obs ); | |||
} | |||
@Override | |||
public void drawRenderableImage(RenderableImage img, AffineTransform xform) { | |||
String l = | |||
"drawRenderableImage(RenderableImage, AfflineTransform):" + | |||
@@ -171,6 +177,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.drawRenderableImage( img, xform ); | |||
} | |||
@Override | |||
public void drawRenderedImage(RenderedImage img, AffineTransform xform) { | |||
String l = | |||
"drawRenderedImage(RenderedImage, AffineTransform):" + | |||
@@ -180,6 +187,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.drawRenderedImage( img, xform ); | |||
} | |||
@Override | |||
public void drawString(String s, float x, float y) { | |||
String l = | |||
"drawString(s,x,y):" + | |||
@@ -190,63 +198,74 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.drawString( s, x, y ); | |||
} | |||
@Override | |||
public void fill(Shape s) { | |||
if (s instanceof Path2D) { | |||
StringBuilder sb = new StringBuilder(); | |||
pathToString(sb, (Path2D)s); | |||
sb.append("g.fill(p);"); | |||
log.println( sb.toString() ); | |||
log.println(sb); | |||
} else { | |||
log.println( "g.fill("+ s + ")" ); | |||
} | |||
g2D.fill( s ); | |||
} | |||
@Override | |||
public Color getBackground() { | |||
log.println( "getBackground():" ); | |||
return g2D.getBackground(); | |||
} | |||
@Override | |||
public Composite getComposite() { | |||
log.println( "getComposite():" ); | |||
return g2D.getComposite(); | |||
} | |||
@Override | |||
public GraphicsConfiguration getDeviceConfiguration() { | |||
log.println( "getDeviceConfiguration():" ); | |||
return g2D.getDeviceConfiguration(); | |||
} | |||
@Override | |||
public FontRenderContext getFontRenderContext() { | |||
log.println( "getFontRenderContext():" ); | |||
return g2D.getFontRenderContext(); | |||
} | |||
@Override | |||
public Paint getPaint() { | |||
log.println( "getPaint():" ); | |||
return g2D.getPaint(); | |||
} | |||
@Override | |||
public Object getRenderingHint(RenderingHints.Key hintKey) { | |||
log.println( "getRenderingHint(\""+hintKey+"\")" ); | |||
return g2D.getRenderingHint( hintKey ); | |||
} | |||
@Override | |||
public RenderingHints getRenderingHints() { | |||
log.println( "getRenderingHints():" ); | |||
return g2D.getRenderingHints(); | |||
} | |||
@Override | |||
public Stroke getStroke() { | |||
log.println( "getStroke():" ); | |||
return g2D.getStroke(); | |||
} | |||
@Override | |||
public AffineTransform getTransform() { | |||
log.println( "getTransform():" ); | |||
return g2D.getTransform(); | |||
} | |||
@Override | |||
public boolean hit(Rectangle rect, Shape s, boolean onStroke) { | |||
String l = | |||
"hit(Rectangle, Shape, onStroke):" + | |||
@@ -257,6 +276,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
return g2D.hit( rect, s, onStroke ); | |||
} | |||
@Override | |||
public void rotate(double theta) { | |||
String l = | |||
"rotate(theta):" + | |||
@@ -265,6 +285,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.rotate( theta ); | |||
} | |||
@Override | |||
public void rotate(double theta, double x, double y) { | |||
String l = | |||
"rotate(double,double,double):" + | |||
@@ -275,13 +296,15 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.rotate( theta, x, y ); | |||
} | |||
@Override | |||
public void scale(double sx, double sy) { | |||
log.println( "g.scale("+sx+","+sy+");" ); | |||
g2D.scale( sx, sy ); | |||
} | |||
@Override | |||
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 ); | |||
} | |||
@@ -289,6 +312,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
"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) { | |||
String l = "g.setComposite("; | |||
if (comp instanceof AlphaComposite) { | |||
@@ -303,6 +327,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.setComposite( comp ); | |||
} | |||
@Override | |||
public void setPaint( Paint paint ) { | |||
String l = "g.setPaint("; | |||
if (paint instanceof Color) { | |||
@@ -314,6 +339,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.setPaint( paint ); | |||
} | |||
@Override | |||
public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue) { | |||
log.println( "g.setRenderingHint("+mapHint(hintKey)+", " + mapHint(hintValue) + ");" ); | |||
g2D.setRenderingHint( hintKey, hintValue ); | |||
@@ -332,10 +358,11 @@ public class DummyGraphics2d extends Graphics2D { | |||
return (String)HINTS[i+1]; | |||
} | |||
} | |||
return "\"" + hint.toString() + "\""; | |||
return "\"" + hint + "\""; | |||
} | |||
@Override | |||
public void setRenderingHints(Map<?,?> hints) { | |||
String l = | |||
"setRenderingHints(Map):" + | |||
@@ -344,6 +371,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.setRenderingHints( hints ); | |||
} | |||
@Override | |||
public void setStroke(Stroke s) { | |||
String l; | |||
if (s instanceof BasicStroke) { | |||
@@ -364,11 +392,13 @@ public class DummyGraphics2d extends Graphics2D { | |||
: "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) { | |||
log.println( "g.setTransform("+mapTransform(Tx)+");" ); | |||
g2D.setTransform( Tx ); | |||
} | |||
@Override | |||
public void shear(double shx, double shy) { | |||
String l = | |||
"shear(shx, dhy):" + | |||
@@ -378,6 +408,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.shear( shx, shy ); | |||
} | |||
@Override | |||
public void transform(AffineTransform Tx) { | |||
String l = | |||
"transform(AffineTransform):" + | |||
@@ -386,6 +417,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.transform( Tx ); | |||
} | |||
@Override | |||
public void translate(double tx, double ty) { | |||
String l = | |||
"translate(double, double):" + | |||
@@ -395,6 +427,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.translate( tx, ty ); | |||
} | |||
@Override | |||
public void clearRect(int x, int y, int width, int height) { | |||
String l = | |||
"clearRect(int,int,int,int):" + | |||
@@ -406,6 +439,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.clearRect( x, y, width, height ); | |||
} | |||
@Override | |||
public void clipRect(int x, int y, int width, int height) { | |||
String l = | |||
"clipRect(int, int, int, int):" + | |||
@@ -417,6 +451,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.clipRect( x, y, width, height ); | |||
} | |||
@Override | |||
public void copyArea(int x, int y, int width, int height, int dx, int dy) { | |||
String l = | |||
"copyArea(int,int,int,int):" + | |||
@@ -428,11 +463,13 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.copyArea( x, y, width, height, dx, dy ); | |||
} | |||
@Override | |||
public Graphics create() { | |||
log.println( "create():" ); | |||
return g2D.create(); | |||
} | |||
@Override | |||
public Graphics create(int x, int y, int width, int height) { | |||
String l = | |||
"create(int,int,int,int):" + | |||
@@ -444,11 +481,13 @@ public class DummyGraphics2d extends Graphics2D { | |||
return g2D.create( x, y, width, height ); | |||
} | |||
@Override | |||
public void dispose() { | |||
log.println( "dispose():" ); | |||
g2D.dispose(); | |||
} | |||
@Override | |||
public void draw3DRect(int x, int y, int width, int height, boolean raised) { | |||
String l = | |||
"draw3DRect(int,int,int,int,boolean):" + | |||
@@ -461,6 +500,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.draw3DRect( x, y, width, height, raised ); | |||
} | |||
@Override | |||
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { | |||
String l = | |||
"drawArc(int,int,int,int,int,int):" + | |||
@@ -474,6 +514,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.drawArc( x, y, width, height, startAngle, arcAngle ); | |||
} | |||
@Override | |||
public void drawBytes(byte[] data, int offset, int length, int x, int y) { | |||
String l = | |||
"drawBytes(byte[],int,int,int,int):" + | |||
@@ -486,6 +527,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.drawBytes( data, offset, length, x, y ); | |||
} | |||
@Override | |||
public void drawChars(char[] data, int offset, int length, int x, int y) { | |||
String l = | |||
"drawChars(data,int,int,int,int):" + | |||
@@ -498,6 +540,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
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) { | |||
String l = | |||
"drawImage(Image,int,int,int,int,int,int,int,int,ImageObserver):" + | |||
@@ -515,6 +558,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
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) { | |||
String l = | |||
"drawImage(Image,int,int,int,int,int,int,int,int,Color,ImageObserver):" + | |||
@@ -533,6 +577,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
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) { | |||
String l = | |||
"drawImage(Image,int,int,Color,ImageObserver):" + | |||
@@ -545,6 +590,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
return g2D.drawImage( img, x, y, bgcolor, observer ); | |||
} | |||
@Override | |||
public boolean drawImage(Image img, int x, int y, ImageObserver observer) { | |||
String l = | |||
"drawImage(Image,int,int,observer):" + | |||
@@ -556,6 +602,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
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) { | |||
String l = | |||
"drawImage(Image,int,int,int,int,Color,ImageObserver):" + | |||
@@ -570,6 +617,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
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) { | |||
String l = | |||
"drawImage(Image,int,int,width,height,observer):" + | |||
@@ -583,6 +631,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
return g2D.drawImage( img, x, y, width, height, observer ); | |||
} | |||
@Override | |||
public void drawLine(int x1, int y1, int x2, int y2) { | |||
String l = | |||
"drawLine(int,int,int,int):" + | |||
@@ -594,6 +643,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.drawLine( x1, y1, x2, y2 ); | |||
} | |||
@Override | |||
public void drawOval(int x, int y, int width, int height) { | |||
String l = | |||
"drawOval(int,int,int,int):" + | |||
@@ -605,6 +655,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.drawOval( x, y, width, height ); | |||
} | |||
@Override | |||
public void drawPolygon(Polygon p) { | |||
String l = | |||
"drawPolygon(Polygon):" + | |||
@@ -613,6 +664,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.drawPolygon( p ); | |||
} | |||
@Override | |||
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) { | |||
String l = | |||
"drawPolygon(int[],int[],int):" + | |||
@@ -623,6 +675,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.drawPolygon( xPoints, yPoints, nPoints ); | |||
} | |||
@Override | |||
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) { | |||
String l = | |||
"drawPolyline(int[],int[],int):" + | |||
@@ -633,6 +686,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.drawPolyline( xPoints, yPoints, nPoints ); | |||
} | |||
@Override | |||
public void drawRect(int x, int y, int width, int height) { | |||
String l = | |||
"drawRect(int,int,int,int):" + | |||
@@ -644,6 +698,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.drawRect( x, y, width, height ); | |||
} | |||
@Override | |||
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { | |||
String l = | |||
"drawRoundRect(int,int,int,int,int,int):" + | |||
@@ -674,15 +729,16 @@ public class DummyGraphics2d extends Graphics2D { | |||
return (String)ATTRS[i+1]; | |||
} | |||
} | |||
return "\""+attr.toString()+"\""; | |||
return "\""+ attr +"\""; | |||
} | |||
@Override | |||
public void drawString(AttributedCharacterIterator iterator, float x, float y) { | |||
final int startIdx = iterator.getIndex(); | |||
final Map<Attribute, Map<Integer,Object>> attMap = new HashMap<>(); | |||
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); | |||
iterator.getAttributes().forEach((k,v) -> | |||
attMap.computeIfAbsent(k, (k2) -> new LinkedHashMap<>()).put(iterator.getIndex(), v) | |||
@@ -695,14 +751,15 @@ public class DummyGraphics2d extends Graphics2D { | |||
for (Map.Entry<Attribute, Map<Integer,Object>> me : attMap.entrySet()) { | |||
int startPos = -2, lastPos = -2; | |||
final Attribute at = me.getKey(); | |||
Object lastObj = null; | |||
for (Map.Entry<Integer,Object> mo : me.getValue().entrySet()) { | |||
int pos = mo.getKey(); | |||
Object obj = mo.getValue(); | |||
if (lastPos < pos-1 || obj != lastObj) { | |||
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; | |||
} | |||
@@ -710,22 +767,24 @@ public class DummyGraphics2d extends Graphics2D { | |||
lastObj = obj; | |||
} | |||
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); | |||
g2D.drawString( iterator, x, y ); | |||
} | |||
@Override | |||
public void drawString(AttributedCharacterIterator iterator, int x, int y) { | |||
drawString(iterator, (float)x, (float)y); | |||
} | |||
@Override | |||
public void drawString(String str, int x, int y) { | |||
String l = | |||
"drawString(str,int,int):" + | |||
@@ -736,6 +795,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.drawString( str, x, y ); | |||
} | |||
@Override | |||
public void fill3DRect(int x, int y, int width, int height, boolean raised) { | |||
String l = | |||
"fill3DRect(int,int,int,int,boolean):" + | |||
@@ -748,6 +808,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.fill3DRect( x, y, width, height, raised ); | |||
} | |||
@Override | |||
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { | |||
String l = | |||
"fillArc(int,int,int,int,int,int):" + | |||
@@ -761,6 +822,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.fillArc( x, y, width, height, startAngle, arcAngle ); | |||
} | |||
@Override | |||
public void fillOval(int x, int y, int width, int height) { | |||
String l = | |||
"fillOval(int,int,int,int):" + | |||
@@ -772,6 +834,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.fillOval( x, y, width, height ); | |||
} | |||
@Override | |||
public void fillPolygon(Polygon p) { | |||
String l = | |||
"fillPolygon(Polygon):" + | |||
@@ -780,6 +843,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.fillPolygon( p ); | |||
} | |||
@Override | |||
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) { | |||
String l = | |||
"fillPolygon(int[],int[],int):" + | |||
@@ -790,26 +854,31 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.fillPolygon( xPoints, yPoints, nPoints ); | |||
} | |||
@Override | |||
public void fillRect(int x, int y, int width, int height) { | |||
log.println( "g.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) { | |||
log.println( "fillRoundRect(" + x + "," + y + "," + width + "," + height + "," + arcWidth + "," + arcHeight + ")" ); | |||
g2D.fillRoundRect( x, y, width, height, arcWidth, arcHeight ); | |||
} | |||
@Override | |||
public Shape getClip() { | |||
log.println( "getClip():" ); | |||
return g2D.getClip(); | |||
} | |||
@Override | |||
public Rectangle getClipBounds() { | |||
log.println( "getClipBounds():" ); | |||
return g2D.getClipBounds(); | |||
} | |||
@Override | |||
public Rectangle getClipBounds(Rectangle r) { | |||
String l = | |||
"getClipBounds(Rectangle):" + | |||
@@ -818,26 +887,31 @@ public class DummyGraphics2d extends Graphics2D { | |||
return g2D.getClipBounds( r ); | |||
} | |||
@Override | |||
public Color getColor() { | |||
log.println( "getColor():" ); | |||
return g2D.getColor(); | |||
} | |||
@Override | |||
public Font getFont() { | |||
log.println( "getFont():" ); | |||
return g2D.getFont(); | |||
} | |||
@Override | |||
public FontMetrics getFontMetrics() { | |||
log.println( "getFontMetrics():" ); | |||
return g2D.getFontMetrics(); | |||
} | |||
@Override | |||
public FontMetrics getFontMetrics(Font f) { | |||
log.println( "getFontMetrics():" ); | |||
return g2D.getFontMetrics( f ); | |||
} | |||
@Override | |||
public boolean hitClip(int x, int y, int width, int height) { | |||
String l = | |||
"hitClip(int,int,int,int):" + | |||
@@ -849,6 +923,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
return g2D.hitClip( x, y, width, height ); | |||
} | |||
@Override | |||
public void setClip(Shape clip) { | |||
String l = | |||
"setClip(Shape):" + | |||
@@ -857,6 +932,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.setClip( clip ); | |||
} | |||
@Override | |||
public void setClip(int x, int y, int width, int height) { | |||
String l = | |||
"setClip(int,int,int,int):" + | |||
@@ -868,11 +944,13 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.setClip( x, y, width, height ); | |||
} | |||
@Override | |||
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 ); | |||
} | |||
@Override | |||
public void setFont(Font font) { | |||
String l = | |||
"setFont(Font):" + | |||
@@ -881,11 +959,13 @@ public class DummyGraphics2d extends Graphics2D { | |||
g2D.setFont( font ); | |||
} | |||
@Override | |||
public void setPaintMode() { | |||
log.println( "setPaintMode():" ); | |||
g2D.setPaintMode(); | |||
} | |||
@Override | |||
public void setXORMode(Color c1) { | |||
String l = | |||
"setXORMode(Color):" + | |||
@@ -899,6 +979,7 @@ public class DummyGraphics2d extends Graphics2D { | |||
return g2D.toString(); | |||
} | |||
@Override | |||
public void translate(int x, int y) { | |||
String l = | |||
"translate(int,int):" + |
@@ -17,6 +17,7 @@ | |||
package org.apache.poi.xssf.usermodel; | |||
import java.io.ByteArrayInputStream; | |||
import java.io.InputStream; | |||
import java.nio.charset.StandardCharsets; | |||
import java.util.EnumMap; | |||
@@ -28,13 +29,11 @@ import javax.xml.transform.TransformerException; | |||
import javax.xml.transform.dom.DOMSource; | |||
import javax.xml.transform.stream.StreamResult; | |||
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream; | |||
import org.apache.commons.io.output.StringBuilderWriter; | |||
import org.apache.poi.ooxml.util.DocumentHelper; | |||
import org.apache.poi.ss.usermodel.DifferentialStyleProvider; | |||
import org.apache.poi.ss.usermodel.TableStyle; | |||
import org.apache.poi.ss.usermodel.TableStyleType; | |||
import org.apache.poi.util.IOUtils; | |||
import org.apache.poi.util.XMLHelper; | |||
import org.apache.poi.xssf.model.StylesTable; | |||
import org.w3c.dom.Document; | |||
@@ -391,30 +390,25 @@ public enum XSSFBuiltinTableStyle { | |||
* </tableStyles> | |||
* </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) { | |||
throw new RuntimeException(e); |
@@ -60,6 +60,21 @@ import org.apache.poi.sl.usermodel.SlideShowFactory; | |||
public class OLE2ScratchpadExtractorFactory implements ExtractorProvider { | |||
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 | |||
public boolean accepts(FileMagic fm) { | |||
return FileMagic.OLE2 == fm; | |||
@@ -87,6 +102,8 @@ public class OLE2ScratchpadExtractorFactory implements ExtractorProvider { | |||
* | |||
* @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 { | |||
final String oldPW = Biff8EncryptionKey.getCurrentUserPassword(); | |||
try { | |||
@@ -112,20 +129,7 @@ public class OLE2ScratchpadExtractorFactory implements ExtractorProvider { | |||
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)) { | |||
return new OutlookTextExtractor(poifsDir); | |||
} |
@@ -47,6 +47,7 @@ public class HSLFSlideShowFactory implements SlideShowProvider<HSLFShape,HSLFTex | |||
* | |||
* @return The created SlideShow | |||
*/ | |||
@Override | |||
public HSLFSlideShow create() { | |||
return new HSLFSlideShow(); | |||
} | |||
@@ -65,6 +66,8 @@ public class HSLFSlideShowFactory implements SlideShowProvider<HSLFShape,HSLFTex | |||
* Note that in order to properly release resources the | |||
* SlideShow should be closed after use. | |||
*/ | |||
@Override | |||
@SuppressWarnings("java:S2093") | |||
public HSLFSlideShow create(final DirectoryNode root, String password) throws IOException { | |||
boolean passwordSet = false; | |||
if (password != null) { | |||
@@ -91,6 +94,7 @@ public class HSLFSlideShowFactory implements SlideShowProvider<HSLFShape,HSLFTex | |||
return create(fs.getRoot(), password); | |||
} | |||
@SuppressWarnings("java:S2093") | |||
@Override | |||
public HSLFSlideShow create(File file, String password, boolean readOnly) throws IOException { | |||
boolean passwordSet = false; |
@@ -38,10 +38,6 @@ import org.apache.poi.hwpf.model.CHPX; | |||
import org.apache.poi.hwpf.model.FieldsDocumentPart; | |||
import org.apache.poi.hwpf.model.FileInformationBlock; | |||
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.PAPX; | |||
import org.apache.poi.hwpf.model.PlexOfCps; | |||
@@ -55,7 +51,6 @@ import org.apache.poi.hwpf.usermodel.Bookmarks; | |||
import org.apache.poi.hwpf.usermodel.Field; | |||
import org.apache.poi.hwpf.usermodel.OfficeDrawing; | |||
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.Range; | |||
import org.apache.poi.poifs.common.POIFSConstants; | |||
@@ -291,7 +286,7 @@ public final class HWPFLister { | |||
char c = text.charAt( charIndex ); | |||
part.append( c ); | |||
if ( c == 13 || c == 7 || c == 12 ) { | |||
paragraphs.put( Integer.valueOf( charIndex ), part.toString() ); | |||
paragraphs.put(charIndex, part.toString() ); | |||
part.setLength( 0 ); | |||
} | |||
} | |||
@@ -398,7 +393,7 @@ public final class HWPFLister { | |||
.hasNext(); ) { | |||
Entry entry = iterator.next(); | |||
String entryToString = "\n" + dumpFileSystem( entry ); | |||
entryToString = entryToString.replaceAll( "\n", "\n+---" ); | |||
entryToString = entryToString.replace("\n", "\n+---"); | |||
result.append( entryToString ); | |||
} | |||
result.append( "\n" ); | |||
@@ -530,7 +525,7 @@ public final class HWPFLister { | |||
} | |||
} | |||
protected void dumpSprms( SprmIterator sprmIt, String linePrefix ) { | |||
private void dumpSprms(SprmIterator sprmIt, String linePrefix) { | |||
while ( sprmIt.hasNext() ) { | |||
SprmOperation sprm = sprmIt.next(); | |||
System.out.println( linePrefix + sprm); | |||
@@ -588,37 +583,6 @@ public final class HWPFLister { | |||
} | |||
} | |||
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 ) { | |||
for ( TextPiece textPiece : _doc.getTextTable().getTextPieces() ) { | |||
System.out.println( textPiece ); |
@@ -35,7 +35,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
* with HWPF. | |||
*/ | |||
public final class Word6Extractor implements POIOLE2TextExtractor { | |||
private HWPFOldDocument doc; | |||
private final HWPFOldDocument doc; | |||
private boolean doCloseFilesystem = true; | |||
/** | |||
@@ -97,14 +97,15 @@ public final class Word6Extractor implements POIOLE2TextExtractor { | |||
ret[i] = doc.getTextTable().getTextPieces().get(i).getStringBuilder().toString(); | |||
// 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; | |||
} | |||
@Override | |||
public String getText() { | |||
try { | |||
WordToTextConverter wordToTextConverter = new WordToTextConverter(); |
@@ -210,8 +210,8 @@ public final class WordExtractor implements POIOLE2TextExtractor { | |||
String text = doc.getDocumentText(); | |||
// 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" )) { | |||
text += "\n"; | |||
@@ -224,6 +224,7 @@ public final class WordExtractor implements POIOLE2TextExtractor { | |||
* Grab the text, based on the WordToTextConverter. Shouldn't include any | |||
* crud, but slower than getTextFromPieces(). | |||
*/ | |||
@Override | |||
public String getText() { | |||
try { | |||
WordToTextConverter wordToTextConverter = new WordToTextConverter(); |
@@ -27,6 +27,7 @@ import java.util.Locale; | |||
import org.apache.logging.log4j.LogManager; | |||
import org.apache.logging.log4j.Logger; | |||
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.util.IOUtils; | |||
import org.apache.poi.util.Internal; | |||
@@ -61,7 +62,7 @@ public final class FileInformationBlock { | |||
private final FibRgLw _fibRgLw; | |||
private int _cbRgFcLcb; | |||
private FIBFieldHandler _fieldHandler; | |||
private int _cswNew; | |||
private final int _cswNew; | |||
private final int _nFibNew; | |||
private final byte[] _fibRgCswNew; | |||
@@ -87,7 +88,7 @@ public final class FileInformationBlock { | |||
if ( _fibBase.getNFib() < 105 ) | |||
{ | |||
_fibRgLw = new FibRgLw95( mainDocument, offset ); | |||
offset += FibRgLw97.getSize(); | |||
offset += FibRgLw97AbstractType.getSize(); | |||
// magic number, run tests after changes | |||
_cbRgFcLcb = 74; | |||
@@ -95,9 +96,7 @@ public final class FileInformationBlock { | |||
// skip fibRgFcLcbBlob (read later at fillVariableFields) | |||
offset += _cbRgFcLcb * LittleEndianConsts.INT_SIZE * 2; | |||
_cswNew = LittleEndian.getUShort( mainDocument, offset ); | |||
offset += LittleEndianConsts.SHORT_SIZE; | |||
// _cswNew = LittleEndian.getUShort( mainDocument, offset ); | |||
_cswNew = 0; | |||
_nFibNew = -1; | |||
_fibRgCswNew = new byte[0]; | |||
@@ -106,7 +105,7 @@ public final class FileInformationBlock { | |||
} | |||
_fibRgLw = new FibRgLw97( mainDocument, offset ); | |||
offset += FibRgLw97.getSize(); | |||
offset += FibRgLw97AbstractType.getSize(); | |||
assert offset == 152; | |||
_cbRgFcLcb = LittleEndian.getUShort( mainDocument, offset ); | |||
@@ -1078,7 +1077,7 @@ public final class FileInformationBlock { | |||
offset += LittleEndianConsts.SHORT_SIZE; | |||
( (FibRgLw97) _fibRgLw ).serialize( mainStream, offset ); | |||
offset += FibRgLw97.getSize(); | |||
offset += FibRgLw97AbstractType.getSize(); | |||
LittleEndian.putUShort( mainStream, offset, _cbRgFcLcb ); | |||
offset += LittleEndianConsts.SHORT_SIZE; | |||
@@ -1093,16 +1092,14 @@ public final class FileInformationBlock { | |||
LittleEndian.putUShort( mainStream, offset, _nFibNew ); | |||
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() | |||
{ | |||
return FibBaseAbstractType.getSize() + LittleEndianConsts.SHORT_SIZE + FibRgW97AbstractType.getSize() | |||
+ LittleEndianConsts.SHORT_SIZE + FibRgLw97.getSize() | |||
+ LittleEndianConsts.SHORT_SIZE + FibRgLw97AbstractType.getSize() | |||
+ LittleEndianConsts.SHORT_SIZE + _fieldHandler.sizeInBytes(); | |||
} | |||
@@ -299,7 +299,6 @@ public final class ListLevel | |||
offset += _grpprlChpx.length; | |||
_xst.serialize( buf, offset ); | |||
offset += _xst.getSize(); | |||
return buf; | |||
} | |||
@@ -307,7 +306,7 @@ public final class ListLevel | |||
@Override | |||
public String toString() | |||
{ | |||
return "LVL: " + ( "\n" + _lvlf ).replaceAll( "\n", "\n " ) | |||
return "LVL: " + ( "\n" + _lvlf ).replace( "\n", "\n " ) | |||
+ "\n" | |||
+ ( "PAPX's grpprl: " + Arrays.toString( _grpprlPapx ) + "\n" ) | |||
+ ( "CHPX's grpprl: " + Arrays.toString( _grpprlChpx ) + "\n" ) |
@@ -37,8 +37,6 @@ import static org.apache.logging.log4j.util.Unbox.box; | |||
public final class StyleDescription { | |||
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 CHARACTER_STYLE = 2; | |||
@@ -84,13 +82,14 @@ public final class StyleDescription { | |||
//first byte(s) of variable length section of std is the length of the | |||
//style name and aliases string | |||
int nameLength = 0; | |||
int multiplier = 1; | |||
int nameLength; | |||
int multiplier; | |||
if (word9) { | |||
nameLength = LittleEndian.getShort(std, nameStart); | |||
multiplier = 2; | |||
nameStart += LittleEndianConsts.SHORT_SIZE; | |||
} else { | |||
multiplier = 1; | |||
nameLength = std[nameStart]; | |||
} | |||
@@ -237,12 +236,10 @@ public final class StyleDescription { | |||
result.append("[STD]: '"); | |||
result.append(_name); | |||
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) { | |||
result.append(("\nUPX:\t" + upx).replaceAll("\n", "\n ")); | |||
result.append(("\nUPX:\t" + upx).replace("\n", "\n ")); | |||
} | |||
return result.toString(); | |||
} |
@@ -117,28 +117,23 @@ public abstract class LFOAbstractType | |||
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]"; | |||
} | |||
/** |
@@ -52,6 +52,7 @@ public class MainExtractorFactory implements ExtractorProvider { | |||
return create(new POIFSFileSystem(inputStream).getRoot(), password); | |||
} | |||
@SuppressWarnings("java:S2093") | |||
@Override | |||
public POITextExtractor create(DirectoryNode poifsDir, String password) throws IOException { | |||
final String oldPW = Biff8EncryptionKey.getCurrentUserPassword(); |
@@ -78,6 +78,7 @@ public class OldExcelExtractor implements POITextExtractor { | |||
open(input); | |||
} | |||
@SuppressWarnings("java:S2093") | |||
public OldExcelExtractor(File f) throws IOException { | |||
POIFSFileSystem poifs = null; | |||
try { | |||
@@ -120,6 +121,7 @@ public class OldExcelExtractor implements POITextExtractor { | |||
open(directory); | |||
} | |||
@SuppressWarnings("java:S2093") | |||
private void open(InputStream biffStream) throws IOException { | |||
BufferedInputStream bis = (biffStream instanceof BufferedInputStream) | |||
? (BufferedInputStream)biffStream | |||
@@ -230,6 +232,7 @@ public class OldExcelExtractor implements POITextExtractor { | |||
* | |||
* @return the text contents of the file | |||
*/ | |||
@Override | |||
public String getText() { | |||
StringBuilder text = new StringBuilder(); | |||
@@ -33,11 +33,11 @@ import org.apache.poi.util.StringUtil; | |||
* DConRef records specify a range in a workbook (internal or external) that serves as a data source | |||
* 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. | |||
* 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"> | |||
* [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"> | |||
* [MS-XLS s. 2.5.296]</a>. | |||
* | |||
@@ -56,16 +56,16 @@ import org.apache.poi.util.StringUtil; | |||
* </pre> | |||
* Where | |||
* <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 | |||
* <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> | |||
* <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> | |||
* | |||
* At the moment this class is read-only. | |||
@@ -85,26 +85,28 @@ public class DConRefRecord extends StandardRecord { | |||
* <a href="http://msdn.microsoft.com/en-us/library/dd920420(office.12).aspx"> | |||
* [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 | |||
*/ | |||
private int charCount; | |||
private final int charCount; | |||
/** | |||
* 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> | |||
* @see <A href="http://msdn.microsoft.com/en-us/library/dd923491(office.12).aspx"> | |||
* DConFile [MS-XLS s. 2.5.77]</A> and | |||
* <A href="http://msdn.microsoft.com/en-us/library/dd950157(office.12).aspx"> | |||
* 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. | |||
*/ | |||
@@ -256,7 +258,7 @@ public class DConRefRecord extends StandardRecord { | |||
} | |||
String out = new String(Arrays.copyOfRange(path, offset, path.length), StringUtil.UTF8); | |||
//UNC paths have \u0003 chars as path separators. | |||
out = out.replaceAll("\u0003", "/"); | |||
out = out.replace("\u0003", "/"); | |||
return out; | |||
} | |||
return null; |
@@ -67,6 +67,7 @@ public class HSSFWorkbookFactory implements WorkbookProvider { | |||
* Note that in order to properly release resources the | |||
* Workbook should be closed after use. | |||
*/ | |||
@SuppressWarnings("java:S2093") | |||
@Override | |||
public HSSFWorkbook create(final DirectoryNode root, String password) throws IOException { | |||
boolean passwordSet = false; | |||
@@ -95,7 +96,7 @@ public class HSSFWorkbookFactory implements WorkbookProvider { | |||
} | |||
@Override | |||
@SuppressWarnings("java:S2095") | |||
@SuppressWarnings({"java:S2095","java:S2093"}) | |||
public Workbook create(File file, String password, boolean readOnly) throws IOException { | |||
boolean passwordSet = false; | |||
if (password != null) { |
@@ -45,14 +45,14 @@ public interface GuideIf extends Formula { | |||
} | |||
default double evaluateGuide(Context ctx) { | |||
Guide.Op op; | |||
Op op; | |||
String[] operands = WHITESPACE.split(getFmla()); | |||
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; |
@@ -235,8 +235,7 @@ public final class WorkbookEvaluator { | |||
int rowIndex, int columnIndex, EvaluationTracker tracker) { | |||
// 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) { | |||
ValueEval result = getValueFromNonFormulaCell(srcCell); | |||
if (shouldCellDependencyBeRecorded) { | |||
@@ -389,7 +388,7 @@ public final class WorkbookEvaluator { | |||
String message = finalDbgIndentStr | |||
+ "- evaluateFormula('" + ec.getRefEvaluatorForCurrentSheet().getSheetNameRange() | |||
+ "'/" + 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); | |||
}); | |||
dbgEvaluationOutputIndent++; | |||
@@ -665,7 +664,7 @@ public final class WorkbookEvaluator { | |||
/** | |||
* returns an appropriate Eval impl instance for the Ptg. The Ptg must be | |||
* one of: Area3DPtg, AreaPtg, ReferencePtg, Ref3DPtg, IntPtg, NumberPtg, | |||
* StringPtg, BoolPtg<p> | |||
* StringPtg, BoolPtg | |||
* <p> | |||
* special Note: OperationPtg subtypes cannot be passed here! | |||
*/ | |||
@@ -889,7 +888,7 @@ public final class WorkbookEvaluator { | |||
* @throws IndexOutOfBoundsException if the resulting shifted row/column indexes are over the document format limits | |||
* @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 | |||
int deltaRow = target.getRow() - region.getFirstRow(); |
@@ -433,7 +433,7 @@ public class DataFormatter { | |||
if (formatStr.contains("#/") || formatStr.contains("?/")) { | |||
String[] chunks = formatStr.split(";"); | |||
for (String chunk1 : chunks) { | |||
String chunk = chunk1.replaceAll("\\?", "#"); | |||
String chunk = chunk1.replace("?", "#"); | |||
Matcher matcher = fractionStripper.matcher(chunk); | |||
chunk = matcher.replaceAll(" "); | |||
chunk = chunk.replaceAll(" +", " "); |