當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLStreamException類代碼示例

本文整理匯總了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)
        );
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:XMLStreamReaderToXMLStreamWriter.java

示例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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:JAXBMessage.java

示例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);
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:40,代碼來源:XlsxSheetContentParser.java

示例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);
    }
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:21,代碼來源:Settlement.java

示例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);
}
 
開發者ID:wintertime,項目名稱:FreeCol,代碼行數:22,代碼來源:WorkerWish.java

示例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
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:DoubleXmlnsTest.java

示例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;
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:AnyTypeBeanInfo.java

示例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;
}
 
開發者ID:wintertime,項目名稱:FreeCol,代碼行數:28,代碼來源:FreeColXMLReader.java

示例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);
        }
    });
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:18,代碼來源:LineXml.java

示例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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:22,代碼來源:StreamReaderBufferCreator.java

示例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();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:XMLDOMWriterImpl.java

示例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();
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:19,代碼來源:VoltageLevelXml.java

示例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);

    }

}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:24,代碼來源:SAX2StAXEventWriter.java

示例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());
    }
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:23,代碼來源:ThreeWindingsTransformerXml.java

示例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);
    }
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:15,代碼來源:ParserContext.java


注:本文中的javax.xml.stream.XMLStreamException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。