KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > bpel > ws > consumption > partner > resource > ResourceDictionary


1 package org.jboss.test.bpel.ws.consumption.partner.resource;
2
3 import java.util.MissingResourceException JavaDoc;
4 import java.util.ResourceBundle JavaDoc;
5
6 import org.jboss.test.bpel.ws.consumption.partner.spi.Dictionary;
7 import org.jboss.test.bpel.ws.consumption.partner.types.TDocument;
8 import org.jboss.test.bpel.ws.consumption.partner.types.TDocumentBody;
9 import org.jboss.test.bpel.ws.consumption.partner.types.TDocumentHead;
10 import org.jboss.test.bpel.ws.consumption.partner.types.TTextNotTranslatable;
11
12 /**
13  * @author Alejandro Guizar
14  * @version $Revision: 43322 $ $Date: 2006-04-03 12:19:24 -0400 (Mon, 03 Apr 2006) $
15  */

16 public class ResourceDictionary implements Dictionary {
17   
18   private final ResourceBundle JavaDoc bundle;
19   
20   public ResourceDictionary(ResourceBundle JavaDoc bundle) {
21     this.bundle = bundle;
22   }
23   
24   /** {@inheritDoc} */
25   public String JavaDoc translate(String JavaDoc text) throws TTextNotTranslatable {
26     try {
27       return bundle.getString(text);
28     }
29     catch (MissingResourceException JavaDoc e) {
30       throw new TTextNotTranslatable(text);
31     }
32   }
33
34   /** {@inheritDoc} */
35   public TDocument translate(TDocument document) throws TTextNotTranslatable {
36     TDocumentHead transHead = new TDocumentHead();
37     transHead.setTitle(bundle.getString(document.getHead().getTitle()));
38     transHead.setLanguage(bundle.getLocale().getLanguage());
39     
40     String JavaDoc[] paragraphs = document.getBody().getParagraph();
41     String JavaDoc[] transParagraphs = new String JavaDoc[paragraphs.length];
42     for (int i = 0; i < paragraphs.length; i++) {
43       String JavaDoc paragraph = paragraphs[i];
44       try {
45         transParagraphs[i] = bundle.getString(paragraph);
46       }
47       catch (MissingResourceException JavaDoc e) {
48         throw new TTextNotTranslatable(paragraph);
49       }
50     }
51     
52     TDocumentBody transBody = new TDocumentBody();
53     transBody.setParagraph(transParagraphs);
54     
55     TDocument targetDocument = new TDocument();
56     targetDocument.setHead(transHead);
57     targetDocument.setBody(transBody);
58     
59     return targetDocument;
60   }
61 }
62
Popular Tags