[fix] Node api changed in basex 9 released

This commit is contained in:
Andy Bunce 2018-06-29 19:16:33 +01:00
parent a6a38601fd
commit 45f06ca4e2
17 changed files with 55 additions and 32 deletions

View File

@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="src" path="src/java"/>
<classpathentry kind="lib" path="src/main/content/thumbnailator-0.4.8.jar"/>
<classpathentry kind="lib" path="lib/BaseX90-20171123.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/BaseX902.jar" sourcepath="/basex-core"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>

View File

@ -1,6 +1,6 @@
<xqdoc:xqdoc xmlns:xqdoc="http://www.xqdoc.org/1.0">
<xqdoc:control>
<xqdoc:date>2017-11-24T23:26:38.524Z</xqdoc:date>
<xqdoc:date>2018-06-29T19:13:26.072+01:00</xqdoc:date>
<xqdoc:version>1.1</xqdoc:version>
</xqdoc:control>
<xqdoc:module type="library">
@ -183,5 +183,12 @@
<xqdoc:type>element(report)</xqdoc:type>
</xqdoc:return>
</xqdoc:function>
<xqdoc:function arity="0">
<xqdoc:name>thumbnails:schema-uri</xqdoc:name>
<xqdoc:signature>declare function thumbnails:schema-uri() as xs:anyURI</xqdoc:signature>
<xqdoc:return>
<xqdoc:type>xs:anyURI</xqdoc:type>
</xqdoc:return>
</xqdoc:function>
</xqdoc:functions>
</xqdoc:xqdoc>

Binary file not shown.

BIN
lib/BaseX902.jar Normal file

Binary file not shown.

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="WINDOWS-1252" standalone="no"?>
<jardesc>
<jar path="ex-thumbnailator/src/main/content/thumbhelper-6.0.0.jar"/>
<jar path="ex-thumbnailator/src/main/content/thumbhelper-7.0.0.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/ex-thumbnailator/makejar.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="true" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/>

View File

@ -58,5 +58,11 @@
<version num="6.0.2">
<!-- generated: {fn:current-dateTime()} -->
</version>
<version num="7.0.0">
<!-- generated: {fn:current-dateTime()} -->
</version>
<version num="7.0.1">
<!-- generated: {fn:current-dateTime()} -->
</version>
</pkg>
</repo>

View File

@ -6,7 +6,7 @@ An XQuery interface to the image thumbnail generator library
Features size, scale, caption, rotate, flip, colorize, watermark. More details at [doc](doc/readme.md)
## Versions
* For Basex 9+ use thumbnailator 6.0.2+
* For Basex 9+ use thumbnailator 7.0.0+
## Usage

View File

@ -14,20 +14,23 @@ import java.util.List;
import javax.imageio.ImageIO;
import org.basex.data.Data;
import org.basex.io.IOContent;
import org.basex.query.QueryException;
import org.basex.query.QueryModule;
//import org.basex.query.func.fn.FnTrace;
import org.basex.query.value.item.B64Lazy;
import org.basex.query.value.item.Dbl;
import org.basex.query.value.item.Int;
import org.basex.query.value.node.ANode;
import org.basex.util.Token;
import org.basex.data.Data;
import net.coobird.thumbnailator.ThumbnailParameter;
import net.coobird.thumbnailator.Thumbnailator;
import net.coobird.thumbnailator.builders.ThumbnailParameterBuilder;
import net.coobird.thumbnailator.filters.Canvas;
import net.coobird.thumbnailator.filters.Caption;
import net.coobird.thumbnailator.filters.Colorize;
import net.coobird.thumbnailator.filters.Flip;
import net.coobird.thumbnailator.filters.ImageFilter;
import net.coobird.thumbnailator.filters.Pipeline;
import net.coobird.thumbnailator.filters.Rotation;
import net.coobird.thumbnailator.filters.Watermark;
@ -36,11 +39,6 @@ import net.coobird.thumbnailator.geometry.Position;
import net.coobird.thumbnailator.geometry.Positions;
import net.coobird.thumbnailator.geometry.Region;
import net.coobird.thumbnailator.tasks.StreamThumbnailTask;
import net.coobird.thumbnailator.filters.Canvas;
import net.coobird.thumbnailator.filters.Caption;
import net.coobird.thumbnailator.filters.Colorize;
import net.coobird.thumbnailator.filters.Flip;
import net.coobird.thumbnailator.filters.ImageFilter;
/*
* BaseX Thumbnailator interface
@ -134,8 +132,8 @@ public class Thumbs extends QueryModule{
void region(final ThumbnailParameterBuilder builder, final ANode node)
throws QueryException {
int width = (int) Int.parse(node.attribute("width"), null);
int height = (int) Int.parse(node.attribute("height"), null);
int width = Utils.attrib(node,"width", 80);
int height = Utils.attrib(node,"height", 80);
Dimension d = new Dimension(width, height);
Position pos = Utils.position(node, "position", Positions.CENTER);
Region r = new Region(pos, new AbsoluteSize(d));
@ -157,8 +155,8 @@ public class Thumbs extends QueryModule{
void size(final ThumbnailParameterBuilder builder, final ANode node)
throws QueryException {
int width = (int) Int.parse(node.attribute("width"), null);
int height = (int) Int.parse(node.attribute("height"), null);
int width = Utils.attrib(node, "width", 80);
int height = Utils.attrib(node, "height", 80);
builder.size(width, height);
}
@ -213,7 +211,7 @@ public class Thumbs extends QueryModule{
throws IOException, QueryException {
ImageFilter filter;
Position pos;
String src = Token.string(node.attribute("src"));
String src = Utils.attrib(node, "src", "");
pos = Utils.position(node, "position", Positions.BOTTOM_RIGHT);
BufferedImage watermarkImg = ImageIO.read(new File(src));
filter = new Watermark(pos, watermarkImg, Utils.attrib(node, "alpha", 0.5f));
@ -222,13 +220,13 @@ public class Thumbs extends QueryModule{
private void rotate(final Pipeline pipeline, final ANode node)
throws QueryException {
double angle = (double) Dbl.parse(node.attribute("angle"), null);
double angle = (double) Utils.attrib(node, "angle", 0);
pipeline.add(Rotation.newRotator(angle));
}
private void flip(final Pipeline pipeline, final ANode node) {
private void flip(final Pipeline pipeline, final ANode node) throws QueryException {
ImageFilter filter;
String axis = Token.string(node.attribute("axis"));
String axis = Utils.attrib(node, "axis", "vertical");
// FnTrace.trace(axis.getBytes(), "FLIP: ".getBytes(), queryContext);
filter = axis.equalsIgnoreCase("vertical") ? Flip.VERTICAL : Flip.HORIZONTAL;
pipeline.add(filter);
@ -247,8 +245,8 @@ public class Thumbs extends QueryModule{
ImageFilter filter;
String color;
Position pos;
int width = (int) Int.parse(node.attribute("width"), null);
int height = (int) Int.parse(node.attribute("height"), null);
int width = Utils.attrib(node, "width", 80);
int height = Utils.attrib(node, "height", 80);
color = Utils.attrib(node, "color", "black");
pos = Utils.position(node, "position", Positions.CENTER);
filter = new Canvas(width, height, pos, false, Utils.stringToColor(color));

View File

@ -2,11 +2,13 @@ package org.expkgzone58.image;
import java.awt.Color;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import org.basex.query.QueryException;
import org.basex.query.value.item.Bln;
import org.basex.query.value.item.Dbl;
import org.basex.query.value.item.Int;
import org.basex.query.value.item.Item;
import org.basex.query.value.node.ANode;
import org.basex.util.Token;
@ -19,31 +21,31 @@ public final class Utils {
// get value from attribute with default
public static String attrib(final ANode element, final String name, final String def)
throws QueryException {
byte[] at = element.attribute(name);
byte[] at = element.attribute(name.getBytes(StandardCharsets.UTF_8));
return (at == null) ? def : Token.string(at);
}
public static float attrib(final ANode element, final String name, final float def)
throws QueryException {
byte[] at = element.attribute(name);
byte[] at = element.attribute(name.getBytes(StandardCharsets.UTF_8));
return (at == null) ? def : (float) Dbl.parse(at, null);
}
public static int attrib(final ANode element, final String name, final int def)
throws QueryException {
byte[] at = element.attribute(name);
return (at == null) ? def : (int) Int.parse(at, null);
byte[] at = element.attribute(name.getBytes(StandardCharsets.UTF_8));
return (at == null) ? def : Token.toInt(at);
}
public static boolean attrib(final ANode element, final String name, final boolean def)
throws QueryException {
byte[] at = element.attribute(name);
return (at == null) ? def : (boolean) Bln.parse(at, null);
byte[] at = element.attribute(name.getBytes(StandardCharsets.UTF_8));
return (boolean) ((at == null) ? def : Bln.parse(at));
}
// e.g. TOP_LEFT
public static Position position(final ANode element, final String name, final Position def) {
byte[] at = element.attribute(name);
byte[] at = element.attribute(name.getBytes(StandardCharsets.UTF_8));
return (at == null) ? def : Positions.valueOf(Token.string(at));
}

View File

@ -1,5 +1,5 @@
<package xmlns="http://www.basex.org/modules/pkg">
<jar>thumbhelper-6.0.0.jar</jar>
<jar>thumbhelper-7.0.0.jar</jar>
<jar>thumbnailator-0.4.8.jar</jar>
<class>org.expkgzone58.image.Thumbs</class>
</package>

Binary file not shown.

View File

@ -84,4 +84,10 @@ declare function thumbnails:validation-report($src)
as element(report)
{
validate:xsd-report($src,"task.xsd")
};
declare function thumbnails:schema-uri()
as xs:anyURI
{
resolve-uri("task.xsd")
};

View File

@ -1,5 +1,5 @@
<package xmlns="http://expath.org/ns/pkg" name="https://github.com/expkg-zone58/ex-thumbnailator"
abbrev="thumbnailator" version="6.0.2" spec="1.0">
abbrev="thumbnailator" version="7.0.1" spec="1.0">
<title>An XQuery interface to thumbnailator the thumbnail generator library.</title>

View File

@ -1,18 +1,22 @@
(:~
:examples of constrain use
: generate 8 files showing all perms of aspect,fit,exif
:)
import module namespace t="expkg-zone58:image.thumbnailator";
declare variable $file-base:=file:parent(static-base-uri());
declare variable $watermark:="C:\Users\andy\git\ex-thumbnailator\src\test\resources\icon.gif";
declare variable $src:=file:resolve-path("resources/A34283.jpg",$file-base);
declare function local:wi($data as xs:base64Binary,$filename as xs:string)
{
file:write-binary(file:resolve-path($filename,$file-base),$data)
};
declare function local:constrain($aspect as xs:boolean,$fit as xs:boolean,$exif as xs:boolean)
{
<constrain aspect="{$aspect}" fit="{$fit}" exif="{$exif}"/>
};
let $s:=function($b){if($b) then ".+" else ".-"}
let $img:= fetch:binary($src)
let $ft:=(false(),true())

View File

@ -29,7 +29,7 @@ declare
};
(:~ make a thumbnail :)
(:~ validate a task :)
declare
%unit:test
function test:validate() {