From: Giulio V. <gva...@us...> - 2004-03-26 11:14:58
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/xquery/functions/xmldb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30151/src/org/exist/xquery/functions/xmldb Modified Files: ModuleImpl.java Added Files: XMLDBCreated.java XMLDBLastModified.java Log Message: add created and last-modified to xquery --- NEW FILE: XMLDBLastModified.java --- /* * eXist Open Source Native XML Database * Copyright (C) 2001-03 Wolfgang M. Meier * wol...@ex... * http://exist.sourceforge.net * * 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. * */ package org.exist.xquery.functions.xmldb; import org.exist.dom.NodeProxy; import org.exist.dom.QName; 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.Sequence; import org.exist.xquery.value.SequenceType; import org.exist.xquery.value.Type; import org.exist.xquery.value.DateTimeValue; import org.exist.security.User; /** * @author Wolfgang Meier (wol...@ex...) * */ public class XMLDBLastModified extends BasicFunction { public final static FunctionSignature signature = new FunctionSignature( new QName("last-modified", ModuleImpl.NAMESPACE_URI, ModuleImpl.PREFIX), "Returns the modified date", new SequenceType[] { new SequenceType(Type.NODE, Cardinality.EXACTLY_ONE) }, new SequenceType(Type.DATE_TIME, Cardinality.EXACTLY_ONE)); public XMLDBLastModified(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 { NodeValue node = (NodeValue)args[0].itemAt(0); if(node.getImplementationType() == NodeValue.PERSISTENT_NODE) { NodeProxy proxy = (NodeProxy)node; return new DateTimeValue(proxy.doc.getLastModified(),0); } return Sequence.EMPTY_SEQUENCE; } } --- NEW FILE: XMLDBCreated.java --- /* * eXist Open Source Native XML Database * Copyright (C) 2001-03 Wolfgang M. Meier * wol...@ex... * http://exist.sourceforge.net * * 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. * */ package org.exist.xquery.functions.xmldb; import org.exist.dom.NodeProxy; import org.exist.dom.QName; 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.Sequence; import org.exist.xquery.value.SequenceType; import org.exist.xquery.value.Type; import org.exist.xquery.value.DateTimeValue; import org.exist.security.User; /** * @author Wolfgang Meier (wol...@ex...) * */ public class XMLDBCreated extends BasicFunction { public final static FunctionSignature signature = new FunctionSignature( new QName("created", ModuleImpl.NAMESPACE_URI, ModuleImpl.PREFIX), "Returns the creation date", new SequenceType[] { new SequenceType(Type.NODE, Cardinality.EXACTLY_ONE) }, new SequenceType(Type.DATE_TIME, Cardinality.EXACTLY_ONE)); public XMLDBCreated(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 { NodeValue node = (NodeValue)args[0].itemAt(0); if(node.getImplementationType() == NodeValue.PERSISTENT_NODE) { NodeProxy proxy = (NodeProxy)node; return new DateTimeValue(proxy.doc.getCreated(),0); } return Sequence.EMPTY_SEQUENCE; } } Index: ModuleImpl.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/functions/xmldb/ModuleImpl.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ModuleImpl.java 1 Mar 2004 13:20:35 -0000 1.4 --- ModuleImpl.java 26 Mar 2004 11:04:01 -0000 1.5 *************** *** 43,47 **** new FunctionDef(XMLDBXUpdate.signature, XMLDBXUpdate.class), new FunctionDef(XMLDBRemove.signature, XMLDBRemove.class), ! new FunctionDef(XMLDBHasLock.signature, XMLDBHasLock.class) }; --- 43,49 ---- new FunctionDef(XMLDBXUpdate.signature, XMLDBXUpdate.class), new FunctionDef(XMLDBRemove.signature, XMLDBRemove.class), ! new FunctionDef(XMLDBHasLock.signature, XMLDBHasLock.class), ! new FunctionDef(XMLDBCreated.signature, XMLDBCreated.class), ! new FunctionDef(XMLDBLastModified.signature, XMLDBLastModified.class) }; |