Code cleanup
- Removed unused xproc step. - Removed unused code. - Removed System.out.printlns - Wrap IOException and Batik TranscodeException in XProcException and throw to fail the build.
This commit is contained in:
@@ -551,10 +551,10 @@ public abstract class WebHelpMojo extends AbstractWebhelpMojo {
|
|||||||
String srcFilename = this.projectBuildDirectory+"/docbkx/"+sourceFile.getName();
|
String srcFilename = this.projectBuildDirectory+"/docbkx/"+sourceFile.getName();
|
||||||
File tempHandle = new File(srcFilename);
|
File tempHandle = new File(srcFilename);
|
||||||
if(tempHandle.exists()) {
|
if(tempHandle.exists()) {
|
||||||
System.out.println("***********************"+ srcFilename);
|
getLog().debug("***********************"+ srcFilename);
|
||||||
pdfBuilder.setSourceFilePath(srcFilename);
|
pdfBuilder.setSourceFilePath(srcFilename);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("***********************"+ getSourceDirectory()+File.separator+inputFilename);
|
getLog().debug("***********************"+ getSourceDirectory()+File.separator+inputFilename);
|
||||||
pdfBuilder.setSourceFilePath(getSourceDirectory()+File.separator+inputFilename);
|
pdfBuilder.setSourceFilePath(getSourceDirectory()+File.separator+inputFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -382,7 +382,6 @@ public class PDFBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Configuration loadFOPConfig() throws MojoExecutionException {
|
protected Configuration loadFOPConfig() throws MojoExecutionException {
|
||||||
System.out.println ("At load config");
|
|
||||||
String fontPath = (new File(getAutopdfTargetDirectory().getParentFile(), "fonts")).getAbsolutePath();
|
String fontPath = (new File(getAutopdfTargetDirectory().getParentFile(), "fonts")).getAbsolutePath();
|
||||||
StringTemplateGroup templateGroup = new StringTemplateGroup("fonts", fontPath);
|
StringTemplateGroup templateGroup = new StringTemplateGroup("fonts", fontPath);
|
||||||
StringTemplate template = templateGroup.getInstanceOf("fontconfig");
|
StringTemplate template = templateGroup.getInstanceOf("fontconfig");
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
package com.rackspace.cloud.api.docs.calabash.extensions;
|
package com.rackspace.cloud.api.docs.calabash.extensions;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import net.sf.saxon.s9api.QName;
|
import net.sf.saxon.s9api.QName;
|
||||||
import net.sf.saxon.s9api.SaxonApiException;
|
import net.sf.saxon.s9api.SaxonApiException;
|
||||||
@@ -22,12 +18,10 @@ import com.xmlcalabash.library.DefaultStep;
|
|||||||
import com.xmlcalabash.model.RuntimeValue;
|
import com.xmlcalabash.model.RuntimeValue;
|
||||||
import com.xmlcalabash.runtime.XAtomicStep;
|
import com.xmlcalabash.runtime.XAtomicStep;
|
||||||
import com.xmlcalabash.util.ProcessMatch;
|
import com.xmlcalabash.util.ProcessMatch;
|
||||||
import com.xmlcalabash.util.ProcessMatchingNodes;
|
|
||||||
|
|
||||||
public class CopyAndTransformXProcStep extends DefaultStep {
|
public class CopyAndTransformXProcStep extends DefaultStep {
|
||||||
private static final QName _target = new QName("target");
|
private static final QName _target = new QName("target");
|
||||||
private static final QName _targetHtmlContentDir = new QName("targetHtmlContentDir");
|
private static final QName _targetHtmlContentDir = new QName("targetHtmlContentDir");
|
||||||
private static final QName _inputFileName = new QName("inputFileName");
|
|
||||||
private static final QName _outputType = new QName("outputType");
|
private static final QName _outputType = new QName("outputType");
|
||||||
private static final QName _fail_on_error = new QName("fail-on-error");
|
private static final QName _fail_on_error = new QName("fail-on-error");
|
||||||
|
|
||||||
@@ -92,11 +86,6 @@ public class CopyAndTransformXProcStep extends DefaultStep {
|
|||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getInputDocbookName() {
|
|
||||||
return getOption(_inputFileName, "Unknown");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getOutputType() {
|
private String getOutputType() {
|
||||||
return getOption(_outputType, "Unknown");
|
return getOption(_outputType, "Unknown");
|
||||||
}
|
}
|
||||||
@@ -107,21 +96,17 @@ public class CopyAndTransformXProcStep extends DefaultStep {
|
|||||||
|
|
||||||
|
|
||||||
private XdmNode processInlineImages(XdmNode doc) {
|
private XdmNode processInlineImages(XdmNode doc) {
|
||||||
// System.out.println("******************* getTargetDirectoryURI() = " + getTargetDirectoryURI());
|
String fileRefsXpath = "//*:imagedata/@fileref";
|
||||||
// System.out.println("******************* getTargetHtmlConteURI() = " + getTargetHtmlContentDirectoryURI());
|
|
||||||
|
|
||||||
CopyTransformImage copyTransform =
|
CopyTransformImage copyTransform =
|
||||||
new CopyTransformImage( "//*:imagedata/@fileref",
|
new CopyTransformImage( fileRefsXpath,
|
||||||
getTargetDirectoryURI(),
|
getTargetDirectoryURI(),
|
||||||
getTargetHtmlContentDirectoryURI(),
|
getTargetHtmlContentDirectoryURI(),
|
||||||
getInputDocbookName(),
|
getOutputType());
|
||||||
getOutputType(),
|
|
||||||
step.getNode());
|
|
||||||
|
|
||||||
matcher = new ProcessMatch(runtime, copyTransform);
|
matcher = new ProcessMatch(runtime, copyTransform);
|
||||||
copyTransform.setMatcher(matcher);
|
copyTransform.setMatcher(matcher);
|
||||||
|
|
||||||
matcher.match(doc, new RuntimeValue("//*:imagedata/@fileref"));
|
matcher.match(doc, new RuntimeValue(fileRefsXpath));
|
||||||
doc = matcher.getResult();
|
doc = matcher.getResult();
|
||||||
|
|
||||||
if (copyTransform.hasErrors() && isFailOnErrorFlagSet()) {
|
if (copyTransform.hasErrors() && isFailOnErrorFlagSet()) {
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
package com.rackspace.cloud.api.docs.calabash.extensions;
|
package com.rackspace.cloud.api.docs.calabash.extensions;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -18,6 +15,7 @@ import net.sf.saxon.s9api.QName;
|
|||||||
import net.sf.saxon.s9api.SaxonApiException;
|
import net.sf.saxon.s9api.SaxonApiException;
|
||||||
import net.sf.saxon.s9api.XdmNode;
|
import net.sf.saxon.s9api.XdmNode;
|
||||||
|
|
||||||
|
import org.apache.batik.transcoder.TranscoderException;
|
||||||
import org.apache.batik.transcoder.TranscoderInput;
|
import org.apache.batik.transcoder.TranscoderInput;
|
||||||
import org.apache.batik.transcoder.TranscoderOutput;
|
import org.apache.batik.transcoder.TranscoderOutput;
|
||||||
import org.apache.batik.transcoder.image.PNGTranscoder;
|
import org.apache.batik.transcoder.image.PNGTranscoder;
|
||||||
@@ -49,10 +47,7 @@ public class CopyTransformImage implements ProcessMatchingNodes {
|
|||||||
|
|
||||||
private URI targetDirectoryUri;
|
private URI targetDirectoryUri;
|
||||||
private URI targetHtmlContentDirectoryUri;
|
private URI targetHtmlContentDirectoryUri;
|
||||||
private String inputDocbookName;
|
|
||||||
private String outputType;
|
private String outputType;
|
||||||
private XdmNode stepNode;
|
|
||||||
private static final int bufferSize = 8192;
|
|
||||||
|
|
||||||
private boolean errorsFound = false;
|
private boolean errorsFound = false;
|
||||||
|
|
||||||
@@ -66,13 +61,11 @@ public class CopyTransformImage implements ProcessMatchingNodes {
|
|||||||
return log;
|
return log;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CopyTransformImage(String _xpath, URI _targetDirectory, URI _targetHtmlContentDirectoryUri, String _inputDocbookName, String _outputType, XdmNode _step) {
|
public CopyTransformImage(String _xpath, URI _targetDirectory, URI _targetHtmlContentDirectoryUri, String _outputType) {
|
||||||
this.xpath = _xpath;
|
this.xpath = _xpath;
|
||||||
this.targetDirectoryUri = _targetDirectory;
|
this.targetDirectoryUri = _targetDirectory;
|
||||||
this.targetHtmlContentDirectoryUri = _targetHtmlContentDirectoryUri;
|
this.targetHtmlContentDirectoryUri = _targetHtmlContentDirectoryUri;
|
||||||
this.inputDocbookName = _inputDocbookName;
|
|
||||||
this.outputType = _outputType;
|
this.outputType = _outputType;
|
||||||
this.stepNode = _step;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasErrors() {
|
public boolean hasErrors() {
|
||||||
@@ -87,76 +80,6 @@ public class CopyTransformImage implements ProcessMatchingNodes {
|
|||||||
this.matcher = matcher;
|
this.matcher = matcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getHandleToImageFile(URI sourceImageUri) {
|
|
||||||
File file = null;
|
|
||||||
file = new File(sourceImageUri.getPath());
|
|
||||||
if (!file.exists()) {
|
|
||||||
getLog().error("DocBook File: '" + inputDocbookName + "' - File: '" + sourceImageUri.getPath() + "' - Problem: File does not exist!");
|
|
||||||
//throw new XProcException(stepNode, "Cannot copy: file does not exist: " + file.getAbsolutePath());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file.isDirectory()) {
|
|
||||||
getLog().error("DocBook File: '" + inputDocbookName + "' - File: '" + sourceImageUri.getPath() + "' - Problem: File is a directory!");
|
|
||||||
//throw new XProcException(stepNode, "Cannot copy: file is a directory: " + file.getAbsolutePath());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
private File performFileCopyAndTransformation(URI uri, String inputFileName, File file) {
|
|
||||||
|
|
||||||
File target;
|
|
||||||
|
|
||||||
target = new File(uri.getPath());
|
|
||||||
if(!target.exists()) {
|
|
||||||
if (target.mkdir() || target.mkdirs()) {
|
|
||||||
//do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (target.isDirectory()) {
|
|
||||||
target = new File(target, file.getName());
|
|
||||||
if (target.isDirectory()) {
|
|
||||||
getLog().error("DocBook File: '" + inputFileName + "' - File: '" + target.getPath() + "' - Problem: File is a directory!");
|
|
||||||
throw new XProcException("Cannot copy: target file is a directory: " + target.getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
FileInputStream src = new FileInputStream(file);
|
|
||||||
FileOutputStream dst = new FileOutputStream(target);
|
|
||||||
byte[] buffer = new byte[bufferSize];
|
|
||||||
int read = src.read(buffer, 0, bufferSize);
|
|
||||||
while (read >= 0) {
|
|
||||||
dst.write(buffer, 0, read);
|
|
||||||
read = src.read(buffer, 0, bufferSize);
|
|
||||||
}
|
|
||||||
src.close();
|
|
||||||
dst.close();
|
|
||||||
//transform SVG file
|
|
||||||
String name = file.getName();
|
|
||||||
int pos = name.lastIndexOf('.');
|
|
||||||
String ext = name.substring(pos + 1);
|
|
||||||
|
|
||||||
if (ext.equalsIgnoreCase("svg")) {
|
|
||||||
TransformSVGToPNG t = new TransformSVGToPNG();
|
|
||||||
String convertedFileUri = t.transform(target.getParent() + File.separator, name);
|
|
||||||
if (convertedFileUri==null || convertedFileUri.isEmpty()) {
|
|
||||||
getLog().error("DocBook File: '" + inputFileName + "' - File: '" + uri.getPath() + "' - Problem: Could not transform SVG to PNG!");
|
|
||||||
//getLog().error("Could not transform SVG file to PNG:" + name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (FileNotFoundException fnfe) {
|
|
||||||
throw new XProcException(fnfe);
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
throw new XProcException(ioe);
|
|
||||||
}
|
|
||||||
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String processSelectedImage(XdmNode imageDataFileRef) {
|
private String processSelectedImage(XdmNode imageDataFileRef) {
|
||||||
final URI baseUri = imageDataFileRef.getBaseURI();
|
final URI baseUri = imageDataFileRef.getBaseURI();
|
||||||
final String fileRef = imageDataFileRef.getStringValue();
|
final String fileRef = imageDataFileRef.getStringValue();
|
||||||
@@ -208,12 +131,11 @@ public class CopyTransformImage implements ProcessMatchingNodes {
|
|||||||
//convert the svg to the relevant type and copy
|
//convert the svg to the relevant type and copy
|
||||||
File svgFile = getFileHandle(srcImgFilePath);
|
File svgFile = getFileHandle(srcImgFilePath);
|
||||||
File copiedFile = new TransformSVGToPNG().transformAndCopy(svgFile, targetDir);
|
File copiedFile = new TransformSVGToPNG().transformAndCopy(svgFile, targetDir);
|
||||||
//TODO: check if conversion was successful
|
|
||||||
relativePathToCopiedFile = RelativePath.getRelativePath(new File(targetHtmlContentDirectoryUri), copiedFile);
|
relativePathToCopiedFile = RelativePath.getRelativePath(new File(targetHtmlContentDirectoryUri), copiedFile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//simply copy the src file to the destination
|
//simply copy the src file to the destination
|
||||||
File copiedFile = copyFile(srcImgFile, targetDir);
|
File copiedFile = copyFile(srcImgFile, targetDir);
|
||||||
relativePathToCopiedFile = RelativePath.getRelativePath(new File(targetHtmlContentDirectoryUri), copiedFile);
|
relativePathToCopiedFile = RelativePath.getRelativePath(new File(targetHtmlContentDirectoryUri), copiedFile);
|
||||||
}
|
}
|
||||||
this.processedFilesMapForHtmlOutput.put(srcImgFilePath, relativePathToCopiedFile);
|
this.processedFilesMapForHtmlOutput.put(srcImgFilePath, relativePathToCopiedFile);
|
||||||
@@ -260,7 +182,8 @@ public class CopyTransformImage implements ProcessMatchingNodes {
|
|||||||
try {
|
try {
|
||||||
FileUtils.copyFileToDirectory(srcFile, targetDir);
|
FileUtils.copyFileToDirectory(srcFile, targetDir);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return null;
|
getLog().error("Unable to copy file: " + srcFile.getAbsolutePath() + " to " + targetDir.getAbsolutePath());
|
||||||
|
throw new XProcException(e);
|
||||||
}
|
}
|
||||||
return new File(targetDir.getAbsolutePath() + File.separator + srcFile.getName());
|
return new File(targetDir.getAbsolutePath() + File.separator + srcFile.getName());
|
||||||
}
|
}
|
||||||
@@ -275,113 +198,24 @@ public class CopyTransformImage implements ProcessMatchingNodes {
|
|||||||
try {
|
try {
|
||||||
return file==null ? false : file.exists() && file.getCanonicalPath().endsWith(file.getName());
|
return file==null ? false : file.exists() && file.getCanonicalPath().endsWith(file.getName());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
getLog().error("Unable to access file: " + file.getAbsolutePath());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private File makeDirs(String relativePath) {
|
private File makeDirs(String relativePath) {
|
||||||
//TODO: handle cases where dirPath is path to a file
|
|
||||||
File dir = new File(targetDirectoryUri.getPath(), relativePath);
|
File dir = new File(targetDirectoryUri.getPath(), relativePath);
|
||||||
if (dir.mkdir() || dir.mkdirs()) {
|
if (dir.exists() || dir.mkdir() || dir.mkdirs()) {
|
||||||
|
return dir;
|
||||||
|
} else {
|
||||||
|
getLog().error("Unable to create directory: " + dir.getAbsolutePath());
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return dir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getFileHandle(String filePath) {
|
private File getFileHandle(String filePath) {
|
||||||
// TODO: Handle cases where the filePath refers to a directory
|
File handle = new File(filePath);
|
||||||
return new File(filePath);
|
return (handle.isDirectory() ? null : handle);
|
||||||
}
|
|
||||||
|
|
||||||
private String processSelectedImageOLD(XdmNode node) {
|
|
||||||
System.out.println("****** Processing node: " + node.toString() + " --- baseUri="+node.getBaseURI().toString());
|
|
||||||
|
|
||||||
String value = node.getStringValue();
|
|
||||||
|
|
||||||
if(processedFilesMapForHtmlOutput.containsKey(value)) {
|
|
||||||
System.out.println("\n\n*********** already processed **************** "+processedFilesMapForHtmlOutput.get(value));
|
|
||||||
return processedFilesMapForHtmlOutput.get(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isSVG = false;
|
|
||||||
if(value.contains(".svg") || value.contains(".SVG")) {
|
|
||||||
isSVG = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//System.out.println("\n\n*********** processing **************** "+value);
|
|
||||||
//if the file hasn't been processed before then ....
|
|
||||||
URI sourceImageUri = null;
|
|
||||||
try {
|
|
||||||
if(isSVG) {
|
|
||||||
String executionPath = System.getProperty("user.dir") + File.separator;
|
|
||||||
sourceImageUri = new URI(executionPath+"src/"+value);
|
|
||||||
} else {
|
|
||||||
String filePath = FilenameUtils.normalize("file://"+targetHtmlContentDirectoryUri.getPath() + File.separator + value);
|
|
||||||
sourceImageUri = new URI(filePath);
|
|
||||||
}
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
throw new XProcException(stepNode, "Unable to get handle to image file",e);
|
|
||||||
}
|
|
||||||
if(sourceImageUri != null) {
|
|
||||||
try {
|
|
||||||
//TODO: Need to handle Case Sensitive file name checking.
|
|
||||||
//TODO: NTH: Do not print error message while getting handle. For non-SVG images we are checking first in the target and then in the source directory.
|
|
||||||
//The error message should be printed after we have made sure that it is not present in both directories.
|
|
||||||
File sourceImageFile = getHandleToImageFile(sourceImageUri);
|
|
||||||
|
|
||||||
if(outputType.equals("pdf")) {
|
|
||||||
//no further processing required. Already checked if the image exists or not in the above get Image call.
|
|
||||||
//System.out.println("*********** found **************** "+sourceImageFile.getAbsolutePath());
|
|
||||||
processedFilesMapForHtmlOutput.put(value, sourceImageFile.getAbsolutePath());
|
|
||||||
}
|
|
||||||
else if(outputType.equals("html")) {
|
|
||||||
System.out.println("****** Entering elseif outputType=='html'");
|
|
||||||
//if the output type is html then we need to decide steps based on the image extension
|
|
||||||
//if the image is an SVG then transform and save a png in the html target directory
|
|
||||||
//if the image is a PNG then make a huge assumption that an SVG was specified in the Docbook before the png
|
|
||||||
//and we need to check in the target directory that it is present.
|
|
||||||
if(sourceImageFile == null && !isSVG) {
|
|
||||||
|
|
||||||
//Send another call to the getHandleToImageFile but this time check relative to the html content folder.
|
|
||||||
try {
|
|
||||||
String executionPath = System.getProperty("user.dir") + File.separator;
|
|
||||||
sourceImageUri = new URI(executionPath+"src/"+value);
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
throw new XProcException(stepNode, "Unable to get handle to image file",e);
|
|
||||||
}
|
|
||||||
sourceImageFile = getHandleToImageFile(sourceImageUri);
|
|
||||||
if(sourceImageFile != null) {
|
|
||||||
System.out.println("****** Case 1");
|
|
||||||
File copiedFile = performFileCopyAndTransformation(targetDirectoryUri, inputDocbookName, sourceImageFile);
|
|
||||||
String correctRelativePathToImage = RelativePath.getRelativePath(new File(targetHtmlContentDirectoryUri), copiedFile);
|
|
||||||
processedFilesMapForHtmlOutput.put(value, correctRelativePathToImage);
|
|
||||||
} else {
|
|
||||||
//File not found in source and target folders.
|
|
||||||
}
|
|
||||||
} else if(sourceImageFile != null && !isSVG) {
|
|
||||||
System.out.println("****** Case 2: " + sourceImageFile);
|
|
||||||
File copiedFile = performFileCopyAndTransformation(targetDirectoryUri, inputDocbookName, sourceImageFile);
|
|
||||||
String correctRelativePathToImage = RelativePath.getRelativePath( new File(targetHtmlContentDirectoryUri), copiedFile);
|
|
||||||
processedFilesMapForHtmlOutput.put(value, correctRelativePathToImage);
|
|
||||||
|
|
||||||
} else if(sourceImageFile != null && isSVG) {
|
|
||||||
System.out.println("****** Case 3");
|
|
||||||
//There really isn't any need to copy the SVG for html output but it is being done right now. We only care about transforming it to a PNG.
|
|
||||||
File copiedFile = performFileCopyAndTransformation(targetDirectoryUri, inputDocbookName, sourceImageFile);
|
|
||||||
|
|
||||||
String correctRelativePathToImage = RelativePath.getRelativePath( new File(targetHtmlContentDirectoryUri), copiedFile);
|
|
||||||
processedFilesMapForHtmlOutput.put(value, correctRelativePathToImage);
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("****** Exiting elseif outputType=='html'");
|
|
||||||
}
|
|
||||||
} catch (XProcException x) {
|
|
||||||
//getLog().error(x.getMessage());
|
|
||||||
//do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return processedFilesMapForHtmlOutput.get(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -427,53 +261,6 @@ public class CopyTransformImage implements ProcessMatchingNodes {
|
|||||||
|
|
||||||
private class TransformSVGToPNG {
|
private class TransformSVGToPNG {
|
||||||
|
|
||||||
String substringBeforeLast(String str, String separator) {
|
|
||||||
if (isEmpty(str) || isEmpty(separator)) {
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
int pos = str.lastIndexOf(separator);
|
|
||||||
if (pos == -1) {
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
return str.substring(0, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isEmpty(String str) {
|
|
||||||
return str == null || str.length() == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
String transform(String directory, String fileName) {
|
|
||||||
PNGTranscoder t = new PNGTranscoder();
|
|
||||||
|
|
||||||
// Set the transcoding hints.
|
|
||||||
//t.addTranscodingHint(PNGTranscoder., value)
|
|
||||||
try {
|
|
||||||
String svgURI = new File(directory, fileName).toURI().toString();
|
|
||||||
TranscoderInput input = new TranscoderInput(svgURI);
|
|
||||||
|
|
||||||
// Create the transcoder output.
|
|
||||||
String pngFileName = directory + substringBeforeLast(fileName, ".svg") + ".png";
|
|
||||||
|
|
||||||
File pngFile = new File(pngFileName);
|
|
||||||
pngFile.createNewFile();
|
|
||||||
|
|
||||||
OutputStream ostream = new FileOutputStream(pngFile);
|
|
||||||
TranscoderOutput output = new TranscoderOutput(ostream);
|
|
||||||
|
|
||||||
// Save the image.
|
|
||||||
t.transcode(input, output);
|
|
||||||
// Flush and close the stream.
|
|
||||||
ostream.flush();
|
|
||||||
ostream.close();
|
|
||||||
|
|
||||||
return pngFileName;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
File transformAndCopy(File svgFile, File targetDir) {
|
File transformAndCopy(File svgFile, File targetDir) {
|
||||||
String pngFileName = FilenameUtils.getBaseName(svgFile.getPath()) + ".png";
|
String pngFileName = FilenameUtils.getBaseName(svgFile.getPath()) + ".png";
|
||||||
File pngFile = new File(targetDir, pngFileName);
|
File pngFile = new File(targetDir, pngFileName);
|
||||||
@@ -491,10 +278,13 @@ public class CopyTransformImage implements ProcessMatchingNodes {
|
|||||||
ostream.close();
|
ostream.close();
|
||||||
|
|
||||||
return pngFile;
|
return pngFile;
|
||||||
} catch (Exception e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
getLog().error("An error occured while transforming " + svgFile.getAbsolutePath() + " to " + pngFile.getAbsolutePath());
|
||||||
|
throw new XProcException(e);
|
||||||
|
} catch (TranscoderException e) {
|
||||||
|
getLog().error("Unable to convert " + svgFile.getAbsolutePath() + " to png");
|
||||||
|
throw new XProcException(e);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -784,27 +784,16 @@
|
|||||||
|
|
||||||
</p:declare-step>
|
</p:declare-step>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<p:declare-step
|
<p:declare-step
|
||||||
xmlns:l="http://xproc.org/library"
|
xmlns:l="http://xproc.org/library"
|
||||||
xmlns:c="http://www.w3.org/ns/xproc-step"
|
xmlns:c="http://www.w3.org/ns/xproc-step"
|
||||||
xml:id="validate-images"
|
xml:id="validate-images"
|
||||||
type="l:validate-images"
|
type="l:validate-images"
|
||||||
name="validate-images-step">
|
name="validate-images-step">
|
||||||
|
|
||||||
<p:input port="source" primary="true" sequence="true"/>
|
<p:input port="source" primary="true" sequence="true"/>
|
||||||
<p:output port="result" sequence="true">
|
<p:output port="result" sequence="true">
|
||||||
<p:pipe step="group" port="result"/>
|
<p:pipe step="group" port="result"/>
|
||||||
</p:output>
|
</p:output>
|
||||||
|
|
||||||
<p:input port="parameters" kind="parameter"/>
|
<p:input port="parameters" kind="parameter"/>
|
||||||
<ut:parameters name="params"/>
|
<ut:parameters name="params"/>
|
||||||
<p:sink/>
|
<p:sink/>
|
||||||
@@ -821,13 +810,11 @@
|
|||||||
<p:variable name="input.docbook.file" select="//c:param[@name = 'inputSrcFile']/@value">
|
<p:variable name="input.docbook.file" select="//c:param[@name = 'inputSrcFile']/@value">
|
||||||
<p:pipe step="params" port="parameters"/>
|
<p:pipe step="params" port="parameters"/>
|
||||||
</p:variable>
|
</p:variable>
|
||||||
|
|
||||||
<p:variable name="strict.image.validation" select="//c:param[@name = 'strictImageValidation']/@value">
|
<p:variable name="strict.image.validation" select="//c:param[@name = 'strictImageValidation']/@value">
|
||||||
<p:pipe step="params" port="parameters"/>
|
<p:pipe step="params" port="parameters"/>
|
||||||
</p:variable>
|
</p:variable>
|
||||||
|
|
||||||
<cx:copy-transform name="validateImages">
|
<cx:copy-transform name="validateImages">
|
||||||
|
|
||||||
<p:input port="source">
|
<p:input port="source">
|
||||||
<p:pipe step="validate-images-step" port="source"/>
|
<p:pipe step="validate-images-step" port="source"/>
|
||||||
</p:input>
|
</p:input>
|
||||||
@@ -835,34 +822,9 @@
|
|||||||
<p:with-option name="inputFileName" select="concat($input.docbook.file,'')"/>
|
<p:with-option name="inputFileName" select="concat($input.docbook.file,'')"/>
|
||||||
<p:with-option name="outputType" select="concat($output.type,'')"/>
|
<p:with-option name="outputType" select="concat($output.type,'')"/>
|
||||||
<p:with-option name="fail-on-error" select="concat($strict.image.validation,'')"/>
|
<p:with-option name="fail-on-error" select="concat($strict.image.validation,'')"/>
|
||||||
|
|
||||||
</cx:copy-transform>
|
</cx:copy-transform>
|
||||||
|
|
||||||
</p:group>
|
</p:group>
|
||||||
|
|
||||||
</p:declare-step>
|
</p:declare-step>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<p:declare-step
|
<p:declare-step
|
||||||
xmlns:l="http://xproc.org/library"
|
xmlns:l="http://xproc.org/library"
|
||||||
@@ -870,7 +832,6 @@
|
|||||||
xml:id="copy-and-transform-images"
|
xml:id="copy-and-transform-images"
|
||||||
type="l:copy-and-transform-images"
|
type="l:copy-and-transform-images"
|
||||||
name="copy-and-transform-images-step">
|
name="copy-and-transform-images-step">
|
||||||
|
|
||||||
<p:input port="source" primary="true" sequence="true"/>
|
<p:input port="source" primary="true" sequence="true"/>
|
||||||
<p:output port="result" sequence="true">
|
<p:output port="result" sequence="true">
|
||||||
<p:pipe step="group" port="result"/>
|
<p:pipe step="group" port="result"/>
|
||||||
@@ -908,10 +869,7 @@
|
|||||||
<p:pipe step="params" port="parameters"/>
|
<p:pipe step="params" port="parameters"/>
|
||||||
</p:variable>
|
</p:variable>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<cx:copy-transform name="copyTransform">
|
<cx:copy-transform name="copyTransform">
|
||||||
|
|
||||||
<p:input port="source">
|
<p:input port="source">
|
||||||
<p:pipe step="copy-and-transform-images-step" port="source"/>
|
<p:pipe step="copy-and-transform-images-step" port="source"/>
|
||||||
</p:input>
|
</p:input>
|
||||||
@@ -921,39 +879,10 @@
|
|||||||
<p:with-option name="inputFileName" select="concat($input.docbook.file,'')"/>
|
<p:with-option name="inputFileName" select="concat($input.docbook.file,'')"/>
|
||||||
<p:with-option name="outputType" select="concat($output.type,'')"/>
|
<p:with-option name="outputType" select="concat($output.type,'')"/>
|
||||||
<p:with-option name="fail-on-error" select="concat($strict.image.validation,'')"/>
|
<p:with-option name="fail-on-error" select="concat($strict.image.validation,'')"/>
|
||||||
|
|
||||||
|
|
||||||
</cx:copy-transform>
|
</cx:copy-transform>
|
||||||
|
|
||||||
</p:group>
|
</p:group>
|
||||||
|
|
||||||
</p:declare-step>
|
</p:declare-step>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- copy and transform images calabash extension -->
|
<!-- copy and transform images calabash extension -->
|
||||||
<p:declare-step
|
<p:declare-step
|
||||||
type="cx:copy-transform"
|
type="cx:copy-transform"
|
||||||
@@ -967,21 +896,5 @@
|
|||||||
<p:option name="outputType" cx:type="xsd:string"/>
|
<p:option name="outputType" cx:type="xsd:string"/>
|
||||||
<p:option name="fail-on-error" select="'true'" cx:type="xsd:boolean"/>
|
<p:option name="fail-on-error" select="'true'" cx:type="xsd:boolean"/>
|
||||||
</p:declare-step>
|
</p:declare-step>
|
||||||
|
|
||||||
<!-- process images calabash extension -->
|
|
||||||
<p:declare-step
|
|
||||||
type="cx:process-images"
|
|
||||||
xml:id="process-images">
|
|
||||||
|
|
||||||
<p:input port="source" primary="true" sequence="true"/>
|
|
||||||
<p:output port="result" primary="true" sequence="true"/>
|
|
||||||
|
|
||||||
<p:option name="validate-only" select="'false'" cx:type="xsd:boolean" />
|
|
||||||
<p:option name="target-dir" required="false" cx:type="xsd:anyURI" />
|
|
||||||
<p:option name="relative-to" required="false" cx:type="xsd:anyURI" />
|
|
||||||
<p:option name="convert-from" select="'svg'" cx:type="xsd:string" />
|
|
||||||
<p:option name="convert-to" select="'png'" cx:type="xsd:string" />
|
|
||||||
<p:option name="fail-on-error" select="'true'" cx:type="xsd:boolean"/>
|
|
||||||
</p:declare-step>
|
|
||||||
|
|
||||||
</p:library>
|
</p:library>
|
||||||
Reference in New Issue
Block a user