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

Quick Search    Search Deep

Source code: com/RuntimeCollective/content/bean/Editor.java


1   /* $Header: /home/CVS/rjp/src/com/RuntimeCollective/content/bean/Editor.java,v 1.7 2003/09/30 15:12:46 joe Exp $
2    * $Revision: 1.7 $
3    * $Date: 2003/09/30 15:12:46 $
4    *
5    * ====================================================================
6    *
7    * Josephine : http://www.runtime-collective.com/josephine/index.html
8    *
9    * Copyright (C) 2003 Runtime Collective
10   * 
11   * This product includes software developed by the
12   * Apache Software Foundation (http://www.apache.org/).
13   *
14   * This library is free software; you can redistribute it and/or
15   * modify it under the terms of the GNU Lesser General Public
16   * License as published by the Free Software Foundation; either
17   * version 2.1 of the License, or (at your option) any later version.
18   *
19   * This library is distributed in the hope that it will be useful,
20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22   * Lesser General Public License for more details.
23   *
24   * You should have received a copy of the GNU Lesser General Public
25   * License along with this library; if not, write to the Free Software
26   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27   *
28   */
29  
30  package com.RuntimeCollective.content.bean; 
31  
32  import com.RuntimeCollective.webapps.bean.User;
33  import com.RuntimeCollective.webapps.bean.SimpleActor;
34  import com.RuntimeCollective.webapps.RuntimeDataSource;
35  import com.RuntimeCollective.webapps.RuntimeParameters;
36  import com.RuntimeCollective.webapps.bean.EntityBean;
37  
38  import java.sql.SQLException;
39  
40  /** 
41   * Represents a user of the content module who has editor or administrator permissions.
42   * 
43   * @deprecated This class shouldn't be used anymore - use the Permissions packages instead.
44   * @author Joe Holmberg
45   * @version $Id: Editor.java,v 1.7 2003/09/30 15:12:46 joe Exp $
46   */ 
47  public class Editor extends SimpleActor {
48  
49      /** The name of the database table for this bean type. */
50      public static final String DATABASE_TABLE = "content_editor";
51  
52  
53      // == Entity Bean Constructors ==================================
54  
55      /** Construct a new blank Editor with a new unique ID. This does NOT create a User for it to wrap.
56       * @deprecated This class shouldn't be used anymore - use the Permissions packages instead.
57       */
58      public Editor() throws SQLException{
59          // Get a new id for this bean
60          this.id = RuntimeDataSource.nextId();
61      }
62  
63      /** Generate an Editor from the database for the given primary key. 
64       * @deprecated This class shouldn't be used anymore - use the Permissions packages instead.
65       * @param id The primary key of the Editor to find. 
66       */ 
67      public Editor( int id ) throws SQLException { 
68          this.id=id;
69          // All the work is done in finding the user for this Editor
70    Object[] result = RuntimeDataSource.queryRow( "SELECT user_id, is_admin, is_editor FROM content_editor WHERE id="+id );
71  
72    if (result.length != 3) {
73        throw new SQLException("Error loading record from content_editor: there should have been 3 values selected; there were "+result.length);
74    }
75  
76    int userId = Integer.parseInt(result[0].toString());
77          user = (User) RuntimeParameters.getStore().get( "com.RuntimeCollective.webapps.bean.User", userId );
78  
79    setIsAdmin( RuntimeDataSource.toboolean(result[1].toString() ) );
80    setIsEditor( RuntimeDataSource.toboolean(result[2].toString() ) );
81  
82    RuntimeParameters.logDebug(this, "The Editor's user is "+user+", and they are admin? "+isAdmin()+", editor?"+isEditor());
83      }
84  
85      /** Get the Editor for a user.
86       * @deprecated This class shouldn't be used anymore - use the Permissions packages instead.
87       */
88      public static Editor getEditorForUser( User user ) throws SQLException {
89    if (user == null) {
90        return null;
91    }
92  
93    EntityBean editorObj = null;
94          int[] results = RuntimeDataSource.queryInts( "SELECT id FROM content_editor WHERE user_id=" + user.getId() );
95    if (results.length > 0) {
96        int id = results[0];
97        editorObj = RuntimeParameters.getStore().get( "com.RuntimeCollective.content.bean.Editor", id );
98    }
99  
100   Editor editor = (Editor)editorObj;
101   if (editor == null) {
102       editor = (Editor)RuntimeParameters.getStore().create( "com.RuntimeCollective.content.bean.Editor" );
103       // Set the user
104       editor.setUser(user);
105   }
106 
107   return editor;
108 
109   /*
110       editorObj = RuntimeParameters.getStore().create( "com.RuntimeCollective.content.bean.Editor" );
111       Editor editor=(Editor)editorObj;
112       // Set the user
113       editor.setUser(user);
114 
115       return (Editor)editorObj;
116   */
117     }
118 
119     
120     /** Save this Editor.
121      * @deprecated This class shouldn't be used anymore - use the Permissions packages instead.
122      */
123     public void save() throws SQLException {
124         RuntimeParameters.getStore().save(user);
125   saveToDatabase();
126     }
127 
128     /** Save this Editor to the database.
129      * @deprecated This class shouldn't be used anymore - use the Permissions packages instead.
130      */
131     public void saveToDatabase() throws SQLException {
132         RuntimeDataSource.save(id,"content_editor", new String[] {"user_id", "is_admin", "is_editor"}, new Object[] { Integer.toString( user.getId() ), new Boolean(isAdmin()), new Boolean(isEditor()) } );
133     }
134 
135     /** Delete this Editor
136      * @deprecated This class shouldn't be used anymore - use the Permissions packages instead.
137      */
138     public void delete() throws SQLException {
139         RuntimeParameters.getStore().delete(user);
140     }
141 
142 
143 
144     // == Properties ==========================================
145 
146     /** The user is a staff administrator.
147      * @deprecated This class shouldn't be used anymore - use the Permissions packages instead.
148      */ 
149     protected boolean isAdmin = false; 
150 
151     /** Get if the user is a staff administrator.
152      * @deprecated This class shouldn't be used anymore - use the Permissions packages instead.
153      */ 
154     public boolean getIsAdmin() { return this.isAdmin; } 
155 
156     /** Get if the user is a staff administrator.
157      * @deprecated This class shouldn't be used anymore - use the Permissions packages instead.
158      */ 
159     public boolean isAdmin() { return this.getIsAdmin(); } 
160 
161     /** Set the user is a staff administrator.
162      * @deprecated This class shouldn't be used anymore - use the Permissions packages instead.
163      */ 
164     public void setIsAdmin(boolean isAdmin) { this.isAdmin = isAdmin; } 
165 
166     /** The user is a content editor.
167      * @deprecated This class shouldn't be used anymore - use the Permissions packages instead.
168      */ 
169     protected boolean isEditor = false; 
170 
171     /** Get if the user is a content editor.
172      * @deprecated This class shouldn't be used anymore - use the Permissions packages instead.
173      */ 
174     public boolean getIsEditor() { return this.isEditor; } 
175 
176     /** Get if the user is a staff member.
177      * @deprecated This class shouldn't be used anymore - use the Permissions packages instead.
178      */ 
179     public boolean isEditor() { return this.getIsEditor(); } 
180 
181     /** Set the user is a content editor.
182      * @deprecated This class shouldn't be used anymore - use the Permissions packages instead.
183      */ 
184     public void setIsEditor(boolean isEditor) { this.isEditor = isEditor; } 
185 
186     
187 }