<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>src/lib/com/izforge/izpack/adaptator/XMLException.java</filename>
    </added>
    <added>
      <filename>src/tests/com/izforge/izpack/adaptator/notvalid.xml</filename>
    </added>
    <added>
      <filename>src/tests/com/izforge/izpack/adaptator/xinclude-notvalid.xml</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -38,6 +38,7 @@ public interface IXMLParser
      *
      * @param inputStream Stream to parse
      * @return Root element of the parsed xml
+     * @throws XMLException if something went wrong.
      */
     IXMLElement parse(InputStream inputStream);
 
@@ -48,6 +49,7 @@ public interface IXMLParser
      * @param inputStream Stran to parse
      * @param systemId    System id of the file parsed
      * @return Root element of the parsed XML
+     * @throws XMLException if something went wrong.
      */
     IXMLElement parse(InputStream inputStream, String systemId);
 
@@ -56,6 +58,7 @@ public interface IXMLParser
      *
      * @param inputString Xml written in a string
      * @return Root element of the parsed xml
+     * @throws XMLException if something went wrong.
      */
     IXMLElement parse(String inputString);
 
@@ -64,6 +67,7 @@ public interface IXMLParser
      *
      * @param inputURL Url of the resource
      * @return Root element of the parsed xml
+     * @throws XMLException
      */
     IXMLElement parse(URL inputURL);
 }</diff>
      <filename>src/lib/com/izforge/izpack/adaptator/IXMLParser.java</filename>
    </modified>
    <modified>
      <diff>@@ -39,11 +39,9 @@ public interface IXMLWriter
      * Write the xml in the writer output
      *
      * @param element Xml to write
-     *
-     * @throws javax.xml.transform.TransformerException
-     *
+     * @throws XMLException if something went wrong.
      */
-    void write(IXMLElement element) throws TransformerException;
+    void write(IXMLElement element);
 
     /**
      * Set the outputStream of the writer</diff>
      <filename>src/lib/com/izforge/izpack/adaptator/IXMLWriter.java</filename>
    </modified>
    <modified>
      <diff>@@ -64,6 +64,16 @@ public class LineNumberFilter extends XMLFilterImpl
     }
 
     /**
+     * Return the locator on the current position.
+     *
+     * @return the current locator.
+     */
+    public Locator getDocumentLocator()
+    {
+        return locator;
+    }
+
+    /**
      * Return the first element found from the given Node.
      *
      * @param elt The Node start point.
@@ -139,6 +149,9 @@ public class LineNumberFilter extends XMLFilterImpl
         boolean end = false;
         Stack&lt;Element&gt; stack = new Stack&lt;Element&gt;();
 
+        /*
+         * We collected the line numbers, now we walk through the xml tree to apply them.
+         */
         while (!end)
         {
             if (hasChildElements(elt))</diff>
      <filename>src/lib/com/izforge/izpack/adaptator/impl/LineNumberFilter.java</filename>
    </modified>
    <modified>
      <diff>@@ -25,17 +25,13 @@ package com.izforge.izpack.adaptator.impl;
 
 import com.izforge.izpack.adaptator.IXMLElement;
 import com.izforge.izpack.adaptator.IXMLParser;
+import com.izforge.izpack.adaptator.XMLException;
 import org.w3c.dom.Node;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
+import org.xml.sax.*;
 
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParserFactory;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.*;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stream.StreamSource;
@@ -52,6 +48,7 @@ public class XMLParser implements IXMLParser
 {
 
     private LineNumberFilter filter;
+    private String parsedItem = null;
 
     public XMLParser()
     {
@@ -65,10 +62,10 @@ public class XMLParser implements IXMLParser
 
         } catch (ParserConfigurationException e)
         {
-            e.printStackTrace();
+            throw new XMLException(e);
         } catch (SAXException e)
         {
-            e.printStackTrace();
+            throw new XMLException(e);
         }
     }
 
@@ -98,16 +95,34 @@ public class XMLParser implements IXMLParser
             filter.applyLN(result);
         } catch (TransformerException e)
         {
-            e.printStackTrace();
+            String extraInfos = null;
+            if (this.parsedItem != null)
+            {
+                extraInfos = &quot; in &quot; + parsedItem;
+            }
+            // we try to get the location of the error.
+            // can't use an ErrorHander here !
+            if (e.getLocator() == null &amp;&amp; filter.getDocumentLocator() != null)
+            {
+                Locator locator = filter.getDocumentLocator();
+                extraInfos += &quot; at line &quot; + locator.getLineNumber() + &quot;, column &quot; + locator.getColumnNumber();
+            }
+            if (extraInfos != null) throw new XMLException(&quot;Error&quot; + extraInfos + &quot; : &quot; + e.getMessage(), e);
+            throw new XMLException(e);
         } catch (IOException e)
         {
-            e.printStackTrace();
+            throw new XMLException(e);
+        }
+        finally
+        {
+            this.parsedItem = null;
         }
         return result;
     }
 
     public IXMLElement parse(InputStream inputStream)
     {
+        this.parsedItem = null;
         InputSource inputSource = new InputSource(inputStream);
         DOMResult result = parseLineNrFromInputSource(inputSource);
         return searchFirstElement(result);
@@ -115,19 +130,22 @@ public class XMLParser implements IXMLParser
 
     public IXMLElement parse(InputStream inputStream, String systemId)
     {
+        this.parsedItem = systemId;
         InputSource inputSource = new InputSource(inputStream);
         inputSource.setSystemId(systemId);
         DOMResult result = parseLineNrFromInputSource(inputSource);
         return searchFirstElement(result);
     }
-    
+
     public IXMLElement parse(String inputString)
     {
+        this.parsedItem = null;
         return parse(new ByteArrayInputStream(inputString.getBytes()));
     }
 
     public IXMLElement parse(URL inputURL)
     {
+        this.parsedItem = inputURL.toString();
         InputSource inputSource = new InputSource(inputURL.toExternalForm());
         DOMResult domResult = parseLineNrFromInputSource(inputSource);
         return searchFirstElement(domResult);</diff>
      <filename>src/lib/com/izforge/izpack/adaptator/impl/XMLParser.java</filename>
    </modified>
    <modified>
      <diff>@@ -24,6 +24,7 @@ package com.izforge.izpack.adaptator.impl;
 
 import com.izforge.izpack.adaptator.IXMLElement;
 import com.izforge.izpack.adaptator.IXMLWriter;
+import com.izforge.izpack.adaptator.XMLException;
 
 import javax.xml.transform.*;
 import javax.xml.transform.dom.DOMSource;
@@ -64,23 +65,29 @@ public class XMLWriter implements IXMLWriter
         this.outputStream = outputStream;
     }
 
-    public void write(IXMLElement element) throws TransformerException
+    public void write(IXMLElement element)
     {
-        Source source = new DOMSource(element.getElement().getOwnerDocument());
-        TransformerFactory fabrique = TransformerFactory.newInstance();
-        Transformer transformer = fabrique.newTransformer();
-        transformer.setOutputProperty(OutputKeys.INDENT, &quot;yes&quot;);
-        transformer.setOutputProperty(OutputKeys.ENCODING, &quot;UTF-8&quot;);
-        Result result;
-        if (outputStream != null)
+        try
         {
-            result = new StreamResult(outputStream);
+            Source source = new DOMSource(element.getElement().getOwnerDocument());
+            TransformerFactory fabrique = TransformerFactory.newInstance();
+            Transformer transformer = fabrique.newTransformer();
+            transformer.setOutputProperty(OutputKeys.INDENT, &quot;yes&quot;);
+            transformer.setOutputProperty(OutputKeys.ENCODING, &quot;UTF-8&quot;);
+            Result result;
+            if (outputStream != null)
+            {
+                result = new StreamResult(outputStream);
+            } else
+            {
+                result = new StreamResult(systemId);
+            }
+            transformer.transform(source, result);
         }
-        else
+        catch (TransformerException e)
         {
-            result = new StreamResult(systemId);
+            throw new XMLException(e);
         }
-        transformer.transform(source, result);
     }
 
     public void setOutput(OutputStream outputStream)</diff>
      <filename>src/lib/com/izforge/izpack/adaptator/impl/XMLWriter.java</filename>
    </modified>
    <modified>
      <diff>@@ -35,6 +35,7 @@ import javax.xml.transform.TransformerException;
 
 import com.izforge.izpack.Pack;
 import com.izforge.izpack.adaptator.IXMLElement;
+import com.izforge.izpack.adaptator.XMLException;
 import com.izforge.izpack.adaptator.impl.XMLElementImpl;
 import com.izforge.izpack.adaptator.impl.XMLParser;
 import com.izforge.izpack.adaptator.impl.XMLWriter;
@@ -576,7 +577,7 @@ public class RulesEngine implements Serializable
             {
                 xmlOut.write(conditionsspec);
             }
-            catch (TransformerException e)
+            catch (XMLException e)
             {
                 Debug.error(&quot;Error writing condition specification: &quot; + e);
             }
@@ -595,7 +596,7 @@ public class RulesEngine implements Serializable
             {
                 xmlOut.write(conditionsel);
             }
-            catch (TransformerException e)
+            catch (XMLException e)
             {
                 Debug.error(&quot;Error writing condition specification: &quot; + e);
             }</diff>
      <filename>src/lib/com/izforge/izpack/rules/RulesEngine.java</filename>
    </modified>
    <modified>
      <diff>@@ -35,7 +35,8 @@ import java.util.Vector;
  * Test on the XMLElement
  *
  * @author Anthonin Bonnefoy
- * @author David Duponchel *
+ * @author David Duponchel
+ *
  */
 public class XMLElementTest extends TestCase
 {</diff>
      <filename>src/tests/com/izforge/izpack/adaptator/XMLElementTest.java</filename>
    </modified>
    <modified>
      <diff>@@ -51,6 +51,8 @@ public class XMLParserTest extends TestCase
     private static final String shortFilename = &quot;short.xml&quot;;
     private static final String lnFilename = &quot;linenumber/linenumber.xml&quot;;
     private static final String xlnFilename = &quot;linenumber/xinclude-linenumber.xml&quot;;
+    private static final String parseErrorFilename = &quot;notvalid.xml&quot;;
+    private static final String parseErrorXincludeFilename = &quot;xinclude-notvalid.xml&quot;;
 
     private IXMLElement root;
 
@@ -121,4 +123,37 @@ public class XMLParserTest extends TestCase
 
         checkEltLN(elt);
     }
+
+    public void testXMLExceptionThrown()
+    {
+        InputStream input = XMLParserTest.class.getResourceAsStream(parseErrorFilename);
+
+        IXMLParser parser = new XMLParser();
+        try
+        {
+            parser.parse(input, parseErrorFilename);
+            fail(&quot;No exception were thrown will reading an invalid xml !&quot;);
+        }
+        catch (XMLException e)
+        {
+            //e.printStackTrace();
+        }
+    }
+
+    public void testXMLExceptionThrownXInclude()
+    {
+        InputStream input = XMLParserTest.class.getResourceAsStream(parseErrorXincludeFilename);
+
+        IXMLParser parser = new XMLParser();
+        try
+        {
+            parser.parse(input, parseErrorXincludeFilename);
+            fail(&quot;No exception were thrown will reading an xincluded invalid xml !&quot;);
+        }
+        catch (XMLException e)
+        {
+            //e.printStackTrace();
+        }
+    }
+
 }
\ No newline at end of file</diff>
      <filename>src/tests/com/izforge/izpack/adaptator/XMLParserTest.java</filename>
    </modified>
    <modified>
      <diff>@@ -24,11 +24,11 @@ package com.izforge.izpack.adaptator;
 
 import com.izforge.izpack.adaptator.impl.XMLParser;
 import com.izforge.izpack.adaptator.impl.XMLWriter;
+import com.izforge.izpack.adaptator.impl.XMLElementImpl;
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
-import javax.xml.transform.TransformerException;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -67,9 +67,8 @@ public class XMLWriterTest extends TestCase
      * Try to write a file with an outputStream
      *
      * @throws FileNotFoundException
-     * @throws TransformerException
      */
-    public void testWriteFile() throws FileNotFoundException, TransformerException
+    public void testWriteFile() throws FileNotFoundException
     {
         IXMLWriter writer = new XMLWriter();
         File file = new File(output);
@@ -86,9 +85,8 @@ public class XMLWriterTest extends TestCase
      * Try to write a file with an Url to a resource
      *
      * @throws FileNotFoundException
-     * @throws TransformerException
      */
-    public void testWriteURL() throws FileNotFoundException, TransformerException
+    public void testWriteURL() throws FileNotFoundException
     {
         IXMLWriter writer = new XMLWriter();
         File file = new File(output);
@@ -100,5 +98,19 @@ public class XMLWriterTest extends TestCase
         assertEquals(root.getName(), element.getName());
     }
 
-
+    public void testFail()
+    {
+        // TODO : don't use XMLElementImpl !
+        IXMLElement elt = new XMLElementImpl(&quot;root&quot;);
+        IXMLWriter writer = new XMLWriter();
+        writer.setOutput(&quot;&quot;); // will take the current directory, which is not a file !
+        try
+        {
+            writer.write(elt);
+            fail(&quot;No exception were thrown will writing on an invalid file !&quot;);
+        }
+        catch (XMLException e)
+        {
+        }
+    }
 }
\ No newline at end of file</diff>
      <filename>src/tests/com/izforge/izpack/adaptator/XMLWriterTest.java</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>8760b46529442319693a0a84926bfe028bac1028</id>
    </parent>
  </parents>
  <author>
    <name>d.duponchel</name>
    <email>d.duponchel@7d736ef5-cfd4-0310-9c9a-b52d5c14b761</email>
  </author>
  <url>http://github.com/jponge/izpack/commit/51cf9836fde088d620ff37069e0c34052500ef24</url>
  <id>51cf9836fde088d620ff37069e0c34052500ef24</id>
  <committed-date>2009-06-17T14:26:22-07:00</committed-date>
  <authored-date>2009-06-17T14:26:22-07:00</authored-date>
  <message>fix for bug IZPACK-407 : No meaningful xml exception

git-svn-id: https://svn.codehaus.org/izpack/izpack-src/trunk@2810 7d736ef5-cfd4-0310-9c9a-b52d5c14b761</message>
  <tree>3ef99a5809aa0ef76737725180098d36ba243342</tree>
  <committer>
    <name>d.duponchel</name>
    <email>d.duponchel@7d736ef5-cfd4-0310-9c9a-b52d5c14b761</email>
  </committer>
</commit>
