|
From: <tr...@us...> - 2003-08-05 23:28:32
|
Update of /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/pipeline/stage
In directory sc8-pr-cvs1:/tmp/cvs-serv21227/src/com/babeldoc/core/pipeline/stage
Modified Files:
XslTransformPipelineStage.java
Log Message:
Now able to add arbitraty numbers of parameters to the XSL transformer thereby making the whole thing more powerful (I hope)
Index: XslTransformPipelineStage.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/pipeline/stage/XslTransformPipelineStage.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** XslTransformPipelineStage.java 4 Aug 2003 23:41:03 -0000 1.16
--- XslTransformPipelineStage.java 5 Aug 2003 23:28:30 -0000 1.17
***************
*** 68,73 ****
--- 68,75 ----
import com.babeldoc.core.I18n;
import com.babeldoc.core.ResourceLoader;
+ import com.babeldoc.core.NameValuePair;
import com.babeldoc.core.option.ConfigOption;
import com.babeldoc.core.option.IConfigOptionType;
+ import com.babeldoc.core.option.ComplexConfigOptionType;
import com.babeldoc.core.pipeline.*;
***************
*** 76,83 ****
import java.net.URL;
! import java.util.ArrayList;
! import java.util.Collection;
! import java.util.Map;
! import java.util.WeakHashMap;
import javax.xml.transform.*;
--- 78,82 ----
import java.net.URL;
! import java.util.*;
import javax.xml.transform.*;
***************
*** 95,99 ****
* script XSLT is also cached, again leading to performance improvements.
* </p>
! *
* <p>
* There are a number of parameters which are set in the tranformer which will
--- 94,98 ----
* script XSLT is also cached, again leading to performance improvements.
* </p>
! *
* <p>
* There are a number of parameters which are set in the tranformer which will
***************
*** 112,115 ****
--- 111,117 ----
public static final String TRANSFORMATION_SCRIPT = "transformationScript";
private static Map map = null;
+ public static final String PARAM = "param";
+ public static final String PARAM_PIPELINESTAGE = "pipelinestage";
+ public static final String PARAM_DOCUMENT = "document";
/**
***************
*** 123,127 ****
public String getDescription() {
! return I18n.get("core.stage.xslTransform.desc");
}
--- 125,129 ----
public String getDescription() {
! return I18n.get("core.pipeline.stage.xslTransform.desc");
}
***************
*** 131,138 ****
options.add(new ConfigOption(TRANSFORMATION_FILE,
IConfigOptionType.FILENAME, null, false,
! I18n.get("core.stage.xslTransform.file")));
options.add(new ConfigOption(TRANSFORMATION_SCRIPT,
IConfigOptionType.MULTI, null, false,
! I18n.get("core.stage.xslTransform.script")));
return options;
--- 133,148 ----
options.add(new ConfigOption(TRANSFORMATION_FILE,
IConfigOptionType.FILENAME, null, false,
! I18n.get("core.pipeline.stage.xslTransform.file")));
options.add(new ConfigOption(TRANSFORMATION_SCRIPT,
IConfigOptionType.MULTI, null, false,
! I18n.get("core.pipeline.stage.xslTransform.script")));
!
! // This allows for arbitrary numbers of parameters to be added to the
! // XSL transformer.
! IConfigOptionType param = new ComplexConfigOptionType(new ConfigOption[] { new ConfigOption(
! PARAM, IConfigOptionType.STRING, I18n.get("core.pipeline.stage.xslTransform.param")) });
!
! //add specific options
! options.add(new ConfigOption(PARAM, param, I18n.get("core.pipeline.stage.xslTransform.param")));
return options;
***************
*** 344,353 ****
private PipelineDocument transformDocument(String xslfile, String xslscript)
throws TransformerException, PipelineException, IOException {
! // Create a transform factory instance.
Transformer transformer = getTransformer(xslfile, xslscript);
! // Create a transformer for the stylesheet.
! transformer.setParameter("pipelinestage", this);
! transformer.setParameter("document", this.getDocument());
byte[] data = transformInputStream(transformer,
--- 354,361 ----
private PipelineDocument transformDocument(String xslfile, String xslscript)
throws TransformerException, PipelineException, IOException {
! // Get a transform.
Transformer transformer = getTransformer(xslfile, xslscript);
! addParametersToTransformer(transformer);
byte[] data = transformInputStream(transformer,
***************
*** 360,363 ****
--- 368,392 ----
return newDoc;
}
+
+ /**
+ * Add the parameters to the transformer. There are mandatory and
+ * configurable parameters.
+ *
+ * @param transformer
+ */
+ private void addParametersToTransformer(Transformer transformer) {
+ // Now add the mandatory parameters
+ transformer.setParameter(PARAM_PIPELINESTAGE, this);
+ transformer.setParameter(PARAM_DOCUMENT, this.getDocument());
+
+ // And any other parameters that might be configured.
+ NameValuePair[] params = this.getOptionList(new String[] { PARAM });
+ if ((params != null) && (params.length > 0)) {
+ for (int i = 0; i < params.length; i++) {
+ NameValuePair param = params[i];
+ transformer.setParameter(param.getName(), param.getValue());
+ }
+ }
+ }
}
***************
*** 379,385 ****
/**
! * TODO: DOCUMENT ME!
*
! * @return DOCUMENT ME!
*/
public Templates getTemplate() {
--- 408,414 ----
/**
! * Get the template on the cache item
*
! * @return
*/
public Templates getTemplate() {
***************
*** 408,412 ****
/**
! * TODO: DOCUMENT ME!
*
* @return DOCUMENT ME!
--- 437,441 ----
/**
! * Get the file name for the cached object
*
* @return DOCUMENT ME!
***************
*** 417,421 ****
/**
! * TODO: DOCUMENT ME!
*
* @return DOCUMENT ME!
--- 446,450 ----
/**
! * Get the modified timestamp
*
* @return DOCUMENT ME!
|