/*
 * Created on 22 avr. 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.injac.oai.server.catalog;

import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.Enumeration;

import org.apache.log4j.Logger;
import org.apache.webdav.lib.BaseProperty;

/**
 * @author shoam
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class IDConverter {
	/**
	 * Static logger
	 */
	static Logger logger = Logger.getLogger(WebdavOAICatalog.class);
	public static String fromOAIIdentifier(String identifier){
		try {
            StringTokenizer tokenizer = new StringTokenizer(identifier, ":");
            tokenizer.nextToken();
            tokenizer.nextToken();
            String res= identifier.substring(identifier.indexOf(tokenizer.nextToken()));
            return res;
        } catch (Exception e) {
            return null;
        }
	}
	
	 /**
     * Construct an OAI identifier from the native item
     *
     * @param nativeItem native Item object
     * @return OAI identifier
     */
    public static String getOAIIdentifier(Object nativeItem, String repositoryIdentifier) {
	StringBuffer sb = new StringBuffer();
	sb.append("oai:");
	sb.append(repositoryIdentifier);
	sb.append(":");
	sb.append(getLocalIdentifier(nativeItem));
	return sb.toString();
    }
    
    public static String getLocalIdentifier(Object nativeItem){
    	return (String)((HashMap)nativeItem).get("webdavurl");
    }
}
