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

Quick Search    Search Deep

Source code: com/obinary/cms/taglibs/Out.java


1   /**
2    *
3    * Magnolia and its source-code is licensed under the LGPL.
4    * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5    * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6    * you are required to provide proper attribution to obinary.
7    * If you reproduce or distribute the document without making any substantive modifications to its content,
8    * please use the following attribution line:
9    *
10   * Copyright 1993-2003 obinary Ltd. (http://www.obinary.com) All rights reserved.
11   *
12   * */
13  
14  
15  
16  
17  package com.obinary.cms.taglibs;
18  
19  
20  import com.obinary.cms.core.Container;
21  import com.obinary.cms.core.Atom;
22  import com.obinary.cms.core.Content;
23  import com.obinary.cms.util.Resource;
24  
25  import javax.servlet.jsp.tagext.TagSupport;
26  import javax.servlet.jsp.JspWriter;
27  import javax.servlet.http.HttpServletRequest;
28  import javax.jcr.PropertyType;
29  import java.io.IOException;
30  
31  
32  /**
33   * User: sameercharles
34   * Date: Apr 28, 2003
35   * Time: 11:20:59 AM
36   * @author Sameer Charles
37   * @version 1.0
38   */
39  
40  
41  public class Out extends TagSupport {
42  
43  
44      private String atomName;
45      private Content container;
46      private Atom atom;
47      private String actpage = "false";
48      private String property = "";
49  
50  
51  
52      private String lineBreak = Atom.HTML_LINEBREAK;
53  
54  
55  
56  
57      /**
58       * <p>starts out tag</p>
59       *
60       * @return int
61       */
62      public int doStartTag() {
63          if (this.actpage.equals("true")) {
64              this.container = Resource.getCurrentActivePage((HttpServletRequest)pageContext.getRequest());
65              return SKIP_BODY;
66          }
67          this.container = (Content) Resource.getLocalContainer((HttpServletRequest)pageContext.getRequest());
68          if (this.container == null) {
69              this.container = (Content) Resource.getGlobalContainer((HttpServletRequest)pageContext.getRequest());
70          }
71          return SKIP_BODY;
72      }
73  
74  
75  
76      /**
77       * <p>continue evaluating jsp</p>
78       *
79       * @return int
80       */
81      public int doEndTag() {
82          this.display();
83          return EVAL_PAGE;
84      }
85  
86  
87  
88      /**
89       * <p>set the atom name</p>
90       *
91       * @param name
92       */
93      public void setAtomName(String name) {
94          this.atomName = name;
95      }
96  
97  
98       /**
99       * <p>set the actpage</p>
100      *
101      * @param set
102      */
103     public void setActpage(String set) {
104         this.actpage = set;
105     }
106 
107 
108      /**
109      * <p>set the property to retrieve information from files</p>
110      *
111      * @param property
112      */
113     public void setProperty(String property) {
114         this.property = property;
115     }
116 
117     /**
118      * <p>set the lineBreak String</p>
119      *
120      * @param lineBreak
121      */
122     public void setLineBreak(String lineBreak) {
123         this.lineBreak = lineBreak;
124     }
125 
126 
127     /**
128      * <p></p>
129      */
130     private void printString() {
131         JspWriter out = pageContext.getOut();
132         try {
133             if (this.lineBreak.equals("")) out.print(this.atom.getString());
134             else out.print(this.atom.getString(this.lineBreak));
135         } catch (IOException e) {}
136     }
137 
138 
139 
140     /**
141      * <p></p>
142      */
143     private void printLong() {
144         JspWriter out = pageContext.getOut();
145         try {
146             out.print(this.atom.getLong());
147         } catch (IOException e) {}
148     }
149 
150 
151 
152     /**
153      * <p></p>
154      */
155     private void printDouble() {
156         JspWriter out = pageContext.getOut();
157         try {
158             out.print(this.atom.getDouble());
159         } catch (IOException e) {}
160     }
161 
162 
163 
164     /**
165      * <p></p>
166      */
167     private void printDate() {
168         JspWriter out = pageContext.getOut();
169         try {
170             out.print(this.atom.getDate().getTime().toString());
171         } catch (Exception e) {}
172     }
173 
174 
175 
176     /**
177       *
178       */
179      private void display() {
180          try {
181        if (!this.property.equals("")) this.atom = this.container.getContainer(this.atomName+"_properties").getAtom(this.property);
182        else this.atom = this.container.getAtom(this.atomName);
183              int type = this.atom.getType();
184              if (type == PropertyType.STRING) {
185                  this.printString();
186              } else if (type == PropertyType.LONG) {
187                  this.printLong();
188              } else if (type == PropertyType.DOUBLE) {
189                  this.printDouble();
190              } else if (type == PropertyType.DATE) {
191                  this.printDate();
192              }
193          } catch (Exception e) {}
194 
195      }
196 
197 
198 
199 
200 
201 
202 }