int slotStopIndex = componentString.indexOf("</ig:slot>", slotStartIndex);
String slot = componentString.substring(slotStartIndex, slotStopIndex + 10);
String id = slot.substring(slot.indexOf("id") + 4, slot.indexOf("\"", slot.indexOf("id") + 4));
Slot slotBean = new Slot();
slotBean.setId(id);
int displayNameIndex = slot.indexOf(" displayName");
if(displayNameIndex > -1)
{
String displayName = slot.substring(displayNameIndex + 14, slot.indexOf("\"", displayNameIndex + 14));
slotBean.setDisplayName(displayName);
}
String[] allowedComponentNamesArray = null;
int allowedComponentNamesIndex = slot.indexOf(" allowedComponentNames");
if(allowedComponentNamesIndex > -1)
{
String allowedComponentNames = slot.substring(allowedComponentNamesIndex + 24, slot.indexOf("\"", allowedComponentNamesIndex + 24));
allowedComponentNamesArray = allowedComponentNames.split(",");
//logger.info("allowedComponentNamesArray:" + allowedComponentNamesArray.length);
slotBean.setAllowedComponentsArray(allowedComponentNamesArray);
}
String[] disallowedComponentNamesArray = null;
int disallowedComponentNamesIndex = slot.indexOf(" disallowedComponentNames");
if(disallowedComponentNamesIndex > -1)
{
String disallowedComponentNames = slot.substring(disallowedComponentNamesIndex + 27, slot.indexOf("\"", disallowedComponentNamesIndex + 27));
disallowedComponentNamesArray = disallowedComponentNames.split(",");
//logger.info("disallowedComponentNamesArray:" + disallowedComponentNamesArray.length);
slotBean.setDisallowedComponentsArray(disallowedComponentNamesArray);
}
String[] allowedComponentGroupNamesArray = null;
int allowedComponentGroupNamesIndex = slot.indexOf(" allowedComponentGroupNames");
if(allowedComponentGroupNamesIndex > -1)
{
String allowedComponentGroupNames = slot.substring(allowedComponentGroupNamesIndex + 29, slot.indexOf("\"", allowedComponentGroupNamesIndex + 29));
allowedComponentGroupNamesArray = allowedComponentGroupNames.split(",");
slotBean.setAllowedComponentGroupsArray(allowedComponentGroupNamesArray);
}
boolean inherit = true;
int inheritIndex = slot.indexOf("inherit");
if(inheritIndex > -1)
{
String inheritString = slot.substring(inheritIndex + 9, slot.indexOf("\"", inheritIndex + 9));
inherit = Boolean.parseBoolean(inheritString);
}
slotBean.setInherit(inherit);
boolean disableAccessControl = false;
int disableAccessControlIndex = slot.indexOf("disableAccessControl");
if(disableAccessControlIndex > -1)
{
String disableAccessControlString = slot.substring(disableAccessControlIndex + "disableAccessControl".length() + 2, slot.indexOf("\"", disableAccessControlIndex + "disableAccessControl".length() + 2));
disableAccessControl = Boolean.parseBoolean(disableAccessControlString);
}
String addComponentText = null;
int addComponentTextIndex = slot.indexOf("addComponentText");
if(addComponentTextIndex > -1)
{
addComponentText = slot.substring(addComponentTextIndex + "addComponentText".length() + 2, slot.indexOf("\"", addComponentTextIndex + "addComponentText".length() + 2));
}
String addComponentLinkHTML = null;
int addComponentLinkHTMLIndex = slot.indexOf("addComponentLinkHTML");
if(addComponentLinkHTMLIndex > -1)
{
addComponentLinkHTML = slot.substring(addComponentLinkHTMLIndex + "addComponentLinkHTML".length() + 2, slot.indexOf("\"", addComponentLinkHTMLIndex + "addComponentLinkHTML".length() + 2));
}
int allowedNumberOfComponentsInt = -1;
int allowedNumberOfComponentsIndex = slot.indexOf("allowedNumberOfComponents");
if(allowedNumberOfComponentsIndex > -1)
{
String allowedNumberOfComponents = slot.substring(allowedNumberOfComponentsIndex + "allowedNumberOfComponents".length() + 2, slot.indexOf("\"", allowedNumberOfComponentsIndex + "allowedNumberOfComponents".length() + 2));
try
{
allowedNumberOfComponentsInt = new Integer(allowedNumberOfComponents);
}
catch (Exception e)
{
allowedNumberOfComponentsInt = -1;
}
}
int disableSlotDecorationIndex = slot.indexOf("disableSlotDecoration");
Boolean disableSlotDecoration = false;
if(disableSlotDecorationIndex > -1)
{
String disableSlotDecorationString = slot.substring(disableSlotDecorationIndex + "disableSlotDecoration".length() + 2, slot.indexOf("\"", disableSlotDecorationIndex + "disableSlotDecoration".length() + 2));
if(disableSlotDecorationString.equalsIgnoreCase("true"))
disableSlotDecoration = true;
}
slotBean.setDisableAccessControl(disableAccessControl);
slotBean.setAddComponentLinkHTML(addComponentLinkHTML);
slotBean.setAddComponentText(addComponentText);
slotBean.setAllowedNumberOfComponents(new Integer(allowedNumberOfComponentsInt));
component.setContainerSlot(slotBean);
String subComponentString = "";
//TODO - test
if(component.getIsInherited() && !disableSlotDecoration)
subComponentString += "<div id=\"Comp" + component.getId() + "_" + id + "\" class=\"inheritedComponentDiv\");\">";
else if(!disableSlotDecoration)
subComponentString += "<div id=\"Comp" + component.getId() + "_" + id + "\" class=\"componentDiv " + slotBean.getLimitationClasses() + "\" onmouseup=\"javascript:assignComponent('" + siteNodeId + "', '" + languageId + "', '" + contentId + "', '" + component.getId() + "', '" + id + "', '" + false + "', '" + slotBean.getAllowedComponentsArrayAsUrlEncodedString() + "', '" + slotBean.getDisallowedComponentsArrayAsUrlEncodedString() + "', '" + slotBean.getAllowedComponentGroupsArrayAsUrlEncodedString() + "', '');\">";
List subComponents = getInheritedComponents(getDatabase(), templateController, component, templateController.getSiteNodeId(), id, inherit);
InfoGluePrincipal principal = templateController.getPrincipal();
String cmsUserName = (String)templateController.getHttpServletRequest().getSession().getAttribute("cmsUserName");
if(cmsUserName != null)
{
InfoGluePrincipal newPrincipal = templateController.getPrincipal(cmsUserName);
if(newPrincipal != null)
principal = newPrincipal;
}
String clickToAddHTML = "";
boolean hasAccessToAddComponent = AccessRightController.getController().getIsPrincipalAuthorized(templateController.getDatabase(), principal, "ComponentEditor.AddComponent", "" + component.getContentId() + "_" + id);
if(slotBean.getDisableAccessControl())
hasAccessToAddComponent = true;
boolean hasMaxComponents = false;
if(component.getSlotList() != null)
{
Iterator slotListIterator = component.getSlotList().iterator();
while(slotListIterator.hasNext())
{
Slot parentSlot = (Slot)slotListIterator.next();
if(parentSlot.getId().equalsIgnoreCase(id))
{
if(parentSlot.getAllowedNumberOfComponents() != -1 && parentSlot.getComponents().size() >= parentSlot.getAllowedNumberOfComponents())
hasMaxComponents = true;
}
}
}
if(hasAccessToAddComponent && !hasMaxComponents)
{
if(slotBean.getAddComponentText() != null)
{
clickToAddHTML = slotBean.getAddComponentText();
}
else
{
Locale locale = templateController.getLocaleAvailableInTool(principal);
clickToAddHTML = getLocalizedString(locale, "deliver.editOnSight.slotInstructionHTML", slotBean.getId(), slotBean.getDisplayName());
}
}
//logger.info("subComponents for " + id + ":" + subComponents);
if(subComponents != null && subComponents.size() > 0)
{
//logger.info("SUBCOMPONENTS:" + subComponents.size());
int index = 0;
List<Integer> handledComponents = new ArrayList<Integer>();
Iterator subComponentsIterator = subComponents.iterator();
while(subComponentsIterator.hasNext())
{
InfoGlueComponent subComponent = (InfoGlueComponent)subComponentsIterator.next();
if(subComponent != null)
{
if(handledComponents.contains(subComponent.getId()))
continue;
handledComponents.add(subComponent.getId());
component.getComponents().put(subComponent.getSlotName(), subComponent);
if(subComponent.getIsInherited())
{
//logger.info("Inherited..." + contentId);
String childComponentsString = decorateComponent(subComponent, templateController, repositoryId, siteNodeId, languageId, contentId/*, metainfoContentId*/, maxDepth, currentDepth + 1);
if(!this.getTemplateController().getDeliveryContext().getShowSimple() && !disableSlotDecoration)
subComponentString += "<div style=\"display:inline;\" id=\""+ id + index + "Comp\" class=\"inheritedslot\">" + childComponentsString + "</div>";
else
subComponentString += childComponentsString;
Document componentPropertiesDocument = getComponentPropertiesDOM4JDocument(templateController, siteNodeId, languageId, component.getContentId());
this.propertiesDivs += getComponentPropertiesDiv(templateController, repositoryId, siteNodeId, languageId, contentId, new Integer(siteNodeId.intValue()*100 + subComponent.getId().intValue()), subComponent.getContentId(), componentPropertiesDocument, subComponent);
Document componentTasksDocument = getComponentTasksDOM4JDocument(templateController, siteNodeId, languageId, subComponent.getContentId());
this.tasksDivs += getComponentTasksDiv(repositoryId, siteNodeId, languageId, contentId, subComponent, index, subComponents.size() - 1, componentTasksDocument, templateController);
}
else
{
//logger.info("Not inherited..." + contentId);
String childComponentsString = decorateComponent(subComponent, templateController, repositoryId, siteNodeId, languageId, contentId/*, metainfoContentId*/, maxDepth, currentDepth + 1);
//logger.info("childComponentsString:" + childComponentsString);
if(!this.getTemplateController().getDeliveryContext().getShowSimple() && !disableSlotDecoration)
{
String allowedComponentNamesAsEncodedString = null;
String disallowedComponentNamesAsEncodedString = null;
String allowedComponentGroupNamesAsEncodedString = null;
for(int i=0; i < subComponent.getParentComponent().getSlotList().size(); i++)
{
Slot subSlotBean = (Slot)subComponent.getParentComponent().getSlotList().get(i);
if(subSlotBean.getId() != null && subSlotBean.getId().equals(subComponent.getSlotName()))
{
allowedComponentNamesAsEncodedString = subSlotBean.getAllowedComponentsArrayAsUrlEncodedString();
disallowedComponentNamesAsEncodedString = subSlotBean.getDisallowedComponentsArrayAsUrlEncodedString();
allowedComponentGroupNamesAsEncodedString = subSlotBean.getAllowedComponentGroupsArrayAsUrlEncodedString();
subComponent.setContainerSlot(subSlotBean);
}
}
//<div id=\"dropZone"+ id + index + "_" + subComponent.getId() + "Comp\" class=\"moveDropZone\"></div>
String changeUrl = componentEditorUrl + "ViewSiteNodePageComponents!listComponentsForChange.action?siteNodeId=" + siteNodeId + "&languageId=" + languageId + "&contentId=" + (contentId == null ? "-1" : contentId) + "&componentId=" + subComponent.getId() + "&slotId=" + id + "&showSimple=" + this.getTemplateController().getDeliveryContext().getShowSimple() + ((allowedComponentNamesAsEncodedString != null) ? "&" + allowedComponentNamesAsEncodedString : "") + ((disallowedComponentNamesAsEncodedString != null) ? "&" + disallowedComponentNamesAsEncodedString : "") + ((allowedComponentGroupNamesAsEncodedString != null) ? "&" + allowedComponentGroupNamesAsEncodedString : "");
String extraClass = "clearFix";
if(childComponentsString.contains("noclearfix"))
extraClass = "clearFixNoBreak";
subComponentString += "<div style=\"position: relative;\" style=\"display:inline;\" id=\""+ id + index + "_" + subComponent.getId() + "Comp\" class=\"moveZone sortableComponent " + extraClass + "\">" + childComponentsString + "<script type=\"text/javascript\">initializeComponentEventHandler('" + id + index + "_" + subComponent.getId() + "Comp', '" + subComponent.getId() + "', '" + componentEditorUrl + "ViewSiteNodePageComponents!listComponents.action?siteNodeId=" + siteNodeId + "&languageId=" + languageId + "&contentId=" + (contentId == null ? "-1" : contentId) + "&parentComponentId=" + component.getId() + "&slotId=" + id + "&showSimple=" + this.getTemplateController().getDeliveryContext().getShowSimple() + ((allowedComponentNamesAsEncodedString != null) ? "&" + allowedComponentNamesAsEncodedString : "") + ((disallowedComponentNamesAsEncodedString != null) ? "&" + disallowedComponentNamesAsEncodedString : "") + ((allowedComponentGroupNamesAsEncodedString != null) ? "&" + allowedComponentGroupNamesAsEncodedString : "") + "', '" + componentEditorUrl + "ViewSiteNodePageComponents!deleteComponent.action?siteNodeId=" + siteNodeId + "&languageId=" + languageId + "&contentId=" + contentId + "&componentId=" + subComponent.getId() + "&slotId=" + id + "&showSimple=" + this.getTemplateController().getDeliveryContext().getShowSimple() + "','" + changeUrl + "');</script></div>";
}
else
{
subComponentString += childComponentsString;
}
Document componentPropertiesDocument = getComponentPropertiesDOM4JDocument(templateController, siteNodeId, languageId, subComponent.getContentId());
this.propertiesDivs += getComponentPropertiesDiv(templateController, repositoryId, siteNodeId, languageId, contentId, subComponent.getId(), subComponent.getContentId(), componentPropertiesDocument, subComponent);
Document componentTasksDocument = getComponentTasksDOM4JDocument(templateController, siteNodeId, languageId, subComponent.getContentId());
this.tasksDivs += getComponentTasksDiv(repositoryId, siteNodeId, languageId, contentId, subComponent, index, subComponents.size() - 1, componentTasksDocument, templateController);
}
}
index++;
}
if(component.getContainerSlot().getAddComponentLinkHTML() != null && !component.getIsInherited())
{
String allowedComponentNamesAsEncodedString = null;
String disallowedComponentNamesAsEncodedString = null;
String allowedComponentGroupNamesAsEncodedString = null;
for(int i=0; i < component.getSlotList().size(); i++)
{
Slot subSlotBean = (Slot)component.getSlotList().get(i);
if(subSlotBean.getId() != null && subSlotBean.getId().equals(id))
{
allowedComponentNamesAsEncodedString = subSlotBean.getAllowedComponentsArrayAsUrlEncodedString();
disallowedComponentNamesAsEncodedString = subSlotBean.getDisallowedComponentsArrayAsUrlEncodedString();
allowedComponentGroupNamesAsEncodedString = subSlotBean.getAllowedComponentGroupsArrayAsUrlEncodedString();
}
}
String linkUrl = componentEditorUrl + "ViewSiteNodePageComponents!listComponents.action?siteNodeId=" + siteNodeId + "&languageId=" + languageId + "&contentId=" + (contentId == null ? "-1" : contentId) + "&parentComponentId=" + component.getId() + "&slotId=" + id + "&showSimple=" + this.getTemplateController().getDeliveryContext().getShowSimple() + ((allowedComponentNamesAsEncodedString != null) ? "&" + allowedComponentNamesAsEncodedString : "") + ((disallowedComponentNamesAsEncodedString != null) ? "&" + disallowedComponentNamesAsEncodedString : "") + ((allowedComponentGroupNamesAsEncodedString != null) ? "&" + allowedComponentGroupNamesAsEncodedString : "");
subComponentString += "" + component.getContainerSlot().getAddComponentLinkHTML().replaceAll("\\$linkUrl", linkUrl);
}
else
{
subComponentString += "" + clickToAddHTML;
}
}
else
{
if(component.getContainerSlot().getAddComponentLinkHTML() != null && !component.getIsInherited())
{
String allowedComponentNamesAsEncodedString = null;
String disallowedComponentNamesAsEncodedString = null;
String allowedComponentGroupNamesAsEncodedString = null;
for(int i=0; i < component.getSlotList().size(); i++)
{
Slot subSlotBean = (Slot)component.getSlotList().get(i);
if(subSlotBean.getId() != null && subSlotBean.getId().equals(id))
{
allowedComponentNamesAsEncodedString = subSlotBean.getAllowedComponentsArrayAsUrlEncodedString();
disallowedComponentNamesAsEncodedString = subSlotBean.getDisallowedComponentsArrayAsUrlEncodedString();
allowedComponentGroupNamesAsEncodedString = subSlotBean.getAllowedComponentGroupsArrayAsUrlEncodedString();
}
}
String linkUrl = componentEditorUrl + "ViewSiteNodePageComponents!listComponents.action?siteNodeId=" + siteNodeId + "&languageId=" + languageId + "&contentId=" + (contentId == null ? "-1" : contentId) + "&parentComponentId=" + component.getId() + "&slotId=" + id + "&showSimple=" + this.getTemplateController().getDeliveryContext().getShowSimple() + ((allowedComponentNamesAsEncodedString != null) ? "&" + allowedComponentNamesAsEncodedString : "") + ((disallowedComponentNamesAsEncodedString != null) ? "&" + disallowedComponentNamesAsEncodedString : "") + ((allowedComponentGroupNamesAsEncodedString != null) ? "&" + allowedComponentGroupNamesAsEncodedString : "");
subComponentString += "" + component.getContainerSlot().getAddComponentLinkHTML().replaceAll("\\$linkUrl", linkUrl);
}
else
{
subComponentString += "" + clickToAddHTML;
}
}
if(!disableSlotDecoration)
{
if(!component.getIsInherited())
{
String allowedComponentNamesAsEncodedString = null;
String disallowedComponentNamesAsEncodedString = null;
String allowedComponentGroupNamesAsEncodedString = null;
for(int i=0; i < component.getSlotList().size(); i++)
{
Slot subSlotBean = (Slot)component.getSlotList().get(i);
if(subSlotBean.getId() != null && subSlotBean.getId().equals(id))
{
allowedComponentNamesAsEncodedString = subSlotBean.getAllowedComponentsArrayAsUrlEncodedString();
disallowedComponentNamesAsEncodedString = subSlotBean.getDisallowedComponentsArrayAsUrlEncodedString();
allowedComponentGroupNamesAsEncodedString = subSlotBean.getAllowedComponentGroupsArrayAsUrlEncodedString();
}
}
subComponentString += "<script type=\"text/javascript\">setTimeout(function() {initializeSlotEventHandler('Comp" + component.getId() + "_" + id + "', '" + componentEditorUrl + "ViewSiteNodePageComponents!listComponents.action?siteNodeId=" + siteNodeId + "&languageId=" + languageId + "&contentId=" + (contentId == null ? "-1" : contentId) + "&parentComponentId=" + component.getId() + "&slotId=" + id + "&showSimple=" + this.getTemplateController().getDeliveryContext().getShowSimple() + ((allowedComponentNamesAsEncodedString != null) ? "&" + allowedComponentNamesAsEncodedString : "") + ((disallowedComponentNamesAsEncodedString != null) ? "&" + disallowedComponentNamesAsEncodedString : "") + ((allowedComponentGroupNamesAsEncodedString != null) ? "&" + allowedComponentGroupNamesAsEncodedString : "") + "', '', '', '" + id + "', '" + component.getContentId() + "'); }, 100);</script></div>";
}