Example usage for org.dom4j.io SAXReader SAXReader

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

Introduction

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

Prototype

public SAXReader() 

Source Link

Usage

From source file:com.magicpwd._util.Util.java

License:Open Source License

public static boolean checkUpdate(String sid, String ver) throws Exception {
    if (!Char.isValidate(sid, 8)) {
        throw new IOException("??");
    }/*  w  w  w.  java2 s .  co  m*/
    if (!Char.isValidate(ver)) {
        throw new IOException("??");
    }

    // ?
    Document document = new SAXReader().read(new URL(ConsEnv.HOMEPAGE + "soft/soft0001.ashx?sid=" + sid));
    Node node = document.selectSingleNode("/amonsoft/version");
    if (node == null) {
        throw new Exception("???");
    }

    // ?
    String tmp = node.getText();
    if (!Char.isValidate(tmp)) {
        return false;
    }
    tmp = tmp.toUpperCase().replaceAll("\\s+", "");
    if (tmp.charAt(0) == 'V') {
        tmp = tmp.substring(1);
    }
    String[] newVer = tmp.split("\\.");

    // ??
    ver = ver.toUpperCase().replaceAll("\\s+", "");
    if (ver.charAt(0) == 'V') {
        ver = ver.substring(1);
    }
    String[] oldVer = ver.split("\\.");

    if (newVer == null || newVer.length != 4 || newVer.length != oldVer.length) {
        return false;
    }

    for (int i = 0; i < newVer.length; i += 1) {
        if (oldVer[i].length() < newVer[i].length()) {
            return true;
        }
        int x = oldVer[i].compareTo(newVer[i]);
        if (x > 0) {
            return false;
        }
        if (x < 0) {
            return true;
        }
    }

    return false;
}

From source file:com.maomao.framework.utils.XmlUtils.java

License:Apache License

@SuppressWarnings("rawtypes")
public SAXReader createSAXReader(String file, List errorsList, EntityResolver entityResolver) {
    if (saxReader == null)
        saxReader = new SAXReader();
    saxReader.setEntityResolver(NONE_DTD_RESOLVER);
    saxReader.setErrorHandler(new ErrorLogger(file, errorsList));
    saxReader.setMergeAdjacentText(true);
    saxReader.setValidation(false);/*from  www  . ja v a 2 s .  co  m*/
    return saxReader;
}

From source file:com.marklogic.client.example.handle.DOM4JHandle.java

License:Apache License

protected SAXReader makeReader() {
    SAXReader reader = new SAXReader();
    reader.setValidation(false);
    return reader;
}

From source file:com.marklogic.client.example.handle.DOM4JHandleExample.java

License:Apache License

public static void runShortcut(ExampleProperties props) throws IOException, DocumentException {
    String filename = "flipper.xml";

    // register the handle from the extra library
    DatabaseClientFactory.getHandleRegistry().register(DOM4JHandle.newFactory());

    // create the client
    DatabaseClient client = DatabaseClientFactory.newClient(props.host, props.port, props.writerUser,
            props.writerPassword, props.authType);

    // create a manager for documents of any format
    XMLDocumentManager docMgr = client.newXMLDocumentManager();

    // read the example file
    InputStream docStream = Util.openStream("data" + File.separator + filename);
    if (docStream == null)
        throw new IOException("Could not read document example");

    // create an identifier for the document
    String docId = "/example/" + filename;

    // parse the example file with dom4j
    SAXReader reader = new SAXReader();
    reader.setValidation(false);//from  w  w w. j  a v  a  2 s  .  c om
    Document writeDocument = reader.read(new InputStreamReader(docStream, "UTF-8"));

    // write the document
    docMgr.writeAs(docId, writeDocument);

    // ... at some other time ...

    // read the document content
    Document readDocument = docMgr.readAs(docId, Document.class);

    String rootName = readDocument.getRootElement().getName();

    // delete the document
    docMgr.delete(docId);

    System.out.println("(Shortcut) Wrote and read /example/" + filename + " content with the <" + rootName
            + "/> root element using dom4j");

    // release the client
    client.release();
}

From source file:com.mg.framework.support.ui.UIProducer.java

License:Open Source License

private static Form doProduceForm(URL url, String formName, RuntimeMacrosLoader runtimeMacrosLoader) {
    if (url == null)
        throw new ApplicationException(Messages.getInstance().getMessage(Messages.FORM_DESCRIPTOR_NOT_FOUND,
                new Object[] { formName }));

    SAXReader reader = new SAXReader();

    try {/*from  ww  w.j a  va  2 s.c o  m*/
        return parseFormDescription(reader.read(url), formName, runtimeMacrosLoader);
    } catch (DocumentException e) {
        throw new ApplicationException(e);
    }
}

From source file:com.mg.framework.support.ui.UIProducer.java

License:Open Source License

public static Document loadMacros(String name) {
    try {//from   www.ja v a  2s .  co  m
        URL macros = loadFormDescription(name);
        if (macros == null)
            throw new ApplicationException(String.format("Macros %s not found", name));
        return new SAXReader().read(macros);
    } catch (DocumentException e) {
        throw new ApplicationException(e);
    }
}

From source file:com.mg.framework.support.ui.UIProducer.java

License:Open Source License

public static Document loadRuntimeMacros(String name, RuntimeMacrosLoader runtimeMacrosLoader) {
    try {/*w w w  .j  a va 2  s.  c  o m*/
        String macros = null;
        if (runtimeMacrosLoader != null)
            macros = runtimeMacrosLoader.loadMacros(name);
        //?   ?,  ?  ?
        if (macros == null)
            macros = "<jfd:empty-macros xmlns:jfd=\"http://xmlns.m-g.ru/jet/ui\" />";
        return new SAXReader().read(new StringReader(macros));
    } catch (DocumentException e) {
        throw new ApplicationException(e);
    }
}

From source file:com.mg.framework.support.ui.XMLMenuLoader.java

License:Open Source License

public XMLMenuLoader(AbstractHandler handler, URL descriptor, Locale locale) {
    handler.loader = this;

    if (descriptor != null)
        this.descriptor = descriptor;
    else/* w  w  w .  j av a  2  s.  com*/
        try {
            this.descriptor = new File(ServerUtils.MBSA_CUSTOM_LOCATION.concat(GLOBAL_MENU)).toURI().toURL();
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("Menu descriptor not found", e); //$NON-NLS-1$
        }

    if (this.descriptor == null)
        throw new IllegalArgumentException("Menu descriptor is null"); //$NON-NLS-1$

    if (locale != null)
        localeStr = locale.toString();

    parser = new SAXReader();
    parser.setDefaultHandler(handler);
}

From source file:com.mindquarry.desktop.model.ModelBase.java

License:Open Source License

protected Document parseInput(InputStream data) {
    SAXReader reader = new SAXReader();
    try {//w  ww .  j  a v  a 2s.co  m
        return reader.read(data);
    } catch (DocumentException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.ming800.core.p.service.impl.JmenuManagerImpl.java

private static void initMenu() {
    menuHashMap = new HashMap<>();
    File tempFile = new File(JmenuManagerImpl.class.getClassLoader().getResource("/").getPath());
    String tempFileName = tempFile.getParentFile().getParentFile().getParentFile().getParentFile()
            .getParentFile().getPath();//from www.j a v  a2  s  .  c o  m

    File dir_standard = new File(tempFileName + "/home/setting3/jmenu_standard.xml");
    File dir_professional = new File(tempFileName + "/home/setting3/jmenu_professional.xml");
    File dir_advance = new File(tempFileName + "/home/setting3/jmenu_advance.xml");
    File dir_edu = new File(tempFileName + "/home/setting3/jmenu_edu.xml");

    /*? setting3,  ?  ?setting2  ??setting*/
    Document infoDocument_standard = null;
    if (dir_standard.exists()) {
        try {
            infoDocument_standard = new SAXReader().read(dir_standard);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (infoDocument_standard == null) {
        infoDocument_standard = ResourcesUtil.getDocument(MENU_STANDARD);
    }

    Document infoDocument_professional = null;
    if (dir_professional.exists()) {
        try {
            infoDocument_professional = new SAXReader().read(dir_professional);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (infoDocument_professional == null) {
        infoDocument_professional = ResourcesUtil.getDocument(MENU_PROFESSIONAL);
    }

    Document infoDocument_advance = null;
    if (dir_advance.exists()) {
        try {
            infoDocument_advance = new SAXReader().read(dir_advance);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (infoDocument_advance == null) {
        infoDocument_advance = ResourcesUtil.getDocument(MENU_ADVANCE);
    }

    Document infoDocument_edu = null;
    if (dir_edu.exists()) {
        try {
            infoDocument_edu = new SAXReader().read(dir_edu);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (infoDocument_edu == null) {
        infoDocument_edu = ResourcesUtil.getDocument(MENU_EDU);
    }

    Menu menu_standard = initJmenuMap(infoDocument_standard);
    Menu menu_professional = initJmenuMap(infoDocument_professional);
    Menu menu_advance = initJmenuMap(infoDocument_advance);
    Menu menu_edu = initJmenuMap(infoDocument_edu);

    menuHashMap.put(menu_standard.getName(), menu_standard);
    menuHashMap.put(menu_professional.getName(), menu_professional);
    menuHashMap.put(menu_advance.getName(), menu_advance);
    menuHashMap.put(menu_edu.getName(), menu_edu);
}