Example usage for org.dom4j Element elements

List of usage examples for org.dom4j Element elements

Introduction

In this page you can find the example usage for org.dom4j Element elements.

Prototype

List<Element> elements(QName qName);

Source Link

Document

Returns the elements contained in this element with the given fully qualified name.

Usage

From source file:com.liferay.portlet.PortletPreferencesSerializer.java

License:Open Source License

public static PortletPreferences fromDefaultXML(String xml) throws PortalException, SystemException {

    PortletPreferencesImpl prefs = new PortletPreferencesImpl();

    if (Validator.isNull(xml)) {
        return prefs;
    }//w  w  w. j ava2 s . c  o  m

    Map preferences = prefs.getPreferences();

    try {
        Document doc = new SAXReader().read(new StringReader(xml));

        Element root = doc.getRootElement();

        Iterator itr1 = root.elements("preference").iterator();

        while (itr1.hasNext()) {
            Element prefEl = (Element) itr1.next();

            String name = prefEl.elementTextTrim("name");

            List values = new ArrayList();

            Iterator itr2 = prefEl.elements("value").iterator();

            while (itr2.hasNext()) {
                Element valueEl = (Element) itr2.next();

                /*if (valueEl.nodeCount() <= 0) {
                   values.add(valueEl.getText());
                }
                else {
                   values.add(valueEl.node(0).asXML());
                }*/

                values.add(valueEl.getTextTrim());
            }

            boolean readOnly = GetterUtil.get(prefEl.elementText("read-only"), false);

            Preference preference = new Preference(name, (String[]) values.toArray(new String[0]), readOnly);

            preferences.put(name, preference);
        }

        return prefs;
    } catch (DocumentException de) {
        throw new SystemException(de);
    }
}

From source file:com.liferay.util.log4j.Log4JUtil.java

License:Open Source License

public static void configureLog4J(URL url) {
    if (url == null) {
        return;//w  ww.j  a  v  a2  s  .com
    }

    String urlContent = _getURLContent(url);

    if (urlContent == null) {
        return;
    }

    // See LPS-6029, LPS-8865, and LPS-24280

    DOMConfigurator domConfigurator = new DOMConfigurator();

    Reader urlReader = new StringReader(urlContent);

    domConfigurator.doConfigure(urlReader, LogManager.getLoggerRepository());

    Set<String> currentLoggerNames = new HashSet<String>();

    Enumeration<Logger> enu = LogManager.getCurrentLoggers();

    while (enu.hasMoreElements()) {
        Logger logger = enu.nextElement();

        currentLoggerNames.add(logger.getName());
    }

    try {
        SAXReader saxReader = new SAXReader();

        Reader reader = new StringReader(urlContent);

        Document document = saxReader.read(reader, url.toExternalForm());

        Element rootElement = document.getRootElement();

        List<Element> categoryElements = rootElement.elements("category");

        for (Element categoryElement : categoryElements) {
            String name = categoryElement.attributeValue("name");

            Element priorityElement = categoryElement.element("priority");

            String priority = priorityElement.attributeValue("value");

            setLevel(name, priority, false);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.liferay.util.xml.XMLMerger.java

License:Open Source License

private void _orderChildren(Element parent, String[] orderedChildrenNames) {

    if (orderedChildrenNames == null) {
        return;/*from   ww w  . j  a  v a2  s.  c o  m*/
    }

    List elements = new ArrayList();

    for (int i = 0; i < orderedChildrenNames.length; i++) {
        elements.addAll(parent.elements(orderedChildrenNames[i]));
    }

    for (int i = 0; i < elements.size(); i++) {
        Element el = (Element) elements.get(i);
        el.detach();
        parent.add(el);
    }
}

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

License:Open Source License

public boolean getMenuBar(String menuId, javax.swing.JMenuBar menuBar, javax.swing.JComponent component) {
    if (!Char.isValidate(menuId) || document == null) {
        return false;
    }//from   w  w w .j  av a  2s .c  o m
    Node node = document.getRootElement().selectSingleNode(Char.format("/magicpwd/menubar[@id='{0}']", menuId));
    if (node == null || !(node instanceof Element)) {
        return false;
    }
    Element element = (Element) node;

    java.util.List elementList = element.elements("menu");
    if (elementList == null || elementList.size() < 1) {
        return false;
    }

    menuBar.setName(menuId);

    Element tmp;
    for (Object obj : elementList) {
        if (!(obj instanceof Element)) {
            continue;
        }
        tmp = (Element) obj;
        javax.swing.JMenu menu = createMenu(tmp, component, null);
        if (menu == null) {
            continue;
        }
        menuBar.add(menu);
    }

    final String KEY_SKIN = "skin";
    if (buttons.containsKey(KEY_SKIN)) {
        javax.swing.JMenu skin = (javax.swing.JMenu) buttons.get(KEY_SKIN);
        if (skin == null) {
            skin = new javax.swing.JMenu();
            menuBar.add(skin);
        }
        loadSkin(skin);
    }
    return true;
}

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

License:Open Source License

private javax.swing.AbstractButton processIcon(Element element, javax.swing.AbstractButton button) {
    java.util.List elements = element.elements("icon");
    if (elements == null || elements.size() < 1) {
        return button;
    }//from  ww  w.  ja va 2  s.  co m
    element = (Element) elements.get(0);
    Element temp = element.element("default");
    if (temp != null) {
        button.setIcon(createIcon(temp));
    }

    temp = element.element("pressed");
    if (temp != null) {
        button.setPressedIcon(createIcon(temp));
    }

    temp = element.element("rollover");
    if (temp != null) {
        button.setRolloverIcon(createIcon(temp));
    }

    temp = element.element("disabled");
    if (temp != null) {
        button.setDisabledIcon(createIcon(temp));
    }
    return button;
}

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

License:Open Source License

private static javax.swing.AbstractButton processStrokes(Element element, javax.swing.AbstractButton button,
        javax.swing.Action action, javax.swing.JComponent component) {
    java.util.List list = element.elements("stroke");
    if (list == null || list.size() < 1) {
        return button;
    }//from   ww  w . ja  v  a2  s.c  om

    for (int i = 0, j = list.size(); i < j; i += 1) {
        String temp = ((Element) list.get(i)).attributeValue("key");
        if (Char.isValidate(temp)) {
            temp = temp.toUpperCase().replaceAll("~|SHIFT", "shift").replaceAll("\\^|CONTROL|CTRL", "control")
                    .replaceAll("#|ALT", "alt").replaceAll("!|META", "meta")
                    .replaceAll("[^-=`;',./\\[\\]a-zA-Z0-9]+", " ").trim();
            javax.swing.KeyStroke stroke = javax.swing.KeyStroke.getKeyStroke(temp);
            if (component != null) {
                Bean.registerKeyStrokeAction(component, stroke, action, temp,
                        javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW);
            }
            if (button != null && i == 0 && (button instanceof javax.swing.JMenuItem)) {
                ((javax.swing.JMenuItem) button).setAccelerator(stroke);
            }
        }
    }
    return button;
}

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

License:Open Source License

private javax.swing.AbstractButton processAction(Element element, javax.swing.AbstractButton button,
        javax.swing.JComponent component) {
    java.util.List list = element.elements("action");
    if (list == null || list.size() < 1) {
        return button;
    }/*from w w w .  j  a v a2s  .co m*/
    String btnInit = element.attributeValue("init");

    for (int i = 0, j = list.size(); i < j; i += 1) {
        element = (Element) list.get(i);
        String name = element.attributeValue("id");
        boolean validate = Char.isValidate(name);
        javax.swing.Action action = validate ? actions.get(name) : null;
        if (action == null) {
            String type = element.attributeValue("class");
            if (Char.isValidate(type)) {
                try {
                    Object obj = Class.forName(type).newInstance();
                    if (obj instanceof javax.swing.Action) {
                        action = (javax.swing.Action) obj;
                        if (action instanceof IAction) {
                            IAction iAction = (IAction) action;
                            iAction.setTrayPtn(trayPtn);
                            String actInit = element.attributeValue("init");

                            if (action instanceof ITrayAction) {
                                ITrayAction trayAction = (ITrayAction) action;
                                trayAction.setTrayPtn(trayPtn);
                                trayAction.doInit(actInit);
                            } else if (action instanceof IMproAction) {
                                IMproAction mproAction = (IMproAction) action;
                                mproAction.setTrayPtn(trayPtn);
                                mproAction.setMproPtn((MproPtn) trayPtn.getMpwdPtn(AppView.mpro));
                                mproAction.doInit(actInit);
                            } else if (action instanceof IMwizAction) {
                                IMwizAction mwizAction = (IMwizAction) action;
                                mwizAction.setTrayPtn(trayPtn);
                                mwizAction.setMwizPtn((MwizPtn) trayPtn.getMpwdPtn(AppView.mwiz));
                                mwizAction.doInit(actInit);
                            } else if (action instanceof IMpadAction) {
                                IMpadAction mpadAction = (IMpadAction) action;
                                mpadAction.setTrayPtn(trayPtn);
                                mpadAction.setMpadPtn((MpadPtn) trayPtn.getMpwdPtn(AppView.mpad));
                                mpadAction.doInit(actInit);
                            } else if (action instanceof IMaocAction) {
                                IMaocAction maocAction = (IMaocAction) action;
                                maocAction.setTrayPtn(trayPtn);
                                maocAction.setMaocPtn((MaocPtn) trayPtn.getMpwdPtn(AppView.maoc));
                                maocAction.doInit(actInit);
                            } else if (action instanceof IMrucAction) {
                                IMrucAction mrucAction = (IMrucAction) action;
                                mrucAction.setTrayPtn(trayPtn);
                                mrucAction.setMrucPtn((MrucPtn) trayPtn.getMpwdPtn(AppView.mruc));
                                mrucAction.doInit(actInit);
                            } else if (action instanceof IMgtdAction) {
                                IMgtdAction mgtdAction = (IMgtdAction) action;
                                mgtdAction.setTrayPtn(trayPtn);
                                mgtdAction.setMgtdPtn((MgtdPtn) trayPtn.getMpwdPtn(AppView.mgtd));
                                mgtdAction.doInit(actInit);
                            }
                        }
                        if (validate) {
                            actions.put(name, action);
                        }
                    }
                } catch (Exception ex) {
                    Logs.exception(ex);
                    Lang.showMesg(trayPtn.getMpwdPtn(), null, ex.getLocalizedMessage());
                }
            }
        }
        if (button != null) {
            button.addActionListener(action);
        }
        if (action instanceof IAction) {
            ((IAction) action).reInit(button, btnInit);
        }
        processStrokes(element, button, action, component);
        processReference(element, button, action);
    }
    return button;
}

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

License:Open Source License

private javax.swing.AbstractButton processReference(Element element, javax.swing.AbstractButton button,
        javax.swing.Action action) {
    if (button == null) {
        return button;
    }//  ww w.j av a2 s.  c o m
    java.util.List list = element.elements("property");
    if (list == null || list.size() < 1) {
        return button;
    }

    String name;
    String refId;
    for (int i = 0, j = list.size(); i < j; i += 1) {
        element = (Element) list.get(i);

        // ?
        name = element.attributeValue("name");
        if (!Char.isValidate(name)) {
            continue;
        }

        // ?
        refId = element.attributeValue("ref-id");
        if (!Char.isValidate(refId)) {
            continue;
        }

        // 
        action = actions.get(refId);
        if (action == null) {
            continue;
        }

        try {
            java.lang.reflect.Method method = button.getAction().getClass()
                    .getDeclaredMethod("set" + Char.lUpper(name), java.net.URL.class);
            if (method != null) {
                method.invoke(button.getAction(), action);
            }
        } catch (Exception exp) {
            Logs.exception(exp);
        }
    }
    return button;
}

From source file:com.ms.commons.test.datareader.impl.XmlReaderUtil.java

License:Open Source License

@SuppressWarnings("unchecked")
protected static MemoryTable readTable(Element tableE) {
    String name = tableE.attributeValue("name");
    MemoryTable table = new MemoryTable(name);

    List<Element> elements = tableE.elements("row");
    List<MemoryRow> rowList = new ArrayList<MemoryRow>();
    for (Element rowE : elements) {
        rowList.add(readRow(rowE));/*from w  ww  .j  a  v  a2s. co m*/
    }
    table.setRowList(rowList);
    return table;
}