String contentString = new String(contentByte);
//Check for previous deployment in pageregistry.xml
String prev = "fragment name=\"" + name;
if (contentString.lastIndexOf(prev) != -1){
String errMsg = "Portlet '" + name + "' already exists in pageregistry.xml";
PlutoAdminException e = new PlutoAdminException(errMsg);
logError(METHOD_NAME, errMsg, e);
throw e;//throw exception here
}
//start before close of root element
long pos = contentString.lastIndexOf("</portal>");
ras.seek(pos);
//start page fragment
ras.writeBytes(" <fragment name=\"" + name + "\" type=\"page\" >" + PlutoAdminConstants.LS);
ras.writeBytes(" <navigation>" + PlutoAdminConstants.LS);
ras.writeBytes(" <title>" + page.getTitle());
ras.writeBytes("</title>" + PlutoAdminConstants.LS);
ras.writeBytes(" <description>" + page.getDescription());
ras.writeBytes("</description>" + PlutoAdminConstants.LS);
ras.writeBytes(" </navigation>" + PlutoAdminConstants.LS);
//iterate through portlets
List portlets = page.getPortlets();
//Sort list using Comparable implementation in PortletTO. This makes sure
// the items in the list are ordered by rows
Collections.sort(portlets);
Iterator iter = portlets.iterator();
int count = 0;
int currRow = 0;
int lastRow = 0;
int currCol = 0;
while (iter.hasNext()) {
count++;
PortletTO portlet = (PortletTO)iter.next();
logDebug(METHOD_NAME, "Portlet: " + portlet);
currRow = portlet.getRow();
currCol = portlet.getCol();
//start row fragment
// Add row fragment when row changes
if (currRow != lastRow) {
ras.writeBytes(" <fragment name=\"row" + currRow + "\" type=\"row\">" + PlutoAdminConstants.LS);
ras.writeBytes(" <fragment name=\"col" + count + "\" type=\"column\">" + PlutoAdminConstants.LS);
}
ras.writeBytes(" <fragment name=\"p" + count + "\" type=\"portlet\">" + PlutoAdminConstants.LS);
ras.writeBytes(" <property name=\"portlet\" value=\"" + portlet.getValue() + "\"/>" + PlutoAdminConstants.LS);
ras.writeBytes(" </fragment><!-- end of portlet frag -->" + PlutoAdminConstants.LS);
//end row fragment
if (cols == currCol) {
ras.writeBytes(" </fragment><!-- end of col frag -->" + PlutoAdminConstants.LS);
//end of column iteration
ras.writeBytes(" </fragment><!-- end of row frag -->" + PlutoAdminConstants.LS);
}
lastRow = currRow;
}
//end page fragment
ras.writeBytes(" </fragment><!-- end of 'page' frag -->" + PlutoAdminConstants.LS);
//add a couple of newlines to separate records
ras.writeBytes(PlutoAdminConstants.LS);
ras.writeBytes(PlutoAdminConstants.LS);
//replace closing root element
ras.writeBytes("</portal>" + PlutoAdminConstants.LS);
} catch (IOException e) {
logError(METHOD_NAME, e);
throw new PlutoAdminException(e);
} finally {
if (ras != null) {
try {
ras.close();
} catch (IOException e) {