env.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 759 行 · 第 1/2 页
JAVA
759 行
/** * Sets a global variable. */ public void setGlobal(String name, Object value) { _useCount++; Var var = null; if (value instanceof Iterator) value = iteratorToList((Iterator) value); if (value instanceof Var) var = (Var) value; else var = new ObjectVar(value); if (_root._globals == null) _root._globals = new HashMap<String,Var>(); _root._globals.put(name, var); } /** * Converts an iterator to an array list */ private ArrayList iteratorToList(Iterator iter) { ArrayList list = new ArrayList(); while (iter.hasNext()) list.add(iter.next()); return list; } /** * Sets the extension function library * * @param function new function library * @return old function library */ public HashMap setFunctions(HashMap functions) { HashMap old = _functions; _functions = functions; return old; } /** * Adds and extension function * * @param function new function library * @return old function library */ public void addFunction(String name, Object fun) { if (_functions == null) _functions = new HashMap(); _functions.put(name, fun); } /** * Returns the named function. */ public XPathFun getFunction(String name) { if (_root._functions == null) return null; else return (XPathFun) _root._functions.get(name); } /** * Returns true if there are more positions() needed to iterate through. */ public boolean hasMorePositions() { return _hasMorePositions; } /** * Set true if there are more positions() needed to iterate through. * * @param more if true, there are more positions to iterate through. * * @return the old more-position value. */ public boolean setMorePositions(boolean more) { boolean old = _hasMorePositions; _hasMorePositions = more; return old; } /* * The position index is used for patterns which have multiple position()s * for the same node. See FilterPattern for a more detailed description. * * @param index the new position index. * * @return the old position index. */ public int setPositionIndex(int index) { int old = _positionIndex; _positionIndex = index; return old; } /* * Returns the position index is used for patterns which have * multiple position()s for the same node. See FilterPattern for a * more detailed description. */ public int getPositionIndex() { return _positionIndex; } /** * Gets the current node. */ public Node getCurrentNode() { return _currentNode; } /** * Sets the current node. */ public void setCurrentNode(Node node) { _currentNode = node; } /** * Sets the selection context */ public AbstractPattern setSelect(Node node, AbstractPattern select) { AbstractPattern oldSelect = _select; _contextNode = node; _select = select; _position = 0; return oldSelect; } public AbstractPattern getSelect() { return _select; } /** * Sets the selection context */ public ExprEnvironment setExprEnv(ExprEnvironment exprEnv) { ExprEnvironment oldExprEnv = _exprEnv; _exprEnv = exprEnv; return oldExprEnv; } public ExprEnvironment getExprEnv() { return _exprEnv; } /** * Gets the context node. */ public Node getContextNode() { return _contextNode; } /** * Sets the context node. */ public Node setContextNode(Node contextNode) { Node oldNode = _contextNode; _contextNode = contextNode; return oldNode; } /** * Returns the position of the context node. */ public int getContextPosition() { if (_exprEnv != null) return _exprEnv.getContextPosition(); if (_position > 0) return _position; if (_contextNode == null || _currentNode == null) return 0; if (_select != null) { try { NodeIterator iter = _select.select(_contextNode, this); Node child; while ((child = iter.nextNode()) != null && child != _currentNode) { } return iter.getContextPosition(); } catch (Exception e) { } } Node child = _contextNode.getFirstChild(); int pos = 1; for (; child != null && child != _currentNode; child = child.getNextSibling()) { pos++; } return pos; } /** * Returns the number of nodes in the context list. */ public int getContextSize() { if (_exprEnv != null) return _exprEnv.getContextSize(); if (_size > 0) return _size; if (_contextNode == null || _currentNode == null) return 0; if (_select != null) { try { NodeIterator iter = _select.select(_contextNode, this); Node child; while ((child = iter.nextNode()) != null && child != _currentNode) { } return iter.getContextSize(); } catch (Exception e) { } } Node child = _contextNode.getFirstChild(); int pos = 0; for (; child != null; child = child.getNextSibling()) pos++; return pos; } /** * Returns a document for creating nodes. */ public Document getOwnerDocument() { return null; } /** * Returns the given system property. */ public Object systemProperty(String namespaceURI, String localName) { return null; } /** * Returns the string-value of the node. */ public String stringValue(Node node) { return XmlUtil.textValue(node); } /* * Returns the position() value. Note, this is not the same as * positionIndex. */ public void setPosition(int position) { _position = position; } public int setContextPosition(int position) { int oldPosition = _position; _position = position; return oldPosition; } /** * Sets the context size to a know value. */ public int setContextSize(int size) { int oldSize = _size; _size = size; return oldSize; } public Object getCache(Object key) { if (_root._cache == null) return null; else return _root._cache.get(key); } public void setCache(Object key, Object value) { if (_root._cache == null) _root._cache = new HashMap(); _root._cache.put(key, value); } public int getUseCount() { return _useCount; } public void free() { _root = null; _parent = null; _select = null; _exprEnv = null; _stylesheetEnv = null; if (_ids != null) { _ids.clear(); _idCache.clear(); } while (_varSize-- > 0) { _varKeys[_varSize] = null; _varValues[_varSize] = null; } _varSize = 0; _lastElement = null; if (_globals != null) _globals.clear(); _functions = null; _cache = null; _currentNode = null; _contextNode = null; _size = 0; _position = 0; _positionIndex = 0; _hasMorePositions = false; _freeList.free(this); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?