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

The following examples show how to use javax.xml.transform.sax.TransformerHandler#characters() . 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: PeakListSaveHandler.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
private void fillInformationElement(PeakInformation information, TransformerHandler hd)
    throws SAXException {
  if (information == null)
    return;

  AttributesImpl atts = new AttributesImpl();

  for (Entry<String, String> property : information.getAllProperties().entrySet()) {
    String value = property.getValue();

    atts.clear();
    atts.addAttribute("", "", PeakListElementName.NAME.getElementName(), "CDATA",
        property.getKey());

    hd.startElement("", "", PeakListElementName.INFO_PROPERTY.getElementName(), atts);
    hd.characters(property.getValue().toCharArray(), 0, value.length());
    hd.endElement("", "", PeakListElementName.INFO_PROPERTY.getElementName());
  }
}
 
Example 2
Source File: IvyArtifactReport.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private void writeOriginLocationIfPresent(RepositoryCacheManager cache,
        TransformerHandler saxHandler, ArtifactDownloadReport artifact) throws SAXException {
    ArtifactOrigin origin = artifact.getArtifactOrigin();
    if (!ArtifactOrigin.isUnknown(origin)) {
        String originName = origin.getLocation();
        boolean isOriginLocal = origin.isLocal();

        String originLocation;
        AttributesImpl originLocationAttrs = new AttributesImpl();
        if (isOriginLocal) {
            originLocationAttrs.addAttribute(null, "is-local", "is-local", "CDATA", "true");
            originLocation = originName.replace('\\', '/');
        } else {
            originLocationAttrs.addAttribute(null, "is-local", "is-local", "CDATA", "false");
            originLocation = originName;
        }
        saxHandler
                .startElement(null, "origin-location", "origin-location", originLocationAttrs);
        char[] originLocationAsChars = originLocation.toCharArray();
        saxHandler.characters(originLocationAsChars, 0, originLocationAsChars.length);
        saxHandler.endElement(null, "origin-location", "origin-location");
    }
}
 
Example 3
Source File: PeakListSaveHandler.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
private void fillInformationElement(PeakInformation information, TransformerHandler hd)
    throws SAXException {
  if (information == null)
    return;

  AttributesImpl atts = new AttributesImpl();

  for (Entry<String, String> property : information.getAllProperties().entrySet()) {
    String value = property.getValue();

    atts.clear();
    atts.addAttribute("", "", PeakListElementName.NAME.getElementName(), "CDATA",
        property.getKey());

    hd.startElement("", "", PeakListElementName.INFO_PROPERTY.getElementName(), atts);
    hd.characters(property.getValue().toCharArray(), 0, value.length());
    hd.endElement("", "", PeakListElementName.INFO_PROPERTY.getElementName());
  }
}
 
Example 4
Source File: PeakListSaveHandler.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add the peak identity information into the XML document
 * 
 * @param identity
 * @param element
 */
private void fillIdentityElement(PeakIdentity identity, TransformerHandler hd)
    throws SAXException {

  AttributesImpl atts = new AttributesImpl();

  Map<String, String> idProperties = identity.getAllProperties();

  for (Entry<String, String> property : idProperties.entrySet()) {
    String propertyValue = property.getValue();
    atts.clear();
    atts.addAttribute("", "", PeakListElementName.NAME.getElementName(), "CDATA",
        property.getKey());

    hd.startElement("", "", PeakListElementName.IDPROPERTY.getElementName(), atts);
    hd.characters(propertyValue.toCharArray(), 0, propertyValue.length());
    hd.endElement("", "", PeakListElementName.IDPROPERTY.getElementName());
  }

}
 
Example 5
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 6
Source File: OpenJDK100017Test.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public final void testXMLStackOverflowBug() throws TransformerConfigurationException, IOException, SAXException {
    try {
        SAXTransformerFactory stf = (SAXTransformerFactory) TransformerFactory.newInstance();
        TransformerHandler ser = stf.newTransformerHandler();
        ser.setResult(new StreamResult(System.out));

        StringBuilder sb = new StringBuilder(4096);
        for (int x = 4096; x > 0; x--) {
            sb.append((char) x);
        }
        ser.characters(sb.toString().toCharArray(), 0, sb.toString().toCharArray().length);
        ser.endDocument();
    } catch (StackOverflowError se) {
        se.printStackTrace();
        Assert.fail("StackOverflow");
    }
}
 
Example 7
Source File: PeakListSaveHandler.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add the peak identity information into the XML document
 *
 * @param identity
 * @param element
 */
private void fillIdentityElement(PeakIdentity identity, TransformerHandler hd)
    throws SAXException {

  AttributesImpl atts = new AttributesImpl();

  Map<String, String> idProperties = identity.getAllProperties();

  for (Entry<String, String> property : idProperties.entrySet()) {
    String propertyValue = property.getValue();
    atts.clear();
    atts.addAttribute("", "", PeakListElementName.NAME.getElementName(), "CDATA",
        property.getKey());

    hd.startElement("", "", PeakListElementName.IDPROPERTY.getElementName(), atts);
    hd.characters(propertyValue.toCharArray(), 0, propertyValue.length());
    hd.endElement("", "", PeakListElementName.IDPROPERTY.getElementName());
  }

}
 
Example 8
Source File: PeakListSaveHandler.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
private void fillAllMS2FragmentScanNumbers(int[] scanNumbers, TransformerHandler hd)
    throws SAXException, IOException {
  AttributesImpl atts = new AttributesImpl();
  if (scanNumbers != null) {
    for (int scan : scanNumbers) {
      hd.startElement("", "", PeakListElementName.ALL_MS2_FRAGMENT_SCANS.getElementName(), atts);
      hd.characters(String.valueOf(scan).toCharArray(), 0, String.valueOf(scan).length());
      hd.endElement("", "", PeakListElementName.ALL_MS2_FRAGMENT_SCANS.getElementName());
    }
  }
}
 
Example 9
Source File: PeakListSaveHandler.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
private void fillIsotopePatternElement(IsotopePattern isotopePattern, TransformerHandler hd)
    throws SAXException, IOException {

  AttributesImpl atts = new AttributesImpl();

  DataPoint isotopes[] = isotopePattern.getDataPoints();

  for (DataPoint isotope : isotopes) {
    hd.startElement("", "", PeakListElementName.ISOTOPE.getElementName(), atts);
    String isotopeString = isotope.getMZ() + ":" + isotope.getIntensity();
    hd.characters(isotopeString.toCharArray(), 0, isotopeString.length());
    hd.endElement("", "", PeakListElementName.ISOTOPE.getElementName());
  }
}
 
Example 10
Source File: PeakListSaveHandler.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
private void fillIsotopePatternElement(IsotopePattern isotopePattern, TransformerHandler hd)
    throws SAXException, IOException {

  AttributesImpl atts = new AttributesImpl();

  DataPoint isotopes[] = isotopePattern.getDataPoints();

  for (DataPoint isotope : isotopes) {
    hd.startElement("", "", PeakListElementName.ISOTOPE.getElementName(), atts);
    String isotopeString = isotope.getMZ() + ":" + isotope.getIntensity();
    hd.characters(isotopeString.toCharArray(), 0, isotopeString.length());
    hd.endElement("", "", PeakListElementName.ISOTOPE.getElementName());
  }
}
 
Example 11
Source File: PeakListSaveHandler.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
private void fillAllMS2FragmentScanNumbers(int[] scanNumbers, TransformerHandler hd)
    throws SAXException, IOException {
  AttributesImpl atts = new AttributesImpl();
  if (scanNumbers != null) {
    for (int scan : scanNumbers) {
      hd.startElement("", "", PeakListElementName.ALL_MS2_FRAGMENT_SCANS.getElementName(), atts);
      hd.characters(String.valueOf(scan).toCharArray(), 0, String.valueOf(scan).length());
      hd.endElement("", "", PeakListElementName.ALL_MS2_FRAGMENT_SCANS.getElementName());
    }
  }
}
 
Example 12
Source File: IvyArtifactReport.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void writeRetrieveLocation(TransformerHandler saxHandler, String artifactDestPath)
        throws SAXException {
    artifactDestPath = removeLeadingPath(getProject().getBaseDir(), new File(artifactDestPath));

    saxHandler.startElement(null, "retrieve-location", "retrieve-location",
        new AttributesImpl());
    char[] artifactDestPathAsChars = artifactDestPath.replace('\\', '/').toCharArray();
    saxHandler.characters(artifactDestPathAsChars, 0, artifactDestPathAsChars.length);
    saxHandler.endElement(null, "retrieve-location", "retrieve-location");
}
 
Example 13
Source File: SaverBase.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
protected void cdataElement(String name, String cdata, AttributesImpl attrs, TransformerHandler handler)
    throws SAXException {
  if (cdata == null) {
    return;
  }
  startElement(name, attrs, handler);
  handler.startCDATA();
  handler.characters(cdata.toCharArray(), 0, cdata.length());
  handler.endCDATA();
  endElement(name, handler);
}
 
Example 14
Source File: XmlSerializer.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
protected void textElement(String name, AttributesImpl attrs, String text, TransformerHandler handler)
    throws SAXException {
  if (text != null) {
    startElement(name, attrs, handler);
    handler.startCDATA();
    handler.characters(text.toCharArray(), 0, text.length());
    handler.endCDATA();
    endElement(name, handler);
    attrs.clear();
  }
}
 
Example 15
Source File: IvyArtifactReport.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void writeCacheLocationIfPresent(RepositoryCacheManager cache,
        TransformerHandler saxHandler, ArtifactDownloadReport artifact) throws SAXException {
    File archiveInCache = artifact.getLocalFile();

    if (archiveInCache != null) {
        saxHandler.startElement(null, "cache-location", "cache-location", new AttributesImpl());
        char[] archiveInCacheAsChars = archiveInCache.getPath().replace('\\', '/')
                .toCharArray();
        saxHandler.characters(archiveInCacheAsChars, 0, archiveInCacheAsChars.length);
        saxHandler.endElement(null, "cache-location", "cache-location");
    }
}
 
Example 16
Source File: XmlTools.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static void iccHeaderXml(LinkedHashMap<String, Object> header, File file) {
    if (header == null || file == null) {
        return;
    }
    try {
        SAXTransformerFactory sf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
        TransformerHandler handler = sf.newTransformerHandler();
        Transformer transformer = handler.getTransformer();
        transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");
        transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        Result result = new StreamResult(new BufferedOutputStream(new FileOutputStream(file)));
        handler.setResult(result);
        handler.startDocument();
        AttributesImpl attr = new AttributesImpl();
        handler.startElement("", "", "IccProfile", attr);
        handler.startElement("", "", "Header", attr);

        handler.startElement("", "", "PreferredCMMType", attr);
        String stringV = (String) header.get("CMMType");
        handler.characters(stringV.toCharArray(), 0, stringV.length());
        handler.endElement("", "", "PreferredCMMType");

        handler.startElement("", "", "PCSIlluminant", attr);
        attr.clear();
        attr.addAttribute("", "", "X", "", header.get("x") + "");
        attr.addAttribute("", "", "Y", "", header.get("y") + "");
        attr.addAttribute("", "", "Z", "", header.get("z") + "");
        handler.startElement("", "", "XYZNumber", attr);
        handler.endElement("", "", "XYZNumber");
        handler.endElement("", "", "PCSIlluminant");

        handler.endElement("", "", "Header");
        handler.endElement("", "", "IccProfile");

        handler.endDocument();

    } catch (Exception e) {

    }

}
 
Example 17
Source File: SAXGenerator.java    From AndroidPixelDimenGenerator with Apache License 2.0 4 votes vote down vote up
public void generate(Values values) throws IOException {
    File dimenFile = values.dimenFile;
    FileOutputStream fos = new FileOutputStream(dimenFile);
    StreamResult result = new StreamResult(fos);
    SAXTransformerFactory sff = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
    TransformerHandler th = null;
    try {
        th = sff.newTransformerHandler();
        Transformer transformer = th.getTransformer();
        transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");

        th.setResult(result);

        th.startDocument();

        AttributesImpl attr = new AttributesImpl();
        char[] space = "\n".toCharArray();
        th.characters(space, 0, space.length);
        th.startElement("", "", "resources", attr);

        List<Dimen> dimens = values.dimens;
        char[] spaceChar = "\n    ".toCharArray();
        for (Dimen dimen : dimens) {
            //white space
            th.characters(spaceChar, 0, spaceChar.length);
            //name attr
            attr.addAttribute("", "", "name", String.class.getName(), dimen.name);
            th.startElement("", "", "dimen", attr);
            char[] valueChars = String.format("%spx", dimen.value).toCharArray();
            th.characters(valueChars, 0, valueChars.length);
            th.endElement("", "", "dimen");
        }

        th.endElement("", "", "resources");
        th.endDocument();

    } catch (TransformerConfigurationException | SAXException e) {
        e.printStackTrace();
    } finally {
        fos.close();
    }
}
 
Example 18
Source File: PeakListSaveHandler.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Add the peaks information into the XML document
 *
 * @param peak
 * @param element
 * @param dataFileID
 * @throws IOException
 */
private void fillPeakElement(Feature peak, TransformerHandler hd)
    throws SAXException, IOException {
  AttributesImpl atts = new AttributesImpl();

  // <REPRESENTATIVE_SCAN>
  hd.startElement("", "", PeakListElementName.REPRESENTATIVE_SCAN.getElementName(), atts);
  hd.characters(String.valueOf(peak.getRepresentativeScanNumber()).toCharArray(), 0,
      String.valueOf(peak.getRepresentativeScanNumber()).length());
  hd.endElement("", "", PeakListElementName.REPRESENTATIVE_SCAN.getElementName());

  // <FRAGMENT_SCAN>
  hd.startElement("", "", PeakListElementName.FRAGMENT_SCAN.getElementName(), atts);
  hd.characters(String.valueOf(peak.getMostIntenseFragmentScanNumber()).toCharArray(), 0,
      String.valueOf(peak.getMostIntenseFragmentScanNumber()).length());
  hd.endElement("", "", PeakListElementName.FRAGMENT_SCAN.getElementName());

  // <ALL_MS2_FRAGMENT_SCANS>
  fillAllMS2FragmentScanNumbers(peak.getAllMS2FragmentScanNumbers(), hd);

  int scanNumbers[] = peak.getScanNumbers();

  // <ISOTOPE_PATTERN>
  IsotopePattern isotopePattern = peak.getIsotopePattern();
  if (isotopePattern != null) {
    atts.addAttribute("", "", PeakListElementName.STATUS.getElementName(), "CDATA",
        String.valueOf(isotopePattern.getStatus()));
    atts.addAttribute("", "", PeakListElementName.DESCRIPTION.getElementName(), "CDATA",
        isotopePattern.getDescription());
    hd.startElement("", "", PeakListElementName.ISOTOPE_PATTERN.getElementName(), atts);
    atts.clear();

    fillIsotopePatternElement(isotopePattern, hd);

    hd.endElement("", "", PeakListElementName.ISOTOPE_PATTERN.getElementName());

  }

  // <MZPEAK>
  atts.addAttribute("", "", PeakListElementName.QUANTITY.getElementName(), "CDATA",
      String.valueOf(scanNumbers.length));
  hd.startElement("", "", PeakListElementName.MZPEAKS.getElementName(), atts);
  atts.clear();

  // <SCAN_ID> <MASS> <HEIGHT>
  ByteArrayOutputStream byteScanStream = new ByteArrayOutputStream();
  DataOutputStream dataScanStream = new DataOutputStream(byteScanStream);

  ByteArrayOutputStream byteMassStream = new ByteArrayOutputStream();
  DataOutputStream dataMassStream = new DataOutputStream(byteMassStream);

  ByteArrayOutputStream byteHeightStream = new ByteArrayOutputStream();
  DataOutputStream dataHeightStream = new DataOutputStream(byteHeightStream);

  float mass, height;
  for (int scan : scanNumbers) {
    dataScanStream.writeInt(scan);
    dataScanStream.flush();
    DataPoint mzPeak = peak.getDataPoint(scan);
    if (mzPeak != null) {
      mass = (float) mzPeak.getMZ();
      height = (float) mzPeak.getIntensity();
    } else {
      mass = 0f;
      height = 0f;
    }
    dataMassStream.writeFloat(mass);
    dataMassStream.flush();
    dataHeightStream.writeFloat(height);
    dataHeightStream.flush();
  }

  byte[] bytes = Base64.encode(byteScanStream.toByteArray());
  hd.startElement("", "", PeakListElementName.SCAN_ID.getElementName(), atts);
  String sbytes = new String(bytes);
  hd.characters(sbytes.toCharArray(), 0, sbytes.length());
  hd.endElement("", "", PeakListElementName.SCAN_ID.getElementName());

  bytes = Base64.encode(byteMassStream.toByteArray());
  hd.startElement("", "", PeakListElementName.MZ.getElementName(), atts);
  sbytes = new String(bytes);
  hd.characters(sbytes.toCharArray(), 0, sbytes.length());
  hd.endElement("", "", PeakListElementName.MZ.getElementName());

  bytes = Base64.encode(byteHeightStream.toByteArray());
  hd.startElement("", "", PeakListElementName.HEIGHT.getElementName(), atts);
  sbytes = new String(bytes);
  hd.characters(sbytes.toCharArray(), 0, sbytes.length());
  hd.endElement("", "", PeakListElementName.HEIGHT.getElementName());

  hd.endElement("", "", PeakListElementName.MZPEAKS.getElementName());
}
 
Example 19
Source File: PeakListSaveHandler.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Add the peaks information into the XML document
 * 
 * @param peak
 * @param element
 * @param dataFileID
 * @throws IOException
 */
private void fillPeakElement(Feature peak, TransformerHandler hd)
    throws SAXException, IOException {
  AttributesImpl atts = new AttributesImpl();

  // <REPRESENTATIVE_SCAN>
  hd.startElement("", "", PeakListElementName.REPRESENTATIVE_SCAN.getElementName(), atts);
  hd.characters(String.valueOf(peak.getRepresentativeScanNumber()).toCharArray(), 0,
      String.valueOf(peak.getRepresentativeScanNumber()).length());
  hd.endElement("", "", PeakListElementName.REPRESENTATIVE_SCAN.getElementName());

  // <FRAGMENT_SCAN>
  hd.startElement("", "", PeakListElementName.FRAGMENT_SCAN.getElementName(), atts);
  hd.characters(String.valueOf(peak.getMostIntenseFragmentScanNumber()).toCharArray(), 0,
      String.valueOf(peak.getMostIntenseFragmentScanNumber()).length());
  hd.endElement("", "", PeakListElementName.FRAGMENT_SCAN.getElementName());

  // <ALL_MS2_FRAGMENT_SCANS>
  fillAllMS2FragmentScanNumbers(peak.getAllMS2FragmentScanNumbers(), hd);

  int scanNumbers[] = peak.getScanNumbers();

  // <ISOTOPE_PATTERN>
  IsotopePattern isotopePattern = peak.getIsotopePattern();
  if (isotopePattern != null) {
    atts.addAttribute("", "", PeakListElementName.STATUS.getElementName(), "CDATA",
        String.valueOf(isotopePattern.getStatus()));
    atts.addAttribute("", "", PeakListElementName.DESCRIPTION.getElementName(), "CDATA",
        isotopePattern.getDescription());
    hd.startElement("", "", PeakListElementName.ISOTOPE_PATTERN.getElementName(), atts);
    atts.clear();

    fillIsotopePatternElement(isotopePattern, hd);

    hd.endElement("", "", PeakListElementName.ISOTOPE_PATTERN.getElementName());

  }

  // <MZPEAK>
  atts.addAttribute("", "", PeakListElementName.QUANTITY.getElementName(), "CDATA",
      String.valueOf(scanNumbers.length));
  hd.startElement("", "", PeakListElementName.MZPEAKS.getElementName(), atts);
  atts.clear();

  // <SCAN_ID> <MASS> <HEIGHT>
  ByteArrayOutputStream byteScanStream = new ByteArrayOutputStream();
  DataOutputStream dataScanStream = new DataOutputStream(byteScanStream);

  ByteArrayOutputStream byteMassStream = new ByteArrayOutputStream();
  DataOutputStream dataMassStream = new DataOutputStream(byteMassStream);

  ByteArrayOutputStream byteHeightStream = new ByteArrayOutputStream();
  DataOutputStream dataHeightStream = new DataOutputStream(byteHeightStream);

  float mass, height;
  for (int scan : scanNumbers) {
    dataScanStream.writeInt(scan);
    dataScanStream.flush();
    DataPoint mzPeak = peak.getDataPoint(scan);
    if (mzPeak != null) {
      mass = (float) mzPeak.getMZ();
      height = (float) mzPeak.getIntensity();
    } else {
      mass = 0f;
      height = 0f;
    }
    dataMassStream.writeFloat(mass);
    dataMassStream.flush();
    dataHeightStream.writeFloat(height);
    dataHeightStream.flush();
  }

  byte[] bytes = Base64.encode(byteScanStream.toByteArray());
  hd.startElement("", "", PeakListElementName.SCAN_ID.getElementName(), atts);
  String sbytes = new String(bytes);
  hd.characters(sbytes.toCharArray(), 0, sbytes.length());
  hd.endElement("", "", PeakListElementName.SCAN_ID.getElementName());

  bytes = Base64.encode(byteMassStream.toByteArray());
  hd.startElement("", "", PeakListElementName.MZ.getElementName(), atts);
  sbytes = new String(bytes);
  hd.characters(sbytes.toCharArray(), 0, sbytes.length());
  hd.endElement("", "", PeakListElementName.MZ.getElementName());

  bytes = Base64.encode(byteHeightStream.toByteArray());
  hd.startElement("", "", PeakListElementName.HEIGHT.getElementName(), atts);
  sbytes = new String(bytes);
  hd.characters(sbytes.toCharArray(), 0, sbytes.length());
  hd.endElement("", "", PeakListElementName.HEIGHT.getElementName());

  hd.endElement("", "", PeakListElementName.MZPEAKS.getElementName());
}
 
Example 20
Source File: UserParameterSaveHandler.java    From mzmine3 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create the part of the XML document related to the scans
 *
 * @param scan
 * @param element
 */
private void fillParameterElement(UserParameter<?, ?> parameter, TransformerHandler hd)
    throws SAXException, IOException {

  AttributesImpl atts = new AttributesImpl();

  RawDataFile dataFiles[] = project.getDataFiles();

  if (parameter instanceof ComboParameter) {
    Object choices[] = ((ComboParameter<?>) parameter).getChoices().toArray();

    for (Object choice : choices) {
      hd.startElement("", "", UserParameterElementName.OPTION.getElementName(), atts);

      hd.characters(choice.toString().toCharArray(), 0, choice.toString().length());
      hd.endElement("", "", UserParameterElementName.OPTION.getElementName());
    }

  }

  for (RawDataFile dataFile : dataFiles) {

    Object value = project.getParameterValue(parameter, dataFile);

    if (value == null)
      continue;

    String valueString = String.valueOf(value);
    String dataFileID = dataFilesIDMap.get(dataFile);

    atts.addAttribute("", "", UserParameterElementName.DATA_FILE.getElementName(), "CDATA",
        dataFileID);

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

    atts.clear();

    hd.characters(valueString.toCharArray(), 0, valueString.length());
    hd.endElement("", "", UserParameterElementName.VALUE.getElementName());

  }

}