Java Code Examples for javax.xml.transform.sax.TransformerHandler#setResult()

The following examples show how to use javax.xml.transform.sax.TransformerHandler#setResult() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmlUtil.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs identity transformation.
 */
public static <T extends Result>
T identityTransform(Source src, T result) throws TransformerException, SAXException, ParserConfigurationException, IOException {
    if (src instanceof StreamSource) {
        // work around a bug in JAXP in JDK6u4 and earlier where the namespace processing
        // is not turned on by default
        StreamSource ssrc = (StreamSource) src;
        TransformerHandler th = ((SAXTransformerFactory) transformerFactory.get()).newTransformerHandler();
        th.setResult(result);
        XMLReader reader = saxParserFactory.get().newSAXParser().getXMLReader();
        reader.setContentHandler(th);
        reader.setProperty(LEXICAL_HANDLER_PROPERTY, th);
        reader.parse(toInputSource(ssrc));
    } else {
        newTransformer().transform(src, result);
    }
    return result;
}
 
Example 2
Source File: XmlUtil.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs identity transformation.
 */
public static <T extends Result>
T identityTransform(Source src, T result) throws TransformerException, SAXException, ParserConfigurationException, IOException {
    if (src instanceof StreamSource) {
        // work around a bug in JAXP in JDK6u4 and earlier where the namespace processing
        // is not turned on by default
        StreamSource ssrc = (StreamSource) src;
        TransformerHandler th = ((SAXTransformerFactory) transformerFactory.get()).newTransformerHandler();
        th.setResult(result);
        XMLReader reader = saxParserFactory.get().newSAXParser().getXMLReader();
        reader.setContentHandler(th);
        reader.setProperty(LEXICAL_HANDLER_PROPERTY, th);
        reader.parse(toInputSource(ssrc));
    } else {
        newTransformer().transform(src, result);
    }
    return result;
}
 
Example 3
Source File: Bug6451633.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
    TransformerHandler th = ((SAXTransformerFactory) TransformerFactory.newInstance()).newTransformerHandler();

    DOMResult result = new DOMResult();
    th.setResult(result);

    th.startDocument();
    th.startElement("", "root", "root", new AttributesImpl());
    th.characters(new char[0], 0, 0);
    th.endElement("", "root", "root");
    th.endDocument();

    // there's no point in having empty text --- we should remove it
    Assert.assertEquals(0, ((Document) result.getNode()).getDocumentElement().getChildNodes().getLength());
}
 
Example 4
Source File: MCRXSLTransformer.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
protected MCRContent getTransformedContent(MCRContent source, XMLReader reader,
    TransformerHandler transformerHandler) throws IOException, SAXException {
    MCRByteArrayOutputStream baos = new MCRByteArrayOutputStream(INITIAL_BUFFER_SIZE);
    StreamResult serializer = new StreamResult(baos);
    transformerHandler.setResult(serializer);
    // Parse the source XML, and send the parse events to the
    // TransformerHandler.
    LOGGER.debug("Start transforming: {}", source.getSystemId() == null ? source.getName() : source.getSystemId());
    reader.parse(source.getInputSource());
    return new MCRByteContent(baos.getBuffer(), 0, baos.size());
}
 
Example 5
Source File: MCRXSL2XMLTransformer.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected MCRContent getTransformedContent(MCRContent source, XMLReader reader,
    TransformerHandler transformerHandler) throws IOException, SAXException {
    JDOMResult result = new JDOMResult();
    transformerHandler.setResult(result);
    // Parse the source XML, and send the parse events to the
    // TransformerHandler.
    reader.parse(source.getInputSource());
    Document resultDoc = getDocument(result);
    if (resultDoc == null) {
        throw new MCRConfigurationException("Stylesheets " + Arrays.asList(templateSources)
            + " does not return any content for " + source.getSystemId());
    }
    return new MCRJDOMContent(resultDoc);
}
 
Example 6
Source File: SAXTFactoryTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Unit test newTransformerHandler with a DOMSource.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testcase06() throws Exception {
    String outputFile = USER_DIR + "saxtf006.out";
    String goldFile = GOLDEN_DIR + "saxtf006GF.out";

    try (FileOutputStream fos = new FileOutputStream(outputFile)) {
        XMLReader reader = XMLReaderFactory.createXMLReader();
        SAXTransformerFactory saxTFactory
                = (SAXTransformerFactory)TransformerFactory.newInstance();

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder docBuilder = dbf.newDocumentBuilder();
        Node node = (Node)docBuilder.parse(new File(XSLT_INCL_FILE));

        DOMSource domSource = new DOMSource(node, "file:///" + XML_DIR);
        TransformerHandler handler =
                    saxTFactory.newTransformerHandler(domSource);

        Result result = new StreamResult(fos);
        handler.setResult(result);
        reader.setContentHandler(handler);
        reader.parse(XML_FILE);
    }
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
Example 7
Source File: SAXTFactoryTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Unit test for XMLReader parsing when relative URI is used in xsl file and
 * SystemId was set.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testcase05() throws Exception {
    String outputFile = USER_DIR + "saxtf005.out";
    String goldFile = GOLDEN_DIR + "saxtf005GF.out";

    try (FileOutputStream fos = new FileOutputStream(outputFile)) {
        XMLReader reader = XMLReaderFactory.createXMLReader();
        SAXTransformerFactory saxTFactory
                = (SAXTransformerFactory)TransformerFactory.newInstance();
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder docBuilder = dbf.newDocumentBuilder();
        Document document = docBuilder.parse(new File(XSLT_INCL_FILE));
        Node node = (Node)document;
        DOMSource domSource= new DOMSource(node);

        domSource.setSystemId("file:///" + XML_DIR);

        TransformerHandler handler =
                    saxTFactory.newTransformerHandler(domSource);
        Result result = new StreamResult(fos);

        handler.setResult(result);
        reader.setContentHandler(handler);
        reader.parse(XML_FILE);
    }
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
Example 8
Source File: XSLTJaxbProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void marshalToOutputStream(Marshaller ms, Object obj, OutputStream os,
                                     Annotation[] anns, MediaType mt)
    throws Exception {

    Templates t = createTemplates(getOutTemplates(anns, mt), outParamsMap, outProperties);
    if (t == null && supportJaxbOnly) {
        super.marshalToOutputStream(ms, obj, os, anns, mt);
        return;
    }
    org.apache.cxf.common.jaxb.JAXBUtils.setMinimumEscapeHandler(ms);
    TransformerHandler th = null;
    try {
        th = factory.newTransformerHandler(t);
    } catch (TransformerConfigurationException ex) {
        TemplatesImpl ti = (TemplatesImpl)t;
        th = factory.newTransformerHandler(ti.getTemplates());
        this.trySettingProperties(th, ti);
    }
    Result result = getStreamResult(os, anns, mt);
    if (systemId != null) {
        result.setSystemId(systemId);
    }
    th.setResult(result);

    if (getContext() == null) {
        th.startDocument();
    }
    ms.marshal(obj, th);
    if (getContext() == null) {
        th.endDocument();
    }
}
 
Example 9
Source File: Processor.java    From jtransc with Apache License 2.0 5 votes vote down vote up
public final ContentHandler createContentHandler() {
    try {
        TransformerHandler handler = saxtf
                .newTransformerHandler(templates);
        handler.setResult(new SAXResult(outputHandler));
        return handler;
    } catch (TransformerConfigurationException ex) {
        throw new RuntimeException(ex.toString());
    }
}
 
Example 10
Source File: DOMResultTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Unit test for simple DOM parsing.
 * @throws Exception If any errors occur.
 */
@Test
public void testcase01() throws Exception {
    String resultFile = USER_DIR  + "domresult01.out";
    String goldFile = GOLDEN_DIR  + "domresult01GF.out";
    String xsltFile = XML_DIR + "cities.xsl";
    String xmlFile = XML_DIR + "cities.xml";

    XMLReader reader = XMLReaderFactory.createXMLReader();
    SAXTransformerFactory saxTFactory
            = (SAXTransformerFactory) TransformerFactory.newInstance();
    SAXSource saxSource = new SAXSource(new InputSource(xsltFile));
    TransformerHandler handler
            = saxTFactory.newTransformerHandler(saxSource);

    DOMResult result = new DOMResult();

    handler.setResult(result);
    reader.setContentHandler(handler);
    reader.parse(xmlFile);

    Node node = result.getNode();
    try (BufferedWriter writer = new BufferedWriter(new FileWriter(resultFile))) {
        writeNodes(node, writer);
    }
    assertTrue(compareWithGold(goldFile, resultFile));
}
 
Example 11
Source File: MessageOutputStreamTest.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore("No contract to call endDocument() in case of an Exception")
public void testX32ContentHandlerAsWriterError() throws Exception {
	
	CloseObservableWriter cow = new CloseObservableWriter() {

		@Override
		public void write(char[] arg0, int arg1, int arg2) {
			throw new RuntimeException("fakeFailure");
		}
		
	};
	Result result = new StreamResult(cow);
	SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance();
	TransformerHandler transformerHandler = tf.newTransformerHandler();
	transformerHandler.setResult(result);

	try (MessageOutputStream stream = new MessageOutputStream(null, transformerHandler, (IForwardTarget)null, null, null)) {
	
		try {
			try (Writer writer = stream.asWriter()) {
				writer.write(testString);
			}
			fail("exception should be thrown");
		} catch (Exception e) {
			assertThat(e.getMessage(),StringContains.containsString("fakeFailure"));
		}
		
	}
	assertTrue(cow.isCloseCalled());
}
 
Example 12
Source File: DOMBuilder.java    From sling-whiteboard with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a new instance of this DOMBuilder.
 *
 * @throws IOException If for some reason the <code>TransformerHandler</code> cannot be created.
 */
public DOMBuilder() throws IOException {
    try {
        final TransformerHandler handler = FACTORY.newTransformerHandler();
        this.contentHandler = handler;
        this.lexicalHandler = handler;
        this.result = new DOMResult();
        handler.setResult(this.result);
    } catch (TransformerException te) {
        throw new IOException("Unable to get transformer handler", te);
    }
}
 
Example 13
Source File: OBRXMLWriter.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public static ContentHandler newHandler(OutputStream out, String encoding, boolean indent)
        throws TransformerConfigurationException {
    SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
    TransformerHandler hd = tf.newTransformerHandler();
    Transformer serializer = tf.newTransformer();
    StreamResult stream = new StreamResult(out);
    serializer.setOutputProperty(OutputKeys.ENCODING, encoding);
    serializer.setOutputProperty(OutputKeys.INDENT, indent ? "yes" : "no");
    hd.setResult(stream);
    return hd;
}
 
Example 14
Source File: IvyArtifactReport.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private TransformerHandler createTransformerHandler(FileOutputStream fileOutputStream)
        throws TransformerFactoryConfigurationError, TransformerConfigurationException {
    SAXTransformerFactory transformerFact = (SAXTransformerFactory) SAXTransformerFactory
            .newInstance();
    TransformerHandler saxHandler = transformerFact.newTransformerHandler();
    saxHandler.getTransformer().setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    saxHandler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes");
    saxHandler.setResult(new StreamResult(fileOutputStream));
    return saxHandler;
}
 
Example 15
Source File: AstroProcessor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void process(String outputfile, TransformerHandler... filters) throws Exception {
    XMLReader catparser = getXMLReader();

    File catalogfile = new File(catalogFileName);
    InputSource catsrc = isfact.newInputSource(catalogfile.getPath());

    TransformerHandler outfilter = ffact.newHTMLOutput();
    // create an array from the Vector of filters...

    // hook the filters up to each other, there may be zero filters
    int nfilters = filters.length;
    if (nfilters != 0) {
        TransformerHandler prev = null;
        for (int i = 0; i < filters.length; i++) {
            TransformerHandler curr = filters[i];
            if (prev != null) {
                prev.setResult(new SAXResult(curr));
            }
            prev = curr;
        }
        // hook up the last filter to the output filter
        prev.setResult(new SAXResult(outfilter));
        // hook up the catalog parser to the first filter...
        catparser.setContentHandler(filters[0]);
    } else {
        // There are no query filters,
        // hook up the catalog parser directly to output filter...
        catparser.setContentHandler(outfilter);
    }
    // hook up the output filter to the output file or std out
    if (outputfile != null) {
        outfilter.setResult(new StreamResult(outputfile));
    } else {
        outfilter.setResult(new StreamResult(System.out));
    }

    catparser.parse(catsrc);
}
 
Example 16
Source File: XMLDocument.java    From jlibs with Apache License 2.0 4 votes vote down vote up
public XMLDocument(Result result, boolean omitXMLDeclaration, int indentAmount, String encoding) throws TransformerConfigurationException{
    TransformerHandler handler = TransformerUtil.newTransformerHandler(null, omitXMLDeclaration, indentAmount, encoding);
    handler.setResult(result);
    xml = new SAXDelegate(handler);
}
 
Example 17
Source File: XmlWriter.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Creates output XML from all read records using SAX.
 * Call this after all records are stored in PortDefinition structures.  
 * @throws TransformerConfigurationException
 * @throws SAXException
 * @throws IOException
 */
/*
private void flushXmlSax() throws TransformerConfigurationException, SAXException, IOException {

	FileOutputStream fos = new FileOutputStream(fileUrl);
	TransformerHandler hd = createHeader(fos);
	PortDefinition portDefinition = rootPortDefinition;
	// for each record of port
	for (Map.Entry<HashKey, TreeRecord> e : portDefinition.dataMap.entrySet()){
		TreeRecord record = e.getValue();
		List<DataRecord> records = new ArrayList<DataRecord>();
		records.add(record.record);
		addRecords(hd, records, portDefinition);
	}// for record

	createFooter(fos, hd);
}*/

private TransformerHandler createHeader(OutputStream os) throws FileNotFoundException, TransformerConfigurationException, SAXException {
	StreamResult streamResult = new StreamResult(os);
	SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
	// SAX2.0 ContentHandler.
	TransformerHandler hd = tf.newTransformerHandler();
	Transformer serializer = hd.getTransformer();
       
	serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
	serializer.setOutputProperty(OutputKeys.ENCODING, this.charset);
	//serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"users.dtd");
	if (omitNewLines)
		serializer.setOutputProperty(OutputKeys.INDENT,"no");
	else
		serializer.setOutputProperty(OutputKeys.INDENT,"yes");
	
	hd.setResult(streamResult);
	hd.startDocument();

	String root = (rootElement!=null && rootElement.length()>0) ? rootElement : DEFAULT_ROOT_ELEMENT; 

	if (useRootElement && dtdPublicId != null && dtdPublicId.trim().length()>0 && dtdSystemId != null && dtdSystemId.trim().length()>0){
		hd.startDTD(root, dtdPublicId, dtdSystemId);
		hd.endDTD();
	}
	
	//if (recordsPerFile!=1){
	if (this.useRootElement) {
		AttributesImpl atts = new AttributesImpl();
		if (rootInfoAttributes) {
			atts.addAttribute("", ATTRIBUTE_COMPONENT_ID, ATTRIBUTE_COMPONENT_ID, "CDATA", getId());
			atts.addAttribute("", ATTRIBUTE_GRAPH_NAME, ATTRIBUTE_GRAPH_NAME, "CDATA", this.getGraph().getName());
			atts.addAttribute("", ATTRIBUTE_CREATED, ATTRIBUTE_CREATED, "CDATA", (new Date()).toString());
		}
		if (!StringUtils.isEmpty(xsdSchemaLocation)) {
			atts.addAttribute(XSI_URI, "schemaLocation", "xsi:schemaLocation", "CDATA", this.xsdSchemaLocation);
		}

		for (String prefix : namespaces.keySet()) {
			String uri = namespaces.get(prefix);
			hd.startPrefixMapping(prefix, uri);
		}
		if (!rootDefaultNamespace.isEmpty()) {
			hd.startPrefixMapping("", rootDefaultNamespace);
		}

		hd.startElement(rootDefaultNamespace, getLocalName(root), root, atts);
	}
	return hd;
}
 
Example 18
Source File: XSLTEntityHandler.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public ContentHandler getOutputHandler(OutputStream out) throws IOException
{
	if (!isAvailable()) return null;

	try
	{
		XSLTTransform xsltTransform = (XSLTTransform) transformerHolder.get();
		if (xsltTransform == null)
		{
			xsltTransform = new XSLTTransform();
			xsltTransform.setXslt(new InputSource(this.getClass()
					.getResourceAsStream(xslt)));
			transformerHolder.set(xsltTransform);
		}
		SAXResult sr = new SAXResult();
		
		TransformerHandler th = xsltTransform.getContentHandler();
		
		Transformer transformer = th.getTransformer();
		if (transformParameters != null) {
			for (Map.Entry<String, String> entry: transformParameters.entrySet()) {
				transformer.setParameter(entry.getKey(), entry.getValue());
			}
		}

		Properties p = OutputPropertiesFactory.getDefaultMethodProperties("xml");
		p.putAll(outputProperties);
		
		/*
		S_KEY_CONTENT_HANDLER:{http://xml.apache.org/xalan}content-handler
			S_KEY_ENTITIES:{http://xml.apache.org/xalan}entities
			S_KEY_INDENT_AMOUNT:{http://xml.apache.org/xalan}indent-amount
			S_OMIT_META_TAG:{http://xml.apache.org/xalan}omit-meta-tag
			S_USE_URL_ESCAPING:{http://xml.apache.org/xalan}use-url-escaping
		*/
		
		Serializer s = SerializerFactory.getSerializer(p);
		s.setOutputStream(out);
		sr.setHandler(s.asContentHandler());
		th.setResult(sr);
		return th;
	}
	catch (Exception ex)
	{
		throw new RuntimeException("Failed to create Content Handler", ex); //$NON-NLS-1$
		/*
		 * String stackTrace = null; try { StringWriter exw = new
		 * StringWriter(); PrintWriter pw = new PrintWriter(exw);
		 * log.error(ex.getMessage(), ex); stackTrace = exw.toString(); } catch
		 * (Exception ex2) { stackTrace =
		 * MessageFormat.format(defaultStackTrace, new Object[] {
		 * ex.getMessage() }); } out.write(MessageFormat.format(errorFormat,
		 * new Object[] { ex.getMessage(), stackTrace }));
		 */
	}
}
 
Example 19
Source File: RawDataFileSaveHandler.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Copy the data points file of the raw data file from the temporary folder to the zip file.
 * Create an XML file which contains the description of the same raw data file an copy it into the
 * same zip file.
 * 
 * @param rawDataFile raw data file to be copied
 * @param rawDataSavedName name of the raw data inside the zip file
 * @throws java.io.IOException
 * @throws TransformerConfigurationException
 * @throws SAXException
 */
void writeRawDataFile(RawDataFileImpl rawDataFile, int number)
    throws IOException, TransformerConfigurationException, SAXException {

  numOfScans = rawDataFile.getNumOfScans();

  // Get the structure of the data points file
  dataPointsOffsets = rawDataFile.getDataPointsOffsets();
  dataPointsLengths = rawDataFile.getDataPointsLengths();
  consolidatedDataPointsOffsets = new TreeMap<Integer, Long>();

  // step 1 - save data file
  logger.info("Saving data points of: " + rawDataFile.getName());

  String rawDataSavedName = "Raw data file #" + number + " " + rawDataFile.getName();

  zipOutputStream.putNextEntry(new ZipEntry(rawDataSavedName + ".scans"));

  // We save only those data points that still have a reference in the
  // dataPointsOffset table. Some deleted mass lists may still be present
  // in the data points file, we don't want to copy those.
  long newOffset = 0;
  byte buffer[] = new byte[1 << 20];
  RandomAccessFile dataPointsFile = rawDataFile.getDataPointsFile();
  for (Integer storageID : dataPointsOffsets.keySet()) {

    if (canceled)
      return;

    final long offset = dataPointsOffsets.get(storageID);
    dataPointsFile.seek(offset);

    final int bytes = dataPointsLengths.get(storageID) * 4 * 2;
    consolidatedDataPointsOffsets.put(storageID, newOffset);
    if (buffer.length < bytes) {
      buffer = new byte[bytes * 2];
    }
    dataPointsFile.read(buffer, 0, bytes);
    zipOutputStream.write(buffer, 0, bytes);
    newOffset += bytes;
    progress = 0.9 * ((double) offset / dataPointsFile.length());
  }

  if (canceled)
    return;

  // step 2 - save raw data description
  logger.info("Saving raw data description of: " + rawDataFile.getName());

  zipOutputStream.putNextEntry(new ZipEntry(rawDataSavedName + ".xml"));
  OutputStream finalStream = zipOutputStream;

  StreamResult streamResult = new StreamResult(finalStream);
  SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();

  TransformerHandler hd = tf.newTransformerHandler();
  Transformer serializer = hd.getTransformer();
  serializer.setOutputProperty(OutputKeys.INDENT, "yes");
  serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");

  hd.setResult(streamResult);
  hd.startDocument();
  saveRawDataInformation(rawDataFile, hd);
  hd.endDocument();
}
 
Example 20
Source File: UserParameterSaveHandler.java    From mzmine3 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Function which creates an XML file with user parameters
 */
void saveParameters() throws SAXException, IOException, TransformerConfigurationException {

  logger.info("Saving user parameters");

  StreamResult streamResult = new StreamResult(finalStream);
  SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();

  TransformerHandler hd = tf.newTransformerHandler();

  Transformer serializer = hd.getTransformer();
  serializer.setOutputProperty(OutputKeys.INDENT, "yes");
  serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");

  hd.setResult(streamResult);
  hd.startDocument();

  UserParameter<?, ?> projectParameters[] = project.getParameters();

  AttributesImpl atts = new AttributesImpl();

  atts.addAttribute("", "", UserParameterElementName.COUNT.getElementName(), "CDATA",
      String.valueOf(projectParameters.length));

  hd.startElement("", "", UserParameterElementName.PARAMETERS.getElementName(), atts);

  atts.clear();

  // <PARAMETER>
  for (UserParameter<?, ?> parameter : project.getParameters()) {

    if (canceled)
      return;

    logger.finest("Saving user parameter " + parameter.getName());

    atts.addAttribute("", "", UserParameterElementName.NAME.getElementName(), "CDATA",
        parameter.getName());

    atts.addAttribute("", "", UserParameterElementName.TYPE.getElementName(), "CDATA",
        parameter.getClass().getSimpleName());

    hd.startElement("", "", UserParameterElementName.PARAMETER.getElementName(), atts);

    atts.clear();

    fillParameterElement(parameter, hd);

    hd.endElement("", "", UserParameterElementName.PARAMETER.getElementName());
    completedParameters++;
  }

  hd.endElement("", "", UserParameterElementName.PARAMETERS.getElementName());

  hd.endDocument();

}