List of usage examples for javax.xml.stream XMLStreamWriter writeAttribute
public void writeAttribute(String localName, String value) throws XMLStreamException;
From source file:org.osaf.cosmo.model.text.XhtmlTicketFormat.java
public String format(Ticket ticket) { try {// w w w . j av a 2 s. com StringWriter sw = new StringWriter(); XMLStreamWriter writer = createXmlWriter(sw); writer.writeStartElement("div"); writer.writeAttribute("class", "ticket"); if (ticket.getKey() != null) { writer.writeCharacters("Key: "); writer.writeStartElement("span"); writer.writeAttribute("class", "key"); writer.writeCharacters(ticket.getKey()); writer.writeEndElement(); } if (ticket.getType() != null) { writer.writeCharacters("Type: "); writer.writeStartElement("span"); writer.writeAttribute("class", "type"); writer.writeAttribute("title", ticket.getType().toString()); writer.writeCharacters(ticket.getType().toString()); writer.writeEndElement(); } if (ticket.getTimeout() != null) { writer.writeCharacters("Timeout: "); writer.writeStartElement("span"); writer.writeAttribute("class", "timeout"); writer.writeAttribute("title", ticket.getTimeout().toString()); writer.writeCharacters(ticket.getTimeout().toString()); writer.writeEndElement(); } writer.writeEndElement(); writer.close(); return sw.toString(); } catch (XMLStreamException e) { throw new RuntimeException("Error formatting XML", e); } }
From source file:org.rhq.enterprise.server.sync.ExportingInputStream.java
/** * @param wrt// w w w.j a v a 2 s. c o m */ private void writeValidators(XMLStreamWriter wrt) throws XMLStreamException { Set<ConsistencyValidator> allValidators = new HashSet<ConsistencyValidator>(); for (Synchronizer<?, ?> syn : synchronizers) { allValidators.addAll(syn.getRequiredValidators()); } for (ConsistencyValidator cv : allValidators) { wrt.writeStartElement(SynchronizationConstants.VALIDATOR_ELEMENT); wrt.writeAttribute(SynchronizationConstants.CLASS_ATTRIBUTE, cv.getClass().getName()); cv.exportState(new ExportWriter(wrt)); wrt.writeEndElement(); } }
From source file:org.rhq.enterprise.server.sync.ExportingInputStream.java
/** * @param wrt/*from w w w.j a va 2 s. co m*/ * @param syn * @return * @throws XMLStreamException */ private void exportSingle(XMLStreamWriter wrt, Synchronizer<?, ?> syn) throws XMLStreamException { ExporterMessages messages = new ExporterMessages(); messagesPerExporter.put(syn.getClass().getName(), messages); wrt.writeStartElement(SynchronizationConstants.EXPORT_NAMESPACE, SynchronizationConstants.ENTITIES_EXPORT_ELEMENT); wrt.writeAttribute(SynchronizationConstants.ID_ATTRIBUTE, syn.getClass().getName()); Exporter<?, ?> exp = syn.getExporter(); ExportingIterator<?> it = exp.getExportingIterator(); DefaultImportConfigurationDescriptor importConfig = getDefaultImportConfiguraton(syn); if (importConfig != null) { try { configurationMarshaller.marshal(importConfig, wrt); } catch (JAXBException e) { throw new XMLStreamException(e); } } messages.setPerEntityErrorMessages(new ArrayList<String>()); messages.setPerEntityNotes(new ArrayList<String>()); while (it.hasNext()) { it.next(); wrt.writeStartElement(SynchronizationConstants.EXPORT_NAMESPACE, SynchronizationConstants.ENTITY_EXPORT_ELEMENT); wrt.writeStartElement(SynchronizationConstants.EXPORT_NAMESPACE, SynchronizationConstants.DATA_ELEMENT); Exception exportError = null; try { it.export(new ExportWriter(wrt)); } catch (XMLStreamException e) { //there's not much we can do about these but to give up. throw e; } catch (Exception e) { exportError = e; } wrt.writeEndElement(); //data if (exportError == null) { String notes = it.getNotes(); if (notes != null) { messages.getPerEntityNotes().add(notes); wrt.writeStartElement(SynchronizationConstants.EXPORT_NAMESPACE, SynchronizationConstants.NOTES_ELEMENT); wrt.writeCharacters(notes); wrt.writeEndElement(); } } else { String message = ThrowableUtil.getStackAsString(exportError); messages.getPerEntityErrorMessages().add(message); wrt.writeStartElement(SynchronizationConstants.EXPORT_NAMESPACE, SynchronizationConstants.ERROR_MESSAGE_ELEMENT); wrt.writeCharacters(message); wrt.writeEndElement(); } wrt.writeEndElement(); //entity } String notes = exp.getNotes(); messages.setExporterNotes(notes); if (notes != null) { wrt.writeStartElement(SynchronizationConstants.EXPORT_NAMESPACE, SynchronizationConstants.NOTES_ELEMENT); wrt.writeCharacters(notes); wrt.writeEndElement(); } wrt.writeEndElement(); //entities }
From source file:org.simbasecurity.core.saml.SAMLServiceImpl.java
@Override public String createAuthRequest(String authRequestId, Date issueInstant) throws XMLStreamException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = factory.createXMLStreamWriter(baos); writer.writeStartElement("samlp", "AuthnRequest", NS_SAMLP); writer.writeNamespace("samlp", NS_SAMLP); writer.writeAttribute("ID", "_" + authRequestId); writer.writeAttribute("Version", "2.0"); writer.writeAttribute("IssueInstant", SAML_DATE_FORMAT.format(issueInstant)); writer.writeAttribute("ForceAuthn", "false"); writer.writeAttribute("IsPassive", "false"); writer.writeAttribute("ProtocolBinding", BINDING_HTTP_POST); writer.writeAttribute("AssertionConsumerServiceURL", configurationService.getValue(SimbaConfigurationParameter.SAML_ASSERTION_CONSUMER_SERVICE_URL)); writer.writeStartElement("saml", "Issuer", NS_SAML); writer.writeNamespace("saml", NS_SAML); writer.writeCharacters(configurationService.getValue(SimbaConfigurationParameter.SAML_ISSUER)); writer.writeEndElement();/* w w w . j a va2 s. c o m*/ writer.writeStartElement("samlp", "NameIDPolicy", NS_SAMLP); writer.writeAttribute("Format", NAMEID_TRANSIENT); writer.writeAttribute("SPNameQualifier", configurationService.getValue(SimbaConfigurationParameter.SAML_ISSUER)); writer.writeAttribute("AllowCreate", "true"); writer.writeEndElement(); writer.writeStartElement("samlp", "RequestedAuthnContext", NS_SAMLP); writer.writeNamespace("samlp", NS_SAMLP); writer.writeAttribute("Comparison", "exact"); writer.writeStartElement("saml", "AuthnContextClassRef", NS_SAML); writer.writeNamespace("saml", NS_SAML); writer.writeCharacters(AC_FAS_EID); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndElement(); writer.flush(); return encodeSAMLRequest(baos.toByteArray()); }
From source file:org.simbasecurity.core.saml.SAMLServiceImpl.java
@Override public String createLogoutRequest(String logoutRequestId, Date issueInstant, String nameId, String sessionIndex) throws XMLStreamException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = factory.createXMLStreamWriter(baos); writer.writeStartElement("samlp", "LogoutRequest", NS_SAMLP); writer.writeNamespace("samlp", NS_SAMLP); writer.writeAttribute("ID", "_" + logoutRequestId); writer.writeAttribute("Version", "2.0"); writer.writeAttribute("IssueInstant", SAML_DATE_FORMAT.format(issueInstant)); writer.writeStartElement("saml", "Issuer", NS_SAML); writer.writeNamespace("saml", NS_SAML); writer.writeCharacters("https://iamapps.belgium.be/"); writer.writeEndElement();//from w w w . j ava 2s. co m writer.writeStartElement("saml", "NameID", NS_SAML); writer.writeNamespace("saml", NS_SAML); writer.writeAttribute("NameQualifier", configurationService.getValue(SimbaConfigurationParameter.SAML_IDP_SLO_TARGET_URL)); writer.writeAttribute("SPNameQualifier", "https://iamapps.belgium.be/"); writer.writeAttribute("Format", NAMEID_TRANSIENT); writer.writeCharacters(nameId); writer.writeEndElement(); writer.writeStartElement("samlp", "SessionIndex", NS_SAMLP); writer.writeNamespace("saml", NS_SAMLP); writer.writeCharacters(sessionIndex); writer.writeEndElement(); writer.writeEndElement(); writer.flush(); return encodeSAMLRequest(baos.toByteArray()); }
From source file:org.slc.sli.modeling.tools.xsdgen.Uml2XsdWriter.java
private static final void maxOccurs(final Occurs value, final XMLStreamWriter xsw) throws XMLStreamException { xsw.writeAttribute(XsdAttributeName.MAX_OCCURS.getLocalName(), toString(value)); }
From source file:org.slc.sli.modeling.tools.xsdgen.Uml2XsdWriter.java
private static final void minOccurs(final Occurs value, final XMLStreamWriter xsw) throws XMLStreamException { xsw.writeAttribute(XsdAttributeName.MIN_OCCURS.getLocalName(), toString(value)); }
From source file:org.slc.sli.modeling.tools.xsdgen.Uml2XsdWriter.java
private static final void writeAttribute(final XsdAttributeName attributeName, final QName name, final XMLStreamWriter xsw) throws XMLStreamException { xsw.writeAttribute(attributeName.getLocalName(), typeLexicalName(name, xsw)); }
From source file:org.slc.sli.modeling.tools.xsdgen.Uml2XsdWriter.java
private static final void writeElementName(final QName name, final XMLStreamWriter xsw) throws XMLStreamException { xsw.writeAttribute(XsdAttributeName.NAME.getLocalName(), name.getLocalPart()); }
From source file:org.slc.sli.modeling.tools.xsdgen.Uml2XsdWriter.java
private static final void writeFormDefaultForAttributes(final boolean qualified, final XMLStreamWriter xsw) throws XMLStreamException { xsw.writeAttribute(XsdAttributeName.ATTRIBUTE_FORM_DEFAULT.getLocalName(), qualified ? QUALIFIED : UNQUALIFIED); }