javax.xml.stream.XMLStreamWriter#writeDefaultNamespace ( )源码实例Demo

下面列出了javax.xml.stream.XMLStreamWriter#writeDefaultNamespace ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-8   文件: StringHeader.java
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
    w.writeStartElement("", name.getLocalPart(), name.getNamespaceURI());
    w.writeDefaultNamespace(name.getNamespaceURI());
    if (mustUnderstand) {
        //Writing the ns declaration conditionally checking in the NSContext breaks XWSS. as readHeader() adds ns declaration,
        // where as writing alonf with the soap envelope does n't add it.
        //Looks like they expect the readHeader() and writeTo() produce the same infoset, Need to understand their usage

        //if(w.getNamespaceContext().getPrefix(soapVersion.nsUri) == null) {
        w.writeNamespace("S", soapVersion.nsUri);
        w.writeAttribute("S", soapVersion.nsUri, MUST_UNDERSTAND, getMustUnderstandLiteral(soapVersion));
        // } else {
        // w.writeAttribute(soapVersion.nsUri,MUST_UNDERSTAND, getMustUnderstandLiteral(soapVersion));
        // }
    }
    w.writeCharacters(value);
    w.writeEndElement();
}
 
源代码2 项目: odata   文件: XMLWriterUtil.java
public static XMLStreamWriter startElement(OutputStream outputStream, String rootName, String typeName,
                                           String context, boolean defaultNameSpace) throws XMLStreamException {
    XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(outputStream, UTF_8.name());
    writer.writeStartElement(METADATA, rootName, ODATA_METADATA_NS);
    if (defaultNameSpace) {
        LOG.debug("Starting {} element with default data namespace", rootName);
        writer.setDefaultNamespace(ODATA_DATA_NS);
        writer.writeDefaultNamespace(ODATA_DATA_NS);
    } else {
        LOG.debug("Starting {} element without default namespaces", rootName);
        writer.writeNamespace(ODATA_DATA, ODATA_DATA_NS);
    }
    writer.writeNamespace(METADATA, ODATA_METADATA_NS);
    writer.writeAttribute(ODATA_METADATA_NS, ODATA_CONTEXT, context);
    if (!PrimitiveType.STRING.getName().equals(typeName)) {
        writer.writeAttribute(ODATA_METADATA_NS, TYPE, typeName);
    }
    return writer;
}
 
源代码3 项目: cloud-odata-java   文件: XmlLinksEntityProducer.java
public void append(final XMLStreamWriter writer, final EntityInfoAggregator entityInfo, final List<Map<String, Object>> data) throws EntityProviderException {
  try {
    writer.writeStartElement(FormatXml.D_LINKS);
    writer.writeDefaultNamespace(Edm.NAMESPACE_D_2007_08);
    if (properties.getInlineCount() != null) {
      writer.writeStartElement(Edm.PREFIX_M, FormatXml.M_COUNT, Edm.NAMESPACE_M_2007_08);
      writer.writeNamespace(Edm.PREFIX_M, Edm.NAMESPACE_M_2007_08);
      writer.writeCharacters(properties.getInlineCount().toString());
      writer.writeEndElement();
    }
    XmlLinkEntityProducer provider = new XmlLinkEntityProducer(properties);
    for (final Map<String, Object> entityData : data) {
      provider.append(writer, entityInfo, entityData, false);
    }
    writer.writeEndElement();
    writer.flush();
  } catch (final XMLStreamException e) {
    throw new EntityProviderException(EntityProviderException.COMMON, e);
  }
}
 
源代码4 项目: hottub   文件: ProblemActionHeader.java
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();
}
 
源代码5 项目: olingo-odata2   文件: AtomFeedProducer.java
public void append(final XMLStreamWriter writer, final EntityInfoAggregator eia,
    final List<Map<String, Object>> data, final boolean isInline) throws EntityProviderException {
  try {
    writer.writeStartElement(FormatXml.ATOM_FEED);
    TombstoneCallback callback = null;
    if (!isInline) {
      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);
      callback = getTombstoneCallback();
      if (callback != null) {
        writer.writeNamespace(TombstoneCallback.PREFIX_TOMBSTONE, TombstoneCallback.NAMESPACE_TOMBSTONE);
      }
    }
    writer.writeAttribute(Edm.PREFIX_XML, Edm.NAMESPACE_XML_1998, FormatXml.XML_BASE, properties.getServiceRoot()
        .toASCIIString());

    // write all atom infos (mandatory and optional)
    appendAtomMandatoryParts(writer, eia);
    appendAtomSelfLink(writer, eia);
    if (properties.getInlineCountType() == InlineCount.ALLPAGES) {
      appendInlineCount(writer, properties.getInlineCount());
    }

    appendEntries(writer, eia, data);

    if (callback != null) {
      appendDeletedEntries(writer, eia, callback);
    }

    if (properties.getNextLink() != null) {
      appendNextLink(writer, properties.getNextLink());
    }

    writer.writeEndElement();
  } catch (XMLStreamException e) {
    throw new EntityProviderProducerException(EntityProviderException.COMMON, e);
  }
}
 
源代码6 项目: openjdk-8   文件: RelatesToHeader.java
@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();
}
 
源代码7 项目: TencentKona-8   文件: ProblemActionHeader.java
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();
}
 
源代码8 项目: woodstox   文件: CompactNsContext.java
@Override
public void outputNamespaceDeclarations(XMLStreamWriter w) throws XMLStreamException
{
    String[] ns = mNamespaces;
    for (int i = mFirstLocalNs, len = mNsLength; i < len; i += 2) {
        String nsURI = ns[i+1];
        String prefix = ns[i];
        if (prefix != null && prefix.length() > 0) {
            w.writeNamespace(prefix, nsURI);
        } else {
            w.writeDefaultNamespace(nsURI);
        }
    }
}
 
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());

  appendTerms(writer, schema.getTerms());

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

  // AnnotationGroups
  appendAnnotationGroups(writer, schema.getAnnotationGroups());

  appendAnnotations(writer, schema);

  writer.writeEndElement();
}
 
源代码10 项目: packagedrone   文件: XmlProfileDataHandler.java
@Override
public void handle ( final DurationEntry entry )
{
    try
    {
        final XMLOutputFactory xml = XMLOutputFactory.newInstance ();

        final Path name = makeNextName ();
        try ( OutputStream stream = new BufferedOutputStream ( Files.newOutputStream ( name, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE ) ) )
        {
            final XMLStreamWriter xsw = xml.createXMLStreamWriter ( stream );

            xsw.writeStartDocument ();
            xsw.writeCharacters ( "\n\n" );
            xsw.writeStartElement ( "trace" );
            xsw.writeDefaultNamespace ( "http://packagedrone.org/profile/trace/v1.0" );

            xsw.writeCharacters ( "\n" );

            dumpEntry ( xsw, entry, 1 );

            xsw.writeEndElement ();
            xsw.writeCharacters ( "\n" ); // end white new line
            xsw.writeEndDocument ();
        }

        if ( !Boolean.getBoolean ( "drone.profile.xml.disableAnnounce" ) )
        {
            System.out.format ( "Wrote profile trace: %s ms - %s -> %s%n", entry.getDuration ().toMillis (), entry.getOperation (), name.toAbsolutePath () );
        }
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to write profile trace", e );
    }
}
 
源代码11 项目: olingo-odata2   文件: AtomFeedSerializer.java
/**
 * This serializes the xml payload feed
 * @param writer
 * @param eia
 * @param data
 * @param isInline
 * @throws EntityProviderException
 */
public void append(final XMLStreamWriter writer, final EntityInfoAggregator eia,
    final EntityCollection data, final boolean isInline) throws EntityProviderException {
  try {
    if (properties.getServiceRoot() == null) {
      throw new EntityProviderProducerException(EntityProviderException.MANDATORY_WRITE_PROPERTY);
    }
    
    writer.writeStartElement(FormatXml.ATOM_FEED);
    if (!isInline) {
      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);
      
    }
    writer.writeAttribute(Edm.PREFIX_XML, Edm.NAMESPACE_XML_1998, FormatXml.XML_BASE, properties.getServiceRoot()
        .toASCIIString());

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

    appendEntries(writer, eia, data);

   

 
    writer.writeEndElement();
  } catch (XMLStreamException e) {
    throw new EntityProviderProducerException(EntityProviderException.COMMON, e);
  }
}
 
源代码12 项目: hottub   文件: RelatesToHeader.java
@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();
}
 
源代码13 项目: openjdk-8   文件: ProblemActionHeader.java
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();
}
 
源代码14 项目: openjdk-8   文件: FaultDetailHeader.java
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();
}
 
源代码15 项目: softwarecave   文件: DefaultNSWriter.java
private void writeBooksElem(XMLStreamWriter writer, List<Book> books) throws XMLStreamException {
    writer.writeStartDocument("utf-8", "1.0");
    writer.writeComment("Describes list of books");
    
    writer.setDefaultNamespace(NS);
    writer.writeStartElement(NS, "books");
    writer.writeDefaultNamespace(NS);
    for (Book book : books)
        writeBookElem(writer, book);
    writer.writeEndElement();

    writer.writeEndDocument();
}
 
源代码16 项目: wildfly-core   文件: CliConfigTestCase.java
private static File createConfigFileWithColors(Boolean enable, int timeout,
        Boolean validate, Boolean outputJSON, Boolean colorOutput, String error,
        String warn, String success, String required, String batch) {
    File f = new File(TestSuiteEnvironment.getTmpDir(), "test-jboss-cli" +
            System.currentTimeMillis() + ".xml");
    f.deleteOnExit();
    String namespace = Namespace.CURRENT.getUriString();
    XMLOutputFactory output = XMLOutputFactory.newInstance();
    try (Writer stream = Files.newBufferedWriter(f.toPath(), StandardCharsets.UTF_8)) {
        XMLStreamWriter writer = output.createXMLStreamWriter(stream);
        writer.writeStartDocument();
        writer.writeStartElement("jboss-cli");
        writer.writeDefaultNamespace(namespace);
        writer.writeStartElement("echo-command");
        writer.writeCharacters(enable.toString());
        writer.writeEndElement(); //echo-command
        if (timeout != 0) {
            writer.writeStartElement("command-timeout");
            writer.writeCharacters("" + timeout);
            writer.writeEndElement(); //command-timeout
        }
        writer.writeStartElement("validate-operation-requests");
        writer.writeCharacters(validate.toString());
        writer.writeEndElement(); //validate-operation-requests

        writer.writeStartElement("output-json");
        writer.writeCharacters(outputJSON.toString());
        writer.writeEndElement(); //output-json

        CliConfigUtils.writeColorConfig(writer, colorOutput, error, warn, success, required, batch);

        writer.writeEndElement(); //jboss-cli
        writer.writeEndDocument();
        writer.flush();
        writer.close();
    } catch (XMLStreamException | IOException ex) {
        fail("Failure creating config file " + ex);
    }
    return f;
}
 
源代码17 项目: openjdk-jdk9   文件: ProblemActionHeader.java
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();
}
 
源代码18 项目: micro-integrator   文件: XMLWriterHelper.java
public void writeResultElement(XMLStreamWriter xmlWriter, String name, ParamValue value,
		QName xsdType, int categoryType, int resultType, ExternalParamCollection params)
		throws XMLStreamException {
       if (xmlWriter == null) {
           return;
       }
	String nsPrefix;
	boolean writeNS;
	switch (resultType) {
	case DBConstants.ResultTypes.XML:			
		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);
	    }
           if (value != null) {
		    this.writeElementValue(xmlWriter, value);
           }
		xmlWriter.writeEndElement();
		break;
	case DBConstants.ResultTypes.RDF:
		switch (categoryType) {
		case DBConstants.DataCategory.VALUE:
			/* <productCode rdf:datatype="http://www.w3.org/2001/XMLSchema#string">S10_1678</productCode> */
			xmlWriter.writeStartElement(this.getNamespace(), name);
			String dataTypeString = xsdType.getNamespaceURI() + "#" + xsdType.getLocalPart();
			xmlWriter.writeAttribute(DBConstants.RDF_NAMESPACE, 
					DBConstants.DBSFields.RDF_DATATYPE, dataTypeString);
			this.writeElementValue(xmlWriter, value);
			xmlWriter.writeEndElement();
			break;
		case DBConstants.DataCategory.REFERENCE:
			/* <productLine rdf:resource="http://productLines.com/Motorcycles/"/> */
			try {
				xmlWriter.writeStartElement(this.getNamespace(), name);
				String evalValue = DBUtils.evaluateString(value.toString(), params);
				xmlWriter.writeAttribute(DBConstants.RDF_NAMESPACE,
						DBConstants.DBSFields.RDF_RESOURCE, evalValue);
				xmlWriter.writeEndElement();
			} catch (DataServiceFault e) {
				throw new XMLStreamException("Error in writing result element using RDF", e);
			}
			break;
		}
	}		
}
 
源代码19 项目: openjdk-jdk9   文件: NamespaceTest.java
private void startDocumentEmptyDefaultNamespace(XMLStreamWriter xmlStreamWriter) throws XMLStreamException {

        xmlStreamWriter.writeStartDocument();
        xmlStreamWriter.writeStartElement("root");
        xmlStreamWriter.writeDefaultNamespace("");
    }
 
源代码20 项目: wildfly-core   文件: CliConfigUtils.java
protected static File createConfigFile(Boolean enable, int timeout,
                                       Boolean validate, Boolean outputJSON, Boolean colorOutput, Boolean outputPaging) {
    File f = new File(TestSuiteEnvironment.getTmpDir(), "test-jboss-cli" +
            System.currentTimeMillis() + ".xml");
    f.deleteOnExit();
    String namespace = Namespace.CURRENT.getUriString();
    XMLOutputFactory output = XMLOutputFactory.newInstance();
    try (Writer stream = Files.newBufferedWriter(f.toPath(), StandardCharsets.UTF_8)) {
        XMLStreamWriter writer = output.createXMLStreamWriter(stream);
        writer.writeStartDocument();
        writer.writeStartElement("jboss-cli");
        writer.writeDefaultNamespace(namespace);
        writer.writeStartElement("echo-command");
        writer.writeCharacters(enable.toString());
        writer.writeEndElement(); //echo-command
        if (timeout != 0) {
            writer.writeStartElement("command-timeout");
            writer.writeCharacters("" + timeout);
            writer.writeEndElement(); //command-timeout
        }
        writer.writeStartElement("validate-operation-requests");
        writer.writeCharacters(validate.toString());
        writer.writeEndElement(); //validate-operation-requests

        writer.writeStartElement("output-json");
        writer.writeCharacters(outputJSON.toString());
        writer.writeEndElement(); //output-json

        writeColorConfig(writer, colorOutput, "", "", "", "", "");

        writer.writeStartElement("output-paging");
        writer.writeCharacters(outputPaging.toString());
        writer.writeEndElement(); //echo-command

        writer.writeEndElement(); //jboss-cli
        writer.writeEndDocument();
        writer.flush();
        writer.close();
    } catch (XMLStreamException | IOException ex) {
        fail("Failure creating config file " + ex);
    }
    return f;
}