KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > modules > actions > portlets > designer > HeaderAction


1 /*
2  * Copyright 2000-2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.jetspeed.modules.actions.portlets.designer;
17
18 import java.io.File JavaDoc;
19 import java.io.FileInputStream JavaDoc;
20 import java.io.FileOutputStream JavaDoc;
21 import java.util.Hashtable JavaDoc;
22 import java.util.Properties JavaDoc;
23
24 import org.apache.jetspeed.modules.actions.portlets.VelocityPortletAction;
25
26 import org.apache.jetspeed.portal.portlets.VelocityPortlet;
27 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
28 import org.apache.jetspeed.services.logging.JetspeedLogger;
29 import org.apache.turbine.services.resources.TurbineResources;
30 import org.apache.turbine.util.RunData;
31 import org.apache.turbine.util.upload.FileItem;
32 import org.apache.velocity.context.Context;
33
34 /**
35  * Header Action
36  *
37  * @author <a HREF="mailto:jlim@gluecode.com">Jonas Lim</a>
38  * @version $Id: HeaderAction.java,v 1.2 2004/03/22 22:26:58 taylor Exp $
39  */

40 public class HeaderAction extends VelocityPortletAction
41 {
42     private static final JetspeedLogger log = JetspeedLogFactoryService.getLogger(HeaderAction.class.getName());
43     private static final String JavaDoc IMAGES_DIRECTORY = "images/designer/";
44     private static final String JavaDoc DEFAULT_CSS = "css/default.css";
45
46     private String JavaDoc fileTypes[] =
47     { "image/jpg",
48       "image/gif",
49       "image/jpeg",
50        "application/x-shockwave-flash",
51        "image/png",
52        "image/x-png"
53     };
54     
55     
56     protected void buildNormalContext(VelocityPortlet portlet, Context context,
57             RunData rundata) throws Exception JavaDoc
58     {
59
60     }
61
62     public void doUpload(RunData rundata, Context context)
63     {
64         Hashtable JavaDoc ht = new Hashtable JavaDoc();
65
66         boolean setLogo = rundata.getParameters().getBoolean("setLogo");
67         boolean setBgImage = rundata.getParameters().getBoolean("setBgImage");
68         boolean setBgColor = rundata.getParameters().getBoolean("setBgColor");
69         boolean setFontFace = rundata.getParameters().getBoolean("setFontFace");
70         boolean setFontSize = rundata.getParameters().getBoolean("setFontSize");
71         boolean setFontColor = rundata.getParameters().getBoolean(
72                 "setFontColor");
73         boolean setTitle = rundata.getParameters().getBoolean("setTitle");
74
75         FileItem fileLogo = null;
76         FileItem fileBgImage = null;
77         String JavaDoc bgColor = "";
78         String JavaDoc fontFace = "";
79         String JavaDoc fontSize = "";
80         String JavaDoc fontColor = "";
81         String JavaDoc bgImage = "";
82         String JavaDoc title = "";
83
84         if (setLogo)
85         {
86             fileLogo = rundata.getParameters().getFileItem("imgLogo");
87         }
88
89         if (setBgImage)
90         {
91             String JavaDoc sampleBg = rundata.getParameters()
92                     .getString("sampleBgImage").trim();
93             if (sampleBg != null && sampleBg.length() != 0)
94             {
95                 bgImage = IMAGES_DIRECTORY + sampleBg;
96             } else
97             {
98                 fileBgImage = rundata.getParameters().getFileItem("bgImage");
99             }
100         }
101
102         if (setBgColor)
103         {
104             bgColor = rundata.getParameters().getString("bgColor").trim();
105         }
106         if (setFontFace)
107         {
108             fontFace = rundata.getParameters().getString("fontFace").trim();
109         }
110         if (setFontSize)
111         {
112             fontSize = rundata.getParameters().getString("fontSize").trim();
113         }
114         if (setFontColor)
115         {
116             fontColor = rundata.getParameters().getString("fontColor").trim();
117         }
118         if (setTitle)
119         {
120             title = rundata.getParameters().getString("portalTitle").trim();
121         }
122
123         log.info("fontColor : " + fontColor);
124
125         String JavaDoc message = "";
126         try
127         {
128             String JavaDoc logo = "";
129
130             String JavaDoc slash = System.getProperty("file.separator");
131             String JavaDoc imagePath = FormatPath.normalizeDirectoryPath(rundata
132                     .getServletContext().getRealPath("/" + IMAGES_DIRECTORY));
133
134             if (fileLogo != null)
135             {
136                 File JavaDoc file = new File JavaDoc(fileLogo.getFileName());
137                 logo = file.getName();
138
139                 int index = logo.lastIndexOf("\\");
140                 int index2 = logo.lastIndexOf("//");
141
142                 if (index > 0)
143                 {
144                     logo = logo.substring(index + 1);
145                 }
146
147                 if (index2 > 0)
148                 {
149                     logo = logo.substring(index2 + 1);
150                 }
151
152                 File JavaDoc f = new File JavaDoc(imagePath + logo);
153                 if (f.exists())
154                 {
155                     f.delete();//nik
156
}
157                 FileUploader fu = new FileUploader();
158                 boolean hasUploaded = fu.upload(fileLogo, imagePath, fileTypes);
159                 //String filename = fu.getFilename(fileLogo, imagePath,
160
// fileTypes);
161

162                 if (hasUploaded == true)
163                 {
164                     logo = IMAGES_DIRECTORY + logo;
165                 } else
166                 {
167                     context
168                             .put(
169                                     "logoStatus",
170                                     "Error occurred while uploading "
171                                             + logo
172                                             + ". Only gif, jpg, and jpeg image files can be uploaded. ");
173                     logo = "";
174                 }
175
176                 //context.put("logoFile", filename);
177

178             }
179
180             if (fileBgImage != null)
181             {
182                 File JavaDoc file1 = new File JavaDoc(fileBgImage.getFileName());
183                 bgImage = file1.getName();
184
185                 int index = bgImage.lastIndexOf("\\");
186                 int index2 = bgImage.lastIndexOf("//");
187
188                 if (index > 0)
189                 {
190                     bgImage = bgImage.substring(index + 1);
191                 }
192
193                 if (index2 > 0)
194                 {
195                     bgImage = bgImage.substring(index2 + 1);
196                 }
197
198                 File JavaDoc f = new File JavaDoc(imagePath + bgImage);
199                 if (f.exists()) f.delete();//nik
200
FileUploader fu = new FileUploader();
201                 boolean hasUploaded = fu.upload(fileBgImage, imagePath,
202                         fileTypes);
203                 log.info("hasUploaded : " + hasUploaded);
204
205                 if (hasUploaded == true)
206                     bgImage = IMAGES_DIRECTORY + bgImage;
207                 else
208                 {
209                     context
210                             .put(
211                                     "bgStatus",
212                                     "Error while uploading "
213                                             + bgImage
214                                             + ". Only gif, jpg, and jpeg image files can be uploaded. ");
215                     bgImage = "";
216                 }
217
218             }
219
220             boolean hasColor = (bgColor == null || bgColor.length() < 1);
221             boolean hasFontFace = (fontFace == null || fontFace.length() < 1);
222             boolean hasFontSize = (fontSize == null || fontSize.length() < 1);
223             boolean hasFontColor = (fontColor == null || fontColor.length() < 1);
224
225             if (hasColor)
226             {
227                 bgColor = "white";
228             }
229             if (hasFontFace)
230             {
231                 fontFace = "verdana";
232             }
233             if (hasFontSize)
234             {
235                 fontSize = "12";
236             }
237             if (hasFontColor)
238             {
239                 fontColor = "black";
240             }
241
242             ht.put("logo", logo);
243             ht.put("BgImage", bgImage);
244             ht.put("BgColor", bgColor);
245             ht.put("FontFace", fontFace);
246             ht.put("FontSize", fontSize);
247             ht.put("FontColor", fontColor);
248             ht.put("PortalTitle", title);
249             ht.put("SetLogo", String.valueOf(setLogo));
250             ht.put("SetBgImage", String.valueOf(setBgImage));
251             ht.put("SetBgColor", String.valueOf(setBgColor));
252             ht.put("SetFontFace", String.valueOf(setFontFace));
253             ht.put("SetFontSize", String.valueOf(setFontSize));
254             ht.put("SetFontColor", String.valueOf(setFontColor));
255             ht.put("SetTitle", String.valueOf(setTitle));
256
257             editHeader(rundata, context, ht);
258
259         } catch (Exception JavaDoc ee)
260         {
261             message = ee.getMessage();
262         }
263     }
264
265     public void editHeader(RunData rundata, Context context, Hashtable JavaDoc ht)
266             throws Exception JavaDoc
267     {
268         try
269         {
270             String JavaDoc logo = (String JavaDoc) ht.get("logo");
271             String JavaDoc bgImage = (String JavaDoc) ht.get("BgImage");
272             String JavaDoc bgColor = (String JavaDoc) ht.get("BgColor");
273             String JavaDoc fontSize = (String JavaDoc) ht.get("FontSize");
274             String JavaDoc fontColor = (String JavaDoc) ht.get("FontColor");
275             String JavaDoc title = (String JavaDoc) ht.get("PortalTitle");
276
277             boolean setLogo = Boolean.valueOf((String JavaDoc) ht.get("SetLogo")).booleanValue();
278             boolean setBgImage = Boolean.valueOf((String JavaDoc) ht.get("SetBgImage"))
279                     .booleanValue();
280             boolean setBgColor = Boolean.valueOf((String JavaDoc) ht.get("SetBgColor"))
281                     .booleanValue();
282             boolean setFontSize = Boolean.valueOf((String JavaDoc) ht.get("SetFontSize"))
283                     .booleanValue();
284             boolean setFontColor = Boolean.valueOf((String JavaDoc) ht.get("SetFontColor"))
285                     .booleanValue();
286             boolean setPortalTitle = Boolean.valueOf((String JavaDoc) ht.get("SetTitle"))
287                     .booleanValue();
288
289             String JavaDoc DEFAULT_ROOT = File.separator + "WEB-INF" + File.separator
290                     + "conf" + File.separator;
291             String JavaDoc root = rundata.getServletConfig().getServletContext()
292                     .getRealPath(DEFAULT_ROOT)
293                     + File.separator;
294
295             Properties JavaDoc prop = new Properties JavaDoc();
296             prop.clear();
297             prop.load(new FileInputStream JavaDoc(root + "JetspeedResources.properties"));
298
299             TurbineResources trProp = (TurbineResources) TurbineResources
300                     .getResources(root + "JetspeedResources.properties");
301
302             int counter = 0;
303             if (setBgImage && !setBgColor && (counter == 0))
304             {
305                 setBgColor = true;
306                 bgColor = "FFFFFF";
307                 counter = 1;
308             }
309             if (!setBgImage && setBgColor && (counter == 0))
310             {
311                 setBgImage = true;
312                 bgImage = "";
313                 counter = 1;
314             }
315             if (setBgImage && setBgColor && (counter == 0))
316             {
317                 setBgColor = true;
318                 bgColor = "FFFFFF";
319                 counter = 1;
320             }
321
322             if (setLogo)
323             {
324                 TurbineResources.setProperty("topnav.logo.file", logo);
325                 prop.setProperty("topnav.logo.file", logo);
326             }
327             if (setBgImage)
328             {
329                 TurbineResources.setProperty("topnav.bg.image", bgImage);
330                 prop.setProperty("topnav.bg.image", bgImage);
331             }
332             if (setBgColor)
333             {
334                 TurbineResources.setProperty("topnav.bg.color", bgColor);
335                 prop.setProperty("topnav.bg.color", bgColor);
336             }
337             if (setFontSize)
338             {
339                 TurbineResources.setProperty("topnav.font.size", fontSize);
340                 prop.setProperty("topnav.font.size", fontSize);
341             }
342             if (setFontColor)
343             {
344                 TurbineResources.setProperty("topnav.font.color", fontColor);
345                 prop.setProperty("topnav.font.color", fontColor);
346             }
347             if (setPortalTitle)
348             {
349                 TurbineResources.setProperty("portal.title", title);
350                 prop.setProperty("portal.title", title);
351             }
352                 
353             FileOutputStream JavaDoc stream = new FileOutputStream JavaDoc(root + "JetspeedResources.properties");
354             prop.store(stream, "topnav.logo.file");
355             prop.store(stream, "topnav.bg.image");
356             prop.store(stream, "topnav.bg.color");
357             prop.store(stream, "topnav.font.size");
358             prop.store(stream, "topnav.font.color");
359             stream.close();
360             
361             String JavaDoc logoJR = prop.getProperty("topnav.logo.file");
362             String JavaDoc bgImageJR = prop.getProperty("topnav.bg.image");
363             String JavaDoc bgColorJR = prop.getProperty("topnav.bg.color");
364             String JavaDoc fontSizeJR = prop.getProperty("topnav.font.size");
365             String JavaDoc fontColorJR = prop.getProperty("topnav.font.color");
366
367             log.info("new Logo : " + logoJR);
368             log.info("new bgImageJR : " + bgImageJR);
369             log.info("new bgColorJR : " + bgColorJR);
370             log.info("new fontSizeJR : " + fontSizeJR);
371             log.info("new fontColorJR : " + fontColorJR);
372
373             prop = null;
374             System.gc();
375
376             context.put("settingStatus", "Successfully changed settings.");
377         } catch (Exception JavaDoc e)
378         {
379             context.put("settingStatus",
380                     "Error occurred while changing settings.");
381             log.error(e);
382         }
383     }
384
385     public void doDefault(RunData rundata, Context context) throws Exception JavaDoc
386     {
387         try
388         {
389             String JavaDoc logo = IMAGES_DIRECTORY + "jetspeed-logo.gif";
390             String JavaDoc bgImage = "";
391             String JavaDoc fontSize = "10";
392             String JavaDoc title = "Jakarta Jetspeed";
393
394             String JavaDoc DEFAULT_ROOT = File.separator + "WEB-INF" + File.separator
395                     + "conf" + File.separator;
396             String JavaDoc root = rundata.getServletConfig().getServletContext()
397                     .getRealPath(DEFAULT_ROOT)
398                     + File.separator;
399
400             Properties JavaDoc prop = new Properties JavaDoc();
401             prop
402                     .load(new FileInputStream JavaDoc(root
403                             + "JetspeedResources.properties"));
404             prop.clone();
405
406             TurbineResources trProp = (TurbineResources) TurbineResources
407                     .getResources(root + "JetspeedResources.properties");
408
409             TurbineResources.setProperty("portal.title", title);
410             prop.setProperty("portal.title", title);
411             TurbineResources.setProperty("topnav.logo.file", logo);
412             prop.setProperty("topnav.logo.file", logo);
413             TurbineResources.setProperty("topnav.bg.image","");
414             prop.setProperty("topnav.bg.image","");
415             TurbineResources.setProperty("topnav.bg.color", "");
416             prop.setProperty("topnav.bg.color", "");
417       
418             TurbineResources.setProperty("topnav.font.size", "");
419             prop.setProperty("topnav.font.size", "");
420       
421             TurbineResources.setProperty("topnav.font.color", "");
422         prop.setProperty("topnav.font.color", "");
423
424
425             FileOutputStream JavaDoc stream = new FileOutputStream JavaDoc(root + "JetspeedResources.properties");
426                         
427             prop.save(stream, "topnav.logo.file");
428             
429             prop.save(stream, "portal.title");
430             prop.save(stream, "topnav.bg.image");
431             prop.save(stream, "topnav.bg.color");
432             prop.save(stream, "ptopnav.font.size");
433             prop.save(stream, "ptopnav.font.size");
434             stream.close();
435             
436             context.put("settingStatus",
437                     "Successfully changed to default settings.");
438         } catch (Exception JavaDoc e)
439         {
440             context.put("settingStatus",
441                     "Error occurred while changing to default settings. ");
442             log.error(e);
443         }
444     }
445     
446     
447     // Methods used by the portlet designer. Not yet implemented
448
/*
449     public void doScheme(RunData rundata, Context context)
450     {
451         Registry reg = org.apache.jetspeed.services.Registry
452                 .get("PortletControl");
453
454         //parameters for border design and skin
455         String portletTheme = rundata.getParameters().getString("PortletTheme");
456         String tabTheme = rundata.getParameters().getString("TabTheme");
457         //conditions for changing portlet settings
458         boolean setPBgImage = rundata.getParameters().getBoolean(
459                 "setPortletBgImage");
460         boolean setPBgColor = rundata.getParameters().getBoolean(
461                 "setPortletBgColor");
462         boolean setPFontFace = rundata.getParameters().getBoolean(
463                 "setPortletFontFace");
464         boolean setPFontColor = rundata.getParameters().getBoolean(
465                 "setPortletFontColor");
466
467         try
468         {
469             if (setPBgImage || setPBgColor || setPFontFace || setPFontColor)
470             {
471                 Hashtable ht = new Hashtable();
472                 ht.put("setPBgImage", Boolean.valueOf(setPBgImage));
473                 ht.put("setPBgColor", Boolean.valueOf(setPBgColor));
474                 ht.put("setPFontFace", Boolean.valueOf(setPFontFace));
475                 ht.put("setPFontColor", Boolean.valueOf(setPFontColor));
476
477                 editPortlet(rundata, context, ht);
478             }
479
480             if (!portletTheme.equalsIgnoreCase("none"))
481             {
482                 BasePortletControlEntry bpce = (BasePortletControlEntry) reg
483                         .getEntry("TitlePortletControl");
484                 Parameter paramName = bpce.getParameter("theme");
485                 String theme = paramName.getValue();
486                 log.info("portletTheme : " + theme);
487                 log.info("!portletTheme.equals('none') : "
488                         + !portletTheme.equals("none"));
489                 log.info("new portletTheme : " + portletTheme);
490
491                 bpce.removeParameter("theme");
492                 bpce.addParameter("theme", portletTheme);
493             }
494
495             if (!tabTheme.equalsIgnoreCase("none"))
496             {
497                 BasePortletControlEntry bpce = (BasePortletControlEntry) reg
498                         .getEntry("TabControl");
499                 Parameter paramName = bpce.getParameter("theme");
500                 String theme = paramName.getValue();
501                 log.info("tabTheme : " + theme);
502                 log.info("!tabTheme.equals('none') : "
503                         + !tabTheme.equals("none"));
504                 log.info("new tabTheme : " + tabTheme);
505
506                 bpce.removeParameter("theme");
507                 bpce.addParameter("theme", tabTheme);
508
509                 bpce = (BasePortletControlEntry) reg
510                         .getEntry("PanedPortletControl");
511                 paramName = bpce.getParameter("theme");
512                 theme = paramName.getValue();
513                 log.info("tabtheme : " + theme);
514                 log.info("new tabTheme : " + tabTheme);
515
516                 bpce.removeParameter("theme");
517                 bpce.addParameter("theme", tabTheme);
518
519                 //setting for menu pane.
520                 String menuTheme = "";
521                 if (tabTheme.indexOf("blue") != -1)
522                         menuTheme = "jetspeed-menu_blue.vm";
523                 if (tabTheme.indexOf("gray") != -1)
524                         menuTheme = "jetspeed-menu_gray.vm";
525                 if (tabTheme.indexOf("green") != -1)
526                         menuTheme = "jetspeed-menu_green.vm";
527                 if (tabTheme.indexOf("red") != -1)
528                         menuTheme = "jetspeed-menu_red.vm";
529                 if (tabTheme.equals("jetspeed-tab.vm"))
530                         menuTheme = "jetspeed-menu.vm";
531
532                 bpce = (BasePortletControlEntry) reg.getEntry("MenuControl");
533                 paramName = bpce.getParameter("theme");
534                 theme = paramName.getValue();
535
536                 bpce.removeParameter("theme");
537                 bpce.addParameter("theme", menuTheme);
538
539             }
540             context.put("settingPStatus",
541                     "Successfully changed to new settings.");
542         } catch (Exception e)
543         {
544             context.put("settingPStatus",
545                     "Error occurred while changing settings.");
546             log.error(e);
547         }
548     }
549
550     public void editPortlet(RunData rundata, Context context, Hashtable ht)
551     {
552         try
553         {
554             boolean setPBgImage = false;
555             boolean setPBgColor = false;
556             boolean setPFontFace = false;
557             boolean setPFontColor = false;
558
559             if (ht != null || ht.size() > 0)
560             {
561                 setPBgImage = ((Boolean) ht.get("setPBgImage")).booleanValue();
562                 setPBgColor = ((Boolean) ht.get("setPBgColor")).booleanValue();
563                 setPFontFace = ((Boolean) ht.get("setPFontFace"))
564                         .booleanValue();
565                 setPFontColor = ((Boolean) ht.get("setPFontColor"))
566                         .booleanValue();
567             }
568
569             FileItem filePBgImage = null;
570             String pBgColor = "";
571             String pFontFace = "";
572             String pFontSize = "";
573             String pFontColor = "";
574
575             String pBgImage = "";
576
577             if (setPBgImage)
578             {
579                 String sampleBg = rundata.getParameters().getString(
580                         "samplePBgImage").trim();
581                 log.info("samplePBgImage : " + sampleBg);
582
583                 if (sampleBg != null && sampleBg.length() != 0)
584                 {
585                     pBgImage = IMAGES_DIRECTORY + sampleBg;
586                 } else
587                 {
588                     filePBgImage = rundata.getParameters().getFileItem(
589                             "portletBgImage");
590                 }
591             }
592
593             if (setPBgColor)
594             {
595                 pBgColor = rundata.getParameters().getString("portletBgColor")
596                         .trim();
597             }
598             if (setPFontFace)
599             {
600                 pFontFace = rundata.getParameters()
601                         .getString("portletFontFace").trim();
602             }
603             if (setPFontColor)
604             {
605                 pFontColor = rundata.getParameters().getString(
606                         "portletFontColor").trim();
607             }
608
609             String slash = System.getProperty("file.separator");
610             String imagePath = FormatPath.normalizeDirectoryPath(rundata.getServletContext().getRealPath("/" + IMAGES_DIRECTORY));
611                     
612             String cssFullPath = FormatPath.normalizeDirectoryPath(rundata.getServletContext().getRealPath("/" + DEFAULT_CSS));
613
614             if (filePBgImage != null)
615             {
616                 log.info("Entering uploadBgImage");
617                 File file1 = new File(filePBgImage.getFileName());
618                 pBgImage = file1.getName();
619
620                 int index = pBgImage.lastIndexOf("\\");
621                 int index2 = pBgImage.lastIndexOf("//");
622
623                 if (index > 0)
624                 {
625                     pBgImage = pBgImage.substring(index + 1);
626                 }
627
628                 if (index2 > 0)
629                 {
630                     pBgImage = pBgImage.substring(index2 + 1);
631                 }
632
633                 log.info("File2 : " + pBgImage);
634
635                 //filePBgImage.write(imagePath + pBgImage);
636                 FileUploader fu = new FileUploader();
637                 boolean hasUploaded = fu.upload(filePBgImage, imagePath,
638                         fileTypes);
639
640                 if (hasUploaded == true)
641                     pBgImage = IMAGES_DIRECTORY + pBgImage;
642                 else
643                 {
644                     context
645                             .put(
646                                     "bgPStatus",
647                                     "Error occurred while uploading "
648                                             + pBgImage
649                                             + ". Only gif, jpg, and jpeg image files can be uploaded. ");
650                     pBgImage = "";
651                 }
652
653                 log.info("writing : " + imagePath + pBgImage);
654             }
655
656             boolean hasPColor = (pBgColor == null || pBgColor.length() < 1);
657             boolean hasPFontFace = (pFontFace == null || pFontFace.length() < 1);
658             boolean hasPFontSize = (pFontSize == null || pFontSize.length() < 1);
659             boolean hasPFontColor = (pFontColor == null || pFontColor.length() < 1);
660
661             if (hasPColor)
662             {
663                 pBgColor = "white";
664             }
665             if (hasPFontFace)
666             {
667                 pFontFace = "verdana";
668             }
669             if (hasPFontSize)
670             {
671                 pFontSize = "12";
672             }
673             if (hasPFontColor)
674             {
675                 pFontColor = "000000";
676             }
677
678             String DEFAULT_ROOT = File.separator + "WEB-INF" + File.separator
679                     + "conf" + File.separator;
680             String root = rundata.getServletConfig().getServletContext()
681                     .getRealPath(DEFAULT_ROOT)
682                     + File.separator;
683
684             Properties prop = new Properties();
685             prop.clear();
686             prop
687                     .load(new FileInputStream(root
688                             + "JetspeedResources.properties"));
689
690             TurbineResources trProp = (TurbineResources) TurbineResources
691                     .getResources(root + "JetspeedResources.properties");
692
693             int counter = 0;
694             if (setPBgImage && !setPBgColor && (counter == 0))
695             {
696                 setPBgColor = true;
697                 pBgColor = "FFFFFF";
698                 counter = 1;
699             }
700             if (!setPBgImage && setPBgColor && (counter == 0))
701             {
702                 setPBgImage = true;
703                 pBgImage = "";
704                 counter = 1;
705             }
706             if (setPBgImage && setPBgColor && (counter == 0))
707             {
708                 setPBgColor = true;
709                 pBgColor = "FFFFFF";
710                 counter = 1;
711             }
712
713             if (setPBgImage)
714             {
715                 trProp.setProperty("portlet.bg.image", pBgImage);
716                 prop.setProperty("portlet.bg.image", pBgImage);
717             }
718             if (setPBgColor)
719             {
720                 trProp.setProperty("portlet.bg.color", pBgColor);
721                 prop.setProperty("portlet.bg.color", pBgColor);
722             }
723             if (setPFontFace)
724             {
725                 trProp.setProperty("portlet.font.face", pFontFace);
726                 prop.setProperty("portlet.font.face", pFontFace);
727             }
728             if (setPFontColor)
729             {
730                 trProp.setProperty("portlet.font.color", pFontColor);
731                 prop.setProperty("portlet.font.color", pFontColor);
732             }
733
734             FileOutputStream stream = new FileOutputStream(root + "JetspeedResources.properties");
735             prop.save(stream, "portlet.logo.file");
736             prop.save(stream, "portlet.bg.image");
737             prop.save(stream, "portlet.bg.color");
738             prop.save(stream, "portlet.font.face");
739             prop.save(stream, "portlet.font.color");
740             stream.close();
741             String pbgImageJR = prop.getProperty("portlet.bg.image");
742             String pbgColorJR = prop.getProperty("portlet.bg.color");
743             String pfontFaceJR = prop.getProperty("portlet.font.face");
744             //String pfontSizeJR = prop.getProperty("portlet.font.size");
745             String pfontColorJR = prop.getProperty("portlet.font.color");
746
747             CSSTemplate.buildTemplate(cssFullPath, pfontFaceJR, pfontColorJR);
748
749             log.info("new bgImageJR : " + pbgImageJR);
750             log.info("new bgColorJR : " + pbgColorJR);
751             log.info("new fontFaceJR : " + pfontFaceJR);
752             log.info("new fontColorJR : " + pfontColorJR);
753
754             context.put("settingPStatus",
755                     "Successfully change to new settings.");
756
757         } catch (Exception e)
758         {
759             context.put("settingPStatus",
760                     "Error occured while changing settings.");
761             log.error(e);
762         }
763     }
764
765     public void doPdefault(RunData rundata, Context context)
766     {
767         try
768         {
769             //change to default for tab and menu theme
770             String portletTheme = "jetspeed.vm";
771             String tabTheme = "jetspeed-tab.vm";
772             String menuTheme = "jetspeed-menu.vm";
773
774             Registry reg = org.apache.jetspeed.services.Registry
775                     .get("PortletControl");
776
777             //for portletTheme
778             BasePortletControlEntry bpce = (BasePortletControlEntry) reg
779                     .getEntry("TitlePortletControl");
780             Parameter paramName = bpce.getParameter("theme");
781             String theme = paramName.getValue();
782             log.info("portletTheme : " + theme);
783             log.info("!portletTheme.equals('none') : "
784                     + !portletTheme.equals("none"));
785             log.info("new portletTheme : " + portletTheme);
786
787             bpce.removeParameter("theme");
788             bpce.addParameter("theme", portletTheme);
789
790             //for tabTheme
791             bpce = (BasePortletControlEntry) reg.getEntry("TabControl");
792             paramName = bpce.getParameter("theme");
793             theme = paramName.getValue();
794             log.info("tabTheme : " + theme);
795             log.info("!tabTheme.equals('none') : " + !tabTheme.equals("none"));
796             log.info("new tabTheme : " + tabTheme);
797
798             bpce.removeParameter("theme");
799             bpce.addParameter("theme", tabTheme);
800
801             bpce = (BasePortletControlEntry) reg
802                     .getEntry("PanedPortletControl");
803             paramName = bpce.getParameter("theme");
804             theme = paramName.getValue();
805             log.info("tabtheme : " + theme);
806             log.info("new tabTheme : " + tabTheme);
807
808             bpce.removeParameter("theme");
809             bpce.addParameter("theme", tabTheme);
810
811             //for menuTheme
812             bpce = (BasePortletControlEntry) reg.getEntry("MenuControl");
813             paramName = bpce.getParameter("theme");
814             theme = paramName.getValue();
815
816             bpce.removeParameter("theme");
817             bpce.addParameter("theme", menuTheme);
818
819             //change to default for font face and size, background,
820             String slash = System.getProperty("file.separator");
821             String cssFullPath = FormatPath.normalizeDirectoryPath(rundata.getServletContext().getRealPath("/" + DEFAULT_CSS));
822             
823             CSSTemplate.buildTemplate(cssFullPath, "verdana", "000000");
824
825             String bgImage = "";
826             String bgColor = "white";
827
828             String DEFAULT_ROOT = File.separator + "WEB-INF" + File.separator
829                     + "conf" + File.separator;
830             String root = rundata.getServletConfig().getServletContext()
831                     .getRealPath(DEFAULT_ROOT)
832                     + File.separator;
833
834             Properties prop = new Properties();
835             prop.clear();
836             
837             FileInputStream istream = new FileInputStream(root + "JetspeedResources.properties");
838                         
839             prop.load(istream);
840             istream.close();
841             
842             TurbineResources trProp = (TurbineResources) TurbineResources
843                     .getResources(root + "JetspeedResources.properties");
844
845             trProp.setProperty("portlet.bg.image", bgImage);
846             prop.setProperty("portlet.bg.image", bgImage);
847             trProp.setProperty("portlet.bg.color", bgColor);
848             prop.setProperty("portlet.bg.color", bgColor);
849             trProp.setProperty("portlet.font.color", "000000");
850             prop.setProperty("portlet.font.color", "000000");
851             trProp.setProperty("portlet.font.face", "verdana");
852             prop.setProperty("portlet.font.face", "verdana");
853
854             FileOutputStream stream = new FileOutputStream(root + "JetspeedResources.properties");
855             
856             prop.store(stream, "portlet.bg.image");
857             prop.store(stream, "portlet.bg.color");
858             stream.close();
859             context.put("settingPStatus",
860                     "Successfully changed to default settings.");
861         } catch (Exception e)
862         {
863             context.put("settingPStatus",
864                     "Error occurred while changing to default settings.");
865             log.error(e);
866         }
867     }
868    */

869
870 }
871
872
Popular Tags