Develop and Download Open Source Software

Browse CVS Repository

Diff of /pal/blog/src/java/jp/sf/pal/blog/model/BlogMessage.java

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.20 by shinsuke, Sat Nov 4 03:20:28 2006 UTC revision 1.21 by tigercat, Wed Feb 6 03:53:02 2008 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright 2005-2006 The Portal Application Laboratory Team.   * Copyright 2005-2008 The Portal Application Laboratory Team.
3   *   *
4   * Licensed under the Apache License, Version 2.0 (the "License");   * Licensed under the Apache License, Version 2.0 (the "License");
5   * you may not use this file except in compliance with the License.   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at   * You may obtain a copy of the License at
7   *   *
8   *      http://www.apache.org/licenses/LICENSE-2.0   *      http://www.apache.org/licenses/LICENSE-2.0
9   *   *
10   * Unless required by applicable law or agreed to in writing, software   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and   * See the License for the specific language governing permissions and
14   * limitations under the License.   * limitations under the License.
15   */   */
16  package jp.sf.pal.blog.model;  package jp.sf.pal.blog.model;
17    
18  import java.io.BufferedReader;  import java.io.BufferedReader;
19  import java.io.ByteArrayInputStream;  import java.io.ByteArrayInputStream;
20  import java.io.IOException;  import java.io.IOException;
21  import java.io.InputStreamReader;  import java.io.InputStreamReader;
22  import java.io.UnsupportedEncodingException;  import java.io.UnsupportedEncodingException;
23  import java.util.Date;  import java.util.Date;
24  import java.util.Iterator;  import java.util.Iterator;
25  import java.util.List;  import java.util.List;
26  import java.util.Set;  import java.util.Set;
27  import java.util.TreeSet;  import java.util.TreeSet;
28    
29  import javax.faces.context.FacesContext;  import javax.faces.context.ExternalContext;
30    import javax.faces.context.FacesContext;
31  import jp.sf.grizzly.pipeline.PipelineException;  
32  import jp.sf.grizzly.storage.StreamStorage;  import jp.sf.grizzly.pipeline.PipelineException;
33  import jp.sf.grizzly.storage.StreamStorageException;  import jp.sf.grizzly.storage.StreamStorage;
34  import jp.sf.grizzly.storage.impl.ByteArrayStreamStorageImpl;  import jp.sf.grizzly.storage.StreamStorageException;
35  import jp.sf.pal.blog.BlogConstants;  import jp.sf.grizzly.storage.impl.ByteArrayStreamStorageImpl;
36  import jp.sf.pal.blog.converter.Converter;  import jp.sf.pal.blog.BlogConstants;
37  import jp.sf.pal.blog.util.BlogCommentComparator;  import jp.sf.pal.blog.converter.Converter;
38  import jp.sf.pal.blog.util.BlogTrackbackComparator;  import jp.sf.pal.blog.util.BlogCommentComparator;
39    import jp.sf.pal.blog.util.BlogTrackbackComparator;
40  import org.apache.commons.lang.StringUtils;  
41  import org.apache.commons.logging.Log;  import org.apache.commons.lang.StringUtils;
42  import org.apache.commons.logging.LogFactory;  import org.apache.commons.logging.Log;
43  import org.seasar.framework.container.S2Container;  import org.apache.commons.logging.LogFactory;
44  import org.seasar.framework.container.factory.SingletonS2ContainerFactory;  import org.seasar.framework.container.S2Container;
45  import org.seasar.portlet.util.RenderResponseUtil;  import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
46    import org.seasar.portlet.util.RenderResponseUtil;
47  import com.marevol.utils.faces.util.DateFormatUtil;  
48    import com.marevol.utils.faces.util.DateFormatUtil;
49  /**  
50   * BlogMessage generated by hbm2java  /**
51   */   * BlogMessage generated by hbm2java
52  public class BlogMessage implements java.io.Serializable   */
53  {  public class BlogMessage implements java.io.Serializable
54      /**  {
55       * Logger for this class      /**
56       */       * Logger for this class
57      private static final Log log = LogFactory.getLog(BlogMessage.class);       */
58        private static final Log log = LogFactory.getLog(BlogMessage.class);
59      /**  
60       *      /**
61       */       *
62      private static final long serialVersionUID = -5551793167782445984L;       */
63        private static final long serialVersionUID = -5551793167782445984L;
64      public static final String ID = "id";  
65        public static final String ID = "id";
66      public static final String OWNER = "owner";  
67        public static final String OWNER = "owner";
68      public static final String TITLE = "title";  
69        public static final String TITLE = "title";
70      public static final String MESSAGE = "message";  
71        public static final String MESSAGE = "message";
72      public static final String CREATEDTIME = "createdtime";  
73        public static final String CREATEDTIME = "createdtime";
74      public static final String UPDATEDTIME = "updatedtime";  
75        public static final String UPDATEDTIME = "updatedtime";
76      // Fields      
77        // Fields    
78      private Long id;  
79        private Long id;
80      private BlogCategory blogcategory;  
81        private BlogCategory blogcategory;
82      private String owner;  
83        private String owner;
84      private String title;  
85        private String title;
86      private String message;  
87        private String message;
88      private String formattype;  
89        private String formattype;
90      private Date createdtime;  
91        private Date createdtime;
92      private Date updatedtime;  
93        private Date updatedtime;
94      private Set blogcomments;  
95        private Set blogcomments;
96      private Set blogtrackbacks;  
97        private Set blogtrackbacks;
98      // Constructors  
99        // Constructors
100      /** default constructor */  
101      public BlogMessage()      /** default constructor */
102      {      public BlogMessage()
103      }      {
104        }
105      /** constructor with id */  
106      public BlogMessage(Long id)      /** constructor with id */
107      {      public BlogMessage(Long id)
108          this.id = id;      {
109      }          this.id = id;
110        }
111      // Property accessors  
112        // Property accessors
113      /**  
114       *      /**
115       */       *
116      public Long getId()       */
117      {      public Long getId()
118          return this.id;      {
119      }          return this.id;
120        }
121      public void setId(Long id)  
122      {      public void setId(Long id)
123          this.id = id;      {
124      }          this.id = id;
125        }
126      /**  
127       *      /**
128       */       *
129      public BlogCategory getBlogCategory()       */
130      {      public BlogCategory getBlogCategory()
131          return this.blogcategory;      {
132      }          return this.blogcategory;
133        }
134      public void setBlogCategory(BlogCategory blogcategory)  
135      {      public void setBlogCategory(BlogCategory blogcategory)
136          this.blogcategory = blogcategory;      {
137      }          this.blogcategory = blogcategory;
138        }
139      /**  
140       *      /**
141       */       *
142      public String getOwner()       */
143      {      public String getOwner()
144          return this.owner;      {
145      }          return this.owner;
146        }
147      public void setOwner(String owner)  
148      {      public void setOwner(String owner)
149          this.owner = owner;      {
150      }          this.owner = owner;
151        }
152      /**  
153       *      /**
154       */       *
155      public String getTitle()       */
156      {      public String getTitle()
157          return this.title;      {
158      }          return this.title;
159        }
160      public void setTitle(String title)  
161      {      public void setTitle(String title)
162          this.title = title;      {
163      }          this.title = title;
164        }
165      /**  
166       *      /**
167       */       *
168      public String getMessage()       */
169      {      public String getMessage()
170          return this.message;      {
171      }          return this.message;
172        }
173      public void setMessage(String message)  
174      {      public void setMessage(String message)
175          this.message = message;      {
176      }          this.message = message;
177        }
178      /**  
179       *      /**
180       */       *
181      public String getFormattype()       */
182      {      public String getFormattype()
183          return this.formattype;      {
184      }          return this.formattype;
185        }
186      public void setFormattype(String formattype)  
187      {      public void setFormattype(String formattype)
188          this.formattype = formattype;      {
189      }          this.formattype = formattype;
190        }
191      /**  
192       *      /**
193       */       *
194      public Date getCreatedtime()       */
195      {      public Date getCreatedtime()
196          return this.createdtime;      {
197      }          return this.createdtime;
198        }
199      public void setCreatedtime(Date createdtime)  
200      {      public void setCreatedtime(Date createdtime)
201          this.createdtime = createdtime;      {
202      }          this.createdtime = createdtime;
203        }
204      /**  
205       *      /**
206       */       *
207      public Date getUpdatedtime()       */
208      {      public Date getUpdatedtime()
209          return this.updatedtime;      {
210      }          return this.updatedtime;
211        }
212      public void setUpdatedtime(Date updatedtime)  
213      {      public void setUpdatedtime(Date updatedtime)
214          this.updatedtime = updatedtime;      {
215      }          this.updatedtime = updatedtime;
216        }
217      /**  
218       *      /**
219       */       *
220      public Set getBlogComments()       */
221      {      public Set getBlogComments()
222          return this.blogcomments;      {
223      }          return this.blogcomments;
224        }
225      public void setBlogComments(Set blogcomments)  
226      {      public void setBlogComments(Set blogcomments)
227          this.blogcomments = blogcomments;      {
228      }          this.blogcomments = blogcomments;
229        }
230      /**  
231       *      /**
232       */       *
233      public Set getBlogTrackbacks()       */
234      {      public Set getBlogTrackbacks()
235          return this.blogtrackbacks;      {
236      }          return this.blogtrackbacks;
237        }
238      public void setBlogTrackbacks(Set blogtrackbacks)  
239      {      public void setBlogTrackbacks(Set blogtrackbacks)
240          this.blogtrackbacks = blogtrackbacks;      {
241      }          this.blogtrackbacks = blogtrackbacks;
242        }
243      public String getRedirectUrl()  
244      {      public String getRedirectUrl()
245          StringBuffer redirectUrl = new StringBuffer();      {
246          String url = RenderResponseUtil.createRenderURL().toString();          StringBuffer redirectUrl = new StringBuffer();
247          String fragment = null;          String url = RenderResponseUtil.createRenderURL().toString();
248          int fragmentIndex = url.indexOf("#");          String fragment = null;
249          if (fragmentIndex >= 0)          int fragmentIndex = url.indexOf("#");
250          {          if (fragmentIndex >= 0)
251              redirectUrl.append(url.substring(0, fragmentIndex));          {
252              fragment = url.substring(fragmentIndex);              redirectUrl.append(url.substring(0, fragmentIndex));
253          }              fragment = url.substring(fragmentIndex);
254          else          }
255          {          else
256              redirectUrl.append(url);          {
257              fragment = "";              redirectUrl.append(url);
258          }              fragment = "";
259          if (url.indexOf("?") < 0)          }
260          {          if (url.indexOf("?") < 0)
261              redirectUrl.append("?");          {
262          }              redirectUrl.append("?");
263          else          }
264          {          else
265              redirectUrl.append("&");          {
266          }              redirectUrl.append("&");
267          redirectUrl.append(FacesContext.getCurrentInstance()          }
268                  .getExternalContext().encodeNamespace(          ExternalContext exContext = FacesContext.getCurrentInstance()
269                          BlogConstants.BLOG_REDIRECT_ID));                  .getExternalContext();
270          redirectUrl.append("=");          redirectUrl.append(exContext.encodeNamespace(
271          redirectUrl.append(getId().toString());                  BlogConstants.BLOG_REDIRECT_ID));
272            redirectUrl.append("=");
273          redirectUrl.append(fragment);          redirectUrl.append(getId().toString());
274    
275          if (log.isDebugEnabled())          redirectUrl.append(fragment);
276          {  
277              log.debug("getRedirectUrl() - redirectUrl=" + redirectUrl          if (log.isDebugEnabled())
278                      + ", url=" + url + ", fragment=" + fragment          {
279                      + ", fragmentIndex=" + fragmentIndex);              log.debug("getRedirectUrl() - redirectUrl=" + redirectUrl
280          }                      + ", url=" + url + ", fragment=" + fragment
281                        + ", fragmentIndex=" + fragmentIndex);
282          return redirectUrl.toString();          }
283      }  
284            return redirectUrl.toString();
285      public void setRedirectUrl(String url)      }
286      {  
287          // NONE      public void setRedirectUrl(String url)
288      }      {
289            // NONE
290      public String getFormattedMessage()      }
291      {  
292        public String getFormattedMessage()
293          S2Container container = SingletonS2ContainerFactory.getContainer();      {
294    
295          List list = (List) container.getComponent(BlogConstants.CONVERTER_LIST);          S2Container container = SingletonS2ContainerFactory.getContainer();
296          Iterator ite = list.iterator();  
297          while (ite.hasNext())          List list = (List) container.getComponent(BlogConstants.CONVERTER_LIST);
298          {          Iterator ite = list.iterator();
299              Object obj = ite.next();          while (ite.hasNext())
300              if (obj instanceof Converter)          {
301              {              Object obj = ite.next();
302                  Converter converter = (Converter) obj;              if (obj instanceof Converter)
303                  if (converter.getFormatType().equals(getFormattype()))              {
304                  {                  Converter converter = (Converter) obj;
305                      StringBuffer buffer = new StringBuffer();                  if (converter.getFormatType().equals(getFormattype()))
306                      try                  {
307                      {                      StringBuffer buffer = new StringBuffer();
308                          StreamStorage storage;                      try
309                          try                      {
310                          {                          StreamStorage storage;
311                              storage = new ByteArrayStreamStorageImpl(                          try
312                                      new ByteArrayInputStream(getMessage()                          {
313                                              .getBytes(BlogConstants.UTF_8)),                              storage = new ByteArrayStreamStorageImpl(
314                                      BlogConstants.UTF_8);                                      new ByteArrayInputStream(getMessage()
315                          }                                              .getBytes(BlogConstants.UTF_8)),
316                          catch (UnsupportedEncodingException e1)                                      BlogConstants.UTF_8);
317                          {                          }
318                              log.warn("Unsupported encoding. ", e1);                          catch (UnsupportedEncodingException e1)
319                              storage = new ByteArrayStreamStorageImpl(                          {
320                                      new ByteArrayInputStream(getMessage()                              log.warn("Unsupported encoding. ", e1);
321                                              .getBytes()), BlogConstants.UTF_8);                              storage = new ByteArrayStreamStorageImpl(
322                          }                                      new ByteArrayInputStream(getMessage()
323                          converter.getConverter().invoke(storage);                                              .getBytes()), BlogConstants.UTF_8);
324                            }
325                          BufferedReader r = null;                          converter.getConverter().invoke(storage);
326                          try  
327                          {                          BufferedReader r = null;
328                              r = new BufferedReader(new InputStreamReader(                          try
329                                      storage.getResultInputStream(), storage                          {
330                                              .getEncoding()));                              r = new BufferedReader(new InputStreamReader(
331                              String l = null;                                      storage.getResultInputStream(), storage
332                              while ((l = r.readLine()) != null)                                              .getEncoding()));
333                              {                              String l = null;
334                                  buffer.append(l);                              while ((l = r.readLine()) != null)
335                                  buffer.append("\n");                              {
336                              }                                  buffer.append(l);
337                          }                                  buffer.append("\n");
338                          catch (UnsupportedEncodingException e)                              }
339                          {                          }
340                              log.warn("Unsupported Encoding. ", e);                          catch (UnsupportedEncodingException e)
341                          }                          {
342                          catch (StreamStorageException e)                              log.warn("Unsupported Encoding. ", e);
343                          {                          }
344                              log.warn("Stream Storage Exception. ", e);                          catch (StreamStorageException e)
345                          }                          {
346                          catch (IOException e)                              log.warn("Stream Storage Exception. ", e);
347                          {                          }
348                              log.error("I/O Exception. ", e);                          catch (IOException e)
349                          }                          {
350                          finally                              log.error("I/O Exception. ", e);
351                          {                          }
352                              if (r != null)                          finally
353                              {                          {
354                                  try                              if (r != null)
355                                  {                              {
356                                      r.close();                                  try
357                                  }                                  {
358                                  catch (IOException e)                                      r.close();
359                                  {                                  }
360                                  }                                  catch (IOException e)
361                              }                                  {
362                          }                                  }
363                          storage.destroy();                              }
364                          return buffer.toString();                          }
365                      }                          storage.destroy();
366                      catch (StreamStorageException e)                          return buffer.toString();
367                      {                      }
368                          log.error("StreamStorage Exception.", e);                      catch (StreamStorageException e)
369                          return getMessage();                      {
370                      }                          log.error("StreamStorage Exception.", e);
371                      catch (PipelineException e)                          return getMessage();
372                      {                      }
373                          log.error("Pipeline Exception.", e);                      catch (PipelineException e)
374                          return getMessage();                      {
375                      }                          log.error("Pipeline Exception.", e);
376                  }                          return getMessage();
377              }                      }
378              else                  }
379              {              }
380                  log.warn("Invalid converter: " + obj);              else
381                  return getMessage();              {
382              }                  log.warn("Invalid converter: " + obj);
383          }                  return getMessage();
384                }
385          return getMessage();          }
386      }  
387            return getMessage();
388      public String getFormattedUpdatedtime()      }
389      {  
390          return DateFormatUtil.getMediumFormattedDateTime(getUpdatedtime());      public String getFormattedUpdatedtime()
391      }      {
392            return DateFormatUtil.getMediumFormattedDateTime(getUpdatedtime());
393      public String getFormattedCreatedtime()      }
394      {  
395          return DateFormatUtil.getMediumFormattedDateTime(getCreatedtime());      public String getFormattedCreatedtime()
396      }      {
397            return DateFormatUtil.getMediumFormattedDateTime(getCreatedtime());
398      public String getAbbreviatedTitle()      }
399      {  
400          return getAbbreviatedTitle(BlogConstants.DEFAULT_TITLE_MAX_LENGTH);      public String getAbbreviatedTitle()
401      }      {
402            return getAbbreviatedTitle(BlogConstants.DEFAULT_TITLE_MAX_LENGTH);
403      public String getAbbreviatedTitle(int maxLength)      }
404      {  
405          return StringUtils.abbreviate(getTitle(), maxLength);      public String getAbbreviatedTitle(int maxLength)
406      }      {
407            return StringUtils.abbreviate(getTitle(), maxLength);
408      public void setAbbreviatedTitle(String title)      }
409      {  
410          setTitle(title);      public void setAbbreviatedTitle(String title)
411      }      {
412            setTitle(title);
413      public int getBlogCommentSize()      }
414      {  
415          if (getBlogComments() != null)      public int getBlogCommentSize()
416          {      {
417              return getBlogComments().size();          if (getBlogComments() != null)
418          }          {
419          return 0;              return getBlogComments().size();
420      }          }
421            return 0;
422      public int getBlogTrackbackSize()      }
423      {  
424          if (getBlogTrackbacks() != null)      public int getBlogTrackbackSize()
425          {      {
426              return getBlogTrackbacks().size();          if (getBlogTrackbacks() != null)
427          }          {
428          return 0;              return getBlogTrackbacks().size();
429      }          }
430            return 0;
431      public String getTrackbackUrl()      }
432      {  
433          return FacesContext.getCurrentInstance().getExternalContext()      public String getTrackbackUrl()
434                  .getRequestContextPath()      {
435                  + "/trackback/" + getId();          return FacesContext.getCurrentInstance().getExternalContext()
436      }                  .getRequestContextPath()
437                    + "/trackback/" + getId();
438      public Set getSortedBlogComments()      }
439      {  
440          TreeSet ts = new TreeSet(new BlogCommentComparator(      public Set getSortedBlogComments()
441                  BlogCommentComparator.ASC));      {
442          ts.addAll(getBlogComments());          TreeSet ts = new TreeSet(new BlogCommentComparator(
443          return (Set) ts;                  BlogCommentComparator.ASC));
444      }          ts.addAll(getBlogComments());
445            return (Set) ts;
446      public Set getSortedBlogTrackbacks()      }
447      {  
448          TreeSet ts = new TreeSet(new BlogTrackbackComparator(      public Set getSortedBlogTrackbacks()
449                  BlogTrackbackComparator.ASC));      {
450          ts.addAll(getBlogTrackbacks());          TreeSet ts = new TreeSet(new BlogTrackbackComparator(
451          return (Set) ts;                  BlogTrackbackComparator.ASC));
452      }          ts.addAll(getBlogTrackbacks());
453            return (Set) ts;
454      /**      }
455       * @return Returns the emptyTitle.  
456       */      /**
457      public boolean isEmptyTitle()       * @return Returns the emptyTitle.
458      {       */
459          return StringUtils.isEmpty(getTitle());      public boolean isEmptyTitle()
460      }      {
461            return StringUtils.isEmpty(getTitle());
462      /**      }
463       * @param emptyTitle The emptyTitle to set.  
464       */      /**
465      public void setEmptyTitle(boolean emptyTitle)       * @param emptyTitle The emptyTitle to set.
466      {       */
467      }      public void setEmptyTitle(boolean emptyTitle)
468  }      {
469        }
470    }

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26