Example usage for org.dom4j.io SAXReader read

List of usage examples for org.dom4j.io SAXReader read

Introduction

In this page you can find the example usage for org.dom4j.io SAXReader read.

Prototype

public Document read(InputSource in) throws DocumentException 

Source Link

Document

Reads a Document from the given InputSource using SAX

Usage

From source file:com.founder.fix.fixflow.editor.impl.PluginServiceImpl.java

License:Apache License

public void getPluginXml(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    InputStream pluginStream = this.getClass().getClassLoader().getResourceAsStream("plugins.xml");
    Document document = null;//from   w w  w.  j a v a  2 s. c  om
    resp.setContentType("text/xml;charset=utf-8");
    PrintWriter out = resp.getWriter();
    SAXReader reader = new SAXReader();
    try {
        document = reader.read(pluginStream);
        out.print(document.asXML());
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.funtl.framework.alipay.trade.util.AlipaySubmit.java

License:Apache License

/**
 * ?query_timestamp???/*from w ww  .j a  v  a 2s.  c  om*/
 * ??XML???SSL?
 *
 * @return 
 * @throws IOException
 * @throws DocumentException
 * @throws MalformedURLException
 */
public static String query_timestamp() throws MalformedURLException, DocumentException, IOException {

    //query_timestamp?URL
    String strUrl = PayManager.HTTPS_MAPI_ALIPAY_COM_GATEWAY_DO + "?" + "service=query_timestamp&partner="
            + AlipayConfig.partner + "&_input_charset" + AlipayConfig.input_charset;
    StringBuffer result = new StringBuffer();

    SAXReader reader = new SAXReader();
    Document doc = reader.read(new URL(strUrl).openStream());

    List<Node> nodeList = doc.selectNodes("//alipay/*");

    for (Node node : nodeList) {
        // ?????
        if (node.getName().equals("is_success") && node.getText().equals("T")) {
            // ??
            List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*");
            for (Node node1 : nodeList1) {
                result.append(node1.getText());
            }
        }
    }

    return result.toString();
}

From source file:com.fxdigital.manager.SoftInfoImpl.java

/**
 * ???/* w  w w  .j  a v a  2 s.c o  m*/
 * 
 * @return
 */
public String getDeviceType() {
    String type = null;
    String path = getPath();
    if (path == null) {
        return "?";
    }
    File f = new File(path);
    SAXReader reader = new SAXReader();
    try {
        Document doc = reader.read(f);
        Element root = doc.getRootElement();
        type = root.attributeValue("DeviceType");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return type;
}

From source file:com.fxdigital.manager.SoftInfoImpl.java

/**
 * ??//  ww w . j a  v a2 s. c  o m
 * 
 * @return
 */
public String getSoftVersion() {
    String version = null;
    String path = getPath();
    if (path == null) {
        return "?";
    }
    File f = new File(path);
    SAXReader reader = new SAXReader();
    try {
        Document doc = reader.read(f);
        Element root = doc.getRootElement();
        version = root.attributeValue("version");
        version = "V" + version;
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (version == null)
        version = "V1.0";
    return version;
}

From source file:com.fxdigital.manager.SoftInfoImpl.java

/**
 * ??/* www . j a va  2 s  .  c  om*/
 * 
 * @return
 */
public String getLicenseTime() {
    String time = null;
    String path = getPath();
    if (path == null) {
        return "?";
    }
    File f = new File(path);
    SAXReader reader = new SAXReader();
    try {
        Document doc = reader.read(f);
        Element root = doc.getRootElement();
        time = root.attributeValue("SerialNumber");
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (time != null && time.length() >= 14) {
        time = time.substring(0, 4) + "-" + time.substring(4, 6) + "-" + time.substring(6, 8) + " "
                + time.substring(8, 10) + ":" + time.substring(10, 12) + ":" + time.substring(12, 14);
    }

    return time;
}

From source file:com.genericworkflownodes.knime.config.impl.GalaxyNodeConfigurationReader.java

License:Open Source License

@Override
public INodeConfiguration read(InputStream in) throws Exception {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser parser = factory.newSAXParser();

    SAXReader reader = new SAXReader(parser.getXMLReader());
    reader.setValidation(false);//from  w  w w. java 2  s.c  o  m

    SimpleErrorHandler errorHandler = new SimpleErrorHandler();

    reader.setErrorHandler(errorHandler);

    doc = reader.read(in);

    if (!errorHandler.isValid()) {
        System.err.println(errorHandler.getErrorReport());
        throw new Exception("Galaxy tool xml file is not valid !");
    }

    readPorts();
    readParameters();
    readDescription();

    config.setXml(doc.asXML());

    return config;
}

From source file:com.genericworkflownodes.knime.schemas.SchemaValidator.java

License:Open Source License

/**
 * Validate the given xml stream against the stored schemata.
 * /*w  ww. ja v a 2 s.  c o m*/
 * @param xmlstream
 *            The stream to validate.
 * @return True if the file is valid, false otherwise.
 */
public boolean validates(InputStream xmlstream) {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");

    SimpleErrorHandler errorHandler = new SimpleErrorHandler();

    try {
        factory.setSchema(schemaFactory.newSchema(getSchemaSources()));

        SAXParser parser = factory.newSAXParser();

        SAXReader reader = new SAXReader(parser.getXMLReader());
        reader.setValidation(false);

        reader.setErrorHandler(errorHandler);

        reader.read(xmlstream);
    } catch (SAXException e) {
        throw new RuntimeException(e);
    } catch (DocumentException e) {
        throw new RuntimeException(e);
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    }

    if (!errorHandler.isValid()) {
        errorReport = errorHandler.getErrorReport();
        return false;
    }

    return true;
}

From source file:com.gi.desktop.maptool.dialog.MapServiceConfDialog.java

License:Open Source License

@SuppressWarnings("unchecked")
private void loadAgsSchema() {
    JFileChooser dialog = getJFileChooserAgsSchema();
    int val = dialog.showOpenDialog(this);
    if (val == JFileChooser.APPROVE_OPTION) {
        File agsSchema = dialog.getSelectedFile();
        try {// www  .j  a v  a  2  s  .co  m
            FileInputStream in = new FileInputStream(agsSchema);
            SAXReader saxReader = new SAXReader();
            Document document = saxReader.read(in);
            Element root = document.getRootElement();
            Element eTileCacheInfo = root.element("TileCacheInfo");

            Element eTileOrigin = eTileCacheInfo.element("TileOrigin");
            this.jTextFieldOriginX.setText(eTileOrigin.elementText("X"));
            this.jTextFieldOriginY.setText(eTileOrigin.elementText("Y"));

            this.jTextFieldWidth.setText(eTileCacheInfo.elementText("TileCols"));
            this.jTextFieldHeight.setText(eTileCacheInfo.elementText("TileRows"));

            jListLevelsModel.removeAllElements();
            Element eLODInfos = eTileCacheInfo.element("LODInfos");
            for (Iterator iLODInfos = eLODInfos.elementIterator(); iLODInfos.hasNext();) {
                Element eLODInfo = (Element) iLODInfos.next();
                TileLodInfo tileLodInfo = new TileLodInfo();
                tileLodInfo.setLevel(Integer.valueOf(eLODInfo.elementText("LevelID")));
                tileLodInfo.setScale(Double.valueOf(eLODInfo.elementText("Scale")));
                tileLodInfo.setResolution(Double.valueOf(eLODInfo.elementText("Resolution")));

                LodItem item = new LodItem();
                item.setTileLodInfo(tileLodInfo);
                jListLevelsModel.addElement(item);
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Load Error!");
        }
    }
}

From source file:com.github.autoprimer3.AutoPrimer3Config.java

License:Open Source License

public void readGenomeXmlFile(File xml) throws IOException, DocumentException {
    SAXReader reader = new SAXReader();
    Document doc = reader.read(xml);
    buildsAndTables.setDasGenomeXmlDocument(doc);
    buildsAndTables.readDasGenomeXmlDocument();
    setBuildToDescription(buildsAndTables.getBuildToDescription());
    setBuildToMapMaster(buildsAndTables.getBuildToMapMaster());

}

From source file:com.github.autoprimer3.AutoPrimer3Config.java

License:Open Source License

public Document getBuildXmlDocument(String build, Boolean forceRefresh)
        throws DocumentException, MalformedURLException, IOException {
    SAXReader reader = new SAXReader();
    File f = getBuildXmlFile(build);
    if (!f.exists() || forceRefresh) {
        Document dasXml = buildsAndTables.getTableXmlDocument(build);
        writeTableXmlFile(dasXml, build);
    }//www.  jav a2  s. c o m
    return reader.read(f);
}