1 package org.apache.jetspeed.util;
2
3 import org.apache.jetspeed.om.profile.Portlets;
4 import org.apache.jetspeed.om.profile.Entry;
5 import org.apache.jetspeed.om.profile.Profile;
6 import org.apache.jetspeed.services.rundata.JetspeedRunData;
7 import org.apache.jetspeed.portal.PortletSet;
8
9 import org.apache.turbine.util.RunData;
10
11 import java.util.*;
12
13 /***
14 * This class is used to handle different mediatype profile
15 *
16 * @author <a href="mailto:A.Kempf@web.de">Andreas Kempf</a>
17 * @version $Id: AutoProfile.java,v1.0 2001/10/31
18 */
19 public class AutoProfile
20 {
21 /***
22 * Load a mediaType specific profile
23 * --------------------------------------------------------------------------
24 * last modified: 10/31/01
25 * Andreas Kempf, Siemens ICM S CP PE, Munich
26 */
27 /*
28 public static Profile loadProfile (RunData rundata, String mediaType) throws Exception
29 {
30 if ((mediaType != null) && (mediaType.equalsIgnoreCase("wml")))
31 {
32 Profile runProfile = ((JetspeedRunData)rundata).getProfile();
33 if (runProfile != null)
34 {
35 runProfile.store();
36 }
37 Profile myPro = Profiler.getProfile (rundata, MimeType.WML);
38 ((JetspeedRunData)rundata).setProfile (myPro);
39
40 // It is essential that a session object exists!
41 rundata.getSession().setAttribute ("customizeType", "wml");
42 }
43 else if ((mediaType != null) && (mediaType.equalsIgnoreCase("xml")))
44 {
45 Profile runProfile = ((JetspeedRunData)rundata).getProfile();
46 if (runProfile != null)
47 {
48 runProfile.store();
49 }
50 Profile myPro = Profiler.getProfile (rundata, MimeType.XML);
51 ((JetspeedRunData)rundata).setProfile (myPro);
52
53 // It is essential that a session object exists!
54 rundata.getSession().setAttribute ("customizeType", "xml");
55 }
56 else
57 {
58 Profile runProfile = ((JetspeedRunData)rundata).getProfile();
59 if (runProfile != null)
60 {
61 runProfile.store();
62 }
63 Profile myPro = Profiler.getProfile (rundata, MimeType.HTML);
64 ((JetspeedRunData)rundata).setProfile (myPro);
65
66 // It is essential that a session object exists!
67 rundata.getSession().setAttribute ("customizeType", "html");
68 }
69
70 return ((JetspeedRunData)rundata).getProfile();
71 }
72 */
73
74 /***
75 * Load a profile - the mediatype is depending on rundata settings
76 * The profile will load if the rundata.profile.mediatype differs from customtype (Session Param)
77 * if the param notForce is false, the profile will be loaded wether is already used or not
78 * --------------------------------------------------------------------------
79 * last modified: 10/31/01
80 * Andreas Kempf, Siemens ICM S CP PE, Munich
81 */
82 /*
83 public static Profile doIt (RunData rundata, boolean notForce) throws Exception
84 {
85 // retrieve current customization mediatype (stored in the user session object)
86 HttpSession ses = rundata.getSession ();
87
88 String mediaType = (String) ses.getAttribute ("customizeType");
89
90
91 if ((mediaType != null) && (mediaType.equalsIgnoreCase ("wml")))
92 {
93 // WML Profil nicht laden, wenn bereits vorhanden!
94 if (notForce)
95 {
96 if (!((JetspeedRunData)rundata).getProfile().getMediaType ().equalsIgnoreCase("wml"))
97 {
98 return loadProfile (rundata, "wml");
99 }
100 }
101 // WML auf jeden Fall neu laden!
102 else
103 return loadProfile (rundata, "wml");
104 }
105 else if ((mediaType != null) && (mediaType.equalsIgnoreCase ("xml")))
106 {
107 // WML Profil nicht laden, wenn bereits vorhanden!
108 if (notForce)
109 {
110 if (!((JetspeedRunData)rundata).getProfile().getMediaType ().equalsIgnoreCase("xml"))
111 {
112 return loadProfile (rundata, "xml");
113 }
114 }
115 // WML auf jeden Fall neu laden!
116 else
117 return loadProfile (rundata, "xml");
118
119
120 }
121 else if ((mediaType != null) && (mediaType.equalsIgnoreCase ("html")))
122 {
123 // HTML Profil nicht laden, wenn bereits vorhanden!
124 if (notForce)
125 {
126 if (!((JetspeedRunData)rundata).getProfile().getMediaType ().equalsIgnoreCase("html"))
127 {
128 return loadProfile (rundata, "html");
129 }
130 }
131 // HTML auf jeden Fall neu laden!
132 else
133 return loadProfile (rundata, "html");
134 }
135 return ((JetspeedRunData)rundata).getProfile();
136 }
137 */
138
139 // Create a list of all used portlets!
140 // last modified: 10/31/01
141 // Andreas Kempf, Siemens ICM S CP PE, Munich
142 // ---------------------------------------------------------------------
143 public static List getPortletList (RunData rundata)
144 {
145 Profile profile = ((JetspeedRunData)rundata).getCustomizedProfile();
146 Portlets allPortlets = profile.getDocument().getPortletsById(((PortletSet)((JetspeedRunData)rundata).getCustomized()).getID());
147
148
149 List installed = new ArrayList ();
150 Entry iPortlet;
151
152
153 if (allPortlets != null)
154 {
155 for (int ii = 0; ii < allPortlets.getEntryCount(); ii++)
156 {
157 iPortlet = (Entry) allPortlets.getEntry (ii);
158 installed.add (iPortlet);
159 }
160 }
161
162 return installed;
163 }
164
165 }