Example usage for javax.xml.stream XMLStreamException XMLStreamException

List of usage examples for javax.xml.stream XMLStreamException XMLStreamException

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamException XMLStreamException.

Prototype

public XMLStreamException(Throwable th) 

Source Link

Document

Construct an exception with the assocated exception

Usage

From source file:org.betaconceptframework.astroboa.model.jaxb.writer.JSONXmlStreamWriter.java

@Override
public void writeCData(String data) throws XMLStreamException {
    try {//  w  ww . ja  v a2  s  . co  m

        if (!objectQueue.isEmpty()) {
            objectQueue.peek().addValue(data);
        } else {
            logger.warn("Cannot find Json Object to write cdata");
        }
    } catch (Exception e) {
        throw new XMLStreamException(e);
    }
}

From source file:org.betaconceptframework.astroboa.model.jaxb.writer.JSONXmlStreamWriter.java

@Override
public void writeCharacters(String text) throws XMLStreamException {

    try {//w w  w .j a  v a2 s.  co  m

        if (!objectQueue.isEmpty()) {
            objectQueue.peek().addValue(text);
        } else {
            logger.warn("Cannot find Json Object to write characters {}", text);
        }
    } catch (Exception e) {
        throw new XMLStreamException(e);
    }

}

From source file:org.betaconceptframework.astroboa.model.jaxb.writer.JSONXmlStreamWriter.java

@Override
public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {

    try {//from  w  w  w .  java  2  s .c  o m

        writeCharacters(new String(text, start, len));

    } catch (Exception e) {
        throw new XMLStreamException(e);
    }
}

From source file:org.betaconceptframework.astroboa.model.jaxb.writer.JSONXmlStreamWriter.java

@Override
public void writeEmptyElement(String localName) throws XMLStreamException {

    try {//  w ww .  ja  v  a2  s .  c o m

        if (!objectQueue.isEmpty()) {
            objectQueue.peek().addChild(localName, new NullJsonObject(localName));
        } else {
            logger.warn("Cannot find Json Object to write empty element {}", localName);
        }

    } catch (Exception e) {
        throw new XMLStreamException(e);
    }
}

From source file:org.betaconceptframework.astroboa.model.jaxb.writer.JSONXmlStreamWriter.java

@Override
public void writeEndDocument() throws XMLStreamException {

    try {/*from   ww w .j ava 2s  .co  m*/

        if (objectQueue.isEmpty()) {
            throw new XMLStreamException("Could not find root JsonObject, queue is empty");
        } else {

            //Get last element in queue and export
            objectQueue.peekLast().toJson(!stripRoot);
        }

        //Free resources
        objectQueue.clear();
    } catch (Exception e) {
        throw new XMLStreamException(e);
    }

}

From source file:org.betaconceptframework.astroboa.model.jaxb.writer.JSONXmlStreamWriter.java

@Override
public void writeEndElement() throws XMLStreamException {
    try {//from w  w w . ja va  2s . c o  m

        //Do not remove the first object in the queue
        //which is the root object
        if (objectQueue.size() > 1) {
            objectQueue.pop();
        }

    } catch (Exception e) {
        throw new XMLStreamException(e);
    }

}

From source file:org.betaconceptframework.astroboa.model.jaxb.writer.JSONXmlStreamWriter.java

@Override
public void writeStartDocument() throws XMLStreamException {

    try {/*from  w  w w  .jav a 2  s  . co m*/

        if (!objectQueue.isEmpty()) {
            objectQueue.clear();
        }

        //At this point we do not know the root name
        objectQueue.push(new JsonObject(null));

    } catch (Exception e) {
        throw new XMLStreamException(e);
    }
}

From source file:org.betaconceptframework.astroboa.model.jaxb.writer.JSONXmlStreamWriter.java

@Override
public void writeStartElement(String localName) throws XMLStreamException {

    try {//from   ww  w .ja  v a2s.  co m

        if (objectQueue.size() == 1 && objectQueue.peekFirst().name == null) {
            //This is the root object. Append its name
            objectQueue.peekFirst().name = localName;
        } else {
            JsonObject jsonObject = new JsonObject(localName);

            if (!objectQueue.isEmpty()) {
                objectQueue.peek().addChild(localName, jsonObject);
            }

            objectQueue.push(jsonObject);
        }

    } catch (Exception e) {
        throw new XMLStreamException(e);
    }
}

From source file:org.callimachusproject.behaviours.ZipArchiveSupport.java

public XMLEventReader createAtomFeedFromArchive(final String id, final String entryPattern) throws IOException {
    final FileObject file = this;
    final XMLEventFactory ef = XMLEventFactory.newInstance();
    final byte[] buf = new byte[1024];
    final ZipArchiveInputStream zip = new ZipArchiveInputStream(file.openInputStream());
    return new XMLEventReaderBase() {
        private boolean started;
        private boolean ended;

        public void close() throws XMLStreamException {
            try {
                zip.close();//from  w w w  .j a va  2  s .  c om
            } catch (IOException e) {
                throw new XMLStreamException(e);
            }
        }

        protected boolean more() throws XMLStreamException {
            try {
                ZipArchiveEntry entry;
                if (!started) {
                    Namespace atom = ef.createNamespace(FEED.getPrefix(), FEED.getNamespaceURI());
                    add(ef.createStartDocument());
                    add(ef.createStartElement(FEED, null, Arrays.asList(atom).iterator()));
                    add(ef.createStartElement(TITLE, null, null));
                    add(ef.createCharacters(file.getName()));
                    add(ef.createEndElement(TITLE, null));
                    add(ef.createStartElement(ID, null, null));
                    add(ef.createCharacters(id));
                    add(ef.createEndElement(ID, null));
                    Attribute href = ef.createAttribute("href", file.toUri().toASCIIString());
                    List<Attribute> attrs = Arrays.asList(href, ef.createAttribute("type", "application/zip"));
                    add(ef.createStartElement(LINK, attrs.iterator(), null));
                    add(ef.createEndElement(LINK, null));
                    add(ef.createStartElement(UPDATED, null, null));
                    add(ef.createCharacters(format(new Date(file.getLastModified()))));
                    add(ef.createEndElement(UPDATED, null));
                    started = true;
                    return true;
                } else if (started && !ended && (entry = zip.getNextZipEntry()) != null) {
                    String name = entry.getName();
                    String link = entryPattern.replace("{entry}", PercentCodec.encode(name));
                    MimetypesFileTypeMap mimetypes = new javax.activation.MimetypesFileTypeMap();
                    String type = mimetypes.getContentType(name);
                    if (type == null || type.length() == 0) {
                        type = "application/octet-stream";
                    }
                    add(ef.createStartElement(ENTRY, null, null));
                    add(ef.createStartElement(TITLE, null, null));
                    add(ef.createCharacters(name));
                    add(ef.createEndElement(TITLE, null));
                    Attribute href = ef.createAttribute("href", link);
                    List<Attribute> attrs = Arrays.asList(href, ef.createAttribute("type", type));
                    add(ef.createStartElement(LINK, attrs.iterator(), null));
                    add(ef.createEndElement(LINK, null));
                    long size = entry.getSize();
                    if (size > 0) {
                        zip.skip(size);
                    } else {
                        while (zip.read(buf, 0, buf.length) >= 0)
                            ;
                    }
                    add(ef.createEndElement(ENTRY, null));
                    return true;
                } else if (!ended) {
                    add(ef.createEndElement(FEED, null));
                    add(ef.createEndDocument());
                    ended = true;
                    return true;
                } else {
                    return false;
                }
            } catch (IOException e) {
                throw new XMLStreamException(e);
            }
        }
    };
}

From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java

private void writeTemplateElement(XMLStreamWriter writer, XMLStreamReader inStream,
        Map<String, String> varToValue) throws XMLStreamException {

    if (inStream.getEventType() != XMLStreamConstants.START_ELEMENT) {
        throw new XMLStreamException("Input stream does not point to a START_ELEMENT event.");
    }//from ww  w.j  a  v a  2 s  . c  o  m
    int openElements = 0;
    boolean firstRun = true;
    while (firstRun || openElements > 0) {
        firstRun = false;
        int eventType = inStream.getEventType();

        switch (eventType) {
        case CDATA: {
            writer.writeCData(inStream.getText());
            break;
        }
        case CHARACTERS: {
            String s = new String(inStream.getTextCharacters(), inStream.getTextStart(),
                    inStream.getTextLength());
            // TODO optimize
            for (String param : varToValue.keySet()) {
                String value = varToValue.get(param);
                s = s.replace(param, value);
            }
            writer.writeCharacters(s);

            break;
        }
        case END_ELEMENT: {
            writer.writeEndElement();
            openElements--;
            break;
        }
        case START_ELEMENT: {
            if (inStream.getNamespaceURI() == "" || inStream.getPrefix() == DEFAULT_NS_PREFIX
                    || inStream.getPrefix() == null) {
                writer.writeStartElement(inStream.getLocalName());
            } else {
                if (writer.getNamespaceContext().getPrefix(inStream.getPrefix()) == "") {
                    // TODO handle special cases for prefix binding, see
                    // http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/javax/xml/namespace/NamespaceContext.html#getNamespaceURI(java.lang.String)
                    writer.setPrefix(inStream.getPrefix(), inStream.getNamespaceURI());
                }
                writer.writeStartElement(inStream.getPrefix(), inStream.getLocalName(),
                        inStream.getNamespaceURI());
            }
            // copy all namespace bindings
            for (int i = 0; i < inStream.getNamespaceCount(); i++) {
                String nsPrefix = inStream.getNamespacePrefix(i);
                String nsURI = inStream.getNamespaceURI(i);
                writer.writeNamespace(nsPrefix, nsURI);
            }

            // copy all attributes
            for (int i = 0; i < inStream.getAttributeCount(); i++) {
                String localName = inStream.getAttributeLocalName(i);
                String nsPrefix = inStream.getAttributePrefix(i);
                String value = inStream.getAttributeValue(i);
                String nsURI = inStream.getAttributeNamespace(i);
                if (nsURI == null) {
                    writer.writeAttribute(localName, value);
                } else {
                    writer.writeAttribute(nsPrefix, nsURI, localName, value);
                }
            }

            openElements++;
            break;
        }
        default: {
            break;
        }
        }
        if (openElements > 0) {
            inStream.next();
        }
    }
}