From: Wolfgang M. M. <wol...@us...> - 2004-06-29 14:21:33
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/xquery/functions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29067/src/org/exist/xquery/functions Modified Files: ModuleImpl.java FunName.java FunRoot.java Added Files: FunNodeName.java Log Message: Added missing XQuery standard function fn:node-name(). Index: FunName.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/functions/FunName.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FunName.java 29 Jan 2004 15:06:41 -0000 1.1 --- FunName.java 29 Jun 2004 14:21:23 -0000 1.2 *************** *** 45,48 **** --- 45,50 ---- new FunctionSignature( new QName("name", BUILTIN_FUNCTION_NS), + "Returns the name of a node, as an xs:string that is " + + "either the zero-length string, or has the lexical form of an xs:QName", new SequenceType[] { new SequenceType(Type.NODE, Cardinality.ZERO_OR_ONE) }, new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE), Index: FunRoot.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/functions/FunRoot.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FunRoot.java 28 May 2004 10:54:09 -0000 1.2 --- FunRoot.java 29 Jun 2004 14:21:23 -0000 1.3 *************** *** 35,38 **** --- 35,39 ---- import org.exist.xquery.value.SequenceType; import org.exist.xquery.value.Type; + import org.w3c.dom.Node; /** *************** *** 73,77 **** throw new XPathException("Context item is not a node; got " + Type.getTypeName(item.getType())); if (item instanceof NodeProxy) ! return new NodeProxy(((NodeProxy) item).doc, 1); else return (NodeImpl) ((NodeImpl) item).getOwnerDocument().getDocumentElement(); --- 74,78 ---- throw new XPathException("Context item is not a node; got " + Type.getTypeName(item.getType())); if (item instanceof NodeProxy) ! return new NodeProxy(((NodeProxy) item).doc, 1, Node.ELEMENT_NODE); else return (NodeImpl) ((NodeImpl) item).getOwnerDocument().getDocumentElement(); --- NEW FILE: FunNodeName.java --- /* * eXist Open Source Native XML Database * Copyright (C) 2001-04 Wolfgang M. Meier * wol...@ex... * http://exist-db.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: FunNodeName.java,v 1.1 2004/06/29 14:21:23 wolfgang_m Exp $ */ package org.exist.xquery.functions; import org.exist.dom.QName; import org.exist.memtree.NodeImpl; import org.exist.xquery.BasicFunction; import org.exist.xquery.Cardinality; import org.exist.xquery.FunctionSignature; import org.exist.xquery.XPathException; import org.exist.xquery.XQueryContext; import org.exist.xquery.value.NodeValue; import org.exist.xquery.value.QNameValue; import org.exist.xquery.value.Sequence; import org.exist.xquery.value.SequenceType; import org.exist.xquery.value.Type; import org.w3c.dom.Node; /** * @author wolf * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class FunNodeName extends BasicFunction { public final static FunctionSignature signature = new FunctionSignature( new QName("node-name", ModuleImpl.NAMESPACE_URI, ModuleImpl.PREFIX), " Returns an expanded-QName for node kinds that can have names. For other kinds " + "of nodes it returns the empty sequence. If $a is the empty sequence, the " + "empty sequence is returned.", new SequenceType[] { new SequenceType(Type.NODE, Cardinality.ZERO_OR_ONE) }, new SequenceType(Type.QNAME, Cardinality.ZERO_OR_ONE), true); /** * @param context * @param signature */ public FunNodeName(XQueryContext context) { super(context, signature); } /* (non-Javadoc) * @see org.exist.xquery.BasicFunction#eval(org.exist.xquery.value.Sequence[], org.exist.xquery.value.Sequence) */ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { if(args[0].getLength() == 0) return Sequence.EMPTY_SEQUENCE; NodeValue val = (NodeValue)args[0]; Node node = val.getNode(); if(node.getNodeType() == Node.ELEMENT_NODE || node.getNodeType() == Node.ATTRIBUTE_NODE) { if(val.getImplementationType() == NodeValue.IN_MEMORY_NODE) return new QNameValue(context, ((NodeImpl)val).getQName()); else return new QNameValue(context, ((org.exist.dom.NodeImpl)node).getQName()); } return Sequence.EMPTY_SEQUENCE; } } Index: ModuleImpl.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/functions/ModuleImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ModuleImpl.java 3 Jun 2004 10:27:05 -0000 1.3 --- ModuleImpl.java 29 Jun 2004 14:21:23 -0000 1.4 *************** *** 74,77 **** --- 74,78 ---- new FunctionDef(FunMax.signature, FunMax.class), new FunctionDef(FunMin.signature, FunMin.class), + new FunctionDef(FunNodeName.signature, FunNodeName.class), new FunctionDef(FunName.signature, FunName.class), new FunctionDef(FunNamespaceURI.signature, FunNamespaceURI.class), |