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.v.app.MenuPtn.java

License:Open Source License

public boolean loadData(java.io.InputStream stream) throws Exception {
    pattern = java.util.regex.Pattern.compile("^[$]P30F[A-F0-9]{4}$", java.util.regex.Pattern.CASE_INSENSITIVE);
    document = new SAXReader().read(stream);
    return document != null;
}

From source file:com.magicpwd.v.app.MenuPtn.java

License:Open Source License

private void loadLook(javax.swing.JMenu skinMenu) {
    javax.swing.JMenu lookMenu = new javax.swing.JMenu();
    Bean.setText(lookMenu, Lang.getLang(LangRes.P30F763B, ""));
    skinMenu.add(lookMenu);//from w  w  w.ja  va2 s.  co  m

    java.io.File lookFile = new java.io.File(ConsEnv.DIR_SKIN, ConsEnv.DIR_LOOK);
    if (!lookFile.exists() || !lookFile.isDirectory() || !lookFile.canRead()) {
        return;
    }

    javax.swing.JCheckBoxMenuItem item;
    String lookName = userMdl.getLook();
    LookAction action = new LookAction();
    action.setMproPtn((MproPtn) trayPtn.getMpwdPtn(AppView.mpro));
    WButtonGroup group = new WButtonGroup();

    // Java
    java.io.File defaultSkin = new java.io.File(lookFile,
            ConsEnv.SKIN_LOOK_DEF_DIR + '/' + ConsEnv.SKIN_LOOK_FILE);
    if (defaultSkin.exists() && defaultSkin.isFile() && defaultSkin.canRead()) {
        item = new javax.swing.JCheckBoxMenuItem();
        item.addActionListener(action);
        Bean.setText(item, Lang.getLang(LangRes.P30F7632, "?"));
        Bean.setTips(item, "");
        item.setActionCommand(ConsCfg.DEF_SKIN_LOOK_DEF + ".Default");
        item.setSelected(lookName.equals(ConsCfg.DEF_SKIN_LOOK_DEF));
        lookMenu.add(item);
        group.add(item.getActionCommand(), item);
    }

    // 
    java.io.File sytemSkin = new java.io.File(lookFile,
            ConsEnv.SKIN_LOOK_SYS_DIR + '/' + ConsEnv.SKIN_LOOK_FILE);
    if (sytemSkin.exists() && sytemSkin.isFile() && sytemSkin.canRead()) {
        item = new javax.swing.JCheckBoxMenuItem();
        item.addActionListener(action);
        Bean.setText(item, Lang.getLang(LangRes.P30F7633, "?"));
        Bean.setTips(item, "");
        item.setActionCommand(ConsCfg.DEF_SKIN_LOOK_SYS + ".System");
        item.setSelected(lookName.equals(ConsCfg.DEF_SKIN_LOOK_SYS));
        lookMenu.add(item);
        group.add(item.getActionCommand(), item);
    }

    java.io.File dirs[] = lookFile
            .listFiles(new AmonFF(true, ConsEnv.SKIN_LOOK_DEF_DIR, ConsEnv.SKIN_LOOK_SYS_DIR));
    if (dirs != null && dirs.length > 0) {
        lookMenu.addSeparator();
        String os = Util.isWindows() ? "win" : (Util.isMac() ? "mac" : "lin");

        for (java.io.File dir : dirs) {
            java.io.File aml = new java.io.File(dir, ConsEnv.SKIN_LOOK_FILE);
            if (!aml.exists() || !aml.isFile() || !aml.canRead()) {
                continue;
            }
            try {
                Document doc = new SAXReader().read(new java.io.FileInputStream(aml));
                if (doc == null) {
                    continue;
                }
                Element root = doc.getRootElement();
                if (root == null) {
                    continue;
                }
                Element look = root.element("look");
                if (look == null) {
                    continue;
                }
                java.util.List<?> items = look.elements("item");
                if (items == null || items.size() < 1) {
                    continue;
                }
                if (items.size() == 1) {
                    Element element = look.element("item");

                    item = new javax.swing.JCheckBoxMenuItem();
                    item.addActionListener(action);
                    Bean.setText(item, getLang(element.attributeValue("text")));
                    Bean.setTips(item, getLang(element.attributeValue("tips")));
                    String id = dir.getName() + '.' + element.attributeValue("id");
                    item.setSelected(lookName.equals(id));
                    item.setActionCommand(id);
                    lookMenu.add(item);
                    group.add(item.getActionCommand(), item);
                } else {
                    String grpText = getLang(look.attributeValue("group"));
                    if (!com.magicpwd._util.Char.isValidate(grpText)) {
                        grpText = dir.getName();
                    }
                    javax.swing.JMenu subMenu = new javax.swing.JMenu();
                    Bean.setText(subMenu, grpText);
                    lookMenu.add(subMenu);

                    for (Object object : items) {
                        if (!(object instanceof Element)) {
                            continue;
                        }
                        Element element = (Element) object;
                        String platform = element.attributeValue("platform");
                        if (Char.isValidate(platform) && platform.toLowerCase().indexOf(os) < 0) {
                            continue;
                        }

                        item = new javax.swing.JCheckBoxMenuItem();
                        item.addActionListener(action);
                        Bean.setText(item, getLang(element.attributeValue("text")));
                        Bean.setTips(item, getLang(element.attributeValue("tips")));
                        String id = dir.getName() + '.' + element.attributeValue("id");
                        item.setSelected(lookName.equals(id));
                        item.setActionCommand(id);
                        subMenu.add(item);
                        group.add(item.getActionCommand(), item);
                    }
                }
            } catch (Exception exp) {
                Logs.exception(exp);
            }
        }
    }

    lookMenu.addSeparator();

    javax.swing.JMenuItem moreLook = new javax.swing.JMenuItem();
    Bean.setText(moreLook, Lang.getLang(LangRes.P30F763C, ""));
    //        Bean.setTips(moreSkin, Lang.getLang("", "tips"));
    moreLook.setActionCommand(ConsEnv.HOMEPAGE + "mpwd/mpwd0101.aspx?sid=" + ConsEnv.VERSIONS);
    moreLook.addActionListener(new MoreAction());
    lookMenu.add(moreLook);
}

From source file:com.magicpwd._bean.mpro.GuidBean.java

License:Open Source License

public void exptCardActionPerformed(java.awt.event.ActionEvent evt) {
    if (processing) {
        return;//ww w  .j  a va2 s  .  c o m
    }

    processing = true;
    if (fileTM == null) {
        fileTM = new FileTM("card", Pattern.compile("[^.]+[.]amc$", Pattern.CASE_INSENSITIVE), false);

        pm_CardMenu = new javax.swing.JPopupMenu();
        mu_HtmMenu = new javax.swing.JMenu("HTM");
        mu_TxtMenu = new javax.swing.JMenu("TXT");
        mu_PngMenu = new javax.swing.JMenu("PNG");
        mu_SvgMenu = new javax.swing.JMenu("SVG");

        al_Listener = new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cardItemActionPerformed(evt);
            }
        };
    }
    if (fileTM.checkModified()) {
        pm_CardMenu.removeAll();

        mu_HtmMenu.removeAll();
        pm_CardMenu.add(mu_HtmMenu);

        mu_TxtMenu.removeAll();
        pm_CardMenu.add(mu_TxtMenu);

        mu_PngMenu.removeAll();
        pm_CardMenu.add(mu_PngMenu);

        mu_SvgMenu.removeAll();
        pm_CardMenu.add(mu_SvgMenu);

        SAXReader reader = new SAXReader();
        javax.swing.JMenuItem item;
        for (java.io.File cardFile : fileTM.getFileList()) {
            try {
                Document doc = reader.read(cardFile);

                Node name = doc.selectSingleNode("/magicpwd/base/name");
                item = new javax.swing.JMenuItem();
                item.addActionListener(al_Listener);
                item.setText(name != null ? name.getText() : cardFile.getName());

                Node type = doc.selectSingleNode("/magicpwd/base/type");
                if (type != null) {
                    String text = (type.getText() + "").trim().toLowerCase();
                    if (ConsEnv.CARD_HTM.equals(text)) {
                        item.setActionCommand(ConsEnv.CARD_HTM + '/' + cardFile.getPath());
                        mu_HtmMenu.add(item);
                        continue;
                    }
                    if (ConsEnv.CARD_TXT.equals(text)) {
                        item.setActionCommand(ConsEnv.CARD_TXT + '/' + cardFile.getPath());
                        mu_TxtMenu.add(item);
                        continue;
                    }
                    if (ConsEnv.CARD_PNG.equals(text)) {
                        item.setActionCommand(ConsEnv.CARD_PNG + '/' + cardFile.getPath());
                        mu_PngMenu.add(item);
                        continue;
                    }
                    if (ConsEnv.CARD_SVG.equals(text)) {
                        item.setActionCommand(ConsEnv.CARD_SVG + '/' + cardFile.getPath());
                        mu_SvgMenu.add(item);
                        continue;
                    }
                }
                item.setActionCommand(ConsEnv.CARD_ALL + '/' + cardFile.getPath());
                pm_CardMenu.add(item);
            } catch (Exception exp) {
                processing = false;
                Logs.exception(exp);
                Lang.showMesg(mainPtn, null, exp.getLocalizedMessage());
                return;
            }
        }
    }
    pm_CardMenu.show(bt_ExptCard, 0, bt_ExptCard.getPreferredSize().height);

    processing = false;
}

From source file:com.magicpwd._bean.mwiz.GuidBean.java

License:Open Source License

public void exptCardActionPerformed(java.awt.event.ActionEvent evt) {
    if (processing) {
        return;//  ww  w .j  av a2  s .  c om
    }

    processing = true;
    if (fileTM == null) {
        fileTM = new FileTM("card", Pattern.compile("[^.]+[.]amc$", Pattern.CASE_INSENSITIVE), false);

        pm_CardMenu = new javax.swing.JPopupMenu();
        mu_HtmMenu = new javax.swing.JMenu("HTM");
        mu_TxtMenu = new javax.swing.JMenu("TXT");
        mu_PngMenu = new javax.swing.JMenu("PNG");
        mu_SvgMenu = new javax.swing.JMenu("SVG");

        al_Listener = new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cardItemActionPerformed(evt);
            }
        };
    }
    if (fileTM.checkModified()) {
        pm_CardMenu.removeAll();

        mu_HtmMenu.removeAll();
        pm_CardMenu.add(mu_HtmMenu);

        mu_TxtMenu.removeAll();
        pm_CardMenu.add(mu_TxtMenu);

        mu_PngMenu.removeAll();
        pm_CardMenu.add(mu_PngMenu);

        mu_SvgMenu.removeAll();
        pm_CardMenu.add(mu_SvgMenu);

        SAXReader reader = new SAXReader();
        javax.swing.JMenuItem item;
        for (java.io.File cardFile : fileTM.getFileList()) {
            try {
                Document doc = reader.read(cardFile);

                Node name = doc.selectSingleNode("/magicpwd/base/name");
                item = new javax.swing.JMenuItem();
                item.addActionListener(al_Listener);
                item.setText(name != null ? name.getText() : cardFile.getName());

                Node type = doc.selectSingleNode("/magicpwd/base/type");
                if (type != null) {
                    String text = (type.getText() + "").trim().toLowerCase();
                    if (ConsEnv.CARD_HTM.equals(text)) {
                        item.setActionCommand(ConsEnv.CARD_HTM + '/' + cardFile.getPath());
                        mu_HtmMenu.add(item);
                        continue;
                    }
                    if (ConsEnv.CARD_TXT.equals(text)) {
                        item.setActionCommand(ConsEnv.CARD_TXT + '/' + cardFile.getPath());
                        mu_TxtMenu.add(item);
                        continue;
                    }
                    if (ConsEnv.CARD_PNG.equals(text)) {
                        item.setActionCommand(ConsEnv.CARD_PNG + '/' + cardFile.getPath());
                        mu_PngMenu.add(item);
                        continue;
                    }
                    if (ConsEnv.CARD_SVG.equals(text)) {
                        item.setActionCommand(ConsEnv.CARD_SVG + '/' + cardFile.getPath());
                        mu_SvgMenu.add(item);
                        continue;
                    }
                }
                item.setActionCommand(ConsEnv.CARD_ALL + '/' + cardFile.getPath());
                pm_CardMenu.add(item);
            } catch (Exception exp) {
                processing = false;
                Logs.exception(exp);
                Lang.showMesg(normPtn, null, exp.getLocalizedMessage());
                return;
            }
        }
    }
    pm_CardMenu.show(bt_ExptCard, 0, bt_ExptCard.getPreferredSize().height);

    processing = false;
}

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

License:Open Source License

public java.io.File exportHtm(java.io.File src, java.io.File dst) throws Exception {
    Document doc = new SAXReader().read(src);

    Node node = doc.selectSingleNode("/magicpwd/card/template-res");
    String text;//from   ww  w . ja va  2 s .  co  m
    if (node != null) {
        text = node.getText();
        if (Char.isValidate(text)) {
            java.io.File tmp = new java.io.File(text);
            File.copy(tmp, new java.io.File(dst, tmp.getName()), true);
        }
    }

    node = doc.selectSingleNode("/magicpwd/card/template-uri");
    if (node == null) {
        return null;
    }
    text = node.getText();
    if (!Char.isValidate(text)) {
        return null;
    }

    return text(text, dst, ".htm");
}

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

License:Open Source License

public java.io.File exportTxt(java.io.File src, java.io.File dst) throws Exception {
    Document doc = new SAXReader().read(src);
    Node node = doc.selectSingleNode("/magicpwd/card/template-uri");
    if (node == null) {
        return null;
    }/*  ww  w .j a v  a2  s. co  m*/
    String text = node.getText();
    if (!Char.isValidate(text)) {
        return null;
    }

    return text(text, dst, ".txt");
}

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

License:Open Source License

public java.io.File exportSvg(java.io.File src, java.io.File dst) throws Exception {
    Document doc = new SAXReader().read(src);
    Node node = doc.selectSingleNode("/magicpwd/card/template-uri");
    if (node == null) {
        return null;
    }// www . j a  v  a 2s. c o m
    String text = node.getText();
    if (!Char.isValidate(text)) {
        return null;
    }

    return text(text, dst, ".svg");
}

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

License:Open Source License

public java.io.File exportAll(java.io.File src, java.io.File dst) throws Exception {
    Document doc = new SAXReader().read(src);

    Node node = doc.selectSingleNode("/magicpwd/card/template-res");
    String text;/*from w  w  w .  j  a  v a  2s  .  c  o m*/
    if (node != null) {
        text = node.getText();
        if (Char.isValidate(text)) {
            java.io.File tmp = new java.io.File(text);
            File.copy(tmp, new java.io.File(dst, tmp.getName()), true);
        }
    }

    node = doc.selectSingleNode("/magicpwd/card/template-uri");
    if (node == null) {
        return null;
    }
    text = node.getText();
    if (!Char.isValidate(text)) {
        return null;
    }

    int si = text.lastIndexOf('/');
    int di = text.lastIndexOf('.');
    String ext = "";
    if (di > si) {
        ext = text.substring(di);
    }
    return text(text, dst, ext);
}

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

License:Open Source License

public static Document load(File file) throws DocumentException {
    Document doc = new SAXReader().read(file);
    //doc.selectNodes("//students/student/@sn");
    return doc;/*from  w w  w.j  a v  a  2  s .  co m*/
}

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

License:Open Source License

private static Element getElement(java.io.File file, String name) {
    try {/*  w  w  w. j  a va 2  s.  c  o  m*/
        Document doc = new SAXReader().read(new java.io.FileInputStream(file));
        if (doc != null) {
            Element root = doc.getRootElement();
            if (root != null) {
                Node node = root.selectSingleNode(Char.format("/magicpwd/look/item[@id='{0}']", name));
                if (node instanceof Element) {
                    return (Element) node;
                }
            }
        }
    } catch (Exception exp) {
        Logs.exception(exp);
    }
    return null;
}