View Javadoc

1   package net.sourceforge.blogentis.modules.actions;
2   
3   //-----------------------------------------------------------------------
4   //Blogentis - a blog publishing platform.
5   //Copyright (C) 2004 Tassos Bassoukos <abassouk@gmail.com>
6   //
7   //This library is free software; you can redistribute it and/or
8   //modify it under the terms of the GNU Lesser General Public
9   //License as published by the Free Software Foundation; either
10  //version 2.1 of the License, or (at your option) any later version.
11  //
12  //This library is distributed in the hope that it will be useful,
13  //but WITHOUT ANY WARRANTY; without even the implied warranty of
14  //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  //Lesser General Public License for more details.
16  //
17  //You should have received a copy of the GNU Lesser General Public
18  //License along with this library; if not, write to the Free Software
19  //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  //-----------------------------------------------------------------------
21  //
22  //$Id: BlogPropMod.java,v 1.3 2004/10/31 07:16:22 tassos Exp $
23  //
24  
25  import net.sourceforge.blogentis.om.Blog;
26  import net.sourceforge.blogentis.om.StoredBlog;
27  import net.sourceforge.blogentis.om.StoredBlogPeer;
28  import net.sourceforge.blogentis.turbine.BlogParameterParser;
29  import net.sourceforge.blogentis.turbine.SecureBlogAction;
30  import net.sourceforge.blogentis.utils.BlogConstants;
31  import net.sourceforge.blogentis.utils.MappedConfiguration;
32  
33  import org.apache.commons.configuration.SubsetConfiguration;
34  import org.apache.turbine.util.RunData;
35  import org.apache.velocity.context.Context;
36  
37  public class BlogPropMod
38          extends SecureBlogAction {
39      protected String[] getPermissions() {
40          return new String[] {BlogConstants.PERM_ADMIN_BLOG};
41      }
42  
43      public void doPerform(RunData data, Context context)
44              throws Exception {
45          data.setMessage("Hmm... Unknown action requested!");
46      }
47  
48      public void doTitle(RunData data, Context context)
49              throws Exception {
50          BlogParameterParser pp = (BlogParameterParser)data.getParameters();
51          StoredBlog blog = StoredBlogPeer.retrieveByPK(pp.getBlog().getBlogId());
52          blog.setTitle(pp.getString("title", blog.getTitle()));
53          blog.setDescription(pp.getString("description", blog.getDescription()));
54          blog.save();
55      }
56  
57      public void doAppearance(RunData data, Context context)
58              throws Exception {
59          BlogParameterParser pp = (BlogParameterParser)data.getParameters();
60          Blog blog = pp.getBlog();
61          int state = pp.getInt("s", -1);
62          String prefix;
63          switch (state) {
64          case 1:
65              prefix = "blog";
66              break;
67          case 2:
68              prefix = "section";
69              break;
70          case 3:
71              prefix = "post";
72              break;
73          case 4:
74              prefix = "edit";
75              break;
76          default:
77              data.setMessage("Invalid object specified");
78              return;
79          }
80          MappedConfiguration master = blog.getConfiguration();
81          SubsetConfiguration conf = new SubsetConfiguration(master, prefix, ".");
82  
83          conf.setProperty("enableShort", pp.getBooleanObject("enableShort",
84                                                              new Boolean(true)));
85          conf.setProperty("enableFullText", pp
86                  .getBooleanObject("enableFullText", new Boolean(false)));
87          conf.setProperty("showComments", pp
88                  .getBooleanObject("showComments", new Boolean(false)));
89          conf.setProperty("enableDetails", pp
90                  .getBooleanObject("enableDetails", new Boolean(true)));
91          conf.setProperty("detailEnableBlog", pp
92                  .getBooleanObject("detailEnableBlog", new Boolean(true)));
93          conf.setProperty("detailEnableAuthor", pp
94                  .getBooleanObject("detailEnableAuthor", new Boolean(true)));
95          conf.setProperty("detailEnableSections", pp
96                  .getBooleanObject("detailEnableSections", new Boolean(true)));
97          conf.setProperty("detailEnablePerma", pp
98                  .getBooleanObject("detailEnablePerma", new Boolean(true)));
99          conf.setProperty("detailEnableCommentCount",
100                          pp.getBooleanObject("detailEnableCommentCount",
101                                              new Boolean(true)));
102         conf.setProperty("detailEnableCommentCount",
103                          pp.getBooleanObject("detailEnableCommentCount",
104                                              new Boolean(true)));
105         conf.setProperty("feedSize", pp.getIntObject("feedSize",
106                                                      new Integer(10)));
107         master.toString();
108         master.save();
109     }
110 }