protected Map getComponentsWithXPP3(Database db, XmlElement element, TemplateController templateController, InfoGlueComponent parentComponent) throws Exception
{
//logger.info("Getting components");
InfoGlueComponent component = null;
Locale locale = LanguageDeliveryController.getLanguageDeliveryController().getLocaleWithId(db, templateController.getLanguageId());
Map components = new HashMap();
String componentXPath = "component";
Xb1XPath xpathObject = (Xb1XPath)cachedXPathObjects.get(componentXPath);
if(xpathObject == null)
{
xpathObject = new Xb1XPath(componentXPath);
cachedXPathObjects.put(componentXPath, xpathObject);
}
List componentNodeList = xpathObject.selectNodes( element );
Iterator componentNodeListIterator = componentNodeList.iterator();
while(componentNodeListIterator.hasNext())
{
XmlElement child = (XmlElement)componentNodeListIterator.next();
Integer id = new Integer(child.getAttributeValue(child.getNamespaceName(), "id"));
Integer contentId = new Integer(child.getAttributeValue(child.getNamespaceName(), "contentId"));
String name = child.getAttributeValue(child.getNamespaceName(), "name");
String isPagePartRef = child.getAttributeValue(child.getNamespaceName(), "isPagePartReference");
//logger.info("id 2:" + id);
//logger.info("contentId 2:" + contentId);
//logger.info("name 2:" + name);
ContentVO contentVO = ContentDeliveryController.getContentDeliveryController().getContentVO(db, contentId, templateController.getDeliveryContext());
component = new InfoGlueComponent();
component.setId(id);
component.setContentId(contentId);
component.setName(contentVO.getName());
//component.setName(name);
component.setSlotName(name);
component.setParentComponent(parentComponent);
if(parentComponent != null)
component.setIsInherited(parentComponent.getIsInherited());
Xb1XPath xpathObject2 = (Xb1XPath)cachedXPathObjects.get("properties");
if(xpathObject2 == null)
{
xpathObject2 = new Xb1XPath("properties");
cachedXPathObjects.put("properties", xpathObject2);
}
List propertiesNodeList = xpathObject2.selectNodes( child );
if(propertiesNodeList.size() > 0)
{
XmlElement propertiesElement = (XmlElement)propertiesNodeList.get(0);
Xb1XPath xpathObject3 = (Xb1XPath)cachedXPathObjects.get("property");
if(xpathObject3 == null)
{
xpathObject3 = new Xb1XPath("property");
cachedXPathObjects.put("property", xpathObject3);
}
List propertyNodeList = xpathObject3.selectNodes(propertiesElement);
//logger.info("propertyNodeList:" + propertyNodeList.getLength());
Iterator propertyNodeListIterator = propertyNodeList.iterator();
while(propertyNodeListIterator.hasNext())
{
XmlElement propertyElement = (XmlElement)propertyNodeListIterator.next();
String propertyName = propertyElement.getAttributeValue(propertyElement.getNamespaceName(), "name");
String type = propertyElement.getAttributeValue(propertyElement.getNamespaceName(), "type");
String path = propertyElement.getAttributeValue(propertyElement.getNamespaceName(), "path");
if(path == null)
{
LanguageVO langaugeVO = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForSiteNode(getDatabase(), templateController.getSiteNodeId());
if(propertyElement.getAttributeValue(propertyElement.getNamespaceName(), "path_" + langaugeVO.getLanguageCode()) != null)
path = propertyElement.getAttributeValue(propertyElement.getNamespaceName(), "path_" + langaugeVO.getLanguageCode());
}
//logger.info("path:" + "path_" + locale.getLanguage() + ":" + propertyElement.attributeValue("path_" + locale.getLanguage()));
if(propertyElement.getAttributeValue(propertyElement.getNamespaceName(), "path_" + locale.getLanguage()) != null)
path = propertyElement.getAttributeValue(propertyElement.getNamespaceName(), "path_" + locale.getLanguage());
if(path == null || path.equals(""))
{
logger.info("Falling back to content master language 1 for property:" + propertyName);
LanguageVO contentMasterLangaugeVO = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForRepository(getDatabase(), contentVO.getRepositoryId());
if(propertyElement.getAttributeValue(propertyElement.getNamespaceName(), "path_" + contentMasterLangaugeVO.getLanguageCode()) != null)
path = propertyElement.getAttributeValue(propertyElement.getNamespaceName(), "path_" + contentMasterLangaugeVO.getLanguageCode());
}
Map property = new HashMap();
property.put("name", propertyName);
property.put("path", path);
property.put("type", type);
property.put("isPagePartReference", (isPagePartRef == null ? "false" : isPagePartRef));
Iterator attributesIterator = propertyElement.attributes();
while(attributesIterator.hasNext())
{
XmlAttribute attribute = (XmlAttribute)attributesIterator.next();
if(attribute.getName().startsWith("path_"))
property.put(attribute.getName(), attribute.getValue());
}
if(path != null)
{
if(propertyName.equals(InfoGlueComponent.CACHE_RESULT_PROPERTYNAME) && (path.equalsIgnoreCase("true") || path.equalsIgnoreCase("yes")))
{
component.setCacheResult(true);
}
if(propertyName.equals(InfoGlueComponent.UPDATE_INTERVAL_PROPERTYNAME) && !path.equals(""))
{
try { component.setUpdateInterval(Integer.parseInt(path)); } catch (Exception e) { logger.warn("The component " + component.getName() + " " + InfoGlueComponent.UPDATE_INTERVAL_PROPERTYNAME + " with a faulty value on page " + this.getTemplateController().getOriginalFullURL() + ":" + e.getMessage()); }
}
if(propertyName.equals(InfoGlueComponent.CACHE_KEY_PROPERTYNAME) && !path.equals(""))
{
component.setCacheKey(path);
}
if(propertyName.equals(InfoGlueComponent.PREPROCESSING_ORDER_PROPERTYNAME) && !path.equals(""))
{
component.setPreProcessingOrder(path);
}
}
List bindings = new ArrayList();
Xb1XPath xpathObject4 = (Xb1XPath)cachedXPathObjects.get("binding");
if(xpathObject4 == null)
{
xpathObject4 = new Xb1XPath("binding");
cachedXPathObjects.put("binding", xpathObject4);
}
List bindingNodeList = xpathObject4.selectNodes(propertyElement);
//logger.info("bindingNodeList:" + bindingNodeList.getLength());
Iterator bindingNodeListIterator = bindingNodeList.iterator();
while(bindingNodeListIterator.hasNext())
{
XmlElement bindingElement = (XmlElement)bindingNodeListIterator.next();
String entity = bindingElement.getAttributeValue(bindingElement.getNamespaceName(), "entity");
String entityId = bindingElement.getAttributeValue(bindingElement.getNamespaceName(), "entityId");
String assetKey = bindingElement.getAttributeValue(bindingElement.getNamespaceName(), "assetKey");
//logger.info("Binding found:" + entity + ":" + entityId);
ComponentBinding componentBinding = new ComponentBinding();
//componentBinding.setId(new Integer(id));
//componentBinding.setComponentId(componentId);
componentBinding.setEntityClass(entity);
componentBinding.setEntityId(new Integer(entityId));
componentBinding.setAssetKey(assetKey);
componentBinding.setBindingPath(path);
bindings.add(componentBinding);
}
property.put("bindings", bindings);
component.getProperties().put(propertyName, property);
//TEST
//component.getProperties().put(propertyName, property);
}
}
getComponentRestrictionsWithXPP3(child, component, locale, templateController);
//Getting slots for the component
String componentString = this.getComponentString(templateController, contentId, component);
//logger.info("Getting the slots for component.......");
//logger.info("componentString:" + componentString);
int offset = 0;
int slotStartIndex = componentString.indexOf("<ig:slot", offset);
while(slotStartIndex > -1)
{
int slotStopIndex = componentString.indexOf("</ig:slot>", slotStartIndex);
String slotString = componentString.substring(slotStartIndex, slotStopIndex + 10);
String slotId = slotString.substring(slotString.indexOf("id") + 4, slotString.indexOf("\"", slotString.indexOf("id") + 4));
boolean inherit = true;
int inheritIndex = slotString.indexOf("inherit");
if(inheritIndex > -1)
{
String inheritString = slotString.substring(inheritIndex + 9, slotString.indexOf("\"", inheritIndex + 9));
inherit = Boolean.parseBoolean(inheritString);
}
boolean disableAccessControl = false;
int disableAccessControlIndex = slotString.indexOf("disableAccessControl");
if(disableAccessControlIndex > -1)
{
String disableAccessControlString = slotString.substring(disableAccessControlIndex + "disableAccessControl".length() + 2, slotString.indexOf("\"", disableAccessControlIndex + "disableAccessControl".length() + 2));
disableAccessControl = Boolean.parseBoolean(disableAccessControlString);
}
String[] allowedComponentNamesArray = null;
int allowedComponentNamesIndex = slotString.indexOf(" allowedComponentNames");
if(allowedComponentNamesIndex > -1)
{
String allowedComponentNames = slotString.substring(allowedComponentNamesIndex + 24, slotString.indexOf("\"", allowedComponentNamesIndex + 24));
allowedComponentNamesArray = allowedComponentNames.split(",");
}
String[] disallowedComponentNamesArray = null;
int disallowedComponentNamesIndex = slotString.indexOf(" disallowedComponentNames");
if(disallowedComponentNamesIndex > -1)
{
String disallowedComponentNames = slotString.substring(disallowedComponentNamesIndex + 27, slotString.indexOf("\"", disallowedComponentNamesIndex + 27));
disallowedComponentNamesArray = disallowedComponentNames.split(",");
}
String[] allowedComponentGroupNamesArray = null;
int allowedComponentGroupNamesIndex = slotString.indexOf(" allowedComponentGroupNames");
if(allowedComponentGroupNamesIndex > -1)
{
String allowedComponentGroupNames = slotString.substring(allowedComponentGroupNamesIndex + 29, slotString.indexOf("\"", allowedComponentGroupNamesIndex + 29));
allowedComponentGroupNamesArray = allowedComponentGroupNames.split(",");
}
String addComponentText = null;
int addComponentTextIndex = slotString.indexOf("addComponentText");
if(addComponentTextIndex > -1)
{
addComponentText = slotString.substring(addComponentTextIndex + "addComponentText".length() + 2, slotString.indexOf("\"", addComponentTextIndex + "addComponentText".length() + 2));
}
String addComponentLinkHTML = null;
int addComponentLinkHTMLIndex = slotString.indexOf("addComponentLinkHTML");
if(addComponentLinkHTMLIndex > -1)
{
addComponentLinkHTML = slotString.substring(addComponentLinkHTMLIndex + "addComponentLinkHTML".length() + 2, slotString.indexOf("\"", addComponentLinkHTMLIndex + "addComponentLinkHTML".length() + 2));
}
int allowedNumberOfComponentsInt = -1;
int allowedNumberOfComponentsIndex = slotString.indexOf("allowedNumberOfComponents");
if(allowedNumberOfComponentsIndex > -1)
{
String allowedNumberOfComponents = slotString.substring(allowedNumberOfComponentsIndex + "allowedNumberOfComponents".length() + 2, slotString.indexOf("\"", allowedNumberOfComponentsIndex + "allowedNumberOfComponents".length() + 2));
try
{
allowedNumberOfComponentsInt = new Integer(allowedNumberOfComponents);
}
catch (Exception e)
{
allowedNumberOfComponentsInt = -1;
}
}
Slot slot = new Slot();
slot.setId(slotId);
slot.setInherit(inherit);
slot.setDisableAccessControl(disableAccessControl);
slot.setAllowedComponentsArray(allowedComponentNamesArray);
slot.setDisallowedComponentsArray(disallowedComponentNamesArray);
slot.setAllowedComponentGroupsArray(allowedComponentGroupNamesArray);
slot.setAddComponentLinkHTML(addComponentLinkHTML);
slot.setAddComponentText(addComponentText);
slot.setAllowedNumberOfComponents(new Integer(allowedNumberOfComponentsInt));
List subComponents = getComponentsWithXPP3(db, templateController, component, templateController.getSiteNodeId(), slotId);
slot.setComponents(subComponents);
component.getSlotList().add(slot);
offset = slotStopIndex; // + 10;
slotStartIndex = componentString.indexOf("<ig:slot", offset);
}
Xb1XPath xpathObject5 = (Xb1XPath)cachedXPathObjects.get("components");
if(xpathObject5 == null)
{
xpathObject5 = new Xb1XPath("components");
cachedXPathObjects.put("components", xpathObject5);
}
List anl = xpathObject5.selectNodes(child);
if(anl.size() > 0)
{
XmlElement componentsElement = (XmlElement)anl.get(0);
component.setComponents(getComponentsWithXPP3(db, componentsElement, templateController, component));
}
components.put(name, component);
}