Java Code Examples for javax.xml.stream.XMLStreamException#printStackTrace()

The following examples show how to use javax.xml.stream.XMLStreamException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationUtility.java    From iBioSim with Apache License 2.0 6 votes vote down vote up
public static int[] parseSpeciesArrayAnnotation(Species species) {
	String annotation;
	try {
		annotation = species.getAnnotationString().replace("<annotation>", "").replace("</annotation>", "").trim();
		Pattern arrayPattern = Pattern.compile(SPECIES_ARRAY_ANNOTATION);
		Matcher arrayMatcher = arrayPattern.matcher(annotation);
		if (arrayMatcher.find()) {
			if (arrayMatcher.group(1)!=null && arrayMatcher.group(2)!=null &&
					arrayMatcher.group(3)!=null && arrayMatcher.group(4)!=null) {
				int[] result = new int[4];
				result[0] = Integer.parseInt(arrayMatcher.group(1));
				result[1] = Integer.parseInt(arrayMatcher.group(2));
				result[2] = Integer.parseInt(arrayMatcher.group(3));
				result[3] = Integer.parseInt(arrayMatcher.group(4));
				return result;
			}
		}
	}
	catch (XMLStreamException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
Example 2
Source File: AnnotationUtility.java    From iBioSim with Apache License 2.0 6 votes vote down vote up
/**
 * Remove the following SBOL annotation associated to the given SBML element. 
 * @param sbmlObject - The SBML element that has the annotated SBOL object.
 */
public static void removeSBOLAnnotation(SBase sbmlObject) {
	try {
		String annotation = sbmlObject.getAnnotationString().replace("<annotation>", "").replace("</annotation>", "").trim();
		Pattern sbolPattern = Pattern.compile(SBOL_ANNOTATION);
		Matcher sbolMatcher = sbolPattern.matcher(annotation);
		while (sbolMatcher.find()) {
			String sbolAnnotation = sbolMatcher.group(0);
			annotation = annotation.replace(sbolAnnotation, "");
		}
		if (annotation.equals("")) {
			sbmlObject.unsetAnnotation();
		} else {
			annotation = "<annotation>\n"+annotation+"\n</annotation>";
			sbmlObject.setAnnotation(new Annotation(annotation));				
		}
	} catch (XMLStreamException e) {
		e.printStackTrace();
	}

}
 
Example 3
Source File: DumpTube.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected void dump(String header, Packet packet) {
    out.println("====["+name+":"+header+"]====");
    if(packet.getMessage()==null)
        out.println("(none)");
    else
        try {
            XMLStreamWriter writer = staxOut.createXMLStreamWriter(new PrintStream(out) {
                @Override
                public void close() {
                    // noop
                }
            });
            writer = createIndenter(writer);
            packet.getMessage().copy().writeTo(writer);
            writer.close();
        } catch (XMLStreamException e) {
            e.printStackTrace(out);
        }
    out.println("============");
}
 
Example 4
Source File: DoubleXmlnsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNestedNS() throws Exception {

    final String VALID_XML = "<foo xmlns:xmli='http://www.w3.org/XML/1998/namespacei'><bar xmlns:xmli='http://www.w3.org/XML/1998/namespaceii'></bar></foo>";

    try {
        XMLStreamReader xsr = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(VALID_XML));

        while (xsr.hasNext()) {
            xsr.next();
        }

        // expected success
    } catch (XMLStreamException e) {
        e.printStackTrace();

        Assert.fail("Wellformedness error is not expected: " + VALID_XML + ", " + e.getMessage());
    }
}
 
Example 5
Source File: DumpTube.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected void dump(String header, Packet packet) {
    out.println("====["+name+":"+header+"]====");
    if(packet.getMessage()==null)
        out.println("(none)");
    else
        try {
            XMLStreamWriter writer = staxOut.createXMLStreamWriter(new PrintStream(out) {
                @Override
                public void close() {
                    // noop
                }
            });
            writer = createIndenter(writer);
            packet.getMessage().copy().writeTo(writer);
            writer.close();
        } catch (XMLStreamException e) {
            e.printStackTrace(out);
        }
    out.println("============");
}
 
Example 6
Source File: InterchangeWriter.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
public void close() {

      System.out.println("generated and marshaled in: "
      + (System.currentTimeMillis() - interchangeStartTime));

        try {
            if (FORMAT_INTERCHANGE_XML && SINGLE_LINE_MARSHALLING) {
                defaultWriter.writeCharacters("\n");
            }
//            writer.writeEndElement();
            writer.writeEndDocument();
            writer.close();
        } catch (XMLStreamException e) {
            e.printStackTrace();
            System.exit(1);  // fail fast for now
        }

        streamMarshaller = null;
    }
 
Example 7
Source File: AnnotationUtility.java    From iBioSim with Apache License 2.0 5 votes vote down vote up
public static boolean checkObsoleteAnnotation(SBase sbmlObject, String annotation) {
	try {
		return sbmlObject.isSetAnnotation() && 
				sbmlObject.getAnnotationString().replace("<annotation>", "").replace("</annotation>", "").trim().contains(annotation) &&
				!sbmlObject.getAnnotationString().replace("<annotation>", "").replace("</annotation>", "").trim().contains("rdf");
	} catch (XMLStreamException e) {
		e.printStackTrace();
	}
	return false;
}
 
Example 8
Source File: StaxXMLWriter.java    From journaldev with MIT License 5 votes vote down vote up
public void writeXML(String fileName, String rootElement, Map<String, String> elementsMap){
        XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
        try {
//            XMLEventWriter xmlEventWriter = xmlOutputFactory
//                    .createXMLEventWriter(new FileOutputStream(fileName), "UTF-8");
            //For Debugging - below code to print XML to Console
            XMLEventWriter xmlEventWriter = xmlOutputFactory.createXMLEventWriter(System.out);
            XMLEventFactory eventFactory = XMLEventFactory.newInstance();
            XMLEvent end = eventFactory.createDTD("\n");
            StartDocument startDocument = eventFactory.createStartDocument();
            xmlEventWriter.add(startDocument);
            xmlEventWriter.add(end);
            StartElement configStartElement = eventFactory.createStartElement("",
                "", rootElement);
            xmlEventWriter.add(configStartElement);
            xmlEventWriter.add(end);
            // Write the element nodes
            Set<String> elementNodes = elementsMap.keySet();
            for(String key : elementNodes){
                createNode(xmlEventWriter, key, elementsMap.get(key));
            }
            
            xmlEventWriter.add(eventFactory.createEndElement("", "", rootElement));
            xmlEventWriter.add(end);
            xmlEventWriter.add(eventFactory.createEndDocument());
            xmlEventWriter.close();

        } catch ( XMLStreamException e) {
            e.printStackTrace();
        }
    }
 
Example 9
Source File: ValidationServer.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public Source invoke(Source request) {
    try {
        Document doc = StaxUtils.read(request);
        String name = doc.getDocumentElement().getLocalName();
        if ("SomeRequest".equals(name)) {
            String v = DOMUtils.getFirstElement(doc.getDocumentElement()).getTextContent();
            return new StreamSource(new StringReader(getResponse(v)));
        }
    } catch (XMLStreamException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 10
Source File: DuplicateNSDeclarationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDuplicateNSDeclaration() {

    // expect only 1 Namespace Declaration
    final String EXPECTED_OUTPUT = "<?xml version=\"1.0\" ?>" + "<ns1:foo" + " xmlns:ns1=\"http://example.com/\">" + "</ns1:foo>";

    // have XMLOutputFactory repair Namespaces
    XMLOutputFactory ofac = XMLOutputFactory.newInstance();
    ofac.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, new Boolean(true));

    // send output to a Stream
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    StreamResult sr = new StreamResult(buffer);
    XMLStreamWriter w = null;

    // write a duplicate Namespace Declaration
    try {
        w = ofac.createXMLStreamWriter(sr);
        w.writeStartDocument();
        w.writeStartElement("ns1", "foo", "http://example.com/");
        w.writeNamespace("ns1", "http://example.com/");
        w.writeNamespace("ns1", "http://example.com/");
        w.writeEndElement();
        w.writeEndDocument();
        w.close();
    } catch (XMLStreamException xmlStreamException) {
        xmlStreamException.printStackTrace();
        Assert.fail(xmlStreamException.toString());
    }

    // debugging output for humans
    System.out.println();
    System.out.println("actual:   \"" + buffer.toString() + "\"");
    System.out.println("expected: \"" + EXPECTED_OUTPUT + "\"");

    // are results as expected?
    Assert.assertEquals(EXPECTED_OUTPUT, buffer.toString());
}
 
Example 11
Source File: NamespaceTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void setUpForNoRepair() {

        xmlOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.FALSE);

        // new Writer
        try {
            xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(byteArrayOutputStream);

        } catch (XMLStreamException xmlStreamException) {
            xmlStreamException.printStackTrace();
            Assert.fail(xmlStreamException.toString());
        }
    }
 
Example 12
Source File: Utils.java    From Course_Generator with GNU General Public License v3.0 5 votes vote down vote up
public static void WriteStringToXML(XMLStreamWriter writer, String Element, String Data) {
	try {
		writer.writeStartElement(Element);
		writer.writeCharacters(Data);
		writer.writeEndElement();
	} catch (XMLStreamException e) {
		e.printStackTrace();
	}
}
 
Example 13
Source File: SlotEditor.java    From open-ig with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** Loads the tech file. */
void doLoad() {
	mainLoad = true;
	try {
		techXML = XElement.parseXML(TECH_XML_FILE);
	} catch (XMLStreamException ex) {
		ex.printStackTrace();
	}

	render.current = null;
	currentSlot = null;
	techItems.clear();
	cbTech.removeAllItems();
	for (XElement xe : techXML.childrenWithName("item")) {
		if (xe.get("category", "").startsWith("SPACESHIP")) {
			techItems.add(xe);
			cbTech.addItem(xe.get("id"));
		}
	}
	cbTech.setSelectedIndex(-1);
	render.current = null;
	currentSlot = null;
	txRace.setText("");
	txSkirmishRace.setText("");
	txLevel.setValue(0);
	txRequires.setText("");
	txIndex.setValue(0);
	txResearch.setValue(0);
	txProduction.setValue(0);
	txCivil.setValue(0);
	txMech.setValue(0);
	txComp.setValue(0);
	txAI.setValue(0);
	txMil.setValue(0);
	mainLoad = false;
}
 
Example 14
Source File: SkipDTDTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() {
    try {
        XMLInputFactory factory = XMLInputFactory.newInstance();
        factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
        for (int i = 0; i < 3; i++) {
            runReader(factory, i);
        }
    } catch (XMLStreamException xe) {
        xe.printStackTrace();
        Assert.fail(xe.getMessage());
    }
}
 
Example 15
Source File: WordPressXMLReader.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public void getNext(CAS aCAS) throws IOException, CollectionException {
  JCas jcas;
  try {
    jcas = aCAS.getJCas();
  } catch (CASException var6) {
    throw new CollectionException(var6);
  }

  try {
    if (this.xmlReader == null) {
      WstxInputFactory e = new WstxInputFactory();
      this.xmlReader = e.createXMLStreamReader((File) this.xmlFiles.get(this.currentParsedFile));
      this.iDoc = 0;
    }

    this.parseSubDocument(jcas);
    System.out.println(jcas.getDocumentText());
    ++this.iDoc;
    if (this.xmlReader.getDepth() < 2) {
      this.xmlReader.closeCompletely();
      this.xmlReader = null;
      ++this.currentParsedFile;
    }

  } catch (XMLStreamException var4) {
    var4.printStackTrace();
    throw new CollectionException(var4);
  } catch (Exception var5) {
    var5.printStackTrace();
    throw new CollectionException(var5);
  }
}
 
Example 16
Source File: SkipDTDTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() {
    try {
        XMLInputFactory factory = XMLInputFactory.newInstance();
        factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
        for (int i = 0; i < 3; i++) {
            runReader(factory, i);
        }
    } catch (XMLStreamException xe) {
        xe.printStackTrace();
        Assert.fail(xe.getMessage());
    }
}
 
Example 17
Source File: Bug8153781.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() {
    try {
        XMLInputFactory factory = XMLInputFactory.newInstance();
        factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
        for (int i = 0; i < 3; i++) {
            runReader(factory, i);
        }
    } catch (XMLStreamException xe) {
        xe.printStackTrace();
        Assert.fail(xe.getMessage());
    }
}
 
Example 18
Source File: StaxMateFactory.java    From setupmaker with Apache License 2.0 5 votes vote down vote up
/**
 * Sets/Gets the root element
 * @return SMOutputElement
 * @param ELEMENT
 */
public SMOutputElement setRoot(String ELEMENT) {
    try {
        root = doc.addElement(ELEMENT);
    } catch (XMLStreamException e) {
        e.printStackTrace();
    }
    return root;
}
 
Example 19
Source File: JacksonOrganisationUnitChildrenSerializer.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void serialize( OrganisationUnit value, JsonGenerator jgen, SerializerProvider provider ) throws IOException
{
    DateFormat DATE_FORMAT = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ" );

    if ( ToXmlGenerator.class.isAssignableFrom( jgen.getClass() ) )
    {
        ToXmlGenerator xmlGenerator = (ToXmlGenerator) jgen;

        try
        {
            XMLStreamWriter staxWriter = xmlGenerator.getStaxWriter();

            staxWriter.writeStartElement( DxfNamespaces.DXF_2_0, "child" );
            staxWriter.writeAttribute( "id", value.getUid() );
            staxWriter.writeAttribute( "name", value.getName() );
            staxWriter.writeAttribute( "created", DATE_FORMAT.format( value.getCreated() ) );
            staxWriter.writeAttribute( "lastUpdated", DATE_FORMAT.format( value.getLastUpdated() ) );

            if ( value.getHref() != null )
            {
                staxWriter.writeAttribute( "href", value.getHref() );
            }

            staxWriter.writeAttribute( "hasChildren", String.valueOf( value.hasChild() ) );
            staxWriter.writeEndElement();
        }
        catch ( XMLStreamException e )
        {
            e.printStackTrace(); //TODO fix
        }
    }
    else
    {
        jgen.writeStartObject();

        jgen.writeStringField( "id", value.getUid() );
        jgen.writeStringField( "name", value.getName() );
        jgen.writeFieldName( "created" );
        provider.defaultSerializeDateValue( value.getCreated(), jgen );

        jgen.writeFieldName( "lastUpdated" );
        provider.defaultSerializeDateValue( value.getLastUpdated(), jgen );

        if ( value.getHref() != null )
        {
            jgen.writeStringField( "href", value.getHref() );
        }

        jgen.writeBooleanField( "hasChildren", value.hasChild() );

        jgen.writeEndObject();
    }
}
 
Example 20
Source File: BingResultParser.java    From AndroidStringsOneTabTranslation with Apache License 2.0 4 votes vote down vote up
public static List<TranslateArrayResponse> parseTranslateArrayResponse(String xml) {

        InputStream stream = new ByteArrayInputStream(xml.getBytes(Charset.forName("UTF-8")));

        List<TranslateArrayResponse> result = new ArrayList<TranslateArrayResponse>();

        try {
            XMLInputFactory inputFactory = XMLInputFactory.newInstance();
            XMLEventReader eventReader = inputFactory.createXMLEventReader(stream);

            TranslateArrayResponse translateArrayResponse = null;

            while (eventReader.hasNext()) {
                XMLEvent event = eventReader.nextEvent();

                if (event.isStartElement()) {
                    StartElement startElement = event.asStartElement();
                    if (startElement.getName().getLocalPart().equals(TranslateArrayResponse)) {
                        translateArrayResponse = new TranslateArrayResponse();
                    }
                    if (event.isStartElement()) {
                        if (event.asStartElement().getName().getLocalPart().equals(From)) {
                            event = eventReader.nextEvent();
                            translateArrayResponse.setFrom(event.asCharacters().getData());
                            continue;
                        }
                    }
                    if (event.asStartElement().getName().getLocalPart().equals(TranslatedText)) {
                        event = eventReader.nextEvent();
                        translateArrayResponse.setTranslatedText(event.asCharacters().getData());
                        continue;
                    }
                }

                if (event.isEndElement()) {
                    EndElement endElement = event.asEndElement();
                    if (endElement.getName().getLocalPart().equals(TranslateArrayResponse)) {
                        result.add(translateArrayResponse);
                    }
                }
            }
        } catch (XMLStreamException e) {
            e.printStackTrace();
        }

        return result;
    }