Example usage for org.dom4j Node getName

List of usage examples for org.dom4j Node getName

Introduction

In this page you can find the example usage for org.dom4j Node getName.

Prototype

String getName();

Source Link

Document

getName returns the name of this node.

Usage

From source file:com.log4ic.compressor.utils.MemcachedUtils.java

License:Open Source License

@SuppressWarnings("unchecked")
private static MemcachedConfig getMemcachedConfig(InputStream in) throws DocumentException {
    SAXReader reader = new SAXReader();

    MemcachedConfig config = new MemcachedConfig();

    Document doc = reader.read(in);

    logger.debug("??...");
    List<Node> nodeList = doc.selectNodes("/memcached/servers/server");
    if (nodeList.isEmpty()) {
        throw new DocumentException(CONFIG_FILE_PATH + " file memcached.servers server element empty!");
    } else {//ww  w. ja  v a2 s .c  o m
        logger.debug("???" + nodeList.size() + ".");
    }

    AddressConfig addrConf = biludAddrMapConfig(nodeList);

    config.builder = new XMemcachedClientBuilder(addrConf.addressMap, addrConf.widgets);

    Element el = (Element) doc.selectSingleNode("/memcached");
    logger.debug("??...");
    Attribute attr = el.attribute("connectionPoolSize");
    if (attr != null) {
        String connPoolSize = attr.getValue();
        if (StringUtils.isNotBlank(connPoolSize)) {
            try {
                config.builder.setConnectionPoolSize(Integer.parseInt(connPoolSize));
                logger.debug("?" + connPoolSize);
            } catch (Exception e) {
                logger.error("???", e);
            }
        } else {
            logger.error("???");
        }
    } else {
        logger.warn("??");
    }
    logger.debug("??...");
    attr = el.attribute("enableHeartBeat");
    if (attr != null) {
        String enableHeartBeatS = attr.getValue();
        if (StringUtils.isNotBlank(enableHeartBeatS)) {
            try {
                config.enableHeartBeat = Boolean.parseBoolean(enableHeartBeatS);
                logger.debug("???" + enableHeartBeatS);
            } catch (Exception e) {
                logger.error("?????", e);
            }
        } else {
            logger.error("?????");
        }
    } else {
        logger.warn("????");
    }
    logger.debug("?...");
    attr = el.attribute("sessionIdleTimeout");
    if (attr != null) {
        String sessionIdleTimeout = attr.getValue();
        if (StringUtils.isNotBlank(sessionIdleTimeout)) {
            try {
                config.builder.getConfiguration().setSessionIdleTimeout(Long.parseLong(sessionIdleTimeout));
                logger.debug("?" + sessionIdleTimeout);
            } catch (Exception e) {
                logger.error("???", e);
            }
        } else {
            logger.error("???");
        }
    } else {
        logger.warn("??");
    }
    //?
    logger.debug("?...");
    attr = el.attribute("statisticsServer");
    if (attr != null) {
        String statisticsServer = attr.getValue();
        if (StringUtils.isNotBlank(statisticsServer)) {
            try {
                config.builder.getConfiguration().setStatisticsServer(Boolean.parseBoolean(statisticsServer));
                logger.debug("?" + statisticsServer);
            } catch (Exception e) {
                logger.error("???", e);
            }
        } else {
            logger.error("???");
        }
    } else {
        logger.warn("??");
    }
    logger.debug("?...");
    attr = el.attribute("statisticsInterval");
    if (attr != null) {
        String statisticsInterval = attr.getValue();
        if (StringUtils.isNotBlank(statisticsInterval)) {
            try {
                config.builder.getConfiguration().setStatisticsInterval(Long.parseLong(statisticsInterval));
                logger.debug("?" + statisticsInterval);
            } catch (Exception e) {
                logger.error("???", e);
            }
        } else {
            logger.error("???");
        }
    } else {
        logger.warn("??");
    }
    logger.debug("????...");
    attr = el.attribute("optimizeMergeBuffer");
    if (attr != null) {
        String optimizeMergeBufferS = attr.getValue();
        if (StringUtils.isNotBlank(optimizeMergeBufferS)) {
            try {
                config.optimizeMergeBuffer = Boolean.parseBoolean(optimizeMergeBufferS);
                logger.debug("????" + optimizeMergeBufferS);
            } catch (Exception e) {
                logger.error("??????", e);
            }
        } else {
            logger.error("??????");
        }
    } else {
        logger.warn("?????");
    }
    logger.debug("??...");
    attr = el.attribute("mergeFactor");
    if (attr != null) {
        String mergeFactorS = attr.getValue();
        if (StringUtils.isNotBlank(mergeFactorS)) {
            try {
                config.mergeFactor = Integer.parseInt(mergeFactorS);
                logger.debug("?" + mergeFactorS);
            } catch (Exception e) {
                logger.error("???", e);
            }
        } else {
            logger.error("???");
        }
    } else {
        logger.warn("??");
    }
    logger.debug("??...");
    attr = el.attribute("commandFactory");
    if (attr != null) {
        String commandFactory = attr.getValue();
        if (StringUtils.isNotBlank(commandFactory)) {
            try {
                config.builder.setCommandFactory((CommandFactory) Class.forName(commandFactory).newInstance());
                logger.debug("??" + commandFactory);
            } catch (Exception e) {
                logger.error("????", e);
            }
        } else {
            logger.error("????");
        }
    } else {
        logger.warn("???");
    }
    config.builder.setCommandFactory(new BinaryCommandFactory());
    logger.debug("...");
    nodeList = doc.selectNodes("/memcached/socketOption/*");
    if (!nodeList.isEmpty()) {
        for (Node n : nodeList) {
            try {
                attr = ((Element) n).attribute("type");
                if (attr == null) {
                    logger.error("type attribute undefined");
                } else {
                    String type = attr.getValue();
                    if (StringUtils.isNotBlank(type)) {
                        String name = n.getName();
                        String value = n.getStringValue();
                        Class valueType = Class.forName(type);
                        Constructor constructor = SocketOption.class.getConstructor(String.class, Class.class);
                        SocketOption socketOption = (SocketOption) constructor.newInstance(name, valueType);
                        constructor = valueType.getConstructor(String.class);
                        config.builder.setSocketOption(socketOption, constructor.newInstance(value));
                        logger.debug("[" + name + "]" + value);
                    }
                }
            } catch (NoSuchMethodException e) {
                logger.error("NoSuchMethodException", e);
            } catch (InvocationTargetException e) {
                logger.error("InvocationTargetException", e);
            } catch (InstantiationException e) {
                logger.error("InstantiationException", e);
            } catch (IllegalAccessException e) {
                logger.error("IllegalAccessException", e);
            } catch (ClassNotFoundException e) {
                logger.error("ClassNotFoundException", e);
            }
        }
    } else {
        logger.warn("?");
    }
    logger.debug("Failure?...");
    attr = el.attribute("failureMode");
    if (attr != null) {
        String failureMode = attr.getValue();
        if (StringUtils.isNotBlank(failureMode)) {
            try {
                config.builder.setFailureMode(Boolean.parseBoolean(failureMode));
                logger.debug("Failure?" + failureMode);
            } catch (Exception e) {
                logger.error("Failure???", e);
            }
        } else {
            logger.error("Failure???");
        }
    } else {
        logger.warn("Failure??");
    }
    return config;
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.handler.MMXChannelManager.java

License:Apache License

public com.magnet.mmx.server.api.v1.protocol.ChannelInfo getChannelInfoFromNode(String appId, Node node) {
    com.magnet.mmx.server.api.v1.protocol.ChannelInfo info = new com.magnet.mmx.server.api.v1.protocol.ChannelInfo();
    info.setDescription(node.getDescription());
    info.setChannelName(node.getName());
    if (node instanceof LeafNode) {
        LeafNode lnode = (LeafNode) node;
        info.setSubscriptionEnabled(lnode.isSubscriptionEnabled());
        info.setMaxItems(lnode.isPersistPublishedItems() ? lnode.getMaxPublishedItems() : 0);
    }/*from   ww w.j a  v  a 2 s .co  m*/
    info.setChannelName(ChannelHelper.parseNode(node.getNodeID()).getName());
    info.setPublisherType(node.getPublisherModel().getName());
    return info;
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.handler.MMXChannelManager.java

License:Apache License

public ChannelInfo nodeToChannelInfo(String userId, Node node) {
    return nodeToInfo(userId, node.getName(), node);
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.handler.MMXChannelManager.java

License:Apache License

private ChannelInfo nodeToInfo(String userId, String channel, Node node) {
    ChannelInfo info = new ChannelInfo(userId, node.getName() != null ? node.getName() : channel,
            node.isCollectionNode()).setCreationDate(node.getCreationDate())
                    .setDescription(node.getDescription()).setModifiedDate(node.getModificationDate())
                    .setCreator(node.getCreator().toString())
                    .setSubscriptionEnabled(node.isSubscriptionEnabled());
    if (!node.isCollectionNode()) {
        LeafNode leafNode = (LeafNode) node;
        info.setMaxItems(leafNode.isPersistPublishedItems() ? leafNode.getMaxPublishedItems() : 0)
                .setMaxPayloadSize(leafNode.getMaxPayloadSize())
                .setPersistent(leafNode.isPersistPublishedItems())
                .setPublishPermission(ConfigureForm.convert(leafNode.getPublisherModel()));
    } else {//  ww w . ja v a 2s .c  o m
        info.setMaxItems(0).setMaxPayloadSize(0).setPersistent(false).setPublishPermission(null);
    }
    return info;
}

From source file:com.noterik.bart.fs.action.SearchAction.java

License:Open Source License

@Override
public String run() {
    // parse input
    Element element;//  w  ww  .j av  a 2  s .  c  o  m
    String eId;
    List<Element> iElements = script.getInput().getInputElements();
    for (Iterator<Element> iter = iElements.iterator(); iter.hasNext();) {
        element = iter.next();
        eId = element.attributeValue("id");
        if (eId != null && eId.equals("search")) {
            // parse properties
            Node pNode = element.selectSingleNode("properties");
            if (pNode != null) {
                List<Node> children = pNode.selectNodes("child::*");
                Node child;
                for (Iterator<Node> cIter = children.iterator(); cIter.hasNext();) {
                    child = cIter.next();
                    sProperties.put(child.getName(), child.getText());
                }
            }
        }
    }

    // check on uri
    String uri = sProperties.get("uri");
    if (uri == null) {
        logger.error("SearchAction: Required input parameters not specified");
        return null;
    }

    // build search uri
    String sUri = "", key, value;
    for (Iterator<String> iter = sProperties.keySet().iterator(); iter.hasNext();) {
        key = iter.next();
        if (!key.equals("uri")) {
            value = sProperties.get(key);
            sUri += "&" + key + "=" + value;
        }
    }
    sUri = sUri.replaceFirst("&", "?");

    // get service
    String domain = URIParser.getDomainFromUri(uri);
    Service service = ServiceHelper.getService(domain, "searchmanager");
    if (service == null) {
        logger.error("SearchAction: Service was null");
        return null;
    }

    // build final url
    String finalUrl = service.getUrl() + uri + sUri;

    logger.error("SearchAction: final url was " + finalUrl);

    // do request
    String response = HttpHelper.sendRequest("GET", finalUrl, null, null);

    // parse response
    String fsxml = parse2fsxml(response);

    logger.debug("result fsxml is " + fsxml);

    // delete old
    FSXMLRequestHandler.instance().handleDELETE(script.getID() + "/output/" + id + "/result", null);

    // save fsxml in output
    script.getOutput().setOutput(fsxml);

    return null;
}

From source file:com.noterik.bart.fs.fscommand.AddEventCommand.java

License:Open Source License

public String execute(String uri, String xml) {
    logger.debug("Add event of presentation " + uri);
    logger.debug("Add event xml " + xml);

    Document doc = XMLHelper.asDocument(xml);
    List<Node> events;
    String ticket = "";
    String user = "";

    if (doc == null) {
        logger.error("Could not parse xml");
        return FSXMLBuilder.getErrorMessage("500", "No xml found", "Please provide xml", "");
    } else {/* www . j av a 2s.  com*/
        events = doc.selectNodes("/fsxml/*");
        user = doc.selectSingleNode("//properties/user") == null ? ""
                : doc.selectSingleNode("//properties/user").getText();
        user = user.toLowerCase();
        ticket = doc.selectSingleNode("//properties/ticket") == null ? ""
                : doc.selectSingleNode("//properties/ticket").getText();
    }

    //TODO: validate ticket

    // create playlist if it does not exist
    createPlaylistIfNotExists(uri);

    for (Iterator<Node> it = events.iterator(); it.hasNext();) {
        Node event = it.next();

        if (!event.getName().equals("properties")) {
            logger.debug("received " + event.asXML());

            String starttime = event.selectSingleNode("properties/starttime") == null ? ""
                    : event.selectSingleNode("properties/starttime").getText();
            String duration = event.selectSingleNode("properties/duration") == null ? ""
                    : event.selectSingleNode("properties/duration").getText();
            String reason = event.selectSingleNode("properties/reason") == null ? ""
                    : event.selectSingleNode("properties/reason").getText();

            logger.debug("starttime = " + starttime + " duration = " + duration + " reason = " + reason);

            // determine starttime relative to beginning of video
            long stSpringfield = determineCorrectStarttime(uri, starttime);

            if (starttime.equals("") || duration.equals("") || reason.equals("")) {
                logger.error("Not all mandatory fields where provided");
                return FSXMLBuilder.getErrorMessage("500", "No all mandatory fields available",
                        "Please provide all mandatory fields in your request", "");
            }

            // create new 'bookmark'
            StringBuffer bmXml = new StringBuffer();
            bmXml.append("<fsxml>");
            bmXml.append("<properties>");
            bmXml.append("<title><![CDATA[");
            bmXml.append(reason);
            bmXml.append("]]></title>");
            bmXml.append("<description><![CDATA[");
            bmXml.append(reason);
            bmXml.append("]]></description>");
            bmXml.append("<starttime>");
            bmXml.append(stSpringfield);
            bmXml.append("</starttime>");
            bmXml.append("<duration>");
            bmXml.append(duration);
            bmXml.append("</duration>");
            bmXml.append("<creator>");
            bmXml.append(user);
            bmXml.append("</creator>");
            bmXml.append("<changedby>");
            bmXml.append(user);
            bmXml.append("</changedby>");
            bmXml.append("<lastupdate>");
            bmXml.append(LASTUPDATE_FORMAT.format(new Date()));
            bmXml.append("</lastupdate>");
            bmXml.append("</properties>");
            bmXml.append("</fsxml>");
            String bmUri = uri + "/videoplaylist/1/bookmark";
            String resp = FSXMLRequestHandler.instance().handlePOST(bmUri, bmXml.toString());
            logger.debug(resp);
        }
    }

    return FSXMLBuilder.getFSXMLStatusMessage("The properties where successfully added", "", "");
}

From source file:com.noterik.bart.fs.fscommand.CommandHandler.java

License:Open Source License

private void initCommandList() {
    File file = new File(GlobalConfig.instance().getBaseDir() + "conf/" + CONFIG_FILE);
    logger.info("Initializing command list: " + file.getAbsolutePath());
    Document doc = XMLHelper.getXmlFromFile(file);
    if (doc != null) {
        List<Node> nl = doc.selectNodes("//command");
        for (Node n : nl) {
            if (n instanceof Element) {
                if (n.getName() != null && n.getName().equals("command")) {
                    Node idn = n.selectSingleNode("./id");
                    Node cln = n.selectSingleNode("./class");
                    Node jn = n.selectSingleNode("./jar");
                    if (idn != null && cln != null) {

                        String id = idn.getText();
                        String cl = cln.getText();
                        String jar = null;
                        if (jn != null && cl != null) {
                            jar = jn.getText();
                        }/*w w  w  .j a  v  a2  s  . c o m*/
                        if (id != null && cl != null) {
                            try {
                                if (jar != null) {
                                    logger.info("Loading jar " + jar + " for class " + cl);
                                    Class<?> commandClass = loadJar(jar, cl);
                                    if (commandClass != null) {
                                        Command o = (Command) commandClass.newInstance();
                                        commands.put(id, o);
                                    }
                                } else {
                                    Class c = Class.forName(cl);
                                    Object o = c.newInstance();
                                    if (o instanceof Command) {
                                        commands.put(id, (Command) o);
                                    }
                                }
                            } catch (Exception e) {
                                System.out.println("Problem with loading " + cl);
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:com.noterik.bart.fs.fscommand.CommandHandler.java

License:Open Source License

/**
 * Load a specific command/*from  w w w.  j av  a  2  s  .co m*/
 * @param cid the command to load
 * @return the command object loaded
 */
private Command loadCommand(String cid) {
    File file = new File(GlobalConfig.instance().getBaseDir() + "conf/" + CONFIG_FILE);
    Document doc = XMLHelper.getXmlFromFile(file);
    if (doc != null) {
        List<Node> nl = doc.selectNodes("//command");
        for (Node n : nl) {
            if (n instanceof Element) {
                if (n.getName() != null && n.getName().equals("command")) {
                    Node idn = n.selectSingleNode("./id");
                    Node cln = n.selectSingleNode("./class");
                    Node jn = n.selectSingleNode("./jar");
                    if (idn != null && cln != null) {
                        String id = idn.getText();
                        String cl = cln.getText();
                        String jar = null;

                        if (id != null && cl != null && id.equals(cid)) {
                            if (jn != null && cl != null) {
                                jar = jn.getText();
                            }
                            try {
                                if (jar != null) {
                                    logger.info("Loading jar " + jar + " for class " + cl);
                                    Class<?> commandClass = loadJar(jar, cl);
                                    if (commandClass != null) {
                                        Command o = (Command) commandClass.newInstance();
                                        commands.put(id, o);
                                    }
                                } else {
                                    Class c = Class.forName(cl);
                                    Object o = c.newInstance();
                                    if (o instanceof Command) {
                                        commands.put(id, (Command) o);
                                    }
                                }
                            } catch (ClassNotFoundException e) {
                                logger.error("", e);
                            } catch (InstantiationException e) {
                                logger.error("", e);
                            } catch (IllegalAccessException e) {
                                logger.error("", e);
                            }
                        }
                    }
                }
            }
        }
    }
    return commands.get(cid);
}

From source file:com.noterik.bart.fs.fscommand.CopyCommand.java

License:Open Source License

/**
 * /*from   w ww  .ja  va  2s . c  o m*/
 * @param uri
 * @return
 */
private Document getPropertiesOfUri(String uri, int depth) {
    // refactor uri
    String cp = URIParser.getCurrentUriPart(uri);
    if (cp.equals(FSXMLHelper.XML_PROPERTIES)) {
        uri = URIParser.getParentUri(uri);
    }

    // get complete
    Document pDoc = null;
    if (depth == -1) {
        pDoc = rHandler.getNodeProperties(uri, true);
    } else {
        pDoc = rHandler.getNodeProperties(uri, depth, true);
    }

    // loop through xml and check referid's
    List<Node> rNodes = pDoc.selectNodes("//@referid");
    logger.debug("rNodes: " + rNodes);
    for (Iterator<Node> iter = rNodes.iterator(); iter.hasNext();) {
        // get referid attribute and parent node
        Node node = iter.next();
        String referid = node.getText();
        Element parent = node.getParent();
        logger.debug("parent: " + parent.asXML() + ", refer: " + referid);

        // get properties of referid
        Document rDoc = rHandler.getNodeProperties(referid, 0, false);
        logger.debug("rDoc: " + rDoc.asXML());
        Node properties = rDoc.selectSingleNode("//properties");
        List<Node> pNodes = properties.selectNodes("child::*");
        logger.debug("pNodes: " + pNodes);
        for (Iterator<Node> iter2 = pNodes.iterator(); iter2.hasNext();) {
            // select the same property elements that are in parent element and refer properties
            Node prop = iter2.next();
            List<Node> parentPNodes = parent.selectNodes("properties/child::*");
            for (Node parentPropNode : parentPNodes) {
                if (parentPropNode.getName().equals(prop.getName())
                        && parentPropNode.getText().equals(prop.getText())) {
                    logger.debug("removing: " + parentPropNode.asXML());
                    parentPropNode.detach();
                }
            }
        }
    }

    return pDoc;
}

From source file:com.noterik.bart.fs.fscommand.UpdatePresentationCommand.java

License:Open Source License

public String execute(String url, String xml) {
    logger.debug("Updating properties of presentation " + url);
    logger.debug("Updating properties xml " + xml);

    Document doc = XMLHelper.asDocument(xml);
    List<Node> properties;

    //TODO: validate ticket

    //add every property in the xml supplied      
    properties = doc.selectNodes("//properties/*");

    for (Iterator<Node> it = properties.iterator(); it.hasNext();) {
        Node property = it.next();

        if (!property.getName().equals("ticket")) {
            logger.debug("updating property " + property.getName() + " with value " + property.getText());

            FSXMLRequestHandler.instance().handlePUT(url + "/properties/" + property.getName(),
                    property.getText());
        }// ww  w  . j  a v  a 2  s.c  om
    }
    return FSXMLBuilder.getFSXMLStatusMessage("The properties where successfully added", "", "");
}