VariantHelper.java :  » Content-Management-System » daisy » org » outerj » daisy » sync » Java Open Source

Java Open Source » Content Management System » daisy 
daisy » org » outerj » daisy » sync » VariantHelper.java
package org.outerj.daisy.sync;

import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.outerj.daisy.repository.VariantKey;

public class VariantHelper {
  private static Logger logger = Logger.getLogger("org.outerj.daisy.sync");

  public static VariantKey extractVariantKey(String key) {
    String regex = "(.*?)@(.*?):(.*?)";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(key);
    if (matcher.matches() && matcher.groupCount() == 3) {
      return new VariantKey(matcher.group(1), Long.parseLong(matcher.group(2)), Long.parseLong(matcher.group(3)));
    } else {
      logger.warning("Could not convert value : " + key + " to a variant key");
      return null;
    }
  }

  public static String variantKeyToString (VariantKey variantKey) {
    return variantKey.getDocumentId() + "@" + variantKey.getBranchId() + ":" + variantKey.getLanguageId();
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.