01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
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
25: RepositoryException implements LocalizedException {
26: private String documentId;
27: private String branchName;
28: private long branchId;
29: private String languageName;
30: private long languageId;
31:
32: private static final String DOC_ID_KEY = "docId";
33: private static final String BRANCH_KEY = "branchName";
34: private static final String LANG_KEY = "langName";
35: private static final String BRANCH_ID_KEY = "branchId";
36: private static final String LANG_ID_KEY = "langId";
37:
38: public DocumentVariantNotFoundException(String documentId,
39: String branchName, long branchId, String languageName,
40: long languageId) {
41: this .documentId = documentId;
42: this .branchName = branchName;
43: this .branchId = branchId;
44: this .languageName = languageName;
45: this .languageId = languageId;
46: }
47:
48: public DocumentVariantNotFoundException(Map params) {
49: this .documentId = (String) params.get(DOC_ID_KEY);
50: this .branchName = (String) params.get(BRANCH_KEY);
51: this .branchId = Long.parseLong((String) params
52: .get(BRANCH_ID_KEY));
53: this .languageName = (String) params.get(LANG_KEY);
54: this .languageId = Long.parseLong((String) params
55: .get(LANG_ID_KEY));
56: }
57:
58: public Map<String, String> getState() {
59: Map<String, String> map = new HashMap<String, String>();
60: map.put(DOC_ID_KEY, documentId);
61: map.put(BRANCH_ID_KEY, String.valueOf(branchId));
62: map.put(LANG_ID_KEY, String.valueOf(languageId));
63: if (branchName != null)
64: map.put(BRANCH_KEY, branchName);
65: if (languageName != null)
66: map.put(LANG_KEY, languageName);
67: return map;
68: }
69:
70: public String getMessage() {
71: return getMessage(Locale.US);
72: }
73:
74: public String getMessage(Locale locale) {
75: ResourceBundle bundle = ResourceBundle.getBundle(
76: "org/outerj/daisy/repository/messages", locale);
77: String message = bundle
78: .getString("documentvariant-not-found-exception");
79: String branch = branchName != null ? branchName + " (ID "
80: + branchId + ")" : String.valueOf(branchId);
81: String language = languageName != null ? languageName + " (ID "
82: + languageId + ")" : String.valueOf(languageId);
83: return MessageFormat.format(message, documentId, branch,
84: language);
85: }
86:
87: public String getDocumentId() {
88: return documentId;
89: }
90:
91: public long getBranchId() {
92: return branchId;
93: }
94:
95: public long getLanguageId() {
96: return languageId;
97: }
98: }
|