Java Code Examples for javax.xml.stream.XMLStreamException

The following are top voted examples for showing how to use javax.xml.stream.XMLStreamException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: openjdk-jdk10   File: XMLStreamReaderToXMLStreamWriter.java   Source Code and License 6 votes vote down vote up
/**
 * 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)
        );
    }
}
 
Example 2
Project: openjdk-jdk10   File: JAXBMessage.java   Source Code and License 6 votes vote down vote up
@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);
    }
}
 
Example 3
Project: rapidminer   File: XlsxSheetContentParser.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 4
Project: freecol   File: Settlement.java   Source Code and License 6 votes vote down vote up
/**
 * {@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);
    }
}
 
Example 5
Project: FreeCol   File: WorkerWish.java   Source Code and License 6 votes vote down vote up
/**
 * {@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);
}
 
Example 6
Project: openjdk-jdk10   File: DoubleXmlnsTest.java   Source Code and License 6 votes vote down vote up
@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
    }
}
 
Example 7
Project: openjdk-jdk10   File: AnyTypeBeanInfo.java   Source Code and License 6 votes vote down vote up
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;
        }
    }
}
 
Example 8
Project: FreeCol   File: FreeColXMLReader.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 9
Project: powsybl-core   File: LineXml.java   Source Code and License 6 votes vote down vote up
@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);
        }
    });
}
 
Example 10
Project: OpenJSharp   File: StreamReaderBufferCreator.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 11
Project: OpenJSharp   File: XMLDOMWriterImpl.java   Source Code and License 6 votes vote down vote up
/**
 * 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();
}
 
Example 12
Project: powsybl-core   File: VoltageLevelXml.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 13
Project: OpenJSharp   File: SAX2StAXEventWriter.java   Source Code and License 6 votes vote down vote up
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);

    }

}
 
Example 14
Project: powsybl-core   File: ThreeWindingsTransformerXml.java   Source Code and License 6 votes vote down vote up
@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());
    }
}
 
Example 15
Project: OperatieBRP   File: ParserContext.java   Source Code and License 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 16
Project: FreeCol   File: IntegerOption.java   Source Code and License 5 votes vote down vote up
/**
 * {@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);
}
 
Example 17
Project: Excel2XML   File: E2xCmdline.java   Source Code and License 5 votes vote down vote up
/**
 * 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();
	}

}
 
Example 18
Project: DocIT   File: Cut.java   Source Code and License 5 votes vote down vote up
@Override
public void endElement(String uri, String name, String qName) {
	isSalary = false;
	try {
		writer.writeEndElement();
	} catch (XMLStreamException e) {
		e.printStackTrace();
	}
}
 
Example 19
Project: rapidminer   File: XlsxResultSet.java   Source Code and License 5 votes vote down vote up
@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());
	}
}
 
Example 20
Project: OpenJSharp   File: StreamSOAPCodec.java   Source Code and License 5 votes vote down vote up
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);
}
 
Example 21
Project: InComb   File: AXMLParser.java   Source Code and License 5 votes vote down vote up
/**
 * 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;
}
 
Example 22
Project: freecol   File: FreeColXMLReader.java   Source Code and License 5 votes vote down vote up
/**
 * 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;
}
 
Example 23
Project: freecol   File: Tile.java   Source Code and License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void readChildren(FreeColXMLReader xr) throws XMLStreamException {
    // Clear containers.
    settlement = null;

    super.readChildren(xr);
}
 
Example 24
Project: FreeCol   File: FreeColModFile.java   Source Code and License 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 25
Project: freecol   File: PlunderType.java   Source Code and License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void readAttributes(FreeColXMLReader xr) throws XMLStreamException {
    super.readAttributes(xr);

    this.plunder = new RandomRange(xr);
}
 
Example 26
Project: OpenJSharp   File: StAXEvent2SAX.java   Source Code and License 5 votes vote down vote up
private void handleCharacters(Characters event) throws XMLStreamException {
    try {
        _sax.characters(
            event.getData().toCharArray(),
            0,
            event.getData().length());
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
 
Example 27
Project: Equella   File: XMLStreamer.java   Source Code and License 5 votes vote down vote up
public void writeData(String data)
{
	try
	{
		xml.writeCharacters(data);
	}
	catch( XMLStreamException ex )
	{
		throw new RuntimeException(ex);
	}
}
 
Example 28
Project: OpenJSharp   File: XMLDOMWriterImpl.java   Source Code and License 5 votes vote down vote up
/**
 * 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();
}
 
Example 29
Project: freecol   File: TransportMission.java   Source Code and License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void readChildren(FreeColXMLReader xr) throws XMLStreamException {
    // Clear containers.
    tClear();

    super.readChildren(xr);
}
 
Example 30
Project: openjdk-jdk10   File: SaajStaxWriter.java   Source Code and License 5 votes vote down vote up
@Override
public void writeCharacters(final String text) throws XMLStreamException {
    currentElement = deferredElement.flushTo(currentElement);
    try {
        currentElement.addTextNode(text);
    } catch (SOAPException e) {
        throw new XMLStreamException(e);
    }
}
 
Example 31
Project: openjdk-jdk10   File: SaajStaxWriterEx.java   Source Code and License 5 votes vote down vote up
@Override
public void writeStartElement(String prefix, String ln, String ns) throws XMLStreamException {
    if (xopNS.equals(ns) && Include.equals(ln)) {
        state = State.xopInclude;
        return;
    } else {
        super.writeStartElement(prefix, ln, ns);
    }
}
 
Example 32
Project: powsybl-core   File: TieLineXml.java   Source Code and License 5 votes vote down vote up
@Override
protected void writeRootElementAttributes(TieLine tl, Network n, XmlWriterContext context) throws XMLStreamException {
    context.getWriter().writeAttribute("ucteXnodeCode", tl.getUcteXnodeCode());
    writeNodeOrBus(1, tl.getTerminal1(), context);
    writeNodeOrBus(2, tl.getTerminal2(), context);
    if (context.getOptions().isWithBranchSV()) {
        writePQ(1, tl.getTerminal1(), context.getWriter());
        writePQ(2, tl.getTerminal2(), context.getWriter());
    }
    writeHalf(tl.getHalf1(), context, 1);
    writeHalf(tl.getHalf2(), context, 2);
}
 
Example 33
Project: FreeCol   File: Colony.java   Source Code and License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void readChild(FreeColXMLReader xr) throws XMLStreamException {
    final Specification spec = getSpecification();
    final Game game = getGame();
    final String tag = xr.getLocalName();

    if (BUILD_QUEUE_TAG.equals(tag)) {
        BuildableType bt = xr.getType(spec, ID_ATTRIBUTE_TAG,
                BuildableType.class, (BuildableType)null);
        if (bt != null) buildQueue.add(bt);
        xr.closeTag(BUILD_QUEUE_TAG);

    } else if (POPULATION_QUEUE_TAG.equals(xr.getLocalName())) {
        UnitType ut = xr.getType(spec, ID_ATTRIBUTE_TAG,
                UnitType.class, (UnitType)null);
        if (ut != null) populationQueue.add(ut);
        xr.closeTag(POPULATION_QUEUE_TAG);

    } else if (Building.TAG.equals(tag)) {
        addBuilding(xr.readFreeColObject(game, Building.class));

    } else if (ColonyTile.TAG.equals(tag)) {
        addColonyTile(xr.readFreeColObject(game, ColonyTile.class));

    } else if (ExportData.TAG.equals(tag)) {
        ExportData data = new ExportData(xr);
        setExportData(data);

    } else {
        super.readChild(xr);
    }
}
 
Example 34
Project: openjdk-jdk10   File: ExceptionTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testException() {

    final String EXPECTED_OUTPUT = "Test XMLStreamException";
    try {
        Exception ex = new IOException("Test XMLStreamException");
        throw new XMLStreamException(ex);
    } catch (XMLStreamException e) {
        Assert.assertTrue(e.getMessage().contains(EXPECTED_OUTPUT), "XMLStreamException does not contain the message " + "of the wrapped exception");
    }
}
 
Example 35
Project: openjdk-jdk10   File: TransformerTestTemplate.java   Source Code and License 5 votes vote down vote up
public StAXSource getStAXSource(XMLInputFactory xif)
    throws XMLStreamException
{
    return new StAXSource(
        xif.createXMLStreamReader(new StringReader(sourceXml))
    );
}
 
Example 36
Project: OpenJSharp   File: XMLSerializer.java   Source Code and License 5 votes vote down vote up
/**
 * Switches to the "marshal child texts/elements" mode.
 * This method has to be called after the 1st pass is completed.
 */
public void endAttributes() throws SAXException, IOException, XMLStreamException  {
    if(!seenRoot) {
        seenRoot = true;
        if(schemaLocation!=null || noNsSchemaLocation!=null) {
            int p = nsContext.getPrefixIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE);
            if(schemaLocation!=null)
                out.attribute(p,"schemaLocation",schemaLocation);
            if(noNsSchemaLocation!=null)
                out.attribute(p,"noNamespaceSchemaLocation",noNsSchemaLocation);
        }
    }

    out.endStartTag();
}
 
Example 37
Project: openjdk-jdk10   File: InlineBinaryTransducer.java   Source Code and License 5 votes vote down vote up
@Override
public void writeText(XMLSerializer w, V o, String fieldName) throws IOException, SAXException, XMLStreamException, AccessorException {
    boolean old = w.setInlineBinaryFlag(true);
    try {
        core.writeText(w,o,fieldName);
    } finally {
        w.setInlineBinaryFlag(old);
    }
}
 
Example 38
Project: FreeCol   File: DefendSettlementMission.java   Source Code and License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void writeAttributes(FreeColXMLWriter xw) throws XMLStreamException {
    super.writeAttributes(xw);

    if (target != null) {
        xw.writeAttribute(SETTLEMENT_TAG, target.getId());
    }
}
 
Example 39
Project: freecol   File: UnitLocation.java   Source Code and License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void readChildren(FreeColXMLReader xr) throws XMLStreamException {
    // Clear containers.
    clearUnitList();

    super.readChildren(xr);
}
 
Example 40
Project: OpenJSharp   File: StreamReaderBufferProcessor.java   Source Code and License 5 votes vote down vote up
public final String getElementText(boolean startElementRead) throws XMLStreamException {
    if (!startElementRead) {
        throw new XMLStreamException("");
    }

    int eventType = getEventType();
    StringBuilder content = new StringBuilder();
    while(eventType != END_ELEMENT ) {
        if(eventType == CHARACTERS
                || eventType == CDATA
                || eventType == SPACE
                || eventType == ENTITY_REFERENCE) {
            content.append(getText());
        } else if(eventType == PROCESSING_INSTRUCTION
                || eventType == COMMENT) {
            // skipping
        } else if(eventType == END_DOCUMENT) {
            throw new XMLStreamException("");
        } else if(eventType == START_ELEMENT) {
            throw new XMLStreamException("");
        } else {
            throw new XMLStreamException("");
        }
        eventType = next();
    }
    return content.toString();
}