List of usage examples for javax.xml.stream XMLStreamWriter writeStartDocument
public void writeStartDocument(String encoding, String version) throws XMLStreamException;
From source file:de.shadowhunt.subversion.internal.LockOperation.java
@Override protected HttpUriRequest createRequest() { final URI uri = URIUtils.createURI(repository, resource); final DavTemplateRequest request = new DavTemplateRequest("LOCK", uri); if (steal) {//from w w w . j a v a 2 s.c om request.addHeader("X-SVN-Options", "lock-steal"); } final Writer body = new StringBuilderWriter(); try { final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("lockinfo"); writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE); writer.writeStartElement("lockscope"); writer.writeEmptyElement("exclusive"); writer.writeEndElement(); // lockscope writer.writeStartElement("locktype"); writer.writeEmptyElement("write"); writer.writeEndElement(); // locktype writer.writeEndElement(); //lockinfo writer.writeEndDocument(); writer.close(); } catch (final XMLStreamException e) { throw new SubversionException("could not create request body", e); } request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML)); return request; }
From source file:de.shadowhunt.subversion.internal.ResolveOperation.java
@Override protected HttpUriRequest createRequest() { final Writer body = new StringBuilderWriter(); try {// ww w. jav a 2 s. co m final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("get-locations"); writer.writeDefaultNamespace(XmlConstants.SVN_NAMESPACE); writer.writeEmptyElement("path"); writer.writeStartElement("peg-revision"); writer.writeCharacters(revision.toString()); writer.writeEndElement(); // peg-revision writer.writeStartElement("location-revision"); writer.writeCharacters(expected.toString()); writer.writeEndElement(); // location-revision writer.writeEndElement(); //get-locations writer.writeEndDocument(); writer.close(); } catch (final XMLStreamException e) { throw new SubversionException("could not create request body", e); } final URI uri = URIUtils.createURI(repository, resource); final DavTemplateRequest request = new DavTemplateRequest("REPORT", uri); request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML)); return request; }
From source file:de.shadowhunt.subversion.internal.LogOperation.java
@Override protected HttpUriRequest createRequest() { final Writer body = new StringBuilderWriter(); try {/*from www. j a va 2s . c om*/ final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("log-report"); writer.writeDefaultNamespace(XmlConstants.SVN_NAMESPACE); writer.writeStartElement("start-revision"); writer.writeCharacters(start.toString()); writer.writeEndElement(); // start-revision writer.writeStartElement("end-revision"); writer.writeCharacters(end.toString()); writer.writeEndElement(); // end-revision if (limit > 0) { writer.writeStartElement("limit"); writer.writeCharacters(Integer.toString(limit)); writer.writeEndElement(); // limit } writer.writeEmptyElement("discover-changed-paths"); writer.writeEmptyElement("all-revprops"); writer.writeEmptyElement("path"); writer.writeEndElement(); // log-report writer.writeEndDocument(); writer.close(); } catch (final XMLStreamException e) { throw new SubversionException("could not create request body", e); } final URI uri = URIUtils.createURI(repository, resource); final DavTemplateRequest request = new DavTemplateRequest("REPORT", uri); request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML)); return request; }
From source file:de.qucosa.webapi.v1.RelationResource.java
@RequestMapping(value = "/relation/urn/{URN}", method = RequestMethod.GET) public ResponseEntity<String> describeRelationships(@PathVariable String URN) throws XMLStreamException, IOException, FedoraClientException { String pid = fedoraRepository.getPIDByIdentifier(URN); List<Tuple<String>> constituentPredecessorPids = fedoraRepository.getPredecessorPIDs(pid, FedoraRepository.RELATION_CONSTITUENT); List<Tuple<String>> derivativePredecessorPIDs = fedoraRepository.getPredecessorPIDs(pid, FedoraRepository.RELATION_DERIVATIVE); List<Tuple<String>> constituentSuccessorPids = fedoraRepository.getSuccessorPIDs(pid, FedoraRepository.RELATION_CONSTITUENT); List<Tuple<String>> derivativeSuccessorPids = fedoraRepository.getSuccessorPIDs(pid, FedoraRepository.RELATION_DERIVATIVE); XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory(); StringWriter sw = new StringWriter(); XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(sw); w.writeStartDocument("UTF-8", "1.0"); w.writeStartElement("Opus"); w.writeStartElement("Opus_Document"); w.writeStartElement("DocumentId"); w.writeCharacters(stripPrefix(pid)); w.writeEndElement();//from w w w . ja v a2 s . c om w.writeStartElement("Relations"); writeRelationElement(constituentPredecessorPids, w, "PredecessorRelation", "journal"); writeRelationElement(derivativePredecessorPIDs, w, "PredecessorRelation", "predecessor"); writeRelationElement(constituentSuccessorPids, w, "SuccessorRelation", "issue"); writeRelationElement(derivativeSuccessorPids, w, "SuccessorRelation", "predecessor"); w.writeEndElement(); w.writeEndElement(); w.writeEndElement(); w.writeEndDocument(); w.flush(); return new ResponseEntity<>(sw.toString(), HttpStatus.OK); }
From source file:de.shadowhunt.subversion.internal.ProbeServerOperation.java
@Override protected HttpUriRequest createRequest() { final Writer body = new StringBuilderWriter(); try {/*from w ww . j av a2 s . com*/ final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("options"); writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE); writer.writeEmptyElement("activity-collection-set"); writer.writeEndElement(); //options writer.writeEndDocument(); writer.close(); } catch (final XMLStreamException e) { throw new SubversionException("could not create request body: " + e.getMessage(), e); } final DavTemplateRequest request = new DavTemplateRequest("OPTIONS", repository); request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML)); return request; }
From source file:de.shadowhunt.subversion.internal.MergeOperation.java
@Override protected HttpUriRequest createRequest() { final DavTemplateRequest request = new DavTemplateRequest("MERGE", repository); request.addHeader("X-SVN-Options", "release-locks"); final Writer body = new StringBuilderWriter(); try {//w ww.j a v a 2s.c o m final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("merge"); writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE); writer.writeStartElement("source"); writer.writeStartElement("href"); writer.writeCData(repository.getPath() + resource.getValue()); writer.writeEndElement(); // href writer.writeEndElement(); // source writer.writeEmptyElement("no-auto-merge"); writer.writeEmptyElement("no-checkout"); writer.writeStartElement("prop"); writer.writeEmptyElement("checked-in"); writer.writeEmptyElement("version-name"); writer.writeEmptyElement("resourcetype"); writer.writeEmptyElement("creationdate"); writer.writeEmptyElement("creator-displayname"); writer.writeEndElement(); // prop if (!infoSet.isEmpty()) { writer.setPrefix(XmlConstants.SVN_PREFIX, XmlConstants.SVN_NAMESPACE); writer.writeStartElement(XmlConstants.SVN_NAMESPACE, "lock-token-list"); writer.writeNamespace(XmlConstants.SVN_PREFIX, XmlConstants.SVN_NAMESPACE); for (final Info info : infoSet) { final String lockToken = info.getLockToken(); assert (lockToken != null) : "must not be null"; final Resource infoResource = info.getResource(); writer.writeStartElement(XmlConstants.SVN_NAMESPACE, "lock"); writer.writeStartElement(XmlConstants.SVN_NAMESPACE, "lock-path"); writer.writeCData(infoResource.getValueWithoutLeadingSeparator()); writer.writeEndElement(); // lock-path writer.writeStartElement(XmlConstants.SVN_NAMESPACE, "lock-token"); writer.writeCharacters(lockToken); writer.writeEndElement(); // lock-token writer.writeEndElement(); // lock } writer.writeEndElement(); // lock-token-list } writer.writeEndElement(); // merge writer.writeEndDocument(); writer.close(); } catch (final XMLStreamException e) { throw new SubversionException("could not create request body", e); } request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML)); return request; }
From source file:de.shadowhunt.subversion.internal.PropertiesUpdateOperation.java
@Override protected HttpUriRequest createRequest() { final URI uri = URIUtils.createURI(repository, resource); final DavTemplateRequest request = new DavTemplateRequest("PROPPATCH", uri); if (lockToken != null) { request.addHeader("If", "<" + uri + "> (<" + lockToken + ">)"); }//from w ww . j ava2 s . co m final Writer body = new StringBuilderWriter(); try { final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("propertyupdate"); writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE); writer.setPrefix(XmlConstants.SUBVERSION_CUSTOM_PREFIX, XmlConstants.SUBVERSION_CUSTOM_NAMESPACE); writer.writeNamespace(XmlConstants.SUBVERSION_CUSTOM_PREFIX, XmlConstants.SUBVERSION_CUSTOM_NAMESPACE); writer.setPrefix(XmlConstants.SUBVERSION_DAV_PREFIX, XmlConstants.SUBVERSION_DAV_NAMESPACE); writer.writeNamespace(XmlConstants.SUBVERSION_DAV_PREFIX, XmlConstants.SUBVERSION_DAV_NAMESPACE); writer.setPrefix(XmlConstants.SUBVERSION_SVN_PREFIX, XmlConstants.SUBVERSION_SVN_NAMESPACE); writer.writeNamespace(XmlConstants.SUBVERSION_SVN_PREFIX, XmlConstants.SUBVERSION_SVN_NAMESPACE); writer.writeStartElement(type.action); writer.writeStartElement("prop"); for (final ResourceProperty property : properties) { final String prefix = property.getType().getPrefix(); if (type == Type.SET) { writer.writeStartElement(prefix, ResourcePropertyUtils.escapedKeyNameXml(property.getName())); writer.writeCharacters(property.getValue()); writer.writeEndElement(); } else { writer.writeEmptyElement(prefix, property.getName()); } } writer.writeEndElement(); // prop writer.writeEndElement(); // set || delete writer.writeEndElement(); // propertyupdate writer.writeEndDocument(); writer.close(); } catch (final XMLStreamException e) { throw new SubversionException("could not create request body", e); } final String bodyWithMakers = body.toString(); final String bodyWithoutMakers = ResourcePropertyUtils.filterMarker(bodyWithMakers); request.setEntity(new StringEntity(bodyWithoutMakers, CONTENT_TYPE_XML)); return request; }
From source file:de.shadowhunt.subversion.internal.AbstractPropfindOperation.java
@Override protected HttpUriRequest createRequest() { final URI uri = URIUtils.createURI(repository, resource); final DavTemplateRequest request = new DavTemplateRequest("PROPFIND", uri); request.addHeader("Depth", depth.value); final Writer body = new StringBuilderWriter(); try {//ww w .j a v a 2s .co m final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("propfind"); writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE); if (requestedProperties == null) { writer.writeEmptyElement("prop"); } else { if (requestedProperties.length == 0) { writer.writeEmptyElement("allprop"); } else { writer.writeStartElement("prop"); if (contains(XmlConstants.SUBVERSION_DAV_NAMESPACE)) { writer.writeNamespace(XmlConstants.SUBVERSION_DAV_PREFIX, XmlConstants.SUBVERSION_DAV_NAMESPACE); writer.setPrefix(XmlConstants.SUBVERSION_DAV_PREFIX, XmlConstants.SUBVERSION_DAV_NAMESPACE); } if (contains(XmlConstants.SUBVERSION_SVN_NAMESPACE)) { writer.writeNamespace(XmlConstants.SUBVERSION_SVN_PREFIX, XmlConstants.SUBVERSION_SVN_NAMESPACE); writer.setPrefix(XmlConstants.SUBVERSION_SVN_PREFIX, XmlConstants.SUBVERSION_SVN_NAMESPACE); } for (final ResourceProperty.Key requestedProperty : requestedProperties) { writer.writeEmptyElement(requestedProperty.getType().getPrefix(), requestedProperty.getName()); } writer.writeEndElement(); // prop } } writer.writeEndElement(); // propfind writer.writeEndDocument(); writer.close(); } catch (final XMLStreamException e) { throw new SubversionException("could not create request body", e); } request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML)); return request; }
From source file:com.acc.xstream.XmlXStreamMarshallerFactory.java
protected XStreamMarshaller createMarshaller() { //final XStream localXStream = getXStream(); final StaxDriver driver = new StaxDriver() { @Override//from w w w .j a v a 2s . co m public StaxWriter createStaxWriter(final XMLStreamWriter out) throws XMLStreamException { out.writeStartDocument("UTF-8", "1.0"); return createStaxWriter(out, false); } }; final XStreamMarshaller marshaller = new XStreamMarshaller() { @Override public XStream getXStream() { return XmlXStreamMarshallerFactory.this.getXStream(); } }; marshaller.setStreamDriver(driver); return marshaller; }
From source file:net.solarnetwork.web.support.SimpleXmlHttpMessageConverter.java
@Override protected void writeInternal(Object t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { OutputStream out = outputMessage.getBody(); try {/*from w w w. j a v a 2s . c om*/ XMLStreamWriter writer = xmlOutputFactory.createXMLStreamWriter(out, "UTF-8"); writer.writeStartDocument("UTF-8", "1.0"); outputObject(t, t.getClass().getSimpleName(), writer); writer.flush(); } catch (XMLStreamException e) { throw new HttpMessageConversionException("Error creating XMLStreamWriter", e); } }