Esempio n. 1
1
  private XMLStreamWriter getXmlStreamWriter(String fileName) {
    try {
      // to avoid filename with forbidden symbols
      fileName = Util.deleteForbiddenSymbols(fileName);

      // if for some XMLStreamWriter was run writeStartDocument,
      // run writeEndDocument and close it
      if (last != null) {
        last.writeEndDocument();
        last.close();
      }

      // if..., create XMLStreamWriter to out
      if (fileName == null) {
        last = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out);
        // else, create XMLStreamWriter to file
      } else {
        last = XMLOutputFactory.newInstance().createXMLStreamWriter(new FileOutputStream(fileName));
      }

      last.writeStartDocument();
    } catch (XMLStreamException | FileNotFoundException e) {
      Util.handleException(e);
    }
    return last;
  }
Esempio n. 2
0
  /**
   * Конвертирует XMLDOM древо в текстовое представление
   *
   * @param xmlDocument XMLDOM древо
   * @return Текстовое представление XMLDOM древа
   * @throws javax.xml.stream.XMLStreamException Если не смогло
   * @throws javax.xml.transform.TransformerConfigurationException Если не смогло
   * @throws javax.xml.transform.TransformerException Если не смогло
   * @throws java.io.IOException Если не смогло
   */
  public static String toStringWithException(Node xmlDocument)
      throws XMLStreamException, TransformerConfigurationException, TransformerException,
          IOException {
    if (xmlDocument == null) {
      throw new IllegalArgumentException("xmlDocument == null");
    }

    Transformer tr = TransformerFactory.newInstance().newTransformer();

    DOMSource domSrc = new DOMSource(xmlDocument);

    StringWriter sWiter = new StringWriter();
    XMLStreamWriter xml2format = new FormatXMLWriter(sWiter);

    StAXResult sResult = new StAXResult(xml2format);
    Result result = sResult;

    tr.transform(domSrc, result);

    //        sWiter.flush();
    xml2format.writeEndDocument();
    xml2format.flush();

    String toOutput = sWiter.toString();

    xml2format.close();
    sWiter.close();

    return toOutput;
  }
  @Override
  public EndElement endElement(final EndElement element) throws XMLStreamException {
    final String theName = element.getLocalName();

    if ("component".equals(theName)) {
      if (this.componentId == null) {
        final Map components = (Map) outputStreams.get("components");
        components.remove(this.componentId);
      }
      this.inComponent = false;
      this.componentId = null;
    }
    if (this.inside) {
      this.insideLevel--;
      if (this.insideLevel > 0 || this.insideLevel == 0 && !"md-record".equals(theName)) {
        writer.writeEndElement();
      }

      if (this.insideLevel == 0) {
        this.inside = false;
        writer.flush();
        writer.close();
      }
    }

    return element;
  }
  public void append(
      final XMLStreamWriter writer,
      final EntityInfoAggregator eia,
      final Map<String, Object> data,
      final boolean isRootElement,
      final boolean isFeedPart)
      throws EntityProviderException {
    try {
      writer.writeStartElement(FormatXml.ATOM_ENTRY);

      if (isRootElement) {
        writer.writeDefaultNamespace(Edm.NAMESPACE_ATOM_2005);
        writer.writeNamespace(Edm.PREFIX_M, Edm.NAMESPACE_M_2007_08);
        writer.writeNamespace(Edm.PREFIX_D, Edm.NAMESPACE_D_2007_08);
      }
      if (!isFeedPart) {
        writer.writeAttribute(
            Edm.PREFIX_XML,
            Edm.NAMESPACE_XML_1998,
            "base",
            properties.getServiceRoot().toASCIIString());
      }

      etag = createETag(eia, data);
      if (etag != null) {
        writer.writeAttribute(Edm.NAMESPACE_M_2007_08, FormatXml.M_ETAG, etag);
      }

      // write all atom infos (mandatory and optional)
      appendAtomMandatoryParts(writer, eia, data);
      appendAtomOptionalParts(writer, eia, data);

      if (eia.getEntityType().hasStream()) {
        // write all links
        appendAtomEditLink(writer, eia, data);
        appendAtomContentLink(writer, eia, data, properties.getMediaResourceMimeType());
        appendAtomNavigationLinks(writer, eia, data);
        // write properties/content
        appendCustomProperties(writer, eia, data);
        appendAtomContentPart(writer, eia, data, properties.getMediaResourceMimeType());
        appendProperties(writer, eia, data);
      } else {
        // write all links
        appendAtomEditLink(writer, eia, data);
        appendAtomNavigationLinks(writer, eia, data);
        // write properties/content
        appendCustomProperties(writer, eia, data);
        writer.writeStartElement(FormatXml.ATOM_CONTENT);
        writer.writeAttribute(FormatXml.ATOM_TYPE, ContentType.APPLICATION_XML.toString());
        appendProperties(writer, eia, data);
        writer.writeEndElement();
      }

      writer.writeEndElement();

      writer.flush();
    } catch (Exception e) {
      throw new EntityProviderException(EntityProviderException.COMMON, e);
    }
  }
  private void writeAttribute(
      final String uri,
      final String elementName,
      final String attributeName,
      final String attributeValue,
      String prefix)
      throws XMLStreamException {

    if (uri != null) {
      if (nsuris.containsKey(uri)) {
        final List namespaceTrace = nsuris.get(uri);
        final String prefixTrace = (String) namespaceTrace.get(2);
        if (!prefixTrace.equals(prefix)) {
          prefix = prefixTrace;
        }
      } else {
        final List namespaceTrace = new ArrayList();
        namespaceTrace.add(this.deepLevel);
        namespaceTrace.add(elementName);
        namespaceTrace.add(prefix);
        nsuris.put(uri, namespaceTrace);

        writer.writeNamespace(prefix, uri);
      }
    }

    writer.writeAttribute(prefix, uri, attributeName, attributeValue);
  }
Esempio n. 6
0
  @Override
  public void encodeTagListToWriter(TagList theTagList, Writer theWriter) throws IOException {
    try {
      XMLStreamWriter eventWriter = createXmlWriter(theWriter);

      eventWriter.writeStartElement(TagList.ELEMENT_NAME_LC);
      eventWriter.writeDefaultNamespace(FHIR_NS);

      for (Tag next : theTagList) {
        eventWriter.writeStartElement(TagList.ATTR_CATEGORY);

        if (isNotBlank(next.getTerm())) {
          eventWriter.writeAttribute(Tag.ATTR_TERM, next.getTerm());
        }
        if (isNotBlank(next.getLabel())) {
          eventWriter.writeAttribute(Tag.ATTR_LABEL, next.getLabel());
        }
        if (isNotBlank(next.getScheme())) {
          eventWriter.writeAttribute(Tag.ATTR_SCHEME, next.getScheme());
        }

        eventWriter.writeEndElement();
      }

      eventWriter.writeEndElement();
      eventWriter.close();
    } catch (XMLStreamException e) {
      throw new ConfigurationException("Failed to initialize STaX event factory", e);
    }
  }
  private void doFromSoapMessage(Message message, Object sm) {
    SOAPMessage m = (SOAPMessage) sm;
    MessageContentsList list = (MessageContentsList) message.getContent(List.class);
    if (list == null) {
      list = new MessageContentsList();
      message.setContent(List.class, list);
    }
    Object o = m;

    if (StreamSource.class.isAssignableFrom(type)) {
      try {
        try (CachedOutputStream out = new CachedOutputStream()) {
          XMLStreamWriter xsw = StaxUtils.createXMLStreamWriter(out);
          StaxUtils.copy(new DOMSource(m.getSOAPPart()), xsw);
          xsw.close();
          o = new StreamSource(out.getInputStream());
        }
      } catch (Exception e) {
        throw new Fault(e);
      }
    } else if (SAXSource.class.isAssignableFrom(type)) {
      o = new StaxSource(new W3CDOMStreamReader(m.getSOAPPart()));
    } else if (Source.class.isAssignableFrom(type)) {
      o = new DOMSource(m.getSOAPPart());
    }
    list.set(0, o);
  }
  /**
   * Convert the contents of a ProfileManager to XML and write the XML to the given writer.
   *
   * @param profileManager the ProfileManager
   * @param writer the XMLStreamWriter to write to
   */
  public static void marshal(ProfileManager profileManager, XMLStreamWriter writer) {
    try {
      writer.writeStartElement("userprofiles");
      String profileVersion = getProfileVersion(profileManager.getProfileObjectStoreWriter());
      writer.writeAttribute(MetadataManager.PROFILE_FORMAT_VERSION, profileVersion);
      List<?> usernames = profileManager.getProfileUserNames();

      for (Object userName : usernames) {
        Profile profile = profileManager.getProfile((String) userName);
        LOG.info("Writing profile: " + profile.getUsername());
        long startTime = System.currentTimeMillis();

        ProfileBinding.marshal(
            profile,
            profileManager.getProductionObjectStore(),
            writer,
            profileManager.getVersion(),
            getClassKeys(profileManager.getProductionObjectStore()));

        long totalTime = System.currentTimeMillis() - startTime;
        LOG.info(
            "Finished writing profile: " + profile.getUsername() + " took " + totalTime + "ms.");
      }

      TrackManagerBinding.marshal(profileManager.getProfileObjectStoreWriter(), writer);
      writer.writeEndElement();
    } catch (XMLStreamException e) {
      throw new RuntimeException(e);
    }
  }
Esempio n. 9
0
 public void marshall(XMLStreamWriter wrt, UserDetails value) throws Exception {
   // write out the userdetails element..
   wrt.writeStartElement("userdetails");
   if (value != null) {
     // marshall the token using the XMLTokenMarshaller..
     Token token = value.getToken();
     XMLTokenMarshaller mar = new XMLTokenMarshaller();
     mar.marshall(wrt, token);
     // write each of the roles..
     String[] values = value.getRoles();
     for (int i = 0; (values != null && i < values.length); i++) {
       String role = values[i];
       wrt.writeStartElement("role");
       wrt.writeAttribute("id", role);
       wrt.writeEndElement();
     }
     // write each of the attributes
     XMLAttributeMarshaller attrMarshaller = new XMLAttributeMarshaller();
     Attribute[] vals = value.getAttributes();
     for (int i = 0; (vals != null && i < vals.length); i++) {
       Attribute attr = vals[i];
       attrMarshaller.marshall(wrt, attr);
     }
   }
   // end the userdetails..
   wrt.writeEndElement();
 }
  private void appendKey(final XMLStreamWriter writer, final EdmEntityType entityType)
      throws XMLStreamException {
    List<EdmKeyPropertyRef> keyPropertyRefs = entityType.getKeyPropertyRefs();
    if (keyPropertyRefs != null && !keyPropertyRefs.isEmpty()) {
      // Resolve Base Type key as it is shown in derived type
      EdmEntityType baseType = entityType.getBaseType();
      if (baseType != null
          && baseType.getKeyPropertyRefs() != null
          && !(baseType.getKeyPropertyRefs().isEmpty())) {
        return;
      }

      writer.writeStartElement(XML_KEY);
      for (EdmKeyPropertyRef keyRef : keyPropertyRefs) {
        writer.writeEmptyElement(XML_PROPERTY_REF);

        writer.writeAttribute(XML_NAME, keyRef.getName());

        if (keyRef.getAlias() != null) {
          writer.writeAttribute(XML_ALIAS, keyRef.getAlias());
        }
      }
      writer.writeEndElement();
    }
  }
Esempio n. 11
0
 private byte[] getMessageBytes(Document doc) throws Exception {
   ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
   XMLStreamWriter byteArrayWriter = StaxUtils.createXMLStreamWriter(outputStream);
   StaxUtils.writeDocument(doc, byteArrayWriter, false);
   byteArrayWriter.flush();
   return outputStream.toByteArray();
 }
  private void appendSchema(final XMLStreamWriter writer, final EdmSchema schema)
      throws XMLStreamException {
    writer.writeStartElement(NS_EDM, SCHEMA);
    writer.writeDefaultNamespace(NS_EDM);
    writer.writeAttribute(XML_NAMESPACE, schema.getNamespace());
    if (schema.getAlias() != null) {
      writer.writeAttribute(XML_ALIAS, schema.getAlias());
      namespaceToAlias.put(schema.getNamespace(), schema.getAlias());
    }

    // EnumTypes
    appendEnumTypes(writer, schema.getEnumTypes());

    // TypeDefinitions
    appendTypeDefinitions(writer, schema.getTypeDefinitions());

    // EntityTypes
    appendEntityTypes(writer, schema.getEntityTypes());

    // ComplexTypes
    appendComplexTypes(writer, schema.getComplexTypes());

    // Actions
    appendActions(writer, schema.getActions());

    // Functions
    appendFunctions(writer, schema.getFunctions());

    // EntityContainer
    appendEntityContainer(writer, schema.getEntityContainer());

    writer.writeEndElement();
  }
Esempio n. 13
0
  /** Writes an Atom author tag. */
  public void writeAuthor(String author) throws XMLStreamException {
    XMLStreamWriter xsw = getWriter();

    xsw.writeStartElement(XMLConstants.PREFIX_ATOM, "author", XMLConstants.NAMESPACE_ATOM);
    XMLUtils.write(xsw, XMLConstants.PREFIX_ATOM, XMLConstants.NAMESPACE_ATOM, "name", author);
    xsw.writeEndElement();
  }
 @Override
 public void xmlMe(XMLStreamWriter writer) throws XMLStreamException {
   writer.writeAttribute("type", "mouseSample");
   writer.writeAttribute("time", getWhen() + "");
   writer.writeAttribute("mouseX", getMouseX() + "");
   writer.writeAttribute("mouseY", getMouseY() + "");
 }
Esempio n. 15
0
  /**
   * makes a {@link Document} out of a {@link XMLStreamReader}
   *
   * @param xmlStreamReader the xmlStreamRader to convert
   * @return the xmlStreamRader as {@link Document}
   * @throws FactoryConfigurationError
   * @throws XMLStreamException
   * @throws ParserConfigurationException
   * @throws IOException
   * @throws SAXException
   */
  public static Document getAsDocument(XMLStreamReader xmlStreamReader)
      throws XMLStreamException, FactoryConfigurationError, ParserConfigurationException,
          SAXException, IOException {
    StreamBufferStore store = new StreamBufferStore();
    XMLStreamWriter xmlWriter = null;
    try {
      xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(store);
      xmlWriter.writeStartDocument();
      XMLAdapter.writeElement(xmlWriter, xmlStreamReader);
    } finally {
      if (xmlWriter != null) {
        try {
          xmlWriter.close();
        } catch (XMLStreamException e) {
          LOG.error("Unable to close xmlwriter.");
        }
      }
    }

    store.flush();
    DOMParser parser = new DOMParser();
    parser.parse(new InputSource(store.getInputStream()));
    Document doc = parser.getDocument();
    store.close();
    return doc;
  }
Esempio n. 16
0
 public void marshall(XMLStreamWriter wrt, Boolean value) throws Exception {
   String token = value.toString();
   assert ((token != null) && (token.length() != 0));
   wrt.writeStartElement("result");
   wrt.writeAttribute("boolean", token);
   wrt.writeEndElement();
 }
  protected void writeFormProperties(FlowElement flowElement, XMLStreamWriter xtw)
      throws Exception {

    List<FormProperty> propertyList = null;
    if (flowElement instanceof UserTask) {
      propertyList = ((UserTask) flowElement).getFormProperties();
    } else if (flowElement instanceof StartEvent) {
      propertyList = ((StartEvent) flowElement).getFormProperties();
    }

    if (propertyList != null) {

      for (FormProperty property : propertyList) {

        if (StringUtils.isNotEmpty(property.getId())) {

          if (didWriteExtensionStartElement == false) {
            xtw.writeStartElement(ELEMENT_EXTENSIONS);
            didWriteExtensionStartElement = true;
          }

          xtw.writeStartElement(
              ACTIVITI_EXTENSIONS_PREFIX, ELEMENT_FORMPROPERTY, ACTIVITI_EXTENSIONS_NAMESPACE);
          writeDefaultAttribute(ATTRIBUTE_FORM_ID, property.getId(), xtw);

          writeDefaultAttribute(ATTRIBUTE_FORM_NAME, property.getName(), xtw);
          writeDefaultAttribute(ATTRIBUTE_FORM_TYPE, property.getType(), xtw);
          writeDefaultAttribute(ATTRIBUTE_FORM_EXPRESSION, property.getExpression(), xtw);
          writeDefaultAttribute(ATTRIBUTE_FORM_VARIABLE, property.getVariable(), xtw);

          xtw.writeEndElement();
        }
      }
    }
  }
  @Override
  public SerializerResult metadataDocument(final ServiceMetadata serviceMetadata)
      throws SerializerException {
    CircleStreamBuffer buffer;
    XMLStreamWriter xmlStreamWriter = null;

    try {
      buffer = new CircleStreamBuffer();
      xmlStreamWriter =
          XMLOutputFactory.newInstance()
              .createXMLStreamWriter(buffer.getOutputStream(), DEFAULT_CHARSET);
      MetadataDocumentXmlSerializer serializer = new MetadataDocumentXmlSerializer(serviceMetadata);
      serializer.writeMetadataDocument(xmlStreamWriter);
      xmlStreamWriter.flush();
      xmlStreamWriter.close();

      return SerializerResultImpl.with().content(buffer.getInputStream()).build();
    } catch (final XMLStreamException e) {
      log.error(e.getMessage(), e);
      throw new SerializerException(
          "An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
    } finally {
      if (xmlStreamWriter != null) {
        try {
          xmlStreamWriter.close();
        } catch (XMLStreamException e) {
          throw new SerializerException(
              "An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
        }
      }
    }
  }
  /** Util method to write an attribute without the ns prefix */
  private void writeQNameAttribute(
      java.lang.String namespace,
      java.lang.String attName,
      javax.xml.namespace.QName qname,
      javax.xml.stream.XMLStreamWriter xmlWriter)
      throws javax.xml.stream.XMLStreamException {

    java.lang.String attributeNamespace = qname.getNamespaceURI();
    java.lang.String attributePrefix = xmlWriter.getPrefix(attributeNamespace);
    if (attributePrefix == null) {
      attributePrefix = registerPrefix(xmlWriter, attributeNamespace);
    }
    java.lang.String attributeValue;
    if (attributePrefix.trim().length() > 0) {
      attributeValue = attributePrefix + ":" + qname.getLocalPart();
    } else {
      attributeValue = qname.getLocalPart();
    }

    if (namespace.equals("")) {
      xmlWriter.writeAttribute(attName, attributeValue);
    } else {
      registerPrefix(xmlWriter, namespace);
      xmlWriter.writeAttribute(namespace, attName, attributeValue);
    }
  }
  private void increaseSearchIndexStartTimeDelay() throws Exception {
    FileOutputStream fileOutputStream = null;
    XMLStreamWriter writer = null;
    OMElement documentElement = getRegistryXmlOmElement();
    try {
      AXIOMXPath xpathExpression =
          new AXIOMXPath("/wso2registry/indexingConfiguration/startingDelayInSeconds");
      OMElement indexConfigNode = (OMElement) xpathExpression.selectSingleNode(documentElement);
      indexConfigNode.setText("2");

      AXIOMXPath xpathExpression1 =
          new AXIOMXPath("/wso2registry/indexingConfiguration/indexingFrequencyInSeconds");
      OMElement indexConfigNode1 = (OMElement) xpathExpression1.selectSingleNode(documentElement);
      indexConfigNode1.setText("1");

      fileOutputStream = new FileOutputStream(getRegistryXMLPath());
      writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream);
      documentElement.serialize(writer);
      documentElement.build();
      Thread.sleep(2000);

    } catch (Exception e) {
      log.error("registry.xml edit fails" + e.getMessage());
      throw new Exception("registry.xml edit fails" + e.getMessage());
    } finally {
      assert fileOutputStream != null;
      fileOutputStream.close();
      assert writer != null;
      writer.flush();
    }
  }
Esempio n. 21
0
 @Override
 public void endElement(final String uri, final String localName, final String name)
     throws SAXException {
   if (start) {
     level--;
     try {
       pushcontentWriter.writeEndElement();
     } catch (XMLStreamException e) {
       throw new SAXException(e);
     }
   }
   if (level == 0) {
     // turn off start if we reach the end tag of staring element
     start = false;
     if (ATTR_CONACTION_VALUE_PUSHAFTER.equals(pushType)
         || ATTR_CONACTION_VALUE_PUSHREPLACE.equals(pushType)) {
       // if it is pushafter or replace, we need to record content in pushtable
       // if target == null we have already reported error in startElement;
       if (target != null) {
         if (pushcontentWriter != null) {
           try {
             pushcontentWriter.close();
           } catch (final XMLStreamException e) {
             throw new SAXException(e);
           }
         }
         addtoPushTable(target, pushcontentDocumentFragment, pushType);
         pushcontentWriter = getXMLStreamWriter();
         target = null;
         pushType = null;
       }
     }
   }
 }
  /**
   * Serialize the given event data as a standalone XML document
   *
   * @param includeProlog if true, include an XML prolog; if not, just render a document fragment
   * @return the XML serialization, or null if <code>data</code> is null.
   */
  public String serialize(EventDataElement data, boolean includeProlog) {
    if (data == null || data.isNull()) return null;

    try {
      // serialize the DOM to our string buffer.
      XMLStreamWriter writer = factory.createXMLStreamWriter(buffer);
      try {
        if (includeProlog) writer.writeStartDocument();
        serializeElement(writer, data);
        writer.writeEndDocument();
        writer.flush();
      } finally {
        writer.close();
      }

      // return buffer contents.
      return buffer.toString();

    } catch (XMLStreamException ioe) {
      // this shouldn't happen, since the target output stream is a StringWriter, but
      // the compiler demands that we handle it.
      throw new RuntimeException("Error serializing XML data", ioe);
    } finally {

      // reset the internal buffer for next run.
      buffer.getBuffer().setLength(0);
    }
  }
  /** Register a namespace prefix */
  private java.lang.String registerPrefix(
      javax.xml.stream.XMLStreamWriter xmlWriter, java.lang.String namespace)
      throws javax.xml.stream.XMLStreamException {
    java.lang.String prefix = xmlWriter.getPrefix(namespace);

    if (prefix == null) {
      prefix = generatePrefix(namespace);

      javax.xml.namespace.NamespaceContext nsContext = xmlWriter.getNamespaceContext();

      while (true) {
        java.lang.String uri = nsContext.getNamespaceURI(prefix);

        if ((uri == null) || (uri.length() == 0)) {
          break;
        }

        prefix = org.apache.axis2.databinding.utils.BeanUtil.getUniquePrefix();
      }

      xmlWriter.writeNamespace(prefix, namespace);
      xmlWriter.setPrefix(prefix, namespace);
    }

    return prefix;
  }
  @Override
  public ISORecord inspect(ISORecord record, Connection conn, SQLDialect dialect)
      throws MetadataInspectorException {

    ISORecord result = record;

    try {
      // create temporary sink for normalized XML
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(bos);
      writer = new NamespaceNormalizingXMLStreamWriter(writer, nsBindings);

      // create normalized copy
      XMLStreamReader reader = record.getAsXMLStream();
      XMLAdapter.writeElement(writer, reader);
      reader.close();
      writer.close();

      InputStream is = new ByteArrayInputStream(bos.toByteArray());
      XMLStreamReader xmlStream = XMLInputFactory.newInstance().createXMLStreamReader(is);
      result = new ISORecord(xmlStream);
    } catch (Throwable t) {
      LOG.error(
          "Namespace normalization failed. Proceeding with unnormalized record. Error: "
              + t.getMessage());
    }

    return result;
  }
 private static void writeNormalizedRpc(
     final ContainerNode normalized,
     final DOMResult result,
     final SchemaPath schemaPath,
     final SchemaContext baseNetconfCtx)
     throws IOException, XMLStreamException {
   final XMLStreamWriter writer =
       NetconfMessageTransformUtil.XML_FACTORY.createXMLStreamWriter(result);
   try {
     try (final NormalizedNodeStreamWriter normalizedNodeStreamWriter =
         XMLStreamNormalizedNodeStreamWriter.create(writer, baseNetconfCtx, schemaPath)) {
       try (final OrderedNormalizedNodeWriter normalizedNodeWriter =
           new OrderedNormalizedNodeWriter(
               normalizedNodeStreamWriter, baseNetconfCtx, schemaPath)) {
         Collection<DataContainerChild<?, ?>> value = normalized.getValue();
         normalizedNodeWriter.write(value);
         normalizedNodeWriter.flush();
       }
     }
   } finally {
     try {
       writer.close();
     } catch (final Exception e) {
       LOG.warn("Unable to close resource properly", e);
     }
   }
 }
 @Override
 public void xmlMe(XMLStreamWriter writer) throws XMLStreamException {
   writer.writeAttribute("type", "insertString");
   writer.writeAttribute("time", getWhen() + "");
   writer.writeAttribute("offset", getOffset() + "");
   writer.writeAttribute("str", getStr());
 }
Esempio n. 27
0
  @Override
  public void write(NominatimEntry entry) {
    try {
      writer.writeStartElement("doc");
      write("id", entry.getPlaceId());

      Coordinate centroid = entry.getCoordinate();
      write("coordinate", String.format(Locale.ENGLISH, "%f,%f", centroid.y, centroid.x));

      write("osm_id", entry.getOsmId());
      write("osm_type", entry.getOsmType() == null ? "" : entry.getOsmType().name());

      write("name", entry.getName());

      write("osm_key", entry.getOsmKey());
      write("osm_value", entry.getOsmValue());

      // Address
      write("street", entry.getStreet());
      write("housenumber", entry.getHousenumber());
      write("postcode", entry.getPostcode());

      write("country", InternationalCountryName.get(entry.getCountry()));
      write("city", entry.getCity());

      write("places", entry.getPlaces());

      write("ranking", 30 - entry.getRankSearch());
      write("importance", entry.getImportance());

      writer.writeEndElement();
    } catch (XMLStreamException | IOException e) {
      throw new RuntimeException(e);
    }
  }
Esempio n. 28
0
  protected void writeMessageDefinition(
      Event parentEvent,
      MessageEventDefinition messageDefinition,
      BpmnModel model,
      XMLStreamWriter xtw)
      throws Exception {
    xtw.writeStartElement(ELEMENT_EVENT_MESSAGEDEFINITION);

    String messageRef = messageDefinition.getMessageRef();
    if (StringUtils.isNotEmpty(messageRef)) {
      // remove the namespace from the message id if set
      if (messageRef.startsWith(model.getTargetNamespace())) {
        messageRef = messageRef.replace(model.getTargetNamespace(), "");
        messageRef = messageRef.replaceFirst(":", "");
      } else {
        for (String prefix : model.getNamespaces().keySet()) {
          String namespace = model.getNamespace(prefix);
          if (messageRef.startsWith(namespace)) {
            messageRef = messageRef.replace(model.getTargetNamespace(), "");
            messageRef = prefix + messageRef;
          }
        }
      }
    }
    writeDefaultAttribute(ATTRIBUTE_MESSAGE_REF, messageRef, xtw);
    boolean didWriteExtensionStartElement =
        BpmnXMLUtil.writeExtensionElements(messageDefinition, false, xtw);
    if (didWriteExtensionStartElement) {
      xtw.writeEndElement();
    }
    xtw.writeEndElement();
  }
Esempio n. 29
0
  public void serialize(
      final javax.xml.namespace.QName parentQName,
      javax.xml.stream.XMLStreamWriter xmlWriter,
      boolean serializeType)
      throws javax.xml.stream.XMLStreamException, org.apache.axis2.databinding.ADBException {

    java.lang.String prefix = null;
    java.lang.String namespace = null;

    prefix = parentQName.getPrefix();
    namespace = parentQName.getNamespaceURI();
    writeStartElement(prefix, namespace, parentQName.getLocalPart(), xmlWriter);

    if (serializeType) {

      java.lang.String namespacePrefix = registerPrefix(xmlWriter, "http://BCXLiqODPCmx.bcx.cl/");
      if ((namespacePrefix != null) && (namespacePrefix.trim().length() > 0)) {
        writeAttribute(
            "xsi",
            "http://www.w3.org/2001/XMLSchema-instance",
            "type",
            namespacePrefix + ":odpWS200151SOLLIQResult",
            xmlWriter);
      } else {
        writeAttribute(
            "xsi",
            "http://www.w3.org/2001/XMLSchema-instance",
            "type",
            "odpWS200151SOLLIQResult",
            xmlWriter);
      }
    }
    if (localItemoutTracker) {
      if (localItemout == null) {
        throw new org.apache.axis2.databinding.ADBException("itemout cannot be null!!");
      }
      localItemout.serialize(new javax.xml.namespace.QName("", "itemout"), xmlWriter);
    }
    namespace = "";
    writeStartElement(null, namespace, "returnValue", xmlWriter);

    if (localReturnValue == java.lang.Integer.MIN_VALUE) {

      throw new org.apache.axis2.databinding.ADBException("returnValue cannot be null!!");

    } else {
      xmlWriter.writeCharacters(
          org.apache.axis2.databinding.utils.ConverterUtil.convertToString(localReturnValue));
    }

    xmlWriter.writeEndElement();
    if (localRowsTracker) {
      if (localRows == null) {
        throw new org.apache.axis2.databinding.ADBException("rows cannot be null!!");
      }
      localRows.serialize(new javax.xml.namespace.QName("", "rows"), xmlWriter);
    }
    xmlWriter.writeEndElement();
  }
  public void serialize(
      final javax.xml.namespace.QName parentQName,
      javax.xml.stream.XMLStreamWriter xmlWriter,
      boolean serializeType)
      throws javax.xml.stream.XMLStreamException, org.apache.axis2.databinding.ADBException {

    java.lang.String prefix = null;
    java.lang.String namespace = null;

    prefix = parentQName.getPrefix();
    namespace = parentQName.getNamespaceURI();
    writeStartElement(prefix, namespace, parentQName.getLocalPart(), xmlWriter);

    if (serializeType) {

      java.lang.String namespacePrefix = registerPrefix(xmlWriter, "urn:partner.soap.sforce.com");
      if ((namespacePrefix != null) && (namespacePrefix.trim().length() > 0)) {
        writeAttribute(
            "xsi",
            "http://www.w3.org/2001/XMLSchema-instance",
            "type",
            namespacePrefix + ":describeSearchLayoutsResponse",
            xmlWriter);
      } else {
        writeAttribute(
            "xsi",
            "http://www.w3.org/2001/XMLSchema-instance",
            "type",
            "describeSearchLayoutsResponse",
            xmlWriter);
      }
    }
    if (localResultTracker) {
      if (localResult != null) {
        for (int i = 0; i < localResult.length; i++) {
          if (localResult[i] != null) {
            localResult[i].serialize(
                new javax.xml.namespace.QName("urn:partner.soap.sforce.com", "result"), xmlWriter);
          } else {

            writeStartElement(null, "urn:partner.soap.sforce.com", "result", xmlWriter);

            // write the nil attribute
            writeAttribute(
                "xsi", "http://www.w3.org/2001/XMLSchema-instance", "nil", "1", xmlWriter);
            xmlWriter.writeEndElement();
          }
        }
      } else {

        writeStartElement(null, "urn:partner.soap.sforce.com", "result", xmlWriter);

        // write the nil attribute
        writeAttribute("xsi", "http://www.w3.org/2001/XMLSchema-instance", "nil", "1", xmlWriter);
        xmlWriter.writeEndElement();
      }
    }
    xmlWriter.writeEndElement();
  }