package eu.dnetlib.enabling.tools;

import com.sun.xml.messaging.saaj.util.Base64;

/**
 * resolve resource file and collection names from the resource identifier according to the DNet 1.0 policy, by encoding
 * the collection path in the identifier itself (as base64).
 * 
 * @author marko
 * 
 */
public class CompatResourceIdentifierResolverImpl implements ResourceIdentifierResolver {

	/**
	 * {@inheritDoc}
	 * @see eu.dnetlib.enabling.tools.ResourceIdentifierResolver#getCollectionName(java.lang.String)
	 */
	public String getCollectionName(final String resId) {
		final String[] components = resId.split("_");
		if (components.length == 1)
			return "DefaultCollection";
		return Base64.base64Decode(components[1]);
	}

	/**
	 * {@inheritDoc}
	 * @see eu.dnetlib.enabling.tools.ResourceIdentifierResolver#getFileName(java.lang.String)
	 */
	public String getFileName(final String resId) {
		return resId.split("_")[0];
	}

}
