01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.portal.tools.userManagement;
18:
19: import org.apache.cocoon.webapps.authentication.context.AuthenticationContext;
20: import org.w3c.dom.DocumentFragment;
21: import org.w3c.dom.Node;
22:
23: /**
24: * Grabbing the context of an user, which is set in the file sunrise-user.xml
25: * and is stored in the class AuthenticationContext.
26: *
27: * @version CVS $Id: ContextGrabber.java 433543 2006-08-22 06:22:54Z crossley $
28: */
29: public class ContextGrabber {
30:
31: /**
32: * Grabbing the context of the current user
33: *
34: * @param context the instantiated class AuthenticationContext
35: * @return Object of context information
36: */
37: public UserBean grab(AuthenticationContext context) {
38: UserBean ub = new UserBean();
39: DocumentFragment df = null;
40: try {
41: df = context.getXML("/authentication/");
42: } catch (Exception e) {
43: }
44:
45: grabAuthContext(df.getFirstChild(), ub);
46:
47: return ub;
48: }
49:
50: private void grabAuthContext(Node node, UserBean ub) {
51:
52: while (node != null) {
53:
54: if (!node.getNodeName().equals("#text")) {
55: if (node.getFirstChild() != null) {
56: grabAuthContext(node.getFirstChild(), ub);
57: ub.addContext(node.getNodeName(), node
58: .getFirstChild().getNodeValue());
59: } else {
60: ub.addContext(node.getNodeName(), "");
61: }
62: }
63: node = node.getNextSibling();
64: }
65: }
66:
67: }
|