List of usage examples for javax.xml.stream XMLStreamWriter writeAttribute
public void writeAttribute(String localName, String value) throws XMLStreamException;
From source file:org.slc.sli.modeling.xmi.writer.XmiWriter.java
private static final void writeName(final HasName hasName, final ModelIndex mapper, final XMLStreamWriter xsw) throws XMLStreamException { xsw.writeAttribute(XmiAttributeName.NAME.getLocalName(), hasName.getName()); }
From source file:org.slc.sli.modeling.xmi.writer.XmiWriter.java
private static final void writeModel(final Model model, final ModelIndex mapper, final XMLStreamWriter xsw) throws XMLStreamException { xsw.writeStartElement(PREFIX_UML, XmiElementName.MODEL.getLocalName(), NAMESPACE_UML); try {/*ww w . j av a 2s. co m*/ xsw.writeAttribute(XmiAttributeName.ID.getLocalName(), model.getId().toString()); xsw.writeAttribute(XmiAttributeName.NAME.getLocalName(), model.getName()); writeModelElementTaggedValues(model, mapper, xsw); writeNamespaceOwnedElements(model.getOwnedElements(), mapper, xsw); } finally { xsw.writeEndElement(); } }
From source file:org.slc.sli.modeling.xmi.writer.XmiWriter.java
private static final void writeMultiplicityRange(final Range range, final XMLStreamWriter xsw) throws XMLStreamException { xsw.writeStartElement(PREFIX_UML, XmiElementName.MULTIPLICITY_DOT_RANGE.getLocalName(), NAMESPACE_UML); xsw.writeStartElement(PREFIX_UML, XmiElementName.MULTIPLICITY_RANGE.getLocalName(), NAMESPACE_UML); writeId(range, xsw);//from w ww. j a v a 2 s . co m xsw.writeAttribute("lower", Integer.toString(range(range.getLower()))); xsw.writeAttribute("upper", Integer.toString(range(range.getUpper()))); xsw.writeEndElement(); xsw.writeEndElement(); }
From source file:org.slc.sli.modeling.xmi.writer.XmiWriter.java
private static final void writeReference(final Identifier reference, final ModelIndex mapper, final XMLStreamWriter xsw) throws XMLStreamException { if (reference == null) { throw new IllegalArgumentException("reference"); }/*from ww w .j ava 2 s. c om*/ mapper.lookup(reference, new Visitor() { @Override public void visit(final AssociationEnd associationEnd) { throw new AssertionError(); } @Override public void visit(final Attribute attribute) { throw new AssertionError(); } @Override public void visit(final ClassType classType) { try { if (classType.isClassType()) { if (classType.isAssociation()) { writeStartElement(XmiElementName.ASSOCIATION_CLASS, xsw); } else { writeStartElement(XmiElementName.CLASS, xsw); } } else { if (classType.isAssociation()) { writeStartElement(XmiElementName.ASSOCIATION, xsw); } else { throw new AssertionError(); } } } catch (final XMLStreamException e) { throw new XmiRuntimeException(e); } } @Override public void visit(final DataType dataType) { try { writeStartElement(XmiElementName.DATA_TYPE, xsw); } catch (final XMLStreamException e) { throw new XmiRuntimeException(e); } } @Override public void visit(final EnumLiteral enumLiteral) { throw new AssertionError(); } @Override public void visit(final EnumType enumType) { try { writeStartElement(XmiElementName.ENUMERATION, xsw); } catch (final XMLStreamException e) { throw new XmiRuntimeException(e); } } @Override public void visit(final Generalization generalization) { throw new AssertionError(); } @Override public void visit(final Model model) { throw new AssertionError(); } @Override public void visit(final Multiplicity multiplicity) { throw new AssertionError(); } @Override public void visit(final Range range) { throw new AssertionError(); } @Override public void visit(final TaggedValue taggedValue) { throw new AssertionError(); } @Override public void beginPackage(final UmlPackage pkg) { throw new AssertionError(); } @Override public void endPackage(final UmlPackage pkg) { throw new AssertionError(); } @Override public void visit(final TagDefinition tagDefinition) { try { writeStartElement(XmiElementName.TAG_DEFINITION, xsw); } catch (final XMLStreamException e) { throw new XmiRuntimeException(e); } } }); try { xsw.writeAttribute(XmiAttributeName.IDREF.getLocalName(), reference.toString()); } finally { xsw.writeEndElement(); } }
From source file:org.slc.sli.modeling.xmi.writer.XmiWriter.java
/** * Writes the UML model to the XML stream in XMI format. * * @param model The UML model.//from ww w . j a v a2s . c o m * @param xsw The XML stream. * @throws XMLStreamException if anything bad happens. */ private static final void writeXMI(final Model model, final ModelIndex mapper, final XMLStreamWriter xsw) throws XMLStreamException { xsw.writeStartElement("XMI"); try { xsw.writeNamespace("UML", NAMESPACE_UML); xsw.writeAttribute("xmi.version", "1.2"); writeContent(model, mapper, xsw); } finally { xsw.writeEndElement(); } }
From source file:org.staxcel.internal.SpreadSheetImpl.java
protected void flushDynamicTemplateWriter(TokenEnumerableTemplateWriter templateWriter, XMLOutputFactory xmlOutFactory) throws IOException { String token = templateWriter.getToken(); while (token != null) { XMLStreamWriter xmlWriter = null; try {/*w w w . j a v a 2 s.c o m*/ if (token.equals("worksheets.count")) { templateWriter.getOutputWriter().write(String.valueOf(this.worksheetList.size())); } else if (token.equals("worksheets.vector")) { xmlWriter = xmlOutFactory.createXMLStreamWriter(appXmlTemplateWriter.getOutputWriter()); xmlWriter.writeStartElement("vt:vector"); xmlWriter.writeAttribute("size", String.valueOf(this.worksheetList.size())); xmlWriter.writeAttribute("baseType", "lpstr"); for (int index = 0; index < this.worksheetList.size(); ++index) { xmlWriter.writeStartElement("vt:lpstr"); xmlWriter.writeCharacters(this.worksheetList.get(index).getName()); xmlWriter.writeEndElement(); } xmlWriter.writeEndElement(); } else if (token.equals("worksheet.relationships")) { xmlWriter = xmlOutFactory.createXMLStreamWriter(templateWriter.getOutputWriter()); for (int index = 0; index < worksheetList.size(); ++index) { WorksheetImpl worksheet = worksheetList.get(index); xmlWriter.writeStartElement("Relationship"); xmlWriter.writeAttribute("Id", "rId" + worksheet.getResourceId()); xmlWriter.writeAttribute("Type", OpenXMLNamespace.NS_OPENXML_OFFICE_DOC_2006_REL_WORKSHEET); xmlWriter.writeAttribute("Target", "worksheets/sheet" + worksheet.getWorksheetNumber() + ".xml"); xmlWriter.writeEndElement(); } } else if (token.equals("workbook.sheets")) { xmlWriter = xmlOutFactory.createXMLStreamWriter(templateWriter.getOutputWriter()); for (int index = 0; index < worksheetList.size(); ++index) { WorksheetImpl worksheet = worksheetList.get(index); xmlWriter.writeStartElement("sheet"); xmlWriter.writeAttribute("name", "Sheet" + worksheet.getWorksheetNumber()); xmlWriter.writeAttribute("sheetId", String.valueOf(worksheet.getWorksheetNumber())); xmlWriter.writeAttribute("r:id", "rId" + worksheet.getResourceId()); xmlWriter.writeEndElement(); } } else { // unknown. Invoke a protected method which can be // overridden by derived classes // to add new template variables and interpret them // accordingly. expandToken(token, templateWriter); } } catch (XMLStreamException ex) { throw new StaxcelException("Error when replacing " + token + " from template file", ex); } finally { if (xmlWriter != null) { try { xmlWriter.flush(); xmlWriter.close(); } catch (XMLStreamException ex2) { logger.error("Error when closing xmlstream", ex2); } } } token = templateWriter.nextElement(); } templateWriter.getOutputWriter().flush(); templateWriter.getOutputWriter().close(); }
From source file:org.staxcel.internal.SpreadSheetImpl.java
/** * Write all shared strings to ./xl/SharedStrings.xml file * /* www. ja va 2 s.c o m*/ * @throws IOException */ protected void addSharedStringsFile() throws IOException { try { BufferedWriter writer = createWriter(OpenXMLFormatConstants.SHARED_STRING_FILE_NAME); XMLStreamWriter xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer); xmlWriter.writeStartDocument("UTF-8", "1.0"); xmlWriter.writeStartElement("sst"); xmlWriter.writeAttribute("xmlns", OpenXMLNamespace.NS_OPENXML_SPREADSHEETML_2006_MAIN); xmlWriter.writeAttribute("count", String.valueOf(this.sharedStrings.size())); xmlWriter.writeAttribute("uniqueCount", String.valueOf(this.sharedStrings.size())); for (Entry<String, Integer> entry : this.sharedStrings.entrySet()) { xmlWriter.writeStartElement("si"); xmlWriter.writeStartElement("t"); xmlWriter.writeCharacters(entry.getKey()); xmlWriter.writeEndElement(); xmlWriter.writeEndElement(); } xmlWriter.writeEndElement(); xmlWriter.writeEndDocument(); xmlWriter.close(); writer.flush(); writer.close(); } catch (XMLStreamException ex) { logger.error("XML error when creating SharedStrings.xml file", ex); throw new StaxcelException("XML error when creating SharedStrings.xml file", ex); } }
From source file:org.tobarsegais.webapp.data.Plugin.java
public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("plugin"); writer.writeAttribute("name", getName()); writer.writeAttribute("id", getId()); writer.writeAttribute("version", getVersion()); writer.writeAttribute("provider-name", getProviderName()); for (Extension extension : getExtensions().values()) { extension.write(writer);/*w w w . j a va2 s .c om*/ } writer.writeEndElement(); }
From source file:org.tobarsegais.webapp.data.Toc.java
public void write(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("toc"); writer.writeAttribute("label", getLabel()); writer.writeAttribute("topic", getHref()); for (Topic topic : getChildren()) { topic.write(writer);/*from w ww .j a va 2s . co m*/ } writer.writeEndElement(); }
From source file:org.tolven.app.bean.DataExtractBean.java
public void streamResultsXML(Writer out, DataQueryResults dq) { Long totalCount = null;//from w w w . j a v a 2 s .c om if (dq.isReturnTotalCount()) { getMDQueryResults(dq, true); totalCount = (Long) dq.getIterator().next(); } if (dq.getLimit() != 0) { getMDQueryResults(dq, false); } try { XMLStreamWriter xmlStreamWriter = null; try { XMLOutputFactory factory = XMLOutputFactory.newInstance(); xmlStreamWriter = factory.createXMLStreamWriter(out); xmlStreamWriter.writeStartDocument("UTF-8", "1.0"); xmlStreamWriter.writeStartElement("results"); xmlStreamWriter.writeAttribute("path", dq.getPath()); xmlStreamWriter.writeAttribute("account", String.valueOf(dq.getAccount().getId())); xmlStreamWriter.writeAttribute("database", getTolvenPropertiesBean().getProperty("tolven.repository.oid")); GregorianCalendar nowCal = new GregorianCalendar(); nowCal.setTime(dq.getNow()); DatatypeFactory xmlFactory = DatatypeFactory.newInstance(); XMLGregorianCalendar ts = xmlFactory.newXMLGregorianCalendar(nowCal); xmlStreamWriter.writeAttribute("timestamp", ts.toXMLFormat()); if (!dq.isItemQuery()) { xmlStreamWriter.writeAttribute("offset", Long.toString(dq.getOffset())); xmlStreamWriter.writeAttribute("limit", Long.toString(dq.getLimit())); xmlStreamWriter.writeAttribute("count", Long.toString(dq.getCount())); } if (!dq.isItemQuery() && totalCount != null) { xmlStreamWriter.writeAttribute("totalCount", totalCount.toString()); } addExtendedFields(dq); //addPlaceholderIds(dq); if (MenuStructure.PLACEHOLDER.equals(dq.getMenuStructure().getRole())) { addParentFields(dq); } addSimpleXMLColumnHeadings(dq, xmlStreamWriter); if (dq.getLimit() != 0) { addXMLRows(dq, xmlStreamWriter); } xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeEndDocument(); } finally { if (xmlStreamWriter != null) { xmlStreamWriter.close(); } } } catch (Exception ex) { throw new RuntimeException("Could not obtain XML results for menupath: " + dq.getPath() + " in account: " + dq.getAccount().getId(), ex); } }