List of usage examples for javax.xml.stream XMLStreamWriter writeEndElement
public void writeEndElement() throws XMLStreamException;
From source file:com.fiorano.openesb.application.application.InputPortInstance.java
protected void toJXMLString_2(XMLStreamWriter writer, boolean writeSchema) throws XMLStreamException, FioranoException { if (writeSchema || subscriberConfigName == null) { // We need to write port properties to stream when passing application launch packet to peer writer.writeStartElement(ELEM_SUBSCRIBER); {// www . ja v a2s . c o m if (sessionCount != 1) writer.writeAttribute(ATTR_SESSION_COUNT, String.valueOf(sessionCount)); if (acknowledgementMode != ACKNOWLEDGEMENT_MODE_DUPS_OK) writer.writeAttribute(ATTR_ACKNOWLEDGEMENT_MODE, String.valueOf(acknowledgementMode)); if (!StringUtils.isEmpty(messageSelector)) writer.writeAttribute(ATTR_MESSAGE_SELECTOR, String.valueOf(messageSelector)); writer.writeStartElement(ELEM_TRANSACTION); { writer.writeAttribute(ATTR_TRANSACTED, String.valueOf(transacted)); if (transactionSize != 0) writer.writeAttribute(ATTR_TRANSACTION_SIZE, String.valueOf(transactionSize)); } writer.writeEndElement(); writer.writeStartElement(ELEM_SUBSCRIPTION); { writer.writeAttribute(ATTR_DURABLE_SUBSCRIPTION, String.valueOf(durableSubscription)); if (!StringUtils.isEmpty(subscriptionName)) writer.writeAttribute(ATTR_SUBSCRIPTION_NAME, String.valueOf(subscriptionName)); } writer.writeEndElement(); } writer.writeEndElement(); } else { writer.writeStartElement(ELEM_SUBSCRIBER_CONFIG_NAME); { writer.writeAttribute(ATTR_NAME, subscriberConfigName); } writer.writeEndElement(); } }
From source file:com.tamingtext.tagrecommender.ExtractStackOverflowData.java
/** Extract as many as <code>limit</code> questions from the <code>reader</code> * provided, writing them to <code>writer</code>. * @param reader/* ww w . j av a2 s . c om*/ * @param writer * @param limit * @return * @throws XMLStreamException */ protected int extractXMLData(XMLStreamReader reader, XMLStreamWriter writer, int limit) throws XMLStreamException { int questionCount = 0; int attrCount; boolean copyElement = false; writer.writeStartDocument(); writer.writeStartElement("posts"); writer.writeCharacters("\n"); while (reader.hasNext() && questionCount < limit) { switch (reader.next()) { case XMLEvent.START_ELEMENT: if (reader.getLocalName().equals("row")) { attrCount = reader.getAttributeCount(); for (int i = 0; i < attrCount; i++) { // copy only the questions. if (reader.getAttributeName(i).getLocalPart().equals("PostTypeId") && reader.getAttributeValue(i).equals("1")) { copyElement = true; break; } } if (copyElement) { writer.writeCharacters(" "); writer.writeStartElement("row"); for (int i = 0; i < attrCount; i++) { writer.writeAttribute(reader.getAttributeName(i).getLocalPart(), reader.getAttributeValue(i)); } writer.writeEndElement(); writer.writeCharacters("\n"); copyElement = false; questionCount++; } } break; } } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); writer.close(); return questionCount; }
From source file:de.escidoc.core.common.util.xml.XmlUtility.java
/** * Adds a new element to the provided {@code XMLStreamWriter} containing a simple xlink with the provided * values. The new element is empty./*from ww w.j av a 2 s.c om*/ * * @param writer The {@code XMLStreamWriter} object to add the element to. * @param elementName The name of the new element. * @param xlinkTitle The title of the xlink contained in the new element. * @param xlinkHref The href of the xlink contained in the new element. * @param namespaceUri The namespace URI of the new element. * @throws XMLStreamException Thrown in case of an xml stream error. */ public static void addReferencingElement(final XMLStreamWriter writer, final String elementName, final String xlinkTitle, final String xlinkHref, final String namespaceUri) throws XMLStreamException { writer.writeStartElement(namespaceUri, elementName); addXlinkAttributes(writer, xlinkTitle, xlinkHref); writer.writeEndElement(); }
From source file:com.amalto.core.storage.services.SystemModels.java
@POST @Path("{model}") @ApiOperation("Get impacts of the model update with the new XSD provided as request content. Changes will not be performed !") public String analyzeModelChange(@ApiParam("Model name") @PathParam("model") String modelName, @ApiParam("Optional language to get localized result") @QueryParam("lang") String locale, InputStream dataModel) {//from w ww .j a v a 2 s . c o m Map<ImpactAnalyzer.Impact, List<Change>> impacts; List<String> typeNamesToDrop = new ArrayList<String>(); if (!isSystemStorageAvailable()) { impacts = new EnumMap<>(ImpactAnalyzer.Impact.class); for (ImpactAnalyzer.Impact impact : impacts.keySet()) { impacts.put(impact, Collections.<Change>emptyList()); } } else { StorageAdmin storageAdmin = ServerContext.INSTANCE.get().getStorageAdmin(); Storage storage = storageAdmin.get(modelName, StorageType.MASTER); if (storage == null) { LOGGER.warn( "Container '" + modelName + "' does not exist. Skip impact analyzing for model change."); //$NON-NLS-1$//$NON-NLS-2$ return StringUtils.EMPTY; } if (storage.getType() == StorageType.SYSTEM) { LOGGER.debug("No model update for system storage"); //$NON-NLS-1$ return StringUtils.EMPTY; } // Compare new data model with existing data model MetadataRepository previousRepository = storage.getMetadataRepository(); MetadataRepository newRepository = new MetadataRepository(); newRepository.load(dataModel); Compare.DiffResults diffResults = Compare.compare(previousRepository, newRepository); // Analyzes impacts on the select storage impacts = storage.getImpactAnalyzer().analyzeImpacts(diffResults); List<ComplexTypeMetadata> typesToDrop = storage.findSortedTypesToDrop(diffResults, true); Set<String> tableNamesToDrop = storage.findTablesToDrop(typesToDrop); for (String tableName : tableNamesToDrop) { if (previousRepository.getInstantiableTypes() .contains(previousRepository.getComplexType(tableName))) { typeNamesToDrop.add(tableName); } } } // Serialize results to XML StringWriter resultAsXml = new StringWriter(); XMLStreamWriter writer = null; try { writer = XMLOutputFactory.newFactory().createXMLStreamWriter(resultAsXml); writer.writeStartElement("result"); //$NON-NLS-1$ { for (Map.Entry<ImpactAnalyzer.Impact, List<Change>> category : impacts.entrySet()) { writer.writeStartElement(category.getKey().name().toLowerCase()); List<Change> changes = category.getValue(); for (Change change : changes) { writer.writeStartElement("change"); //$NON-NLS-1$ { writer.writeStartElement("message"); //$NON-NLS-1$ { Locale messageLocale; if (StringUtils.isEmpty(locale)) { messageLocale = Locale.getDefault(); } else { messageLocale = new Locale(locale); } writer.writeCharacters(change.getMessage(messageLocale)); } writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndElement(); } writer.writeStartElement("entitiesToDrop"); //$NON-NLS-1$ for (String typeName : typeNamesToDrop) { writer.writeStartElement("entity"); //$NON-NLS-1$ writer.writeCharacters(typeName); writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndElement(); } catch (XMLStreamException e) { throw new RuntimeException(e); } finally { if (writer != null) { try { writer.flush(); } catch (XMLStreamException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Could not flush XML content.", e); //$NON-NLS-1$ } } } } return resultAsXml.toString(); }
From source file:net.landora.video.info.file.FileInfoManager.java
private synchronized void writeCacheFile(File file, Map<String, FileInfo> infoMap) { OutputStream os = null;//from w w w. j a v a 2 s .co m try { os = new BufferedOutputStream(new FileOutputStream(file)); if (COMPRESS_INFO_FILE) { os = new GZIPOutputStream(os); } XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(os); writer.writeStartDocument(); writer.writeStartElement("files"); writer.writeCharacters("\n"); for (Map.Entry<String, FileInfo> entry : infoMap.entrySet()) { FileInfo info = entry.getValue(); writer.writeStartElement("file"); writer.writeAttribute("filename", entry.getKey()); writer.writeAttribute("ed2k", info.getE2dkHash()); writer.writeAttribute("length", String.valueOf(info.getFileSize())); writer.writeAttribute("lastmodified", String.valueOf(info.getLastModified())); if (info.getMetadataSource() != null) { writer.writeAttribute("metadatasource", info.getMetadataSource()); } if (info.getMetadataId() != null) { writer.writeAttribute("metadataid", info.getMetadataId()); } if (info.getVideoId() != null) { writer.writeAttribute("videoid", info.getVideoId()); } writer.writeEndElement(); writer.writeCharacters("\n"); } writer.writeEndElement(); writer.writeEndDocument(); writer.close(); } catch (Exception e) { log.error("Error writing file cache.", e); } finally { if (os != null) { IOUtils.closeQuietly(os); } } }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void writeAtomLink(XMLStreamWriter theEventWriter, String theRel, StringDt theStringDt) throws XMLStreamException { if (StringUtils.isNotBlank(theStringDt.getValue())) { theEventWriter.writeStartElement("link"); theEventWriter.writeAttribute("rel", theRel); theEventWriter.writeAttribute("href", theStringDt.getValue()); theEventWriter.writeEndElement(); }//from w w w .ja va 2 s .c o m }
From source file:de.qucosa.webapi.v1.DocumentResource.java
@RequestMapping(value = "/document", method = RequestMethod.GET) public ResponseEntity<String> listAll() throws IOException, FedoraClientException, XMLStreamException { List<String> pids = fedoraRepository.getPIDsByPattern("^qucosa:"); StringWriter sw = new StringWriter(); XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(sw); w.writeStartDocument("UTF-8", "1.0"); w.writeStartElement("Opus"); w.writeAttribute("version", "2.0"); w.writeStartElement("DocumentList"); w.writeNamespace("xlink", "http://www.w3.org/1999/xlink"); for (String pid : pids) { String nr = pid.substring(pid.lastIndexOf(':') + 1); String href = getHrefLink(nr); w.writeEmptyElement("Document"); w.writeAttribute("xlink:href", href); w.writeAttribute("xlink:nr", nr); w.writeAttribute("xlink:type", "simple"); }/*from ww w .ja va 2s. c om*/ w.writeEndElement(); w.writeEndElement(); w.writeEndDocument(); w.flush(); return new ResponseEntity<>(sw.toString(), HttpStatus.OK); }
From source file:com.fiorano.openesb.application.application.ApplicationReference.java
protected void toJXMLString(XMLStreamWriter writer, boolean writeManageableProperties) throws XMLStreamException, FioranoException { writer.writeStartElement(ELEM_APPLICATION); {/* w w w .j a v a2s . com*/ writer.writeAttribute(ATTR_GUID, guid); writer.writeAttribute(ATTR_VERSION, String.valueOf(version)); writer.writeStartElement(ELEM_DISPLAY); { writer.writeAttribute(ATTR_DISPLAY_NAME, displayName); writeAttribute(writer, ATTR_CATEGORIES, categories); } writer.writeEndElement(); writer.writeStartElement(ELEM_SERVER_VERSION); { writer.writeAttribute(ATTR_SERVER_VERSION, serverVersion); writer.writeAttribute(ATTR_SERVER_CATEGORY, serverCategory); writer.writeAttribute(ATTR_BUILD_NO, buildNo); writer.writeAttribute(ATTR_USER_NAME, userName); } writer.writeEndElement(); writer.writeStartElement(ELEM_CREATION); { writeAttribute(writer, ATTR_CREATION_DATE, creationDate); writeAttribute(writer, ATTR_AUTHORS, authors); writeAttribute(writer, ATTR_SCHEMA_VERSION, schemaVersion); } writer.writeEndElement(); if (typeName != null) { writer.writeStartElement(ELEM_TYPE); { writeAttribute(writer, ATTR_TYPE_NAME, getTypeName()); if (subType != null) writeAttribute(writer, ATTR_SUB_TYPE, getSubType()); } writer.writeEndElement(); } writeElement(writer, ELEM_SHORT_DESCRIPTION, shortDescription); writeElement(writer, ELEM_LONG_DESCRIPTION, longDescription); writer.writeStartElement(ELEM_DEPLOYMENT); { writer.writeAttribute(ATTR_LABEL, label); if (!componentCached) writer.writeAttribute(ATTR_COMPONENT_CACHED, String.valueOf(componentCached)); } writer.writeEndElement(); writer.writeStartElement(ELEM_DL_DST); { writer.writeAttribute(String.valueOf(ATTR_DL_DST), String.valueOf(deleteDestination)); } writer.writeEndElement(); //write App RouteDurability writer.writeStartElement(ELEM_DURABLE_ROUTE); { writer.writeAttribute(ATTR_DURABLE_ROUTE_VALUE, String.valueOf(appRouteDurability)); } writer.writeEndElement(); if (componentLaunchOrderEnabled) { writer.writeStartElement(ELEM_COMPONENT_LAUNCH_ORDER); { writer.writeAttribute(ATTR_COMPONENT_LAUNCH_ORDER_ENABLED, String.valueOf(componentLaunchOrderEnabled)); } writer.writeEndElement(); } if (componentStopOrderEnabled) { writer.writeStartElement(ELEM_COMPONENT_STOP_ORDER); { writer.writeAttribute(ATTR_COMPONENT_STOP_ORDER_ENABLED, String.valueOf(componentStopOrderEnabled)); writer.writeAttribute(ATTR_USE_REVERSE_ORDER_OF_COMPONENT_LAUNCH_ORDER, String.valueOf(reverseComponentLaunchOrder)); } writer.writeEndElement(); } if (exposedWebInterfaces != WEB_INTERFACES_NONE) { writer.writeStartElement(ELEM_WEB); { writeAttribute(writer, ATTR_EXPOSED_INTERFACES, exposedWebInterfaces); } writer.writeEndElement(); } toJXMLString_1(writer, writeManageableProperties); } writer.writeEndElement(); }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void writeAuthor(XMLStreamWriter theEventWriter, BaseBundle theBundle) throws XMLStreamException { if (StringUtils.isNotBlank(theBundle.getAuthorName().getValue())) { theEventWriter.writeStartElement("author"); writeTagWithTextNode(theEventWriter, "name", theBundle.getAuthorName()); writeOptionalTagWithTextNode(theEventWriter, "uri", theBundle.getAuthorUri()); theEventWriter.writeEndElement(); }/*w ww . j a v a 2s . c o m*/ }
From source file:org.gaul.s3proxy.S3ProxyHandler.java
private static void writeSimpleElement(XMLStreamWriter xml, String elementName, String characters) throws XMLStreamException { xml.writeStartElement(elementName);//www.j a va 2s . co m xml.writeCharacters(characters); xml.writeEndElement(); }