/**
* Writes out the {@code i}-th attribute of the current element.
*
* <p>
* Used from {@link #handleStartElement()}.
*/
protected void handleAttribute(int i) throws XMLStreamException {
String nsUri = in.getAttributeNamespace(i);
String prefix = in.getAttributePrefix(i);
if (fixNull(nsUri).equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
//Its a namespace decl, ignore as it is already written.
return;
}
if(nsUri==null || prefix == null || prefix.equals("")) {
out.writeAttribute(
in.getAttributeLocalName(i),
in.getAttributeValue(i)
);
} else {
out.writeAttribute(
prefix,
nsUri,
in.getAttributeLocalName(i),
in.getAttributeValue(i)
);
}
}
java类javax.xml.stream.XMLStreamException的实例源码
XMLStreamReaderToXMLStreamWriter.java 文件源码
项目:openjdk-jdk10
阅读 23
收藏 0
点赞 0
评论 0
JAXBMessage.java 文件源码
项目:openjdk-jdk10
阅读 29
收藏 0
点赞 0
评论 0
@Override
public XMLStreamReader readPayload() throws XMLStreamException {
try {
if(infoset==null) {
if (rawContext != null) {
XMLStreamBufferResult sbr = new XMLStreamBufferResult();
Marshaller m = rawContext.createMarshaller();
m.setProperty("jaxb.fragment", Boolean.TRUE);
m.marshal(jaxbObject, sbr);
infoset = sbr.getXMLStreamBuffer();
} else {
MutableXMLStreamBuffer buffer = new MutableXMLStreamBuffer();
writePayloadTo(buffer.createFromXMLStreamWriter());
infoset = buffer;
}
}
XMLStreamReader reader = infoset.readAsXMLStreamReader();
if(reader.getEventType()== START_DOCUMENT)
XMLStreamReaderUtil.nextElementContent(reader);
return reader;
} catch (JAXBException e) {
// bug 6449684, spec 4.3.4
throw new WebServiceException(e);
}
}
XlsxSheetContentParser.java 文件源码
项目:rapidminer
阅读 21
收藏 0
点赞 0
评论 0
/**
* Closes the current open {@link XMLStreamReader} and creates a new one which starts the
* reading process at the first row. It is assumed the the XLSX content and operator
* configuration remain the same.
*
* @param factory
* the {@link XMLInputFactory} that should be used to open the
* {@link XMLStreamReader}.
*
* @throws IOException
* if an I/O error has occurred
* @throws XMLStreamException
* if there are errors freeing associated XML reader resources or creating a new XML
* reader
*/
void reset(XMLInputFactory xmlFactory) throws IOException, XMLStreamException {
// close open file and reader object
close();
// create new file and stream reader objects
xlsxZipFile = new ZipFile(xlsxFile);
ZipEntry workbookZipEntry = xlsxZipFile.getEntry(workbookZipEntryPath);
if (workbookZipEntry == null) {
throw new FileNotFoundException(
"XLSX file is malformed. Reason: Selected workbook is missing in XLSX file. Path: "
+ workbookZipEntryPath);
}
InputStream inputStream = xlsxZipFile.getInputStream(workbookZipEntry);
reader = xmlFactory.createXMLStreamReader(new InputStreamReader(inputStream, encoding));
// reset other variables
currentRowIndex = -1;
parsedRowIndex = -1;
currentRowContent = null;
nextRowWithContent = null;
hasMoreContent = true;
Arrays.fill(emptyColumn, true);
}
Settlement.java 文件源码
项目:freecol
阅读 21
收藏 0
点赞 0
评论 0
/**
* {@inheritDoc}
*/
@Override
protected void readChild(FreeColXMLReader xr) throws XMLStreamException {
final Specification spec = getSpecification();
final String tag = xr.getLocalName();
if (Ability.TAG.equals(tag)) {
Ability ability = new Ability(xr, spec);
if (ability.isIndependent()) addAbility(ability);
} else if (Modifier.TAG.equals(tag)) {
Modifier modifier = new Modifier(xr, spec);
if (modifier.isIndependent()) addModifier(modifier);
} else {
super.readChild(xr);
}
}
WorkerWish.java 文件源码
项目:FreeCol
阅读 26
收藏 0
点赞 0
评论 0
/**
* {@inheritDoc}
*/
@Override
protected void readAttributes(FreeColXMLReader xr) throws XMLStreamException {
super.readAttributes(xr);
final AIMain aiMain = getAIMain();
final Specification spec = getSpecification();
// Delegated from Wish
transportable = (xr.hasAttribute(TRANSPORTABLE_TAG))
? xr.makeAIObject(aiMain, TRANSPORTABLE_TAG,
AIUnit.class, (AIUnit)null, true)
: null;
unitType = xr.getType(spec, UNIT_TYPE_TAG,
UnitType.class, (UnitType)null);
expertNeeded = xr.getAttribute(EXPERT_NEEDED_TAG, false);
}
DoubleXmlnsTest.java 文件源码
项目:openjdk-jdk10
阅读 23
收藏 0
点赞 0
评论 0
@Test
public void testDoubleXmlns() throws Exception {
final String INVALID_XML = "<foo xmlns:xml='http://www.w3.org/XML/1998/namespace' xmlns:xml='http://www.w3.org/XML/1998/namespace' ></foo>";
try {
XMLStreamReader xsr = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(INVALID_XML));
while (xsr.hasNext()) {
xsr.next();
}
Assert.fail("Wellformedness error expected :" + INVALID_XML);
} catch (XMLStreamException e) {
; // this is expected
}
}
AnyTypeBeanInfo.java 文件源码
项目:openjdk-jdk10
阅读 24
收藏 0
点赞 0
评论 0
public void serializeBody(Object element, XMLSerializer target) throws SAXException, IOException, XMLStreamException {
NodeList childNodes = ((Element)element).getChildNodes();
int len = childNodes.getLength();
for( int i=0; i<len; i++ ) {
Node child = childNodes.item(i);
switch(child.getNodeType()) {
case Node.CDATA_SECTION_NODE:
case Node.TEXT_NODE:
target.text(child.getNodeValue(),null);
break;
case Node.ELEMENT_NODE:
target.writeDom((Element)child,domHandler,null,null);
break;
}
}
}
FreeColXMLReader.java 文件源码
项目:FreeCol
阅读 27
收藏 0
点赞 0
评论 0
/**
* Find a FreeCol AI object from an attribute in a stream.
*
* @param <T> The actual return type.
* @param aiMain The {@code AIMain} that contains the object.
* @param attributeName The attribute name.
* @param returnClass The {@code AIObject} type to expect.
* @param defaultValue The default value.
* @param required If true a null result should throw an exception.
* @exception XMLStreamException if there is problem reading the stream.
* @return The {@code AIObject} found, or the default value if not.
*/
public <T extends AIObject> T findAIObject(AIMain aiMain,
String attributeName, Class<T> returnClass, T defaultValue,
boolean required) throws XMLStreamException {
T ret = getAttribute(aiMain, attributeName, returnClass, (T)null);
if (ret == (T)null) {
if (required) {
throw new XMLStreamException("Missing " + attributeName
+ " for " + returnClass.getName() + ": " + currentTag());
} else {
ret = defaultValue;
}
}
return ret;
}
LineXml.java 文件源码
项目:powsybl-core
阅读 21
收藏 0
点赞 0
评论 0
@Override
protected void readSubElements(Line l, XmlReaderContext context) throws XMLStreamException {
readUntilEndRootElement(context.getReader(), () -> {
switch (context.getReader().getLocalName()) {
case "currentLimits1":
readCurrentLimits(1, l::newCurrentLimits1, context.getReader());
break;
case "currentLimits2":
readCurrentLimits(2, l::newCurrentLimits2, context.getReader());
break;
default:
super.readSubElements(l, context);
}
});
}
StreamReaderBufferCreator.java 文件源码
项目:OpenJSharp
阅读 22
收藏 0
点赞 0
评论 0
private void storeDocumentAndChildren(XMLStreamReader reader) throws XMLStreamException {
storeStructure(T_DOCUMENT);
_eventType = reader.next();
while (_eventType != XMLStreamReader.END_DOCUMENT) {
switch (_eventType) {
case XMLStreamReader.START_ELEMENT:
storeElementAndChildren(reader);
continue;
case XMLStreamReader.COMMENT:
storeComment(reader);
break;
case XMLStreamReader.PROCESSING_INSTRUCTION:
storeProcessingInstruction(reader);
break;
}
_eventType = reader.next();
}
storeStructure(T_END);
}
XMLDOMWriterImpl.java 文件源码
项目:OpenJSharp
阅读 24
收藏 0
点赞 0
评论 0
/**
* creates a DOM Element and appends it to the current element in the tree.
* @param localName {@inheritDoc}
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
*/
public void writeStartElement(String localName) throws XMLStreamException {
if(ownerDoc != null){
Element element = ownerDoc.createElement(localName);
if(currentNode!=null){
currentNode.appendChild(element);
}else{
ownerDoc.appendChild(element);
}
currentNode = element;
}
if(needContextPop[depth]){
namespaceContext.pushContext();
}
incDepth();
}
VoltageLevelXml.java 文件源码
项目:powsybl-core
阅读 22
收藏 0
点赞 0
评论 0
private void writeBusBreakerTopology(VoltageLevel vl, XmlWriterContext context) throws XMLStreamException {
context.getWriter().writeStartElement(IIDM_URI, BUS_BREAKER_TOPOLOGY_ELEMENT_NAME);
for (Bus b : vl.getBusBreakerView().getBuses()) {
if (!context.getFilter().test(b)) {
continue;
}
BusXml.INSTANCE.write(b, null, context);
}
for (Switch sw : vl.getBusBreakerView().getSwitches()) {
Bus b1 = vl.getBusBreakerView().getBus1(context.getAnonymizer().anonymizeString(sw.getId()));
Bus b2 = vl.getBusBreakerView().getBus2(context.getAnonymizer().anonymizeString(sw.getId()));
if (!context.getFilter().test(b1) || !context.getFilter().test(b2)) {
continue;
}
BusBreakerViewSwitchXml.INSTANCE.write(sw, vl, context);
}
context.getWriter().writeEndElement();
}
SAX2StAXEventWriter.java 文件源码
项目:OpenJSharp
阅读 23
收藏 0
点赞 0
评论 0
public void comment(char[] ch, int start, int length) throws SAXException {
if (needToCallStartDocument) {
// Drat. We were trying to postpone this until the first element so that we could get
// the locator, but we can't output a comment before the start document, so we're just
// going to have to do without the locator if it hasn't been set yet.
writeStartDocument();
}
super.comment(ch, start, length);
eventFactory.setLocation(getCurrentLocation());
try {
writer.add(eventFactory.createComment(new String(ch, start,
length)));
} catch (XMLStreamException e) {
throw new SAXException(e);
}
}
ThreeWindingsTransformerXml.java 文件源码
项目:powsybl-core
阅读 21
收藏 0
点赞 0
评论 0
@Override
protected void writeRootElementAttributes(ThreeWindingsTransformer twt, Substation s, XmlWriterContext context) throws XMLStreamException {
XmlUtil.writeFloat("r1", twt.getLeg1().getR(), context.getWriter());
XmlUtil.writeFloat("x1", twt.getLeg1().getX(), context.getWriter());
XmlUtil.writeFloat("g1", twt.getLeg1().getG(), context.getWriter());
XmlUtil.writeFloat("b1", twt.getLeg1().getB(), context.getWriter());
XmlUtil.writeFloat("ratedU1", twt.getLeg1().getRatedU(), context.getWriter());
XmlUtil.writeFloat("r2", twt.getLeg2().getR(), context.getWriter());
XmlUtil.writeFloat("x2", twt.getLeg2().getX(), context.getWriter());
XmlUtil.writeFloat("ratedU2", twt.getLeg2().getRatedU(), context.getWriter());
XmlUtil.writeFloat("r3", twt.getLeg3().getR(), context.getWriter());
XmlUtil.writeFloat("x3", twt.getLeg3().getX(), context.getWriter());
XmlUtil.writeFloat("ratedU3", twt.getLeg3().getRatedU(), context.getWriter());
writeNodeOrBus(1, twt.getLeg1().getTerminal(), context);
writeNodeOrBus(2, twt.getLeg2().getTerminal(), context);
writeNodeOrBus(3, twt.getLeg3().getTerminal(), context);
if (context.getOptions().isWithBranchSV()) {
writePQ(1, twt.getLeg1().getTerminal(), context.getWriter());
writePQ(2, twt.getLeg2().getTerminal(), context.getWriter());
writePQ(3, twt.getLeg3().getTerminal(), context.getWriter());
}
}
ParserContext.java 文件源码
项目:OperatieBRP
阅读 28
收藏 0
点赞 0
评论 0
/**
* Het volgende event dat verwerkt moet worden.
*
* @return het volgende event
* @see javax.xml.stream.events.XMLEvent
* @throws ParseException als het verwerken van het XML document fout gaat
*/
public int volgendeEvent() throws ParseException {
try {
return reader.next();
} catch (XMLStreamException e) {
throw new ParseException(FOUTMELDING, e);
}
}
IntegerOption.java 文件源码
项目:FreeCol
阅读 28
收藏 0
点赞 0
评论 0
/**
* {@inheritDoc}
*/
@Override
protected void readAttributes(FreeColXMLReader xr) throws XMLStreamException {
super.readAttributes(xr);
maximumValue = xr.getAttribute(MAXIMUM_VALUE_TAG, Integer.MAX_VALUE);
minimumValue = xr.getAttribute(MINIMUM_VALUE_TAG, Integer.MIN_VALUE);
value = limitValue(this.value);
}
E2xCmdline.java 文件源码
项目:Excel2XML
阅读 23
收藏 0
点赞 0
评论 0
/**
* Writes out an XML cell based on coordinates and provided value
*
* @param row
* the row index of the cell
* @param col
* the column index
* @param cellValue
* value of the cell, can be null for an empty cell
* @param out
* the XML output stream
* @param columns
* the Map with column titles
*/
private void writeAnyCell(final int row, final int col, final String cellValue, final XMLStreamWriter out,
final Map<String, String> columns) {
try {
out.writeStartElement("cell");
String colNum = String.valueOf(col);
out.writeAttribute("row", String.valueOf(row));
out.writeAttribute("col", colNum);
if (columns.containsKey(colNum)) {
out.writeAttribute("title", columns.get(colNum));
}
if (cellValue != null) {
if (cellValue.contains("<") || cellValue.contains(">")) {
out.writeCData(cellValue);
} else {
out.writeCharacters(cellValue);
}
} else {
out.writeAttribute("empty", "true");
}
out.writeEndElement();
} catch (XMLStreamException e) {
e.printStackTrace();
}
}
Cut.java 文件源码
项目:DocIT
阅读 23
收藏 0
点赞 0
评论 0
@Override
public void endElement(String uri, String name, String qName) {
isSalary = false;
try {
writer.writeEndElement();
} catch (XMLStreamException e) {
e.printStackTrace();
}
}
XlsxResultSet.java 文件源码
项目:rapidminer
阅读 24
收藏 0
点赞 0
评论 0
@Override
public void next(ProgressListener listener) throws OperatorException {
try {
worksheetParser.next(readMode);
} catch (XMLStreamException | ParseException e) {
throw new UserError(null, e, 321, configuration.getFile(), e.getMessage());
}
if (listener != null) {
listener.setCompleted(getCurrentRow());
}
}
StreamSOAPCodec.java 文件源码
项目:OpenJSharp
阅读 21
收藏 0
点赞 0
评论 0
public ContentType encode(Packet packet, OutputStream out) {
if (packet.getMessage() != null) {
String encoding = getPacketEncoding(packet);
packet.invocationProperties.remove(DECODED_MESSAGE_CHARSET);
XMLStreamWriter writer = XMLStreamWriterFactory.create(out, encoding);
try {
packet.getMessage().writeTo(writer);
writer.flush();
} catch (XMLStreamException e) {
throw new WebServiceException(e);
}
XMLStreamWriterFactory.recycle(writer);
}
return getContentType(packet);
}
AXMLParser.java 文件源码
项目:InComb
阅读 30
收藏 0
点赞 0
评论 0
/**
* Reads the data from the {@link XMLEvent} and returns it. CData
* will be handled special.
* @param event {@link XMLEvent}
* @param eventReader Reader for Reading {@link XMLEvent}
* @return Character data from element
* @throws XMLStreamException
*/
private String getCharacterData(XMLEvent event, final XMLEventReader eventReader) throws XMLStreamException {
String result = "";
event = eventReader.nextEvent();
if (event instanceof Characters) {
result = event.asCharacters().getData();
}
return result;
}
FreeColXMLReader.java 文件源码
项目:freecol
阅读 26
收藏 0
点赞 0
评论 0
/**
* Seek to an identifier in this stream.
*
* @param id The identifier to find.
* @return This {@code FreeColXMLReader} positioned such that the
* required identifier is current, or null on error or if not found.
* @exception XMLStreamException if a problem was encountered
* during parsing.
*/
public FreeColXMLReader seek(String id) throws XMLStreamException {
nextTag();
for (int type = getEventType(); type != XMLEvent.END_DOCUMENT;
type = getEventType()) {
if (type == XMLEvent.START_ELEMENT
&& id.equals(readId())) return this;
nextTag();
}
return null;
}
Tile.java 文件源码
项目:freecol
阅读 24
收藏 0
点赞 0
评论 0
/**
* {@inheritDoc}
*/
@Override
protected void readChildren(FreeColXMLReader xr) throws XMLStreamException {
// Clear containers.
settlement = null;
super.readChildren(xr);
}
FreeColModFile.java 文件源码
项目:FreeCol
阅读 23
收藏 0
点赞 0
评论 0
/**
* Reads a file object representing this mod.
*
* @exception IOException if thrown while reading the "mod.xml" file.
*/
protected void readModDescriptor() throws IOException {
try (
FreeColXMLReader xr
= new FreeColXMLReader(getModDescriptorInputStream());
) {
xr.nextTag();
id = xr.readId();
parent = xr.getAttribute("parent", (String)null);
} catch (XMLStreamException xse) {
throw new IOException(xse);
}
}
PlunderType.java 文件源码
项目:freecol
阅读 24
收藏 0
点赞 0
评论 0
/**
* {@inheritDoc}
*/
@Override
protected void readAttributes(FreeColXMLReader xr) throws XMLStreamException {
super.readAttributes(xr);
this.plunder = new RandomRange(xr);
}
StAXEvent2SAX.java 文件源码
项目:OpenJSharp
阅读 27
收藏 0
点赞 0
评论 0
private void handleCharacters(Characters event) throws XMLStreamException {
try {
_sax.characters(
event.getData().toCharArray(),
0,
event.getData().length());
} catch (SAXException e) {
throw new XMLStreamException(e);
}
}
XMLStreamer.java 文件源码
项目:Equella
阅读 26
收藏 0
点赞 0
评论 0
public void writeData(String data)
{
try
{
xml.writeCharacters(data);
}
catch( XMLStreamException ex )
{
throw new RuntimeException(ex);
}
}
XMLDOMWriterImpl.java 文件源码
项目:OpenJSharp
阅读 27
收藏 0
点赞 0
评论 0
/**
* creates a DOM Element and appends it to the current element in the tree.
* @param namespaceURI {@inheritDoc}
* @param localName {@inheritDoc}
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
*/
public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
if(ownerDoc != null){
String qualifiedName = null;
String prefix = null;
if(namespaceURI == null ){
throw new XMLStreamException("NamespaceURI cannot be null");
}
if(localName == null){
throw new XMLStreamException("Local name cannot be null");
}
if(namespaceContext != null){
prefix = namespaceContext.getPrefix(namespaceURI);
}
if(prefix == null){
throw new XMLStreamException("Namespace URI "+namespaceURI +
"is not bound to any prefix" );
}
if("".equals(prefix)){
qualifiedName = localName;
}else{
qualifiedName = getQName(prefix,localName);
}
Element element = ownerDoc.createElementNS(namespaceURI, qualifiedName);
if(currentNode!=null){
currentNode.appendChild(element);
}else{
ownerDoc.appendChild(element);
}
currentNode = element;
}
if(needContextPop[depth]){
namespaceContext.pushContext();
}
incDepth();
}
TransportMission.java 文件源码
项目:freecol
阅读 24
收藏 0
点赞 0
评论 0
/**
* {@inheritDoc}
*/
@Override
protected void readChildren(FreeColXMLReader xr) throws XMLStreamException {
// Clear containers.
tClear();
super.readChildren(xr);
}
SaajStaxWriter.java 文件源码
项目:openjdk-jdk10
阅读 21
收藏 0
点赞 0
评论 0
@Override
public void writeCharacters(final String text) throws XMLStreamException {
currentElement = deferredElement.flushTo(currentElement);
try {
currentElement.addTextNode(text);
} catch (SOAPException e) {
throw new XMLStreamException(e);
}
}