View Javadoc

1   /*
2    *  ginp - Java Web Application for Viewing Photo Collections
3    *  Copyright (C) 2004  Douglas John Culnane <doug@culnane.net>
4    *
5    *  This program is free software; you can redistribute it and/or modify
6    *  it under the terms of the GNU General Public License as published by
7    *  the Free Software Foundation; either version 2 of the License, or
8    *  any later version.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   *
19   */
20  
21  package net.sf.ginp.tags;
22  
23  import java.io.File;
24  import java.io.FileReader;
25  import java.io.LineNumberReader;
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.jsp.JspException;
28  import javax.servlet.jsp.JspTagException;
29  import net.sf.ginp.GinpModel;
30  import net.sf.ginp.config.ModelUtil;
31  import net.sf.ginp.util.StringTool;
32  import org.apache.commons.logging.Log;
33  import org.apache.commons.logging.LogFactory;
34  
35  /**
36   *  For the Current PicCollection's currently selected Folder retrieve information
37   *  from the ginpfolder.xml data file.
38   *
39   *@author    doc
40   */
41  public class GetFolderInfo extends javax.servlet.jsp.tagext.TagSupport
42           implements javax.servlet.jsp.tagext.IterationTag {
43  
44      private  GinpModel         model;
45      private Log log = LogFactory.getLog(GetFolderInfo.class);
46  
47  
48      /**
49       *  Description of the Method
50       *
51       *@return                   Description of the Return Value
52       *@exception  JspException  Description of the Exception
53       */
54      public int doStartTag() throws JspException {
55  
56          String  title        = "";
57          String  description  = "";
58          String  date         = "";
59          String  time         = "";
60  
61  		try {
62  			model = ModelUtil.getModel((HttpServletRequest) pageContext.getRequest());
63  		} catch (Exception e) {
64  			throw new JspException(e);
65  		}
66          try {
67              File  fl  = new File(model.getCollection().getRoot()
68                       + model.getCollection().getPath() + "ginpfolder.xml");
69              if (fl.exists()) {
70                  FileReader        fr    = new FileReader(fl);
71                  LineNumberReader  lr    = new LineNumberReader(fr);
72                  StringBuffer      sb    = new StringBuffer();
73                  String            temp;
74  
75                  while ((temp = lr.readLine()) != null) {
76                      sb.append(temp + "\n");
77                  }
78  
79                  // Date
80                  date = StringTool.getXMLTagContent("date", sb.toString());
81                  if (date != null) {
82                      pageContext.setAttribute("date", date);
83                  } else {
84                      pageContext.setAttribute("date", "");
85                  }
86  
87                  // Time
88                  time = StringTool.getXMLTagContent("time", sb.toString());
89                  if (time != null) {
90                      pageContext.setAttribute("time", time);
91                  } else {
92                      pageContext.setAttribute("time", "");
93                  }
94  
95                  // Title
96                  temp = StringTool.getXMLTagContent("title", sb.toString());
97                  title = StringTool.getXMLTagContent(
98                                  model.getLocale().getLanguage(), temp);
99                  if (title != null) {
100                     pageContext.setAttribute("title", title);
101                 } else {
102                     pageContext.setAttribute("title", "");
103                 }
104 
105                 // description
106                 temp = StringTool.getXMLTagContent("description", sb.toString());
107                 description = StringTool.getXMLTagContent(
108                                 model.getLocale().getLanguage(), temp);
109                 if (description != null) {
110                     pageContext.setAttribute("description", description);
111                 } else {
112                     pageContext.setAttribute("description", "");
113                 }
114 
115                 pageContext.setAttribute("path", model.getCollection().getPath());
116                 pageContext.setAttribute("colid", "" + model.getCurrCollectionId());
117                 pageContext.setAttribute("langcode", "" + model.getLocale().getLanguage());
118 
119                 return EVAL_BODY_AGAIN;
120             } else {
121                 return SKIP_BODY;
122             }
123         } catch (Exception ex) {
124             return SKIP_BODY;
125         }
126     }
127 }
128 
129