Search in sources :

Example 61 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project uPortal by Jasig.

the class StaxEventLexicalContentHandler method startDTD.

/* (non-Javadoc)
     * @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, java.lang.String, java.lang.String)
     */
@Override
public void startDTD(String name, String publicId, String systemId) throws SAXException {
    // System identifier must be specified to print DOCTYPE.
    // This method is only called if the system identifier is specified.
    // Since the HTML5 DOCTYPE declaration does not include a system
    // identifier, this code allows the static string EMPTY to serve as
    // a temporary system id for doctypes which should not have one set.
    // If public identifier is specified print 'PUBLIC
    // <public> <system>', or if a non-'EMPTY' system identifier is
    // specified, print 'SYSTEM <system>'.
    final StringBuilder dtdBuilder = new StringBuilder("<!DOCTYPE ");
    dtdBuilder.append(name);
    if (publicId != null) {
        dtdBuilder.append(" PUBLIC \"").append(publicId).append("\" \"");
        dtdBuilder.append(systemId).append("\"");
    } else if (!EMPTY_SYSTEM_IDENTIFIER.equals(systemId)) {
        dtdBuilder.append(" SYSTEM \"");
        dtdBuilder.append(systemId).append("\"");
    }
    dtdBuilder.append(">");
    final DTD event = eventFactory.createDTD(dtdBuilder.toString());
    try {
        this.consumeEvent(event);
    } catch (XMLStreamException ex) {
        throw new SAXException("Could not create DTD: " + ex.getMessage(), ex);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) DTD(javax.xml.stream.events.DTD) SAXException(org.xml.sax.SAXException)

Example 62 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project uPortal by Jasig.

the class StaxEventLexicalContentHandler method endCDATA.

/* (non-Javadoc)
     * @see org.xml.sax.ext.LexicalHandler#endCDATA()
     */
@Override
public void endCDATA() throws SAXException {
    final Characters event = eventFactory.createCData(cdata.toString());
    cdata = null;
    try {
        this.consumeEvent(event);
    } catch (XMLStreamException ex) {
        throw new SAXException("Could not create CDATA: " + ex.getMessage(), ex);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) Characters(javax.xml.stream.events.Characters) SAXException(org.xml.sax.SAXException)

Example 63 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project uPortal by Jasig.

the class StaticDocumentComponent method getEventReader.

/* (non-Javadoc)
     * @see org.apereo.portal.rendering.PipelineComponent#getEventReader(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
@Override
public PipelineEventReader<XMLEventReader, XMLEvent> getEventReader(HttpServletRequest request, HttpServletResponse response) {
    final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder documentBuilder;
    try {
        documentBuilder = documentBuilderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    }
    final InputStream documentStream;
    try {
        documentStream = this.document.getInputStream();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    final Document document;
    try {
        document = documentBuilder.parse(documentStream);
    } catch (SAXException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(documentStream);
    }
    final XMLInputFactory inputFactory = XMLInputFactory.newFactory();
    final DOMSource source = new DOMSource(document);
    final XMLEventReader streamReader;
    try {
        streamReader = inputFactory.createXMLEventReader(source);
    } catch (XMLStreamException e) {
        throw new RuntimeException(e);
    }
    return new PipelineEventReaderImpl<XMLEventReader, XMLEvent>(streamReader);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) InputStream(java.io.InputStream) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) XMLStreamException(javax.xml.stream.XMLStreamException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) XMLEventReader(javax.xml.stream.XMLEventReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 64 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project aries by apache.

the class InitContextExample method initContext.

@Override
public void initContext(ContextEnricher contextEnricher) {
    final Map<String, String> customParameters = contextEnricher.getBlueprintConfiguration().getCustomParameters();
    for (final String param : customParameters.keySet()) {
        if (param.startsWith("example.")) {
            final String key = param.split("\\.")[1];
            contextEnricher.addBlueprintContentWriter("enrichContextWithExample-" + key, new XmlWriter() {

                @Override
                public void write(XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
                    xmlStreamWriter.writeEmptyElement("example");
                    xmlStreamWriter.writeDefaultNamespace("http://exampleNamespace");
                    xmlStreamWriter.writeAttribute("id", key);
                    xmlStreamWriter.writeAttribute("value", customParameters.get(param));
                }
            });
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) XmlWriter(org.apache.aries.blueprint.plugin.spi.XmlWriter)

Example 65 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project aima-java by aimacode.

the class SVGGroupParserTest method testParse.

@Test
public void testParse() {
    IGeometric2D x;
    IGeometric2D y;
    Iterator<IGeometric2D> j;
    try {
        j = testParser.parse(this.getClass().getResourceAsStream(file), groupID).iterator();
        Iterator<IGeometric2D> i = testGroup.iterator();
        while (i.hasNext()) {
            x = i.next();
            y = j.next();
            if (x instanceof Circle2D && y instanceof Circle2D) {
                assertEquals("Circle: Center-X.", ((Circle2D) (y)).getCenter().getX(), ((Circle2D) (x)).getCenter().getX(), 0.000005d);
                assertEquals("Circle: Center-Y.", ((Circle2D) (y)).getCenter().getY(), ((Circle2D) (x)).getCenter().getY(), 0.000005d);
                assertEquals("Circle: Radius.", ((Circle2D) (y)).getRadius(), ((Circle2D) (x)).getRadius(), 0.000005d);
            } else if (x instanceof Ellipse2D && y instanceof Ellipse2D) {
                assertEquals("Ellipse: Center-X.", ((Ellipse2D) (y)).getCenter().getX(), ((Ellipse2D) (x)).getCenter().getX(), 0.000005d);
                assertEquals("Ellipse: Center-Y.", ((Ellipse2D) (y)).getCenter().getY(), ((Ellipse2D) (x)).getCenter().getY(), 0.000005d);
                assertEquals("Ellipse: Horizontal length.", ((Ellipse2D) (y)).getHorizontalLength(), ((Ellipse2D) (x)).getHorizontalLength(), 0.000005d);
                assertEquals("Ellipse: Vertical length.", ((Ellipse2D) (y)).getVerticalLength(), ((Ellipse2D) (x)).getVerticalLength(), 0.000005d);
                assertEquals("Ellipse: Rotation angle.", ((Ellipse2D) (y)).getAngle(), ((Ellipse2D) (x)).getAngle(), 0.000005d);
            } else if (x instanceof Line2D && y instanceof Line2D) {
                assertEquals("Line: Start-X.", ((Line2D) (y)).getStart().getX(), ((Line2D) (x)).getStart().getX(), 0.000005d);
                assertEquals("Line: Start-Y.", ((Line2D) (y)).getStart().getY(), ((Line2D) (x)).getStart().getY(), 0.000005d);
                assertEquals("Line: End-X.", ((Line2D) (y)).getEnd().getX(), ((Line2D) (x)).getEnd().getX(), 0.000005d);
                assertEquals("Line: End-Y.", ((Line2D) (y)).getEnd().getY(), ((Line2D) (x)).getEnd().getY(), 0.000005d);
            } else if (x instanceof Polyline2D && y instanceof Polyline2D) {
                if (((Polyline2D) x).getVertexes().length != ((Polyline2D) x).getVertexes().length)
                    fail();
                else {
                    for (int k = 0; k < ((Polyline2D) x).getVertexes().length; k++) {
                        assertEquals("Polygon: Vertex-X", ((Polyline2D) x).getVertexes()[k].getX(), ((Polyline2D) y).getVertexes()[k].getX(), 0.000005d);
                        assertEquals("Polygon: Vertex-Y", ((Polyline2D) x).getVertexes()[k].getY(), ((Polyline2D) y).getVertexes()[k].getY(), 0.000005d);
                    }
                }
            } else if (x instanceof Rect2D && y instanceof Rect2D) {
                assertEquals("Line: UpperLeft-X.", ((Rect2D) (y)).getUpperLeft().getX(), ((Rect2D) (x)).getUpperLeft().getX(), 0.000005d);
                assertEquals("Line: UpperLeft-Y.", ((Rect2D) (y)).getUpperLeft().getY(), ((Rect2D) (x)).getUpperLeft().getY(), 0.000005d);
                assertEquals("Line: LowerRight-X.", ((Rect2D) (y)).getLowerRight().getX(), ((Rect2D) (x)).getLowerRight().getX(), 0.000005d);
                assertEquals("Line: LowerRight-Y.", ((Rect2D) (y)).getLowerRight().getY(), ((Rect2D) (x)).getLowerRight().getY(), 0.000005d);
            }
        }
        assertFalse("Both groups are the same length and contain only legal shapes.", i.hasNext() || j.hasNext());
    } catch (XMLStreamException e) {
        e.printStackTrace();
        fail();
    } catch (NullPointerException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : IGeometric2D(aima.core.util.math.geom.shapes.IGeometric2D) Polyline2D(aima.core.util.math.geom.shapes.Polyline2D) XMLStreamException(javax.xml.stream.XMLStreamException) Circle2D(aima.core.util.math.geom.shapes.Circle2D) Line2D(aima.core.util.math.geom.shapes.Line2D) Rect2D(aima.core.util.math.geom.shapes.Rect2D) Ellipse2D(aima.core.util.math.geom.shapes.Ellipse2D) Test(org.junit.Test)

Aggregations

XMLStreamException (javax.xml.stream.XMLStreamException)442 XMLStreamReader (javax.xml.stream.XMLStreamReader)137 IOException (java.io.IOException)126 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)75 XMLInputFactory (javax.xml.stream.XMLInputFactory)69 InputStream (java.io.InputStream)66 Document (org.w3c.dom.Document)36 JAXBException (javax.xml.bind.JAXBException)35 Fault (org.apache.cxf.interceptor.Fault)34 Element (org.w3c.dom.Element)32 StringReader (java.io.StringReader)30 XMLEvent (javax.xml.stream.events.XMLEvent)28 DOMSource (javax.xml.transform.dom.DOMSource)27 ByteArrayInputStream (java.io.ByteArrayInputStream)25 ArrayList (java.util.ArrayList)23 QName (javax.xml.namespace.QName)23 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)23 Node (org.w3c.dom.Node)22 StringWriter (java.io.StringWriter)21 XMLEventReader (javax.xml.stream.XMLEventReader)20