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

Quick Search    Search Deep

Source code: com/aendvari/tethys/tag/notices/NoticesTag.java


1   /*
2    * NoticesTag.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.aendvari.tethys.tag.notices;
11  
12  import java.io.IOException;
13  
14  import java.util.Collection;
15  import java.util.Iterator;
16  
17  import javax.servlet.http.*;
18  import javax.servlet.jsp.*;
19  import javax.servlet.jsp.tagext.*;
20  
21  import com.aendvari.common.model.*;
22  
23  import com.aendvari.tethys.*;
24  import com.aendvari.tethys.tag.*;
25  import com.aendvari.tethys.tag.data.*;
26  import com.aendvari.tethys.context.*;
27  
28  
29  import com.aendvari.common.notices.*;
30  
31  
32  /**
33   * <p>Implementation class for the "notices" tag.</p>
34   *
35   * @author  Scott Milne
36   *
37   */
38  
39  public class NoticesTag extends DataTag
40  {
41    /* Variables */
42  
43    /** The OSM path containing notices. */
44    protected String path;
45  
46    /** Should recursion be used to extract the messages. */
47    protected boolean recursive;
48  
49  
50    /* Constructor */
51  
52    public NoticesTag()
53    {
54      super();
55  
56      path = null;
57      recursive = true;
58    }
59  
60    /* Attributes */
61  
62    public void setPath(String path) { this.path = path; }
63    public String getPath() { return path; }
64  
65    public void setRecursive(boolean recursive)
66    {
67      this.recursive = recursive;
68    }
69  
70    public boolean getRecursive()
71    {
72      return recursive;
73    }
74  
75    public int doEndTag() throws JspTagException
76    {
77      try
78      {
79        // get the notices map
80        NoticesMap noticesMap = NoticesTagData.getData(
81          pageContext, getDataScope()).getNoticesMap();
82  
83        // get the messages
84        Notices messages = noticesMap.getNotices();
85  
86        // get the translator
87        NoticeTranslator translator = noticesMap.getTranslator();
88  
89        if ((messages != null) && (translator != null))
90        {
91          // get all the specified messages from the translator
92          Collection errorNotices = messages.getNotices(getPath(), recursive);
93          Collection errorStrings = translator.translate(errorNotices);
94  
95          // now display them (if any)
96          Iterator messagesIterator = errorStrings.iterator();
97  
98          while (messagesIterator.hasNext())
99          {
100           String parsedMsg = (String)messagesIterator.next();
101 
102           pageContext.getOut().write(parsedMsg.trim());
103         }
104       }
105     }
106     catch (Exception exception)
107     {
108       throw new JspTagException("NoticesTag:" + exception.toString());
109     }
110 
111     // Have the JSP Container continue the JSP page as normal
112     return EVAL_PAGE;
113   }
114 
115     /**
116      * Release all allocated resources.
117    *
118      */
119 
120     public void release()
121     {
122         super.release();
123 
124     path = null;
125     recursive = true;
126     }
127 }
128