1 22 26 27 package jahiatemplates.org.jahia.portlets_api; 28 29 import java.io.File ; 30 import java.io.FileInputStream ; 31 import java.io.FileOutputStream ; 32 import java.io.IOException ; 33 import java.util.Vector ; 34 35 import javax.xml.parsers.DocumentBuilder ; 36 import javax.xml.parsers.DocumentBuilderFactory ; 37 import javax.xml.transform.OutputKeys ; 38 import javax.xml.transform.Transformer ; 39 import javax.xml.transform.TransformerFactory ; 40 import javax.xml.transform.dom.DOMSource ; 41 import javax.xml.transform.stream.StreamResult ; 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 ; 47 import org.w3c.dom.Element ; 48 import org.w3c.dom.NamedNodeMap ; 49 import org.w3c.dom.Node ; 50 import org.w3c.dom.Text ; 51 52 84 public class XMLPortlets { 85 86 private static final String CANT_READ_PORTLET_XML_MSG = "Can't read portlet XML file"; 87 private static final String ERROR_READING_PLML_FILE_MSG = "Error reading PLML file"; 88 private static final String PLML_TAG = "PLML"; 89 private static final String PARAMETER_TAG = "PARAMETER"; 90 private static final String PARAMETER_TAG_NAME_ATTRIBUTE = "name"; 91 private static final String PARAMETER_TAG_ID_ATTRIBUTE = "id"; 92 private static final String PORTLETLIST_TAG = "PORTLETGROUP"; 93 private static final String PORTLET_TAG = "PORTLET"; 94 private static final String XML_ENCODING = "ISO-8859-1"; 95 private Document xmlDocument = null; 96 private boolean addPortletGroup = false; 97 private File theFile; 98 private String theXMLfile; 99 private String theDefaultXMLfile; 100 private String paramAttrNode; 101 private Text theTextNode; 102 private Node portletgroupNode; 103 private Node plmlNode; 104 private Vector thePortletList; 105 private int thePageID; 106 private int MaxColumn = 0; 107 108 112 XMLPortlets(String theTemplatesPathDirectory, String thefilename, String theDefaultfilename, int thePageID) throws JahiaException { 113 114 File thePortletsAPIDirectory = new File ( theTemplatesPathDirectory + File.separator + "portlets_api" + File.separator ); 115 if(!thePortletsAPIDirectory.exists()) { 116 thePortletsAPIDirectory.mkdirs(); 117 } 118 String thePath = theTemplatesPathDirectory + File.separator + "portlets_api" + File.separator; 119 this.addPortletGroup = false; 120 this.theFile = new File ( 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 xmlDoc = null; 131 132 try { 133 134 DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); 135 DocumentBuilder docBuilder = dfactory.newDocumentBuilder(); 137 xmlDoc = docBuilder.newDocument(); 138 139 } catch ( Throwable t ){ 140 throw new JahiaException( "XMLPortlets", 141 "Exception " + t.getMessage(), 142 JahiaException.ERROR_SEVERITY, 143 JahiaException.SERVICE_ERROR); 144 } 145 146 147 Element newPlmlNode = (Element ) xmlDoc.createElement(PLML_TAG); 148 149 if ( newPlmlNode == null ){ 150 JahiaConsole.println("XMLPortlets constructor", "newPlmlNode is null"); 151 } 152 153 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 thePGID = new Integer (update_count("portletgroup")); 162 Element newPortletGroupNode = (Element ) xmlDoc.createElement(PORTLETLIST_TAG); 163 newPortletGroupNode.setAttribute(PARAMETER_TAG_ID_ATTRIBUTE, thePGID.toString()); 164 165 newPlmlNode.appendChild(newPortletGroupNode); 166 167 Integer thePID = new Integer (thePageID); 168 Element paramNode = (Element ) xmlDoc.createElement(PARAMETER_TAG); 169 paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "page_id"); 170 Text 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 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 } 207 208 209 210 private Document loadFile(String sourceFileName) 212 throws JahiaException { 213 214 Document xmlDoc = null; 215 216 try { 217 DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); 218 DocumentBuilder docBuilder = dfactory.newDocumentBuilder(); 220 222 FileInputStream sourceStream = new FileInputStream (sourceFileName); 223 xmlDoc = docBuilder.parse(sourceStream); 224 xmlDoc.normalize(); Element docEl = (Element )xmlDoc.getDocumentElement(); 226 227 } catch ( Throwable 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 private void saveFile(Document xmlDoc, String destinationFileName) 238 throws JahiaException { 239 240 try { 241 242 xmlDoc.normalize(); 244 TransformerFactory tfactory = TransformerFactory.newInstance(); 245 246 Transformer serializer = tfactory.newTransformer(); 249 250 serializer.setOutputProperty(OutputKeys.METHOD, "xml"); 251 serializer.setOutputProperty(OutputKeys.INDENT, "yes"); 252 FileOutputStream fileStream = new FileOutputStream (destinationFileName); 253 serializer.transform(new DOMSource (xmlDoc), 254 new StreamResult (fileStream)); 255 256 } catch ( Throwable t ){ 257 throw new JahiaException( "XMLPortlets", 258 "Exception " + t.getMessage(), 259 JahiaException.ERROR_SEVERITY, 260 JahiaException.SERVICE_ERROR); 261 } 262 263 } 264 265 266 271 public String getParameterValue(Node paramParent, String 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 curNode = paramParent.getFirstChild(); 279 while (curNode != null) { 280 if (curNode.getNodeType() == Node.ELEMENT_NODE) { 282 if (curNode.getNodeName().equalsIgnoreCase(PARAMETER_TAG)) { 283 NamedNodeMap attrib = curNode.getAttributes(); 285 Node paramAttrib = attrib.getNamedItem(PARAMETER_TAG_NAME_ATTRIBUTE); 286 if (paramAttrib != null) { 287 if (paramAttrib.getNodeValue().equalsIgnoreCase(parameterName)) { 288 Node 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 } 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 } 319 320 325 public String getAttributeValue(Node paramParent, String attributeName) throws JahiaException { 326 327 NamedNodeMap attrib = paramParent.getAttributes(); 328 Node paramAttrib = attrib.getNamedItem(attributeName); 329 return paramAttrib.getNodeValue(); 330 331 } 333 334 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 portletNode = portletgroupNode.getFirstChild(); 354 while (portletNode != null) { 355 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 357 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 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 } 381 382 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 portletNode = portletgroupNode.getFirstChild(); 402 while (portletNode != null) { 403 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 405 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 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 } 454 455 462 public Vector getPortletList() throws JahiaException { 463 464 thePortletList = new Vector (); 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 portletNode = portletgroupNode.getFirstChild(); 475 while (portletNode != null) { 476 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 478 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 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 } 521 522 523 530 public Vector getPortletListFromColumn(int theColumn) throws JahiaException { 531 532 thePortletList = new Vector (); 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 portletNode = portletgroupNode.getFirstChild(); 543 int RowSpace = 0; 544 int RowCounter = 1; 545 int MaxRow = 0; 546 while (portletNode != null) { 547 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 549 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 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 } 598 599 606 public void moveRightPortlet(int thePortletID) throws JahiaException { 607 608 portletgroupNode = plmlNode.getFirstChild(); 609 Node 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 portletNode = portletgroupNode.getFirstChild(); 616 int Column = 0; 617 while (portletNode != null) { 618 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 620 paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE); 622 if (paramAttrNode.equals(new Integer (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 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 635 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 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 647 paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE); 649 if (paramAttrNode.equals(new Integer (thePortletID).toString())) { 650 651 Node 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 (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 (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 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 } 703 704 711 public void moveLeftPortlet(int thePortletID) throws JahiaException { 712 713 portletgroupNode = plmlNode.getFirstChild(); 714 Node 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 portletNode = portletgroupNode.getFirstChild(); 721 int Column = 0; 722 while (portletNode != null) { 723 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 725 paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE); 727 if (paramAttrNode.equals(new Integer (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 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 741 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 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 753 paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE); 755 if (paramAttrNode.equals(new Integer (thePortletID).toString())) { 756 757 Node 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 (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 (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 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 } 808 809 816 public void moveBottomPortlet(int thePortletID) throws JahiaException { 817 818 portletgroupNode = plmlNode.getFirstChild(); 819 Node 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 portletNode = portletgroupNode.getFirstChild(); 826 int Column = 0; 827 int Row = 0; 828 int MaxRow = 0; 829 830 while (portletNode != null) { 831 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 833 paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE); 835 if (paramAttrNode.equals(new Integer (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 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 849 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 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 863 paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE); 865 if (paramAttrNode.equals(new Integer (thePortletID).toString())) { 866 Node 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 (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 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 895 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 (thePortletID).toString())) { 900 Node 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 (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 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 } 942 943 950 public void moveTopPortlet(int thePortletID) throws JahiaException { 951 952 portletgroupNode = plmlNode.getFirstChild(); 953 Node 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 portletNode = portletgroupNode.getFirstChild(); 960 int Column = 0; 961 int Row = 0; 962 while (portletNode != null) { 963 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 965 paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE); 967 if (paramAttrNode.equals(new Integer (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 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 (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 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 1000 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 (thePortletID).toString())) { 1005 Node 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 (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 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 } 1047 1048 1055 public void updatePortlet(PortletObj thePortlet) throws JahiaException { 1056 1057 portletgroupNode = plmlNode.getFirstChild(); 1058 Node 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 portletNode = portletgroupNode.getFirstChild(); 1065 while (portletNode != null) { 1066 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 1068 String theParam; 1070 paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE); 1071 if (paramAttrNode.equals(new Integer (thePortlet.getPortletID()).toString())) { 1072 Node 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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 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 } 1317 1318 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 portletNode = portletgroupNode.getFirstChild(); 1334 while (portletNode != null) { 1335 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 1337 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 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 } 1364 1365 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 portletNode = portletgroupNode.getFirstChild(); 1384 int MaxRow = 0; 1385 while (portletNode != null) { 1386 if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) { 1388 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 thePID = new Integer (update_count("portlet")); 1397 Element newPortletNode = (Element ) xmlDocument.createElement(PORTLET_TAG); 1398 1399 newPortletNode.setAttribute(PARAMETER_TAG_ID_ATTRIBUTE, thePID.toString()); 1400 portletgroupNode.appendChild(newPortletNode); 1401 1402 Element paramNode = (Element ) 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 ) 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 theSID = new Integer (theSourceID); 1415 paramNode = (Element ) 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 ) 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 ) 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 ) 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 ) 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 ) 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 ) 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 ) 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 ) 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 ) 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 ) 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 ) 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 ) 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 ) 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 ) 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 ) 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 ) 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 theMROW = new Integer (MaxRow + 1); 1518 paramNode = (Element ) 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 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 } 1546 1547 1554 public void addPortletGroup() throws JahiaException { 1555 1556 if (addPortletGroup) { return; } 1557 1558 Document defaultXmlDocument = null; 1559 Element theDefaultPlmlNode; 1560 Node defaultPortletGroupNode; 1561 plmlNode = getPlmlNode(); 1563 File theDefaultFile = new File (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 thePGID = new Integer (update_count("portletgroup")); 1570 Element newPortletGroupNode = (Element ) xmlDocument.createElement(PORTLETLIST_TAG); 1571 newPortletGroupNode.setAttribute(PARAMETER_TAG_ID_ATTRIBUTE, thePGID.toString()); 1572 plmlNode.appendChild(newPortletGroupNode); 1573 1574 Integer thePID = new Integer (thePageID); 1575 Element paramNode = (Element ) xmlDocument.createElement(PARAMETER_TAG); 1576 paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "page_id"); 1577 Text 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 DefaultDocElNode = (Element ) 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(); 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(); 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 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 thePGID = new Integer (update_count("portletgroup")); 1651 Element newPortletGroupNode = (Element ) xmlDocument.createElement(PORTLETLIST_TAG); 1652 newPortletGroupNode.setAttribute(PARAMETER_TAG_ID_ATTRIBUTE, thePGID.toString()); 1653 plmlNode.appendChild(newPortletGroupNode); 1654 1655 Integer thePID = new Integer (thePageID); 1656 Element paramNode = (Element ) xmlDocument.createElement(PARAMETER_TAG); 1657 paramNode.setAttribute(PARAMETER_TAG_NAME_ATTRIBUTE, "page_id"); 1658 Text 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 } 1670 1671 1678 public Vector copyXMLPortletGroup(String theNewXMLfile) throws JahiaException { 1679 1680 Element theNewPlmlNode = null; 1681 Node newPortletGroupNode = null; 1682 Document newXmlDocument = null; 1683 Vector sourceIDList = new Vector (); 1684 File theNewFile = new File (theNewXMLfile); 1685 1686 if (!theNewFile.exists()) { 1687 1688 try { 1689 1690 JahiaConsole.println("XMLPortlets.copyPortletGroup", "file doesn't exists"); 1691 1692 DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); 1693 DocumentBuilder docBuilder = dfactory.newDocumentBuilder(); 1695 Document 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 NewDocElNode = (Element ) newXmlDocument.getDocumentElement(); 1708 NewDocElNode.normalize(); 1709 1710 theNewPlmlNode = newXmlDocument.getDocumentElement(); 1711 1712 } catch (IOException 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 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 NewDocElNode = (Element ) 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(); 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(); 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 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 portletNode = portletgroupNode.getFirstChild(); 1799 1800 1801 1802 1811 while (portletNode != null) { 1812 if ((portletNode.getNodeType() == Node.ELEMENT_NODE) && 1814 (portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG))) 1815 { 1816 sourceIDList.addElement (new Integer (getParameterValue (portletNode, "source_id"))); 1818 } 1819 portletNode = portletNode.getNextSibling (); 1820 } 1821 1822 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 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 } 1847 1848 1855 public Node 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 psmlNode = xmlDocument.getDocumentElement(); 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 portletgroupNode = psmlNode.getFirstChild(); 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 } 1897 1898 1905 public Node 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 plmlNode = xmlDocument.getDocumentElement(); 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 } 1935 1936 1937 1944 public int update_count(String 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 se ) { 1958 String 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 } 1971} 1972 | Popular Tags |