List of usage examples for javax.xml.stream XMLStreamWriter writeCharacters
public void writeCharacters(String text) throws XMLStreamException;
From source file:org.gluewine.trace.XMLTracer.java
@Override public void afterSuccess(Object o, Method m, Object[] params, Object result) { if (isSuppressed()) return;// w w w.j a va2 s.com XMLStreamWriter writer = getWriter(); if (writer != null) { try { if (!m.getReturnType().equals(Void.TYPE)) { writer.writeStartElement("result"); if (result != null) writer.writeCharacters(result.toString()); else writer.writeCharacters("null"); writer.writeEndElement(); } } catch (Throwable e) { ErrorLogger.log(getClass(), e); } } clearSuppression(); }
From source file:org.gluewine.trace.XMLTracer.java
@Override public void afterFailure(Object o, Method m, Object[] params, Throwable e) { if (isSuppressed()) return;/*from w w w .j a v a 2 s . com*/ XMLStreamWriter writer = getWriter(); if (writer != null) { try { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); writer.writeStartElement("exception"); writer.writeCharacters(sw.toString()); writer.writeEndElement(); } catch (Throwable t) { ErrorLogger.log(getClass(), t); } } clearSuppression(); }
From source file:org.gluu.saml.AuthRequest.java
public String getStreamedRequest(boolean useBase64) throws XMLStreamException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = factory.createXMLStreamWriter(baos); writer.writeStartElement("samlp", "AuthnRequest", "urn:oasis:names:tc:SAML:2.0:protocol"); writer.writeNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol"); writer.writeAttribute("ID", id); writer.writeAttribute("Version", "2.0"); writer.writeAttribute("IssueInstant", this.issueInstant); writer.writeAttribute("ProtocolBinding", "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"); writer.writeAttribute("AssertionConsumerServiceURL", this.samlSettings.getAssertionConsumerServiceUrl()); writer.writeStartElement("saml", "Issuer", "urn:oasis:names:tc:SAML:2.0:assertion"); writer.writeNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion"); writer.writeCharacters(this.samlSettings.getIssuer()); writer.writeEndElement();/*from ww w. j a va 2s .c om*/ writer.writeStartElement("samlp", "NameIDPolicy", "urn:oasis:names:tc:SAML:2.0:protocol"); writer.writeNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol"); writer.writeAttribute("Format", this.samlSettings.getNameIdentifierFormat()); writer.writeAttribute("AllowCreate", "true"); writer.writeEndElement(); writer.writeStartElement("samlp", "RequestedAuthnContext", "urn:oasis:names:tc:SAML:2.0:protocol"); writer.writeNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol"); writer.writeAttribute("Comparison", "exact"); writer.writeStartElement("saml", "AuthnContextClassRef", "urn:oasis:names:tc:SAML:2.0:assertion"); writer.writeNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion"); writer.writeCharacters("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndElement(); writer.flush(); if (log.isDebugEnabled()) { log.debug("Genereated Saml Request " + new String(baos.toByteArray(), "UTF-8")); } if (useBase64) { byte[] deflated = CompressionHelper.deflate(baos.toByteArray(), true); String base64 = Base64.encodeBase64String(deflated); String encoded = URLEncoder.encode(base64, "UTF-8"); return encoded; } return new String(baos.toByteArray(), "UTF-8"); }
From source file:org.gtdfree.model.GTDDataXMLTools.java
static public void store(GTDModel model, OutputStream out, ActionFilter filter) throws IOException, XMLStreamException, FactoryConfigurationError { if (filter == null) { filter = new DummyFilter(true); }//from w ww . jav a2s .c om XMLStreamWriter w = XMLOutputFactory.newInstance().createXMLStreamWriter(out, "UTF-8"); //$NON-NLS-1$ w.writeStartDocument("UTF-8", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ w.writeCharacters(EOL); w.writeCharacters(EOL); w.writeStartElement("gtd-data"); //$NON-NLS-1$ w.writeAttribute("version", "2.2"); //$NON-NLS-1$ //$NON-NLS-2$ w.writeAttribute("modified", ApplicationHelper.formatLongISO(new Date())); //$NON-NLS-1$ w.writeAttribute("lastActionID", Integer.toString(model.getLastActionID())); //$NON-NLS-1$ w.writeCharacters(EOL); w.writeCharacters(EOL); // Write folders Folder[] fn = model.toFoldersArray(); w.writeStartElement("lists"); //$NON-NLS-1$ w.writeCharacters(EOL); for (int i = 0; i < fn.length; i++) { Folder ff = fn[i]; if (ff.isMeta() || !filter.isAcceptable(ff, null)) { continue; } w.writeCharacters(SKIP); w.writeStartElement("list"); //$NON-NLS-1$ w.writeAttribute("id", String.valueOf(ff.getId())); //$NON-NLS-1$ w.writeAttribute("name", ff.getName()); //$NON-NLS-1$ w.writeAttribute("type", ff.getType().toString()); //$NON-NLS-1$ w.writeAttribute("closed", Boolean.toString(ff.isClosed())); //$NON-NLS-1$ if (ff.getCreated() != null) w.writeAttribute("created", Long.toString(ff.getCreated().getTime())); //$NON-NLS-1$ if (ff.getModified() != null) w.writeAttribute("modified", Long.toString(ff.getModified().getTime())); //$NON-NLS-1$ if (ff.getResolved() != null) w.writeAttribute("resolved", Long.toString(ff.getResolved().getTime())); //$NON-NLS-1$ if (!ff.isInBucket() && ff.getDescription() != null) { w.writeAttribute("description", ApplicationHelper.escapeControls(ff.getDescription())); //$NON-NLS-1$ } w.writeCharacters(EOL); for (Action a : ff) { if (!filter.isAcceptable(ff, a)) { continue; } w.writeCharacters(SKIPSKIP); w.writeStartElement("action"); //$NON-NLS-1$ w.writeAttribute("id", Integer.toString(a.getId())); //$NON-NLS-1$ w.writeAttribute("created", Long.toString(a.getCreated().getTime())); //$NON-NLS-1$ w.writeAttribute("resolution", a.getResolution().toString()); //$NON-NLS-1$ if (a.getResolved() != null) w.writeAttribute("resolved", Long.toString(a.getResolved().getTime())); //$NON-NLS-1$ if (a.getModified() != null) w.writeAttribute("modified", Long.toString(a.getModified().getTime())); //$NON-NLS-1$ if (a.getDescription() != null) w.writeAttribute("description", ApplicationHelper.escapeControls(a.getDescription())); //$NON-NLS-1$ if (a.getStart() != null) w.writeAttribute("start", Long.toString(a.getStart().getTime())); //$NON-NLS-1$ if (a.getRemind() != null) w.writeAttribute("remind", Long.toString(a.getRemind().getTime())); //$NON-NLS-1$ if (a.getDue() != null) w.writeAttribute("due", Long.toString(a.getDue().getTime())); //$NON-NLS-1$ if (a.getType() != null) w.writeAttribute("type", a.getType().toString()); //$NON-NLS-1$ if (a.getUrl() != null) w.writeAttribute("url", a.getUrl().toString()); //$NON-NLS-1$ if (a.isQueued()) w.writeAttribute("queued", Boolean.toString(a.isQueued())); //$NON-NLS-1$ if (a.getProject() != null) w.writeAttribute("project", a.getProject().toString()); //$NON-NLS-1$ if (a.getPriority() != null) w.writeAttribute("priority", a.getPriority().toString()); //$NON-NLS-1$ w.writeEndElement(); w.writeCharacters(EOL); } w.writeCharacters(SKIP); w.writeEndElement(); w.writeCharacters(EOL); } w.writeEndElement(); w.writeCharacters(EOL); // Write projects Project[] pn = model.toProjectsArray(); w.writeStartElement("projects"); //$NON-NLS-1$ w.writeCharacters(EOL); for (int i = 0; i < pn.length; i++) { Project ff = pn[i]; if (!filter.isAcceptable(ff, null)) { continue; } w.writeCharacters(SKIP); w.writeStartElement("project"); //$NON-NLS-1$ w.writeAttribute("id", String.valueOf(ff.getId())); //$NON-NLS-1$ w.writeAttribute("name", ff.getName()); //$NON-NLS-1$ w.writeAttribute("closed", String.valueOf(ff.isClosed())); //$NON-NLS-1$ if (ff.getCreated() != null) w.writeAttribute("created", Long.toString(ff.getCreated().getTime())); //$NON-NLS-1$ if (ff.getModified() != null) w.writeAttribute("modified", Long.toString(ff.getModified().getTime())); //$NON-NLS-1$ if (ff.getResolved() != null) w.writeAttribute("resolved", Long.toString(ff.getResolved().getTime())); //$NON-NLS-1$ if (ff.getDescription() != null) { w.writeAttribute("description", ApplicationHelper.escapeControls(ff.getDescription())); //$NON-NLS-1$ } StringBuilder sb = new StringBuilder(); for (Action a : ff) { if (!filter.isAcceptable(ff, a)) { continue; } if (sb.length() > 0) { sb.append(","); //$NON-NLS-1$ } sb.append(a.getId()); } w.writeAttribute("actions", sb.toString()); //$NON-NLS-1$ w.writeEndElement(); w.writeCharacters(EOL); } w.writeEndElement(); w.writeCharacters(EOL); // Write queue Folder f = model.getQueue(); if (filter.isAcceptable(f, null)) { w.writeStartElement("queue"); //$NON-NLS-1$ w.writeAttribute("id", String.valueOf(f.getId())); //$NON-NLS-1$ w.writeAttribute("name", f.getName()); //$NON-NLS-1$ StringBuilder sb = new StringBuilder(); Iterator<Action> i = f.iterator(); if (i.hasNext()) { sb.append(i.next().getId()); } while (i.hasNext()) { sb.append(","); //$NON-NLS-1$ sb.append(i.next().getId()); } w.writeAttribute("actions", sb.toString()); //$NON-NLS-1$ w.writeEndElement(); w.writeCharacters(EOL); } // containers w.writeEndElement(); w.writeEndDocument(); w.flush(); w.close(); //changed=false; }
From source file:org.icgc.dcc.portal.manifest.writer.GNOSManifestWriter.java
private static void addFileInfoEntriesToXml(XMLStreamWriter writer, Iterable<ManifestFile> info) throws XMLStreamException { for (val file : info) { writer.writeStartElement(GNOS_FILE); addXmlElement(writer, GNOS_FILE_NAME, file.getName()); addXmlElement(writer, GNOS_FILE_SIZE, file.getSize() + ""); writer.writeStartElement(GNOS_CHECK_SUM); writer.writeAttribute("type", "md5"); writer.writeCharacters(file.getMd5sum()); writer.writeEndElement();//from w ww . j a v a 2 s . c o m writer.writeEndElement(); } }
From source file:org.icgc.dcc.portal.manifest.writer.GNOSManifestWriter.java
private static void addXmlElement(XMLStreamWriter writer, String elementName, String elementValue) throws XMLStreamException { writer.writeStartElement(elementName); writer.writeCharacters(elementValue); writer.writeEndElement();//from w w w.j av a 2 s . c om }
From source file:org.intermine.api.tracker.xml.TemplateTrackBinding.java
/** * Convert a TemplateTrack to XML and write XML to given writer. * @param uos the UserObjectStore//from w w w . j av a 2 s.c o m * @param writer the XMLStreamWriter to write to */ public static void marshal(ObjectStore uos, XMLStreamWriter writer) { Connection conn = null; Statement stm = null; ResultSet rs = null; try { writer.writeCharacters("\n"); writer.writeStartElement(TEMPLATETRACKS); conn = ((ObjectStoreWriterInterMineImpl) uos).getConnection(); String sql = "SELECT templatename, username, sessionidentifier,timestamp " + "FROM " + TrackerUtil.TEMPLATE_TRACKER_TABLE; stm = conn.createStatement(); rs = stm.executeQuery(sql); while (rs.next()) { writer.writeCharacters("\n"); writer.writeStartElement(TEMPLATETRACK); writer.writeAttribute("templatename", rs.getString(1)); String username = rs.getString(2); if (!StringUtils.isBlank(username)) { writer.writeAttribute("username", username); } writer.writeAttribute("sessionidentifier", rs.getString(3)); writer.writeAttribute("timestamp", rs.getTimestamp(4).toString()); writer.writeEndElement(); } writer.writeCharacters("\n"); writer.writeEndElement(); } catch (SQLException sqle) { LOG.error("The templatetrack table does't exist!", sqle); try { writer.writeEndElement(); } catch (XMLStreamException e) { } } catch (XMLStreamException e) { throw new RuntimeException("exception while marshalling template tracks", e); } finally { if (rs != null) { try { rs.close(); if (stm != null) { stm.close(); } } catch (SQLException e) { LOG.error("Problem closing resources.", e); } } ((ObjectStoreWriterInterMineImpl) uos).releaseConnection(conn); } }
From source file:org.intermine.pathquery.PathQueryBinding.java
/** * Create XML for the constraints in a PathQuery. */// w w w . j ava 2 s. c om private void marshalPathQueryConstraints(PathQuery query, XMLStreamWriter writer, boolean hasMultipleConstraints) throws XMLStreamException { for (Map.Entry<PathConstraint, String> constraint : query.getConstraints().entrySet()) { boolean emptyElement = true; if (constraint.getKey() instanceof PathConstraintMultiValue) { emptyElement = false; } if (emptyElement) { writer.writeEmptyElement("constraint"); } else { writer.writeStartElement("constraint"); } writer.writeAttribute("path", constraint.getKey().getPath()); if ((constraint.getValue() != null) && (hasMultipleConstraints)) { writer.writeAttribute("code", constraint.getValue()); } doAdditionalConstraintStuff(query, constraint.getKey(), writer); if (constraint.getKey() instanceof PathConstraintAttribute) { writer.writeAttribute("op", "" + constraint.getKey().getOp()); String outputValue = ((PathConstraintAttribute) constraint.getKey()).getValue(); writer.writeAttribute("value", "" + outputValue); } else if (constraint.getKey() instanceof PathConstraintNull) { writer.writeAttribute("op", "" + constraint.getKey().getOp()); } else if (constraint.getKey() instanceof PathConstraintSubclass) { writer.writeAttribute("type", ((PathConstraintSubclass) constraint.getKey()).getType()); } else if (constraint.getKey() instanceof PathConstraintBag) { writer.writeAttribute("op", "" + constraint.getKey().getOp()); writer.writeAttribute("value", ((PathConstraintBag) constraint.getKey()).getBag()); } else if (constraint.getKey() instanceof PathConstraintIds) { writer.writeAttribute("op", "" + constraint.getKey().getOp()); StringBuilder sb = new StringBuilder(); boolean needComma = false; for (Integer id : ((PathConstraintIds) constraint.getKey()).getIds()) { if (needComma) { sb.append(", "); } needComma = true; sb.append("" + id); } writer.writeAttribute("ids", sb.toString()); } else if (constraint.getKey() instanceof PathConstraintMultiValue) { // Includes PathConstraintRange, which is serialised in the exact same manner. writer.writeAttribute("op", "" + constraint.getKey().getOp()); for (String value : ((PathConstraintMultiValue) constraint.getKey()).getValues()) { if (value == null) { writer.writeStartElement("nullValue"); writer.writeEndElement(); } else { if (!value.equals(value.trim())) { throw new XMLStreamException("Value in MultiValue starts or ends with " + "whitespace - this query cannot be represented in XML"); } writer.writeStartElement("value"); writer.writeCharacters(value); writer.writeEndElement(); } } } else if (constraint.getKey() instanceof PathConstraintLoop) { writer.writeAttribute("op", "" + constraint.getKey().getOp()); writer.writeAttribute("loopPath", ((PathConstraintLoop) constraint.getKey()).getLoopPath()); } else if (constraint.getKey() instanceof PathConstraintLookup) { writer.writeAttribute("op", "" + constraint.getKey().getOp()); writer.writeAttribute("value", ((PathConstraintLookup) constraint.getKey()).getValue()); String extraValue = ((PathConstraintLookup) constraint.getKey()).getExtraValue(); if (extraValue != null) { writer.writeAttribute("extraValue", extraValue); } } else { throw new IllegalStateException( "Unrecognised constraint type " + constraint.getKey().getClass().getName()); } if (!emptyElement) { writer.writeEndElement(); } } }
From source file:org.intermine.template.xml.TemplateQueryBinding.java
/** * Convert a TemplateQuery to XML and write XML to given writer. * * @param template the TemplateQuery//from w w w . j av a 2 s . c o m * @param writer the XMLStreamWriter to write to * @param version the version number of the XML format */ public void doMarshal(TemplateQuery template, XMLStreamWriter writer, int version) { if (template == null) { throw new NullPointerException("template must not be null"); } if (writer == null) { throw new NullPointerException("writer must not be null"); } try { writer.writeCharacters("\n"); writer.writeStartElement("template"); writer.writeAttribute("name", template.getName()); if (template.getTitle() != null) { writer.writeAttribute("title", template.getTitle()); } if (template.getComment() == null) { writer.writeAttribute("comment", ""); } else { writer.writeAttribute("comment", template.getComment()); } doMarshal(template, template.getName(), template.getModel().getName(), writer, version); writer.writeEndElement(); } catch (XMLStreamException e) { throw new RuntimeException(e); } }
From source file:org.mule.module.xml.util.XMLUtils.java
public static void copy(XMLStreamReader reader, XMLStreamWriter writer, boolean fragment) throws XMLStreamException { // number of elements read in int read = 0; int event = reader.getEventType(); while (reader.hasNext()) { switch (event) { case XMLStreamConstants.START_ELEMENT: read++;//from w ww. ja v a2 s. co m writeStartElement(reader, writer); break; case XMLStreamConstants.END_ELEMENT: writer.writeEndElement(); read--; if (read <= 0 && !fragment) { return; } break; case XMLStreamConstants.CHARACTERS: writer.writeCharacters(reader.getText()); break; case XMLStreamConstants.START_DOCUMENT: case XMLStreamConstants.END_DOCUMENT: case XMLStreamConstants.ATTRIBUTE: case XMLStreamConstants.NAMESPACE: break; default: break; } event = reader.next(); } }