private void mergeContentPageAttributes(ContentPageImpl contentPageImpl, BaseFragmentsElement pageOrTemplate)
{
// merge content page attributes
if ((contentPageImpl != null) && (pageOrTemplate != null))
{
BasePageElement page = ((pageOrTemplate instanceof BasePageElement) ? (BasePageElement)pageOrTemplate : null);
if ((pageOrTemplate.getMetadata() != null) && (pageOrTemplate.getMetadata().getFields() != null))
{
Iterator fieldIter = pageOrTemplate.getMetadata().getFields().iterator();
while (fieldIter.hasNext())
{
LocalizedField field = (LocalizedField)fieldIter.next();
Locale fieldLocale = field.getLocale();
String fieldName = field.getName();
if (fieldName != null)
{
boolean containsField = false;
Iterator containsFieldIterator = contentPageImpl.getMetadata().getFields().iterator();
while (!containsField && containsFieldIterator.hasNext())
{
LocalizedField testField = (LocalizedField)containsFieldIterator.next();
Locale testFieldLocale = testField.getLocale();
String testFieldName = testField.getName();
containsField = (fieldName.equals(testFieldName) &&
(((fieldLocale == null) && (testFieldLocale == null)) ||
((fieldLocale != null) && fieldLocale.equals(testFieldLocale))));
}
if (!containsField)
{
contentPageImpl.getMetadata().getFields().add(new ContentLocalizedFieldImpl(fieldLocale, fieldName, field.getValue()));
}
}
}
}
if (page != null)
{
String layoutDefaultDecorator = contentPageImpl.getDefaultDecorator(Fragment.LAYOUT);
String portletDefaultDecorator = contentPageImpl.getDefaultDecorator(Fragment.PORTLET);
Map defaultDecorators = null;
if (layoutDefaultDecorator == null)
{
layoutDefaultDecorator = page.getDefaultDecorator(Fragment.LAYOUT);
if (layoutDefaultDecorator != null)
{
if (defaultDecorators == null)
{
defaultDecorators = new HashMap();
}
defaultDecorators.put(Fragment.LAYOUT, layoutDefaultDecorator);
if (portletDefaultDecorator != null)
{
defaultDecorators.put(Fragment.PORTLET, portletDefaultDecorator);
}
}
}
if (portletDefaultDecorator == null)
{
portletDefaultDecorator = page.getDefaultDecorator(Fragment.PORTLET);
if (portletDefaultDecorator != null)
{
if (defaultDecorators == null)
{
defaultDecorators = new HashMap();
}
defaultDecorators.put(Fragment.PORTLET, portletDefaultDecorator);
if (layoutDefaultDecorator != null)
{
defaultDecorators.put(Fragment.LAYOUT, layoutDefaultDecorator);
}
}
}
if (defaultDecorators != null)
{
contentPageImpl.setDefaultDecorators(defaultDecorators);
}
}
if (contentPageImpl.getShortTitle() == null)
{
contentPageImpl.setShortTitle(pageOrTemplate.getShortTitle());
}
if ((contentPageImpl.getSkin() == null) && (page != null))
{
contentPageImpl.setSkin(page.getSkin());
}
if (contentPageImpl.getTitle() == null)
{
contentPageImpl.setTitle(pageOrTemplate.getTitle());
}