Skip to content

Commit 3d4444e

Browse files
authored
Merge pull request #4794 from evolvedbinary/feature/image-module-options
Add an image:scale#2 function that takes advanced options
2 parents 4f1eada + 01faa68 commit 3d4444e

File tree

10 files changed

+1635
-190
lines changed

10 files changed

+1635
-190
lines changed

exist-core/src/main/java/org/exist/xquery/value/JavaObjectValue.java

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,12 @@ public JavaObjectValue(final Object object) {
4141
this(null, object);
4242
}
4343

44-
public JavaObjectValue(final Expression expression, Object object) {
44+
public JavaObjectValue(final Expression expression, final Object object) {
4545
super(expression);
4646
this.object = object;
4747
}
4848

49-
/* (non-Javadoc)
50-
* @see org.exist.xquery.value.AtomicValue#getType()
51-
*/
49+
@Override
5250
public int getType() {
5351
return Type.JAVA_OBJECT;
5452
}
@@ -57,67 +55,56 @@ public Object getObject() {
5755
return object;
5856
}
5957

60-
/* (non-Javadoc)
61-
* @see org.exist.xquery.value.Sequence#getStringValue()
62-
*/
58+
@Override
6359
public String getStringValue() {
6460
return String.valueOf(object);
6561
}
6662

67-
/* (non-Javadoc)
68-
* @see org.exist.xquery.value.Sequence#convertTo(int)
69-
*/
70-
public AtomicValue convertTo(int requiredType) throws XPathException {
63+
@Override
64+
public AtomicValue convertTo(final int requiredType) throws XPathException {
7165
if (requiredType == Type.JAVA_OBJECT) {
7266
return this;
7367
}
7468
throw new XPathException(getExpression(), ErrorCodes.FORG0001,
7569
"cannot convert Java object to " + Type.getTypeName(requiredType));
7670
}
7771

72+
@Override
7873
public boolean effectiveBooleanValue() throws XPathException {
7974
throw new XPathException(getExpression(), "Called effectiveBooleanValue() on JavaObjectValue");
8075
}
8176

8277
@Override
83-
public boolean compareTo(Collator collator, Comparison operator, AtomicValue other) throws XPathException {
84-
throw new XPathException(getExpression(),
78+
public boolean compareTo(final Collator collator, final Comparison operator, final AtomicValue other) throws XPathException {
79+
throw new XPathException(getExpression(),
8580
"cannot compare Java object to " + Type.getTypeName(other.getType()));
8681
}
8782

88-
/* (non-Javadoc)
89-
* @see org.exist.xquery.value.AtomicValue#compareTo(org.exist.xquery.value.AtomicValue)
90-
*/
91-
public int compareTo(Collator collator, AtomicValue other) throws XPathException {
92-
throw new XPathException(getExpression(),
83+
@Override
84+
public int compareTo(final Collator collator, final AtomicValue other) throws XPathException {
85+
throw new XPathException(getExpression(),
9386
"cannot compare Java object to " + Type.getTypeName(other.getType()));
9487
}
9588

96-
/* (non-Javadoc)
97-
* @see org.exist.xquery.value.AtomicValue#max(org.exist.xquery.value.AtomicValue)
98-
*/
99-
public AtomicValue max(Collator collator, AtomicValue other) throws XPathException {
89+
@Override
90+
public AtomicValue max(final Collator collator, final AtomicValue other) throws XPathException {
10091
throw new XPathException(getExpression(), "Invalid argument to aggregate function: cannot compare Java objects");
10192
}
10293

103-
public AtomicValue min(Collator collator, AtomicValue other) throws XPathException {
94+
@Override
95+
public AtomicValue min(final Collator collator, final AtomicValue other) throws XPathException {
10496
throw new XPathException(getExpression(), "Invalid argument to aggregate function: cannot compare Java objects");
10597
}
10698

107-
/* (non-Javadoc)
108-
* @see org.exist.xquery.value.Item#conversionPreference(java.lang.Class)
109-
*/
110-
public int conversionPreference(Class<?> javaClass) {
99+
@Override
100+
public int conversionPreference(final Class<?> javaClass) {
111101
if (javaClass.isAssignableFrom(object.getClass())) {
112102
return 0;
113103
}
114104

115105
return Integer.MAX_VALUE;
116106
}
117107

118-
/* (non-Javadoc)
119-
* @see org.exist.xquery.value.Item#toJavaObject(java.lang.Class)
120-
*/
121108
@Override
122109
public <T> T toJavaObject(final Class<T> target) throws XPathException {
123110
if (target.isAssignableFrom(object.getClass())) {
@@ -128,4 +115,23 @@ public <T> T toJavaObject(final Class<T> target) throws XPathException {
128115

129116
throw new XPathException(getExpression(), "cannot convert value of type " + Type.getTypeName(getType()) + " to Java object of type " + target.getName());
130117
}
118+
119+
@Override
120+
public boolean equals(final Object o) {
121+
if (this == o) {
122+
return true;
123+
}
124+
125+
if (o == null || getClass() != o.getClass()) {
126+
return false;
127+
}
128+
129+
final JavaObjectValue that = (JavaObjectValue) o;
130+
return this.object.equals(that.object);
131+
}
132+
133+
@Override
134+
public int hashCode() {
135+
return this.object.hashCode();
136+
}
131137
}

extensions/modules/image/pom.xml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,59 @@
6262
<artifactId>commons-io</artifactId>
6363
</dependency>
6464

65+
<dependency>
66+
<groupId>com.google.code.findbugs</groupId>
67+
<artifactId>jsr305</artifactId>
68+
</dependency>
69+
70+
<dependency>
71+
<groupId>junit</groupId>
72+
<artifactId>junit</artifactId>
73+
<scope>test</scope>
74+
</dependency>
75+
76+
<dependency>
77+
<groupId>org.exist-db</groupId>
78+
<artifactId>exist-file</artifactId>
79+
<version>${project.version}</version>
80+
<scope>test</scope>
81+
</dependency>
82+
6583
</dependencies>
6684

85+
<build>
86+
<testResources>
87+
<testResource>
88+
<directory>src/test/resources</directory>
89+
<filtering>false</filtering>
90+
</testResource>
91+
<testResource>
92+
<directory>src/test/resources-filtered</directory>
93+
<filtering>true</filtering>
94+
</testResource>
95+
</testResources>
96+
97+
<plugins>
98+
<plugin>
99+
<groupId>org.apache.maven.plugins</groupId>
100+
<artifactId>maven-dependency-plugin</artifactId>
101+
<executions>
102+
<execution>
103+
<id>analyze</id>
104+
<goals>
105+
<goal>analyze-only</goal>
106+
</goals>
107+
<configuration>
108+
<failOnWarning>true</failOnWarning>
109+
<ignoredUnusedDeclaredDependencies>
110+
<!-- needed for running tests that depend on file module -->
111+
<ignoredUnusedDeclaredDependency>org.exist-db:exist-file:jar:${project.version}</ignoredUnusedDeclaredDependency>
112+
</ignoredUnusedDeclaredDependencies>
113+
</configuration>
114+
</execution>
115+
</executions>
116+
</plugin>
117+
</plugins>
118+
</build>
119+
67120
</project>

extensions/modules/image/src/main/java/org/exist/xquery/modules/image/GetThumbnailsFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence)
264264

265265
try {
266266
bImage = ImageModule.createThumb(image, maxThumbHeight,
267-
maxThumbWidth);
267+
maxThumbWidth, null);
268268
} catch (Exception e) {
269269
throw new XPathException(this, e.getMessage());
270270
}

0 commit comments

Comments
 (0)