Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/sample/addressbook/view/util/ContactViewUtil.java


1   /*
2    * ContactViewUtil.java
3    *
4    * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5    *
6    * See the file LICENSE for terms of use.
7    *
8    */
9   
10  package com.sample.addressbook.view.util;
11  
12  import javax.servlet.*;
13  import javax.servlet.http.*;
14  
15  import com.aendvari.common.model.*;
16  
17  import com.aendvari.common.util.*;
18  import com.aendvari.common.model.*;
19  import com.aendvari.common.notices.*;
20  
21  import com.aendvari.tethys.context.*;
22  import com.aendvari.tethys.context.model.*;
23  
24  import com.aendvari.tethys.tag.notices.*;
25  import com.aendvari.tethys.tag.context.*;
26  import com.aendvari.tethys.tag.model.*;
27  
28  import com.aendvari.cerberus.component.descriptor.ComponentDescriptor;
29  
30  import com.aendvari.cerberus.component.assembly.AssembledComponent;
31  import com.aendvari.cerberus.component.assembly.AssemblyContext;
32  
33  import com.aendvari.hermes.broker.*;
34  import com.aendvari.hermes.broker.http.*;
35  
36  import com.aendvari.satyr.servlet.*;
37  
38  import com.sample.addressbook.Names;
39  
40  
41  /**
42   * <p>A utility class for all the contact view classes.</p>
43   *
44   * @author  Scott Milne
45   *
46   */
47  
48  public class ContactViewUtil
49  {
50    public static void createContactContext(HttpServletRequest request, String model)
51    {
52      // obtain model tree
53      ModelTree modelTree = ServletModelUtil.getModelTree(request.getSession());
54  
55      // get the model tag data
56      ModelTagData modelTagData = ModelTagData.getData(request);
57  
58      // get the  node
59      ModelNode modelNode = modelTree.getNode(modelTree.getRootNode(), model);
60  
61      // define a context for the addresses component
62      ModelContext tagContext = new ModelContext("contact", modelNode);
63      modelTagData.getModelContextMap().setContext(tagContext);
64    }
65  
66    public static void checkForErrorMessages(ComponentDescriptor descriptor, Message message, HttpServletRequest request)
67    {
68      // get the "errorMessage" topic
69      String errorMessagesPath = descriptor.getAttribute("errorMessages").getValue();
70  
71      // get the error messages list
72      Notices errorMessages =
73        (Notices)message.getProperties().getObject(errorMessagesPath);
74  
75      if (errorMessages != null && errorMessages.getNotices("*",true).size() > 0)
76      {
77        // get the "resourceNoticeTranslator" topic
78        String resourceNoticeTranslator = descriptor.getAttribute("resourceNoticeTranslator").getValue();
79  
80        // create a notice translator. This is used to extract and parse notice text from a .properties file
81        NoticeTranslator translator = new ResourceNoticeTranslator(resourceNoticeTranslator);
82  
83        // get the tag data for notices
84        NoticesTagData tagData = NoticesTagData.getData(request);
85  
86        // set a new mapping into the tag data
87        NoticesMap map = new NoticesMap(errorMessages, translator);
88        tagData.setNoticesMap(map);
89      }
90    }
91  }
92