1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.jetspeed.modules.actions.portlets.designer;
17
18 import java.io.File;
19 import java.io.FileInputStream;
20 import java.io.FileOutputStream;
21 import java.util.Hashtable;
22 import java.util.Properties;
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 IMAGES_DIRECTORY = "images/designer/";
44 private static final String DEFAULT_CSS = "css/default.css";
45
46 private String 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
58 {
59
60 }
61
62 public void doUpload(RunData rundata, Context context)
63 {
64 Hashtable ht = new Hashtable();
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 bgColor = "";
78 String fontFace = "";
79 String fontSize = "";
80 String fontColor = "";
81 String bgImage = "";
82 String title = "";
83
84 if (setLogo)
85 {
86 fileLogo = rundata.getParameters().getFileItem("imgLogo");
87 }
88
89 if (setBgImage)
90 {
91 String 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 message = "";
126 try
127 {
128 String logo = "";
129
130 String slash = System.getProperty("file.separator");
131 String imagePath = FormatPath.normalizeDirectoryPath(rundata
132 .getServletContext().getRealPath("/" + IMAGES_DIRECTORY));
133
134 if (fileLogo != null)
135 {
136 File file = new File(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 f = new File(imagePath + logo);
153 if (f.exists())
154 {
155 f.delete();
156 }
157 FileUploader fu = new FileUploader();
158 boolean hasUploaded = fu.upload(fileLogo, imagePath, fileTypes);
159
160
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
177
178 }
179
180 if (fileBgImage != null)
181 {
182 File file1 = new File(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 f = new File(imagePath + bgImage);
199 if (f.exists()) f.delete();
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 ee)
260 {
261 message = ee.getMessage();
262 }
263 }
264
265 public void editHeader(RunData rundata, Context context, Hashtable ht)
266 throws Exception
267 {
268 try
269 {
270 String logo = (String) ht.get("logo");
271 String bgImage = (String) ht.get("BgImage");
272 String bgColor = (String) ht.get("BgColor");
273 String fontSize = (String) ht.get("FontSize");
274 String fontColor = (String) ht.get("FontColor");
275 String title = (String) ht.get("PortalTitle");
276
277 boolean setLogo = Boolean.valueOf((String) ht.get("SetLogo")).booleanValue();
278 boolean setBgImage = Boolean.valueOf((String) ht.get("SetBgImage"))
279 .booleanValue();
280 boolean setBgColor = Boolean.valueOf((String) ht.get("SetBgColor"))
281 .booleanValue();
282 boolean setFontSize = Boolean.valueOf((String) ht.get("SetFontSize"))
283 .booleanValue();
284 boolean setFontColor = Boolean.valueOf((String) ht.get("SetFontColor"))
285 .booleanValue();
286 boolean setPortalTitle = Boolean.valueOf((String) ht.get("SetTitle"))
287 .booleanValue();
288
289 String DEFAULT_ROOT = File.separator + "WEB-INF" + File.separator
290 + "conf" + File.separator;
291 String root = rundata.getServletConfig().getServletContext()
292 .getRealPath(DEFAULT_ROOT)
293 + File.separator;
294
295 Properties prop = new Properties();
296 prop.clear();
297 prop.load(new FileInputStream(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 stream = new FileOutputStream(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 logoJR = prop.getProperty("topnav.logo.file");
362 String bgImageJR = prop.getProperty("topnav.bg.image");
363 String bgColorJR = prop.getProperty("topnav.bg.color");
364 String fontSizeJR = prop.getProperty("topnav.font.size");
365 String 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 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
386 {
387 try
388 {
389 String logo = IMAGES_DIRECTORY + "jetspeed-logo.gif";
390 String bgImage = "";
391 String fontSize = "10";
392 String title = "Jakarta Jetspeed";
393
394 String DEFAULT_ROOT = File.separator + "WEB-INF" + File.separator
395 + "conf" + File.separator;
396 String root = rundata.getServletConfig().getServletContext()
397 .getRealPath(DEFAULT_ROOT)
398 + File.separator;
399
400 Properties prop = new Properties();
401 prop
402 .load(new FileInputStream(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 stream = new FileOutputStream(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 e)
439 {
440 context.put("settingStatus",
441 "Error occurred while changing to default settings. ");
442 log.error(e);
443 }
444 }
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870 }
871