List of usage examples for java.io StringReader StringReader
public StringReader(String s)
From source file:ReaderUtilClient.java
public static void main(String[] args) { ReaderUtil readerUtil = new ReaderUtil(new GenericObjectPool<StringBuffer>(new StringBufferFactory())); Reader reader = new StringReader("foo"); try {/*from w w w. j a v a 2s . c o m*/ System.out.println(readerUtil.readToString(reader)); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
License:asdf
public static void main(String[] args) throws Exception { String xml = "<soapenv:Envelope " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " + "xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " + "xmlns:ser=\"http://services.web.post.list.com\"><soapenv:Header>" + "<authInfo xsi:type=\"soap:authentication\" " + "xmlns:soap=\"http://list.com/services/SoapRequestProcessor\">" + "<username xsi:type=\"xsd:string\">asdf@g.com</username>" + "<password xsi:type=\"xsd:string\">asdf</password></authInfo></soapenv:Header></soapenv:Envelope>"; System.out.println(xml);/*from w ww. j a v a 2 s . c om*/ DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse(new InputSource(new StringReader(xml))); XPath xpath = XPathFactory.newInstance().newXPath(); xpath.setNamespaceContext(new NamespaceContext() { @Override public Iterator getPrefixes(String arg0) { return null; } @Override public String getPrefix(String arg0) { return null; } @Override public String getNamespaceURI(String arg0) { if ("soapenv".equals(arg0)) { return "http://schemas.xmlsoap.org/soap/envelope/"; } return null; } }); XPathExpression expr = xpath.compile("/soapenv:Envelope/soapenv:Header/authInfo/password"); Object result = expr.evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) result; System.out.println("Got " + nodes.getLength() + " nodes"); }
From source file:MyErrorHandler.java
static public void main(String[] arg) throws Exception { boolean validate = false; validate = true;/*from w w w . j a v a 2 s . c o m*/ SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setValidating(validate); XMLReader reader = null; SAXParser parser = spf.newSAXParser(); reader = parser.getXMLReader(); reader.setErrorHandler(new MyErrorHandler()); InputSource is = new InputSource(new StringReader(getXMLData())); reader.parse(is); }
From source file:Main.java
public static void main(String[] args) throws Exception { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(new InputSource(new StringReader(cfgXml))); doc.getDocumentElement().normalize(); System.out.println("Root element :" + doc.getDocumentElement().getNodeName()); NodeList nList = doc.getElementsByTagName("config"); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); System.out.println("\nCurrent Element :" + nNode.getNodeName()); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; Config c = new Config(); c.name = eElement.getAttribute("name"); c.type = eElement.getAttribute("type"); c.format = eElement.getAttribute("format"); c.size = Integer.valueOf(eElement.getAttribute("size")); c.scale = Integer.valueOf(eElement.getAttribute("scale")); String attribute = eElement.getAttribute("required"); c.required = Boolean.valueOf("Yes".equalsIgnoreCase(attribute) ? true : false); System.out.println("Imported config : " + c); }/*from w w w . ja v a 2s . co m*/ } }
From source file:Main.java
public static void main(String[] args) throws Exception { String xml = "<?xml version='1.0'?><test><test2></test2></test>"; String schemaString = // "<?xml version='1.0'?>"// + "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema' elementFormDefault='unqualified' attributeFormDefault='unqualified'>"// + "<xsd:element name='test' type='Test'/>"// + "<xsd:element name='test2' type='Test2'/>"// + "<xsd:complexType name='Test'>"// + "<xsd:sequence>"// + "<xsd:element ref='test2' minOccurs='1' maxOccurs='unbounded'/>"// + "</xsd:sequence>"// + "</xsd:complexType>"// + "<xsd:simpleType name='Test2'>"// + "<xsd:restriction base='xsd:string'><xsd:minLength value='1'/></xsd:restriction>"// + "</xsd:simpleType>"// + "</xsd:schema>"; Source schemaSource = new StreamSource(new StringReader(schemaString)); Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaSource); SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true);//from w w w . j av a 2s . c om factory.setSchema(schema); SAXParser parser = factory.newSAXParser(); MyContentHandler handler = new MyContentHandler(); parser.parse(new InputSource(new StringReader(xml)), handler); }
From source file:Main.java
public static void main(String args[]) { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setNamespaceAware(true); // Set namespace aware builderFactory.setValidating(true); // and validating parser feaures builderFactory.setIgnoringElementContentWhitespace(true); DocumentBuilder builder = null; try {//from www.j a v a 2 s. c om builder = builderFactory.newDocumentBuilder(); // Create the parser } catch (ParserConfigurationException e) { e.printStackTrace(); } Document xmlDoc = null; try { xmlDoc = builder.parse(new InputSource(new StringReader(xmlString))); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } DocumentType doctype = xmlDoc.getDoctype(); if (doctype == null) { System.out.println("DOCTYPE is null"); } else { System.out.println("DOCTYPE node:\n" + doctype.getInternalSubset()); } System.out.println("\nDocument body contents are:"); listNodes(xmlDoc.getDocumentElement(), ""); // Root element & children }
From source file:MainClass.java
public static void main(String args[]) throws Exception { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser parser = null;//from w w w . j a v a 2s . com spf.setNamespaceAware(true); try { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); spf.setSchema(sf.newSchema(new SAXSource(new InputSource(new StringReader(schemaString))))); parser = spf.newSAXParser(); } catch (SAXException e) { e.printStackTrace(System.err); System.exit(1); } catch (ParserConfigurationException e) { e.printStackTrace(System.err); System.exit(1); } MySAXHandler handler = new MySAXHandler(); System.out.println(schemaString); parser.parse(new InputSource(new StringReader(xmlString)), handler); }
From source file:MainClass.java
public static void main(String args[]) { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setValidating(true); // and validating parser feaures builderFactory.setIgnoringElementContentWhitespace(true); DocumentBuilder builder = null; try {//www. ja va 2 s .c o m builder = builderFactory.newDocumentBuilder(); // Create the parser } catch (ParserConfigurationException e) { e.printStackTrace(); } Document xmlDoc = null; try { xmlDoc = builder.parse(new InputSource(new StringReader(xmlString))); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } DocumentType doctype = xmlDoc.getDoctype(); if (doctype == null) { System.out.println("DOCTYPE is null"); } else { System.out.println("DOCTYPE node:\n" + doctype.getInternalSubset()); } System.out.println("\nDocument body contents are:"); listNodes(xmlDoc.getDocumentElement(), ""); // Root element & children }
From source file:loanbroker.normalizer.NormalizerOurSoapXmlBank.java
public static void main(String[] argv) throws IOException, InterruptedException, TimeoutException { //Connection/*from w w w . j a v a 2 s . c om*/ ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); //Consumer channel.exchangeDeclare(EXCHANGE_NAME, "fanout"); String queueName = channel.queueDeclare().getQueue(); //s channel.queueBind(queueName, EXCHANGE_NAME, "OurSoapXmlBank"); channel.queueBind(queueName, EXCHANGE_NAME, ""); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(queueName, true, consumer); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); //Producer Channel channelOutput = connection.createChannel(); channelOutput.exchangeDeclare("TeamFirebug", "direct"); LoanResponse loanResponse; DtoOurSoapXmlBank dtoOurSoapXmlBank; while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); String message = new String(delivery.getBody()); String routingKey = delivery.getEnvelope().getRoutingKey(); dtoOurSoapXmlBank = JAXB.unmarshal(new StringReader(message), DtoOurSoapXmlBank.class); loanResponse = new LoanResponse(dtoOurSoapXmlBank.getSsn(), dtoOurSoapXmlBank.getInterestRate(), "Our Soap Xml bank", delivery.getProperties().getCorrelationId()); // loanResponse.setBank(routingKey); System.out.println("renter: " + loanResponse.getInterestRate()); System.out.println("ssn: " + loanResponse.getSsn()); System.out.println("bank : " + loanResponse.getBank()); JSONObject jsonObj = new JSONObject(loanResponse); // channelOutput.basicPublish("", RoutingKeys.Aggregator, null, jsonObj.toString().getBytes()); channelOutput.basicPublish("TeamFirebug", "normalizerToAggregator", null, jsonObj.toString().getBytes()); } }
From source file:loanbroker.normalizer.NormalizerTeachersXmlBank.java
public static void main(String[] argv) throws IOException, InterruptedException, TimeoutException { //Connection/*from www . j a v a 2 s.c o m*/ ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); //Consumer channel.exchangeDeclare(EXCHANGE_NAME, "fanout"); //String queueName = channel.queueDeclare().getQueue(); //s channel.queueBind(queueName, EXCHANGE_NAME, "OurSoapXmlBank"); channel.queueDeclare(RPC_QUEUE_NAME, false, false, false, null); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(RPC_QUEUE_NAME, true, consumer); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); //Producer Channel channelOutput = connection.createChannel(); channelOutput.exchangeDeclare("TeamFirebug", "direct"); while (true) { System.out.println("Reading"); QueueingConsumer.Delivery delivery = consumer.nextDelivery(); String message = new String(delivery.getBody()); String routingKey = delivery.getEnvelope().getRoutingKey(); DtoTeachersXmlBank dtoOurSoapXmlBank = JAXB.unmarshal(new StringReader(message), DtoTeachersXmlBank.class); LoanResponse loanResponse = new LoanResponse(dtoOurSoapXmlBank.getSsn(), dtoOurSoapXmlBank.getInterestRate(), "Teachers Xml Bank", delivery.getProperties().getCorrelationId()); // loanResponse.setBank(routingKey); System.out.println("CorrelationId: " + delivery.getProperties().getCorrelationId()); System.out.println("renter: " + loanResponse.getInterestRate()); System.out.println("ssn: " + loanResponse.getSsn()); System.out.println("bank : " + loanResponse.getBank()); JSONObject jsonObj = new JSONObject(loanResponse); System.out.println("JSON:" + jsonObj); // channelOutput.basicPublish("", RoutingKeys.Aggregator, null, jsonObj.toString().getBytes()); channelOutput.basicPublish("TeamFirebug", "normalizerToAggregator", null, jsonObj.toString().getBytes()); delivery = null; } }