KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > JahiaData


1
2 //
3
// ____.
4
// __/\ ______| |__/\. _______
5
// __ .____| | \ | +----+ \
6
// _______| /--| | | - \ _ | : - \_________
7
// \\______: :---| : : | : | \________>
8
// |__\---\_____________:______: :____|____:_____\
9
// /_____|
10
//
11
// . . . i n j a h i a w e t r u s t . . .
12
//
13

14 //
15
// JahiaData
16
// EV 30.10.2000
17
// EV 23.12.2000 settings is not anymore in JahiaData, but in ParamBean
18
//
19
// params()
20
// fields()
21
// containers()
22
// gui()
23
//
24
//
25

26 package org.jahia.data;
27
28 import org.jahia.data.containers.JahiaContainerSet;
29 import org.jahia.data.fields.JahiaFieldSet;
30 import org.jahia.exceptions.JahiaException;
31 import org.jahia.gui.GuiBean;
32 import org.jahia.params.ParamBean;
33 import org.jahia.registries.ServicesRegistry;
34 import org.jahia.services.pages.JahiaPage;
35 import org.jahia.services.usermanager.JahiaUser;
36 import org.jahia.utils.JahiaConsole;
37
38
39 public class JahiaData {
40
41     public static final String JavaDoc JAHIA_DATA = "org.jahia.data.JahiaData";
42
43     private ParamBean jParams;
44
45     private JahiaFieldSet fieldSet;
46     private JahiaContainerSet containerSet;
47     private GuiBean guiBean;
48
49     /***
50         * constructor
51         * Build a JahiaData and optionaly can force to create or not the fields set or containers set.
52         * This is used in particular situation where fields and conternaer sets are not required,
53         * i.e. : when some engines are called from JahiaAdministration Servlet
54         *
55         * @author NK
56         * @param ParamBean jParams
57         * @param boolean doBuildData
58         */

59     public JahiaData (ParamBean jParams, boolean doBuildData)
60     throws JahiaException
61     {
62         this.jParams = jParams;
63         if ( doBuildData ){
64             buildData(); // throws JahiaException
65
} else {
66             guiBean = new GuiBean( this.params() );
67         }
68     } // end constructor
69

70
71
72     /***
73         * constructor
74         * EV 30.10.2000
75         * EV 18.11.2000 added jSettings in parameters
76         *
77         */

78     public JahiaData (ParamBean jParams)
79     throws JahiaException
80     {
81         this.jParams = jParams;
82
83         buildData(); // throws JahiaException
84
} // end constructor
85

86
87
88     /***
89         * buildData
90         * EV 30.10.2000
91         *
92         */

93     private void buildData()
94     throws JahiaException
95     {
96         try {
97
98             // Get the current page and user
99
JahiaPage currentPage = params().getPage();
100             JahiaUser currentUser = params().getUser();
101
102             if (currentPage != null)
103             {
104                 if (currentUser != null)
105                 {
106                     // test if the user has read access to the current page.
107
if (currentPage.checkReadAccess (currentUser))
108                     {
109
110                         fieldSet = ServicesRegistry.getInstance().getJahiaFieldService(
111                                             ).buildFieldStructureForPage( this, params().getEntryLoadRequest() );
112                         containerSet = ServicesRegistry.getInstance().getJahiaContainersService(
113                                             ).buildContainerStructureForPage( this, params().getEntryLoadRequest() );
114                         guiBean = new GuiBean( this.params() );
115                     }
116
117                 } else {
118                     throw new JahiaException ("No user present !",
119                             "No current user defined in the params in buildData() method.",
120                             JahiaException.USER_ERROR, JahiaException.ERROR_SEVERITY);
121                 }
122             } else {
123                 String JavaDoc errorMsg = "Page does not exist : " + jParams.getPageID();
124                 JahiaConsole.println ( "OperationManager", errorMsg + " -> BAILING OUT" );
125                 throw new JahiaException ("404 Page not found",
126                                           errorMsg, JahiaException.PAGE_ERROR, JahiaException.ERROR_SEVERITY );
127             }
128
129         } catch (JahiaException je) {
130             if (je.getSeverity() > JahiaException.WARNING_SEVERITY) {
131                 JahiaConsole.println( "JahiaData", "Error in buildData -> BAILING OUT" );
132                 throw je;
133             } else {
134                 JahiaConsole.println( "JahiaData", "Warning in buildData. Continuing..." );
135             }
136         }
137     } // end buildData;
138

139
140     /***
141         * accessor methods
142         * EV 30.10.2000
143         *
144         */

145     public ParamBean params() { return jParams; }
146     public JahiaPage page() { return jParams.getPage(); } // for upward compatibility
147
public JahiaFieldSet fields() { return fieldSet; }
148     public JahiaContainerSet containers() { return containerSet; }
149     public GuiBean gui() { return guiBean; }
150     // end accessor methods
151

152     public ParamBean getParamBean() {
153         return jParams;
154     }
155
156     public JahiaFieldSet getFields() {
157         return fieldSet;
158     }
159
160     public JahiaContainerSet getContainerLists() {
161         return containerSet;
162     }
163
164 } // end JahiaData
165

166
Popular Tags