Java Code Examples for javax.xml.stream.XMLStreamWriter#writeCharacters()

The following examples show how to use javax.xml.stream.XMLStreamWriter#writeCharacters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Base64Data.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void writeTo(XMLStreamWriter output) throws IOException, XMLStreamException {
    if (data==null) {
        try {
            InputStream is = dataHandler.getDataSource().getInputStream();
            ByteArrayOutputStream outStream = new ByteArrayOutputStream(); // dev-null stream
            Base64EncoderStream encWriter = new Base64EncoderStream(output, outStream);
            int b;
            byte[] buffer = new byte[CHUNK_SIZE];
            while ((b = is.read(buffer)) != -1) {
                encWriter.write(buffer, 0, b);
            }
            outStream.close();
            encWriter.close();
        } catch (IOException e) {
            dataLen = 0;    // recover by assuming length-0 data
            throw e;
        }
    } else {
        // the data is already in memory and not streamed
        String s = Base64Encoder.print(data, 0, dataLen);
        output.writeCharacters(s);
    }
}
 
Example 2
Source File: HtmlExtensionDocWriter.java    From nifi-registry with Apache License 2.0 6 votes vote down vote up
private void writeProvidedServiceApis(final Extension extension, final XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    final List<ProvidedServiceAPI> serviceAPIS = extension.getProvidedServiceAPIs();
    if (serviceAPIS != null && serviceAPIS.size() > 0) {
        writeSimpleElement(xmlStreamWriter, "h3", "Provided Service APIs:");

        xmlStreamWriter.writeStartElement("ul");

        for (final ProvidedServiceAPI serviceAPI : serviceAPIS) {
            final String name = getSimpleName(serviceAPI.getClassName());
            final String bundleInfo = " (" + serviceAPI.getGroupId() + "-" + serviceAPI.getArtifactId() + "-" + serviceAPI.getVersion() + ")";

            xmlStreamWriter.writeStartElement("li");
            xmlStreamWriter.writeCharacters(name);
            xmlStreamWriter.writeStartElement("i");
            xmlStreamWriter.writeCharacters(bundleInfo);
            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeEndElement();
        }

        xmlStreamWriter.writeEndElement();
    }
}
 
Example 3
Source File: Base64Data.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void writeTo(XMLStreamWriter output) throws IOException, XMLStreamException {
    if (data==null) {
        try {
            InputStream is = dataHandler.getDataSource().getInputStream();
            ByteArrayOutputStream outStream = new ByteArrayOutputStream(); // dev-null stream
            Base64EncoderStream encWriter = new Base64EncoderStream(output, outStream);
            int b;
            byte[] buffer = new byte[CHUNK_SIZE];
            while ((b = is.read(buffer)) != -1) {
                encWriter.write(buffer, 0, b);
            }
            outStream.close();
            encWriter.close();
        } catch (IOException e) {
            dataLen = 0;    // recover by assuming length-0 data
            throw e;
        }
    } else {
        // the data is already in memory and not streamed
        String s = Base64Encoder.print(data, 0, dataLen);
        output.writeCharacters(s);
    }
}
 
Example 4
Source File: XMLPersistence.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private static void writeFont(XMLStreamWriter writer, final String tag_name, final Font font) throws Exception
{
    writer.writeStartElement(tag_name);
    final StringBuilder buf = new StringBuilder();
    buf.append(font.getFamily())
       .append('|')
       .append((int)font.getSize())
       .append('|');
    // Cannot get the style out of the font as FontWeight, FontPosture??
    final String style = font.getStyle().toLowerCase();
    int code = 0;
    if (style.contains("bold"))
        code |= 1;
    if (style.contains("italic"))
        code |= 2;
    buf.append(code);
    writer.writeCharacters(buf.toString());
    writer.writeEndElement();
}
 
Example 5
Source File: RelatesToHeader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
    w.writeStartElement("", name.getLocalPart(), name.getNamespaceURI());
    w.writeDefaultNamespace(name.getNamespaceURI());
    if (type != null)
        w.writeAttribute("type", type);
    w.writeCharacters(value);
    w.writeEndElement();
}
 
Example 6
Source File: UnsupportedPrivilegeException.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
protected void writeContent(XMLStreamWriter writer)
    throws XMLStreamException {
    writer.writeStartElement("DAV:", "not-supported-privilege");
    if (getMessage() != null) {
        writer.writeCharacters(getMessage());
    }
    writer.writeEndElement();
}
 
Example 7
Source File: AnnotationInfo.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Write XML formatted annotation configuration
 *  @param writer PrintWriter
 *  @throws Exception on error
 */
public void write(final XMLStreamWriter writer) throws Exception
{
    if (internal)
        return;

    writer.writeStartElement(XMLPersistence.TAG_ANNOTATION);
    {
        writer.writeStartElement(XMLPersistence.TAG_PV);
        writer.writeCharacters(Integer.toString(item_index));
        writer.writeEndElement();
        writer.writeStartElement(XMLPersistence.TAG_TIME);
        writer.writeCharacters(TimestampFormats.MILLI_FORMAT.format(time));
        writer.writeEndElement();
        writer.writeStartElement(XMLPersistence.TAG_VALUE);
        writer.writeCharacters(Double.toString(value));
        writer.writeEndElement();

        writer.writeStartElement(XMLPersistence.TAG_OFFSET);
        {
            writer.writeStartElement(XMLPersistence.TAG_X);
            writer.writeCharacters(Double.toString(offset.getX()));
            writer.writeEndElement();
            writer.writeStartElement(XMLPersistence.TAG_Y);
            writer.writeCharacters(Double.toString(offset.getY()));
            writer.writeEndElement();
        }
        writer.writeEndElement();

        writer.writeStartElement(XMLPersistence.TAG_TEXT);
        writer.writeCharacters(text);
        writer.writeEndElement();
    }
    writer.writeEndElement();
}
 
Example 8
Source File: AbstractSTSClient.java    From steady with Apache License 2.0 5 votes vote down vote up
protected void addTokenType(XMLStreamWriter writer) throws XMLStreamException {
    if (tokenType != null) {
        writer.writeStartElement("wst", "TokenType", namespace);
        writer.writeCharacters(tokenType);
        writer.writeEndElement();
    }
}
 
Example 9
Source File: ProblemActionHeader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
    w.writeStartElement("", getLocalPart(), getNamespaceURI());
    w.writeDefaultNamespace(getNamespaceURI());
    w.writeStartElement(actionLocalName);
    w.writeCharacters(action);
    w.writeEndElement();
    if (soapAction != null) {
        w.writeStartElement(soapActionLocalName);
        w.writeCharacters(soapAction);
        w.writeEndElement();
    }
    w.writeEndElement();
}
 
Example 10
Source File: FaultDetailHeader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
    w.writeStartElement("", av.faultDetailTag.getLocalPart(), av.faultDetailTag.getNamespaceURI());
    w.writeDefaultNamespace(av.nsUri);
    w.writeStartElement("", wrapper, av.nsUri);
    w.writeCharacters(problemValue);
    w.writeEndElement();
    w.writeEndElement();
}
 
Example 11
Source File: AtomGeoValueSerializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void points(final XMLStreamWriter writer, final Iterator<Point> itor, final boolean wrap)
    throws XMLStreamException {

  while (itor.hasNext()) {
    final Point point = itor.next();

    if (wrap) {
      writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POINT, Constants.NS_GML);
    }

    writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POS, Constants.NS_GML);
    try {
      writer.writeCharacters(EdmDouble.getInstance().valueToString(point.getX(), null, null,
          Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)
          + " "
          + EdmDouble.getInstance().valueToString(point.getY(), null, null,
              Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null));
    } catch (EdmPrimitiveTypeException e) {
      throw new XMLStreamException("While serializing point coordinates as double", e);
    }
    writer.writeEndElement();

    if (wrap) {
      writer.writeEndElement();
    }
  }
}
 
Example 12
Source File: FaultDetailHeader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
    w.writeStartElement("", av.faultDetailTag.getLocalPart(), av.faultDetailTag.getNamespaceURI());
    w.writeDefaultNamespace(av.nsUri);
    w.writeStartElement("", wrapper, av.nsUri);
    w.writeCharacters(problemValue);
    w.writeEndElement();
    w.writeEndElement();
}
 
Example 13
Source File: HtmlProcessorDocumentationWriter.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Writes out just the attributes that are being written to in a table form.
 *
 * @param xmlStreamWriter the xml stream writer to use
 * @param processor the processor to describe
 * @throws XMLStreamException xse
 */
private void handleWritesAttributes(XMLStreamWriter xmlStreamWriter, final Processor processor)
        throws XMLStreamException {
    List<WritesAttribute> attributesRead = getWritesAttributes(processor);

    writeSimpleElement(xmlStreamWriter, "h3", "Writes Attributes: ");
    if (attributesRead.size() > 0) {
        xmlStreamWriter.writeStartElement("table");
        xmlStreamWriter.writeAttribute("id", "writes-attributes");
        xmlStreamWriter.writeStartElement("tr");
        writeSimpleElement(xmlStreamWriter, "th", "Name");
        writeSimpleElement(xmlStreamWriter, "th", "Description");
        xmlStreamWriter.writeEndElement();
        for (WritesAttribute attribute : attributesRead) {
            xmlStreamWriter.writeStartElement("tr");
            writeSimpleElement(xmlStreamWriter, "td",
                    defaultIfBlank(attribute.attribute(), "Not Specified"));
            // TODO allow for HTML characters here.
            writeSimpleElement(xmlStreamWriter, "td",
                    defaultIfBlank(attribute.description(), "Not Specified"));
            xmlStreamWriter.writeEndElement();
        }
        xmlStreamWriter.writeEndElement();

    } else {
        xmlStreamWriter.writeCharacters("None specified.");
    }
}
 
Example 14
Source File: HtmlDocumentationWriter.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void writeDynamicProperties(final ConfigurableComponent configurableComponent,
        final XMLStreamWriter xmlStreamWriter) throws XMLStreamException {

    final List<DynamicProperty> dynamicProperties = getDynamicProperties(configurableComponent);

    if (dynamicProperties != null && dynamicProperties.size() > 0) {
        writeSimpleElement(xmlStreamWriter, "h3", "Dynamic Properties: ");
        xmlStreamWriter.writeStartElement("p");
        xmlStreamWriter
                .writeCharacters("Dynamic Properties allow the user to specify both the name and value of a property.");
        xmlStreamWriter.writeStartElement("table");
        xmlStreamWriter.writeAttribute("id", "dynamic-properties");
        xmlStreamWriter.writeStartElement("tr");
        writeSimpleElement(xmlStreamWriter, "th", "Name");
        writeSimpleElement(xmlStreamWriter, "th", "Value");
        writeSimpleElement(xmlStreamWriter, "th", "Description");
        xmlStreamWriter.writeEndElement();
        for (final DynamicProperty dynamicProperty : dynamicProperties) {
            xmlStreamWriter.writeStartElement("tr");
            writeSimpleElement(xmlStreamWriter, "td", dynamicProperty.name(), false, "name");
            writeSimpleElement(xmlStreamWriter, "td", dynamicProperty.value(), false, "value");
            xmlStreamWriter.writeStartElement("td");
            xmlStreamWriter.writeCharacters(dynamicProperty.description());
            if (dynamicProperty.supportsExpressionLanguage()) {
                xmlStreamWriter.writeEmptyElement("br");
                writeSimpleElement(xmlStreamWriter, "strong", "Supports Expression Language: true");
            }
            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeEndElement();
        }

        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeEndElement();
    }
}
 
Example 15
Source File: DefaultNSWriter.java    From softwarecave with GNU General Public License v3.0 5 votes vote down vote up
private void writeAuthorsElem(XMLStreamWriter writer, List<String> authors) throws XMLStreamException {
    writer.writeStartElement(NS, "authors");
    for (String author : authors) {
        writer.writeStartElement(NS, "author");
        writer.writeCharacters(author);
        writer.writeEndElement();
    }
    writer.writeEndElement();
}
 
Example 16
Source File: XmlMetadataProducer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private static void writeAnnotationElements(final Collection<AnnotationElement> annotationElements,
    final Map<String, String> predefinedNamespaces, final XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
  if (annotationElements != null) {
    for (AnnotationElement annotationElement : annotationElements) {
      ArrayList<String> setNamespaces = new ArrayList<String>();
      if (annotationElement.getNamespace() != null) {
        if (annotationElement.getPrefix() != null) {
          xmlStreamWriter.writeStartElement(annotationElement.getPrefix(), annotationElement.getName(),
              annotationElement.getNamespace());
          if (!predefinedNamespaces.containsValue(annotationElement.getNamespace())) {
            xmlStreamWriter.writeNamespace(annotationElement.getPrefix(), annotationElement.getNamespace());
            setNamespaces.add(annotationElement.getNamespace());
          }
        } else {
          xmlStreamWriter.writeStartElement("", annotationElement.getName(), annotationElement.getNamespace());
          if (!predefinedNamespaces.containsValue(annotationElement.getNamespace())) {
            xmlStreamWriter.writeNamespace("", annotationElement.getNamespace());
            setNamespaces.add(annotationElement.getNamespace());
          }
        }
      } else {
        xmlStreamWriter.writeStartElement(annotationElement.getName());
      }

      writeAnnotationAttributes(annotationElement.getAttributes(), predefinedNamespaces, setNamespaces,
          xmlStreamWriter);

      if (annotationElement.getChildElements() != null) {
        writeAnnotationElements(annotationElement.getChildElements(), predefinedNamespaces, xmlStreamWriter);
      } else {
        if (annotationElement.getText() != null) {
          xmlStreamWriter.writeCharacters(annotationElement.getText());
        }
      }

      xmlStreamWriter.writeEndElement();
    }
  }
}
 
Example 17
Source File: UnsupportedCalendarDataException.java    From cosmo with Apache License 2.0 4 votes vote down vote up
protected void writeContent(XMLStreamWriter writer)
    throws XMLStreamException {
    writer.writeStartElement(NS_CALDAV, "supported-calendar-data");
    writer.writeCharacters(getMessage());
    writer.writeEndElement();
}
 
Example 18
Source File: SOSService.java    From sensorhub with Mozilla Public License 2.0 4 votes vote down vote up
@Override
protected void handleRequest(DescribeSensorRequest request) throws Exception
{
    String sensorID = request.getProcedureID();
            
    // check query parameters
    OWSExceptionReport report = new OWSExceptionReport();        
    checkQueryProcedure(sensorID, report);
    checkQueryProcedureFormat(procedureToOfferingMap.get(sensorID), request.getFormat(), report);
    report.process();
    
    // get procedure description
    AbstractProcess processDesc = generateSensorML(sensorID, request.getTime());
    if (processDesc == null)
        throw new SOSException(SOSException.invalid_param_code, "validTime"); 
    
    // init xml document writing
    OutputStream os = new BufferedOutputStream(request.getResponseStream());
    XMLOutputFactory factory = XMLImplFinder.getStaxOutputFactory();
    XMLStreamWriter xmlWriter = factory.createXMLStreamWriter(os, StandardCharsets.UTF_8.name());
    xmlWriter = new IndentingXMLStreamWriter(xmlWriter);
    
    // prepare SensorML writing
    SMLStaxBindings smlBindings = new SMLStaxBindings();
    smlBindings.setNamespacePrefixes(xmlWriter);
    smlBindings.declareNamespacesOnRootElement();
    
    // start XML response
    xmlWriter.writeStartDocument();
    
    // wrap with SOAP envelope if requested
    String soapUri = request.getSoapVersion(); 
    if (soapUri != null)
    {
        xmlWriter.writeStartElement(SOAP_PREFIX, "Envelope", soapUri);
        xmlWriter.writeNamespace(SOAP_PREFIX, soapUri);
        xmlWriter.writeStartElement(SOAP_PREFIX, "Body", soapUri);
    }
    
    String swesNsUri = OGCRegistry.getNamespaceURI(SOSUtils.SWES, DEFAULT_VERSION);
    xmlWriter.writeStartElement(SWES_PREFIX, "DescribeSensorResponse", swesNsUri);
    xmlWriter.writeNamespace(SWES_PREFIX, swesNsUri);
    
    xmlWriter.writeStartElement(SWES_PREFIX, "procedureDescriptionFormat", swesNsUri);
    xmlWriter.writeCharacters(DescribeSensorRequest.DEFAULT_FORMAT);
    xmlWriter.writeEndElement();
    
    xmlWriter.writeStartElement(SWES_PREFIX, "description", swesNsUri);
    xmlWriter.writeStartElement(SWES_PREFIX, "SensorDescription", swesNsUri);
    xmlWriter.writeStartElement(SWES_PREFIX, "data", swesNsUri);
    smlBindings.writeAbstractProcess(xmlWriter, processDesc);
    xmlWriter.writeEndElement();
    xmlWriter.writeEndElement();
    xmlWriter.writeEndElement();
    
    xmlWriter.writeEndElement();
    
    // close SOAP elements
    if (soapUri != null)
    {
        xmlWriter.writeEndElement();
        xmlWriter.writeEndElement();
    }
    
    xmlWriter.writeEndDocument();
    xmlWriter.close();
}
 
Example 19
Source File: CfgNet.java    From aion with MIT License 4 votes vote down vote up
public String toXML() {
    final XMLOutputFactory output = XMLOutputFactory.newInstance();
    output.setProperty("escapeCharacters", false);
    XMLStreamWriter xmlWriter;
    String xml;
    try {
        Writer strWriter = new StringWriter();
        xmlWriter = output.createXMLStreamWriter(strWriter);

        // start element net
        xmlWriter.writeCharacters("\r\n\t");
        xmlWriter.writeStartElement("net");

        // sub-element id
        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeStartElement("id");
        xmlWriter.writeCharacters(this.id + "");
        xmlWriter.writeEndElement();

        // sub-element nodes
        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeStartElement("nodes");
        for (String node : nodes) {
            xmlWriter.writeCharacters("\r\n\t\t\t");
            xmlWriter.writeStartElement("node");
            xmlWriter.writeCharacters(node);
            xmlWriter.writeEndElement();
        }
        xmlWriter.writeCharacters("\r\n\t\t");
        xmlWriter.writeEndElement();

        // sub-element p2p
        xmlWriter.writeCharacters(this.p2p.toXML());

        // close element net
        xmlWriter.writeCharacters("\r\n\t");
        xmlWriter.writeEndElement();

        xml = strWriter.toString();
        strWriter.flush();
        strWriter.close();
        xmlWriter.flush();
        xmlWriter.close();
        return xml;
    } catch (IOException | XMLStreamException e) {
        e.printStackTrace();
        return "";
    }
}
 
Example 20
Source File: JkMavenMetadata.java    From jeka with Apache License 2.0 4 votes vote down vote up
private static void writeElement(XMLStreamWriter writer, String name, String value)
        throws XMLStreamException {
    writer.writeStartElement(name);
    writer.writeCharacters(value);
    writer.writeEndElement();
}