Example usage for javax.xml.parsers SAXParser parse

List of usage examples for javax.xml.parsers SAXParser parse

Introduction

In this page you can find the example usage for javax.xml.parsers SAXParser parse.

Prototype

public void parse(InputSource is, DefaultHandler dh) throws SAXException, IOException 

Source Link

Document

Parse the content given org.xml.sax.InputSource as XML using the specified org.xml.sax.helpers.DefaultHandler .

Usage

From source file:com.knowledgebooks.rdf.SparqlClient.java

public SparqlClient(String endpoint_URL, String sparql) throws Exception {
    //System.out.println("SparqlClient("+endpoint_URL+", "+sparql+")");
    HttpClient client = new HttpClient();
    client.getHttpConnectionManager().getParams().setConnectionTimeout(10000);

    String req = URLEncoder.encode(sparql, "utf-8");
    HttpMethod method = new GetMethod(endpoint_URL + "?query=" + req);
    method.setFollowRedirects(false);//  w  w w. j  av  a2  s .co  m
    try {
        client.executeMethod(method);
        //System.out.println(method.getResponseBodyAsString());
        //if (true) return;
        InputStream ins = method.getResponseBodyAsStream();
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser sax = factory.newSAXParser();
        sax.parse(ins, this);
    } catch (HttpException he) {
        System.err.println("Http error connecting to '" + endpoint_URL + "'");
    } catch (IOException ioe) {
        System.err.println("Unable to connect to '" + endpoint_URL + "'");
    }
    method.releaseConnection();
}

From source file:VSX.java

public TreeModel parse(String filename) {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    XMLTreeHandler handler = new XMLTreeHandler();
    try {/*  w w  w  .  ja v a 2  s  . c o m*/
        // Parse the input.
        SAXParser saxParser = factory.newSAXParser();
        saxParser.parse(new File(filename), handler);
    } catch (Exception e) {
        System.err.println("File Read Error: " + e);
        e.printStackTrace();
        return new DefaultTreeModel(new DefaultMutableTreeNode("error"));
    }
    return new DefaultTreeModel(handler.getRoot());
}

From source file:de.shadowhunt.subversion.xml.AbstractSaxExpressionHandler.java

public V parse(final InputStream inputStream) throws ParserConfigurationException, SAXException, IOException {
    final SAXParser saxParser = FACTORY.newSAXParser();
    saxParser.parse(inputStream, this);
    return getValue();
}

From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java

public static String getSubscriptionArnFromString(String res) {
    javax.xml.parsers.SAXParserFactory fac = new org.apache.xerces.jaxp.SAXParserFactoryImpl();
    javax.xml.parsers.SAXParser saxParser;

    SubscribeParser p = new SubscribeParser();

    try {/*from   ww  w .  j ava2  s.  co  m*/
        saxParser = fac.newSAXParser();
        saxParser.parse(new ByteArrayInputStream(res.getBytes()), p);

    } catch (Exception ex) {
        logger.error("Exception parsing", ex);
    }
    String arn = p.getSubscriptionArn();
    return arn;
}

From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java

public static TopicAttributeParser getTopicAttributesFromString(String res) {
    javax.xml.parsers.SAXParserFactory fac = new org.apache.xerces.jaxp.SAXParserFactoryImpl();
    javax.xml.parsers.SAXParser saxParser;

    TopicAttributeParser p = new TopicAttributeParser();

    try {/*from  w w  w  .  j  a  v a 2 s .co m*/
        saxParser = fac.newSAXParser();
        saxParser.parse(new ByteArrayInputStream(res.getBytes()), p);

    } catch (Exception ex) {
        logger.error("Exception parsing", ex);
    }

    return p;
}

From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java

public static ListSubscriptionParser getSubscriptionDataFromString(String res) {
    //System.out.println("Starting parsing: res is:" + res);
    javax.xml.parsers.SAXParserFactory fac = new org.apache.xerces.jaxp.SAXParserFactoryImpl();
    javax.xml.parsers.SAXParser saxParser;

    ListSubscriptionParser pl = new ListSubscriptionParser();

    try {/*from   w ww .  j  a  v a  2 s. com*/
        saxParser = fac.newSAXParser();
        saxParser.parse(new ByteArrayInputStream(res.getBytes()), pl);

    } catch (Exception ex) {

        logger.error("Exception parsing", ex);
    }
    return pl;
}

From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java

public static Vector<String> getArnsFromString(String res) {
    //System.out.println("Starting parsing: res is:" + res);
    javax.xml.parsers.SAXParserFactory fac = new org.apache.xerces.jaxp.SAXParserFactoryImpl();
    javax.xml.parsers.SAXParser saxParser;

    ListTopicsResponseParser pl = new ListTopicsResponseParser();

    try {/*  w  ww  .  j av a  2s.  com*/
        saxParser = fac.newSAXParser();
        saxParser.parse(new ByteArrayInputStream(res.getBytes()), pl);

    } catch (Exception ex) {
        logger.error("Exception parsing", ex);
    }
    return pl.getArns();
}

From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java

public static String getArnFromString(String res) {
    javax.xml.parsers.SAXParserFactory fac = new org.apache.xerces.jaxp.SAXParserFactoryImpl();
    javax.xml.parsers.SAXParser saxParser;

    CreateTopicResponseParser p = new CreateTopicResponseParser();

    try {/*from   ww w  .j a v  a 2  s .com*/
        saxParser = fac.newSAXParser();
        saxParser.parse(new ByteArrayInputStream(res.getBytes()), p);

    } catch (Exception ex) {
        logger.error("Exception parsing", ex);

    }
    String arn = p.getTopicArn();
    return arn;
}

From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java

public static boolean verifyErrorResponse(String res, String code, String message) {

    SAXParserFactory fac = new org.apache.xerces.jaxp.SAXParserFactoryImpl();
    SAXParser saxParser;

    ErrorParser p = new ErrorParser();
    res = res.trim();//from  www  .j av  a 2 s.  c om

    try {
        saxParser = fac.newSAXParser();
        saxParser.parse(new ByteArrayInputStream(res.getBytes()), p);
    } catch (Exception ex) {
        logger.error("Exception parsing error response", ex);
    }

    if (code != null) {

        String rescode = p.getCode();

        if (!code.equals(rescode)) {
            logger.error("Wrong error code");
            return false;
        }
    }

    if (message != null) {

        String resmessage = p.getMessage();

        if (!resmessage.equals(message)) {
            logger.error("Wrong error messahe");
            return false;
        }
    }

    return true;
}

From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java

public static SubscriptionAttributeParser getSubscriptionAttributesFromString(String res) {
    javax.xml.parsers.SAXParserFactory fac = new org.apache.xerces.jaxp.SAXParserFactoryImpl();
    javax.xml.parsers.SAXParser saxParser;

    SubscriptionAttributeParser p = new SubscriptionAttributeParser();

    try {/*  w  w w.  j a va2 s . c  om*/
        saxParser = fac.newSAXParser();
        saxParser.parse(new ByteArrayInputStream(res.getBytes()), p);

    } catch (Exception ex) {
        logger.error("Exception parsing", ex);
    }

    return p;
}