Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Java 9 and dependency update #79

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
645 changes: 318 additions & 327 deletions pom.xml

Large diffs are not rendered by default.

233 changes: 116 additions & 117 deletions src/main/java/org/ghost4j/AbstractComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,139 +25,138 @@
*/
public abstract class AbstractComponent implements Component {

/**
* Holds available device names of the Ghostscript interperter.
*/
private static final List<String> AVAILABLE_DEVICE_NAMES = new ArrayList<String>();

/**
* Classes of Document supported by the converter.
*/
protected Class<?>[] supportedDocumentClasses;

/**
* Assert a given document instance is supported by the converter
*
* @param document
* @throws DocumentException
* When document is not supported
*/
protected void assertDocumentSupported(Document document)
throws DocumentException {

if (supportedDocumentClasses != null) {

for (Class<?> clazz : supportedDocumentClasses) {
if (clazz.getName().equals(document.getClass().getName())) {
// supported
return;
/**
* Holds available device names of the Ghostscript interperter.
*/
private static final List<String> AVAILABLE_DEVICE_NAMES = new ArrayList<String>();

/**
* Classes of Document supported by the converter.
*/
protected Class<?>[] supportedDocumentClasses;

/**
* Assert a given document instance is supported by the converter
*
* @param document
* @throws DocumentException
* When document is not supported
*/
protected void assertDocumentSupported(Document document)
throws DocumentException {

if (supportedDocumentClasses != null) {

for (Class<?> clazz : supportedDocumentClasses) {
if (clazz.getName().equals(document.getClass().getName())) {
// supported
return;
}
}

// document not supported
throw new DocumentException("Documents of class "
+ document.getClass().getName()
+ " are not supported by the component");
}
}

// document not supported
throw new DocumentException("Documents of class "
+ document.getClass().getName()
+ " are not supported by the component");
}
}

public void copySettings(Map<String, Object> settings)
throws IllegalAccessException, InvocationTargetException {

if (settings.get("maxProcessCount") != null) {
settings.remove("maxProcessCount");
}

BeanUtils.populate(this, settings);
public void copySettings(Map<String, Object> settings)
throws IllegalAccessException, InvocationTargetException {

}

@SuppressWarnings("unchecked")
public Map<String, Object> extractSettings() throws IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
if (settings.get("maxProcessCount") != null) {
settings.remove("maxProcessCount");
}

Map<String, Object> result = PropertyUtils.describe(this);
BeanUtils.populate(this, settings);

if (result.get("maxProcessCount") != null) {
result.remove("maxProcessCount");
}

return result;
}

/**
* Checks if a given device is supported by the current Ghostscript version.
*
* @param deviceName
* Device name
* @return true/false
* @throws GhostscriptException
*/
protected synchronized boolean isDeviceSupported(String deviceName)
throws GhostscriptException {

// if no device names know yet : query the interpreter
if (AVAILABLE_DEVICE_NAMES.size() == 0) {
public Map<String, Object> extractSettings() throws IllegalAccessException,
InvocationTargetException, NoSuchMethodException {

// get Ghostscript instance
Ghostscript gs = Ghostscript.getInstance();
Map<String, Object> result = PropertyUtils.describe(this);

// retrieve available devices
try {

ByteArrayOutputStream baos = new ByteArrayOutputStream();

String[] gsArgs = { "-dQUIET", "-dNOPAUSE", "-dBATCH",
"-dNODISPLAY" };

synchronized (gs) {
gs.setStdOut(baos);
gs.initialize(gsArgs);
gs.runString("devicenames ==");
gs.exit();
if (result.get("maxProcessCount") != null) {
result.remove("maxProcessCount");
}

// result string
String result = new String(baos.toByteArray());
String[] lines = result.split("\n");
int i = 0;
while (!lines[i].startsWith("[")) {
i++;
}
String[] deviceNames = lines[i].substring(1,
lines[i].length() - 2).split("/");
for (String string : deviceNames) {
AVAILABLE_DEVICE_NAMES.add(string.trim());
return result;
}

/**
* Checks if a given device is supported by the current Ghostscript version.
*
* @param deviceName
* Device name
* @return true/false
* @throws GhostscriptException
*/
protected synchronized boolean isDeviceSupported(String deviceName)
throws GhostscriptException {

// if no device names know yet : query the interpreter
if (AVAILABLE_DEVICE_NAMES.size() == 0) {

// get Ghostscript instance
Ghostscript gs = Ghostscript.getInstance();

// retrieve available devices
try {

ByteArrayOutputStream baos = new ByteArrayOutputStream();

String[] gsArgs = { "-dQUIET", "-dNOPAUSE", "-dBATCH",
"-dNODISPLAY" };

synchronized (gs) {
gs.setStdOut(baos);
gs.initialize(gsArgs);
gs.runString("devicenames ==");
gs.exit();
}

// result string
String result = new String(baos.toByteArray());
String[] lines = result.split("\n");
int i = 0;
while (!lines[i].startsWith("[")) {
i++;
}
String[] deviceNames = lines[i].substring(1,
lines[i].length() - 2).split("/");
for (String string : deviceNames) {
AVAILABLE_DEVICE_NAMES.add(string.trim());
}

} catch (GhostscriptException e) {
throw e;
} finally {
Ghostscript.deleteInstance();
}
}

} catch (GhostscriptException e) {
throw e;
} finally {
Ghostscript.deleteInstance();
}
return AVAILABLE_DEVICE_NAMES.contains(deviceName);
}

return AVAILABLE_DEVICE_NAMES.contains(deviceName);
}

/**
* Asserts a given device is supported by the current Ghostscript version.
*
* @param deviceName
* Device name
* @throws GhostscriptException
* Thrown is device is not supported, or call to the interpreter
* fails
*/
protected void assertDeviceSupported(String deviceName)
throws GhostscriptException {

if (!this.isDeviceSupported(deviceName)) {
throw new GhostscriptException(
"device "
+ deviceName
+ " is not supported by the current Ghostscript interpreter.");
/**
* Asserts a given device is supported by the current Ghostscript version.
*
* @param deviceName
* Device name
* @throws GhostscriptException
* Thrown is device is not supported, or call to the interpreter
* fails
*/
protected void assertDeviceSupported(String deviceName)
throws GhostscriptException {

if (!this.isDeviceSupported(deviceName)) {
throw new GhostscriptException(
"device "
+ deviceName
+ " is not supported by the current Ghostscript interpreter.");
}
}
}

}
Loading