Java Code Examples for javax.xml.transform.sax.TransformerHandler#startElement()
The following examples show how to use
javax.xml.transform.sax.TransformerHandler#startElement() .
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: IvyArtifactReport.java From ant-ivy with Apache License 2.0 | 6 votes |
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 2
Source File: PeakListSaveHandler.java From mzmine3 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 |
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 |
/** * 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: IvyArtifactReport.java From ant-ivy with Apache License 2.0 | 5 votes |
private void startModule(TransformerHandler saxHandler, IvyNode dependency) throws SAXException { AttributesImpl moduleAttrs = new AttributesImpl(); moduleAttrs.addAttribute(null, "organisation", "organisation", "CDATA", dependency .getModuleId().getOrganisation()); moduleAttrs.addAttribute(null, "name", "name", "CDATA", dependency.getModuleId().getName()); ResolvedModuleRevision moduleRevision = dependency.getModuleRevision(); moduleAttrs.addAttribute(null, "rev", "rev", "CDATA", moduleRevision.getId().getRevision()); moduleAttrs.addAttribute(null, "status", "status", "CDATA", moduleRevision.getDescriptor() .getStatus()); saxHandler.startElement(null, "module", "module", moduleAttrs); }
Example 6
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 7
Source File: PeakListSaveHandler.java From mzmine2 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 8
Source File: IvyArtifactReport.java From ant-ivy with Apache License 2.0 | 5 votes |
private void startArtifact(TransformerHandler saxHandler, Artifact artifact) throws SAXException { AttributesImpl artifactAttrs = new AttributesImpl(); artifactAttrs.addAttribute(null, "name", "name", "CDATA", artifact.getName()); artifactAttrs.addAttribute(null, "ext", "ext", "CDATA", artifact.getExt()); artifactAttrs.addAttribute(null, "type", "type", "CDATA", artifact.getType()); saxHandler.startElement(null, "artifact", "artifact", artifactAttrs); }
Example 9
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 10
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 11
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 12
Source File: IvyArtifactReport.java From ant-ivy with Apache License 2.0 | 4 votes |
private void generateXml(IvyNode[] dependencies, Map<ModuleRevisionId, Set<ArtifactDownloadReport>> moduleRevToArtifactsMap, Map<ArtifactDownloadReport, Set<String>> artifactsToCopy) { try { try (FileOutputStream fileOutputStream = new FileOutputStream(tofile)) { TransformerHandler saxHandler = createTransformerHandler(fileOutputStream); saxHandler.startDocument(); saxHandler.startElement(null, "modules", "modules", new AttributesImpl()); for (IvyNode dependency : dependencies) { if (dependency.getModuleRevision() == null || dependency.isCompletelyEvicted()) { continue; } startModule(saxHandler, dependency); Set<ArtifactDownloadReport> artifactsOfModuleRev = moduleRevToArtifactsMap.get(dependency .getModuleRevision().getId()); if (artifactsOfModuleRev != null) { for (ArtifactDownloadReport artifact : artifactsOfModuleRev) { RepositoryCacheManager cache = dependency.getModuleRevision() .getArtifactResolver().getRepositoryCacheManager(); startArtifact(saxHandler, artifact.getArtifact()); writeOriginLocationIfPresent(cache, saxHandler, artifact); writeCacheLocationIfPresent(cache, saxHandler, artifact); for (String artifactDestPath : artifactsToCopy.get(artifact)) { writeRetrieveLocation(saxHandler, artifactDestPath); } saxHandler.endElement(null, "artifact", "artifact"); } } saxHandler.endElement(null, "module", "module"); } saxHandler.endElement(null, "modules", "modules"); saxHandler.endDocument(); } } catch (SAXException | IOException | TransformerConfigurationException e) { throw new BuildException("impossible to generate report", e); } }
Example 13
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 14
Source File: XmlWriter.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 4 votes |
/** * 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 15
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 16
Source File: SaverBase.java From ganttproject with GNU General Public License v3.0 | 4 votes |
protected void startElement(String name, AttributesImpl attrs, TransformerHandler handler) throws SAXException { handler.startElement("", name, name, attrs); attrs.clear(); }
Example 17
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 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 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(); }
Example 20
Source File: UserParameterSaveHandler.java From mzmine2 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(); 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()); } }