Java Code Examples for javax.xml.transform.sax.TransformerHandler#endElement()
The following examples show how to use
javax.xml.transform.sax.TransformerHandler#endElement() .
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 |
/** * 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 2
Source File: PeakListSaveHandler.java From mzmine2 with GNU General Public License v2.0 | 6 votes |
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 3
Source File: PeakListSaveHandler.java From mzmine2 with GNU General Public License v2.0 | 6 votes |
/** * 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 4
Source File: Bug6451633.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@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 5
Source File: PeakListSaveHandler.java From mzmine3 with GNU General Public License v2.0 | 5 votes |
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 6
Source File: PeakListSaveHandler.java From mzmine3 with GNU General Public License v2.0 | 5 votes |
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 7
Source File: IvyArtifactReport.java From ant-ivy with Apache License 2.0 | 5 votes |
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 8
Source File: IvyArtifactReport.java From ant-ivy with Apache License 2.0 | 5 votes |
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 9
Source File: PeakListSaveHandler.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
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 10
Source File: XmlWriter.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 5 votes |
private void createFooter(OutputStream os, TransformerHandler hd) throws TransformerConfigurationException, SAXException, IOException { try { //if (recordsPerFile!=1){ if (this.useRootElement){ String root = (rootElement!=null && rootElement.length()>0) ? rootElement : DEFAULT_ROOT_ELEMENT; hd.endElement(rootDefaultNamespace, getLocalName(root), root); for (String prefix : namespaces.keySet()) hd.endPrefixMapping(prefix); } hd.endDocument(); } finally { os.close(); } }
Example 11
Source File: GanttOptions.java From ganttproject with GNU General Public License v3.0 | 5 votes |
private void saveRoleSets(TransformerHandler handler) throws TransformerFactoryConfigurationError, SAXException { RoleSet[] roleSets = getRoleManager().getRoleSets(); for (int i = 0; i < roleSets.length; i++) { AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", "roleset-name", "roleset-name", "CDATA", roleSets[i].getName()); handler.startElement("", "roles", "roles", attrs); saveRoles(roleSets[i], handler); handler.endElement("", "roles", "roles"); } }
Example 12
Source File: XmlTools.java From MyBox with Apache License 2.0 | 4 votes |
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 13
Source File: SAXGenerator.java From AndroidPixelDimenGenerator with Apache License 2.0 | 4 votes |
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 14
Source File: PeakListSaveHandler.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
/** * 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 15
Source File: PeakListSaveHandler.java From mzmine2 with GNU General Public License v2.0 | 4 votes |
/** * Add the row information into the XML document * * @param row * @param element * @throws IOException */ private void fillRowElement(PeakListRow row, TransformerHandler hd) throws SAXException, IOException { // <PEAK_IDENTITY> PeakIdentity preferredIdentity = row.getPreferredPeakIdentity(); PeakIdentity[] identities = row.getPeakIdentities(); AttributesImpl atts = new AttributesImpl(); for (int i = 0; i < identities.length; i++) { if (canceled) return; atts.addAttribute("", "", PeakListElementName.ID.getElementName(), "CDATA", String.valueOf(i)); atts.addAttribute("", "", PeakListElementName.PREFERRED.getElementName(), "CDATA", String.valueOf(identities[i] == preferredIdentity)); hd.startElement("", "", PeakListElementName.PEAK_IDENTITY.getElementName(), atts); fillIdentityElement(identities[i], hd); hd.endElement("", "", PeakListElementName.PEAK_IDENTITY.getElementName()); } // <PEAK_INFORMATION> // atts.clear(); if (canceled) return; // atts.addAttribute("", "", PeakListElementName.ID.getElementName(), // "CDATA", "INFORMATION"); hd.startElement("", "", PeakListElementName.PEAK_INFORMATION.getElementName(), atts); fillInformationElement(row.getPeakInformation(), hd); hd.endElement("", "", PeakListElementName.PEAK_INFORMATION.getElementName()); // <PEAK> Feature[] peaks = row.getPeaks(); for (Feature p : peaks) { if (canceled) return; atts.clear(); String dataFileID = dataFilesIDMap.get(p.getDataFile()); atts.addAttribute("", "", PeakListElementName.COLUMN.getElementName(), "CDATA", dataFileID); atts.addAttribute("", "", PeakListElementName.MZ.getElementName(), "CDATA", String.valueOf(p.getMZ())); // In the project file, retention time is represented in seconds, // for historical reasons double rt = p.getRT() * 60d; atts.addAttribute("", "", PeakListElementName.RT.getElementName(), "CDATA", String.valueOf(rt)); atts.addAttribute("", "", PeakListElementName.HEIGHT.getElementName(), "CDATA", String.valueOf(p.getHeight())); atts.addAttribute("", "", PeakListElementName.AREA.getElementName(), "CDATA", String.valueOf(p.getArea())); atts.addAttribute("", "", PeakListElementName.STATUS.getElementName(), "CDATA", p.getFeatureStatus().toString()); atts.addAttribute("", "", PeakListElementName.CHARGE.getElementName(), "CDATA", String.valueOf(p.getCharge())); atts.addAttribute("", "", PeakListElementName.PARENT_CHROMATOGRAM_ROW_ID.getElementName(), "CDATA", p.getParentChromatogramRowID() != null ? String.valueOf(p.getParentChromatogramRowID()) : ""); hd.startElement("", "", PeakListElementName.PEAK.getElementName(), atts); fillPeakElement(p, hd); hd.endElement("", "", PeakListElementName.PEAK.getElementName()); } }
Example 16
Source File: PeakListSaveHandler.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
/** * Add the row information into the XML document * * @param row * @param element * @throws IOException */ private void fillRowElement(PeakListRow row, TransformerHandler hd) throws SAXException, IOException { // <PEAK_IDENTITY> PeakIdentity preferredIdentity = row.getPreferredPeakIdentity(); PeakIdentity[] identities = row.getPeakIdentities(); AttributesImpl atts = new AttributesImpl(); for (int i = 0; i < identities.length; i++) { if (canceled) return; atts.addAttribute("", "", PeakListElementName.ID.getElementName(), "CDATA", String.valueOf(i)); atts.addAttribute("", "", PeakListElementName.PREFERRED.getElementName(), "CDATA", String.valueOf(identities[i] == preferredIdentity)); hd.startElement("", "", PeakListElementName.PEAK_IDENTITY.getElementName(), atts); fillIdentityElement(identities[i], hd); hd.endElement("", "", PeakListElementName.PEAK_IDENTITY.getElementName()); } // <PEAK_INFORMATION> // atts.clear(); if (canceled) return; // atts.addAttribute("", "", PeakListElementName.ID.getElementName(), // "CDATA", "INFORMATION"); hd.startElement("", "", PeakListElementName.PEAK_INFORMATION.getElementName(), atts); fillInformationElement(row.getPeakInformation(), hd); hd.endElement("", "", PeakListElementName.PEAK_INFORMATION.getElementName()); // <PEAK> Feature[] peaks = row.getPeaks(); for (Feature p : peaks) { if (canceled) return; atts.clear(); String dataFileID = dataFilesIDMap.get(p.getDataFile()); atts.addAttribute("", "", PeakListElementName.COLUMN.getElementName(), "CDATA", dataFileID); atts.addAttribute("", "", PeakListElementName.MZ.getElementName(), "CDATA", String.valueOf(p.getMZ())); // In the project file, retention time is represented in seconds, // for historical reasons double rt = p.getRT() * 60d; atts.addAttribute("", "", PeakListElementName.RT.getElementName(), "CDATA", String.valueOf(rt)); atts.addAttribute("", "", PeakListElementName.HEIGHT.getElementName(), "CDATA", String.valueOf(p.getHeight())); atts.addAttribute("", "", PeakListElementName.AREA.getElementName(), "CDATA", String.valueOf(p.getArea())); atts.addAttribute("", "", PeakListElementName.STATUS.getElementName(), "CDATA", p.getFeatureStatus().toString()); atts.addAttribute("", "", PeakListElementName.CHARGE.getElementName(), "CDATA", String.valueOf(p.getCharge())); atts.addAttribute("", "", PeakListElementName.PARENT_CHROMATOGRAM_ROW_ID.getElementName(), "CDATA", p.getParentChromatogramRowID() != null ? String.valueOf(p.getParentChromatogramRowID()) : ""); hd.startElement("", "", PeakListElementName.PEAK.getElementName(), atts); fillPeakElement(p, hd); hd.endElement("", "", PeakListElementName.PEAK.getElementName()); } }
Example 17
Source File: PeakListSaveHandler.java From mzmine2 with GNU General Public License v2.0 | 4 votes |
/** * 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 18
Source File: UserParameterSaveHandler.java From mzmine3 with GNU General Public License v2.0 | 2 votes |
/** * 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(); }
Example 19
Source File: UserParameterSaveHandler.java From mzmine3 with GNU General Public License v2.0 | 2 votes |
/** * 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()); } }
Example 20
Source File: UserParameterSaveHandler.java From mzmine2 with GNU General Public License v2.0 | 2 votes |
/** * 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(); }