1 16 package org.outerj.daisy.repository; 17 18 import java.util.Map ; 19 import java.util.HashMap ; 20 import java.util.Locale ; 21 import java.util.ResourceBundle ; 22 import java.text.MessageFormat ; 23 24 public class DocumentVariantNotFoundException extends RepositoryException implements LocalizedException { 25 private long documentId; 26 private String branch; 27 private String language; 28 29 private static final String DOC_ID_KEY = "docId"; 30 private static final String BRANCH_KEY = "branch"; 31 private static final String LANG_KEY = "lang"; 32 33 public DocumentVariantNotFoundException(long documentId, String branch, String language) { 34 this.documentId = documentId; 35 this.branch = branch; 36 this.language = language; 37 } 38 39 public DocumentVariantNotFoundException(Map params) { 40 this.documentId = Long.parseLong((String )params.get(DOC_ID_KEY)); 41 this.branch = (String )params.get(BRANCH_KEY); 42 this.language = (String )params.get(LANG_KEY); 43 } 44 45 public Map getState() { 46 HashMap map = new HashMap (1); 47 map.put(DOC_ID_KEY, String.valueOf(documentId)); 48 map.put(BRANCH_KEY, branch); 49 map.put(LANG_KEY, language); 50 return map; 51 } 52 53 public String getMessage() { 54 return getMessage(Locale.US); 55 } 56 57 public String getMessage(Locale locale) { 58 ResourceBundle bundle = ResourceBundle.getBundle("org/outerj/daisy/repository/messages", locale); 59 String message = bundle.getString("documentvariant-not-found-exception"); 60 return MessageFormat.format(message, new String [] { String.valueOf(documentId), branch, language }); 61 } 62 } | Popular Tags |