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);
String[] allowedComponentNamesArray = null;
int allowedComponentNamesIndex = slot.indexOf(" allowedComponentNames");
if(allowedComponentNamesIndex > -1)
{
String allowedComponentNames = slot.substring(allowedComponentNamesIndex + 24, slot.indexOf("\"", allowedComponentNamesIndex + 24));
allowedComponentNamesArray = allowedComponentNames.split(",");
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(",");
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));
}
if(addComponentLinkHTML == null || addComponentLinkHTML.equals(""))
{
Locale locale = templateController.getLocaleAvailableInTool(templateController.getPrincipal());
addComponentLinkHTML = getLocalizedString(locale, "deliver.editOnSight.slotInstructionHTML", slotBean.getId(), slotBean.getDisplayName());
}
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 = "";
if(!disableSlotDecoration)
{
if(component.getIsInherited())
subComponentString += "<div id=\"" + component.getId() + "_" + id + "\" class=\"inheritedComponentDiv\");\">";
else
{
subComponentString += "<div id=\"" + component.getId() + "_" + id + "\" class=\"componentDiv slotPosition\">";
subComponentString += "\n<script type=\"text/javascript\">\n";
subComponentString += " $(document).ready(function() {";
subComponentString += " var element = document.getElementById(\"" + component.getId() + "_" + id + "\");\n";
subComponentString += " if (document.addEventListener != null)\n";
subComponentString += " element.addEventListener('mouseup', function (event){if(!$('#" + component.getId() + "_" + id + "').hasClass(\"slotPosition\")) { return;} assignComponent(event, '" + siteNodeId + "', '" + languageId + "', '" + contentId + "', '" + component.getId() + "', '" + id + "', '" + false + "', '" + slotBean.getAllowedComponentsArrayAsUrlEncodedString() + "', '" + slotBean.getDisallowedComponentsArrayAsUrlEncodedString() + "', '" + slotBean.getAllowedComponentGroupsArrayAsUrlEncodedString() + "', '');}, false);\n";
subComponentString += " else{\n";
subComponentString += " element.attachEvent(\"onmouseup\", function (evt){if(!$('#" + component.getId() + "_" + id + "').hasClass(\"slotPosition\")) { return;} assignComponent(evt, '" + siteNodeId + "', '" + languageId + "', '" + contentId + "', '" + component.getId() + "', '" + id + "', '" + false + "', '" + slotBean.getAllowedComponentsArrayAsUrlEncodedString() + "', '" + slotBean.getDisallowedComponentsArrayAsUrlEncodedString() + "', '" + slotBean.getAllowedComponentGroupsArrayAsUrlEncodedString() + "', '');\n";
subComponentString += " });";
subComponentString += " }\n";
subComponentString += " });\n";
subComponentString += "</script>\n";
}
}
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 && !CmsPropertyHandler.getAnonymousUser().equalsIgnoreCase(cmsUserName))
principal = templateController.getPrincipal(cmsUserName);
String clickToAddHTML = "";
boolean hasAccessToAddComponent = AccessRightController.getController().getIsPrincipalAuthorized(templateController.getDatabase(), principal, "ComponentEditor.AddComponent", "" + component.getContentId() + "_" + id);
if(slotBean.getDisableAccessControl())
hasAccessToAddComponent = true;
boolean hasMaxComponents = false;
//logger.info("Checking for max components on: " + id);
if(component.getSlotList() != null)
{
Iterator slotListIterator = component.getSlotList().iterator();
while(slotListIterator.hasNext())
{
Slot parentSlot = (Slot)slotListIterator.next();
if(parentSlot.getId().equalsIgnoreCase(id))
{
//logger.info("parentSlot.getAllowedNumberOfComponents(): " + parentSlot.getAllowedNumberOfComponents());
//logger.info("parentSlot.getComponents().size(): " + parentSlot.getComponents().size());
if(parentSlot.getAllowedNumberOfComponents() != -1 && parentSlot.getComponents().size() >= parentSlot.getAllowedNumberOfComponents())
hasMaxComponents = true;
}
}
}
if(hasAccessToAddComponent && !hasMaxComponents)
{
if(slotBean.getAddComponentText() != null)
{
clickToAddHTML = slotBean.getAddComponentText();
//logger.info("Fick:" + clickToAddHTML);
}
else
{
Locale locale = templateController.getLocaleAvailableInTool(principal);
clickToAddHTML = getLocalizedString(locale, "deliver.editOnSight.slotInstructionHTML", slotBean.getId(), slotBean.getDisplayName());
//logger.info("Fack:" + clickToAddHTML + locale);
}
}
else
{
addComponentLinkHTML = "";
clickToAddHTML = "";
}
//logger.info("addComponentLinkHTML:" + addComponentLinkHTML);
//logger.info("clickToAddHTML:" + clickToAddHTML);
//logger.info("hasMaxComponents:" + hasMaxComponents);
//logger.info("subComponents for " + id + ":" + subComponents);
if(subComponents != null && subComponents.size() > 0)
{
//logger.info("SUBCOMPONENTS:" + subComponents.size());
int index = 0;
Iterator subComponentsIterator = subComponents.iterator();
while(subComponentsIterator.hasNext())
{
InfoGlueComponent subComponent = (InfoGlueComponent)subComponentsIterator.next();
if(subComponent != null)
{
component.getComponents().put(subComponent.getSlotName(), subComponent);
if(subComponent.getIsInherited() && subComponent.getPagePartTemplateComponent() == null)
{
//logger.info("Inherited..." + contentId);
String childComponentsString = decorateComponent(subComponent, templateController, repositoryId, siteNodeId, languageId, contentId/*, metainfoContentId*/, maxDepth, currentDepth + 1);
if(!this.getTemplateController().getDeliveryContext().getShowSimple()/* && !disableSlotDecoration */)
subComponentString += "<a id=\"" + index + "Comp\" name=\"" + index + "Comp\"></a><span id=\""+ id + index + "Comp\" class=\"inheritedslot\">" + childComponentsString + "</span>";
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);
}
}
if(subComponent.getPagePartTemplateComponent() != null)
{
subComponent.setComponentDivId("" + id + index + "_" + subComponent.getPagePartTemplateComponent().getId() + "Comp");
subComponentString += "<a id=\"" + subComponent.getPagePartTemplateComponent().getId() + "Comp\" name=\"" + subComponent.getPagePartTemplateComponent().getId() + "Comp\"></a><span class=\"dragableComponent slotPosition\" id=\"" + id + index + "_" + subComponent.getPagePartTemplateComponent().getId() + "Comp\">" + childComponentsString + "<script type=\"text/javascript\">initializeComponentEventHandler('" + id + index + "_" + subComponent.getPagePartTemplateComponent().getId() + "Comp', '" + subComponent.getPagePartTemplateComponent().getId() + "', '" + id + "', " + templateController.getSiteNode().getRepositoryId() + ", " + templateController.getSiteNodeId() + ", " + templateController.getLanguageId() + ", " + templateController.getContentId() + ", " + subComponent.getPagePartTemplateComponent().getId() + ", " + subComponent.getPagePartTemplateComponent().getContentId() + ", '" + URLEncoder.encode(templateController.getOriginalFullURL(), "UTF-8") + "');</script></span>";
}
else
{
subComponent.setComponentDivId("" + id + index + "_" + subComponent.getId() + "Comp");
subComponentString += "<a id=\"" + subComponent.getId() + "Comp\" name=\"" + subComponent.getId() + "Comp\"></a><span class=\"dragableComponent slotPosition\" id=\"" + id + index + "_" + subComponent.getId() + "Comp\">" + childComponentsString + "<script type=\"text/javascript\">initializeComponentEventHandler('" + id + index + "_" + subComponent.getId() + "Comp', '" + subComponent.getId() + "', '" + id + "', " + templateController.getSiteNode().getRepositoryId() + ", " + templateController.getSiteNodeId() + ", " + templateController.getLanguageId() + ", " + templateController.getContentId() + ", " + subComponent.getId() + ", " + subComponent.getContentId() + ", '" + URLEncoder.encode(templateController.getOriginalFullURL(), "UTF-8") + "'); " + "registerOnMouseUp('" + id + index + "_" + subComponent.getId() + "Comp', " + templateController.getSiteNodeId() + ", " + templateController.getLanguageId() + ", " + templateController.getContentId() + ", '" + component.getId() + "', '" + id + "', false, '" + allowedComponentNamesAsEncodedString + "', '" + disallowedComponentNamesAsEncodedString + "','" + allowedComponentGroupNamesAsEncodedString + "', " + subComponent.getId() + ");</script></span>";
}
}
else
{
subComponentString += childComponentsString;
}
if(subComponent.getPagePartTemplateComponent() != null)
{
Document componentPropertiesDocument = getComponentPropertiesDOM4JDocument(templateController, siteNodeId, languageId, subComponent.getPagePartTemplateComponent().getContentId());
//this.propertiesDivs += getComponentPropertiesDiv(templateController, repositoryId, siteNodeId, languageId, contentId, subComponent.getPagePartTemplateComponent().getId(), subComponent.getPagePartTemplateComponent().getContentId(), componentPropertiesDocument, subComponent.getPagePartTemplateComponent());
Document componentTasksDocument = getComponentTasksDOM4JDocument(templateController, siteNodeId, languageId, subComponent.getPagePartTemplateComponent().getContentId());
//this.tasksDivs += getComponentTasksDiv(repositoryId, siteNodeId, languageId, contentId, subComponent.getPagePartTemplateComponent(), index, subComponents.size() - 1, componentTasksDocument, templateController);
}
else
{
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() && !hasMaxComponents && !disableSlotDecoration)
{
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 : "");
//logger.info("clickToAddHTML 1:" + component.getContainerSlot().getAddComponentLinkHTML().replaceAll("\\$linkUrl", linkUrl));
subComponentString += "" + component.getContainerSlot().getAddComponentLinkHTML().replaceAll("\\$linkUrl", linkUrl);
}
else if(!component.getIsInherited() && !hasMaxComponents && !disableSlotDecoration)
{
//logger.info("clickToAddHTML 2:" + clickToAddHTML);
subComponentString += "" + clickToAddHTML;
}
}
else
{
if(component.getContainerSlot().getAddComponentLinkHTML() != null && !component.getIsInherited() && !hasMaxComponents && !disableSlotDecoration)
{
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?BBB=1&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 : "");
//logger.info("clickToAddHTML 3:" + component.getContainerSlot().getAddComponentLinkHTML().replaceAll("\\$linkUrl", linkUrl));
subComponentString += "" + component.getContainerSlot().getAddComponentLinkHTML().replaceAll("\\$linkUrl", linkUrl);
}
else if(!component.getIsInherited() && !hasMaxComponents && !disableSlotDecoration)
{
//logger.info("clickToAddHTML 4:" + clickToAddHTML);
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\">initializeSlotEventHandler('" + component.getId() + "_" + id + "', '" + id + "', '" + component.getContentId() + "', " + templateController.getSiteNode().getRepositoryId() + ", " + templateController.getSiteNodeId() + ", " + templateController.getLanguageId() + ", " + templateController.getContentId() + ", " + component.getId() + ", " + component.getContentId() + ", '" + URLEncoder.encode(templateController.getOriginalFullURL(), "UTF-8") + "');</script></div>";
}