comparison software/eXist/mpdl-modules/src/org/exist/xquery/modules/mpdldoc/GetESciDocContainerIdByExistId.java @ 0:408254cf2f1d

Erstellung
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Wed, 24 Nov 2010 17:24:23 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:408254cf2f1d
1 /*
2 * eXist Open Source Native XML Database: Extension module
3 * Copyright (C) 2008 Josef Willenborg
4 * jwillenborg@mpiwg-berlin.mpg.de
5 * http://www.mpiwg-berlin.mpg.de
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 * $Id: TextModule.java $
22 */
23 package org.exist.xquery.modules.mpdldoc;
24
25 import org.exist.dom.QName;
26 import org.exist.xquery.BasicFunction;
27 import org.exist.xquery.Cardinality;
28 import org.exist.xquery.FunctionSignature;
29 import org.exist.xquery.XPathException;
30 import org.exist.xquery.XQueryContext;
31 import org.exist.xquery.value.Sequence;
32 import org.exist.xquery.value.SequenceType;
33 import org.exist.xquery.value.StringValue;
34 import org.exist.xquery.value.Type;
35 import org.exist.xquery.value.ValueSequence;
36
37 import de.mpg.mpiwg.berlin.mpdl.escidoc.ESciDocRestSession;
38 import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException;
39
40 /**
41 * @author Josef Willenborg (jwillenborg@mpiwg-berlin.mpg.de)
42 */
43 public class GetESciDocContainerIdByExistId extends BasicFunction {
44
45 public final static FunctionSignature signature =
46 new FunctionSignature(
47 new QName("escidoc-get-containerid", MPDLDocModule.NAMESPACE_URI, MPDLDocModule.PREFIX),
48 "A function which delivers the container id of the first argument: existId." +
49 "Second argument is the cookieId.",
50 new SequenceType[] {
51 new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE),
52 new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE)
53 },
54 new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE));
55
56 public GetESciDocContainerIdByExistId(XQueryContext context) {
57 super(context, signature);
58 }
59
60 public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
61 try {
62 Sequence firstSeq = args[0];
63 Sequence secondSeq = args[1];
64 if (firstSeq.isEmpty() || secondSeq.isEmpty())
65 return Sequence.EMPTY_SEQUENCE;
66 String firstSeqStrValue = firstSeq.getStringValue();
67 String existId = null;
68 if (! firstSeqStrValue.equals(""))
69 existId = firstSeqStrValue;
70 String secondSeqStrValue = secondSeq.getStringValue();
71 String eSciDocCookieId = null;
72 if (! secondSeqStrValue.equals(""))
73 eSciDocCookieId = secondSeqStrValue;
74 ESciDocRestSession eSciDocSession = ESciDocRestSession.getInstance(eSciDocCookieId);
75 String eScidDocContainerId = eSciDocSession.getContainerIdByEXistId(existId);
76 ValueSequence result = new ValueSequence();
77 if (eScidDocContainerId != null) {
78 result.add(new StringValue(eScidDocContainerId));
79 } else {
80 result.add(new StringValue(""));
81 }
82 return result;
83 } catch (ApplicationException e) {
84 throw new XPathException(e);
85 }
86 }
87
88 }