[izpack-changes] r1980 - in izpack-src/trunk: . src/lib/com/izforge/izpack/compiler src/lib/net/n3/nanoxml
noreply at berlios.de
noreply at berlios.de
Sat Jan 12 14:37:31 CET 2008
Author: jponge
Date: 2008-01-12 14:37:27 +0100 (Sat, 12 Jan 2008)
New Revision: 1980
Modified:
izpack-src/trunk/Versions.txt
izpack-src/trunk/src/lib/com/izforge/izpack/compiler/CompilerConfig.java
izpack-src/trunk/src/lib/net/n3/nanoxml/XIncludeXMLBuilder.java
Log:
'parsexml' attribute for resources (Matthew Fudge via Julien Ponge)
Modified: izpack-src/trunk/Versions.txt
===================================================================
--- izpack-src/trunk/Versions.txt 2008-01-12 11:21:02 UTC (rev 1979)
+++ izpack-src/trunk/Versions.txt 2008-01-12 13:37:27 UTC (rev 1980)
@@ -81,6 +81,7 @@
- FileExecutor: fix a blank dialog prompting the user to continue if there's a failure (Jeff Gordon via Julien Ponge)
- Italian translation update (Roberto Boriotti, Sylvain Gaudard via Julien Ponge)
- PacksPanelAutomationHelper fix (Jeff Gordon via Julien Ponge)
+- 'parsexml' attribute for resources (Matthew Fudge via Julien Ponge)
> 3.10.2 (build 2007.05.11)
Modified: izpack-src/trunk/src/lib/com/izforge/izpack/compiler/CompilerConfig.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/compiler/CompilerConfig.java 2008-01-12 11:21:02 UTC (rev 1979)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/compiler/CompilerConfig.java 2008-01-12 13:37:27 UTC (rev 1980)
@@ -26,14 +26,44 @@
package com.izforge.izpack.compiler;
+import com.izforge.izpack.CustomData;
+import com.izforge.izpack.ExecutableFile;
+import com.izforge.izpack.GUIPrefs;
+import com.izforge.izpack.Info;
+import com.izforge.izpack.PackFile;
+import com.izforge.izpack.Panel;
+import com.izforge.izpack.ParsableFile;
+import com.izforge.izpack.UpdateCheck;
+import com.izforge.izpack.compiler.Compiler.CmdlinePackagerListener;
+import com.izforge.izpack.event.CompilerListener;
+import com.izforge.izpack.rules.Condition;
+import com.izforge.izpack.rules.RulesEngine;
+import com.izforge.izpack.util.Debug;
+import com.izforge.izpack.util.OsConstraint;
+import com.izforge.izpack.util.VariableSubstitutor;
+import net.n3.nanoxml.IXMLParser;
+import net.n3.nanoxml.IXMLReader;
+import net.n3.nanoxml.NonValidator;
+import net.n3.nanoxml.StdXMLParser;
+import net.n3.nanoxml.StdXMLReader;
+import net.n3.nanoxml.XMLBuilderFactory;
+import net.n3.nanoxml.XMLElement;
+import net.n3.nanoxml.XMLException;
+import net.n3.nanoxml.XMLParserFactory;
+import net.n3.nanoxml.XMLWriter;
+import org.apache.tools.ant.DirectoryScanner;
+
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
@@ -55,32 +85,6 @@
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
-import org.apache.tools.ant.DirectoryScanner;
-
-import com.izforge.izpack.CustomData;
-import com.izforge.izpack.ExecutableFile;
-import com.izforge.izpack.GUIPrefs;
-import com.izforge.izpack.Info;
-import com.izforge.izpack.PackFile;
-import com.izforge.izpack.Panel;
-import com.izforge.izpack.ParsableFile;
-import com.izforge.izpack.UpdateCheck;
-import com.izforge.izpack.compiler.Compiler.CmdlinePackagerListener;
-import com.izforge.izpack.event.CompilerListener;
-import com.izforge.izpack.rules.Condition;
-import com.izforge.izpack.rules.RulesEngine;
-import com.izforge.izpack.util.Debug;
-import com.izforge.izpack.util.OsConstraint;
-import com.izforge.izpack.util.VariableSubstitutor;
-
-import net.n3.nanoxml.IXMLReader;
-import net.n3.nanoxml.NonValidator;
-import net.n3.nanoxml.StdXMLParser;
-import net.n3.nanoxml.StdXMLReader;
-import net.n3.nanoxml.XMLElement;
-import net.n3.nanoxml.XMLException;
-import net.n3.nanoxml.XMLBuilderFactory;
-
/**
* A parser for the installer xml configuration. This parses a document
* conforming to the installation.dtd and populates a Compiler instance to
@@ -1294,46 +1298,96 @@
XMLElement res = (XMLElement) iter.next();
String id = requireAttribute(res, "id");
String src = requireAttribute(res, "src");
- boolean parse = validateYesNoAttribute(res, "parse", NO);
+ boolean substitute = validateYesNoAttribute(res, "substitute", NO);
+ boolean parsexml = validateYesNoAttribute(res, "parsexml", NO);
// basedir is not prepended if src is already an absolute path
- URL url = findProjectResource(src, "Resource", res);
+ URL originalUrl = findProjectResource(src, "Resource", res);
+ URL url = originalUrl;
- // substitute variable values in the resource if parsed
- if (parse)
+ InputStream is = null;
+ OutputStream os = null;
+ try
{
- if (compiler.getVariables().isEmpty())
+ if (parsexml ||
+ (substitute && !compiler.getVariables().isEmpty()))
{
- parseWarn(res, "No variables defined. " + url.getPath() + " not parsed.");
+ // make the substitutions into a temp file
+ File parsedFile = File.createTempFile("izpp", null);
+ parsedFile.deleteOnExit();
+ FileOutputStream outFile = new FileOutputStream(parsedFile);
+ os = new BufferedOutputStream(outFile);
+ // and specify the substituted file to be added to the
+ // packager
+ url = parsedFile.toURL();
}
- else
+
+ if (parsexml)
+ {
+ IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
+ // this constructor will open the specified url (this is
+ // why the InputStream is not handled in a similar manner
+ // to the OutputStream)
+ IXMLReader reader = new StdXMLReader(null, url.toExternalForm());
+ parser.setReader(reader);
+ XMLElement xml = (XMLElement) parser.parse();
+
+ if (substitute && !compiler.getVariables().isEmpty()) {
+ // if we are also performing substitutions on the file
+ // then create an in-memory copy to pass to the
+ // substitutor
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ XMLWriter xmlWriter = new XMLWriter(baos);
+ xmlWriter.write(xml);
+ is = new ByteArrayInputStream(baos.toByteArray());
+ } else {
+ // otherwise write direct to the temp file
+ XMLWriter xmlWriter = new XMLWriter(os);
+ xmlWriter.write(xml);
+ }
+ }
+
+ // substitute variable values in the resource if parsed
+ if (substitute)
{
- String type = res.getAttribute("type");
- String encoding = res.getAttribute("encoding");
- File parsedFile = null;
-
- try
+ if (compiler.getVariables().isEmpty())
{
- // make the substitutions into a temp file
- InputStream bin = new BufferedInputStream(url.openStream());
+ // reset url to original.
+ url = originalUrl;
+ parseWarn(res, "No variables defined. " + url.getPath() + " not parsed.");
+ }
+ else
+ {
+ String type = res.getAttribute("type");
+ String encoding = res.getAttribute("encoding");
- parsedFile = File.createTempFile("izpp", null);
- parsedFile.deleteOnExit();
- FileOutputStream outFile = new FileOutputStream(parsedFile);
- BufferedOutputStream bout = new BufferedOutputStream(outFile);
-
+ // if the xml parser did not open the url
+ // ('parsexml' was not enabled)
+ if (null == is) {
+ is = new BufferedInputStream(url.openStream());
+ }
VariableSubstitutor vs = new VariableSubstitutor(compiler.getVariables());
- vs.substitute(bin, bout, type, encoding);
- bin.close();
- bout.close();
+ vs.substitute(is, os, type, encoding);
+ }
+ }
- // and specify the substituted file to be added to the
- // packager
- url = parsedFile.toURL();
+ } catch (Exception e)
+ {
+ parseError(res, e.getMessage(), e);
+ } finally {
+ if (null != os) {
+ try {
+ os.close();
+ } catch (IOException e) {
+ // ignore as there is nothing we can realistically do
+ // so lets at least try to close the input stream
}
- catch (IOException x)
- {
- parseError(res, x.getMessage(), x);
+ }
+ if (null != is) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // ignore as there is nothing we can realistically do
}
}
}
Modified: izpack-src/trunk/src/lib/net/n3/nanoxml/XIncludeXMLBuilder.java
===================================================================
--- izpack-src/trunk/src/lib/net/n3/nanoxml/XIncludeXMLBuilder.java 2008-01-12 11:21:02 UTC (rev 1979)
+++ izpack-src/trunk/src/lib/net/n3/nanoxml/XIncludeXMLBuilder.java 2008-01-12 13:37:27 UTC (rev 1980)
@@ -31,9 +31,9 @@
*/
public class XIncludeXMLBuilder extends StdXMLBuilder {
/**
- * Namespace to for XInclude (NOTE that this is not used
+ * Namespace for XInclude (NOTE that this is not used
* at the moment). The specification can be found
- * here'>http://www.w3.org/TR/xinclude/">here.
+ * <a href="http://www.w3.org/TR/xinclude/">here</a>.
*/
public static final String INCLUDE_NS = "http://www.w3.org/2001/XInclude";
/**
@@ -82,7 +82,7 @@
public static final String FRAGMENT_NS = "https://izpack.github.io/izpack/fragment";
/**
- * The name of the fragment element is a root node element that can be
+ * The fragment element is a root node element that can be
* used to wrap xml fragments for inclusion. It is removed during the
* include operation. This should be called "fragment" and be in the
* {@link #FRAGMENT_NS} but namespaces are not supported.
More information about the izpack-changes
mailing list