/** * */ package at.knowcenter.wag.egov.egiz.sig.sigid; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; /** * @author wprinz * */ public class DetachedIdFormatter implements IdFormatter { /** * The SIG_ID prefix. * Default value: etsi-bka-1.0 */ public static String SIG_ID_PREFIX = "etsi-bka-1.0"; //$NON-NLS-1$ public static final String SIG_ID_KEY = "default.bku.algorithm.id"; /** * The log. */ private static Log log = LogFactory.getLog(DetachedIdFormatter.class); /** * @see at.knowcenter.wag.egov.egiz.sig.sigid.IdFormatter#formatIds(java.lang.String[]) */ public String formatIds(String[] ids) { // read SIG_ID_PREFIX from config file try { SIG_ID_PREFIX = SettingsReader.getInstance().getValueFromKey(SIG_ID_KEY); } catch (SettingsException e) { e.printStackTrace(); } // ids algorithm: String join = ""; //$NON-NLS-1$ String base = null; for (int arr_idx = 0; arr_idx < ids.length; arr_idx++) { String id = ids[arr_idx]; if (log.isDebugEnabled()) { log.debug("Set BKU id:" + id); //$NON-NLS-1$ } int id_idx = id.lastIndexOf("-"); //$NON-NLS-1$ if (arr_idx == 0) { base = id.substring(0, id_idx); } String cur_id = id.substring(id_idx + 1); if (cur_id.equalsIgnoreCase("")) //$NON-NLS-1$ { cur_id = "0"; //$NON-NLS-1$ } join += "-" + cur_id; //$NON-NLS-1$ } String idstr = base + "@" + join.substring(1); //$NON-NLS-1$ String final_ids = SIG_ID_PREFIX + "@" + idstr; return final_ids; } }