package com.exedio.copernica;

import java.util.Collection;
import java.util.Collections;

import com.exedio.cope.lib.Attribute;
import com.exedio.cope.lib.Item;
import com.exedio.cope.lib.Type;


public class TransientCopernicaProvider implements CopernicaProvider
{
	public Collection getDisplayLanguages()
	{
		return Collections.EMPTY_LIST;
	}
	
	public Collection getRootCategories()
	{
		return Collections.EMPTY_LIST;
	}
	
	public Collection getMainAttributes(final Type type)
	{
		return Collections.EMPTY_LIST;
	}

	public Collection getSections(final Type type)
	{
		return Collections.EMPTY_LIST;
	}
	
	public static final String breakupName(final String name)
	{
		final StringBuffer result = new StringBuffer(name.length());
		boolean wordStart = true;
		for(int i=0; i<name.length(); i++)
		{
			final char c = name.charAt(i);

			if(Character.isUpperCase(c))
			{
				if(!wordStart)
					result.append(' ');
				wordStart = true;
			}
			else
				wordStart = false;

			if(i==0)
				result.append(Character.toUpperCase(c));
			else
				result.append(c);
		}
		return result.toString();
	}
	
	public String getDisplayName(final com.exedio.copernica.Language displayLanguage, final Type type)
	{
		return breakupName(type.getID());
	}

	public String getDisplayName(final com.exedio.copernica.Language displayLanguage, final Attribute attribute)
	{
		String name = attribute.getName();
		if(name.endsWith("Internal"))
			name = name.substring(0, name.length()-"Internal".length());

		return breakupName(name);
	}
	
	public String getDisplayName(final com.exedio.copernica.Language displayLanguage, final Item item)
	{
		return item.toString();
	}
	
	public String getIconURL(final Type type)
	{
		return null;
	}

	public com.exedio.copernica.Language findLanguageByUniqueID(final String uniqueID)
	{
		return null;
	}
	
	public Category findCategoryByUniqueID(final String uniqueID)
	{
		return null;
	}
	
	public Section findSectionByUniqueID(final String uniqueID)
	{
		return null;
	}

	public void initializeExampleSystem()
	{
	}

}

@@ -82,16 +82,66 @@
 ections;
+%0Aimport java.util.Iterator;%0Aimport java.util.List;
 %0A%0Aimport
@@ -232,20 +232,109 @@
 ope.lib.
-Type
+ObjectAttribute;%0Aimport com.exedio.cope.lib.Type;%0Aimport com.exedio.cope.lib.UniqueConstraint
 ;%0A%0A%0Apubl
@@ -1770,31 +1770,930 @@
 %7B%0A%09%09
-return item.toString();
+final Type type = item.getType();%0A%09%09final List uniqueConstraints = type.getUniqueConstraints();%0A%09%09if(uniqueConstraints.isEmpty())%0A%09%09%09return item.toString();%0A%09%09else%0A%09%09%7B%0A%09%09%09final StringBuffer result = new StringBuffer();%0A%09%09%09final UniqueConstraint uniqueConstraint = (UniqueConstraint)uniqueConstraints.iterator().next();%0A%09%09%09boolean first = true;%0A%09%09%09for(Iterator i = uniqueConstraint.getUniqueAttributes().iterator(); i.hasNext(); )%0A%09%09%09%7B%0A%09%09%09%09if(first)%0A%09%09%09%09%09first = false;%0A%09%09%09%09else%0A%09%09%09%09%09result.append(%22 - %22);%0A%0A%09%09%09%09final ObjectAttribute attribute = (ObjectAttribute)i.next();%0A%09%09%09%09final Object value = item.getAttribute(attribute);%0A%0A%09%09%09%09final String valueString;%0A%09%09%09%09if(value == null)%0A%09%09%09%09%09valueString = %22NULL%22;%0A%09%09%09%09else if(value instanceof Item)%0A%09%09%09%09%09valueString = getDisplayName(displayLanguage, (Item)value);%0A%09%09%09%09else%0A%09%09%09%09%09valueString = value.toString();%0A%0A%09%09%09%09result.append(valueString);%0A%09%09%09%7D%0A%09%09%09return result.toString();%0A%09%09%7D
 %0A%09%7D%0A

create a useful TransientCopernicaProvider#getDisplayName(Language, Item)