KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > repository > DocumentVariantNotFoundException


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.Locale JavaDoc;
21 import java.util.ResourceBundle JavaDoc;
22 import java.text.MessageFormat JavaDoc;
23
24 public class DocumentVariantNotFoundException extends RepositoryException implements LocalizedException {
25     private long documentId;
26     private String JavaDoc branch;
27     private String JavaDoc language;
28
29     private static final String JavaDoc DOC_ID_KEY = "docId";
30     private static final String JavaDoc BRANCH_KEY = "branch";
31     private static final String JavaDoc LANG_KEY = "lang";
32
33     public DocumentVariantNotFoundException(long documentId, String JavaDoc branch, String JavaDoc language) {
34         this.documentId = documentId;
35         this.branch = branch;
36         this.language = language;
37     }
38
39     public DocumentVariantNotFoundException(Map JavaDoc params) {
40         this.documentId = Long.parseLong((String JavaDoc)params.get(DOC_ID_KEY));
41         this.branch = (String JavaDoc)params.get(BRANCH_KEY);
42         this.language = (String JavaDoc)params.get(LANG_KEY);
43     }
44
45     public Map JavaDoc getState() {
46         HashMap JavaDoc map = new HashMap JavaDoc(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 JavaDoc getMessage() {
54         return getMessage(Locale.US);
55     }
56
57     public String JavaDoc getMessage(Locale JavaDoc locale) {
58         ResourceBundle JavaDoc bundle = ResourceBundle.getBundle("org/outerj/daisy/repository/messages", locale);
59         String JavaDoc message = bundle.getString("documentvariant-not-found-exception");
60         return MessageFormat.format(message, new String JavaDoc[] { String.valueOf(documentId), branch, language });
61     }
62 }
Popular Tags