try
{
Iterator iterator = contents.iterator();
while(iterator.hasNext())
{
Content content = (Content)iterator.next();
if(includeFolders || content.getIsBranch().booleanValue() == false)
{
int index = 0;
Iterator sortedListIterator = sortedContents.iterator();
while(sortedListIterator.hasNext())
{
Content sortedContent = (Content)sortedListIterator.next();
//Here we sort on name if the name on a container is wanted
if(sortAttributeName.equalsIgnoreCase("contentId"))
{
Integer id = content.getContentId();
Integer sortedId = sortedContent.getContentId();
if(id != null && sortedId != null && sortOrder.equalsIgnoreCase("asc") && id.compareTo(sortedId) < 0)
{
break;
}
else if(id != null && sortedId != null && sortOrder.equalsIgnoreCase("desc") && id.compareTo(sortedId) > 0)
{
break;
}
}
else if(sortAttributeName.equalsIgnoreCase("name"))
{
String name = content.getName();
String sortedName = sortedContent.getName();
if(name != null && sortedName != null && sortOrder.equalsIgnoreCase("asc") && name.compareTo(sortedName) < 0)
{
break;
}
else if(name != null && sortedName != null && sortOrder.equalsIgnoreCase("desc") && name.compareTo(sortedName) > 0)
{
break;
}
}
//Here we sort on date if the dates on a container is wanted
else if(sortAttributeName.equalsIgnoreCase("publishDateTime"))
{
Date date = content.getPublishDateTime();
Date sortedDate = sortedContent.getPublishDateTime();
if(date != null && sortedDate != null && sortOrder.equalsIgnoreCase("asc") && date.before(sortedDate))
{
break;
}
else if(date != null && sortedDate != null && sortOrder.equalsIgnoreCase("desc") && date.after(sortedDate))
{
break;
}
}
else if(sortAttributeName.equalsIgnoreCase("expireDateTime"))
{
Date date = content.getExpireDateTime();
Date sortedDate = sortedContent.getExpireDateTime();
if(date != null && sortedDate != null && sortOrder.equalsIgnoreCase("asc") && date.before(sortedDate))
{
break;
}
else if(date != null && sortedDate != null && sortOrder.equalsIgnoreCase("desc") && date.after(sortedDate))
{
break;
}
}
else
{
long current = System.currentTimeMillis();
String contentAttribute = this.getContentAttribute(db, content.getId(), languageId, sortAttributeName, siteNodeId, useLanguageFallback, deliveryContext, infoGluePrincipal, false);
String sortedContentAttribute = this.getContentAttribute(db, sortedContent.getId(), languageId, sortAttributeName, siteNodeId, useLanguageFallback, deliveryContext, infoGluePrincipal, false);
attributesTimes = attributesTimes + (System.currentTimeMillis() - current);
if(contentAttribute != null && sortedContentAttribute != null && sortOrder.equalsIgnoreCase("asc") && contentAttribute.compareTo(sortedContentAttribute) < 0)
{
break;
}