diff --git a/src/main/java/com/rackspace/cloud/api/docs/WebHelpMojo.java b/src/main/java/com/rackspace/cloud/api/docs/WebHelpMojo.java
index 4e7f29c..8f0b037 100644
--- a/src/main/java/com/rackspace/cloud/api/docs/WebHelpMojo.java
+++ b/src/main/java/com/rackspace/cloud/api/docs/WebHelpMojo.java
@@ -551,10 +551,10 @@ public abstract class WebHelpMojo extends AbstractWebhelpMojo {
String srcFilename = this.projectBuildDirectory+"/docbkx/"+sourceFile.getName();
File tempHandle = new File(srcFilename);
if(tempHandle.exists()) {
- System.out.println("***********************"+ srcFilename);
+ getLog().debug("***********************"+ srcFilename);
pdfBuilder.setSourceFilePath(srcFilename);
} else {
- System.out.println("***********************"+ getSourceDirectory()+File.separator+inputFilename);
+ getLog().debug("***********************"+ getSourceDirectory()+File.separator+inputFilename);
pdfBuilder.setSourceFilePath(getSourceDirectory()+File.separator+inputFilename);
}
diff --git a/src/main/java/com/rackspace/cloud/api/docs/builders/PDFBuilder.java b/src/main/java/com/rackspace/cloud/api/docs/builders/PDFBuilder.java
index 6a7263c..c351b8b 100644
--- a/src/main/java/com/rackspace/cloud/api/docs/builders/PDFBuilder.java
+++ b/src/main/java/com/rackspace/cloud/api/docs/builders/PDFBuilder.java
@@ -382,7 +382,6 @@ public class PDFBuilder {
}
protected Configuration loadFOPConfig() throws MojoExecutionException {
- System.out.println ("At load config");
String fontPath = (new File(getAutopdfTargetDirectory().getParentFile(), "fonts")).getAbsolutePath();
StringTemplateGroup templateGroup = new StringTemplateGroup("fonts", fontPath);
StringTemplate template = templateGroup.getInstanceOf("fontconfig");
diff --git a/src/main/java/com/rackspace/cloud/api/docs/calabash/extensions/CopyAndTransformXProcStep.java b/src/main/java/com/rackspace/cloud/api/docs/calabash/extensions/CopyAndTransformXProcStep.java
index a13a3f8..092c40d 100644
--- a/src/main/java/com/rackspace/cloud/api/docs/calabash/extensions/CopyAndTransformXProcStep.java
+++ b/src/main/java/com/rackspace/cloud/api/docs/calabash/extensions/CopyAndTransformXProcStep.java
@@ -1,10 +1,6 @@
package com.rackspace.cloud.api.docs.calabash.extensions;
-import java.io.File;
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.SaxonApiException;
@@ -22,12 +18,10 @@ import com.xmlcalabash.library.DefaultStep;
import com.xmlcalabash.model.RuntimeValue;
import com.xmlcalabash.runtime.XAtomicStep;
import com.xmlcalabash.util.ProcessMatch;
-import com.xmlcalabash.util.ProcessMatchingNodes;
public class CopyAndTransformXProcStep extends DefaultStep {
private static final QName _target = new QName("target");
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 _fail_on_error = new QName("fail-on-error");
@@ -92,11 +86,6 @@ public class CopyAndTransformXProcStep extends DefaultStep {
return uri;
}
- private String getInputDocbookName() {
- return getOption(_inputFileName, "Unknown");
-
- }
-
private String getOutputType() {
return getOption(_outputType, "Unknown");
}
@@ -107,21 +96,17 @@ public class CopyAndTransformXProcStep extends DefaultStep {
private XdmNode processInlineImages(XdmNode doc) {
-// System.out.println("******************* getTargetDirectoryURI() = " + getTargetDirectoryURI());
-// System.out.println("******************* getTargetHtmlConteURI() = " + getTargetHtmlContentDirectoryURI());
-
+ String fileRefsXpath = "//*:imagedata/@fileref";
CopyTransformImage copyTransform =
- new CopyTransformImage( "//*:imagedata/@fileref",
+ new CopyTransformImage( fileRefsXpath,
getTargetDirectoryURI(),
getTargetHtmlContentDirectoryURI(),
- getInputDocbookName(),
- getOutputType(),
- step.getNode());
+ getOutputType());
matcher = new ProcessMatch(runtime, copyTransform);
copyTransform.setMatcher(matcher);
- matcher.match(doc, new RuntimeValue("//*:imagedata/@fileref"));
+ matcher.match(doc, new RuntimeValue(fileRefsXpath));
doc = matcher.getResult();
if (copyTransform.hasErrors() && isFailOnErrorFlagSet()) {
diff --git a/src/main/java/com/rackspace/cloud/api/docs/calabash/extensions/CopyTransformImage.java b/src/main/java/com/rackspace/cloud/api/docs/calabash/extensions/CopyTransformImage.java
index 55dcc9f..06dbfd6 100644
--- a/src/main/java/com/rackspace/cloud/api/docs/calabash/extensions/CopyTransformImage.java
+++ b/src/main/java/com/rackspace/cloud/api/docs/calabash/extensions/CopyTransformImage.java
@@ -1,13 +1,10 @@
package com.rackspace.cloud.api.docs.calabash.extensions;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
-import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.HashSet;
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.XdmNode;
+import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.transcoder.image.PNGTranscoder;
@@ -49,10 +47,7 @@ public class CopyTransformImage implements ProcessMatchingNodes {
private URI targetDirectoryUri;
private URI targetHtmlContentDirectoryUri;
- private String inputDocbookName;
private String outputType;
- private XdmNode stepNode;
- private static final int bufferSize = 8192;
private boolean errorsFound = false;
@@ -66,13 +61,11 @@ public class CopyTransformImage implements ProcessMatchingNodes {
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.targetDirectoryUri = _targetDirectory;
this.targetHtmlContentDirectoryUri = _targetHtmlContentDirectoryUri;
- this.inputDocbookName = _inputDocbookName;
this.outputType = _outputType;
- this.stepNode = _step;
}
public boolean hasErrors() {
@@ -87,76 +80,6 @@ public class CopyTransformImage implements ProcessMatchingNodes {
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) {
final URI baseUri = imageDataFileRef.getBaseURI();
final String fileRef = imageDataFileRef.getStringValue();
@@ -208,12 +131,11 @@ public class CopyTransformImage implements ProcessMatchingNodes {
//convert the svg to the relevant type and copy
File svgFile = getFileHandle(srcImgFilePath);
File copiedFile = new TransformSVGToPNG().transformAndCopy(svgFile, targetDir);
- //TODO: check if conversion was successful
relativePathToCopiedFile = RelativePath.getRelativePath(new File(targetHtmlContentDirectoryUri), copiedFile);
}
else {
//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);
}
this.processedFilesMapForHtmlOutput.put(srcImgFilePath, relativePathToCopiedFile);
@@ -260,7 +182,8 @@ public class CopyTransformImage implements ProcessMatchingNodes {
try {
FileUtils.copyFileToDirectory(srcFile, targetDir);
} 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());
}
@@ -275,113 +198,24 @@ public class CopyTransformImage implements ProcessMatchingNodes {
try {
return file==null ? false : file.exists() && file.getCanonicalPath().endsWith(file.getName());
} catch (IOException e) {
+ getLog().error("Unable to access file: " + file.getAbsolutePath());
return false;
}
}
private File makeDirs(String relativePath) {
- //TODO: handle cases where dirPath is path to a file
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) {
- // TODO: Handle cases where the filePath refers to a directory
- return new File(filePath);
- }
-
- 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);
+ File handle = new File(filePath);
+ return (handle.isDirectory() ? null : handle);
}
@Override
@@ -427,53 +261,6 @@ public class CopyTransformImage implements ProcessMatchingNodes {
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) {
String pngFileName = FilenameUtils.getBaseName(svgFile.getPath()) + ".png";
File pngFile = new File(targetDir, pngFileName);
@@ -491,10 +278,13 @@ public class CopyTransformImage implements ProcessMatchingNodes {
ostream.close();
return pngFile;
- } catch (Exception e) {
- e.printStackTrace();
+ } catch (IOException e) {
+ 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;
}
}
}
diff --git a/src/main/resources/rackspace-library.xpl b/src/main/resources/rackspace-library.xpl
index 99fb6ec..085cfee 100644
--- a/src/main/resources/rackspace-library.xpl
+++ b/src/main/resources/rackspace-library.xpl
@@ -784,27 +784,16 @@
-
-
-
-
-
-
-
-
-
-
-
@@ -821,13 +810,11 @@
-
-
@@ -835,34 +822,9 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -908,10 +869,7 @@
-
-
-
@@ -921,39 +879,10 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file