KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > clipbuilder > html > bean > ClipperBean


1 package org.jahia.clipbuilder.html.bean;
2
3 import java.util.*;
4
5 import org.jahia.clipbuilder.html.XML.*;
6 import org.jahia.clipbuilder.html.struts.*;
7 import org.jahia.clipbuilder.html.util.*;
8
9 /**
10  * Catch attribut of the description
11  *
12  *@author Tlili Khaled
13  */

14 public class ClipperBean extends Bean {
15
16     // attribute
17
private String JavaDoc description;
18     private String JavaDoc name;
19     private String JavaDoc targetUrl;
20
21     //Clipper configuration
22
private ConfigureBean configurationBean;
23
24     //Portlet Configuration
25
private PortletConfigBean portletConfigBean;
26
27     //filter
28
private FilterBean filterBean;
29
30     // contain the sequence of all url
31
private List urlListBean = new ArrayList();
32     private boolean hasBeanInit = false;
33
34     private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(ClipperBean.class);
35
36
37     /**
38      * Constructor for the DescriptionBean object
39      */

40     public ClipperBean() {
41
42     }
43
44
45     /**
46      * Constructor for the ClipperBean object
47      *
48      *@param xmlPath Description of Parameter
49      */

50     public ClipperBean(String JavaDoc xmlPath) {
51         loadWhithoutUrlBeanListFromXML(xmlPath);
52         setHasBeanInit(false);
53
54     }
55
56
57     /**
58      * Constructor for the DescriptionBean object
59      *
60      *@param form Description of Parameter
61      */

62     public ClipperBean(DescriptionClipperForm form) {
63         buildFromDescriptionForm(form);
64         setHasBeanInit(true);
65     }
66
67
68
69     /**
70      * Sets the MappingFormParam attribute of the ClipperBean object
71      */

72     /*
73      * public void setMappingFormParam(int posUrl, String formParentName,String formParentId, String paramName, String paramMapping) {
74      * UrlBean uBean = getUrlBean(posUrl);
75      * logger.debug("[Mapping for param " + paramName + " and url " + uBean.getUrlValue() + " has been setted+- ]");
76      * uBean.setMappingFormParam(formParentName,formParentId, paramName, paramMapping);
77      * }
78      */

79     /**
80      * Sets the Description attribute of the DescriptionClipperForm object
81      *
82      *@param description The new Description value
83      */

84     public void setDescription(String JavaDoc description) {
85         this.description = description;
86     }
87
88
89     /**
90      * Sets the Name attribute of the DescriptionClipperForm object
91      *
92      *@param name The new Name value
93      */

94     public void setName(String JavaDoc name) {
95         this.name = name;
96     }
97
98
99     /**
100      * Sets the TargetUrl attribute of the DescriptionClipperForm object
101      *
102      *@param targetUrl The new TargetUrl value
103      */

104     public void setTargetUrl(String JavaDoc targetUrl) {
105         //update target
106
this.targetUrl = targetUrl;
107     }
108
109
110
111     /**
112      * Sets the UrlListBean attribute of the ClipperBean object
113      *
114      *@param urlListBean The new UrlListBean value
115      */

116     public void setUrlListBean(List urlListBean) {
117         this.urlListBean = urlListBean;
118     }
119
120
121     /**
122      * Sets the HasBeanInit attribute of the ClipperBean object
123      *
124      *@param hasBeanInit The new HasBeanInit value
125      */

126     public void setHasBeanInit(boolean hasBeanInit) {
127         this.hasBeanInit = hasBeanInit;
128     }
129
130
131     /**
132      * Sets the ConfigurationBean attribute of the ClipperBean object
133      *
134      *@param configurationBean The new ConfigurationBean value
135      */

136     public void setConfigurationBean(ConfigureBean configurationBean) {
137         this.configurationBean = configurationBean;
138     }
139
140
141     /**
142      * Sets the FilterBean attribute of the ClipperBean object
143      *
144      *@param filterBean The new FilterBean value
145      */

146     public void setFilterBean(FilterBean filterBean) {
147         this.filterBean = filterBean;
148     }
149
150
151     /**
152      * Sets the PortletConfigBean attribute of the ClipperBean object
153      *
154      *@param portletConfigBean The new PortletConfigBean value
155      */

156     public void setPortletConfigBean(PortletConfigBean portletConfigBean) {
157         this.portletConfigBean = portletConfigBean;
158     }
159
160
161     /**
162      * Description of the Method
163      *
164      *@param uBean The new TargetUrlResources value
165      */

166     public void setTargetUrlResources(UrlBean uBean) {
167         setTargetUrl(uBean.getAbsoluteUrlValue());
168         setUrlListBean(new ArrayList());
169         addUrlBean(uBean);
170     }
171
172
173     /**
174      * Gets the UrlBean attribute of the ClipperBean object
175      *
176      *@param pos Description of Parameter
177      *@return The UrlBean value
178      */

179     public UrlBean getUrlBean(int pos) {
180         UrlBean uBean = null;
181         try {
182             uBean = (UrlBean) getUrlListBean().get(pos);
183             if (uBean == null) {
184                 logger.error("[ UrlBean at position " + pos +" not found ]");
185             }
186             else {
187                 logger.debug("[ UrlBean at position " + pos +" found ]");
188             }
189         }
190         catch (Exception JavaDoc ex) {
191                     logger.error("Error: "+ex.toString());
192                     ex.printStackTrace();
193         }
194         return uBean;
195     }
196
197
198     /**
199      * Gets the LastRecordedUrl attribute of the ClipperBean object
200      *
201      *@return The LastRecordedUrl value
202      */

203     public String JavaDoc getLastRecordedUrlValue() {
204         UrlBean uBean = getLastRecordedUrlBean();
205         return uBean.getAbsoluteUrlValue();
206     }
207
208
209     /**
210      * Gets the LastRecordedUrlBean attribute of the ClipperBean object
211      *
212      *@return The LastRecordedUrlBean value
213      */

214     public UrlBean getLastRecordedUrlBean() {
215         if (urlListIsEmpty()) {
216             logger.debug("[ Url list bean is empty ]");
217             return null;
218         }
219         Object JavaDoc o = getUrlListBean().get(getPositionLastRecordeUrl());
220         return (UrlBean) o;
221     }
222
223
224     /**
225      * Gets the NextRecordedUrl attribute of the ClipperBean object
226      *
227      *@param posUrl Description of Parameter
228      *@return The NextRecordedUrl value
229      */

230     public UrlBean getNextRecordedUrlBean(int posUrl) {
231         UrlBean uBean = this.getUrlBean(posUrl);
232         return this.getNextRecordedUrlBean(uBean);
233     }
234
235
236     /**
237      * Gets the NextRecordedUrl attribute of the ClipperBean object
238      *
239      *@param uBean Description of Parameter
240      *@return The NextRecordedUrl value
241      */

242     public UrlBean getNextRecordedUrlBean(UrlBean uBean) {
243         int currentIndex = getUrlListBean().indexOf(uBean);
244         int indexNextUrl = currentIndex + 1;
245         //test that it's not the last url
246
if (indexNextUrl > (getUrlListBean().size() - 1)) {
247             logger.debug("[url " + uBean.getAbsoluteUrlValue() +
248                     " is the last recorded bean]");
249             return null;
250         }
251
252         UrlBean nextUrlBean = (UrlBean) getUrlListBean().get(indexNextUrl);
253         logger.debug("[nextUrl of " + uBean.getAbsoluteUrlValue() + " is: " +
254                 nextUrlBean.getAbsoluteUrlValue() + " ]");
255         /*
256          * for (int i = 0; i < getUrlListBean().size(); i++) {
257          * UrlBean b = (UrlBean) getUrlListBean().get(i);
258          * logger.debug("[url at " + i + " is: " + b.getUrl() + " ]");
259          * }
260          */

261         return nextUrlBean;
262     }
263
264
265     /**
266      * Gets the FormParamDefaultValue attribute of the ClipperBean object
267      *
268      *@param uBean Description of Parameter
269      *@param paramName Description of Parameter
270      *@return The FormParamDefaultValue value
271      */

272     public String JavaDoc getFormParamDefaultValue(UrlBean uBean, String JavaDoc paramName) {
273         //The default value of the form param is the value of the query param whith name=paramName of the next url
274
UrlBean nextBean = getNextRecordedUrlBean(uBean);
275
276         if (nextBean == null) {
277             return "no value used";
278         }
279         return nextBean.getQueryParamDefaultValue(paramName);
280     }
281
282
283     /**
284      * Gets the FormParamDefaultValue attribute of the ClipperBean object
285      *
286      *@param posUrl Description of Parameter
287      *@param paramName Description of Parameter
288      *@return The FormParamDefaultValue value
289      */

290     public String JavaDoc getFormParamDefaultValue(int posUrl, String JavaDoc paramName) {
291         //The default value of the form param is the value of the query param whith name=paramName of the next url
292
UrlBean uBean = getUrlBean(posUrl);
293         return getFormParamDefaultValue(uBean, paramName);
294     }
295
296
297     /**
298      * Gets the Description attribute of the DescriptionClipperForm object
299      *
300      *@return The Description value
301      */

302     public String JavaDoc getDescription() {
303         return description;
304     }
305
306
307     /**
308      * Gets the Name attribute of the DescriptionClipperForm object
309      *
310      *@return The Name value
311      */

312     public String JavaDoc getName() {
313         return name;
314     }
315
316
317     /**
318      * Gets the TargetUrl attribute of the DescriptionClipperForm object
319      *
320      *@return The TargetUrl value
321      */

322     public String JavaDoc getTargetUrl() {
323         return targetUrl;
324     }
325
326
327
328     /**
329      * Gets the UrlListBean attribute of the ClipperBean object
330      *
331      *@return The UrlListBean value
332      */

333     public List getUrlListBean() {
334         return urlListBean;
335     }
336
337
338     /**
339      * Gets the ConfigurationBean attribute of the ClipperBean object
340      *
341      *@return The ConfigurationBean value
342      */

343     public ConfigureBean getConfigurationBean() {
344         /*
345          * if (configurationBean == null) {
346          * logger.debug("[ Configuration set to default ]");
347          * ConfigureBean defaultConfigureBean = org.jahia.clipbuilder.html.database.hibernate.DatabaseManager.getUniqueInstance().getDefaultConfiguration();
348          * setConfigurationBean(defaultConfigureBean);
349          * }
350          */

351         return configurationBean;
352     }
353
354
355     /**
356      * Gets the FilterBean attribute of the ClipperBean object
357      *
358      *@return The FilterBean value
359      */

360     public FilterBean getFilterBean() {
361         return filterBean;
362     }
363
364
365     /**
366      * Gets the PortletConfigBean attribute of the ClipperBean object
367      *
368      *@return The PortletConfigBean value
369      */

370     public PortletConfigBean getPortletConfigBean() {
371         return portletConfigBean;
372     }
373
374
375     /**
376      * Gets the Empty attribute of the ClipperBean object
377      *
378      *@return The Empty value
379      */

380     public boolean isEmpty() {
381         return this.getUrlListBean().isEmpty();
382     }
383
384
385     /**
386      * Gets the AllParams attribute of the ClipperBean object
387      *
388      *@param posUrl Description of Parameter
389      *@return The AllParams value
390      */

391     public List getAllFormParam(int posUrl) {
392         UrlBean bean = getUrlBean(posUrl);
393         logger.debug("[ url at position " + posUrl + " whith value " + bean.getAbsoluteUrlValue() + " in process]");
394         return bean.getFormParamBeanList();
395     }
396
397
398     /**
399      * Gets the AllQueryParam attribute of the ClipperBean object
400      *
401      *@param posUrl Description of Parameter
402      *@return The AllQueryParam value
403      */

404     public List getAllQueryParam(int posUrl) {
405         UrlBean bean = getUrlBean(posUrl);
406         return bean.getQueryParamBeanList();
407     }
408
409
410     /**
411      * Gets the ParameterMapping attribute of the ClipperBean object
412      *
413      *@param posUrl Description of Parameter
414      *@param formParentName Description of Parameter
415      *@param formParentId Description of Parameter
416      *@param formParentPos Description of Parameter
417      *@param paramName Description of Parameter
418      *@param paramPosition Description of Parameter
419      *@return The ParameterMapping value
420      */

421     public String JavaDoc getParameterMapping(int posUrl, String JavaDoc formParentName, String JavaDoc formParentId, int formParentPos, String JavaDoc paramName, int paramPosition) {
422         UrlBean bean = this.getUrlBean(posUrl);
423         return bean.getFormParameterMapping(formParentName, formParentId, formParentPos, paramName, paramPosition);
424     }
425
426
427     /**
428      * Gets the ParameterDefaultValue attribute of the ClipperBean object
429      *
430      *@param posUrl Description of Parameter
431      *@param param Description of Parameter
432      *@return The ParameterDefaultValue value
433      */

434     public String JavaDoc getParameterDefaultValue(int posUrl, String JavaDoc param) {
435         UrlBean bean = this.getUrlBean(posUrl);
436         return bean.getQueryParamDefaultValue(param);
437     }
438
439
440     /**
441      * Gets the FirstParamName attribute of the ClipperBean object
442      *
443      *@param posUrl Description of Parameter
444      *@return The FirstParamName value
445      */

446     public String JavaDoc getFirstParamName(int posUrl) {
447         UrlBean bean = this.getUrlBean(posUrl);
448         return bean.getFirtParamName();
449     }
450
451
452     /**
453      * Gets the ParamType attribute of the ClipperBean object
454      *
455      *@param posUrl Description of Parameter
456      *@param formParentName Description of Parameter
457      *@param formParentId Description of Parameter
458      *@param formParentPos Description of Parameter
459      *@param paramName Description of Parameter
460      *@param paramPosition Description of Parameter
461      *@return The ParamType value
462      */

463     public String JavaDoc getParamType(int posUrl, String JavaDoc formParentName, String JavaDoc formParentId, int formParentPos, String JavaDoc paramName, int paramPosition) {
464         UrlBean bean = this.getUrlBean(posUrl);
465         return bean.getFormParamType(formParentName, formParentId, formParentPos, paramName, paramPosition);
466     }
467
468
469     /**
470      * Gets the ParamAllowedValue attribute of the ClipperBean object
471      *
472      *@param posUrl Description of Parameter
473      *@param formParentName Description of Parameter
474      *@param formParentId Description of Parameter
475      *@param formParentPos Description of Parameter
476      *@param paramName Description of Parameter
477      *@param paramPosition Description of Parameter
478      *@return The ParamAllowedValue value
479      */

480     public ArrayList getParamAllowedValuesBeanList(int posUrl, String JavaDoc formParentName, String JavaDoc formParentId, int formParentPos, String JavaDoc paramName, int paramPosition) {
481         UrlBean uBean = getUrlBean(posUrl);
482         return uBean.getParamFormAllowedValueBeanList(formParentName, formParentId, formParentPos, paramName, paramPosition);
483     }
484
485
486     /**
487      * Gets the ParamAllowedValuesStringList attribute of the ClipperBean object
488      *
489      *@param posUrl Description of Parameter
490      *@param formParentName Description of Parameter
491      *@param formParentId Description of Parameter
492      *@param formParentPos Description of Parameter
493      *@param paramName Description of Parameter
494      *@param paramPosition Description of Parameter
495      *@return The ParamAllowedValuesStringList value
496      */

497     public ArrayList getParamAllowedValuesStringList(int posUrl, String JavaDoc formParentName, String JavaDoc formParentId, int formParentPos, String JavaDoc paramName, int paramPosition) {
498         UrlBean uBean = this.getUrlBean(posUrl);
499         return uBean.getParamFormAllowedValueStringList(formParentName, formParentId, formParentPos, paramName, paramPosition);
500     }
501
502
503     /**
504      * Gets the PositionLastRecordeUrl attribute of the ClipperBean object
505      *
506      *@return The PositionLastRecordeUrl value
507      */

508     public int getPositionLastRecordeUrl() {
509         return getUrlListBean().size() - 1;
510     }
511
512
513     /**
514      * Description of the Method
515      *
516      *@return Description of the Returned Value
517      */

518     public boolean urlListIsEmpty() {
519         return getUrlListBean().isEmpty();
520     }
521
522
523     /**
524      * Description of the Method
525      *
526      *@param xmlPath Description of Parameter
527      */

528
529     public void loadFromXml(String JavaDoc xmlPath) {
530         // load the xml document
531
ClipperDocument document = new ClipperDocument(xmlPath);
532         ClipperParser parser = document.getParser();
533         setDescription(parser.getDescription());
534         setName(parser.getName());
535         setTargetUrl(parser.getTargetUrl());
536
537         // contain the sequence of all url
538
int urlListSize = parser.getUrlListSize();
539         for (int i = 0; i < urlListSize; i++) {
540             String JavaDoc baseURL = parser.getBaseUrlValue(i);
541             String JavaDoc relativeURL = parser.getRelativeUrlValue(i);
542             String JavaDoc finalValue = parser.getRedirectUrlValue(i);
543             String JavaDoc from = parser.getUrlFrom(i);
544             String JavaDoc hash = parser.getUrlHash(i);
545             Map queryMap = parser.getUrlQueryMap(i);
546
547             // build UrlBean
548
UrlBean uBean = new UrlBean(this, baseURL, relativeURL, queryMap, from, hash);
549             uBean.setRedirectUrl(URLUtilities.getURL(finalValue));
550
551             //add the form params
552
int formSize = parser.getUrlListFormParamSize(i);
553             for (int j = 0; j < formSize; j++) {
554                 // add the parameter
555
String JavaDoc name = parser.getFromName(i, j);
556                 String JavaDoc type = parser.getFormType(i, j);
557                 String JavaDoc visibility = parser.getFormParamVisibility(i, j);
558                 String JavaDoc update = parser.getFormParamUpdate(i, j);
559                 int paramPosition = Integer.parseInt(parser.getFormParamPosition(i, j));
560                 List possibleValueList = parser.getFromPossibleValue(i, j);
561                 String JavaDoc formParentName = parser.getFormFormParentName(i, j);
562                 String JavaDoc formParentId = parser.getFormFormParentId(i, j);
563                 int formParentPosition = Integer.parseInt(parser.getFormFormParentPosition(i, j));
564
565                 FormParamBean fBean = null;
566                 for (int k = 0; k < possibleValueList.size(); k++) {
567                     String JavaDoc possibleValue = parser.getPossibleValue(possibleValueList.get(k));
568                     // add the parameter
569
fBean = uBean.addFormParameter(formParentName, formParentId, formParentPosition, name, possibleValue, type, visibility, paramPosition);
570                 }
571                 //set the mapping
572
String JavaDoc mapping = parser.getFormParamMapping(i, j);
573                 fBean.setUpdate(update);
574                 uBean.setMappingFormParam(formParentName, formParentId, formParentPosition, name, mapping, paramPosition);
575
576             }
577
578             //add the queryParams
579
int querySize = parser.getUrlListQueryParamSize(i);
580             logger.debug("Query param size " + querySize + " ]");
581             for (int j = 0; j < querySize; j++) {
582                 // add the parameter
583
String JavaDoc name = parser.getQueryName(i, j);
584                 String JavaDoc value = parser.getQueryDefault(i, j);
585                 logger.debug("[ Query param whith name " + name + " and value " + value + " found ]");
586                 int qPosition = Integer.parseInt(parser.getQueryPosition(i, j));
587                 QueryParamBean qBean = uBean.addQueryParameter(name, value, qPosition);
588                 if (value == null) {
589                     qBean.setUseAsDefaultValue("false");
590                 }
591                 else {
592                     qBean.setUseAsDefaultValue("true");
593                 }
594                 //add the qBean to the formBean
595
if (i > 0) {
596                     UrlBean previousUrlBean = getUrlBean(i - 1);
597                     FormParamBean fBean = previousUrlBean.getFormParamByNameAndFormParentHash(name, qPosition, hash);
598                     if (fBean != null) {
599                         fBean.setQueryParamBean(qBean);
600                     }
601                 }
602
603             }
604
605             // add the url
606
addUrlBean(uBean);
607         }
608
609         //set the filter
610
String JavaDoc typeFilter = parser.getFilterType();
611         if (typeFilter == null) {
612             logger.error("[Filter type is null ]");
613         }
614         else {
615             logger.debug("[Filter type is " + typeFilter + " ]");
616             FilterBean filterBean = new FilterBean();
617             filterBean.setName(typeFilter);
618             if (filterBean == null) {
619                 logger.error("Unexpected type of filter");
620                 logger.warn("Filter not initialised");
621                 setHasBeanInit(false);
622             }
623             else {
624                 //set the key of the filter
625
Map keysMap = parser.getKeysMap();
626                 Iterator it = keysMap.keySet().iterator();
627                 while (it.hasNext()) {
628                     String JavaDoc name = (String JavaDoc) it.next();
629                     String JavaDoc value = (String JavaDoc) keysMap.get(name);
630                     filterBean.addKeyPart(name, value);
631                 }
632
633                 // set the filter
634
setFilterBean(filterBean);
635             }
636         }
637
638         //set the configuration
639
ConfigureBean config = new ConfigureBean();
640         String JavaDoc proxy = parser.getConfigProxy();
641         String JavaDoc enableSSL = parser.getConfigEnableSSL();
642         String JavaDoc enableJavascript = parser.getConfigEnableJavascript();
643         String JavaDoc client = parser.getConfigClient();
644         String JavaDoc htmlDocument = parser.getConfigHtmlDocument();
645         String JavaDoc enableCSS = parser.getConfigEnableCSS();
646         String JavaDoc browserJavascriptEvent = parser.getConfigBrowserJavascriptEvent();
647         String JavaDoc browserJavascriptCode = parser.getConfigBrowserJavascriptCode();
648         String JavaDoc portletEnableSSL = parser.getPortletEnableSSL();
649         String JavaDoc portletContinualClipping = parser.getPortletContinualClipping();
650         String JavaDoc portletCacheExpiration = parser.getPortletCacheExpiration();
651                 String JavaDoc portletCacheContext = parser.getPortletCacheContext();
652
653         config.setProxy(proxy);
654         config.setEnableCSS(enableCSS);
655         config.setEnableJavascript(enableJavascript);
656         config.setClient(client);
657         config.setHtmlDocument(htmlDocument);
658         config.setEnableSSL(enableSSL);
659         config.setBrowserJavascriptCode(browserJavascriptCode);
660         config.setBrowserJavascriptEvent(browserJavascriptEvent);
661         config.setPortletEnableSSL(portletEnableSSL);
662         config.setPortletContinualClipping(portletContinualClipping);
663         config.setPortletCacheExpiration(portletCacheExpiration);
664                 config.setPortletCacheContext(portletCacheContext);
665         setConfigurationBean(config);
666
667         //update
668
setHasBeanInit(true);
669
670     }
671
672
673
674
675     /**
676      * Gets the Init attribute of the ClipperBean object
677      *
678      *@return The Init value
679      */

680     public boolean hasBeanInit() {
681         return hasBeanInit;
682     }
683
684
685     /**
686      * Description of the Method
687      */

688     public void removeLastRecordedUrl() {
689         getUrlListBean().remove(getUrlListBean().size() - 1);
690     }
691
692
693     /**
694      * Description of the Method
695      */

696     public void clearUrlParam() {
697         for (int i = 0; i < this.getUrlListBean().size(); i++) {
698             UrlBean uBean = (UrlBean) this.getUrlListBean().get(i);
699             uBean.clearParam();
700         }
701
702     }
703
704
705     /**
706      * Adds a feature to the Param attribute of the ClipperBean object
707      *
708      *@param posUrl The feature to be added to the FormParam
709      * attribute
710      *@param formParentName The feature to be added to the FormParam
711      * attribute
712      *@param formParentId The feature to be added to the FormParam
713      * attribute
714      *@param formParentPosition The feature to be added to the FormParam
715      * attribute
716      *@param param name of the param
717      *@param possibleValue The feature to be added to the Param attribute
718      *@param type The feature to be added to the Param attribute
719      *@param visibility The feature to be added to the FormParam
720      * attribute
721      *@param paramPosition The feature to be added to the FormParam
722      * attribute
723      */

724     public void addFormParam(int posUrl, String JavaDoc formParentName, String JavaDoc formParentId, int formParentPosition, String JavaDoc param, String JavaDoc possibleValue, String JavaDoc type, String JavaDoc visibility, int paramPosition) {
725         UrlBean bean = this.getUrlBean(posUrl);
726         logger.debug("[Param " + param + " whith possible value " + possibleValue + " is being added to url " + bean.getAbsoluteUrlValue() + " ]");
727         bean.addFormParameter(formParentName, formParentId, formParentPosition, param, possibleValue, type, visibility, paramPosition);
728     }
729
730
731     /**
732      * Adds a feature to the FormParamToCurrentUrl attribute of the ClipperBean
733      * object
734      *
735      *@param formParentName The feature to be added to the
736      * FormParamToCurrentUrl attribute
737      *@param formParentId The feature to be added to the
738      * FormParamToCurrentUrl attribute
739      *@param formParentPosition The feature to be added to the
740      * FormParamToCurrentUrl attribute
741      *@param param The feature to be added to the
742      * FormParamToCurrentUrl attribute
743      *@param possibleValue The feature to be added to the
744      * FormParamToCurrentUrl attribute
745      *@param type The feature to be added to the
746      * FormParamToCurrentUrl attribute
747      *@param visibility The feature to be added to the
748      * FormParamToCurrentUrl attribute
749      *@param paramPosition The feature to be added to the
750      * FormParamToCurrentUrl attribute
751      */

752     public void addFormParamToCurrentUrl(String JavaDoc formParentName, String JavaDoc formParentId, int formParentPosition, String JavaDoc param, String JavaDoc possibleValue, String JavaDoc type, String JavaDoc visibility, int paramPosition) {
753         int posUrl = getPositionLastRecordeUrl();
754         addFormParam(posUrl, formParentName, formParentId, formParentPosition, param, possibleValue, type, visibility, paramPosition);
755     }
756
757
758     /**
759      * Save the Clipper in the XML format
760      *
761      *@param path Description of Parameter
762      */

763     public void saveAsXML(String JavaDoc path) {
764         ClipperDocument doc = buildXmlDocument();
765
766         //Print in a file
767
if (path == null) {
768             logger.error("[ Path is null. ]");
769             return;
770         }
771         String JavaDoc file = path + java.io.File.separator + getName();
772         doc.saveInFile(file);
773         logger.debug("[ Saved in " + file + " ]");
774     }
775
776
777     /**
778      * Save the Clipper as a portlet
779      */

780     public void saveAsPortlet() {
781         // to do...
782
}
783
784
785     /**
786      * Adds a feature to the UrlBean attribute of the ClipperBean object
787      *
788      *@param u The feature to be added to the UrlBean attribute
789      */

790     public void addUrlBean(UrlBean u) {
791         int pos = getUrlListBean().size();
792         logger.debug("[ Url " + u.getAbsoluteUrlValue() + " added at position " + pos + " ]");
793         u.setPosition(pos);
794         if (!getUrlListBean().add(u)) {
795             logger.error("[Error occured when adding Url " + u.getAbsoluteUrlValue() + " added at position " + pos + " ]");
796         }
797     }
798
799
800     /**
801      * Sets the Attributes attribute of the DescriptionBean object
802      *
803      *@param form The new Attributes value
804      */

805     public void buildFromDescriptionForm(DescriptionClipperForm form) {
806         setDescription(form.getWebClippingDescription());
807         setName(form.getWebClippingName());
808         setTargetUrl(form.getWebClippingTargetUrl());
809         clearRecordedUrl();
810     }
811
812
813     /**
814      * Remove all the recorded url
815      */

816     public void clearRecordedUrl() {
817         setUrlListBean(new ArrayList());
818     }
819
820
821     /**
822      * Description of the Method
823      *
824      *@return Description of the Returned Value
825      */

826     public ClipperDocument buildXmlDocument() {
827         //Instance of a clipper document
828
ClipperDocument doc = new ClipperDocument(getName(), getDescription());
829
830         //Set the configuration
831
doc.setConfiguration(getConfigurationBean());
832
833         //Add the url
834
List urlBeanList = this.getUrlListBean();
835         for (int i = 0; i < urlBeanList.size(); i++) {
836             // add the url
837
UrlBean uBean = (UrlBean) urlBeanList.get(i);
838             doc.addUrlWhithParam(uBean);
839         }
840
841         //Set the filter
842
doc.setFilter(getFilterBean());
843         return doc;
844     }
845
846
847     /**
848      * Description of the Method
849      *
850      *@param name Description of Parameter
851      */

852     private void loadWhithoutUrlBeanListFromXML(String JavaDoc name) {
853         // load the xml document
854
ClipperDocument document = new ClipperDocument(name);
855         ClipperParser parser = document.getParser();
856         setDescription(parser.getDescription());
857         setName(parser.getName());
858         setTargetUrl(parser.getTargetUrl());
859     }
860
861 }
862
Popular Tags