Refine search
protected Object saveHierarchy(final ConfigurationNode parentNode) { if (parentNode.getChildrenCount() == 0) return parentNode.getValue(); if (parentNode.getChildrenCount("item") == parentNode.getChildrenCount()) { return parentNode.getChildren().stream().map(this::saveHierarchy).collect(Collectors.toList()); } else { final Map<String, Object> map = new LinkedHashMap<>(); for (ConfigurationNode childNode : parentNode.getChildren()) { String nodeName = childNode.getName(); if (this.xmlCompatibility && childNode.getAttributes("name").size() > 0) nodeName = String.valueOf(childNode.getAttributes("name").get(0).getValue()); map.put(nodeName, saveHierarchy(childNode)); } return map; } } }
protected void loadHierarchy(final ConfigurationNode parentNode, final Object obj) { final String parentName = parentNode.getName(); if (obj instanceof Map<?, ?>) { for (Map.Entry<String, Object> entry : ((Map<String, Object>) obj).entrySet()) { final Node childNode = new Node(entry.getKey()); // if parent node is look like "tableS", "userS" or "groupS" if (this.xmlCompatibility && parentName != null && parentName.endsWith("s")) { //this is done to have "users.user[@name='smith'] instead of "users.smith" childNode.setName(parentName.substring(0, parentName.length() - 1)); childNode.addAttribute(new Node("name", entry.getKey())); } childNode.setReference(entry); loadHierarchy(childNode, entry.getValue()); parentNode.addChild(childNode); } } else if (obj instanceof Collection) { for (Object child : (Collection) obj) { final Node childNode = new Node("item"); childNode.setReference(child); loadHierarchy(childNode, child); parentNode.addChild(childNode); } } parentNode.setValue(obj); }
private void initProperties() { List<ConfigurationNode> nodes = getRootNode().getChildren(); if (nodes == null || nodes.isEmpty()) { return; } for (ConfigurationNode p : nodes) { String name = (String) p.getChildren("name").get(0).getValue(); String value = (String) p.getChildren("value").get(0).getValue(); if (!StringUtils.isEmpty(name)) { properties.put(name, value); } } }
public Configuration subset(String prefix) return new HierarchicalConfiguration(); HierarchicalConfiguration result = new HierarchicalConfiguration() for (ConfigurationNode nd : nodes) if (nd.getValue() != null) value = nd.getValue(); valueCount++; nd.visit(visitor); for (ConfigurationNode c : visitor.getClone().getChildren()) result.getRootNode().addChild(c); for (ConfigurationNode attr : visitor.getClone().getAttributes()) result.getRootNode().addAttribute(attr); result.getRootNode().setValue(value); return (result.isEmpty()) ? new HierarchicalConfiguration() : result;
private void populateAlternateKeyMap(HierarchicalConfiguration config) { List<SubnodeConfiguration> configurationsAt = config.configurationsAt("/*/" + ALTERNATE_KEY); alternateKeysMap = new HashMap<>(configurationsAt.size()); for (SubnodeConfiguration node : configurationsAt) { String rootKey = node.getRootNode() .getParentNode().getName(); String[] alternateKeys = config.getStringArray("/" + rootKey + "/" + ALTERNATE_KEY); for (String token : alternateKeys) { alternateKeysMap.put(token, rootKey); } } }
/** * Creates a new instance of {@code Node} based on the given * source node. All properties of the source node, including its * children and attributes, will be copied. * * @param src the node to be copied */ public Node(ConfigurationNode src) { this(src.getName(), src.getValue()); setReference(src.getReference()); for (ConfigurationNode nd : src.getChildren()) { // Don't change the parent node ConfigurationNode parent = nd.getParentNode(); addChild(nd); nd.setParentNode(parent); } for (ConfigurationNode nd : src.getAttributes()) { // Don't change the parent node ConfigurationNode parent = nd.getParentNode(); addAttribute(nd); nd.setParentNode(parent); } }
public static boolean iterateAllKeys(ConfigKeyFactory factory, HierarchicalConfiguration config, ConfigKeyHandler handler) { List<ConfigurationNode> configNodes = config.getRootNode().getChildren(); for (ConfigurationNode node : configNodes) { ConfigKey key = factory.generateByPropertiesKey(node.getName()); if (!handler.handle(key)) { return true; } } return false; }
protected ServiceEnvironmentImpl.MessagesProvider getMP() { if (messagesProvider == null) { if (0 < cn.getChildrenCount(OA4MPConfigTags.MESSAGES)) { messagesProvider = new ServiceEnvironmentImpl.MessagesProvider(((ConfigurationNode) cn.getChildren(OA4MPConfigTags.MESSAGES).get(0))); } } return messagesProvider; }
/** * Tests if a child node of the second node can be combined with the given * child node of the first node. If this is the case, the corresponding node * will be returned, otherwise <b>null</b>. This implementation checks * whether the child node occurs only once in both hierarchies and is no * known list node. * * @param node1 the first node * @param node2 the second node * @param child the child node (of the first node) * @return a child of the second node, with which a combination is possible */ protected ConfigurationNode canCombine(ConfigurationNode node1, ConfigurationNode node2, ConfigurationNode child) { if (node2.getChildrenCount(child.getName()) == 1 && node1.getChildrenCount(child.getName()) == 1 && !isListNode(child)) { return node2.getChildren(child.getName()).get(0); } else { return null; } } }
protected void printNodes(ConfigurationNode root) { for (Object kid : root.getChildren()) { ConfigurationNode cn = (ConfigurationNode) kid; say("key=" + cn.getName() + ", value=" + cn.getValue()); printNodes(cn); } }
fireEvent(EVENT_ADD_NODES, key, nodes, true); ConfigurationNode parent; List<ConfigurationNode> target = fetchNodeList(key); if (target.size() == 1) parent = processNodeAddData(getExpressionEngine().prepareAdd( getRootNode(), key)); if (parent.isAttribute()) if (child.isAttribute()) parent.addAttribute(child); parent.addChild(child); clearReferences(child);
/** * Determines the index of the specified child node. * * @param nd the node * @return the index of this node relative to its parent */ private static int indexForChild(ConfigurationNode nd) { ConfigurationNode parent = nd.getParentNode(); assert parent != null : "No parent node!"; List<?> children = parent.getChildren(nd.getName()); int index = 0; for (Object c : children) { if (c == nd) { break; } index++; } return index; } }
/** * Returns a map with the bean's (simple) properties. The properties are * collected from all attribute nodes, which are not reserved. * * @return a map with the bean's properties */ public Map<String, Object> getBeanProperties() { Map<String, Object> props = new HashMap<String, Object>(); for (ConfigurationNode attr : getNode().getAttributes()) { if (!isReservedNode(attr)) { props.put(attr.getName(), interpolate(attr .getValue())); } } return props; }
/** * Handles the attributes during a combination process. First all attributes * of the first node will be added to the result. Then all attributes of the * second node, which are not contained in the first node, will also be * added. * * @param result the resulting node * @param node1 the first node * @param node2 the second node */ protected void addAttributes(ViewNode result, ConfigurationNode node1, ConfigurationNode node2) { result.appendAttributes(node1); for (ConfigurationNode attr : node2.getAttributes()) { if (node1.getAttributeCount(attr.getName()) == 0) { result.addAttribute(attr); } } }
XMLConfiguration config = new XMLConfiguration("_config.xml"); Map<String, String> configMap = new HashMap<String, String>(); ConfigurationNode node = config.getRootNode(); for (ConfigurationNode c : node.getChildren("entry")) { String key = (String)c.getAttribute(0).getValue(); String value = (String)c.getValue(); configMap.put(key, value); }
/** * Checks if a node is a list node. This implementation tests if the given * node name is contained in the set of known list nodes. Derived classes * which use different criteria may overload this method. * * @param node the node to be tested * @return a flag whether this is a list node */ public boolean isListNode(ConfigurationNode node) { return listNodes.contains(node.getName()); }
@Override protected boolean checkEvent(CfgEvent cfgEvent) { if (cfgEvent.getConfiguration().getName().equals(getType()) && !cfgEvent.getConfiguration().getChildren(getTarget()).isEmpty()) { setTypeConfig(cfgEvent.getConfiguration()); setConfig((ConfigurationNode) cfgEvent.getConfiguration().getChildren(getTarget()).get(0)); return true; } return false; }
/** * Checks whether the given node is reserved. This method will take * further reserved attributes into account * * @param nd the node * @return a flag whether this node is reserved */ @Override protected boolean isReservedNode(ConfigurationNode nd) { if (super.isReservedNode(nd)) { return true; } return nd.isAttribute() && ((ATTR_ATNAME.equals(nd.getName()) && nd.getParentNode() .getAttributeCount(RESERVED_PREFIX + ATTR_ATNAME) == 0) || (ATTR_OPTIONALNAME .equals(nd.getName()) && nd.getParentNode() .getAttributeCount(RESERVED_PREFIX + ATTR_OPTIONALNAME) == 0)); }
/** * Visits and copies the specified node. * * @param node the node */ @Override public void visitBeforeChildren(ConfigurationNode node) { ConfigurationNode copy = (ConfigurationNode) node.clone(); copy.setParentNode(null); if (!copyStack.isEmpty()) { if (node.isAttribute()) { copyStack.peek().addAttribute(copy); } else { copyStack.peek().addChild(copy); } } copyStack.push(copy); }
/** * Return the first named child configuration node of the given node or null if there is * no such named child. Very useful if your specification only allows for a single child node. * * @param node * @param name * @return */ public static ConfigurationNode getFirstNode(ConfigurationNode node, String name) { List list = node.getChildren(name); if (list.isEmpty()) { return null; } return ((ConfigurationNode) list.get(0)); }