javax.xml.stream.XMLStreamWriter Java Examples

The following examples show how to use javax.xml.stream.XMLStreamWriter. 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: StaxUtilsTest.java    From cxf with Apache License 2.0 7 votes vote down vote up
@Test
public void testCopyWithEmptyNamespace() throws Exception {
    StringBuilder in = new StringBuilder(128);
    in.append("<foo xmlns=\"http://example.com/\">");
    in.append("<bar xmlns=\"\"/>");
    in.append("</foo>");

    XMLStreamReader reader = StaxUtils.createXMLStreamReader(
         new ByteArrayInputStream(in.toString().getBytes()));

    Writer out = new StringWriter();
    XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out);
    StaxUtils.copy(reader, writer);
    writer.close();

    assertEquals(in.toString(), out.toString());
}
 
Example #2
Source File: CorbaStreamOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void handleOutBoundMessage(CorbaMessage message, BindingOperationInfo boi) {
    boolean wrap = false;
    if (boi.isUnwrappedCapable()) {
        wrap = true;
    }
    OperationType opType = boi.getExtensor(OperationType.class);
    List<ParamType> paramTypes = opType.getParam();
    List<ArgType> params = new ArrayList<>();
    for (Iterator<ParamType> iter = paramTypes.iterator(); iter.hasNext();) {
        ParamType param = iter.next();
        if (!param.getMode().equals(ModeType.OUT)) {
            params.add(param);
        }
    }
    CorbaStreamWriter writer = new CorbaStreamWriter(orb, params, typeMap, service, wrap);
    message.setContent(XMLStreamWriter.class, writer);
}
 
Example #3
Source File: Wsdl.java    From iaf with Apache License 2.0 6 votes vote down vote up
protected void jmsBinding(XMLStreamWriter w, String namePrefix) throws XMLStreamException, IOException, ConfigurationException {
    w.writeStartElement(WSDL_NAMESPACE, "binding");
    w.writeAttribute("name", namePrefix + "Binding_" + WsdlUtils.getNCName(getName()));
    w.writeAttribute("type", getTargetNamespacePrefix() + ":" + "PortType_" + getName()); {
        w.writeEmptyElement(wsdlSoapNamespace, "binding");
        w.writeAttribute("style", "document");
        if (esbSoap) {
            w.writeAttribute("transport", ESB_SOAP_JMS_NAMESPACE);
            w.writeEmptyElement(ESB_SOAP_JMS_NAMESPACE, "binding");
            w.writeAttribute("messageFormat", "Text");
            for (IListener listener : WsdlUtils.getListeners(pipeLine.getAdapter())) {
                if (listener instanceof JmsListener) {
                    writeSoapOperation(w, listener);
                }
            }
        } else {
            w.writeAttribute("transport", SOAP_JMS_NAMESPACE);
        }
    }
    w.writeEndElement();
}
 
Example #4
Source File: ServletHelper.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Create XML content for scan server info
 *  @param writer {@link XMLStreamWriter}
 *  @param info {@link ScanServerInfo}
 *  @throws Exception on error
 */
public static void write(final XMLStreamWriter writer, final ScanServerInfo info) throws Exception
{
    writer.writeStartElement("server");

    write(writer, "version", info.getVersion());
    write(writer, "start_time", info.getStartTime());
    write(writer, "scan_config", info.getScanConfig());
    write(writer, "script_paths", PathUtil.joinPaths(info.getScriptPaths()));
    write(writer, "macros", info.getMacros());
    write(writer, "used_mem", info.getUsedMem());
    write(writer, "max_mem", info.getMaxMem());
    write(writer, "non_heap", info.getNonHeapUsedMem());

    writer.writeEndElement();
}
 
Example #5
Source File: DocumentMetadataHandle.java    From java-client-api with Apache License 2.0 6 votes vote down vote up
private void sendPermissionsImpl(XMLStreamWriter serializer) throws XMLStreamException {
  if ( getPermissions() == null || getPermissions().size() == 0 ) return;
  serializer.writeStartElement("rapi", "permissions", REST_API_NS);

  for (Map.Entry<String, Set<Capability>> permission: getPermissions().entrySet()) {
    serializer.writeStartElement("rapi", "permission", REST_API_NS);

    serializer.writeStartElement("rapi", "role-name", REST_API_NS);
    if(permission.getKey() != null)
      serializer.writeCharacters(permission.getKey());
    serializer.writeEndElement();

    for (Capability capability: permission.getValue()) {
      serializer.writeStartElement("rapi", "capability", REST_API_NS);
      serializer.writeCharacters(capability.toString().toLowerCase());
      serializer.writeEndElement();
    }

    serializer.writeEndElement();
  }

  serializer.writeEndElement();
}
 
Example #6
Source File: AtomEntryEntityProducer.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
private void appendProperties(final XMLStreamWriter writer, final EntityInfoAggregator eia, final Map<String, Object> data) throws EntityProviderException {
  try {
    List<String> propertyNames = eia.getSelectedPropertyNames();
    if (!propertyNames.isEmpty()) {
      writer.writeStartElement(Edm.NAMESPACE_M_2007_08, FormatXml.M_PROPERTIES);

      for (String propertyName : propertyNames) {
        EntityPropertyInfo propertyInfo = eia.getPropertyInfo(propertyName);

        if (isNotMappedViaCustomMapping(propertyInfo)) {
          Object value = data.get(propertyName);
          XmlPropertyEntityProducer aps = new XmlPropertyEntityProducer();
          aps.append(writer, propertyInfo.getName(), propertyInfo, value);
        }
      }

      writer.writeEndElement();
    }
  } catch (XMLStreamException e) {
    throw new EntityProviderException(EntityProviderException.COMMON, e);
  }
}
 
Example #7
Source File: BaseBpmnXMLConverter.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void writeEventDefinitions(Event parentEvent, List<EventDefinition> eventDefinitions, BpmnModel model, XMLStreamWriter xtw) throws Exception {
    for (EventDefinition eventDefinition : eventDefinitions) {
        if (eventDefinition instanceof TimerEventDefinition) {
            writeTimerDefinition(parentEvent, (TimerEventDefinition) eventDefinition, model, xtw);
        } else if (eventDefinition instanceof SignalEventDefinition) {
            writeSignalDefinition(parentEvent, (SignalEventDefinition) eventDefinition, model, xtw);
        } else if (eventDefinition instanceof MessageEventDefinition) {
            writeMessageDefinition(parentEvent, (MessageEventDefinition) eventDefinition, model, xtw);
        } else if (eventDefinition instanceof ConditionalEventDefinition) {
            writeConditionalDefinition(parentEvent, (ConditionalEventDefinition) eventDefinition, model, xtw);
        } else if (eventDefinition instanceof ErrorEventDefinition) {
            writeErrorDefinition(parentEvent, (ErrorEventDefinition) eventDefinition, model, xtw);
        } else if (eventDefinition instanceof EscalationEventDefinition) {
            writeEscalationDefinition(parentEvent, (EscalationEventDefinition) eventDefinition, model, xtw);
        } else if (eventDefinition instanceof TerminateEventDefinition) {
            writeTerminateDefinition(parentEvent, (TerminateEventDefinition) eventDefinition, model, xtw);
        } else if (eventDefinition instanceof CancelEventDefinition) {
            writeCancelDefinition(parentEvent, (CancelEventDefinition) eventDefinition, model, xtw);
        } else if (eventDefinition instanceof CompensateEventDefinition) {
            writeCompensateDefinition(parentEvent, (CompensateEventDefinition) eventDefinition, model, xtw);
        }
    }
}
 
Example #8
Source File: OdsWritter.java    From SODS with Apache License 2.0 6 votes vote down vote up
private void writeBorderStyle(XMLStreamWriter out, Style style) throws XMLStreamException {
  	
Borders borders = style.getBorders();
if (borders.isBorder()) {
	out.writeAttribute("fo:border", borders.getBorderProperties());
}

if (borders.isBorderTop()) {
	out.writeAttribute("fo:border-top", borders.getBorderTopProperties());
}

if (borders.isBorderBottom()) {
	out.writeAttribute("fo:border-bottom", borders.getBorderBottomProperties());
}

if (borders.isBorderLeft()) {
	out.writeAttribute("fo:border-left", borders.getBorderLeftProperties());
}

if (borders.isBorderRight()) {
	out.writeAttribute("fo:border-right", borders.getBorderRightProperties());
}
  }
 
Example #9
Source File: DocumentStaxUtils.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void writeDocument(Document doc, OutputStream outputStream, String namespaceURI) throws XMLStreamException, IOException {
  if(outputFactory == null) {
    outputFactory = XMLOutputFactory.newInstance();
  }

  XMLStreamWriter xsw = null;
  try {
    if(doc instanceof TextualDocument) {
      xsw = outputFactory.createXMLStreamWriter(outputStream,
              ((TextualDocument)doc).getEncoding());
      xsw.writeStartDocument(((TextualDocument)doc).getEncoding(), "1.0");
    }
    else {
      xsw = outputFactory.createXMLStreamWriter(outputStream);
      xsw.writeStartDocument("1.0");
    }
    newLine(xsw);

    writeDocument(doc, xsw, namespaceURI);
  }
  finally {
    if(xsw != null) {
      xsw.close();
    }
  }
}
 
Example #10
Source File: StaxUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static void writeAttributeEvent(XMLEvent event, XMLStreamWriter writer)
    throws XMLStreamException {

    Attribute attr = (Attribute)event;
    QName name = attr.getName();
    String nsURI = name.getNamespaceURI();
    String localName = name.getLocalPart();
    String prefix = name.getPrefix();
    String value = attr.getValue();

    if (prefix != null) {
        writer.writeAttribute(prefix, nsURI, localName, value);
    } else if (nsURI != null) {
        writer.writeAttribute(nsURI, localName, value);
    } else {
        writer.writeAttribute(localName, value);
    }
}
 
Example #11
Source File: XMLOutputTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testSpecialSymbolsInAttributeValuesAreEscaped() throws KettleException, XMLStreamException {
  xmlOutput.init( xmlOutputMeta, xmlOutputData );

  xmlOutputData.writer = mock( XMLStreamWriter.class );
  xmlOutput.writeRowAttributes( rowWithData );
  xmlOutput.dispose( xmlOutputMeta, xmlOutputData );
  verify( xmlOutputData.writer, times( rowWithData.length ) ).writeAttribute( any(), any() );
  verify( xmlOutput, atLeastOnce() ).closeOutputStream( any() );
}
 
Example #12
Source File: XMLStreamWriterUtil.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gives the encoding with which XMLStreamWriter is created.
 *
 * @param writer XMLStreamWriter for which encoding is required
 * @return null if cannot be found, else the encoding
 */
public static @Nullable String getEncoding(XMLStreamWriter writer) {
    /*
     * TODO Add reflection logic to handle woodstox writer
     * as it implements XMLStreamWriter2#getEncoding()
     * It's not that important since woodstox writer is typically wrapped
     * in a writer with HasEncoding
     */
    return (writer instanceof HasEncoding)
            ? ((HasEncoding)writer).getEncoding()
            : null;
}
 
Example #13
Source File: SAAJMessage.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void writeTo(XMLStreamWriter writer) throws XMLStreamException {
    try {
        writer.writeStartDocument();
        if (!parsedMessage) {
            DOMUtil.serializeNode(sm.getSOAPPart().getEnvelope(), writer);
        } else {
            SOAPEnvelope env = sm.getSOAPPart().getEnvelope();
            DOMUtil.writeTagWithAttributes(env, writer);
            if (hasHeaders()) {
                if(env.getHeader() != null) {
                    DOMUtil.writeTagWithAttributes(env.getHeader(), writer);
                } else {
                    writer.writeStartElement(env.getPrefix(), "Header", env.getNamespaceURI());
                }
                for (Header h : headers.asList()) {
                    h.writeTo(writer);
                }
                writer.writeEndElement();
            }

            DOMUtil.serializeNode(sm.getSOAPBody(), writer);
            writer.writeEndElement();
        }
        writer.writeEndDocument();
        writer.flush();
    } catch (SOAPException ex) {
        throw new XMLStreamException2(ex);
        //for now. ask jaxws team what to do.
    }
}
 
Example #14
Source File: XMLStreamWriterFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Fetchs an instance from the pool if available, otherwise null.
 */
private @Nullable XMLStreamWriter fetch() {
    XMLStreamWriter sr = pool.get();
    if(sr==null)    return null;
    pool.set(null);
    return sr;
}
 
Example #15
Source File: MarshallerBridge.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void marshal(Marshaller m, Object object, XMLStreamWriter output) throws JAXBException {
    m.setProperty(Marshaller.JAXB_FRAGMENT,true);
    try {
        m.marshal(object,output);
    } finally {
        m.setProperty(Marshaller.JAXB_FRAGMENT,false);
    }
}
 
Example #16
Source File: XMLWriterHelper.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public void startWrapperElement(XMLStreamWriter xmlWriter, String namespace,
		String name, int resultType) throws XMLStreamException {
       if (xmlWriter == null) {
           return;
       }
	String nsPrefix;
	boolean writeNS;
	switch (resultType) {
	case DBConstants.ResultTypes.XML:
		if (name != null) {
		    /* start result wrapper */
		    xmlWriter.writeStartElement(name);
		    /* write default namespace */
		    nsPrefix = xmlWriter.getNamespaceContext().getPrefix(this.getNamespace());
			writeNS = nsPrefix == null || !"".equals(nsPrefix);				
		    if (writeNS) {
		    	xmlWriter.setDefaultNamespace(namespace);
		        xmlWriter.writeDefaultNamespace(namespace);
		    }
		}
		break;
	case DBConstants.ResultTypes.RDF:
		xmlWriter.setDefaultNamespace(namespace);
		xmlWriter.writeStartElement(DBConstants.DEFAULT_RDF_PREFIX,
				DBConstants.DBSFields.RDF, DBConstants.RDF_NAMESPACE);
		xmlWriter.writeNamespace(DBConstants.DEFAULT_RDF_PREFIX, DBConstants.RDF_NAMESPACE);
		xmlWriter.writeDefaultNamespace(namespace);
		break;
	}
}
 
Example #17
Source File: RequiredParts.java    From steady with Apache License 2.0 5 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    String localName = getRealName().getLocalPart();
    String namespaceURI = getRealName().getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);

    if (prefix == null) {
        prefix = getRealName().getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:RequiredParts>
    writer.writeStartElement(prefix, localName, namespaceURI);

    // xmlns:sp=".."
    writer.writeNamespace(prefix, namespaceURI);

    Header header;
    for (Iterator<Header> iterator = headers.iterator(); iterator.hasNext();) {
        header = iterator.next();
        // <sp:Header Name=".." Namespace=".." />
        writer.writeStartElement(prefix, SPConstants.HEADER, namespaceURI);
        // Name attribute is optional
        if (!StringUtils.isEmpty(header.getName())) {
            writer.writeAttribute("Name", header.getName());
        }
        writer.writeAttribute("Namespace", header.getNamespace());

        writer.writeEndElement();
    }

    // </sp:RequiredParts>
    writer.writeEndElement();
}
 
Example #18
Source File: RoundTripTest.java    From jettison with Apache License 2.0 5 votes vote down vote up
public void toXMLStream(XMLStreamWriter xwrt) throws XMLStreamException {
    xwrt.writeStartElement(ELEMENT);
    if (getColor() != null) {
        String color = ColorUtil.colorToString(getColor());
        xwrt.writeAttribute(COLOR, color);
    }
    if (StringUtil.isNotBlank(getLabel())) {
        xwrt.writeAttribute(LABEL, getLabel());
    }
    if (getURI() != null) {
        xwrt.writeAttribute(URI, getURI().toString());
    }
    xwrt.writeAttribute(VALUE, getValue().toString());
    xwrt.writeEndElement();
}
 
Example #19
Source File: JkPomTemplateGenerator.java    From jeka with Apache License 2.0 5 votes vote down vote up
private static void writeElement(String indent, XMLStreamWriter writer, String elementName,
        String text) throws XMLStreamException {
    if (text == null) {
        return;
    }
    writer.writeCharacters(indent);
    writeElement(writer, elementName, text);
}
 
Example #20
Source File: RequiredParts.java    From steady with Apache License 2.0 5 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    String localName = getRealName().getLocalPart();
    String namespaceURI = getRealName().getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);

    if (prefix == null) {
        prefix = getRealName().getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:RequiredParts>
    writer.writeStartElement(prefix, localName, namespaceURI);

    // xmlns:sp=".."
    writer.writeNamespace(prefix, namespaceURI);

    Header header;
    for (Iterator<Header> iterator = headers.iterator(); iterator.hasNext();) {
        header = iterator.next();
        // <sp:Header Name=".." Namespace=".." />
        writer.writeStartElement(prefix, SPConstants.HEADER, namespaceURI);
        // Name attribute is optional
        if (!StringUtils.isEmpty(header.getName())) {
            writer.writeAttribute("Name", header.getName());
        }
        writer.writeAttribute("Namespace", header.getNamespace());

        writer.writeEndElement();
    }

    // </sp:RequiredParts>
    writer.writeEndElement();
}
 
Example #21
Source File: RecipientSignatureToken.java    From steady with Apache License 2.0 5 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    String localName = getRealName().getLocalPart();
    String namespaceURI = getRealName().getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);

    if (prefix == null) {
        prefix = getRealName().getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:RecipientSignatureToken>
    writer.writeStartElement(prefix, localName, namespaceURI);

    String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
    if (pPrefix == null) {
        pPrefix = SPConstants.POLICY.getPrefix();
        writer.setPrefix(pPrefix, SPConstants.POLICY.getNamespaceURI());
    }

    // <wsp:Policy>
    writer.writeStartElement(pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY
        .getNamespaceURI());

    Token token = getRecipientSignatureToken();
    if (token == null) {
        throw new RuntimeException("RecipientSignatureToken doesn't contain any token assertions");
    }
    token.serialize(writer);

    // </wsp:Policy>
    writer.writeEndElement();

    // </sp:RecipientSignatureToken>
    writer.writeEndElement();
}
 
Example #22
Source File: AtomSerializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void collection(final XMLStreamWriter writer,
    final ValueType valueType, final EdmPrimitiveTypeKind kind, final List<?> value)
        throws XMLStreamException, EdmPrimitiveTypeException {
  for (Object item : value) {
    writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ELEM_ELEMENT, Constants.NS_METADATA);
    value(writer, valueType, kind, item);
    writer.writeEndElement();
  }
}
 
Example #23
Source File: FieldExtensionExport.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static boolean writeFieldExtensions(List<FieldExtension> fieldExtensionList, boolean didWriteExtensionStartElement, XMLStreamWriter xtw) throws Exception {

    for (FieldExtension fieldExtension : fieldExtensionList) {

      if (StringUtils.isNotEmpty(fieldExtension.getFieldName())) {

        if (StringUtils.isNotEmpty(fieldExtension.getStringValue()) || StringUtils.isNotEmpty(fieldExtension.getExpression())) {

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

          xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ELEMENT_FIELD, ACTIVITI_EXTENSIONS_NAMESPACE);
          BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_FIELD_NAME, fieldExtension.getFieldName(), xtw);

          if (StringUtils.isNotEmpty(fieldExtension.getStringValue())) {
            xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ELEMENT_FIELD_STRING, ACTIVITI_EXTENSIONS_NAMESPACE);
            xtw.writeCData(fieldExtension.getStringValue());
          } else {
            xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ATTRIBUTE_FIELD_EXPRESSION, ACTIVITI_EXTENSIONS_NAMESPACE);
            xtw.writeCData(fieldExtension.getExpression());
          }
          xtw.writeEndElement();
          xtw.writeEndElement();
        }
      }
    }
    return didWriteExtensionStartElement;
  }
 
Example #24
Source File: SPARQLQuery.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private void processPostQuery(Object result, XMLStreamWriter xmlWriter,
                              InternalParamCollection params, int queryLevel) throws DataServiceFault {
    try {
        ResultSet results = (ResultSet) result;
        DataEntry dataEntry;
        while (results != null && results.hasNext()) {
            dataEntry = this.getDataEntryFromRS(results);
            this.writeResultEntry(xmlWriter, dataEntry, params, queryLevel);
        }
    } catch (Exception e) {
        throw new DataServiceFault(e, "Error in 'SPARQLQuery.processQuery'");
    }
}
 
Example #25
Source File: StaxUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Return the {@link XMLStreamWriter} for the given StAX Result.
 * @param result a JAXP 1.4 {@link StAXResult}
 * @return the {@link XMLStreamReader}
 * @throws IllegalArgumentException if {@code source} isn't a JAXP 1.4 {@link StAXResult}
 * or custom StAX Result
 */
@Nullable
public static XMLStreamWriter getXMLStreamWriter(Result result) {
	if (result instanceof StAXResult) {
		return ((StAXResult) result).getXMLStreamWriter();
	}
	else if (result instanceof StaxResult) {
		return ((StaxResult) result).getXMLStreamWriter();
	}
	else {
		throw new IllegalArgumentException("Result '" + result + "' is neither StaxResult nor StAXResult");
	}
}
 
Example #26
Source File: DocumentMetadataPatchBuilderImpl.java    From java-client-api with Apache License 2.0 5 votes vote down vote up
@Override
public void write(XMLOutputSerializer out) throws Exception {
  XMLStreamWriter serializer = out.getSerializer();
  writeStartInsert(out, "/rapi:metadata/rapi:metadata-values", "last-child", null);

  serializer.writeStartElement("rapi", "metadata-value", REST_API_NS);
  serializer.writeAttribute("key", key);
  if(value != null)
    serializer.writeCharacters(value);
  serializer.writeEndElement();

  serializer.writeEndElement();
}
 
Example #27
Source File: FastInfosetStreamSOAPCodec.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private XMLStreamWriter getXMLStreamWriter(OutputStream out) {
    if (_serializer != null) {
        _serializer.setOutputStream(out);
        return _serializer;
    } else {
        return _serializer = FastInfosetCodec.createNewStreamWriter(out, _retainState);
    }
}
 
Example #28
Source File: XmlFormatter.java    From jboss-logmanager-ext with Apache License 2.0 5 votes vote down vote up
@Override
protected Generator createGenerator(final Writer writer) throws Exception {
    final XMLStreamWriter xmlWriter;
    if (prettyPrint) {
        xmlWriter = new IndentingXmlWriter(factory.createXMLStreamWriter(writer));
    } else {
        xmlWriter = factory.createXMLStreamWriter(writer);
    }
    return new XmlGenerator(xmlWriter);
}
 
Example #29
Source File: HtmlDocumentationWriter.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Write the description of the Restricted annotation if provided in this component.
 *
 * @param configurableComponent the component to describe
 * @param xmlStreamWriter the stream writer to use
 * @throws XMLStreamException thrown if there was a problem writing the XML
 */
private void writeRestrictedInfo(ConfigurableComponent configurableComponent, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    final Restricted restricted = configurableComponent.getClass().getAnnotation(Restricted.class);

    writeSimpleElement(xmlStreamWriter, "h3", "Restricted: ");

    if(restricted != null) {
        final String value = restricted.value();

        if (!StringUtils.isBlank(value)) {
            xmlStreamWriter.writeCharacters(restricted.value());
        }

        final Restriction[] restrictions = restricted.restrictions();
        if (restrictions != null && restrictions.length > 0) {
            xmlStreamWriter.writeStartElement("table");
            xmlStreamWriter.writeAttribute("id", "restrictions");
            xmlStreamWriter.writeStartElement("tr");
            writeSimpleElement(xmlStreamWriter, "th", "Required Permission");
            writeSimpleElement(xmlStreamWriter, "th", "Explanation");
            xmlStreamWriter.writeEndElement();

            for (Restriction restriction : restrictions) {
                xmlStreamWriter.writeStartElement("tr");
                writeSimpleElement(xmlStreamWriter, "td", restriction.requiredPermission().getPermissionLabel());
                writeSimpleElement(xmlStreamWriter, "td", restriction.explanation());
                xmlStreamWriter.writeEndElement();
            }

            xmlStreamWriter.writeEndElement();
        } else {
            xmlStreamWriter.writeCharacters("This component requires access to restricted components regardless of restriction.");
        }
    } else {
        xmlStreamWriter.writeCharacters("This component is not restricted.");
    }
}
 
Example #30
Source File: DOMUtil.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isPrefixDeclared(XMLStreamWriter writer, String nsUri, String prefix) {
    boolean prefixDecl = false;
    NamespaceContext nscontext = writer.getNamespaceContext();
    Iterator prefixItr = nscontext.getPrefixes(nsUri);
    while (prefixItr.hasNext()) {
        if (prefix.equals(prefixItr.next())) {
            prefixDecl = true;
            break;
        }
    }
    return prefixDecl;
}