KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jahiatemplates > org > jahia > portlets_api > XMLPortlets


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12
//---------------------------------------
13
// XMLPortlets
14
//---------------------------------------
15
// Serge Huber & Jerome Bedat 12.01.2001
16
// ... little hack made by Fulco ;)
17
//---------------------------------------
18
// NK 25.04.2001
19
// Ported to jaxp-1.1
20
//---------------------------------------
21

22 /**
23  * @todo: this class should probably be renamed to XMLPortletsPersistanceManager,
24  * or even PersonalizedPortletsPersistanceManager
25  */

26
27 package jahiatemplates.org.jahia.portlets_api;
28
29 import java.io.File JavaDoc;
30 import java.io.FileInputStream JavaDoc;
31 import java.io.FileOutputStream JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.util.Vector JavaDoc;
34
35 import javax.xml.parsers.DocumentBuilder JavaDoc;
36 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
37 import javax.xml.transform.OutputKeys JavaDoc;
38 import javax.xml.transform.Transformer JavaDoc;
39 import javax.xml.transform.TransformerFactory JavaDoc;
40 import javax.xml.transform.dom.DOMSource JavaDoc;
41 import javax.xml.transform.stream.StreamResult JavaDoc;
42
43 import org.jahia.exceptions.JahiaException;
44 import org.jahia.registries.ServicesRegistry;
45 import org.jahia.utils.JahiaConsole;
46 import org.w3c.dom.Document JavaDoc;
47 import org.w3c.dom.Element JavaDoc;
48 import org.w3c.dom.NamedNodeMap JavaDoc;
49 import org.w3c.dom.Node JavaDoc;
50 import org.w3c.dom.Text JavaDoc;
51
52 /**
53  * This class is responsible for loading up data from an XML file that contains
54  * the portlet configuration of a specific user.
55  *
56  * Format of XML document is as follows:
57  * <?xml version="1.0" encoding="ISO-8859-1"?>
58  * <plml>
59  * <portletgroup id="">
60  * <parameter name="page_number">1</parameter>
61  * <portlet id="">
62  * <parameter name="active">1</parameter>
63  * <parameter name="title">First Portlet</parameter>
64  * <parameter name="source_id">12</parameter>
65  * <parameter name="icon_url">http://</parameter>
66  * <parameter name="bgcolor">#FFFFFF</parameter>
67  * <parameter name="bgimage_url">http://</parameter>
68  * <parameter name="font">arial, helvetica, sans-serif</parameter>
69  * <parameter name="fontsize">1</parameter>
70  * <parameter name="fontcolor">#000000</parameter>
71  * <parameter name="innerspace">10</parameter>
72  * <parameter name="column_position">1</parameter>
73  * <parameter name="row_position">1</parameter>
74  * other parameters...
75  * </portlet>
76  * other portlets
77  * </portletgroup>
78  * other portlet lists (also known as pages)
79  * </plml>
80  *
81  * @author Serge Huber
82  *
83  */

84 public class XMLPortlets {
85
86     private static final String JavaDoc CANT_READ_PORTLET_XML_MSG = "Can't read portlet XML file";
87     private static final String JavaDoc ERROR_READING_PLML_FILE_MSG = "Error reading PLML file";
88     private static final String JavaDoc PLML_TAG = "PLML";
89     private static final String JavaDoc PARAMETER_TAG = "PARAMETER";
90     private static final String JavaDoc PARAMETER_TAG_NAME_ATTRIBUTE = "name";
91     private static final String JavaDoc PARAMETER_TAG_ID_ATTRIBUTE = "id";
92     private static final String JavaDoc PORTLETLIST_TAG = "PORTLETGROUP";
93     private static final String JavaDoc PORTLET_TAG = "PORTLET";
94     private static final String JavaDoc XML_ENCODING = "ISO-8859-1";
95     private Document JavaDoc xmlDocument = null;
96     private boolean addPortletGroup = false;
97     private File JavaDoc theFile;
98     private String JavaDoc theXMLfile;
99     private String JavaDoc theDefaultXMLfile;
100     private String JavaDoc paramAttrNode;
101     private Text JavaDoc theTextNode;
102     private Node JavaDoc portletgroupNode;
103     private Node JavaDoc plmlNode;
104     private Vector JavaDoc thePortletList;
105     private int thePageID;
106     private int MaxColumn = 0;
107
108     //--------------------------------------------------------------------------
109
/**
110      * Constructor is initialized with the path to the Portlets XML file Descriptor
111      */

112     XMLPortlets(String JavaDoc theTemplatesPathDirectory, String JavaDoc thefilename, String JavaDoc theDefaultfilename, int thePageID) throws JahiaException {
113
114         File JavaDoc thePortletsAPIDirectory = new File JavaDoc( theTemplatesPathDirectory + File.separator + "portlets_api" + File.separator );
115         if(!thePortletsAPIDirectory.exists()) {
116             thePortletsAPIDirectory.mkdirs();
117         }
118         String JavaDoc thePath = theTemplatesPathDirectory + File.separator + "portlets_api" + File.separator;
119         this.addPortletGroup = false;
120         this.theFile = new File JavaDoc( thePath + thefilename);
121         this.theXMLfile = thePath + thefilename;
122         this.theDefaultXMLfile = thePath + theDefaultfilename;
123         this.thePageID = thePageID;
124
125         if (!theFile.exists()) {
126             try {
127
128                 JahiaConsole.println("XMLPortlets constructor", "Creating file " + theXMLfile + "...");
129
130                 Document JavaDoc xmlDoc = null;
131
132                 try {
133
134                     DocumentBuilderFactory JavaDoc dfactory = DocumentBuilderFactory.newInstance();
135                     //dfactory.setValidating(true); // create only parsers that are validating
136
DocumentBuilder JavaDoc docBuilder = dfactory.newDocumentBuilder();
137                     xmlDoc = docBuilder.newDocument();
138
139                 } catch ( Throwable JavaDoc t ){
140                     throw new JahiaException( "XMLPortlets",
141                                         "Exception " + t.getMessage(),
142                                         JahiaException.ERROR_SEVERITY,
143                                         JahiaException.SERVICE_ERROR);
144                 }
145
146
147                 Element JavaDoc newPlmlNode = (Element JavaDoc) xmlDoc.createElement(PLML_TAG);
148
149                 if ( newPlmlNode == null ){
150                     JahiaConsole.println("XMLPortlets constructor", "newPlmlNode is null");
151                 }
152
153                 //newPlmlNode.normalize();
154

155                 xmlDoc.appendChild(newPlmlNode);
156
157                 theFile.createNewFile();
158
159                 if (theXMLfile.equals(theDefaultXMLfile)) {
160                     JahiaConsole.println("XMLPortlets constructor", "Creating default file with user guest !");
161                     Integer JavaDoc thePGID = new Integer JavaDoc(update_count("portletgroup"));
162                     Element JavaDoc newPortletGroupNode = (Element JavaDoc) xmlDoc.createElement(PORTLETLIST_TAG);
163                     newPortletGroupNode.setAttribute(PARAMETER_TAG_ID_ATTRIBUTE, thePGID.toString());
164
165                     newPlmlNode.appendChild(newPortletGroupNode);
166
167                     Integer JavaDoc thePID = new Integer JavaDoc(thePageID);
168                     Element JavaDoc paramNode = (Element JavaDoc) xmlDoc.createElement(PARAMETER_TAG);
169                     paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "page_id");
170                     Text JavaDoc theTextNode = xmlDoc.createTextNode(thePID.toString());
171                     paramNode.appendChild(theTextNode);
172                     newPortletGroupNode.appendChild(paramNode);
173
174                     saveFile(xmlDoc,theFile.getAbsolutePath());
175
176                     xmlDocument = loadFile("file:" + theXMLfile);
177
178                 } else {
179
180                     saveFile(xmlDoc,theFile.getAbsolutePath());
181
182                     xmlDocument = loadFile("file:" + theXMLfile);
183
184                     addPortletGroup();
185                 }
186
187                 addPortletGroup = true;
188
189             } catch (IOException JavaDoc ioe) {
190                 throw new JahiaException(CANT_READ_PORTLET_XML_MSG,
191                                         "IOException in XML file writing : " + ioe.toString(),
192                                         JahiaException.CRITICAL_SEVERITY,
193                                         JahiaException.CONFIG_ERROR);
194             }
195         } else {
196
197             JahiaConsole.println("XMLPortlets constructor", "Loading file " + theXMLfile + "...");
198
199             xmlDocument = loadFile("file:" + theXMLfile);
200
201         }
202
203         portletgroupNode = getPortletGroupNode();
204         plmlNode = getPlmlNode();
205     } // end Constructor
206

207
208
209
210     //--------------------------------------------------------------------------
211
private Document JavaDoc loadFile(String JavaDoc sourceFileName)
212     throws JahiaException {
213
214         Document JavaDoc xmlDoc = null;
215
216         try {
217             DocumentBuilderFactory JavaDoc dfactory = DocumentBuilderFactory.newInstance();
218             //dfactory.setValidating(true); // create only parsers that are validating
219
DocumentBuilder JavaDoc docBuilder = dfactory.newDocumentBuilder();
220             //docBuilder.setEntityResolver();
221

222             FileInputStream JavaDoc sourceStream = new FileInputStream JavaDoc(sourceFileName);
223             xmlDoc = docBuilder.parse(sourceStream);
224             xmlDoc.normalize(); // clean up DOM tree a little
225
Element JavaDoc docEl = (Element JavaDoc)xmlDoc.getDocumentElement();
226
227         } catch ( Throwable JavaDoc t ){
228             throw new JahiaException( "XMLPortlets",
229                                         "Exception " + t.getMessage(),
230                                         JahiaException.ERROR_SEVERITY,
231                                         JahiaException.SERVICE_ERROR);
232         }
233         return xmlDoc;
234     }
235
236     //--------------------------------------------------------------------------
237
private void saveFile(Document JavaDoc xmlDoc, String JavaDoc destinationFileName)
238     throws JahiaException {
239
240         try {
241
242             xmlDoc.normalize(); // cleanup DOM tree a little
243

244             TransformerFactory JavaDoc tfactory = TransformerFactory.newInstance();
245
246             // This creates a transformer that does a simple identity transform,
247
// and thus can be used for all intents and purposes as a serializer.
248
Transformer JavaDoc serializer = tfactory.newTransformer();
249
250             serializer.setOutputProperty(OutputKeys.METHOD, "xml");
251             serializer.setOutputProperty(OutputKeys.INDENT, "yes");
252             FileOutputStream JavaDoc fileStream = new FileOutputStream JavaDoc(destinationFileName);
253             serializer.transform(new DOMSource JavaDoc(xmlDoc),
254                              new StreamResult JavaDoc(fileStream));
255
256         } catch ( Throwable JavaDoc t ){
257             throw new JahiaException( "XMLPortlets",
258                                         "Exception " + t.getMessage(),
259                                         JahiaException.ERROR_SEVERITY,
260                                         JahiaException.SERVICE_ERROR);
261         }
262
263     }
264
265
266     //--------------------------------------------------------------------------
267
/**
268      * Processes through all the parameter tags of a given node to find the value of a certain named parameter
269      *
270      */

271     public String JavaDoc getParameterValue(Node JavaDoc paramParent, String JavaDoc parameterName) throws JahiaException {
272     if (!paramParent.hasChildNodes()) {
273         throw new JahiaException("No parameters available on portlet XML tag",
274                      "Parent has no children at all",
275                      JahiaException.CRITICAL_SEVERITY,
276                      JahiaException.CONFIG_ERROR);
277     }
278     Node JavaDoc curNode = paramParent.getFirstChild();
279     while (curNode != null) {
280         // let's go through all the children nodes
281
if (curNode.getNodeType() == Node.ELEMENT_NODE) {
282         if (curNode.getNodeName().equalsIgnoreCase(PARAMETER_TAG)) {
283             // we have found a parameter tag, let's check further for match of param name
284
NamedNodeMap JavaDoc attrib = curNode.getAttributes();
285             Node JavaDoc paramAttrib = attrib.getNamedItem(PARAMETER_TAG_NAME_ATTRIBUTE);
286             if (paramAttrib != null) {
287             if (paramAttrib.getNodeValue().equalsIgnoreCase(parameterName)) {
288                 // we found the parameter
289
// we must now extract value of text node below this node.
290
Node JavaDoc textNode = curNode.getFirstChild();
291                 if (textNode.getNodeType() == Node.TEXT_NODE) {
292                 return textNode.getNodeValue();
293                 } else {
294                 throw new JahiaException(ERROR_READING_PLML_FILE_MSG,
295                              "Value of parameter is not in correct format, should only be text",
296                              JahiaException.CRITICAL_SEVERITY,
297                              JahiaException.CONFIG_ERROR);
298                 }
299             }
300             } else {
301             throw new JahiaException(ERROR_READING_PLML_FILE_MSG,
302                          "No attribute name found on parameter !",
303                          JahiaException.CRITICAL_SEVERITY,
304                          JahiaException.CONFIG_ERROR);
305             }
306         }
307         } else {
308         // we just ignore other type of tags
309
}
310         curNode = curNode.getNextSibling();
311     }
312     throw new JahiaException(ERROR_READING_PLML_FILE_MSG,
313                  "No parameter with name "+ parameterName +" found !",
314                  JahiaException.CRITICAL_SEVERITY,
315                  JahiaException.CONFIG_ERROR);
316
317     } // end getParameterValue()
318

319
320     //--------------------------------------------------------------------------
321
/**
322      * Find the value of a certain named attribute
323      *
324      */

325     public String JavaDoc getAttributeValue(Node JavaDoc paramParent, String JavaDoc attributeName) throws JahiaException {
326
327     NamedNodeMap JavaDoc attrib = paramParent.getAttributes();
328     Node JavaDoc paramAttrib = attrib.getNamedItem(attributeName);
329     return paramAttrib.getNodeValue();
330
331     } // end getAttributeValue()
332

333
334     //--------------------------------------------------------------------------
335
/**
336      * Retrieves a column count for the specified page
337      *
338      * @author Jerome Bedat
339      *
340      */

341     public int getColumnCount() throws JahiaException {
342
343     MaxColumn = 0;
344     boolean isPortletGroupNode = false;
345
346     portletgroupNode = plmlNode.getFirstChild();
347
348     try {
349         while (portletgroupNode != null) {
350             if (portletgroupNode.getNodeType() == Node.ELEMENT_NODE && portletgroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {
351                 if (Integer.parseInt(getParameterValue(portletgroupNode, "page_id")) == thePageID) {
352                     isPortletGroupNode = true;
353                     Node JavaDoc portletNode = portletgroupNode.getFirstChild();
354                     while (portletNode != null) {
355                         // we are going through the portletgroup tags which represent list of portlets
356
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
357                             // we are now on a PORTLET tag
358
if (Integer.parseInt(getParameterValue(portletNode, "column_position")) > MaxColumn) { MaxColumn = Integer.parseInt(getParameterValue(portletNode, "column_position")); }
359                         }
360
361                         portletNode = portletNode.getNextSibling();
362                     }
363                 }
364             }
365             portletgroupNode = portletgroupNode.getNextSibling();
366         }
367     } catch (NumberFormatException JavaDoc n) {
368         throw new JahiaException(ERROR_READING_PLML_FILE_MSG,
369                                 "Invalid Integer !!!",
370                                 JahiaException.CRITICAL_SEVERITY,
371                                 JahiaException.CONFIG_ERROR);
372     }
373
374     if (!isPortletGroupNode) {
375         addPortletGroup();
376         getColumnCount();
377     }
378     return MaxColumn;
379     } // end getColumnCount()
380

381
382     //--------------------------------------------------------------------------
383
/**
384      * Retrieves a portlet settings
385      *
386      * @author Jerome Bedat
387      *
388      */

389     public PortletObj getPortlet(int thePortletID) throws JahiaException {
390
391     PortletObj thePortlet = null;
392     boolean isPortletGroupNode = false;
393
394     portletgroupNode = plmlNode.getFirstChild();
395
396     try {
397         while (portletgroupNode != null) {
398             if (portletgroupNode.getNodeType() == Node.ELEMENT_NODE && portletgroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {
399                 if (Integer.parseInt(getParameterValue(portletgroupNode, "page_id")) == thePageID) {
400                     isPortletGroupNode = true;
401                     Node JavaDoc portletNode = portletgroupNode.getFirstChild();
402                     while (portletNode != null) {
403                         // we are going through the portletgroup tags which represent list of portlets
404
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
405                             // we are now on a PORTLET tag
406
paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE);
407                             if (Integer.parseInt(paramAttrNode) == thePortletID) {
408                                 thePortlet = new PortletObj(Integer.parseInt(paramAttrNode),
409                                                             Integer.parseInt(getParameterValue(portletNode, "source_id")),
410                                                             Integer.parseInt(getParameterValue(portletNode, "active")),
411                                                             getParameterValue(portletNode, "title"),
412                                                             getParameterValue(portletNode, "icon_url"),
413                                                             getParameterValue(portletNode, "bgcolor"),
414                                                             getParameterValue(portletNode, "bgimage_url"),
415                                                             getParameterValue(portletNode, "font"),
416                                                             getParameterValue(portletNode, "fontsize"),
417                                                             getParameterValue(portletNode, "fontcolor"),
418                                                             Integer.parseInt(getParameterValue(portletNode, "skin_id")),
419                                                             Integer.parseInt(getParameterValue(portletNode, "scrollable")),
420                                                             Integer.parseInt(getParameterValue(portletNode, "resizable")),
421                                                             Integer.parseInt(getParameterValue(portletNode, "fixed")),
422                                                             Integer.parseInt(getParameterValue(portletNode, "innerspace")),
423                                                             Integer.parseInt(getParameterValue(portletNode, "x")),
424                                                             Integer.parseInt(getParameterValue(portletNode, "y")),
425                                                             Integer.parseInt(getParameterValue(portletNode, "w")),
426                                                             Integer.parseInt(getParameterValue(portletNode, "h")),
427                                                             Integer.parseInt(getParameterValue(portletNode, "column_position")),
428                                                             Integer.parseInt(getParameterValue(portletNode, "row_position")));
429                                 break;
430                             }
431                         }
432                         portletNode = portletNode.getNextSibling();
433                     }
434                     break;
435                 }
436             }
437             portletgroupNode = portletgroupNode.getNextSibling();
438
439         }
440     } catch (NumberFormatException JavaDoc n) {
441         throw new JahiaException(ERROR_READING_PLML_FILE_MSG,
442                                 "Invalid Integer !!!",
443                                 JahiaException.CRITICAL_SEVERITY,
444                                 JahiaException.CONFIG_ERROR);
445     }
446
447     if (!isPortletGroupNode) {
448         addPortletGroup();
449         getPortlet(thePortletID);
450     }
451     return thePortlet;
452     } // end getPortlet()
453

454
455     //--------------------------------------------------------------------------
456
/**
457      * Retrieves a list of portlet settings
458      *
459      * @author Jerome Bedat
460      *
461      */

462     public Vector JavaDoc getPortletList() throws JahiaException {
463
464     thePortletList = new Vector JavaDoc();
465     boolean isPortletGroupNode = false;
466
467     portletgroupNode = plmlNode.getFirstChild();
468
469     try {
470         while (portletgroupNode != null) {
471             if (portletgroupNode.getNodeType() == Node.ELEMENT_NODE && portletgroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {
472                 if (Integer.parseInt(getParameterValue(portletgroupNode, "page_id")) == thePageID) {
473                     isPortletGroupNode = true;
474                     Node JavaDoc portletNode = portletgroupNode.getFirstChild();
475                     while (portletNode != null) {
476                         // we are going through the portletgroup tags which represent list of portlets
477
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
478                             // we are now on a PORTLET tag
479
paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE);
480                             thePortletList.addElement(new PortletObj(Integer.parseInt(paramAttrNode),
481                                                                     Integer.parseInt(getParameterValue(portletNode, "source_id")),
482                                                                     Integer.parseInt(getParameterValue(portletNode, "active")),
483                                                                     getParameterValue(portletNode, "title"),
484                                                                     getParameterValue(portletNode, "icon_url"),
485                                                                     getParameterValue(portletNode, "bgcolor"),
486                                                                     getParameterValue(portletNode, "bgimage_url"),
487                                                                     getParameterValue(portletNode, "font"),
488                                                                     getParameterValue(portletNode, "fontsize"),
489                                                                     getParameterValue(portletNode, "fontcolor"),
490                                                                     Integer.parseInt(getParameterValue(portletNode, "skin_id")),
491                                                                     Integer.parseInt(getParameterValue(portletNode, "scrollable")),
492                                                                     Integer.parseInt(getParameterValue(portletNode, "resizable")),
493                                                                     Integer.parseInt(getParameterValue(portletNode, "fixed")),
494                                                                     Integer.parseInt(getParameterValue(portletNode, "innerspace")),
495                                                                     Integer.parseInt(getParameterValue(portletNode, "x")),
496                                                                     Integer.parseInt(getParameterValue(portletNode, "y")),
497                                                                     Integer.parseInt(getParameterValue(portletNode, "w")),
498                                                                     Integer.parseInt(getParameterValue(portletNode, "h"))));
499                         }
500                         portletNode = portletNode.getNextSibling();
501                     }
502                 }
503             }
504             portletgroupNode = portletgroupNode.getNextSibling();
505
506         }
507     } catch (NumberFormatException JavaDoc n) {
508         throw new JahiaException(ERROR_READING_PLML_FILE_MSG,
509                                 "Invalid Integer !!!",
510                                 JahiaException.CRITICAL_SEVERITY,
511                                 JahiaException.CONFIG_ERROR);
512     }
513
514     if (!isPortletGroupNode) {
515         addPortletGroup();
516         getPortletList();
517     }
518     return thePortletList;
519     } // end getPortletList()
520

521
522
523     //--------------------------------------------------------------------------
524
/**
525      * Retrieves a list of portlet settings for the specified column
526      *
527      * @author Jerome Bedat
528      *
529      */

530     public Vector JavaDoc getPortletListFromColumn(int theColumn) throws JahiaException {
531
532     thePortletList = new Vector JavaDoc();
533     boolean isPortletGroupNode = false;
534
535     portletgroupNode = plmlNode.getFirstChild();
536
537     try {
538         while (portletgroupNode != null) {
539             if (portletgroupNode.getNodeType() == Node.ELEMENT_NODE && portletgroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {
540                 if (Integer.parseInt(getParameterValue(portletgroupNode, "page_id")) == thePageID) {
541                     isPortletGroupNode = true;
542                     Node JavaDoc portletNode = portletgroupNode.getFirstChild();
543                     int RowSpace = 0;
544                     int RowCounter = 1;
545                     int MaxRow = 0;
546                     while (portletNode != null) {
547                         // we are going through the portletgroup tags which represent list of portlets
548
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
549                             // we are now on a PORTLET tag
550
if (Integer.parseInt(getParameterValue(portletNode, "column_position")) == theColumn) {
551                                 if (Integer.parseInt(getParameterValue(portletNode, "row_position")) == RowCounter) {
552                                     paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE);
553                                     thePortletList.addElement(new PortletObj(Integer.parseInt(paramAttrNode),
554                                                                             Integer.parseInt(getParameterValue(portletNode, "source_id")),
555                                                                             Integer.parseInt(getParameterValue(portletNode, "active")),
556                                                                             getParameterValue(portletNode, "title"),
557                                                                             getParameterValue(portletNode, "icon_url"),
558                                                                             getParameterValue(portletNode, "bgcolor"),
559                                                                             getParameterValue(portletNode, "bgimage_url"),
560                                                                             getParameterValue(portletNode, "font"),
561                                                                             getParameterValue(portletNode, "fontsize"),
562                                                                             getParameterValue(portletNode, "fontcolor"),
563                                                                             Integer.parseInt(getParameterValue(portletNode, "innerspace")),
564                                                                             Integer.parseInt(getParameterValue(portletNode, "column_position")),
565                                                                             Integer.parseInt(getParameterValue(portletNode, "row_position"))));
566                                     RowCounter++;
567                                 }
568                                 if (Integer.parseInt(getParameterValue(portletNode, "row_position")) > MaxRow) { MaxRow = Integer.parseInt(getParameterValue(portletNode, "row_position")); }
569                             }
570                         }
571                         if (portletNode.getNextSibling() == null && MaxRow >= RowCounter) {
572                             portletNode = portletgroupNode.getFirstChild();
573                             if (RowSpace == RowCounter) { RowCounter++; }
574                             RowSpace = RowCounter;
575                         } else {
576                         portletNode = portletNode.getNextSibling();
577                         }
578                     }
579                 }
580             }
581             portletgroupNode = portletgroupNode.getNextSibling();
582
583         }
584     } catch (NumberFormatException JavaDoc n) {
585         throw new JahiaException(ERROR_READING_PLML_FILE_MSG,
586                                 "Invalid Integer !!!",
587                                 JahiaException.CRITICAL_SEVERITY,
588                                 JahiaException.CONFIG_ERROR);
589     }
590
591     if (!isPortletGroupNode) {
592         addPortletGroup();
593         getPortletListFromColumn(theColumn);
594     }
595     return thePortletList;
596     } // end getPortletListFromColumn()
597

598
599     //--------------------------------------------------------------------------
600
/**
601      * Move the portlet to the right column in the Portlets XML file Descriptor
602      *
603      * @author Jerome Bedat
604      *
605      */

606     public void moveRightPortlet(int thePortletID) throws JahiaException {
607
608     portletgroupNode = plmlNode.getFirstChild();
609     Node JavaDoc theNode;
610
611     try {
612         while (portletgroupNode != null) {
613             if (portletgroupNode.getNodeType() == Node.ELEMENT_NODE && portletgroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {
614                 if (Integer.parseInt(getParameterValue(portletgroupNode, "page_id")) == thePageID) {
615                     Node JavaDoc portletNode = portletgroupNode.getFirstChild();
616                     int Column = 0;
617                     while (portletNode != null) {
618                         // we are going through the portletgroup tags which represent list of portlets
619
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
620                             // we are now on a PORTLET tag
621
paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE);
622                             if (paramAttrNode.equals(new Integer JavaDoc(thePortletID).toString())) {
623                                 Column = Integer.parseInt(getParameterValue(portletNode, "column_position"));
624                                 break;
625                             }
626                         }
627                         portletNode = portletNode.getNextSibling();
628                     }
629
630                     portletNode = portletgroupNode.getFirstChild();
631                     int MaxRow = 0;
632                     while (portletNode != null) {
633                         // we are going through the portletgroup tags which represent list of portlets
634
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
635                             // we are now on a PORTLET tag
636
if (Integer.parseInt(getParameterValue(portletNode, "column_position")) == Column + 1) {
637                                 if (Integer.parseInt(getParameterValue(portletNode, "row_position")) > MaxRow) { MaxRow = Integer.parseInt(getParameterValue(portletNode, "row_position")); }
638                             }
639                         }
640                         portletNode = portletNode.getNextSibling();
641                     }
642
643                     portletNode = portletgroupNode.getFirstChild();
644                     while (portletNode != null) {
645                         // we are going through the portletgroup tags which represent list of portlets
646
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
647                             // we are now on a PORTLET tag
648
paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE);
649                             if (paramAttrNode.equals(new Integer JavaDoc(thePortletID).toString())) {
650
651                                 Node JavaDoc paramNode = portletNode.getFirstChild();
652                                 while (paramNode != null) {
653                                     if (paramNode.getNodeType() == Node.ELEMENT_NODE && paramNode.getNodeName().equalsIgnoreCase(PARAMETER_TAG)) {
654                                         paramAttrNode = getAttributeValue(paramNode, PARAMETER_TAG_NAME_ATTRIBUTE);
655                                         if (paramAttrNode.equals("column_position")) {
656                                             theNode = paramNode.getFirstChild();
657                                             while (theNode != null) {
658                                                 if (theNode.getNodeType() == Node.TEXT_NODE) {
659                                                     theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(Column + 1).toString());
660                                                     paramNode.replaceChild(theTextNode, theNode);
661                                                     break;
662                                                 }
663                                                 theNode = theNode.getNextSibling();
664                                             }
665                                         }
666                                         if (paramAttrNode.equals("row_position")) {
667                                             theNode = paramNode.getFirstChild();
668                                             while (theNode != null) {
669                                                 if (theNode.getNodeType() == Node.TEXT_NODE) {
670                                                     theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(MaxRow + 1).toString());
671                                                     paramNode.replaceChild(theTextNode, theNode);
672                                                     break;
673                                                 }
674                                                 theNode = theNode.getNextSibling();
675                                             }
676                                         }
677                                     }
678                                     paramNode = paramNode.getNextSibling();
679                                 }
680                                 break;
681                             }
682                         }
683                         portletNode = portletNode.getNextSibling();
684                     }
685
686
687                     saveFile(xmlDocument,theFile.getAbsolutePath());
688
689                     return;
690                 }
691             }
692             portletgroupNode = portletgroupNode.getNextSibling();
693         }
694     } catch (NumberFormatException JavaDoc n) {
695         throw new JahiaException(ERROR_READING_PLML_FILE_MSG,
696                                 "Invalid Integer in moveRightPortlet !!! : " + n.toString(),
697                                 JahiaException.CRITICAL_SEVERITY,
698                                 JahiaException.CONFIG_ERROR);
699     }
700
701     } // end moveRightPortlet
702

703
704     //--------------------------------------------------------------------------
705
/**
706      * Move the portlet to the left column in the Portlets XML file Descriptor
707      *
708      * @author Jerome Bedat
709      *
710      */

711     public void moveLeftPortlet(int thePortletID) throws JahiaException {
712
713     portletgroupNode = plmlNode.getFirstChild();
714     Node JavaDoc theNode;
715
716     try {
717         while (portletgroupNode != null) {
718             if (portletgroupNode.getNodeType() == Node.ELEMENT_NODE && portletgroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {
719                 if (Integer.parseInt(getParameterValue(portletgroupNode, "page_id")) == thePageID) {
720                     Node JavaDoc portletNode = portletgroupNode.getFirstChild();
721                     int Column = 0;
722                     while (portletNode != null) {
723                         // we are going through the portletgroup tags which represent list of portlets
724
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
725                             // we are now on a PORTLET tag
726
paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE);
727                             if (paramAttrNode.equals(new Integer JavaDoc(thePortletID).toString())) {
728                                 Column = Integer.parseInt(getParameterValue(portletNode, "column_position"));
729                                 break;
730                             }
731                         }
732                         portletNode = portletNode.getNextSibling();
733                     }
734
735                     if (Column == 1) { return; }
736                     int MaxRow = 0;
737                     portletNode = portletgroupNode.getFirstChild();
738                     while (portletNode != null) {
739                         // we are going through the portletgroup tags which represent list of portlets
740
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
741                             // we are now on a PORTLET tag
742
if (Integer.parseInt(getParameterValue(portletNode, "column_position")) == Column - 1) {
743                                 if (Integer.parseInt(getParameterValue(portletNode, "row_position")) > MaxRow) { MaxRow = Integer.parseInt(getParameterValue(portletNode, "row_position")); }
744                             }
745                         }
746                         portletNode = portletNode.getNextSibling();
747                     }
748
749                     portletNode = portletgroupNode.getFirstChild();
750                     while (portletNode != null) {
751                         // we are going through the portletgroup tags which represent list of portlets
752
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
753                             // we are now on a PORTLET tag
754
paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE);
755                             if (paramAttrNode.equals(new Integer JavaDoc(thePortletID).toString())) {
756
757                                 Node JavaDoc paramNode = portletNode.getFirstChild();
758                                 while (paramNode != null) {
759                                     if (paramNode.getNodeType() == Node.ELEMENT_NODE && paramNode.getNodeName().equalsIgnoreCase(PARAMETER_TAG)) {
760                                         paramAttrNode = getAttributeValue(paramNode, PARAMETER_TAG_NAME_ATTRIBUTE);
761                                         if (paramAttrNode.equals("column_position")) {
762                                             theNode = paramNode.getFirstChild();
763                                             while (theNode != null) {
764                                                 if (theNode.getNodeType() == Node.TEXT_NODE) {
765                                                     theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(Column - 1).toString());
766                                                     paramNode.replaceChild(theTextNode, theNode);
767                                                     break;
768                                                 }
769                                                 theNode = theNode.getNextSibling();
770                                             }
771                                         }
772                                         if (paramAttrNode.equals("row_position")) {
773                                             theNode = paramNode.getFirstChild();
774                                             while (theNode != null) {
775                                                 if (theNode.getNodeType() == Node.TEXT_NODE) {
776                                                     theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(MaxRow + 1).toString());
777                                                     paramNode.replaceChild(theTextNode, theNode);
778                                                     break;
779                                                 }
780                                                 theNode = theNode.getNextSibling();
781                                             }
782                                         }
783                                     }
784                                     paramNode = paramNode.getNextSibling();
785                                 }
786                                 break;
787                             }
788                         }
789                         portletNode = portletNode.getNextSibling();
790                     }
791
792                     saveFile(xmlDocument,theFile.getAbsolutePath());
793
794                     return;
795                 }
796             }
797             portletgroupNode = portletgroupNode.getNextSibling();
798         }
799     } catch (NumberFormatException JavaDoc n) {
800         throw new JahiaException(ERROR_READING_PLML_FILE_MSG,
801                                 "Invalid Integer in moveLeftPortlet !!! : " + n.toString(),
802                                 JahiaException.CRITICAL_SEVERITY,
803                                 JahiaException.CONFIG_ERROR);
804     }
805
806     } // end moveLeftPortlet
807

808
809     //--------------------------------------------------------------------------
810
/**
811      * Move the portlet to the bottom row in the Portlets XML file Descriptor
812      *
813      * @author Jerome Bedat
814      *
815      */

816     public void moveBottomPortlet(int thePortletID) throws JahiaException {
817
818     portletgroupNode = plmlNode.getFirstChild();
819     Node JavaDoc theNode;
820
821     try {
822         while (portletgroupNode != null) {
823             if (portletgroupNode.getNodeType() == Node.ELEMENT_NODE && portletgroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {
824                 if (Integer.parseInt(getParameterValue(portletgroupNode, "page_id")) == thePageID) {
825                     Node JavaDoc portletNode = portletgroupNode.getFirstChild();
826                     int Column = 0;
827                     int Row = 0;
828                     int MaxRow = 0;
829
830                     while (portletNode != null) {
831                         // we are going through the portletgroup tags which represent list of portlets
832
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
833                             // we are now on a PORTLET tag
834
paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE);
835                             if (paramAttrNode.equals(new Integer JavaDoc(thePortletID).toString())) {
836                                 Column = Integer.parseInt(getParameterValue(portletNode, "column_position"));
837                                 Row = Integer.parseInt(getParameterValue(portletNode, "row_position"));
838                                 break;
839                             }
840                         }
841                         portletNode = portletNode.getNextSibling();
842                     }
843
844
845                     portletNode = portletgroupNode.getFirstChild();
846                     while (portletNode != null) {
847                         // we are going through the portletgroup tags which represent list of portlets
848
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
849                             // we are now on a PORTLET tag
850
if (Integer.parseInt(getParameterValue(portletNode, "column_position")) == Column) {
851                                 if (Integer.parseInt(getParameterValue(portletNode, "row_position")) > MaxRow) { MaxRow = Integer.parseInt(getParameterValue(portletNode, "row_position")); }
852                             }
853                         }
854                         portletNode = portletNode.getNextSibling();
855                     }
856                     if (Row == MaxRow) { return; }
857
858
859                     portletNode = portletgroupNode.getFirstChild();
860                     while (portletNode != null) {
861                         // we are going through the portletgroup tags which represent list of portlets
862
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
863                             // we are now on a PORTLET tag
864
paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE);
865                             if (paramAttrNode.equals(new Integer JavaDoc(thePortletID).toString())) {
866                                 Node JavaDoc paramNode = portletNode.getFirstChild();
867                                 while (paramNode != null) {
868                                     if (paramNode.getNodeType() == Node.ELEMENT_NODE && paramNode.getNodeName().equalsIgnoreCase(PARAMETER_TAG)) {
869                                         paramAttrNode = getAttributeValue(paramNode, PARAMETER_TAG_NAME_ATTRIBUTE);
870                                         if (paramAttrNode.equals("row_position")) {
871                                             theNode = paramNode.getFirstChild();
872                                             while (theNode != null) {
873                                                 if (theNode.getNodeType() == Node.TEXT_NODE) {
874                                                     theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(Row + 1).toString());
875                                                     paramNode.replaceChild(theTextNode, theNode);
876                                                     break;
877                                                 }
878                                                 theNode = theNode.getNextSibling();
879                                             }
880                                         }
881                                     }
882                                     paramNode = paramNode.getNextSibling();
883                                 }
884                                 break;
885                             }
886                         }
887                         portletNode = portletNode.getNextSibling();
888                     }
889
890
891                     portletNode = portletgroupNode.getFirstChild();
892                     while (portletNode != null) {
893                         // we are going through the portletgroup tags which represent list of portlets
894
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
895                             // we are now on a PORTLET tag
896
if (Integer.parseInt(getParameterValue(portletNode, "column_position")) == Column) {
897                                 if (Integer.parseInt(getParameterValue(portletNode, "row_position")) == (Row + 1)) {
898                                     paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE);
899                                     if (!paramAttrNode.equals(new Integer JavaDoc(thePortletID).toString())) {
900                                         Node JavaDoc paramNode = portletNode.getFirstChild();
901                                         while (paramNode != null) {
902                                             if (paramNode.getNodeType() == Node.ELEMENT_NODE && paramNode.getNodeName().equalsIgnoreCase(PARAMETER_TAG)) {
903                                                 paramAttrNode = getAttributeValue(paramNode, PARAMETER_TAG_NAME_ATTRIBUTE);
904                                                 if (paramAttrNode.equals("row_position")) {
905                                                     theNode = paramNode.getFirstChild();
906                                                     while (theNode != null) {
907                                                         if (theNode.getNodeType() == Node.TEXT_NODE) {
908                                                             theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(Row).toString());
909                                                             paramNode.replaceChild(theTextNode, theNode);
910                                                             break;
911                                                         }
912                                                         theNode = theNode.getNextSibling();
913                                                     }
914                                                 }
915                                             }
916                                             paramNode = paramNode.getNextSibling();
917                                         }
918                                     }
919                                 }
920                             }
921                         }
922                         portletNode = portletNode.getNextSibling();
923                     }
924
925                     saveFile(xmlDocument,theFile.getAbsolutePath());
926
927                     return;
928
929                 }
930             }
931             portletgroupNode = portletgroupNode.getNextSibling();
932         }
933     } catch (NumberFormatException JavaDoc n) {
934         throw new JahiaException(ERROR_READING_PLML_FILE_MSG,
935                                 "Invalid Integer in moveBottomPortlet !!! : " + n.toString(),
936                                 JahiaException.CRITICAL_SEVERITY,
937                                 JahiaException.CONFIG_ERROR);
938     }
939
940 } // end moveBottomPortlet
941

942
943     //--------------------------------------------------------------------------
944
/**
945      * Move the portlet to the top row in the Portlets XML file Descriptor
946      *
947      * @author Jerome Bedat
948      *
949      */

950     public void moveTopPortlet(int thePortletID) throws JahiaException {
951
952     portletgroupNode = plmlNode.getFirstChild();
953     Node JavaDoc theNode;
954
955     try {
956         while (portletgroupNode != null) {
957             if (portletgroupNode.getNodeType() == Node.ELEMENT_NODE && portletgroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {
958                 if (Integer.parseInt(getParameterValue(portletgroupNode, "page_id")) == thePageID) {
959                     Node JavaDoc portletNode = portletgroupNode.getFirstChild();
960                     int Column = 0;
961                     int Row = 0;
962                     while (portletNode != null) {
963                         // we are going through the portletgroup tags which represent list of portlets
964
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
965                             // we are now on a PORTLET tag
966
paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE);
967                             if (paramAttrNode.equals(new Integer JavaDoc(thePortletID).toString())) {
968                                 Column = Integer.parseInt(getParameterValue(portletNode, "column_position"));
969                                 Row = Integer.parseInt(getParameterValue(portletNode, "row_position"));
970                                 if (Row == 1) { return; }
971                                 Node JavaDoc paramNode = portletNode.getFirstChild();
972                                 while (paramNode != null) {
973                                     if (paramNode.getNodeType() == Node.ELEMENT_NODE && paramNode.getNodeName().equalsIgnoreCase(PARAMETER_TAG)) {
974                                         paramAttrNode = getAttributeValue(paramNode, PARAMETER_TAG_NAME_ATTRIBUTE);
975                                         if (paramAttrNode.equals("row_position")) {
976                                             theNode = paramNode.getFirstChild();
977                                             while (theNode != null) {
978                                                 if (theNode.getNodeType() == Node.TEXT_NODE) {
979                                                     theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(Row - 1).toString());
980                                                     paramNode.replaceChild(theTextNode, theNode);
981                                                     break;
982                                                 }
983                                                 theNode = theNode.getNextSibling();
984                                             }
985                                         }
986                                     }
987                                     paramNode = paramNode.getNextSibling();
988                                 }
989                                 break;
990                             }
991                         }
992                         portletNode = portletNode.getNextSibling();
993                     }
994
995
996                     portletNode = portletgroupNode.getFirstChild();
997                     while (portletNode != null) {
998                         // we are going through the portletgroup tags which represent list of portlets
999
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
1000                            // we are now on a PORTLET tag
1001
if (Integer.parseInt(getParameterValue(portletNode, "column_position")) == Column) {
1002                                if (Integer.parseInt(getParameterValue(portletNode, "row_position")) == (Row - 1)) {
1003                                    paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE);
1004                                    if (!paramAttrNode.equals(new Integer JavaDoc(thePortletID).toString())) {
1005                                        Node JavaDoc paramNode = portletNode.getFirstChild();
1006                                        while (paramNode != null) {
1007                                            if (paramNode.getNodeType() == Node.ELEMENT_NODE && paramNode.getNodeName().equalsIgnoreCase(PARAMETER_TAG)) {
1008                                                paramAttrNode = getAttributeValue(paramNode, PARAMETER_TAG_NAME_ATTRIBUTE);
1009                                                if (paramAttrNode.equals("row_position")) {
1010                                                    theNode = paramNode.getFirstChild();
1011                                                    while (theNode != null) {
1012                                                        if (theNode.getNodeType() == Node.TEXT_NODE) {
1013                                                            theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(Row).toString());
1014                                                            paramNode.replaceChild(theTextNode, theNode);
1015                                                            break;
1016                                                        }
1017                                                        theNode = theNode.getNextSibling();
1018                                                    }
1019                                                }
1020                                            }
1021                                            paramNode = paramNode.getNextSibling();
1022                                        }
1023                                    }
1024                                }
1025                            }
1026                        }
1027                        portletNode = portletNode.getNextSibling();
1028                    }
1029
1030                    saveFile(xmlDocument,theFile.getAbsolutePath());
1031
1032                    return;
1033
1034                }
1035            }
1036            portletgroupNode = portletgroupNode.getNextSibling();
1037        }
1038    } catch (NumberFormatException JavaDoc n) {
1039        throw new JahiaException(ERROR_READING_PLML_FILE_MSG,
1040                                "Invalid Integer in moveTopPortlet !!! : " + n.toString(),
1041                                JahiaException.CRITICAL_SEVERITY,
1042                                JahiaException.CONFIG_ERROR);
1043    }
1044
1045    } // end moveTopPortlet
1046

1047
1048    //--------------------------------------------------------------------------
1049
/**
1050     * update the portlet settings
1051     *
1052     * @author Jerome Bedat
1053     *
1054     */

1055    public void updatePortlet(PortletObj thePortlet) throws JahiaException {
1056
1057    portletgroupNode = plmlNode.getFirstChild();
1058    Node JavaDoc theNode;
1059
1060    try {
1061        while (portletgroupNode != null) {
1062            if (portletgroupNode.getNodeType() == Node.ELEMENT_NODE && portletgroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {
1063                if (Integer.parseInt(getParameterValue(portletgroupNode, "page_id")) == thePageID) {
1064                    Node JavaDoc portletNode = portletgroupNode.getFirstChild();
1065                    while (portletNode != null) {
1066                        // we are going through the portletgroup tags which represent list of portlets
1067
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
1068                            // we are now on a PORTLET tag
1069
String JavaDoc theParam;
1070                            paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE);
1071                            if (paramAttrNode.equals(new Integer JavaDoc(thePortlet.getPortletID()).toString())) {
1072                                Node JavaDoc paramNode = portletNode.getFirstChild();
1073                                while (paramNode != null) {
1074                                    if (paramNode.getNodeType() == Node.ELEMENT_NODE && paramNode.getNodeName().equalsIgnoreCase(PARAMETER_TAG)) {
1075                                        paramAttrNode = getAttributeValue(paramNode, PARAMETER_TAG_NAME_ATTRIBUTE);
1076                                        if (paramAttrNode.equals("source_id")) {
1077                                            theNode = paramNode.getFirstChild();
1078                                            while (theNode != null) {
1079                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1080                                                    theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(thePortlet.getPortletSourceID()).toString());
1081                                                    paramNode.replaceChild(theTextNode, theNode);
1082                                                    break;
1083                                                }
1084                                                theNode = theNode.getNextSibling();
1085                                            }
1086                                        }
1087                                        if (paramAttrNode.equals("active")) {
1088                                            theNode = paramNode.getFirstChild();
1089                                            while (theNode != null) {
1090                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1091                                                    theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(thePortlet.getPortletActive()).toString());
1092                                                    paramNode.replaceChild(theTextNode, theNode);
1093                                                    break;
1094                                                }
1095                                                theNode = theNode.getNextSibling();
1096                                            }
1097                                        }
1098                                        if (paramAttrNode.equals("title")) {
1099                                            theNode = paramNode.getFirstChild();
1100                                            while (theNode != null) {
1101                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1102                                                    theParam = (!thePortlet.getPortletTitle().equals("")) ? thePortlet.getPortletTitle() : "-";
1103                                                    theTextNode = xmlDocument.createTextNode(theParam);
1104                                                    paramNode.replaceChild(theTextNode, theNode);
1105                                                    break;
1106                                                }
1107                                                theNode = theNode.getNextSibling();
1108                                            }
1109                                        }
1110                                        if (paramAttrNode.equals("bgcolor")) {
1111                                            theNode = paramNode.getFirstChild();
1112                                            while (theNode != null) {
1113                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1114                                                    theParam = (!thePortlet.getPortletBgColor().equals("")) ? thePortlet.getPortletBgColor() : "-";
1115                                                    theTextNode = xmlDocument.createTextNode(theParam);
1116                                                    paramNode.replaceChild(theTextNode, theNode);
1117                                                    break;
1118                                                }
1119                                                theNode = theNode.getNextSibling();
1120                                            }
1121                                        }
1122                                        if (paramAttrNode.equals("bgimage_url")) {
1123                                            theNode = paramNode.getFirstChild();
1124                                            while (theNode != null) {
1125                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1126                                                    theParam = (!thePortlet.getPortletBgImage().equals("")) ? thePortlet.getPortletBgImage() : "-";
1127                                                    theTextNode = xmlDocument.createTextNode(theParam);
1128                                                    paramNode.replaceChild(theTextNode, theNode);
1129                                                    break;
1130                                                }
1131                                                theNode = theNode.getNextSibling();
1132                                            }
1133                                        }
1134                                        if (paramAttrNode.equals("font")) {
1135                                            theNode = paramNode.getFirstChild();
1136                                            while (theNode != null) {
1137                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1138                                                    theParam = (!thePortlet.getPortletFont().equals("")) ? thePortlet.getPortletFont() : "-";
1139                                                    theTextNode = xmlDocument.createTextNode(theParam);
1140                                                    paramNode.replaceChild(theTextNode, theNode);
1141                                                    break;
1142                                                }
1143                                                theNode = theNode.getNextSibling();
1144                                            }
1145                                        }
1146                                        if (paramAttrNode.equals("fontsize")) {
1147                                            theNode = paramNode.getFirstChild();
1148                                            while (theNode != null) {
1149                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1150                                                    theParam = (!thePortlet.getPortletFontSize().equals("")) ? thePortlet.getPortletFontSize() : "-";
1151                                                    theTextNode = xmlDocument.createTextNode(theParam);
1152                                                    paramNode.replaceChild(theTextNode, theNode);
1153                                                    break;
1154                                                }
1155                                                theNode = theNode.getNextSibling();
1156                                            }
1157                                        }
1158                                        if (paramAttrNode.equals("fontcolor")) {
1159                                            theNode = paramNode.getFirstChild();
1160                                            while (theNode != null) {
1161                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1162                                                    theParam = (!thePortlet.getPortletFontColor().equals("")) ? thePortlet.getPortletFontColor() : "-";
1163                                                    theTextNode = xmlDocument.createTextNode(theParam);
1164                                                    paramNode.replaceChild(theTextNode, theNode);
1165                                                    break;
1166                                                }
1167                                                theNode = theNode.getNextSibling();
1168                                            }
1169                                        }
1170                                        if (paramAttrNode.equals("skin_id")) {
1171                                            theNode = paramNode.getFirstChild();
1172                                            while (theNode != null) {
1173                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1174                                                    theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(thePortlet.getPortletSkinID()).toString());
1175                                                    paramNode.replaceChild(theTextNode, theNode);
1176                                                    break;
1177                                                }
1178                                                theNode = theNode.getNextSibling();
1179                                            }
1180                                        }
1181                                        if (paramAttrNode.equals("scrollable")) {
1182                                            theNode = paramNode.getFirstChild();
1183                                            while (theNode != null) {
1184                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1185                                                    theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(thePortlet.getPortletScrollable()).toString());
1186                                                    paramNode.replaceChild(theTextNode, theNode);
1187                                                    break;
1188                                                }
1189                                                theNode = theNode.getNextSibling();
1190                                            }
1191                                        }
1192                                        if (paramAttrNode.equals("resizable")) {
1193                                            theNode = paramNode.getFirstChild();
1194                                            while (theNode != null) {
1195                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1196                                                    theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(thePortlet.getPortletResizable()).toString());
1197                                                    paramNode.replaceChild(theTextNode, theNode);
1198                                                    break;
1199                                                }
1200                                                theNode = theNode.getNextSibling();
1201                                            }
1202                                        }
1203                                        if (paramAttrNode.equals("fixed")) {
1204                                            theNode = paramNode.getFirstChild();
1205                                            while (theNode != null) {
1206                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1207                                                    theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(thePortlet.getPortletFixed()).toString());
1208                                                    paramNode.replaceChild(theTextNode, theNode);
1209                                                    break;
1210                                                }
1211                                                theNode = theNode.getNextSibling();
1212                                            }
1213                                        }
1214                                        if (paramAttrNode.equals("innerspace")) {
1215                                            theNode = paramNode.getFirstChild();
1216                                            while (theNode != null) {
1217                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1218                                                    theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(thePortlet.getPortletInnerSpace()).toString());
1219                                                    paramNode.replaceChild(theTextNode, theNode);
1220                                                    break;
1221                                                }
1222                                                theNode = theNode.getNextSibling();
1223                                            }
1224                                        }
1225                                        if (paramAttrNode.equals("x")) {
1226                                            theNode = paramNode.getFirstChild();
1227                                            while (theNode != null) {
1228                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1229                                                    theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(thePortlet.getPortletX()).toString());
1230                                                    paramNode.replaceChild(theTextNode, theNode);
1231                                                    break;
1232                                                }
1233                                                theNode = theNode.getNextSibling();
1234                                            }
1235                                        }
1236                                        if (paramAttrNode.equals("y")) {
1237                                            theNode = paramNode.getFirstChild();
1238                                            while (theNode != null) {
1239                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1240                                                    theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(thePortlet.getPortletY()).toString());
1241                                                    paramNode.replaceChild(theTextNode, theNode);
1242                                                    break;
1243                                                }
1244                                                theNode = theNode.getNextSibling();
1245                                            }
1246                                        }
1247                                        if (paramAttrNode.equals("w")) {
1248                                            theNode = paramNode.getFirstChild();
1249                                            while (theNode != null) {
1250                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1251                                                    theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(thePortlet.getPortletW()).toString());
1252                                                    paramNode.replaceChild(theTextNode, theNode);
1253                                                    break;
1254                                                }
1255                                                theNode = theNode.getNextSibling();
1256                                            }
1257                                        }
1258                                        if (paramAttrNode.equals("h")) {
1259                                            theNode = paramNode.getFirstChild();
1260                                            while (theNode != null) {
1261                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1262                                                    theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(thePortlet.getPortletH()).toString());
1263                                                    paramNode.replaceChild(theTextNode, theNode);
1264                                                    break;
1265                                                }
1266                                                theNode = theNode.getNextSibling();
1267                                            }
1268                                        }
1269                                        if (paramAttrNode.equals("column_position")) {
1270                                            theNode = paramNode.getFirstChild();
1271                                            while (theNode != null) {
1272                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1273                                                    theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(thePortlet.getPortletColumn()).toString());
1274                                                    paramNode.replaceChild(theTextNode, theNode);
1275                                                    break;
1276                                                }
1277                                                theNode = theNode.getNextSibling();
1278                                            }
1279                                        }
1280                                        if (paramAttrNode.equals("row_position")) {
1281                                            theNode = paramNode.getFirstChild();
1282                                            while (theNode != null) {
1283                                                if (theNode.getNodeType() == Node.TEXT_NODE) {
1284                                                    theTextNode = xmlDocument.createTextNode(new Integer JavaDoc(thePortlet.getPortletRow()).toString());
1285                                                    paramNode.replaceChild(theTextNode, theNode);
1286                                                    break;
1287                                                }
1288                                                theNode = theNode.getNextSibling();
1289                                            }
1290                                        }
1291                                    }
1292                                    paramNode = paramNode.getNextSibling();
1293                                }
1294                                break;
1295                            }
1296                        }
1297                        portletNode = portletNode.getNextSibling();
1298                    }
1299
1300                    saveFile(xmlDocument,theFile.getAbsolutePath());
1301
1302                    return;
1303
1304                }
1305            }
1306            portletgroupNode = portletgroupNode.getNextSibling();
1307        }
1308    } catch (NumberFormatException JavaDoc n) {
1309        throw new JahiaException(ERROR_READING_PLML_FILE_MSG,
1310                                "Invalid Integer in updatePortlet !!! : " + n.toString(),
1311                                JahiaException.CRITICAL_SEVERITY,
1312                                JahiaException.CONFIG_ERROR);
1313    }
1314
1315    } // end updatePortlet
1316

1317
1318    //--------------------------------------------------------------------------
1319
/**
1320     * delete the portlet
1321     *
1322     * @author Jerome Bedat
1323     *
1324     */

1325    public void deletePortlet(int theSourceID) throws JahiaException {
1326
1327    portletgroupNode = plmlNode.getFirstChild();
1328
1329    try {
1330        while (portletgroupNode != null) {
1331            if (portletgroupNode.getNodeType() == Node.ELEMENT_NODE && portletgroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {
1332                if (Integer.parseInt(getParameterValue(portletgroupNode, "page_id")) == thePageID) {
1333                    Node JavaDoc portletNode = portletgroupNode.getFirstChild();
1334                    while (portletNode != null) {
1335                        // we are going through the portletgroup tags which represent list of portlets
1336
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
1337                            // we are now on a PORTLET tag
1338
paramAttrNode = getParameterValue(portletNode, "source_id");
1339                            if (Integer.parseInt(paramAttrNode) == theSourceID) {
1340                                portletgroupNode.removeChild(portletNode);
1341                                break;
1342                            }
1343                        }
1344                        portletNode = portletNode.getNextSibling();
1345                    }
1346
1347                    saveFile(xmlDocument,theFile.getAbsolutePath());
1348
1349                    return;
1350
1351                }
1352            }
1353            portletgroupNode = portletgroupNode.getNextSibling();
1354        }
1355    } catch (NumberFormatException JavaDoc n) {
1356        throw new JahiaException(ERROR_READING_PLML_FILE_MSG,
1357                                "Invalid Integer in deletePortlet !!! : " + n.toString(),
1358                                JahiaException.CRITICAL_SEVERITY,
1359                                JahiaException.CONFIG_ERROR);
1360    }
1361
1362    } // end deletePortlet
1363

1364
1365    //--------------------------------------------------------------------------
1366
/**
1367     * Add new Portlet to the Portlets XML file Descriptor
1368     *
1369     * @author Jerome Bedat
1370     *
1371     */

1372    public void addPortlet(int theSourceID) throws JahiaException {
1373
1374    boolean isPortletGroupNode = false;
1375
1376    portletgroupNode = plmlNode.getFirstChild();
1377
1378    try {
1379        while (portletgroupNode != null) {
1380            if (portletgroupNode.getNodeType() == Node.ELEMENT_NODE && portletgroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {
1381                if (Integer.parseInt(getParameterValue(portletgroupNode, "page_id")) == thePageID) {
1382                    isPortletGroupNode = true;
1383                    Node JavaDoc portletNode = portletgroupNode.getFirstChild();
1384                    int MaxRow = 0;
1385                    while (portletNode != null) {
1386                        // we are going through the portletgroup tags which represent list of portlets
1387
if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {
1388                            // we are now on a PORTLET tag
1389
if (Integer.parseInt(getParameterValue(portletNode, "column_position")) == 1) {
1390                                if (Integer.parseInt(getParameterValue(portletNode, "row_position")) > MaxRow) { MaxRow = Integer.parseInt(getParameterValue(portletNode, "row_position")); }
1391                            }
1392                        }
1393                        portletNode = portletNode.getNextSibling();
1394                    }
1395
1396                    Integer JavaDoc thePID = new Integer JavaDoc(update_count("portlet"));
1397                    Element JavaDoc newPortletNode = (Element JavaDoc) xmlDocument.createElement(PORTLET_TAG);
1398
1399                    newPortletNode.setAttribute(PARAMETER_TAG_ID_ATTRIBUTE, thePID.toString());
1400                    portletgroupNode.appendChild(newPortletNode);
1401
1402                    Element JavaDoc paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1403                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "active");
1404                    theTextNode = xmlDocument.createTextNode("1");
1405                    paramNode.appendChild(theTextNode);
1406                    newPortletNode.appendChild(paramNode);
1407
1408                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1409                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "title");
1410                    theTextNode = xmlDocument.createTextNode("-1");
1411                    paramNode.appendChild(theTextNode);
1412                    newPortletNode.appendChild(paramNode);
1413
1414                    Integer JavaDoc theSID = new Integer JavaDoc(theSourceID);
1415                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1416                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "source_id");
1417                    theTextNode = xmlDocument.createTextNode(theSID.toString());
1418                    paramNode.appendChild(theTextNode);
1419                    newPortletNode.appendChild(paramNode);
1420
1421                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1422                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "icon_url");
1423                    theTextNode = xmlDocument.createTextNode("-1");
1424                    paramNode.appendChild(theTextNode);
1425                    newPortletNode.appendChild(paramNode);
1426
1427                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1428                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "bgcolor");
1429                    theTextNode = xmlDocument.createTextNode("-1");
1430                    paramNode.appendChild(theTextNode);
1431                    newPortletNode.appendChild(paramNode);
1432
1433                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1434                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "bgimage_url");
1435                    theTextNode = xmlDocument.createTextNode("-1");
1436                    paramNode.appendChild(theTextNode);
1437                    newPortletNode.appendChild(paramNode);
1438
1439                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1440                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "font");
1441                    theTextNode = xmlDocument.createTextNode("-1");
1442                    paramNode.appendChild(theTextNode);
1443                    newPortletNode.appendChild(paramNode);
1444
1445                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1446                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "fontsize");
1447                    theTextNode = xmlDocument.createTextNode("-1");
1448                    paramNode.appendChild(theTextNode);
1449                    newPortletNode.appendChild(paramNode);
1450
1451                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1452                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "fontcolor");
1453                    theTextNode = xmlDocument.createTextNode("-1");
1454                    paramNode.appendChild(theTextNode);
1455                    newPortletNode.appendChild(paramNode);
1456
1457                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1458                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "skin_id");
1459                    theTextNode = xmlDocument.createTextNode("-1");
1460                    paramNode.appendChild(theTextNode);
1461                    newPortletNode.appendChild(paramNode);
1462
1463                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1464                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "scrollable");
1465                    theTextNode = xmlDocument.createTextNode("-1");
1466                    paramNode.appendChild(theTextNode);
1467                    newPortletNode.appendChild(paramNode);
1468
1469                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1470                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "resizable");
1471                    theTextNode = xmlDocument.createTextNode("-1");
1472                    paramNode.appendChild(theTextNode);
1473                    newPortletNode.appendChild(paramNode);
1474
1475                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1476                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "fixed");
1477                    theTextNode = xmlDocument.createTextNode("-1");
1478                    paramNode.appendChild(theTextNode);
1479                    newPortletNode.appendChild(paramNode);
1480
1481                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1482                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "innerspace");
1483                    theTextNode = xmlDocument.createTextNode("-1");
1484                    paramNode.appendChild(theTextNode);
1485                    newPortletNode.appendChild(paramNode);
1486
1487                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1488                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "x");
1489                    theTextNode = xmlDocument.createTextNode("-1");
1490                    paramNode.appendChild(theTextNode);
1491                    newPortletNode.appendChild(paramNode);
1492
1493                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1494                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "y");
1495                    theTextNode = xmlDocument.createTextNode("-1");
1496                    paramNode.appendChild(theTextNode);
1497                    newPortletNode.appendChild(paramNode);
1498
1499                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1500                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "w");
1501                    theTextNode = xmlDocument.createTextNode("-1");
1502                    paramNode.appendChild(theTextNode);
1503                    newPortletNode.appendChild(paramNode);
1504
1505                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1506                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "h");
1507                    theTextNode = xmlDocument.createTextNode("-1");
1508                    paramNode.appendChild(theTextNode);
1509                    newPortletNode.appendChild(paramNode);
1510
1511                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1512                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "column_position");
1513                    theTextNode = xmlDocument.createTextNode("1");
1514                    paramNode.appendChild(theTextNode);
1515                    newPortletNode.appendChild(paramNode);
1516
1517                    Integer JavaDoc theMROW = new Integer JavaDoc(MaxRow + 1);
1518                    paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1519                    paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "row_position");
1520                    theTextNode = xmlDocument.createTextNode(theMROW.toString());
1521                    paramNode.appendChild(theTextNode);
1522                    newPortletNode.appendChild(paramNode);
1523
1524                    saveFile(xmlDocument,theFile.getAbsolutePath());
1525
1526                    return;
1527
1528                }
1529            }
1530            portletgroupNode = portletgroupNode.getNextSibling();
1531        }
1532    } catch (NumberFormatException JavaDoc n) {
1533        throw new JahiaException(ERROR_READING_PLML_FILE_MSG,
1534                                "Invalid Integer in addPortlet !!! : " + n.toString(),
1535                                JahiaException.CRITICAL_SEVERITY,
1536                                JahiaException.CONFIG_ERROR);
1537    }
1538
1539    if (!isPortletGroupNode) {
1540        addPortletGroup();
1541        addPortlet(theSourceID);
1542    }
1543
1544    } // end addPortlet
1545

1546
1547    //--------------------------------------------------------------------------
1548
/**
1549     * Add new Portlet Group to the Portlets XML file
1550     *
1551     * @author Jerome Bedat
1552     *
1553     */

1554    public void addPortletGroup() throws JahiaException {
1555
1556    if (addPortletGroup) { return; }
1557
1558    Document JavaDoc defaultXmlDocument = null;
1559    Element JavaDoc theDefaultPlmlNode;
1560    Node JavaDoc defaultPortletGroupNode;
1561    plmlNode = getPlmlNode(); // should put us on "portletgroup" tag.
1562

1563    File JavaDoc theDefaultFile = new File JavaDoc(theDefaultXMLfile);
1564
1565    if (!theDefaultFile.exists()) {
1566
1567        JahiaConsole.println("XMLPortlets.addPortletGroup", "Default XML File does not exist, adding PORTLETGROUP and PARAMETER tags...");
1568
1569        Integer JavaDoc thePGID = new Integer JavaDoc(update_count("portletgroup"));
1570        Element JavaDoc newPortletGroupNode = (Element JavaDoc) xmlDocument.createElement(PORTLETLIST_TAG);
1571        newPortletGroupNode.setAttribute(PARAMETER_TAG_ID_ATTRIBUTE, thePGID.toString());
1572        plmlNode.appendChild(newPortletGroupNode);
1573
1574        Integer JavaDoc thePID = new Integer JavaDoc(thePageID);
1575        Element JavaDoc paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1576        paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "page_id");
1577        Text JavaDoc theTextNode = xmlDocument.createTextNode(thePID.toString());
1578        paramNode.appendChild(theTextNode);
1579        newPortletGroupNode.appendChild(paramNode);
1580
1581    } else {
1582
1583        JahiaConsole.println("XMLPortlets.addPortletGroup", "Default XML File exists...");
1584
1585        defaultXmlDocument = loadFile("file:" + theDefaultXMLfile);
1586
1587        Element JavaDoc DefaultDocElNode = (Element JavaDoc) defaultXmlDocument.getDocumentElement();
1588        DefaultDocElNode.normalize();
1589
1590        if (defaultXmlDocument == null) {
1591            throw new JahiaException("Can't access portlet layout",
1592                                "Initialisation of portlet layout desc must have failed",
1593                                JahiaException.CRITICAL_SEVERITY,
1594                                JahiaException.CONFIG_ERROR);
1595        }
1596
1597        if (!DefaultDocElNode.hasChildNodes()) {
1598            throw new JahiaException("Empty XML portlet layout file (PLML tag is empty)",
1599                                "Main document node has no children",
1600                                JahiaException.CRITICAL_SEVERITY,
1601                                JahiaException.CONFIG_ERROR);
1602        }
1603
1604
1605        theDefaultPlmlNode = defaultXmlDocument.getDocumentElement(); // should put us on "plml" tag.
1606

1607        if (!theDefaultPlmlNode.getNodeName().equalsIgnoreCase(PLML_TAG)) {
1608            throw new JahiaException("Invalid XML format",
1609                                "PSML tag is not present as starting tag in file",
1610                                JahiaException.CRITICAL_SEVERITY,
1611                                JahiaException.CONFIG_ERROR);
1612        }
1613
1614
1615        defaultPortletGroupNode = theDefaultPlmlNode.getFirstChild(); // should put us on "portletgroupe" tag.
1616

1617        if (defaultPortletGroupNode.getNodeType() == Node.ELEMENT_NODE) {
1618            if (!defaultPortletGroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {
1619            throw new JahiaException("Invalid XML format",
1620                                "PORTLETGROUPE tag is not present in file",
1621                                JahiaException.CRITICAL_SEVERITY,
1622                                JahiaException.CONFIG_ERROR);
1623            }
1624        } else {
1625            defaultPortletGroupNode = defaultPortletGroupNode.getNextSibling();
1626        }
1627
1628        boolean isDefaultPortletGroup = false;
1629
1630        try {
1631            while (defaultPortletGroupNode != null) {
1632                if (defaultPortletGroupNode.getNodeType() == Node.ELEMENT_NODE && defaultPortletGroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {
1633                    if (Integer.parseInt(getParameterValue(defaultPortletGroupNode, "page_id")) == thePageID) {
1634                        plmlNode.appendChild(xmlDocument.importNode(defaultPortletGroupNode,true));
1635                        isDefaultPortletGroup = true;
1636                        break;
1637                    }
1638                }
1639                defaultPortletGroupNode = defaultPortletGroupNode.getNextSibling();
1640            }
1641        } catch (NumberFormatException JavaDoc n) {
1642            throw new JahiaException(ERROR_READING_PLML_FILE_MSG,
1643                                    "Invalid Integer in addPortletGroup !!! : " + n.toString(),
1644                                    JahiaException.CRITICAL_SEVERITY,
1645                                    JahiaException.CONFIG_ERROR);
1646        }
1647
1648        if (!isDefaultPortletGroup) {
1649
1650            Integer JavaDoc thePGID = new Integer JavaDoc(update_count("portletgroup"));
1651            Element JavaDoc newPortletGroupNode = (Element JavaDoc) xmlDocument.createElement(PORTLETLIST_TAG);
1652            newPortletGroupNode.setAttribute(PARAMETER_TAG_ID_ATTRIBUTE, thePGID.toString());
1653            plmlNode.appendChild(newPortletGroupNode);
1654
1655            Integer JavaDoc thePID = new Integer JavaDoc(thePageID);
1656            Element JavaDoc paramNode = (Element JavaDoc) xmlDocument.createElement(PARAMETER_TAG);
1657            paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "page_id");
1658            Text JavaDoc theTextNode = xmlDocument.createTextNode(thePID.toString());
1659            paramNode.appendChild(theTextNode);
1660            newPortletGroupNode.appendChild(paramNode);
1661
1662        }
1663
1664    }
1665
1666    saveFile(xmlDocument,theFile.getAbsolutePath());
1667
1668    } // end addPortletGroup
1669

1670
1671    //--------------------------------------------------------------------------
1672
/**
1673     * Copy new Portlet Group to the Guest file Descriptor
1674     *
1675     * @author Jerome Bedat
1676     *
1677     */

1678    public Vector JavaDoc copyXMLPortletGroup(String JavaDoc theNewXMLfile) throws JahiaException {
1679
1680    Element JavaDoc theNewPlmlNode = null;
1681    Node JavaDoc newPortletGroupNode = null;
1682    Document JavaDoc newXmlDocument = null;
1683    Vector JavaDoc sourceIDList = new Vector JavaDoc();
1684    File JavaDoc theNewFile = new File JavaDoc(theNewXMLfile);
1685
1686    if (!theNewFile.exists()) {
1687
1688        try {
1689
1690            JahiaConsole.println("XMLPortlets.copyPortletGroup", "file doesn't exists");
1691
1692            DocumentBuilderFactory JavaDoc dfactory = DocumentBuilderFactory.newInstance();
1693            //dfactory.setValidating(true); // create only parsers that are validating
1694
DocumentBuilder JavaDoc docBuilder = dfactory.newDocumentBuilder();
1695            //docBuilder.setEntityResolver();
1696
Document JavaDoc newXmlDoc = docBuilder.newDocument();
1697
1698            theNewPlmlNode = newXmlDoc.createElement(PLML_TAG);
1699            theNewPlmlNode.normalize();
1700            newXmlDoc.appendChild(theNewPlmlNode);
1701
1702            theNewFile.createNewFile();
1703            saveFile(newXmlDoc,theNewFile.getAbsolutePath());
1704
1705            newXmlDocument = loadFile("file:" + theNewXMLfile);
1706
1707            Element JavaDoc NewDocElNode = (Element JavaDoc) newXmlDocument.getDocumentElement();
1708            NewDocElNode.normalize();
1709
1710            theNewPlmlNode = newXmlDocument.getDocumentElement();
1711
1712        } catch (IOException JavaDoc ioe) {
1713            throw new JahiaException(CANT_READ_PORTLET_XML_MSG,
1714                                    "IOException in XML file writing : " + ioe.toString(),
1715                                    JahiaException.CRITICAL_SEVERITY,
1716                                    JahiaException.CONFIG_ERROR);
1717        } catch (Throwable JavaDoc t) {
1718            throw new JahiaException(CANT_READ_PORTLET_XML_MSG,
1719                                    "Exception in XML file writing : " + t.toString(),
1720                                    JahiaException.CRITICAL_SEVERITY,
1721                                    JahiaException.CONFIG_ERROR);
1722
1723        }
1724
1725    } else {
1726
1727        JahiaConsole.println("XMLPortlets.copyPortletGroup", "file exists");
1728
1729        newXmlDocument = loadFile("file:" + theNewXMLfile);
1730
1731        Element JavaDoc NewDocElNode = (Element JavaDoc) newXmlDocument.getDocumentElement();
1732        NewDocElNode.normalize();
1733
1734        if (newXmlDocument == null) {
1735            throw new JahiaException("Can't access portlet layout",
1736                                "Initialisation of portlet layout desc must have failed",
1737                                JahiaException.CRITICAL_SEVERITY,
1738                                JahiaException.CONFIG_ERROR);
1739        }
1740
1741        if (!newXmlDocument.hasChildNodes()) {
1742            throw new JahiaException("Empty XML portlet layout file",
1743                                "Main document node has no children",
1744                                JahiaException.CRITICAL_SEVERITY,
1745                                JahiaException.CONFIG_ERROR);
1746        }
1747
1748
1749        theNewPlmlNode = newXmlDocument.getDocumentElement(); // should put us on "plml" tag.
1750

1751        if (!theNewPlmlNode.getNodeName().equalsIgnoreCase(PLML_TAG)) {
1752            throw new JahiaException("Invalid XML format",
1753                                "PSML tag is not present as starting tag in file",
1754                                JahiaException.CRITICAL_SEVERITY,
1755                                JahiaException.CONFIG_ERROR);
1756        }
1757
1758
1759        newPortletGroupNode = theNewPlmlNode.getFirstChild(); // should put us on "portletgroupe" tag.
1760

1761        if (newPortletGroupNode.getNodeType() == Node.ELEMENT_NODE) {
1762            if (!newPortletGroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {
1763            throw new JahiaException("Invalid XML format",
1764                                "PORTLETGROUPE tag is not present in file",
1765                                JahiaException.CRITICAL_SEVERITY,
1766                                JahiaException.CONFIG_ERROR);
1767            }
1768        } else {
1769            newPortletGroupNode = newPortletGroupNode.getNextSibling();
1770        }
1771
1772    }
1773
1774
1775    try {
1776        while (newPortletGroupNode != null) {
1777            if (newPortletGroupNode.getNodeType() == Node.ELEMENT_NODE && newPortletGroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {
1778                if (Integer.parseInt(getParameterValue(newPortletGroupNode, "page_id")) == thePageID) {
1779                    theNewPlmlNode.removeChild(newPortletGroupNode);
1780                    break;
1781                }
1782            }
1783            newPortletGroupNode = newPortletGroupNode.getNextSibling();
1784        }
1785    } catch (NumberFormatException JavaDoc n) {
1786        throw new JahiaException(ERROR_READING_PLML_FILE_MSG,
1787                                "Invalid Integer in copyXMLPortletGroup !!! : " + n.toString(),
1788                                JahiaException.CRITICAL_SEVERITY,
1789                                JahiaException.CONFIG_ERROR);
1790    }
1791
1792
1793    try {
1794
1795        while (portletgroupNode != null) {
1796            if (portletgroupNode.getNodeType() == Node.ELEMENT_NODE && portletgroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {
1797                if (Integer.parseInt(getParameterValue(portletgroupNode, "page_id")) == thePageID) {
1798                    Node JavaDoc portletNode = portletgroupNode.getFirstChild();
1799
1800
1801
1802                    ////////////////////////////////////////////////////////////////////////////////////
1803
// FIXME -Fulco-
1804
//
1805
// The following part is a temporary hack in order to avoid any other users,
1806
// beside the administrators, to have write and/or administration rights
1807
// on all the containers containing a portlet.
1808
//
1809
////////////////////////////////////////////////////////////////////////////////////
1810

1811                    while (portletNode != null) {
1812                        // we are going through the portletgroup tags which represent list of portlets
1813
if ((portletNode.getNodeType() == Node.ELEMENT_NODE) &&
1814                            (portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)))
1815                        {
1816                            // we are now on a PORTLET tag
1817
sourceIDList.addElement (new Integer JavaDoc (getParameterValue (portletNode, "source_id")));
1818                        }
1819                        portletNode = portletNode.getNextSibling ();
1820                    }
1821
1822                    ////////////////////////////////////////////////////////////////////////////////////
1823

1824
1825
1826
1827                    theNewPlmlNode.appendChild(newXmlDocument.importNode(portletgroupNode,true));
1828
1829                    saveFile(newXmlDocument,theNewFile.getAbsolutePath());
1830
1831                    return sourceIDList;
1832
1833                }
1834            }
1835            portletgroupNode = portletgroupNode.getNextSibling();
1836        }
1837
1838    } catch (NumberFormatException JavaDoc n) {
1839        throw new JahiaException(ERROR_READING_PLML_FILE_MSG,
1840                                "Invalid Integer in copyXMLPortletGroup !!! : " + n.toString(),
1841                                JahiaException.CRITICAL_SEVERITY,
1842                                JahiaException.CONFIG_ERROR);
1843    }
1844        return sourceIDList;
1845    } // end copyXMLPortletGroup
1846

1847
1848    //--------------------------------------------------------------------------
1849
/**
1850     * Retrieves the portletgroup node from the Portlets XML file Descriptor
1851     *
1852     * @author Jerome Bedat
1853     *
1854     */

1855    public Node JavaDoc getPortletGroupNode() throws JahiaException {
1856
1857        if (xmlDocument == null) {
1858            throw new JahiaException("Can't access portlet layout",
1859                                "Initialisation of portlet layout desc must have failed",
1860                                JahiaException.CRITICAL_SEVERITY,
1861                                JahiaException.CONFIG_ERROR);
1862        }
1863
1864        if (!xmlDocument.hasChildNodes()) {
1865            throw new JahiaException("Empty XML portlet layout file",
1866                                "Main document node has no children",
1867                                JahiaException.CRITICAL_SEVERITY,
1868                                JahiaException.CONFIG_ERROR);
1869        }
1870
1871        Element JavaDoc psmlNode = xmlDocument.getDocumentElement(); // should put us on "plml" tag.
1872

1873        if (!psmlNode.getNodeName().equalsIgnoreCase(PLML_TAG)) {
1874            throw new JahiaException("Invalid XML format",
1875                                "PSML tag is not present as starting tag in file",
1876                                JahiaException.CRITICAL_SEVERITY,
1877                                JahiaException.CONFIG_ERROR);
1878        }
1879
1880        Node JavaDoc portletgroupNode = psmlNode.getFirstChild(); // should put us on "portletgroupe" tag.
1881

1882        if (portletgroupNode.getNodeType() == Node.ELEMENT_NODE) {
1883            if (!portletgroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {
1884            throw new JahiaException("Invalid XML format",
1885                                "PORTLETGROUPE tag is not present in file",
1886                                JahiaException.CRITICAL_SEVERITY,
1887                                JahiaException.CONFIG_ERROR);
1888            }
1889            return portletgroupNode;
1890        } else {
1891            portletgroupNode = portletgroupNode.getNextSibling();
1892        }
1893
1894        return portletgroupNode;
1895    } // end getPortletGroupNode()
1896

1897
1898    //--------------------------------------------------------------------------
1899
/**
1900     * Retrieves the plml node from the Portlets XML file Descriptor
1901     *
1902     * @author Jerome Bedat
1903     *
1904     */

1905    public Node JavaDoc getPlmlNode() throws JahiaException {
1906
1907
1908        if (xmlDocument == null) {
1909            throw new JahiaException("Can't access portlet layout",
1910                                "Initialisation of portlet layout desc must have failed",
1911                                JahiaException.CRITICAL_SEVERITY,
1912                                JahiaException.CONFIG_ERROR);
1913        }
1914
1915        if (!xmlDocument.hasChildNodes()) {
1916            throw new JahiaException("Empty XML portlet layout file",
1917                                "Main document node has no children",
1918                                JahiaException.CRITICAL_SEVERITY,
1919                                JahiaException.CONFIG_ERROR);
1920        }
1921
1922        Element JavaDoc plmlNode = xmlDocument.getDocumentElement(); // should put us on "plml" tag.
1923

1924
1925        if (!plmlNode.getNodeName().equalsIgnoreCase(PLML_TAG)) {
1926            throw new JahiaException("Invalid XML format",
1927                                "PSML tag is not present as starting tag in file",
1928                                JahiaException.CRITICAL_SEVERITY,
1929                                JahiaException.CONFIG_ERROR);
1930        }
1931
1932        return plmlNode;
1933    } // end getPlmlNode()
1934

1935
1936
1937    //--------------------------------------------------------------------------
1938
/**
1939     * Update portlet autoid or portletgroup autoid
1940     *
1941     * @author Jerome Bedat
1942     *
1943     */

1944    public int update_count(String JavaDoc theType)
1945    throws JahiaException
1946    {
1947        int thePortletsCount = 0;
1948        int theDesktopsCount = 0;
1949        try {
1950
1951            if (theType.equals("portlet")) {
1952                thePortletsCount = ServicesRegistry.getInstance().getJahiaIncrementorsDBService().autoIncrement( "jahiatemplates_portlet" );
1953            } else {
1954                theDesktopsCount = ServicesRegistry.getInstance().getJahiaIncrementorsDBService().autoIncrement( "jahiatemplates_portletgroup" );
1955            }
1956
1957        } catch ( Exception JavaDoc se ) {
1958            String JavaDoc errorMsg = "Error in update_count : " + se.getMessage();
1959            JahiaConsole.println( "JahiaDBManager", errorMsg + " -> BAILING OUT" );
1960            throw new JahiaException( "Cannot update count data to the database",
1961                                        errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL_SEVERITY );
1962        }
1963        if (theType.equals("portlet")) {
1964            return thePortletsCount;
1965        } else {
1966            return theDesktopsCount;
1967        }
1968
1969    } // end update_count
1970

1971}
1972
Popular Tags