Mercurial > hg > mpdl-group
comparison software/eXist/mpdl-modules/src/org/exist/xquery/modules/mpdldoc/ESciDocLogin.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 ESciDocLogin extends BasicFunction { | |
44 | |
45 public final static FunctionSignature signature = | |
46 new FunctionSignature( | |
47 new QName("escidoc-login", MPDLDocModule.NAMESPACE_URI, MPDLDocModule.PREFIX), | |
48 "A function which delivers an eSciDoc cookie id for the given login name and password", | |
49 new SequenceType[] { | |
50 new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE), | |
51 new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE) | |
52 }, | |
53 new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE)); | |
54 | |
55 public ESciDocLogin(XQueryContext context) { | |
56 super(context, signature); | |
57 } | |
58 | |
59 public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { | |
60 try { | |
61 Sequence firstSeq = args[0]; | |
62 Sequence secondSeq = args[1]; | |
63 if (firstSeq.isEmpty() || secondSeq.isEmpty()) | |
64 return Sequence.EMPTY_SEQUENCE; | |
65 String userName = firstSeq.getStringValue(); | |
66 String pw = secondSeq.getStringValue(); | |
67 String eSciDocCookieId = ESciDocRestSession.login(userName, pw); | |
68 ValueSequence resultSequence = new ValueSequence(); | |
69 StringValue strValCookieId = new StringValue(""); | |
70 if (eSciDocCookieId != null) | |
71 strValCookieId = new StringValue(eSciDocCookieId); | |
72 resultSequence.add(strValCookieId); | |
73 return resultSequence; | |
74 } catch (ApplicationException e) { | |
75 throw new XPathException(e); | |
76 } | |
77 } | |
78 | |
79 } |