KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > tools > userManagement > ContextGrabber


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.portal.tools.userManagement;
17
18 import org.apache.cocoon.webapps.authentication.context.AuthenticationContext;
19 import org.w3c.dom.DocumentFragment JavaDoc;
20 import org.w3c.dom.Node JavaDoc;
21
22 /**
23  * Grabbing the context of an user, which is set in the file sunrise-user.xml
24  * and is stored in the class AuthenticationContext.
25  *
26  * @version CVS $Id: ContextGrabber.java 149055 2005-01-29 18:21:34Z cziegeler $
27  */

28 public class ContextGrabber {
29     
30     /**
31      * Grabbing the context of the current user
32      *
33      * @param context the instantiated class AuthenticationContext
34      * @return Object of context information
35      */

36     public UserBean grab (AuthenticationContext context) {
37         UserBean ub = new UserBean ();
38         DocumentFragment JavaDoc df = null;
39         try {
40             df = context.getXML ("/authentication/");
41         } catch (Exception JavaDoc e) {}
42         
43         grabAuthContext (df.getFirstChild(),ub);
44         
45         return ub;
46     }
47     
48     private void grabAuthContext (Node JavaDoc node, UserBean ub) {
49         
50         while (node != null) {
51             
52             if (!node.getNodeName().equals("#text")) {
53                 if (node.getFirstChild() != null) {
54                     grabAuthContext (node.getFirstChild () ,ub);
55                     ub.addContext(node.getNodeName(),node.getFirstChild().getNodeValue());
56                 } else {
57                     ub.addContext(node.getNodeName(),"");
58                 }
59             }
60             node = node.getNextSibling();
61         }
62     }
63     
64 }
65
Popular Tags