final DefaultConfigurationKey common = commonKey(other); final DefaultConfigurationKey result = new DefaultConfigurationKey(getExpressionEngine()); if (common.length() < other.length()) final String k = other.toString().substring(common.length()); getSymbols().getPropertyDelimiter())) result.append(k.substring(i));
@Override public String attributeKey(final String parentKey, final String attributeName) { final DefaultConfigurationKey key = new DefaultConfigurationKey(this, parentKey); key.appendAttribute(attributeName); return key.toString(); }
/** * Appends an attribute to this configuration key. * * @param attr the name of the attribute to be appended * @return a reference to this object */ public DefaultConfigurationKey appendAttribute(final String attr) { keyBuffer.append(constructAttributeKey(attr)); return this; }
/** * {@inheritDoc} This implementation takes the * given parent key, adds a property delimiter, and then adds the node's * name. * The name of the root node is a blank string. Note that no indices are * returned. */ @Override public <T> String nodeKey(final T node, final String parentKey, final NodeHandler<T> handler) { if (parentKey == null) { // this is the root node return StringUtils.EMPTY; } final DefaultConfigurationKey key = new DefaultConfigurationKey(this, parentKey); key.append(handler.nodeName(node), true); return key.toString(); }
/** * {@inheritDoc} This method supports the syntax as described in the class * comment. */ @Override public <T> List<QueryResult<T>> query(final T root, final String key, final NodeHandler<T> handler) { final List<QueryResult<T>> results = new LinkedList<>(); findNodesForKey(new DefaultConfigurationKey(this, key).iterator(), root, results, handler); return results; }
final DefaultConfigurationKey result = new DefaultConfigurationKey(getExpressionEngine()); final KeyIterator it1 = iterator(); final KeyIterator it2 = other.iterator(); while (it1.hasNext() && it2.hasNext() && partsEqual(it1, it2)) result.appendAttribute(it1.currentKey()); result.append(it1.currentKey()); if (it1.hasIndex) result.appendIndex(it1.getIndex());
/** * Fires all necessary element start events for the specified key. This * method is called for each key obtained from the configuration to be * converted. It ensures that all elements "between" the last key and the * actual key are opened and their values are set. * * @param keyLast the last processed key * @param keyAct the actual key * @param config the configuration to process * @param keySet the set with the processed keys * @return the name of the last element on the path */ protected String openElements(final DefaultConfigurationKey keyLast, final DefaultConfigurationKey keyAct, final Configuration config, final Set<String> keySet) { final DefaultConfigurationKey.KeyIterator it = keyLast.differenceKey(keyAct).iterator(); final DefaultConfigurationKey k = keyLast.commonKey(keyAct); for (it.nextKey(); it.hasNext(); it.nextKey()) { k.append(it.currentKey(true)); elementStart(it.currentKey(true), config.getProperty(k.toString())); keySet.add(k.toString()); } return it.currentKey(true); }
/** * Appends the name of a property to this key. If necessary, a property * delimiter will be added. If the boolean argument is set to <b>true</b>, * property delimiters contained in the property name will be escaped. * * @param property the name of the property to be added * @param escape a flag if property delimiters in the passed in property name * should be escaped * @return a reference to this object */ public DefaultConfigurationKey append(final String property, final boolean escape) { String key; if (escape && property != null) { key = escapeDelimiters(property); } else { key = property; } key = trim(key); if (keyBuffer.length() > 0 && !isAttributeKey(property) && key.length() > 0) { keyBuffer.append(getSymbols().getPropertyDelimiter()); } keyBuffer.append(key); return this; }
/** * {@inheritDoc} This implementation works similar to {@code nodeKey()}; * however, each key returned by this method has an index (except for the * root node). The parent key is prepended to the name of the current node * in any case and without further checks. If it is <b>null</b>, only the * name of the current node with its index is returned. */ @Override public <T> String canonicalKey(final T node, final String parentKey, final NodeHandler<T> handler) { final String nodeName = handler.nodeName(node); final T parent = handler.getParent(node); final DefaultConfigurationKey key = new DefaultConfigurationKey(this, parentKey); key.append(StringUtils.defaultString(nodeName)); if (parent != null) { // this is not the root key key.appendIndex(determineIndex(node, parent, nodeName, handler)); } return key.toString(); }
/** * Appends an index to this configuration key. * * @param index the index to be appended * @return a reference to this object */ public DefaultConfigurationKey appendIndex(final int index) { keyBuffer.append(getSymbols().getIndexStart()); keyBuffer.append(index); keyBuffer.append(getSymbols().getIndexEnd()); return this; }
/** * Removes leading property delimiters from the specified key. * * @param key the key * @return the key with removed leading property delimiters */ public String trimLeft(final String key) { if (key == null) { return StringUtils.EMPTY; } String result = key; while (hasLeadingDelimiter(result)) { result = result.substring(getSymbols() .getPropertyDelimiter().length()); } return result; }
/** * Removes trailing property delimiters from the specified key. * * @param key the key * @return the key with removed trailing property delimiters */ public String trimRight(final String key) { if (key == null) { return StringUtils.EMPTY; } String result = key; while (hasTrailingDelimiter(result)) { result = result .substring(0, result.length() - getSymbols().getPropertyDelimiter() .length()); } return result; }
/** * Decorates the given key so that it represents an attribute. Adds special * start and end markers. The passed in string will be modified only if does * not already represent an attribute. * * @param key the key to be decorated * @return the decorated attribute key */ public String constructAttributeKey(final String key) { if (key == null) { return StringUtils.EMPTY; } if (isAttributeKey(key)) { return key; } final StringBuilder buf = new StringBuilder(); buf.append(getSymbols().getAttributeStart()).append(key); if (getSymbols().getAttributeEnd() != null) { buf.append(getSymbols().getAttributeEnd()); } return buf.toString(); }
/** * Appends the name of a property to this key. If necessary, a property * delimiter will be added. Property delimiters in the given string will not * be escaped. * * @param property the name of the property to be added * @return a reference to this object */ public DefaultConfigurationKey append(final String property) { return append(property, false); }
/** * Returns the symbols object from the associated expression engine. * * @return the {@code DefaultExpressionEngineSymbols} */ private DefaultExpressionEngineSymbols getSymbols() { return getExpressionEngine().getSymbols(); }
/** * Fires all necessary element end events for the specified keys. This * method is called for each key obtained from the configuration to be * converted. It calculates the common part of the actual and the last * processed key and thus determines how many elements must be * closed. * * @param keyLast the last processed key * @param keyAct the actual key */ protected void closeElements(final DefaultConfigurationKey keyLast, final DefaultConfigurationKey keyAct) { final DefaultConfigurationKey keyDiff = keyAct.differenceKey(keyLast); final Iterator<String> it = reverseIterator(keyDiff); if (it.hasNext()) { // Skip first because it has already been closed by fireValue() it.next(); } while (it.hasNext()) { elementEnd(it.next()); } }
new DefaultConfigurationKey(exprEngine); DefaultConfigurationKey keyLast = keyEmpty; final Set<String> keySet = new HashSet<>(); new DefaultConfigurationKey(exprEngine, key); closeElements(keyLast, keyAct); final String elem = openElements(keyLast, keyAct, config, keySet);
/** * Splits the at path into its components. * * @param at the at string * @return a collection with the names of the single components */ private Collection<String> parseAt(final String at) { if (at == null) { return null; } final Collection<String> result = new ArrayList<>(); final DefaultConfigurationKey.KeyIterator it = new DefaultConfigurationKey( AT_ENGINE, at).iterator(); while (it.hasNext()) { result.add(it.nextKey()); } return result; } }
/** * Unescapes the delimiters in the specified string. * * @param key the key to be unescaped * @return the unescaped key */ private String unescapeDelimiters(final String key) { return (getSymbols().getEscapedDelimiter() == null) ? key : StringUtils.replace(key, getSymbols() .getEscapedDelimiter(), getSymbols() .getPropertyDelimiter()); }
public <T> NodeAddData<T> prepareAdd(final T root, final String key, final NodeHandler<T> handler) final DefaultConfigurationKey.KeyIterator it = new DefaultConfigurationKey( this, key).iterator(); if (!it.hasNext())