本文整理汇总了Java中javax.xml.stream.XMLStreamException类的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamException类的具体用法?Java XMLStreamException怎么用?Java XMLStreamException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XMLStreamException类属于javax.xml.stream包,在下文中一共展示了XMLStreamException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleAttribute
import javax.xml.stream.XMLStreamException; //导入依赖的package包/类
/**
* 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)
);
}
}
示例2: readPayload
import javax.xml.stream.XMLStreamException; //导入依赖的package包/类
@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);
}
}
示例3: reset
import javax.xml.stream.XMLStreamException; //导入依赖的package包/类
/**
* 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);
}
示例4: readChild
import javax.xml.stream.XMLStreamException; //导入依赖的package包/类
/**
* {@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);
}
}
示例5: readAttributes
import javax.xml.stream.XMLStreamException; //导入依赖的package包/类
/**
* {@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);
}
示例6: testDoubleXmlns
import javax.xml.stream.XMLStreamException; //导入依赖的package包/类
@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
}
}
示例7: serializeBody
import javax.xml.stream.XMLStreamException; //导入依赖的package包/类
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;
}
}
}
示例8: findAIObject
import javax.xml.stream.XMLStreamException; //导入依赖的package包/类
/**
* 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;
}
示例9: readSubElements
import javax.xml.stream.XMLStreamException; //导入依赖的package包/类
@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);
}
});
}
示例10: storeDocumentAndChildren
import javax.xml.stream.XMLStreamException; //导入依赖的package包/类
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);
}
示例11: writeStartElement
import javax.xml.stream.XMLStreamException; //导入依赖的package包/类
/**
* 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();
}
示例12: writeBusBreakerTopology
import javax.xml.stream.XMLStreamException; //导入依赖的package包/类
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();
}
示例13: comment
import javax.xml.stream.XMLStreamException; //导入依赖的package包/类
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);
}
}
示例14: writeRootElementAttributes
import javax.xml.stream.XMLStreamException; //导入依赖的package包/类
@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());
}
}
示例15: volgendeEvent
import javax.xml.stream.XMLStreamException; //导入依赖的package包/类
/**
* 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);
}
}