/** * Determines the index of the given node based on its parent node. * * @param node the current node * @param parent the parent node * @param nodeName the name of the current node * @param handler the node handler * @param <T> the type of the nodes to be dealt with * @return the index of this node */ private <T> int determineIndex(final T node, final T parent, final String nodeName, final NodeHandler<T> handler) { return findChildNodesByName(handler, parent, nodeName).indexOf(node); }
/** * {@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; }
/** * Returns the symbols object from the associated expression engine. * * @return the {@code DefaultExpressionEngineSymbols} */ private DefaultExpressionEngineSymbols getSymbols() { return getExpressionEngine().getSymbols(); }
private static CombinedConfiguration readConfig(){ try{ // 指定文件编码方式,否则properties文件读取中文会是乱码,要求文件编码是UTF-8 FileBasedConfigurationBuilder.setDefaultEncoding(PropertiesConfiguration.class, ENCODING); // 使用默认表达式引擎 DefaultExpressionEngine engine = new DefaultExpressionEngine(DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS); Configurations configs = new Configurations(); CombinedConfiguration config = configs.combined(ROOT_URL); config.setExpressionEngine(engine); // 设置同步器 config.setSynchronizer(new ReadWriteSynchronizer()); return config; }catch(Exception e){ throw new ExceptionInInitializerError(e); } } private static PropertiesConfiguration createUserConfig(){
return findLastPathNode(keyIt, findChildNodesByName(handler, node, keyPart).get(idx), handler);
if (keyPart.isPropertyKey()) processSubNodes(keyPart, findChildNodesByName(handler, node, key), results, handler);
@Override public <T> List<QueryResult<T>> query(T root, String key, NodeHandler<T> handler) { List<QueryResult<T>> results = super.query(root, key, handler); if (!results.isEmpty()) { return results; } // If we find no results, fall back to the query that specifies the attribute handler return super.query(root, this.attributeKey(null, key), handler); } };
/** * {@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(); }
final T parent = findLastPathNode(it, root, handler); final List<String> pathNodes = new LinkedList<>();
private void loadZeidonIni( InputStream iniFile ) { if ( iniFile == null ) throw new ZeidonException( "Could not find " + iniFileName ); InputStreamReader reader = new InputStreamReader( iniFile ); try { DefaultExpressionEngine engine = new DefaultExpressionEngine( DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS, NodeNameMatchers.EQUALS_IGNORE_CASE ); Parameters params = new Parameters(); FileBasedConfigurationBuilder<INIConfiguration> builder = new FileBasedConfigurationBuilder<INIConfiguration>( INIConfiguration.class ) .configure( params.hierarchical().setExpressionEngine( engine ) ); iniConfObj = builder.getConfiguration(); iniConfObj.read( reader ); reader.close(); sectionNameMap = new HashMap<>(); for ( String sectionName : iniConfObj.getSections() ) sectionNameMap.put( sectionName.toLowerCase(), sectionName ); } catch ( Exception e ) { throw ZeidonException.wrapException( e ).prependFilename( iniFileName ); } finally { IOUtils.closeQuietly( reader ); } }
@Override public <T> List<QueryResult<T>> query(T root, String key, NodeHandler<T> handler) { List<QueryResult<T>> results = super.query(root, key, handler); if (!results.isEmpty()) { return results; } // If we find no results, fall back to the query that specifies the attribute handler return super.query(root, this.attributeKey(null, key), handler); } };
findNodesForKey((DefaultConfigurationKey.KeyIterator) keyPart .clone(), subNodes.get(keyPart.getIndex()), nodes, handler); findNodesForKey((DefaultConfigurationKey.KeyIterator) keyPart .clone(), node, nodes, handler);