Expand CalabashHelper to support parameter values which are instances of String, File, URI, or URL (previously only String was supported)
This commit is contained in:
@@ -68,7 +68,7 @@ public abstract class ApiRefMojo extends AbstractHtmlMojo {
|
|||||||
String pathToPipelineFile = "classpath:/wadl2html.xpl"; //use "classpath:/path" for this to work
|
String pathToPipelineFile = "classpath:/wadl2html.xpl"; //use "classpath:/path" for this to work
|
||||||
Source source = super.createSource(inputFilename, sourceFile, filter);
|
Source source = super.createSource(inputFilename, sourceFile, filter);
|
||||||
|
|
||||||
Map map=new HashMap<String, String>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
|
||||||
map.put("security", security);
|
map.put("security", security);
|
||||||
map.put("canonicalUrlBase", canonicalUrlBase);
|
map.put("canonicalUrlBase", canonicalUrlBase);
|
||||||
|
|||||||
@@ -10,16 +10,17 @@ import javax.xml.transform.Source;
|
|||||||
import javax.xml.transform.sax.SAXSource;
|
import javax.xml.transform.sax.SAXSource;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class CalabashHelper {
|
public class CalabashHelper {
|
||||||
private static Source run(final String pipelineURI, final InputSource inputSource, final Map<String, String>map) throws FileNotFoundException {
|
private static Source run(final String pipelineURI, final InputSource inputSource, final Map<String, Object> map) throws FileNotFoundException {
|
||||||
Pipeline pipeline = new CalabashPipelineBuilder(false, true).build(pipelineURI);
|
Pipeline pipeline = new CalabashPipelineBuilder(false, true).build(pipelineURI);
|
||||||
|
|
||||||
// <c:param-set xmlns:c="http://www.w3.org/ns/xproc-step">
|
// <c:param-set xmlns:c="http://www.w3.org/ns/xproc-step">
|
||||||
@@ -33,17 +34,30 @@ public class CalabashHelper {
|
|||||||
|
|
||||||
|
|
||||||
if(null!=map){
|
if(null!=map){
|
||||||
Set<String>keys=map.keySet();
|
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||||
if(null!=keys){
|
String rawValue;
|
||||||
|
if (entry.getValue() instanceof File) {
|
||||||
|
rawValue = ((File)entry.getValue()).toURI().toString();
|
||||||
|
} else if (entry.getValue() instanceof URI || entry.getValue() instanceof String) {
|
||||||
|
rawValue = entry.getValue().toString();
|
||||||
|
} else if (entry.getValue() instanceof URL) {
|
||||||
|
rawValue = ((URL)entry.getValue()).toExternalForm();
|
||||||
|
} else if (entry.getValue() != null) {
|
||||||
|
throw new UnsupportedOperationException(String.format("The map cannot contain values of type %s.", entry.getValue().getClass()));
|
||||||
|
} else {
|
||||||
|
// ignore nulls
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for(Iterator<String>iter=keys.iterator();iter.hasNext();){
|
strBuff
|
||||||
String aKey=iter.next();
|
.append("<c:param name=\"")
|
||||||
if(null!=map.get(aKey)){
|
.append(entry.getKey())
|
||||||
strBuff.append("<c:param name=\""+aKey+ "\" namespace=\"\" value=\""+map.get(aKey)+"\"/>");
|
.append("\" namespace=\"\" value=\"")
|
||||||
}
|
.append(rawValue)
|
||||||
}
|
.append("\"/>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
strBuff.append("</c:param-set>");
|
strBuff.append("</c:param-set>");
|
||||||
String params=strBuff.toString();
|
String params=strBuff.toString();
|
||||||
final InputStream paramsStream = new ByteArrayInputStream(params.getBytes());
|
final InputStream paramsStream = new ByteArrayInputStream(params.getBytes());
|
||||||
@@ -60,7 +74,27 @@ public class CalabashHelper {
|
|||||||
return sources.get(0);
|
return sources.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Source createSource(Source source, String pipelineURI, Map<String, String> map)
|
/**
|
||||||
|
* Creates a {@link Source} for use in a Calabash pipeline.
|
||||||
|
*
|
||||||
|
* <p>The {@code map} values may instances of {@link String}, {@link File},
|
||||||
|
* {@link URI}, or {@link URL}.</p>
|
||||||
|
*
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link String}: These are passed to the pipeline unchanged.</li>
|
||||||
|
* <li>{@link URI}: The results of {@link URI#toString()} is passed to the pipeline.</li>
|
||||||
|
* <li>{@link File}: These are treated as URIs by calling {@link File#toURI()}.</li>
|
||||||
|
* <li>{@link URL}: The result of {@link URL#toExternalForm()} is passed to the pipeline.</li>
|
||||||
|
* <li>{@code null}: This is passed to the pipeline as an empty string.</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param source
|
||||||
|
* @param pipelineURI
|
||||||
|
* @param map
|
||||||
|
* @return
|
||||||
|
* @throws MojoExecutionException
|
||||||
|
*/
|
||||||
|
public static Source createSource(Source source, String pipelineURI, Map<String, Object> map)
|
||||||
throws MojoExecutionException {
|
throws MojoExecutionException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -533,7 +533,7 @@ public abstract class PDFMojo extends AbstractFoMojo {
|
|||||||
Source source = new SAXSource(filter, inputSource);
|
Source source = new SAXSource(filter, inputSource);
|
||||||
//Source source = super.createSource(inputFilename, sourceFile, filter);
|
//Source source = super.createSource(inputFilename, sourceFile, filter);
|
||||||
|
|
||||||
Map map=new HashMap<String, String>();
|
Map<String, Object> map=new HashMap<String, Object>();
|
||||||
String sysSecurity=System.getProperty("security");
|
String sysSecurity=System.getProperty("security");
|
||||||
getLog().info("adjustTransformer():sysSecurity="+sysSecurity);
|
getLog().info("adjustTransformer():sysSecurity="+sysSecurity);
|
||||||
if(null!=sysSecurity && !sysSecurity.isEmpty()){
|
if(null!=sysSecurity && !sysSecurity.isEmpty()){
|
||||||
|
|||||||
@@ -754,7 +754,7 @@ public abstract class WebHelpMojo extends AbstractWebhelpMojo {
|
|||||||
Source source = new SAXSource(filter, inputSource);
|
Source source = new SAXSource(filter, inputSource);
|
||||||
//Source source = super.createSource(inputFilename, sourceFile, filter);
|
//Source source = super.createSource(inputFilename, sourceFile, filter);
|
||||||
|
|
||||||
Map<String, String> map=new HashMap<String, String>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
|
||||||
String sysWebhelpWar=System.getProperty("webhelp.war");
|
String sysWebhelpWar=System.getProperty("webhelp.war");
|
||||||
|
|||||||
@@ -292,7 +292,7 @@ public abstract class XhtmlMojo extends AbstractHtmlMojo {
|
|||||||
String pathToPipelineFile = "classpath:/war.xpl"; //use "classpath:/path" for this to work
|
String pathToPipelineFile = "classpath:/war.xpl"; //use "classpath:/path" for this to work
|
||||||
Source source = super.createSource(inputFilename, sourceFile, filter);
|
Source source = super.createSource(inputFilename, sourceFile, filter);
|
||||||
|
|
||||||
Map map=new HashMap<String, String>();
|
Map<String, Object> map=new HashMap<String, Object>();
|
||||||
|
|
||||||
map.put("failOnValidationError", failOnValidationError);
|
map.put("failOnValidationError", failOnValidationError);
|
||||||
map.put("transform.dir", transformDir);
|
map.put("transform.dir", transformDir);
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ public class PDFBuilder {
|
|||||||
FileUtils.extractJaredDirectory("fonts",PDFBuilder.class,imageParentDirectory);
|
FileUtils.extractJaredDirectory("fonts",PDFBuilder.class,imageParentDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public File processSources(Map<String,String> map) throws MojoExecutionException{
|
public File processSources(Map<String, Object> map) throws MojoExecutionException {
|
||||||
final String[] included = scanIncludedFiles();
|
final String[] included = scanIncludedFiles();
|
||||||
// configure a resolver for catalog files
|
// configure a resolver for catalog files
|
||||||
final CatalogManager catalogManager = createCatalogManager();
|
final CatalogManager catalogManager = createCatalogManager();
|
||||||
@@ -1063,7 +1063,7 @@ public class PDFBuilder {
|
|||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Source createSource(String inputFilename, File sourceFile, PreprocessingFilter filter, Map<String,String> map)
|
protected Source createSource(String inputFilename, File sourceFile, PreprocessingFilter filter, Map<String, Object> map)
|
||||||
throws MojoExecutionException {
|
throws MojoExecutionException {
|
||||||
String pathToPipelineFile = "classpath:/pdf.xpl"; //use "classpath:/path" for this to work
|
String pathToPipelineFile = "classpath:/pdf.xpl"; //use "classpath:/path" for this to work
|
||||||
|
|
||||||
@@ -1072,7 +1072,7 @@ public class PDFBuilder {
|
|||||||
final InputSource inputSource = new InputSource(sourceFileNameNormalized);
|
final InputSource inputSource = new InputSource(sourceFileNameNormalized);
|
||||||
Source source = new SAXSource(filter, inputSource);
|
Source source = new SAXSource(filter, inputSource);
|
||||||
|
|
||||||
Map<String,String> localMap = new HashMap<String,String>(map);
|
Map<String, Object> localMap = new HashMap<String, Object>(map);
|
||||||
localMap.put("outputType", "pdf");
|
localMap.put("outputType", "pdf");
|
||||||
|
|
||||||
//removing webhelp specific settings from map
|
//removing webhelp specific settings from map
|
||||||
|
|||||||
Reference in New Issue
Block a user