diff --git a/build.sh b/build.sh index 05e87db..d0938ee 100755 --- a/build.sh +++ b/build.sh @@ -10,24 +10,16 @@ while test ! -z "$1" ; do case "$1" in -major*) (cd $bDIR && mvn build-helper:parse-version versions:set \ - -DnewVersion="\${parsedVersion.nextMajorVersion}.1.0" ) || exit 1 + -DnewVersion="\${parsedVersion.nextMajorVersion}.1.\${parsedVersion.nextIncrementalVersion}" ) || exit 1 ;; -minor*) (cd $bDIR && mvn build-helper:parse-version versions:set \ - -DnewVersion="\${parsedVersion.majorVersion}.\${parsedVersion.nextMinorVersion}.0" ) || exit 1 + -DnewVersion="\${parsedVersion.majorVersion}.\${parsedVersion.nextMinorVersion}.\${parsedVersion.nextIncrementalVersion}" ) || exit 1 ;; -release*) (cd $bDIR && mvn -X build-helper:parse-version versions:set \ -DnewVersion="\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion}" ) || exit 1 ;; - -build*) - (cd $bDIR && mvn -X buildnumber:create build-helper:parse-version versions:set \ - -DnewVersion="\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.incrementalVersion}-\${buildNumber}" ) || exit 1 - ;; - -snapshot*) - (cd $bDIR && mvn -X buildnumber:create build-helper:parse-version versions:set \ - -DnewVersion="\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.incrementalVersion}-rc$bDATE" ) || exit 1 - ;; -clean*) (cd $bDIR && mvn clean $OPTS -U) || exit 1 ;; @@ -38,7 +30,8 @@ while test ! -z "$1" ; do (cd $bDIR && mvn -N versions:update-child-modules) || exit 1 ;; -install*) - (cd $bDIR && mvn install $OPTS) || exit 1 + (cd $bDIR && mvn clean install $OPTS) || exit 1 + (test -e ~/bin/template-cli.sh && cd $bDIR && cp template-cli/target/bin/template-cli.*.sh.bin ~/bin/template-cli.sh) ;; *) echo "unknow option ..." ;; diff --git a/buildNumber.properties b/buildNumber.properties index a7f1d1d..4995140 100644 --- a/buildNumber.properties +++ b/buildNumber.properties @@ -1,3 +1,3 @@ #maven.buildNumber.plugin properties file -#Mon Mar 22 12:18:11 CET 2021 -buildNumber=328 +#Wed Mar 31 19:51:21 CEST 2021 +buildNumber=340 diff --git a/examples/check.fm b/examples/check.fm new file mode 100644 index 0000000..3e65d06 --- /dev/null +++ b/examples/check.fm @@ -0,0 +1,6 @@ +<#if _.checkBoolean('on')> +ON + +<#if _.checkBoolean('off')> +OFF + \ No newline at end of file diff --git a/examples/gfx.groovy b/examples/gfx.groovy index 044f26f..29577b6 100644 --- a/examples/gfx.groovy +++ b/examples/gfx.groovy @@ -1,6 +1,6 @@ -import com.github.terefang.imageutil.PixelImage; -import com.github.terefang.imageutil.SvgImage; -import com.github.terefang.imageutil.ImageUtil; +import com.github.terefang.jmelange.image.PixelImage; +import com.github.terefang.jmelange.image.SvgImage; +import com.github.terefang.jmelange.util.ImageUtil; SvgImage _im = SvgImage.create(200, 200); diff --git a/pom.xml b/pom.xml index 9812fab..37fd70d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.terefang.template template - 2021.4.25 + 2021.4.26 template-cli template-maven-plugin @@ -29,6 +29,7 @@ 3.6.3 ${maven.build.timestamp} yyyyMMdd'.'HHmm + 2021.1.1 diff --git a/template-cli/buildNumber.properties b/template-cli/buildNumber.properties index 5db0201..357396f 100644 --- a/template-cli/buildNumber.properties +++ b/template-cli/buildNumber.properties @@ -1,3 +1,3 @@ #maven.buildNumber.plugin properties file -#Mon Mar 22 12:18:22 CET 2021 -buildNumber=323 +#Wed Mar 31 19:51:31 CEST 2021 +buildNumber=331 diff --git a/template-cli/pom.xml b/template-cli/pom.xml index 41dc09d..a487257 100644 --- a/template-cli/pom.xml +++ b/template-cli/pom.xml @@ -5,7 +5,7 @@ template com.github.terefang.template - 2021.4.25 + 2021.4.26 4.0.0 diff --git a/template-cli/src/test/java/TestFM.java b/template-cli/src/test/java/TestFM.java new file mode 100644 index 0000000..07bf7b6 --- /dev/null +++ b/template-cli/src/test/java/TestFM.java @@ -0,0 +1,12 @@ +import com.github.terefang.template_cli.TemplateCliMain; + +public class TestFM { + static String[] ARGS = { + "-T", "FREEMARKER", "-M", "STD", + "-D", "examples/check.fm.out", + "-S", "examples/check.fm", + "--additional-variables", "_out_dir=examples" }; + public static void main(String[] args) { + TemplateCliMain.main(ARGS); + } +} diff --git a/template-cli/template-cli.iml b/template-cli/template-cli.iml index c9cbf28..a738997 100644 --- a/template-cli/template-cli.iml +++ b/template-cli/template-cli.iml @@ -12,12 +12,20 @@ + + + + + + + + + - @@ -63,10 +71,6 @@ - - - - diff --git a/template-maven-plugin/buildNumber.properties b/template-maven-plugin/buildNumber.properties index a7f1d1d..1b3ddc7 100644 --- a/template-maven-plugin/buildNumber.properties +++ b/template-maven-plugin/buildNumber.properties @@ -1,3 +1,3 @@ #maven.buildNumber.plugin properties file -#Mon Mar 22 12:18:11 CET 2021 -buildNumber=328 +#Wed Mar 31 19:51:22 CEST 2021 +buildNumber=340 diff --git a/template-maven-plugin/pom.xml b/template-maven-plugin/pom.xml index df60a47..f3dd4b0 100644 --- a/template-maven-plugin/pom.xml +++ b/template-maven-plugin/pom.xml @@ -5,7 +5,7 @@ template com.github.terefang.template - 2021.4.25 + 2021.4.26 4.0.0 @@ -14,6 +14,11 @@ maven-plugin + + com.github.terefang.jmelange + utils-jmelange + ${version.jmelange} + org.soulwing.snmp @@ -166,16 +171,6 @@ plexus-utils 3.3.0 - - org.jfree - jfreesvg - 3.4 - - - de.rototor.pdfbox - graphics2d - 0.31 - diff --git a/template-maven-plugin/src/main/java/com/github/terefang/concat_maven_plugin/ConcatMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/concat_maven_plugin/ConcatMojo.java index a38d1db..ce26e5d 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/concat_maven_plugin/ConcatMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/concat_maven_plugin/ConcatMojo.java @@ -13,7 +13,6 @@ import org.codehaus.plexus.util.StringUtils; import java.io.*; -import java.util.ArrayDeque; import java.util.Arrays; @Mojo(name = "concat", defaultPhase = LifecyclePhase.GENERATE_RESOURCES) diff --git a/template-maven-plugin/src/main/java/com/github/terefang/convert_maven_plugin/ToPdataMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/convert_maven_plugin/ToPdataMojo.java index aa9de93..70c5289 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/convert_maven_plugin/ToPdataMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/convert_maven_plugin/ToPdataMojo.java @@ -1,7 +1,7 @@ package com.github.terefang.convert_maven_plugin; +import com.github.terefang.jmelange.pdata.PdataWriter; import com.github.terefang.template_maven_plugin.util.ContextUtil; -import com.github.terefang.template_maven_plugin.util.PdxWriter; import lombok.Data; import lombok.SneakyThrows; import org.apache.maven.plugin.AbstractMojo; @@ -11,7 +11,6 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.codehaus.plexus.util.DirectoryScanner; -import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; import java.io.*; @@ -109,11 +108,11 @@ public static void convertToPdata(File _from, File _to) Map _data = ContextUtil.loadContextFrom(_from); if(_to == null) { - PdxWriter.writeTo(_data, new OutputStreamWriter(System.out)); + PdataWriter.writeTo(_data, new OutputStreamWriter(System.out)); } else { - PdxWriter.writeTo(_data, _to); + PdataWriter.writeTo(_data, _to); } } } diff --git a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/AbstractGfxInterface.java b/template-maven-plugin/src/main/java/com/github/terefang/imageutil/AbstractGfxInterface.java deleted file mode 100644 index 2448c50..0000000 --- a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/AbstractGfxInterface.java +++ /dev/null @@ -1,265 +0,0 @@ -package com.github.terefang.imageutil; - -import org.jfree.graphics2d.svg.SVGGraphics2D; -import org.jfree.graphics2d.svg.SVGHints; - -import java.awt.*; -import java.awt.font.FontRenderContext; -import java.awt.font.GlyphVector; -import java.awt.geom.AffineTransform; -import java.awt.image.BufferedImage; -import java.awt.image.BufferedImageOp; -import java.awt.image.ImageObserver; -import java.awt.image.RenderedImage; -import java.awt.image.renderable.RenderableImage; -import java.text.AttributedCharacterIterator; -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.Map; -import java.util.UUID; - -public abstract class AbstractGfxInterface implements GfxInterface, StackedGfxInterface -{ - Deque _queue = new ArrayDeque<>(); - Graphics2D _current; - - @Override - public StackedGfxInterface getStackedGfxInterface() - { - this.beginDraw(); - return this; - } - - @Override - public Graphics2D getCurrentGraphics2D() - { - if(_current!=null) return _current; - if(!_queue.isEmpty()) - { - return (_current = _queue.poll()); - } - return (_current = getG2d()); - } - - public void dispose() - { - this.endDraw(); - } - - public void beginDraw() - { - beginDraw(UUID.randomUUID().toString()); - } - - @Override - public void beginDraw(String _id) { - if(_current!=null) - { - _queue.push(_current); - _current = (Graphics2D) _current.create(); - } - else - { - getCurrentGraphics2D(); - } - - if(_current instanceof SVGGraphics2D) - { - ((SVGGraphics2D)_current).setRenderingHint(SVGHints.KEY_BEGIN_GROUP, _id); - } - } - - @Override - public void endDraw() { - if(_current!=null) - { - _current.dispose(); - } - _current = _queue.poll(); - - if(_current instanceof SVGGraphics2D) - { - ((SVGGraphics2D)_current).setRenderingHint(SVGHints.KEY_END_GROUP, "true"); - } - } - - @Override - public void beginText() { - if(_current!=null) - { - _queue.push(_current); - _current = (Graphics2D) _current.create(); - } - else - { - getCurrentGraphics2D(); - } - } - - @Override - public void endText() { - if(_current!=null) - { - _current.dispose(); - } - _current = _queue.poll(); - } - - - public void draw3DRect(int x, int y, int width, int height, boolean raised) { - _current.draw3DRect(x, y, width, height, raised); - } - - public void fill3DRect(int x, int y, int width, int height, boolean raised) { - _current.fill3DRect(x, y, width, height, raised); - } - - public void drawString(String str, int x, int y) { - _current.drawString(str, x, y); - } - - public void drawString(String str, float x, float y) { - _current.drawString(str, x, y); - } - - public void setComposite(Composite comp) { - _current.setComposite(comp); - } - - public void setPaint(Paint paint) { - _current.setPaint(paint); - } - - public void setStroke(Stroke s) { - _current.setStroke(s); - } - - public void translate(int x, int y) { - _current.translate(x, y); - } - - public void translate(double tx, double ty) { - _current.translate(tx, ty); - } - - public void rotate(double theta) { - _current.rotate(theta); - } - - public void rotate(double theta, double x, double y) { - _current.rotate(theta, x, y); - } - - public void scale(double sx, double sy) { - _current.scale(sx, sy); - } - - public void shear(double shx, double shy) { - _current.shear(shx, shy); - } - - public void setBackground(int _color) { - _current.setBackground(ImageUtil.createColor(_color)); - } - - public void clip(Shape s) { - _current.clip(s); - } - - public void setColor(long _color) { - _current.setColor(ImageUtil.createColor(_color)); - } - - public void setPaintMode() { - _current.setPaintMode(); - } - - public void setFont(Font font) { - _current.setFont(font); - } - - public void clipRect(int x, int y, int width, int height) { - _current.clipRect(x, y, width, height); - } - - public void setClip(int x, int y, int width, int height) { - _current.setClip(x, y, width, height); - } - - public void drawLine(int x1, int y1, int x2, int y2) { - _current.drawLine(x1, y1, x2, y2); - } - - public void fillRect(int x, int y, int width, int height) { - _current.fillRect(x, y, width, height); - } - - public void drawRect(int x, int y, int width, int height) { - _current.drawRect(x, y, width, height); - } - - public void clearRect(int x, int y, int width, int height) { - _current.clearRect(x, y, width, height); - } - - public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { - _current.drawRoundRect(x, y, width, height, arcWidth, arcHeight); - } - - public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { - _current.fillRoundRect(x, y, width, height, arcWidth, arcHeight); - } - - public void drawOval(int x, int y, int width, int height) { - _current.drawOval(x, y, width, height); - } - - public void fillOval(int x, int y, int width, int height) { - _current.fillOval(x, y, width, height); - } - - public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { - _current.drawArc(x, y, width, height, startAngle, arcAngle); - } - - public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { - _current.fillArc(x, y, width, height, startAngle, arcAngle); - } - - public void drawPolyline(int[] points) { - int _np = points.length/2; - int[] _x = new int[_np]; - int[] _y = new int[_np]; - for(int _i = 0; _i<_np; _i++) - { - _x[_i] = points[_i*2]; - _y[_i] = points[(_i*2)+1]; - } - _current.drawPolyline(_x, _y, _np); - } - - public void drawPolygon(int[] points) { - int _np = points.length/2; - int[] _x = new int[_np]; - int[] _y = new int[_np]; - for(int _i = 0; _i<_np; _i++) - { - _x[_i] = points[_i*2]; - _y[_i] = points[(_i*2)+1]; - } - _current.drawPolygon(_x, _y, _np); - } - - public void fillPolygon(int[] points) { - int _np = points.length/2; - int[] _x = new int[_np]; - int[] _y = new int[_np]; - for(int _i = 0; _i<_np; _i++) - { - _x[_i] = points[_i*2]; - _y[_i] = points[(_i*2)+1]; - } - _current.fillPolygon(_x, _y, _np); - } - -} diff --git a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/G2dProxy.java b/template-maven-plugin/src/main/java/com/github/terefang/imageutil/G2dProxy.java deleted file mode 100644 index 1dc3562..0000000 --- a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/G2dProxy.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.github.terefang.imageutil; - -import org.jfree.graphics2d.svg.SVGGraphics2D; -import org.jfree.graphics2d.svg.SVGHints; - -import java.awt.*; -import java.io.File; -import java.io.OutputStream; -import java.util.UUID; - -public class G2dProxy implements GfxSubInterface -{ - Graphics2D _g2d; - GfxInterface _g; - public static final GfxSubInterface create(GfxInterface _g, String _id) - { - G2dProxy _p = new G2dProxy(); - _p._g2d = _g.getG2d(); - _p._g=_g; - - if(_p._g2d instanceof SVGGraphics2D) - { - ((SVGGraphics2D)_p._g2d).setRenderingHint(SVGHints.KEY_BEGIN_GROUP, _id); - } - return _p; - } - - public static final GfxSubInterface create(GfxInterface _g) - { - return create(_g,UUID.randomUUID().toString()); - } - - @Override - public Graphics2D getG2d() { - return (Graphics2D) _g2d.create(); - } - - @Override - public String beginGroup() { - return this._g.beginGroup(); - } - - @Override - public String beginGroup(String _id) { - return this._g.beginGroup(_id); - } - - @Override - public void endGroup() { - this._g.endGroup(); - } - - @Override - public void gSet(int _x, int _y, long _color) { - _g.gSet(_x, _y, _color); - } - - @Override - public int gGet(int _x, int _y) { - return _g.gGet(_x, _y); - } - - @Override - public void save(File _out) { - - } - - @Override - public void save(OutputStream _out) { - - } - - @Override - public StackedGfxInterface getStackedGfxInterface() { - return _g.getStackedGfxInterface(); - } - - @Override - public void dispose() - { - if(this._g2d instanceof SVGGraphics2D) - { - ((SVGGraphics2D)this._g2d).setRenderingHint(SVGHints.KEY_END_GROUP, "true"); - } - this._g2d.dispose(); - this._g2d=null; - } -} diff --git a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/GfxInterface.java b/template-maven-plugin/src/main/java/com/github/terefang/imageutil/GfxInterface.java deleted file mode 100644 index 021e914..0000000 --- a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/GfxInterface.java +++ /dev/null @@ -1,401 +0,0 @@ -package com.github.terefang.imageutil; - -import java.awt.*; -import java.io.File; -import java.io.OutputStream; - -public interface GfxInterface -{ - public Graphics2D getG2d(); - default GfxInterface getSub() - { - return G2dProxy.create(this); - } - - public String beginGroup(); - - public String beginGroup(String _id); - - public void endGroup(); - - default GfxInterface getSub(String _id) - { - return G2dProxy.create(this, _id); - } - - default Font getFont(String _name, int _size) - { - return ImageUtil.getFont(_name, _size); - } - - default Font getPSFont(String _name, int _size) - { - Font _font = ImageUtil.getPSFont(new File(_name), _size); - if(this instanceof PdfImage) - { - ((PdfImage)this).registerFont(_font, new File(_name)); - } - return _font; - } - - default Font getTTFont(String _name, int _size) - { - Font _font = ImageUtil.getTTFont(new File(_name), _size); - if(this instanceof PdfImage) - { - ((PdfImage)this).registerFont(_font, new File(_name)); - } - return _font; - } - - default Font getFont(String _name, float _size) - { - return ImageUtil.getFont(_name, _size); - } - - default Font getPSFont(String _name, float _size) - { - Font _font = ImageUtil.getPSFont(new File(_name), _size); - if(this instanceof PdfImage) - { - ((PdfImage)this).registerFont(_font, new File(_name)); - } - return _font; - } - - default Font getTTFont(String _name, float _size) - { - Font _font = ImageUtil.getTTFont(new File(_name), _size); - if(this instanceof PdfImage) - { - ((PdfImage)this).registerFont(_font, new File(_name)); - } - return _font; - } - - public void gSet(int _x, int _y, long _color); - public int gGet(int _x, int _y); - - default void gLine(int _x1, int _y1, int _x2, int _y2, long _color) - { - gLine(_x1, _y1, _x2, _y2, 1, _color); - } - - default void gLine(int _x1, int _y1, int _x2, int _y2, float _lineWidth, long _color) - { - Graphics2D _g = (Graphics2D) this.getG2d(); - _g.setPaint(ImageUtil.createColor(_color)); - Stroke _s = new BasicStroke(_lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0); - _g.setStroke(_s); - _g.drawLine(_x1, _y1, _x2, _y2); - _g.dispose(); - } - - default void gDashedLine(int _x1, int _y1, int _x2, int _y2, long _color, float _shape) - { - gDashedLine(_x1, _y1, _x2, _y2, 1, _color, new float[] {_shape}); - } - - default void gDashedLine(int _x1, int _y1, int _x2, int _y2, long _color, float... _shape) - { - gDashedLine(_x1, _y1, _x2, _y2, 1, _color, _shape); - } - - default void gDashedLine(int _x1, int _y1, int _x2, int _y2, float _lineWidth, long _color, float _shape) - { - gDashedLine(_x1, _y1, _x2, _y2, _lineWidth, _color, new float[] {_shape}); - } - - default void gDashedLine(int _x1, int _y1, int _x2, int _y2, float _lineWidth, long _color, float... _shape) - { - Graphics2D _g = (Graphics2D) this.getG2d(); - _g.setPaint(ImageUtil.createColor(_color)); - Stroke _dashed = new BasicStroke(_lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, _shape, 0); - _g.setStroke(_dashed); - _g.drawLine(_x1, _y1, _x2, _y2); - _g.dispose(); - } - - default void gRectangle(int _x1, int _y1, int _x2, int _y2, long _color) - { - gRectangle(false, _x1, _y1, _x2, _y2, 1, _color, null); - } - - default void gRectangle(int _x1, int _y1, int _x2, int _y2, float _lineWidth, long _color, float _dash) - { - gRectangle(false, _x1, _y1, _x2, _y2, _lineWidth, _color, new float[] {_dash}); - } - - default void gRectangle(int _x1, int _y1, int _x2, int _y2, float _lineWidth, long _color, float[] _dash) - { - gRectangle(false, _x1, _y1, _x2, _y2, _lineWidth, _color, null); - } - - default void gRectangle(boolean _fill, int _x1, int _y1, int _x2, int _y2, float _lineWidth, long _color, float[] _dash) - { - Graphics2D _g = (Graphics2D) this.getG2d(); - _g.setPaint(ImageUtil.createColor(_color)); - if(!_fill) - { - Stroke _s = null; - if(_dash == null || _dash.length==0) - { - _s = new BasicStroke(_lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0); - } - else - { - _s = new BasicStroke(_lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, _dash, 0f); - } - _g.setStroke(_s); - _g.drawRect(_x1,_y1, _x2-_x1, _y2-_y1); - } - else - { - _g.fillRect(_x1,_y1, _x2-_x1, _y2-_y1); - } - _g.dispose(); - } - - default void gFilledRectangle(int _x1, int _y1, int _x2, int _y2, long _color) - { - gRectangle(true, _x1, _y1, _x2, _y2, 1, _color, null); - } - - default void gFilledRectangle(int _x1, int _y1, int _x2, int _y2, float _lineWidth, long _color) - { - gRectangle(true, _x1, _y1, _x2, _y2, _lineWidth, _color, null); - } - - default void gPolygon(long _color, int... _points) - { - gPolygon(1, _color, null, _points); - } - - default void gPolygon(float _lineWidth, long _color, float[] _dash, int... _points) - { - this.gPolygon(false,_lineWidth, _color, _dash, _points); - } - - default void gPolygon(boolean _fill, float _lineWidth, long _color, float[] _dash, int... _points) - { - Graphics2D _g = (Graphics2D) this.getG2d(); - _g.setPaint(ImageUtil.createColor(_color)); - Polygon _p = new Polygon(); - for(int _i = 0; _i<_points.length; _i+=2) - { - _p.addPoint(_points[_i], _points[_i+1]); - } - if(!_fill) - { - Stroke _s = null; - if(_dash == null || _dash.length==0) - { - _s = new BasicStroke(_lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0); - } - else - { - _s = new BasicStroke(_lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, _dash, 0f); - } - _g.setStroke(_s); - _g.drawPolygon(_p); - } - else - { - _g.fillPolygon(_p); - } - _g.dispose(); - } - - default void gFilledPolygon(long _color, int... _points) - { - gFilledPolygon(1, _color, _points); - } - - default void gFilledPolygon(float _lineWidth, long _color, int... _points) - { - this.gPolygon(true,_lineWidth, _color, null, _points); - } - - default void gPolyline(long _color, int... _points) - { - gPolyline(1, _color, null, _points); - } - - default void gPolyline(float _lineWidth, long _color, int... _points) - { - gPolyline(_lineWidth, _color, null, _points); - } - - default void gPolyline(float _lineWidth, long _color, float[] _dash, int... _points) - { - Graphics2D _g = (Graphics2D) this.getG2d(); - _g.setPaint(ImageUtil.createColor(_color)); - Stroke _s = null; - if(_dash == null || _dash.length==0) - { - _s = new BasicStroke(_lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0); - } - else - { - _s = new BasicStroke(_lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, _dash, 0f); - } - _g.setStroke(_s); - int _lx = _points[0]; - int _ly = _points[1]; - for(int _i = 2; _i<_points.length; _i+=2) - { - _g.drawLine(_lx,_ly,_points[_i], _points[_i+1]); - _lx = _points[_i]; - _ly = _points[_i+1]; - } - _g.dispose(); - } - - default void gCircle(int _cx, int _cy, int _r, long _color) - { - this.gOval(_cx, _cy, _r, _r, 1, _color, null); - } - - default void gCircle(int _cx, int _cy, int _r, float _lineWidth, long _color) - { - this.gOval(_cx, _cy, _r, _r, _lineWidth, _color, null); - } - - default void gCircle(int _cx, int _cy, int _r, float _lineWidth, long _color, float _dash) - { - this.gOval(_cx, _cy, _r, _r, _lineWidth, _color, new float[]{ _dash }); - } - - default void gCircle(int _cx, int _cy, int _r, float _lineWidth, long _color, float[] _dash) - { - this.gOval(false, _cx, _cy, _r, _r, _lineWidth, _color, _dash); - } - - default void gCircle(boolean _fill, int _cx, int _cy, int _r, float _lineWidth, long _color, float _dash) - { - this.gOval(_fill, _cx, _cy, _r, _r, _lineWidth, _color, new float[]{ _dash }); - } - - default void gCircle(boolean _fill, int _cx, int _cy, int _r, float _lineWidth, long _color, float[] _dash) - { - this.gOval(_fill, _cx, _cy, _r, _r, _lineWidth, _color, _dash); - } - - default void gFilledCircle(int _cx, int _cy, int _r, long _color) - { - this.gCircle(true, _cx, _cy, _r, 1, _color, null); - } - - default void gOval(int _cx, int _cy, int _ra, int _rb, long _color) - { - this.gOval(_cx, _cy, _ra, _rb, 1, _color, null); - } - - default void gOval(int _cx, int _cy, int _ra, int _rb, float _lineWidth, long _color, float _dash) - { - this.gOval(false, _cx, _cy, _ra, _rb, _lineWidth, _color, new float[]{ _dash }); - } - - default void gOval(int _cx, int _cy, int _ra, int _rb, float _lineWidth, long _color, float[] _dash) - { - this.gOval(false, _cx, _cy, _ra, _rb, 1, _color, null); - } - - default void gOval(boolean _fill, int _cx, int _cy, int _ra, int _rb, float _lineWidth, long _color, float _dash) - { - this.gOval(_fill, _cx, _cy, _ra, _rb, _lineWidth, _color, new float[]{ _dash }); - } - - default void gOval(boolean _fill, int _cx, int _cy, int _ra, int _rb, float _lineWidth, long _color, float[] _dash) - { - Graphics2D _g = (Graphics2D) this.getG2d(); - _g.setPaint(ImageUtil.createColor(_color)); - if(!_fill) - { - Stroke _s = null; - if(_dash == null || _dash.length==0) - { - _s = new BasicStroke(_lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0); - } - else - { - _s = new BasicStroke(_lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, _dash, 0f); - } - _g.setStroke(_s); - _g.drawOval(_cx-_ra, _cy-_rb, _ra*2,_rb*2); - } - else - { - _g.fillOval(_cx-_ra, _cy-_rb,_ra*2,_rb*2); - } - _g.dispose(); - } - - default void gFilledOval(int _cx, int _cy, int _ra, int _rb, long _color) - { - this.gOval(true, _cx, _cy, _ra, _rb, 1, _color, null); - } - - default void gArc(int _cx, int _cy, int _ra, int _rb, int _as, int _ae, long _color) - { - gArc(false, _cx, _cy, _ra, _rb, _as, _ae,1, _color, null); - } - - default void gArc(boolean _fill, int _cx, int _cy, int _ra, int _rb, int _as, int _ae, float _lineWidth, long _color, float _dash) - { - gArc(_fill, _cx, _cy, _ra, _rb, _as, _ae,1, _color, new float[] { _dash }); - } - - default void gArc(boolean _fill, int _cx, int _cy, int _ra, int _rb, int _as, int _ae, float _lineWidth, long _color, float[] _dash) - { - Graphics2D _g = (Graphics2D) this.getG2d(); - _g.setPaint(ImageUtil.createColor(_color)); - if(!_fill) - { - Stroke _s = null; - if(_dash == null || _dash.length==0) - { - _s = new BasicStroke(_lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0); - } - else - { - _s = new BasicStroke(_lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, _dash, 0f); - } - _g.setStroke(_s); - _g.drawArc(_cx-_ra, _cy-_rb, _ra*2,_rb*2, _as, _ae-_as); - } - else - { - _g.fillArc(_cx-_ra, _cy-_rb, _ra*2,_rb*2, _as, _ae-_as); - } - _g.dispose(); - } - - default void gFilledArc(int _cx, int _cy, int _ra, int _rb, int _as, int _ae, long _color) - { - gArc(true, _cx, _cy, _ra, _rb, _as, _ae,1, _color, null); - } - - default void gString(String _font, int _size, int _x, int _y, String _s, long _color) - { - Graphics2D _g = (Graphics2D) this.getG2d(); - _g.setPaint(ImageUtil.createColor(_color)); - _g.setFont(ImageUtil.getFont(_font, _size)); - _g.drawString(_s, _x, _y); - _g.dispose(); - } - - default void gString(Font _font, int _x, int _y, String _s, long _color) - { - Graphics2D _g = (Graphics2D) this.getG2d(); - _g.setPaint(ImageUtil.createColor(_color)); - _g.setFont(_font); - _g.drawString(_s, _x, _y); - _g.dispose(); - } - - public void save(File _out); - public void save(OutputStream _out); - - public StackedGfxInterface getStackedGfxInterface(); -} diff --git a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/GfxSubInterface.java b/template-maven-plugin/src/main/java/com/github/terefang/imageutil/GfxSubInterface.java deleted file mode 100644 index 3da2f25..0000000 --- a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/GfxSubInterface.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.github.terefang.imageutil; - -public interface GfxSubInterface extends GfxInterface -{ - void dispose(); -} diff --git a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/ImageUtil.java b/template-maven-plugin/src/main/java/com/github/terefang/imageutil/ImageUtil.java deleted file mode 100644 index a91f2d3..0000000 --- a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/ImageUtil.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.github.terefang.imageutil; - -import lombok.SneakyThrows; - -import java.awt.*; -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -public class ImageUtil -{ - public static final int ALPHA_OPAQUE = 0xff000000; - public static final int ALPHA_MASK = 0xff000000; - public static final int COLOR_MASK = 0x00ffffff; - public static final int ALPHA_TRANSPARENT = 0x00000000; - - public static final int WHITE = 0xffffffff; - public static final int BLACK = 0xffffffff; - - public static final int RED = 0xffff0000; - public static final int GREEN = 0xff00ff00; - public static final int BLUE = 0xff0000ff; - public static final int YELLOW = 0xffffff00; - public static final int MAGENTA = 0xffff00ff; - public static final int CYAN = 0xff00ffff; - - public static final int HALF_WHITE = 0x88ffffff; - public static final int HALF_RED = 0x88ff0000; - public static final int HALF_GREEN = 0x8800ff00; - public static final int HALF_BLUE = 0x880000ff; - public static final int HALF_YELLOW = 0x88ffff00; - public static final int HALF_MAGENTA = 0x88ff00ff; - public static final int HALF_CYAN = 0x8800ffff; - - public static final Map FONT_MAP = new HashMap<>(); - public static Color createColor(long _color) - { - return new Color((int)_color, true); - } - - public static Font getFont(String _name, int _size) - { - String _l = String.format("%s/%d", _name, _size); - if(!FONT_MAP.containsKey(_l)) - { - Font _awt = Font.getFont(_name); - if(_awt==null) - { - _awt = new Font(_name, Font.PLAIN,_size); - } - else - { - _awt = _awt.deriveFont((float) _size); - } - FONT_MAP.put(_l, _awt); - } - return FONT_MAP.get(_l); - } - - @SneakyThrows - public static Font getTTFont(File _name, int _size) - { - String _l = String.format("%s/%d", _name.getName(), _size); - if(!FONT_MAP.containsKey(_l)) - { - FONT_MAP.put(_l,Font.createFont(Font.TRUETYPE_FONT, _name).deriveFont((float)_size)); - } - return FONT_MAP.get(_l); - } - - @SneakyThrows - public static Font getPSFont(File _name, int _size) - { - String _l = String.format("%s/%d", _name.getName(), _size); - if(!FONT_MAP.containsKey(_l)) - { - FONT_MAP.put(_l,Font.createFont(Font.TYPE1_FONT, _name).deriveFont((float)_size)); - } - return FONT_MAP.get(_l); - } - - public static Font getFont(String _name, float _size) - { - String _l = String.format("%s/%f", _name, _size); - if(!FONT_MAP.containsKey(_l)) - { - Font _awt = Font.getFont(_name); - if(_awt==null) - { - _awt = new Font(_name, Font.PLAIN, (int)_size); - } - else - { - _awt = _awt.deriveFont(_size); - } - FONT_MAP.put(_l, _awt); - } - return FONT_MAP.get(_l); - } - - @SneakyThrows - public static Font getTTFont(File _name, float _size) - { - String _l = String.format("%s/%f", _name.getName(), _size); - if(!FONT_MAP.containsKey(_l)) - { - FONT_MAP.put(_l,Font.createFont(Font.TRUETYPE_FONT, _name).deriveFont(_size)); - } - return FONT_MAP.get(_l); - } - - @SneakyThrows - public static Font getPSFont(File _name, float _size) - { - String _l = String.format("%s/%f", _name.getName(), _size); - if(!FONT_MAP.containsKey(_l)) - { - FONT_MAP.put(_l,Font.createFont(Font.TYPE1_FONT, _name).deriveFont(_size)); - } - return FONT_MAP.get(_l); - } - - public static int toColor(float _r, float _g, float _b) { - return (((0xff) << 24) | (((int) (_r * 255)) << 16) | (((int) (_g * 255)) << 8) | ((int) (_b * 255))); - } - - public static int toColor(float _r, float _g, float _b, float _a) { - return((((int) (_a * 255)) << 24) | (((int) (_r * 255)) << 16) | (((int) (_g * 255)) << 8) | ((int) (_b * 255))); - } - - public static int toColor(int _rgb, float _a) { - return((((_rgb)) << 8) | ((int) (_a * 255))); - } -} diff --git a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/PdfCustomFontTextDrawer.java b/template-maven-plugin/src/main/java/com/github/terefang/imageutil/PdfCustomFontTextDrawer.java deleted file mode 100644 index 0345a0f..0000000 --- a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/PdfCustomFontTextDrawer.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.github.terefang.imageutil; - -import de.rototor.pdfbox.graphics2d.PdfBoxGraphics2DFontTextDrawer; -import org.apache.fontbox.ttf.OTFParser; -import org.apache.fontbox.ttf.OpenTypeFont; -import org.apache.pdfbox.pdmodel.font.PDFont; -import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont; -import org.apache.pdfbox.pdmodel.font.PDType0Font; - -import java.awt.*; -import java.awt.font.TextAttribute; -import java.io.File; -import java.io.IOException; -import java.text.AttributedCharacterIterator; -import java.util.HashMap; -import java.util.Map; - -public class PdfCustomFontTextDrawer extends PdfBoxGraphics2DFontTextDrawer -{ - Map pfontMap = new HashMap<>(); - Map xfontMap = new HashMap<>(); - PdfStdEncoding ENC = new PdfStdEncoding(); - @Override - public void registerFont(String fontName, File fontFile) { - super.registerFont(fontName, fontFile); - pfontMap.put(fontName, fontFile); - } - - @Override - public boolean canDrawText(AttributedCharacterIterator iterator, IFontTextDrawerEnv env) throws IOException, FontFormatException - { - Font attributeFont = (Font) iterator.getAttribute(TextAttribute.FONT); - - if (attributeFont == null) attributeFont = env.getFont(); - - if(this.pfontMap.containsKey(attributeFont.getFontName())) - { - return true; - } - - return super.canDrawText(iterator, env); - } - - @Override - protected PDFont mapFont(Font font, IFontTextDrawerEnv env) - throws IOException, FontFormatException { - // Using the font, especially the font.getFontName() or font.getFamily() to determine which - // font to use... return null if the font can not be mapped. You can also call registerFont() here. - - // Default lookup in the registered fonts - String fontName = font.getFontName(); - if(this.pfontMap.containsKey(fontName)) - { - if(!this.xfontMap.containsKey(fontName)) - { - try - { - PDFont pdFont = PDType0Font.load(env.getDocument(), this.pfontMap.get(fontName)); - this.xfontMap.put(fontName, pdFont); - } - catch(Exception _xe) - { - OTFParser parser = new OTFParser(false, true); - OpenTypeFont _font = parser.parse(this.pfontMap.get(fontName)); - PDFont pdFont = PDTrueTypeFont.load(env.getDocument(), _font, ENC); - this.xfontMap.put(fontName, pdFont); - } - } - return this.xfontMap.get(fontName); - } - - return super.mapFont(font, env); - } -} diff --git a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/PdfImage.java b/template-maven-plugin/src/main/java/com/github/terefang/imageutil/PdfImage.java deleted file mode 100644 index 5a50f69..0000000 --- a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/PdfImage.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.github.terefang.imageutil; - -import de.rototor.pdfbox.graphics2d.PdfBoxGraphics2D; -import de.rototor.pdfbox.graphics2d.PdfBoxGraphics2DFontTextDrawer; -import lombok.SneakyThrows; -import org.apache.pdfbox.pdmodel.PDDocument; -import org.apache.pdfbox.pdmodel.PDPage; -import org.apache.pdfbox.pdmodel.PDPageContentStream; -import org.apache.pdfbox.pdmodel.common.PDRectangle; -import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject; -import org.apache.pdfbox.util.Matrix; -import org.codehaus.plexus.util.IOUtil; -import org.jfree.graphics2d.svg.SVGGraphics2D; -import org.jfree.graphics2d.svg.SVGHints; -import org.jfree.graphics2d.svg.SVGUnits; - -import java.awt.*; -import java.io.*; -import java.util.UUID; - -public class PdfImage extends AbstractGfxInterface implements GfxInterface -{ - PdfCustomFontTextDrawer fontTextDrawer = new PdfCustomFontTextDrawer(); - PDDocument document; - PDPage page; - PdfBoxGraphics2D g2d; - public static final PdfImage create(int _width, int _height) { - return new PdfImage(_width, _height); - } - - public void registerFont(Font _font, File _file) - { - this.fontTextDrawer.registerFont(_font.getFontName(), _file); - } - - @SneakyThrows - public PdfImage(int width, int height) - { - super(); - this.document = new PDDocument(); - this.page = new PDPage(new PDRectangle(width, height)); - this.document.addPage(this.page); - this.g2d = new PdfBoxGraphics2D(this.document, width, height); - this.g2d.setFontTextDrawer(this.fontTextDrawer); - } - - @Override - public Graphics2D getG2d() { - return (Graphics2D) this.g2d.create(); - } - - @Override - public void gSet(int _x, int _y, long _color) { - Graphics2D _g = this.getG2d(); - _g.setColor(ImageUtil.createColor(_color)); - _g.fillRect(_x, _y, 1, 1); - _g.dispose(); - } - - public String beginGroup() - { - return beginGroup(UUID.randomUUID().toString()); - } - - public String beginGroup(String _id) - { - this.g2d.setRenderingHint(SVGHints.KEY_BEGIN_GROUP, _id); - return _id; - } - - public void endGroup() - { - this.g2d.setRenderingHint(SVGHints.KEY_END_GROUP, "true"); - } - - @Override - public int gGet(int _x, int _y) { - return 0; - } - - @SneakyThrows - public void save(String _path) { - this.save(new File(_path)); - } - - @SneakyThrows - public void save(File _out) - { - this.save(new FileOutputStream(_out)); - } - - @SneakyThrows - public void save(OutputStream _out) - { - this.g2d.dispose(); - PDFormXObject xform = this.g2d.getXFormObject(); - Matrix matrix = new Matrix(); - matrix.translate(0, this.page.getMediaBox().getHeight()); - PDPageContentStream contentStream = new PDPageContentStream(this.document, this.page); - //contentStream.transform(matrix); - contentStream.drawForm(xform); - contentStream.close(); - - this.document.save(new BufferedOutputStream(_out, 8192)); - document.close(); - } -} diff --git a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/PdfStdEncoding.java b/template-maven-plugin/src/main/java/com/github/terefang/imageutil/PdfStdEncoding.java deleted file mode 100644 index 5421655..0000000 --- a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/PdfStdEncoding.java +++ /dev/null @@ -1,275 +0,0 @@ -package com.github.terefang.imageutil; - -import org.apache.pdfbox.cos.*; -import org.apache.pdfbox.pdmodel.font.encoding.DictionaryEncoding; -import org.apache.pdfbox.pdmodel.font.encoding.Encoding; -import org.apache.pdfbox.pdmodel.font.encoding.MacRomanEncoding; - -public class PdfStdEncoding extends DictionaryEncoding -{ - static COSArray DIFS = new COSArray(); - static { - DIFS.add(COSInteger.ZERO); - DIFS.add(COSName.getPDFName("uni0000")); - DIFS.add(COSName.getPDFName("controlSTX")); - DIFS.add(COSName.getPDFName("controlSOT")); - DIFS.add(COSName.getPDFName("controlETX")); - DIFS.add(COSName.getPDFName("controlEOT")); - DIFS.add(COSName.getPDFName("controlENQ")); - DIFS.add(COSName.getPDFName("controlACK")); - DIFS.add(COSName.getPDFName("controlBEL")); - DIFS.add(COSName.getPDFName("controlBS")); - DIFS.add(COSName.getPDFName("controlHT")); - DIFS.add(COSName.getPDFName("controlLF")); - DIFS.add(COSName.getPDFName("controlVT")); - DIFS.add(COSName.getPDFName("controlFF")); - DIFS.add(COSName.getPDFName("controlCR")); - DIFS.add(COSName.getPDFName("controlSO")); - DIFS.add(COSName.getPDFName("controlSI")); - DIFS.add(COSName.getPDFName("controlDLE")); - DIFS.add(COSName.getPDFName("controlDC1")); - DIFS.add(COSName.getPDFName("controlDC2")); - DIFS.add(COSName.getPDFName("controlDC3")); - DIFS.add(COSName.getPDFName("controlDC4")); - DIFS.add(COSName.getPDFName("controlNAK")); - DIFS.add(COSName.getPDFName("controlSYN")); - DIFS.add(COSName.getPDFName("controlETB")); - DIFS.add(COSName.getPDFName("breve")); - DIFS.add(COSName.getPDFName("caron")); - DIFS.add(COSName.getPDFName("circumflex")); - DIFS.add(COSName.getPDFName("dotaccent")); - DIFS.add(COSName.getPDFName("hungarumlaut")); - DIFS.add(COSName.getPDFName("ogonek")); - DIFS.add(COSName.getPDFName("ring")); - DIFS.add(COSName.getPDFName("tilde")); - DIFS.add(COSName.getPDFName("space")); - DIFS.add(COSName.getPDFName("exclam")); - DIFS.add(COSName.getPDFName("quotedbl")); - DIFS.add(COSName.getPDFName("numbersign")); - DIFS.add(COSName.getPDFName("dollar")); - DIFS.add(COSName.getPDFName("percent")); - DIFS.add(COSName.getPDFName("ampersand")); - DIFS.add(COSName.getPDFName("quotesingle")); - DIFS.add(COSName.getPDFName("parenleft")); - DIFS.add(COSName.getPDFName("parenright")); - DIFS.add(COSName.getPDFName("asterisk")); - DIFS.add(COSName.getPDFName("plus")); - DIFS.add(COSName.getPDFName("comma")); - DIFS.add(COSName.getPDFName("hyphen")); - DIFS.add(COSName.getPDFName("period")); - DIFS.add(COSName.getPDFName("slash")); - DIFS.add(COSName.getPDFName("zero")); - DIFS.add(COSName.getPDFName("one")); - DIFS.add(COSName.getPDFName("two")); - DIFS.add(COSName.getPDFName("three")); - DIFS.add(COSName.getPDFName("four")); - DIFS.add(COSName.getPDFName("five")); - DIFS.add(COSName.getPDFName("six")); - DIFS.add(COSName.getPDFName("seven")); - DIFS.add(COSName.getPDFName("eight")); - DIFS.add(COSName.getPDFName("nine")); - DIFS.add(COSName.getPDFName("colon")); - DIFS.add(COSName.getPDFName("semicolon")); - DIFS.add(COSName.getPDFName("less")); - DIFS.add(COSName.getPDFName("equal")); - DIFS.add(COSName.getPDFName("greater")); - DIFS.add(COSName.getPDFName("question")); - DIFS.add(COSName.getPDFName("at")); - DIFS.add(COSName.getPDFName("A")); - DIFS.add(COSName.getPDFName("B")); - DIFS.add(COSName.getPDFName("C")); - DIFS.add(COSName.getPDFName("D")); - DIFS.add(COSName.getPDFName("E")); - DIFS.add(COSName.getPDFName("F")); - DIFS.add(COSName.getPDFName("G")); - DIFS.add(COSName.getPDFName("H")); - DIFS.add(COSName.getPDFName("I")); - DIFS.add(COSName.getPDFName("J")); - DIFS.add(COSName.getPDFName("K")); - DIFS.add(COSName.getPDFName("L")); - DIFS.add(COSName.getPDFName("M")); - DIFS.add(COSName.getPDFName("N")); - DIFS.add(COSName.getPDFName("O")); - DIFS.add(COSName.getPDFName("P")); - DIFS.add(COSName.getPDFName("Q")); - DIFS.add(COSName.getPDFName("R")); - DIFS.add(COSName.getPDFName("S")); - DIFS.add(COSName.getPDFName("T")); - DIFS.add(COSName.getPDFName("U")); - DIFS.add(COSName.getPDFName("V")); - DIFS.add(COSName.getPDFName("W")); - DIFS.add(COSName.getPDFName("X")); - DIFS.add(COSName.getPDFName("Y")); - DIFS.add(COSName.getPDFName("Z")); - DIFS.add(COSName.getPDFName("bracketleft")); - DIFS.add(COSName.getPDFName("backslash")); - DIFS.add(COSName.getPDFName("bracketright")); - DIFS.add(COSName.getPDFName("asciicircum")); - DIFS.add(COSName.getPDFName("underscore")); - DIFS.add(COSName.getPDFName("grave")); - DIFS.add(COSName.getPDFName("a")); - DIFS.add(COSName.getPDFName("b")); - DIFS.add(COSName.getPDFName("c")); - DIFS.add(COSName.getPDFName("d")); - DIFS.add(COSName.getPDFName("e")); - DIFS.add(COSName.getPDFName("f")); - DIFS.add(COSName.getPDFName("g")); - DIFS.add(COSName.getPDFName("h")); - DIFS.add(COSName.getPDFName("i")); - DIFS.add(COSName.getPDFName("j")); - DIFS.add(COSName.getPDFName("k")); - DIFS.add(COSName.getPDFName("l")); - DIFS.add(COSName.getPDFName("m")); - DIFS.add(COSName.getPDFName("n")); - DIFS.add(COSName.getPDFName("o")); - DIFS.add(COSName.getPDFName("p")); - DIFS.add(COSName.getPDFName("q")); - DIFS.add(COSName.getPDFName("r")); - DIFS.add(COSName.getPDFName("s")); - DIFS.add(COSName.getPDFName("t")); - DIFS.add(COSName.getPDFName("u")); - DIFS.add(COSName.getPDFName("v")); - DIFS.add(COSName.getPDFName("w")); - DIFS.add(COSName.getPDFName("x")); - DIFS.add(COSName.getPDFName("y")); - DIFS.add(COSName.getPDFName("z")); - DIFS.add(COSName.getPDFName("braceleft")); - DIFS.add(COSName.getPDFName("bar")); - DIFS.add(COSName.getPDFName("braceright")); - DIFS.add(COSName.getPDFName("asciitilde")); - DIFS.add(COSName.getPDFName("uniFFFD")); - DIFS.add(COSName.getPDFName("bullet")); - DIFS.add(COSName.getPDFName("dagger")); - DIFS.add(COSName.getPDFName("daggerdbl")); - DIFS.add(COSName.getPDFName("ellipsis")); - DIFS.add(COSName.getPDFName("emdash")); - DIFS.add(COSName.getPDFName("endash")); - DIFS.add(COSName.getPDFName("florin")); - DIFS.add(COSName.getPDFName("fraction")); - DIFS.add(COSName.getPDFName("guilsinglleft")); - DIFS.add(COSName.getPDFName("guilsinglright")); - DIFS.add(COSName.getPDFName("minus")); - DIFS.add(COSName.getPDFName("perthousand")); - DIFS.add(COSName.getPDFName("quotedblbase")); - DIFS.add(COSName.getPDFName("quotedblleft")); - DIFS.add(COSName.getPDFName("quotedblright")); - DIFS.add(COSName.getPDFName("quoteleft")); - DIFS.add(COSName.getPDFName("quoteright")); - DIFS.add(COSName.getPDFName("quotesinglbase")); - DIFS.add(COSName.getPDFName("trademark")); - DIFS.add(COSName.getPDFName("uniFB01")); - DIFS.add(COSName.getPDFName("uniFB02")); - DIFS.add(COSName.getPDFName("Lslash")); - DIFS.add(COSName.getPDFName("OE")); - DIFS.add(COSName.getPDFName("Scaron")); - DIFS.add(COSName.getPDFName("Ydieresis")); - DIFS.add(COSName.getPDFName("Zcaron")); - DIFS.add(COSName.getPDFName("dotlessi")); - DIFS.add(COSName.getPDFName("lslash")); - DIFS.add(COSName.getPDFName("oe")); - DIFS.add(COSName.getPDFName("scaron")); - DIFS.add(COSName.getPDFName("zcaron")); - DIFS.add(COSName.getPDFName("uniFFFD")); - DIFS.add(COSName.getPDFName("Euro")); - DIFS.add(COSName.getPDFName("exclamdown")); - DIFS.add(COSName.getPDFName("cent")); - DIFS.add(COSName.getPDFName("sterling")); - DIFS.add(COSName.getPDFName("currency")); - DIFS.add(COSName.getPDFName("yen")); - DIFS.add(COSName.getPDFName("brokenbar")); - DIFS.add(COSName.getPDFName("section")); - DIFS.add(COSName.getPDFName("dieresis")); - DIFS.add(COSName.getPDFName("copyright")); - DIFS.add(COSName.getPDFName("ordfeminine")); - DIFS.add(COSName.getPDFName("guillemotleft")); - DIFS.add(COSName.getPDFName("logicalnot")); - DIFS.add(COSName.getPDFName("uni00AD")); - DIFS.add(COSName.getPDFName("registered")); - DIFS.add(COSName.getPDFName("macron")); - DIFS.add(COSName.getPDFName("degree")); - DIFS.add(COSName.getPDFName("plusminus")); - DIFS.add(COSName.getPDFName("uni00B2")); - DIFS.add(COSName.getPDFName("uni00B3")); - DIFS.add(COSName.getPDFName("acute")); - DIFS.add(COSName.getPDFName("mu")); - DIFS.add(COSName.getPDFName("paragraph")); - DIFS.add(COSName.getPDFName("periodcentered")); - DIFS.add(COSName.getPDFName("cedilla")); - DIFS.add(COSName.getPDFName("uni00B9")); - DIFS.add(COSName.getPDFName("ordmasculine")); - DIFS.add(COSName.getPDFName("guillemotright")); - DIFS.add(COSName.getPDFName("onequarter")); - DIFS.add(COSName.getPDFName("onehalf")); - DIFS.add(COSName.getPDFName("threequarters")); - DIFS.add(COSName.getPDFName("questiondown")); - DIFS.add(COSName.getPDFName("Agrave")); - DIFS.add(COSName.getPDFName("Aacute")); - DIFS.add(COSName.getPDFName("Acircumflex")); - DIFS.add(COSName.getPDFName("Atilde")); - DIFS.add(COSName.getPDFName("Adieresis")); - DIFS.add(COSName.getPDFName("Aring")); - DIFS.add(COSName.getPDFName("AE")); - DIFS.add(COSName.getPDFName("Ccedilla")); - DIFS.add(COSName.getPDFName("Egrave")); - DIFS.add(COSName.getPDFName("Eacute")); - DIFS.add(COSName.getPDFName("Ecircumflex")); - DIFS.add(COSName.getPDFName("Edieresis")); - DIFS.add(COSName.getPDFName("Igrave")); - DIFS.add(COSName.getPDFName("Iacute")); - DIFS.add(COSName.getPDFName("Icircumflex")); - DIFS.add(COSName.getPDFName("Idieresis")); - DIFS.add(COSName.getPDFName("Eth")); - DIFS.add(COSName.getPDFName("Ntilde")); - DIFS.add(COSName.getPDFName("Ograve")); - DIFS.add(COSName.getPDFName("Oacute")); - DIFS.add(COSName.getPDFName("Ocircumflex")); - DIFS.add(COSName.getPDFName("Otilde")); - DIFS.add(COSName.getPDFName("Odieresis")); - DIFS.add(COSName.getPDFName("multiply")); - DIFS.add(COSName.getPDFName("Oslash")); - DIFS.add(COSName.getPDFName("Ugrave")); - DIFS.add(COSName.getPDFName("Uacute")); - DIFS.add(COSName.getPDFName("Ucircumflex")); - DIFS.add(COSName.getPDFName("Udieresis")); - DIFS.add(COSName.getPDFName("Yacute")); - DIFS.add(COSName.getPDFName("Thorn")); - DIFS.add(COSName.getPDFName("germandbls")); - DIFS.add(COSName.getPDFName("agrave")); - DIFS.add(COSName.getPDFName("aacute")); - DIFS.add(COSName.getPDFName("acircumflex")); - DIFS.add(COSName.getPDFName("atilde")); - DIFS.add(COSName.getPDFName("adieresis")); - DIFS.add(COSName.getPDFName("aring")); - DIFS.add(COSName.getPDFName("ae")); - DIFS.add(COSName.getPDFName("ccedilla")); - DIFS.add(COSName.getPDFName("egrave")); - DIFS.add(COSName.getPDFName("eacute")); - DIFS.add(COSName.getPDFName("ecircumflex")); - DIFS.add(COSName.getPDFName("edieresis")); - DIFS.add(COSName.getPDFName("igrave")); - DIFS.add(COSName.getPDFName("iacute")); - DIFS.add(COSName.getPDFName("icircumflex")); - DIFS.add(COSName.getPDFName("idieresis")); - DIFS.add(COSName.getPDFName("eth")); - DIFS.add(COSName.getPDFName("ntilde")); - DIFS.add(COSName.getPDFName("ograve")); - DIFS.add(COSName.getPDFName("oacute")); - DIFS.add(COSName.getPDFName("ocircumflex")); - DIFS.add(COSName.getPDFName("otilde")); - DIFS.add(COSName.getPDFName("odieresis")); - DIFS.add(COSName.getPDFName("divide")); - DIFS.add(COSName.getPDFName("oslash")); - DIFS.add(COSName.getPDFName("ugrave")); - DIFS.add(COSName.getPDFName("uacute")); - DIFS.add(COSName.getPDFName("ucircumflex")); - DIFS.add(COSName.getPDFName("udieresis")); - DIFS.add(COSName.getPDFName("yacute")); - DIFS.add(COSName.getPDFName("thorn")); - DIFS.add(COSName.getPDFName("ydieresis")); - } - - public PdfStdEncoding() - { - super(COSName.WIN_ANSI_ENCODING, DIFS); - } -} diff --git a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/PixelImage.java b/template-maven-plugin/src/main/java/com/github/terefang/imageutil/PixelImage.java deleted file mode 100644 index f48c483..0000000 --- a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/PixelImage.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.github.terefang.imageutil; - -import lombok.SneakyThrows; - -import java.awt.*; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.OutputStream; -import java.util.Iterator; -import javax.imageio.ImageIO; -import javax.imageio.ImageReadParam; -import javax.imageio.ImageReader; -import javax.imageio.stream.ImageInputStream; - -public class PixelImage extends AbstractGfxInterface implements GfxInterface { - - BufferedImage _bimg; - - public static final PixelImage create(int _width, int _height) { - return new PixelImage(_width, _height); - } - - public static final PixelImage from(BufferedImage _bimg) { - PixelImage _pi = new PixelImage(_bimg.getWidth(), _bimg.getHeight()); - _bimg.copyData(_pi._bimg.getRaster()); - return _pi; - } - - public PixelImage(int _width, int _height) { - _bimg = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_ARGB); - } - - @SneakyThrows - public void savePng(String _path) { - this.saveAs("png", new File(_path)); - } - - @SneakyThrows - public void savePng(File _out) { - this.saveAs("png", _out); - } - - @SneakyThrows - public void savePng(OutputStream _out) { - this.saveAs("png", _out); - } - - @SneakyThrows - public void saveAs(String _type, File _out) { - ImageIO.write(this._bimg, _type, _out); - } - - @SneakyThrows - public void saveAs(String _type, OutputStream _out) { - ImageIO.write(this._bimg, _type, _out); - } - - @SneakyThrows - public void save(File _out) { this.saveAs("png", _out);} - - @SneakyThrows - public void save(OutputStream _out) { this.saveAs("png", _out);} - - @SneakyThrows - public static PixelImage load(File _file) { - ImageInputStream stream = ImageIO.createImageInputStream(_file); - Iterator readers = ImageIO.getImageReaders(stream); - - if (readers.hasNext()) { - ImageReader reader = readers.next(); - reader.setInput(reader); - - int w = reader.getWidth(0); - int h = reader.getHeight(0); - - ImageReadParam param = reader.getDefaultReadParam(); - - PixelImage _pi = PixelImage.create(w, h); - param.setDestination(_pi._bimg); - - reader.read(0, param); - return _pi; - } - return null; - } - - @Override - public Graphics2D getG2d() { - return (Graphics2D) this._bimg.getGraphics(); - } - - @Override - public String beginGroup() { - return null; - } - - @Override - public String beginGroup(String _id) { - return null; - } - - @Override - public void endGroup() { - - } - - public int gGet(int _x, int _y) { return this._bimg.getRGB(_x, _y); } - - public void gSet(int _x, int _y, long _color) { this._bimg.setRGB(_x, _y, (int)_color); } - - public int gColorReplace(int _src, int _dst) { return 0; } - public int gColorReplaceThreshold(int _src, int _dst, float _threshold) { return 0; } - -} diff --git a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/StackedGfxInterface.java b/template-maven-plugin/src/main/java/com/github/terefang/imageutil/StackedGfxInterface.java deleted file mode 100644 index 3d8be8e..0000000 --- a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/StackedGfxInterface.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.github.terefang.imageutil; - -import java.awt.*; - -public interface StackedGfxInterface -{ - public Graphics2D getCurrentGraphics2D(); - - public void beginDraw(); - public void beginDraw(String _id); - public void endDraw(); - public void beginText(); - public void endText(); - - public void draw3DRect(int x, int y, int width, int height, boolean raised); - - public void fill3DRect(int x, int y, int width, int height, boolean raised); - - public void drawString(String str, int x, int y); - - public void drawString(String str, float x, float y); - - public void setComposite(Composite comp); - - public void setPaint(Paint paint); - - public void setStroke(Stroke s); - - public void translate(int x, int y); - - public void translate(double tx, double ty); - - public void rotate(double theta); - - public void rotate(double theta, double x, double y); - - public void scale(double sx, double sy); - - public void shear(double shx, double shy); - - public void setBackground(int _color); - - public void clip(Shape s); - - default void clip(int[] _points) - { - Polygon _p = new Polygon(); - for(int _i = 0; _i<_points.length; _i+=2) - { - _p.addPoint(_points[_i], _points[_i+1]); - } - clip(_p); - } - - public void setColor(long _color); - - public void setPaintMode(); - - public void setFont(Font font); - - public void clipRect(int x, int y, int width, int height); - - public void setClip(int x, int y, int width, int height); - - public void drawLine(int x1, int y1, int x2, int y2); - - public void fillRect(int x, int y, int width, int height); - - public void drawRect(int x, int y, int width, int height); - - public void clearRect(int x, int y, int width, int height); - - public void drawRoundRect(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); - - public void drawOval(int x, int y, int width, int height); - - public void fillOval(int x, int y, int width, int height); - - public void drawArc(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); - - public void drawPolyline(int[] points); - - public void drawPolygon(int[] points); - - public void fillPolygon(int[] points); - - public void dispose(); -} diff --git a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/SvgImage.java b/template-maven-plugin/src/main/java/com/github/terefang/imageutil/SvgImage.java deleted file mode 100644 index ac6ec0d..0000000 --- a/template-maven-plugin/src/main/java/com/github/terefang/imageutil/SvgImage.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.github.terefang.imageutil; - -import lombok.SneakyThrows; -import org.apache.commons.io.IOUtils; -import org.codehaus.plexus.util.IOUtil; -import org.jfree.graphics2d.svg.SVGGraphics2D; -import org.jfree.graphics2d.svg.SVGHints; -import org.jfree.graphics2d.svg.SVGUnits; - -import java.awt.*; -import java.io.*; -import java.util.UUID; - -public class SvgImage extends AbstractGfxInterface implements GfxInterface -{ - SVGGraphics2D g2d; - public static final SvgImage create(int _width, int _height) { - return new SvgImage(_width, _height); - } - - public SvgImage(int width, int height) - { - super(); - this.g2d = new SVGGraphics2D(width, height); - this.g2d.setFontSizeUnits(SVGUnits.PT); - } - - @Override - public Graphics2D getG2d() { - return (Graphics2D) this.g2d.create(); - } - - @Override - public void gSet(int _x, int _y, long _color) { - Graphics2D _g = this.getG2d(); - _g.setColor(ImageUtil.createColor(_color)); - _g.fillRect(_x, _y, 1, 1); - _g.dispose(); - } - - public String beginGroup() - { - return beginGroup(UUID.randomUUID().toString()); - } - - public String beginGroup(String _id) - { - this.g2d.setRenderingHint(SVGHints.KEY_BEGIN_GROUP, _id); - return _id; - } - - public void endGroup() - { - this.g2d.setRenderingHint(SVGHints.KEY_END_GROUP, "true"); - } - - @Override - public int gGet(int _x, int _y) { - return 0; - } - - @SneakyThrows - public void save(String _path) { - this.save(new File(_path)); - } - - @SneakyThrows - public void save(File _out) - { - this.save(new FileOutputStream(_out)); - } - - @SneakyThrows - public void save(OutputStream _out) - { - BufferedWriter _bw = new BufferedWriter(new OutputStreamWriter(_out), 8192); - IOUtil.copy(this.g2d.getSVGDocument(), _bw); - IOUtil.close(_bw); - } -} diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/AbstractTmpMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/AbstractTmpMojo.java index 474d7d4..3b09c63 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/AbstractTmpMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/AbstractTmpMojo.java @@ -1,8 +1,8 @@ package com.github.terefang.template_maven_plugin; -import com.github.terefang.imageutil.GfxInterface; -import com.github.terefang.imageutil.PixelImage; -import com.github.terefang.imageutil.SvgImage; +import com.github.terefang.jmelange.image.GfxInterface; +import com.github.terefang.jmelange.image.PixelImage; +import com.github.terefang.jmelange.image.SvgImage; import com.github.terefang.template_maven_plugin.util.ContextHelper; import com.github.terefang.template_maven_plugin.util.ContextUtil; import lombok.Data; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/freemarker/FreeMarkerStandardMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/freemarker/FreeMarkerStandardMojo.java index e52a011..42a2c06 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/freemarker/FreeMarkerStandardMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/freemarker/FreeMarkerStandardMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.freemarker; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractStandardMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.SneakyThrows; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/freemarker/FreeMarkerTemplateMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/freemarker/FreeMarkerTemplateMojo.java index 0e9854d..c99d857 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/freemarker/FreeMarkerTemplateMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/freemarker/FreeMarkerTemplateMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.freemarker; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractTemplateMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.SneakyThrows; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GSimpleStandardMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GSimpleStandardMojo.java index 2a93b00..b856228 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GSimpleStandardMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GSimpleStandardMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.groovy; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractStandardMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.SneakyThrows; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GSimpleTemplateMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GSimpleTemplateMojo.java index 8e8e139..6870ea7 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GSimpleTemplateMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GSimpleTemplateMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.groovy; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractTemplateMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import com.github.terefang.template_maven_plugin.thymeleaf.ThymeleafUtil; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GroovyStandardMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GroovyStandardMojo.java index 00747ae..2455413 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GroovyStandardMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GroovyStandardMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.groovy; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractStandardMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.Data; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GroovyTemplateMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GroovyTemplateMojo.java index 4e7bd73..bc0a868 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GroovyTemplateMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GroovyTemplateMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.groovy; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractTemplateMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.Data; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GroovyUtil.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GroovyUtil.java index 8dc692a..f90ce37 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GroovyUtil.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/groovy/GroovyUtil.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.groovy; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.TemplateContext; import groovy.lang.Binding; import groovy.lang.Closure; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/handlebars/HandlebarsStandardMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/handlebars/HandlebarsStandardMojo.java index 96d71f9..47fad0d 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/handlebars/HandlebarsStandardMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/handlebars/HandlebarsStandardMojo.java @@ -1,7 +1,7 @@ package com.github.terefang.template_maven_plugin.handlebars; import com.github.jknack.handlebars.Handlebars; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractStandardMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.SneakyThrows; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/handlebars/HandlebarsTemplateMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/handlebars/HandlebarsTemplateMojo.java index d90593c..419efcf 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/handlebars/HandlebarsTemplateMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/handlebars/HandlebarsTemplateMojo.java @@ -1,7 +1,7 @@ package com.github.terefang.template_maven_plugin.handlebars; import com.github.jknack.handlebars.Handlebars; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractTemplateMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.SneakyThrows; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlJxtStandardMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlJxtStandardMojo.java index 88c726c..c6d9db5 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlJxtStandardMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlJxtStandardMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.jexl; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractStandardMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.SneakyThrows; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlJxtTemplateMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlJxtTemplateMojo.java index 4459f24..b8d8b41 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlJxtTemplateMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlJxtTemplateMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.jexl; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractTemplateMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import freemarker.log._CommonsLoggingLoggerFactory; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlStandardMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlStandardMojo.java index 252c70a..60f5ddd 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlStandardMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlStandardMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.jexl; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractStandardMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.SneakyThrows; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlTemplateMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlTemplateMojo.java index 58ccb2e..6169de1 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlTemplateMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlTemplateMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.jexl; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractTemplateMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.SneakyThrows; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlUtil.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlUtil.java index 8c8534f..0091705 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlUtil.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jexl/JexlUtil.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.jexl; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.SneakyThrows; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jinjava/JinjavaStandardMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jinjava/JinjavaStandardMojo.java index af2aadc..6f901ce 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jinjava/JinjavaStandardMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jinjava/JinjavaStandardMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.jinjava; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractStandardMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import com.hubspot.jinjava.Jinjava; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jinjava/JinjavaTemplateMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jinjava/JinjavaTemplateMojo.java index 4bfe6bf..281080b 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jinjava/JinjavaTemplateMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/jinjava/JinjavaTemplateMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.jinjava; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractTemplateMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import com.github.terefang.template_maven_plugin.util.ContextUtil; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/luaj/LuajStandardMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/luaj/LuajStandardMojo.java index 4c8e38b..c00e241 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/luaj/LuajStandardMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/luaj/LuajStandardMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.luaj; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractStandardMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.Data; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/luaj/LuajTemplateMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/luaj/LuajTemplateMojo.java index 813c71f..7758467 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/luaj/LuajTemplateMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/luaj/LuajTemplateMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.luaj; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractTemplateMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.Data; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/rhino/RhinoScript.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/rhino/RhinoScript.java index de935ff..f4b9583 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/rhino/RhinoScript.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/rhino/RhinoScript.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.rhino; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.Data; import lombok.SneakyThrows; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/rhino/RhinoStandardMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/rhino/RhinoStandardMojo.java index 9133242..fcdbdbd 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/rhino/RhinoStandardMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/rhino/RhinoStandardMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.rhino; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractStandardMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.Data; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/rhino/RhinoTemplateMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/rhino/RhinoTemplateMojo.java index 51335eb..109612a 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/rhino/RhinoTemplateMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/rhino/RhinoTemplateMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.rhino; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractTemplateMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.Data; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/thymeleaf/ThymeleafStandardMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/thymeleaf/ThymeleafStandardMojo.java index e96a852..2aa1355 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/thymeleaf/ThymeleafStandardMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/thymeleaf/ThymeleafStandardMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.thymeleaf; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractStandardMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.SneakyThrows; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/thymeleaf/ThymeleafTemplateMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/thymeleaf/ThymeleafTemplateMojo.java index f8a8503..8f4b811 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/thymeleaf/ThymeleafTemplateMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/thymeleaf/ThymeleafTemplateMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.thymeleaf; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractTemplateMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.SneakyThrows; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/trimou/TrimouStandardMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/trimou/TrimouStandardMojo.java index cc21454..8fe5864 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/trimou/TrimouStandardMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/trimou/TrimouStandardMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.trimou; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractStandardMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import com.hubspot.jinjava.Jinjava; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/trimou/TrimouTemplateMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/trimou/TrimouTemplateMojo.java index 2ec5359..015d2d7 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/trimou/TrimouTemplateMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/trimou/TrimouTemplateMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.trimou; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractTemplateMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import com.hubspot.jinjava.Jinjava; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/util/ContextHelper.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/util/ContextHelper.java index 0899586..19b8554 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/util/ContextHelper.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/util/ContextHelper.java @@ -1,8 +1,8 @@ package com.github.terefang.template_maven_plugin.util; -import com.github.terefang.imageutil.PdfImage; -import com.github.terefang.imageutil.PixelImage; -import com.github.terefang.imageutil.SvgImage; +import com.github.terefang.jmelange.image.PdfImage; +import com.github.terefang.jmelange.image.PixelImage; +import com.github.terefang.jmelange.image.SvgImage; import com.github.terefang.jdao.JDAO; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.SneakyThrows; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/util/ContextUtil.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/util/ContextUtil.java index 7801e9c..ef188de 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/util/ContextUtil.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/util/ContextUtil.java @@ -1,10 +1,12 @@ package com.github.terefang.template_maven_plugin.util; -import com.github.terefang.imageutil.PdfImage; -import com.github.terefang.imageutil.PixelImage; -import com.github.terefang.imageutil.SvgImage; +import com.github.terefang.jmelange.image.PdfImage; +import com.github.terefang.jmelange.image.PixelImage; +import com.github.terefang.jmelange.image.SvgImage; import com.github.terefang.jdao.JDAO; import com.github.terefang.jdao.JdaoUtils; +import com.github.terefang.jmelange.pdata.PdataParser; +import com.github.terefang.jmelange.pdata.PdataWriter; import com.github.terefang.template_maven_plugin.luaj.LuaScriptContext; import com.moandjiezana.toml.Toml; import lombok.SneakyThrows; @@ -422,7 +424,7 @@ public static List> readFileCsv(String _infmt, InputStream _ @SneakyThrows public static Map loadContextFromPdx(InputStream _source) { - return PdxParser.loadFrom(new InputStreamReader(_source)); + return PdataParser.loadFrom(new InputStreamReader(_source)); } @SneakyThrows @@ -503,7 +505,7 @@ public static String toJson(Map _res) @SneakyThrows public static void writeAsPdata(Writer _out, Map _res) { - PdxWriter.writeTo(_res,_out); + PdataWriter.writeTo(_res,_out); } public static String toPdata(Map _res) @@ -2006,18 +2008,20 @@ public static boolean checkBoolean(final Object _str) return checkBoolean(_str.toString()); } - public static boolean checkBoolean(final String _str) + static final String [] _btests = {"false", "f", "off", "none", "no", "n", "null", "nul", "nil", "0"}; + public static boolean checkBoolean(String _str) { if (_str == null) { return false; } + _str = _str.trim().toLowerCase(); // any defined string is "true" unless it is a false indicator: // false, off, none, no, null, nul, nil, 0 - if (containsAny(_str.trim().toLowerCase(), - "false", "off", "none", "no", "null", "nul", "nil", "0")) + for(String _test : _btests) { - return false; + if(_test.equalsIgnoreCase(_str)) + return false; } return true; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/util/CustomStreamTokenizer.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/util/CustomStreamTokenizer.java deleted file mode 100644 index 3c26432..0000000 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/util/CustomStreamTokenizer.java +++ /dev/null @@ -1,857 +0,0 @@ -package com.github.terefang.template_maven_plugin.util; - -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Original Code from github.com/apache/harmony/.../StreamTokenizer.java - * - * changes Copyright (c) 2021. terefang@gmail.com - * - */ - -import java.io.EOFException; -import java.io.IOException; -import java.io.Reader; - -/** - * Parses a stream into a set of defined tokens, one at a time. The different - * types of tokens that can be found are numbers, identifiers, quoted strings, - * and different comment styles. The class can be used for limited processing - * of source code of programming languages like Java, although it is nowhere - * near a full parser. - */ -public class CustomStreamTokenizer { - /** - * Contains a number if the current token is a number ({@code ttype} == - * {@code TOKEN_TYPE_NUMBER}). - */ - public double numValue; - - /** - * Contains a string if the current token is a word ({@code ttype} == - * {@code TOKEN_TYPE_WORD}). - */ - public String stringValue; - - /** - * Contains a cadinal if the current token is a number ({@code ttype} == - * {@code TOKEN_TYPE_CADINAL}). - */ - public long cardinalValue; - /** - * The constant representing the end of the stream. - */ - public static final int TOKEN_TYPE_EOF = -1; - - /** - * The constant representing the end of the line. - */ - public static final int TOKEN_TYPE_EOL = '\n'; - - /** - * The constant representing a number token. - */ - public static final int TOKEN_TYPE_NUMBER = -2; - - /** - * The constant representing a word token. - */ - public static final int TOKEN_TYPE_WORD = -3; - - /** - * The constant representing a cardinal/integer token. - */ - public static final int TOKEN_TYPE_CARDINAL = -4; - - /** - * Internal representation of unknown state. - */ - private static final int TOKEN_TYPE_UNKNOWN = -5; - - /** - * After calling {@code nextToken()}, {@code ttype} contains the type of - * token that has been read. When a single character is read, its value - * converted to an integer is stored in {@code ttype}. For a quoted string, - * the value is the quoted character. Otherwise, its value is one of the - * following: - *
    - *
  • {@code TOKEN_TYPE_WORD} - the token is a word.
  • - *
  • {@code TOKEN_TYPE_NUMBER} - the token is a number.
  • - *
  • {@code TOKEN_TYPE_CARDINAL} - the token is a cardinal.
  • - *
  • {@code TOKEN_TYPE_EOL} - the end of line has been reached. Depends on - * whether {@code eolIsSignificant} is {@code true}.
  • - *
  • {@code TOKEN_TYPE_EOF} - the end of the stream has been reached.
  • - *
- */ - public int ttype = TOKEN_TYPE_UNKNOWN; - - /** - * Internal character meanings, 0 implies TOKEN_ORDINARY - */ - private byte tokenTypes[] = new byte[256]; - - private static final byte TOKEN_COMMENT = 1; - - private static final byte TOKEN_QUOTE = 2; - - private static final byte TOKEN_WHITE = 4; - - private static final byte TOKEN_WORD = 8; - - private static final byte TOKEN_DIGIT = 16; - - private int lineNumber = 1; - - private boolean forceLowercase; - - private boolean isEOLSignificant; - - private boolean slashStarComments; - - private boolean slashSlashComments; - - private boolean tripleQuotes; - - private boolean hexLiterals; - - private boolean pushBackToken; - - private boolean lastCr; - - private Reader inReader; - - private int peekChar = -2; - - /** - * Private constructor to initialize the default values according to the - * specification. - */ - private CustomStreamTokenizer() { - /* - * Initialize the default state per specification. All byte values 'A' - * through 'Z', 'a' through 'z', and '\u00A0' through '\u00FF' are - * considered to be alphabetic. - */ - wordChars('A', 'Z'); - wordChars('a', 'z'); - wordChars(160, 255); - /** - * All byte values '\u0000' through '\u0020' are considered to be white - * space. - */ - whitespaceChars(0, 32); - /** - * '/' is a comment character. Single quote '\'' and double quote '"' - * are string quote characters. - */ - commentChar('/'); - quoteChar('"'); - quoteChar('\''); - /** - * Numbers are parsed. - */ - parseNumbers(); - /** - * Ends of lines are treated as white space, not as separate tokens. - * C-style and C++-style comments are not recognized. These are the - * defaults and are not needed in constructor. - */ - } - - /** - * Constructs a new {@code CustomStreamTokenizer} with {@code r} as source reader. - * The tokenizer's initial state is as follows: - *
    - *
  • All byte values 'A' through 'Z', 'a' through 'z', and '\u00A0' - * through '\u00FF' are considered to be alphabetic.
  • - *
  • All byte values '\u0000' through '\u0020' are considered to - * be white space. '/' is a comment character.
  • - *
  • Single quote '\'' and double quote '"' are string quote characters. - *
  • - *
  • Numbers are parsed.
  • - *
  • End of lines are considered to be white space rather than separate - * tokens.
  • - *
  • C-style and C++-style comments are not recognized.
  • - *
- * - * @param r - * the source reader from which to parse tokens. - */ - public CustomStreamTokenizer(Reader r) { - this(); - if (r == null) { - throw new NullPointerException(); - } - inReader = r; - } - - /** - * Specifies that the character {@code ch} shall be treated as a comment - * character. - * - * @param ch - * the character to be considered a comment character. - */ - public void commentChar(int ch) { - if (0 <= ch && ch < tokenTypes.length) { - tokenTypes[ch] = TOKEN_COMMENT; - } - } - - /** - * Specifies whether the end of a line is significant and should be returned - * as {@code TOKEN_TYPE_EOF} in {@code ttype} by this tokenizer. - * - * @param flag - * {@code true} if EOL is significant, {@code false} otherwise. - */ - public void eolIsSignificant(boolean flag) { - isEOLSignificant = flag; - } - - /** - * Returns the current line number. - * - * @return this tokenizer's current line number. - */ - public int lineno() { - return lineNumber; - } - - /** - * Specifies whether word tokens should be converted to lower case when they - * are stored in {@code sval}. - * - * @param flag - * {@code true} if {@code sval} should be converted to lower - * case, {@code false} otherwise. - */ - public void lowerCaseMode(boolean flag) { - forceLowercase = flag; - } - - /* get tokens as specific value */ - - public String tokenAsString() { return this.stringValue; } - public long tokenAsCardinal() { return this.cardinalValue; } - public double tokenAsNumber() { return this.numValue; } - - /** - * Parses the next token from this tokenizer's source stream or reader. The - * type of the token is stored in the {@code ttype} field, additional - * information may be stored in the {@code nval} or {@code sval} fields. - * - * @return the value of {@code ttype}. - * @throws IOException - * if an I/O error occurs while parsing the next token. - */ - public static final String HEX_SET = "0123456789abcdefABCDEF"; - public int nextToken() throws IOException { - if (pushBackToken) { - pushBackToken = false; - if (ttype != TOKEN_TYPE_UNKNOWN) { - return ttype; - } - } - stringValue = null; // Always reset sval to null - int currentChar = peekChar == -2 ? read() : peekChar; - - if (lastCr && currentChar == '\n') { - lastCr = false; - currentChar = read(); - } - if (currentChar == -1) { - return (ttype = TOKEN_TYPE_EOF); - } - - byte currentType = currentChar > 255 ? TOKEN_WORD - : tokenTypes[currentChar]; - while ((currentType & TOKEN_WHITE) != 0) { - /** - * Skip over white space until we hit a new line or a real token - */ - if (currentChar == '\r') { - lineNumber++; - if (isEOLSignificant) { - lastCr = true; - peekChar = -2; - return (ttype = TOKEN_TYPE_EOL); - } - if ((currentChar = read()) == '\n') { - currentChar = read(); - } - } else if (currentChar == '\n') { - lineNumber++; - if (isEOLSignificant) { - peekChar = -2; - return (ttype = TOKEN_TYPE_EOL); - } - currentChar = read(); - } else { - // Advance over this white space character and try again. - currentChar = read(); - } - if (currentChar == -1) { - return (ttype = TOKEN_TYPE_EOF); - } - currentType = currentChar > 255 ? TOKEN_WORD - : tokenTypes[currentChar]; - } - - /** - * Check for digits before checking for words since digits can be - * contained within words. - */ - if ((currentType & TOKEN_DIGIT) != 0) { - StringBuilder digits = new StringBuilder(20); - boolean haveDecimal = false, checkJustNegative = currentChar == '-', isHex = false, isBinary = false; - while (true) { - if(hexLiterals && (digits.length() == 0) && (currentChar == '0')) - { - // should we detect hex-literals starting with '0x' and switch parsing ? - // actually we can discard the zero here - currentChar = read(); - if(currentChar == 'x') - { - isHex = true; - currentChar = read(); - if (!(HEX_SET.indexOf(currentChar)>=0)) { - break; - } - } - else - if(currentChar == 'b') - { - isBinary = true; - currentChar = read(); - if ((currentChar < '0') || (currentChar > '1')) { - break; - } - } - else - // alternative would be to have a float-literal starting with '0.'. - if (currentChar == '.') - { - haveDecimal = true; - } - else - if ((currentChar < '0') || (currentChar > '9')) - { - digits.append("0"); - break; - } - } - - if(isBinary) - { - if(currentChar != '_') digits.append((char) currentChar); - currentChar = read(); - if (((currentChar < '0') || (currentChar > '1')) - && (currentChar != '_')) { - break; - } - } - else - if(isHex) - { - if(currentChar != '_') digits.append((char) currentChar); - currentChar = read(); - if ((!(HEX_SET.indexOf(currentChar)>=0)) - && (currentChar != '_')) { - break; - } - } - else - { - if (currentChar == '.') { - haveDecimal = true; - } - if(currentChar != '_') digits.append((char) currentChar); - currentChar = read(); - if ((currentChar < '0' || currentChar > '9') - && (haveDecimal || currentChar != '.') && (currentChar != '_')) { - break; - } - } - } - peekChar = currentChar; - if (checkJustNegative && digits.length() == 1) { - // Didn't get any other digits other than '-' - return (ttype = '-'); - } - try { - if(isHex) - { - cardinalValue = Long.valueOf(digits.toString(), 16).longValue(); - } - else - if(isBinary) - { - cardinalValue = Long.valueOf(digits.toString(), 2).longValue(); - } - else - if(haveDecimal) - { - numValue = Double.valueOf(digits.toString()).doubleValue(); - } - else - { - cardinalValue = Long.valueOf(digits.toString()).longValue(); - } - } catch (NumberFormatException e) { - // Unsure what to do, will write test. - numValue = 0; - } - return (ttype = (haveDecimal ? TOKEN_TYPE_NUMBER : TOKEN_TYPE_CARDINAL)); - } - // Check for words - if ((currentType & TOKEN_WORD) != 0) { - StringBuilder word = new StringBuilder(20); - while (true) { - word.append((char) currentChar); - currentChar = read(); - if (currentChar == -1 - || (currentChar < 256 && (tokenTypes[currentChar] & (TOKEN_WORD | TOKEN_DIGIT)) == 0)) { - break; - } - } - peekChar = currentChar; - stringValue = forceLowercase ? word.toString().toLowerCase() : word - .toString(); - return (ttype = TOKEN_TYPE_WORD); - } - // Check for quoted character - if (currentType == TOKEN_QUOTE) { - int matchQuote = currentChar; - StringBuilder quoteString = new StringBuilder(); - int peekOne = read(); - while (peekOne >= 0 && peekOne != matchQuote && peekOne != '\r' - && peekOne != '\n') { - boolean readPeek = true; - if (peekOne == '\\') { - int c1 = read(); - // Check for quoted octal IE: \377 - if (c1 <= '7' && c1 >= '0') { - int digitValue = c1 - '0'; - c1 = read(); - if (c1 > '7' || c1 < '0') { - readPeek = false; - } else { - digitValue = digitValue * 8 + (c1 - '0'); - c1 = read(); - // limit the digit value to a byte - if (digitValue > 037 || c1 > '7' || c1 < '0') { - readPeek = false; - } else { - digitValue = digitValue * 8 + (c1 - '0'); - } - } - if (!readPeek) { - // We've consumed one to many - quoteString.append((char) digitValue); - peekOne = c1; - } else { - peekOne = digitValue; - } - } else { - switch (c1) { - case 'a': - peekOne = 0x7; - break; - case 'b': - peekOne = 0x8; - break; - case 'f': - peekOne = 0xc; - break; - case 'n': - peekOne = 0xA; - break; - case 'r': - peekOne = 0xD; - break; - case 't': - peekOne = 0x9; - break; - case 'v': - peekOne = 0xB; - break; - default: - peekOne = c1; - } - } - } - if (readPeek) { - quoteString.append((char) peekOne); - peekOne = read(); - } - } - - if (peekOne == matchQuote) { - peekOne = read(); - if(tripleQuotes && (quoteString.length() == 0) && (peekOne == matchQuote)) - { - // found start of QQQ - // should we parse it or return error? - peekOne = readTripleQuoted(matchQuote,quoteString); - } - } - peekChar = peekOne; - ttype = matchQuote; - stringValue = quoteString.toString(); - return ttype; - } - - // Do comments, both "//" and "/*stuff*/" - if (currentChar == '/' && (slashSlashComments || slashStarComments)) { - if ((currentChar = read()) == '*' && slashStarComments) { - int peekOne = read(); - while (true) { - currentChar = peekOne; - peekOne = read(); - if (currentChar == -1) { - peekChar = -1; - return (ttype = TOKEN_TYPE_EOF); - } - if (currentChar == '\r') { - if (peekOne == '\n') { - peekOne = read(); - } - lineNumber++; - } else if (currentChar == '\n') { - lineNumber++; - } else if (currentChar == '*' && peekOne == '/') { - peekChar = read(); - return nextToken(); - } - } - } else if (currentChar == '/' && slashSlashComments) { - // Skip to EOF or new line then return the next token - while ((currentChar = read()) >= 0 && currentChar != '\r' - && currentChar != '\n') { - // Intentionally empty - } - peekChar = currentChar; - return nextToken(); - } else if (currentType != TOKEN_COMMENT) { - // Was just a slash by itself - peekChar = currentChar; - return (ttype = '/'); - } - } - // Check for comment character - if (currentType == TOKEN_COMMENT) { - // Skip to EOF or new line then return the next token - while ((currentChar = read()) >= 0 && currentChar != '\r' - && currentChar != '\n') { - // Intentionally empty - } - peekChar = currentChar; - return nextToken(); - } - - peekChar = read(); - return (ttype = currentChar); - } - - private int readTripleQuoted(int matchQuote, StringBuilder quoteString) throws IOException - { - int _c1,_c2,_c3,_c4; - String _qqq = new String(new char[] {(char) matchQuote, (char) matchQuote, (char) matchQuote}); - while(!quoteString.toString().endsWith(_qqq)) - { - int _c = read(); - if(_c == '\n') lineNumber++; - if(_c<0) throw new EOFException(); - if(_c == '\\') - { - _c = read(); - switch (_c) { - case 'a': - _c = 0x7; - break; - case 'b': - _c = 0x8; - break; - case 'f': - _c = 0xc; - break; - case 'n': - _c = 0xA; - break; - case 'r': - _c = 0xD; - break; - case 't': - _c = 0x9; - break; - case 'v': - _c = 0xB; - break; - case 'x': - _c1 = read(); - _c2 = read(); - _c = Integer.parseInt(new String(new char[]{(char) _c1, (char) _c2}), 16); - break; - case 'u': - _c1 = read(); - _c2 = read(); - _c3 = read(); - _c4 = read(); - _c = Integer.parseInt(new String(new char[]{(char) _c1, (char) _c2, (char) _c3, (char) _c4}), 16); - break; - default: - // IGNORE - } - } - quoteString.append((char) _c); - } - quoteString.setLength(quoteString.length()-3); - // text blocks remove all the incidental indentations and keep only essential indentations. - int _i=0; - String [] _parts = quoteString.toString().split("\\n"); - // eat whitespaced lines - while((_i<_parts.length) && _parts[_i].trim().length()==0) _i++; - int _j=0; - // find incidential whitespace - while((_j<_parts[_i].length()) && Character.isWhitespace(_parts[_i].charAt(_j))) _j++; - quoteString.setLength(0); - for(int _k=_i; _k<_parts.length; _k++) - { - int _l = 0; - // eat incidential whitespace - while((_l<_j) && (_l<_parts[_k].length()) && Character.isWhitespace(_parts[_k].charAt(_l))) _l++; - quoteString.append(_parts[_k].substring(_l)); - if(_k!=_parts.length-1) quoteString.append("\n"); - } - return -2; - } - - /** - * Specifies that the character {@code ch} shall be treated as an ordinary - * character by this tokenizer. That is, it has no special meaning as a - * comment character, word component, white space, string delimiter or - * number. - * - * @param ch - * the character to be considered an ordinary character. - */ - public void ordinaryChar(int ch) { - if (0 <= ch && ch < tokenTypes.length) { - tokenTypes[ch] = 0; - } - } - - /** - * Specifies that the characters in the range from {@code low} to {@code hi} - * shall be treated as an ordinary character by this tokenizer. That is, - * they have no special meaning as a comment character, word component, - * white space, string delimiter or number. - * - * @param low - * the first character in the range of ordinary characters. - * @param hi - * the last character in the range of ordinary characters. - */ - public void ordinaryChars(int low, int hi) { - if (low < 0) { - low = 0; - } - if (hi > tokenTypes.length) { - hi = tokenTypes.length - 1; - } - for (int i = low; i <= hi; i++) { - tokenTypes[i] = 0; - } - } - - /** - * Specifies that this tokenizer shall parse numbers. - */ - public void parseNumbers() { - for (int i = '0'; i <= '9'; i++) { - tokenTypes[i] |= TOKEN_DIGIT; - } - tokenTypes['.'] |= TOKEN_DIGIT; - tokenTypes['-'] |= TOKEN_DIGIT; - } - - /** - * Indicates that the current token should be pushed back and returned again - * the next time {@code nextToken()} is called. - */ - public void pushBack() { - pushBackToken = true; - } - - /** - * Specifies that the character {@code ch} shall be treated as a quote - * character. - * - * @param ch - * the character to be considered a quote character. - */ - public void quoteChar(int ch) { - if (0 <= ch && ch < tokenTypes.length) { - tokenTypes[ch] = TOKEN_QUOTE; - } - } - - private int read() throws IOException { - return inReader.read(); - } - - /** - * Specifies that all characters shall be treated as ordinary characters. - */ - public void resetSyntax() { - for (int i = 0; i < 256; i++) { - tokenTypes[i] = 0; - } - } - - /** - * Specifies whether "slash-slash" (C++-style) comments shall be recognized. - * This kind of comment ends at the end of the line. - * - * @param flag - * {@code true} if {@code //} should be recognized as the start - * of a comment, {@code false} otherwise. - */ - public void slashSlashComments(boolean flag) { - slashSlashComments = flag; - } - - /** - * Specifies whether "slash-star" (C-style) comments shall be recognized. - * Slash-star comments cannot be nested and end when a star-slash - * combination is found. - * - * @param flag - * {@code true} if {@code /*} should be recognized as the start - * of a comment, {@code false} otherwise. - */ - public void slashStarComments(boolean flag) { - slashStarComments = flag; - } - - public void tripleQuotes(boolean flag) { - tripleQuotes = flag; - } - - public void hexLiterals(boolean flag) { hexLiterals = flag; } - - /** - * Returns the state of this tokenizer in a readable format. - * - * @return the current state of this tokenizer. - */ - @Override - public String toString() { - // Values determined through experimentation - StringBuilder result = new StringBuilder(); - result.append("Token["); //$NON-NLS-1$ - switch (ttype) { - case TOKEN_TYPE_EOF: - result.append("EOF"); //$NON-NLS-1$ - break; - case TOKEN_TYPE_EOL: - result.append("EOL"); //$NON-NLS-1$ - break; - case TOKEN_TYPE_NUMBER: - result.append("n="); //$NON-NLS-1$ - result.append(numValue); - break; - case TOKEN_TYPE_WORD: - result.append(stringValue); - break; - default: - if (ttype == TOKEN_TYPE_UNKNOWN || tokenTypes[ttype] == TOKEN_QUOTE) { - result.append(stringValue); - } else { - result.append('\''); - result.append((char) ttype); - result.append('\''); - } - } - result.append("], line "); //$NON-NLS-1$ - result.append(lineNumber); - return result.toString(); - } - - /** - * Specifies that the characters in the range from {@code low} to {@code hi} - * shall be treated as whitespace characters by this tokenizer. - * - * @param low - * the first character in the range of whitespace characters. - * @param hi - * the last character in the range of whitespace characters. - */ - public void whitespaceChars(int low, int hi) { - if (low < 0) { - low = 0; - } - if (hi > tokenTypes.length) { - hi = tokenTypes.length - 1; - } - for (int i = low; i <= hi; i++) { - tokenTypes[i] = TOKEN_WHITE; - } - } - - /** - * Specifies that the characters in the range from {@code low} to {@code hi} - * shall be treated as word characters by this tokenizer. A word consists of - * a word character followed by zero or more word or number characters. - * - * @param low - * the first character in the range of word characters. - * @param hi - * the last character in the range of word characters. - */ - public void wordChars(int low, int hi) { - if (low < 0) { - low = 0; - } - if (hi > tokenTypes.length) { - hi = tokenTypes.length - 1; - } - for (int i = low; i <= hi; i++) { - tokenTypes[i] |= TOKEN_WORD; - } - } - - public void wordChar(int low) { - if (low < 0) { - low = 0; - } - if (low > tokenTypes.length) { - low = tokenTypes.length - 1; - } - tokenTypes[low] |= TOKEN_WORD; - } - - public void wordChar(int... _chars) { - for(int _c : _chars) - { - this.wordChar(_c); - } - } - -} \ No newline at end of file diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/util/PdxParser.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/util/PdxParser.java deleted file mode 100644 index 8e23e94..0000000 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/util/PdxParser.java +++ /dev/null @@ -1,282 +0,0 @@ -package com.github.terefang.template_maven_plugin.util; - -import lombok.SneakyThrows; -import org.apache.commons.collections4.map.MultiValueMap; -import org.codehaus.plexus.util.IOUtil; - -import java.io.File; -import java.io.FileReader; -import java.io.Reader; -import java.util.*; - -public class PdxParser { - - @SneakyThrows - public static Map loadFrom(File _file) - { - FileReader _fh = new FileReader(_file); - try { - return loadFrom(_fh); - } - finally { - IOUtil.close(_fh); - } - } - - @SneakyThrows - public static Map loadFrom(Reader _file) - { - CustomStreamTokenizer _tokener = new CustomStreamTokenizer(_file); - - _tokener.quoteChar('"'); - _tokener.tripleQuotes(true); - _tokener.slashSlashComments(true); - _tokener.slashStarComments(true); - _tokener.commentChar('#'); - _tokener.whitespaceChars(0, 32); - _tokener.wordChar('_', ':', '@', '\''); - _tokener.hexLiterals(true); - - int _token = _tokener.nextToken(); - // check for unicode marker ! - if(_token==CustomStreamTokenizer.TOKEN_TYPE_WORD && _tokener.tokenAsString().charAt(0)==0xfeff) - { - //ignore - } - else - { - _tokener.pushBack(); - } - - return readKeyValuePairs(_tokener); - } - - @SneakyThrows - static Map readKeyValuePairs(CustomStreamTokenizer _tokener) - { - return readKeyValuePairs(_tokener, null, false); - } - - @SneakyThrows - static Map readKeyValuePairs(CustomStreamTokenizer _tokener, String _first, boolean _check) - { - Map _keyi = new HashMap<>(); - Map _ret = new LinkedHashMap<>(); - MultiValueMap _dups = new MultiValueMap(); - - if(_first!=null) - { - _ret.put(_first, readValue(_tokener, _check)); - } - else if(_check) - { - int _assign = _tokener.nextToken(); - if(_assign!='=') throw new IllegalArgumentException(String.format("Token not '=' in line %d", _tokener.lineno())); - } - - int _token; - while((_token = _tokener.nextToken()) != CustomStreamTokenizer.TOKEN_TYPE_EOF) - { - //System.out.println(String.format("T=%s n=%f t=%d s=%s", tokenToString(_token), _tokener.nval, _tokener.ttype, _tokener.sval)); - String _key = null; - Object _val; - if(_token == '}') - { - break; - } - else - { - if(_token == CustomStreamTokenizer.TOKEN_TYPE_WORD || _token == '"') - { - _key = _tokener.tokenAsString(); - } - else - if(_token == CustomStreamTokenizer.TOKEN_TYPE_NUMBER) - { - _key = Long.toString((long) _tokener.tokenAsNumber()); - } - else - if(_token == CustomStreamTokenizer.TOKEN_TYPE_CARDINAL) - { - _key = Long.toString(_tokener.tokenAsCardinal()); - } - - if(_key!=null) - { - _val = readValue(_tokener, true); - - //System.out.println("K: "+_key); - //System.out.println("V: "+_val); - - if(_ret.containsKey(_key)) - { - int _i = 1; - if(!_keyi.containsKey(_key)) - { - _keyi.put(_key,_i); - _dups.put(_key, _key); - } - else - { - _i = _keyi.get(_key)+1; - _keyi.put(_key,_i); - } - _dups.put(_key, _key+"+"+_i); - //_ret.put("___dup_keys___", _dups); - _key+="+"+_i; - } - _ret.put(_key, _val); - } - else - { - throw new IllegalArgumentException(String.format("Illegal Key in line %d", _tokener.lineno())); - } - } - } - - if(_dups.size()>0) - { - for(String _base : _dups.keySet()) - { - List _l = new Vector(); - for(String _key : _dups.getCollection(_base)) - { - _l.add(_ret.get(_key)); - _ret.remove(_key); - } - _ret.put(_base, _l); - } - } - - return _ret; - } - - @SneakyThrows - static Object readValue(CustomStreamTokenizer _tokener, boolean _check) - { - //System.err.println("-value-"); - if(_check) - { - int _assign = _tokener.nextToken(); - if(_assign!='=') throw new IllegalArgumentException(String.format("Token not '=' in line %d", _tokener.lineno())); - } - int _peek = _tokener.nextToken(); - Object _ret = null; - switch(_peek) - { - case '"': - case CustomStreamTokenizer.TOKEN_TYPE_WORD: return _tokener.tokenAsString(); - case CustomStreamTokenizer.TOKEN_TYPE_CARDINAL: return _tokener.tokenAsCardinal(); - case CustomStreamTokenizer.TOKEN_TYPE_NUMBER: return _tokener.tokenAsNumber(); - case '[': _tokener.pushBack(); return readList(_tokener, null); - case '{': _tokener.pushBack(); return readObjectOrList(_tokener); - } - return _ret; - } - - @SneakyThrows - static List readList(CustomStreamTokenizer _tokener, Object _first) - { - List _ret = new Vector(); - - if(_first==null) - { - int _assign = _tokener.nextToken(); - if(_assign!='[' && _assign!='{') throw new IllegalArgumentException(String.format("Token not '[' or '{' in line %d", _tokener.lineno())); - } - else - { - _ret.add(_first); - } - - int _token; - while((_token = _tokener.nextToken()) != CustomStreamTokenizer.TOKEN_TYPE_EOF) - { - switch (_token) - { - case ']': - case '}': return _ret; - case '[': _tokener.pushBack(); _ret.add(readList(_tokener, null)); break; - case '{': _tokener.pushBack(); _ret.add(readObjectOrList(_tokener)); break; - case '"': - case CustomStreamTokenizer.TOKEN_TYPE_WORD: _ret.add(_tokener.tokenAsString()); break; - case CustomStreamTokenizer.TOKEN_TYPE_CARDINAL: _ret.add(_tokener.tokenAsCardinal()); break; - case CustomStreamTokenizer.TOKEN_TYPE_NUMBER: _ret.add(_tokener.tokenAsNumber()); break; - default: _ret.add(Character.toString((char) _token)); break; - } - } - return _ret; - } - - @SneakyThrows - static Object readObjectOrList(CustomStreamTokenizer _tokener) - { - int _assign = _tokener.nextToken(); - if(_assign!='{') throw new IllegalArgumentException(String.format("Token not '{' in line %d", _tokener.lineno())); - - int _token; - // we need to peek 2 tokens worth deep - _token = _tokener.nextToken(); - if(_token=='}') return null; - if(_token==']') return null; - - // case '[' -> list - // case '{' -> list - if(_token=='{' || _token=='[') - { - _tokener.pushBack(); - Object _first = readValue(_tokener, false); - return readList(_tokener, _first); - } - - // case WORD/NUM -> switch - // case WORD/NUM WORD/NUM -> list - // case WORD/NUM '=' -> kv - if(_token=='"' - || _token == CustomStreamTokenizer.TOKEN_TYPE_WORD - || _token == CustomStreamTokenizer.TOKEN_TYPE_NUMBER - || _token == CustomStreamTokenizer.TOKEN_TYPE_CARDINAL) - { - String _first = _tokener.tokenAsString(); - boolean _first_is_number=false; - boolean _first_is_cadinal=false; - if(_token == CustomStreamTokenizer.TOKEN_TYPE_NUMBER) - { - _first = ""+_tokener.tokenAsNumber(); - _first_is_number = true; - } - else - if(_token == CustomStreamTokenizer.TOKEN_TYPE_CARDINAL) - { - _first = ""+_tokener.tokenAsCardinal(); - _first_is_cadinal = true; - } - _token = _tokener.nextToken(); - _tokener.pushBack(); - if(_token == '=') - { - if(_first_is_number) - { - _first=Long.toString((long)Double.parseDouble(_first)); - } - return readKeyValuePairs(_tokener, _first, true); - } - else - { - if(_first_is_cadinal) - { - return readList(_tokener, Long.parseLong(_first)); - } - else - if(_first_is_number) - { - return readList(_tokener, Double.parseDouble(_first)); - } - return readList(_tokener, _first); - } - } - - throw new IllegalArgumentException(String.format("Illegal Token in line %d", _tokener.lineno())); - } - -} diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/util/PdxWriter.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/util/PdxWriter.java deleted file mode 100644 index e45c995..0000000 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/util/PdxWriter.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.github.terefang.template_maven_plugin.util; - -import lombok.SneakyThrows; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.StringUtils; - - -import java.io.File; -import java.io.FileWriter; -import java.io.Writer; -import java.text.MessageFormat; -import java.util.*; - -public class PdxWriter -{ - public static void writeTo(Map _data, Writer _out) - { - writeTo(0, _data, _out); - } - - @SneakyThrows - public static void writeTo(int _level, Map _data, Writer _out) - { - if(_level>0) - { - _out.write("\n"+StringUtils.repeat(" ", _level)+"{"); - } - - List _keys = new Vector(_data.keySet()); - _keys.sort((x,y)->x.compareToIgnoreCase(y)); - - for(String _key : _keys) - { - _out.write(MessageFormat.format("\n{0}\"{1}\" = ", StringUtils.repeat(" ", (_level==0 ? 0 : _level+1)), _key)); - writeTo(_level+2, _data.get(_key), _out); - } - - if(_level>0) - { - _out.write("\n"+StringUtils.repeat(" ", _level)+"}"); - } - _out.flush(); - } - - @SneakyThrows - public static void writeTo(int _level, Object _data, Writer _out) - { - if(_data == null) - { - _out.write("null\n"); - } - else - if(_data instanceof Map) - { - writeTo(_level, (Map)_data, _out); - } - else - if(_data instanceof List) - { - writeTo(_level, (List)_data, _out); - } - else - if(_data instanceof String) - { - writeTo(_level, (String)_data, _out); - } - else - if(_data instanceof Integer) - { - writeTo(_level, (Integer)_data, _out); - } - else - if(_data instanceof Long) - { - writeTo(_level, (Long)_data, _out); - } - else - if(_data instanceof Boolean) - { - writeTo(_level, (Boolean)_data, _out); - } - else - if(_data instanceof Double) - { - writeTo(_level, (Double)_data, _out); - } - else - if(_data instanceof Float) - { - writeTo(_level, (Float)_data, _out); - } - else - if(_data.getClass().isArray()) - { - writeTo(_level, (List) Arrays.asList((Object[])_data), _out); - } - else - { - writeTo(_level, _data.toString(), _out); - } - } - - @SneakyThrows - public static void writeTo(int _level, List _data, Writer _out) - { - _out.write(" [ "); - for(Object _o : _data) - { - writeTo(_level+1, _o, _out); - } - _out.write(" ] "); - _out.flush(); - } - - @SneakyThrows - public static void writeTo(int _level, Integer _data, Writer _out) - { - _out.write(" "+(_data)+" "); - } - - @SneakyThrows - public static void writeTo(int _level, Long _data, Writer _out) - { - _out.write(" "+(_data)+" "); - } - - @SneakyThrows - public static void writeTo(int _level, Boolean _data, Writer _out) - { - _out.write(_data ? " true " : " false "); - } - - @SneakyThrows - public static void writeTo(int _level, Double _data, Writer _out) - { - _out.write(String.format(" %.9f ", _data.doubleValue())); - } - - @SneakyThrows - public static void writeTo(int _level, Float _data, Writer _out) - { - _out.write(String.format(" %.6f ", _data.floatValue())); - } - - @SneakyThrows - public static void writeTo(int _level, String _data, Writer _out) - { - if(_data.indexOf('\n')>=0 || _data.indexOf('\r')>=0 || _data.indexOf('\t')>=0 || _data.indexOf('"')>=0) - { - _out.write("\n\"\"\""); - _out.write(_data); - _out.write("\"\"\" "); - } - else - { - _out.write(String.format(" \"%s\" ", _data)); - } - _out.flush(); - } - - @SneakyThrows - public static void writeTo(Map _data, File _file) - { - FileWriter _out = new FileWriter(_file); - writeTo(_data, _out); - _out.flush(); - IOUtil.close(_out); - } -} diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/velocity/VelocityStandardMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/velocity/VelocityStandardMojo.java index 044fe0e..ae2f32b 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/velocity/VelocityStandardMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/velocity/VelocityStandardMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.velocity; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractStandardMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.SneakyThrows; diff --git a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/velocity/VelocityTemplateMojo.java b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/velocity/VelocityTemplateMojo.java index f371426..fd956f2 100644 --- a/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/velocity/VelocityTemplateMojo.java +++ b/template-maven-plugin/src/main/java/com/github/terefang/template_maven_plugin/velocity/VelocityTemplateMojo.java @@ -1,6 +1,6 @@ package com.github.terefang.template_maven_plugin.velocity; -import com.github.terefang.imageutil.GfxInterface; +import com.github.terefang.jmelange.image.GfxInterface; import com.github.terefang.template_maven_plugin.AbstractTemplateMojo; import com.github.terefang.template_maven_plugin.TemplateContext; import lombok.SneakyThrows; diff --git a/template-maven-plugin/template-maven-plugin.iml b/template-maven-plugin/template-maven-plugin.iml index f8ba179..f8c6d2f 100644 --- a/template-maven-plugin/template-maven-plugin.iml +++ b/template-maven-plugin/template-maven-plugin.iml @@ -11,13 +11,21 @@ + + + + + + + + + - @@ -95,9 +103,5 @@ - - - - \ No newline at end of file