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

The following examples show how to use javax.xml.stream.XMLStreamException#printStackTrace() . These examples are extracted from open source projects. 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 Project: iBioSim   File: AnnotationUtility.java    License: 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
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 3
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 4
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 5
@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 6
Source Project: iBioSim   File: AnnotationUtility.java    License: 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 7
/** 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 8
Source Project: setupmaker   File: StaxMateFactory.java    License: 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 9
@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 10
@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 11
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 12
@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 13
Source Project: iBioSim   File: AnnotationUtility.java    License: 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 14
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 15
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 16
@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 17
Source Project: cxf   File: ValidationServer.java    License: 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 18
Source Project: journaldev   File: StaxXMLWriter.java    License: 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 19
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;
    }
 
Example 20
@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();
    }
}