< prev index next >

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/MessageRetriever.java

Print this page
rev 3395 : [mq]: javadoc_rb


  69      * @param rb the resource bundle to read.
  70      */
  71     public MessageRetriever(ResourceBundle rb) {
  72         this.configuration = null;
  73         this.messageRB = rb;
  74         this.resourcelocation = null;
  75     }
  76 
  77     /**
  78      * Initialize the ResourceBundle with the given resource.
  79      *
  80      * @param configuration the configuration
  81      * @param resourcelocation Resource.
  82      */
  83     public MessageRetriever(Configuration configuration,
  84                             String resourcelocation) {
  85         this.configuration = configuration;
  86         this.resourcelocation = resourcelocation;
  87     }
  88 
  89     private void initRB() {
  90         if (messageRB == null) {

  91             try {
  92                 messageRB = ResourceBundle.getBundle(resourcelocation, configuration.getLocale());

  93             } catch (MissingResourceException e) {
  94                 throw new Error("Fatal: Resource (" + resourcelocation
  95                         + ") for javadoc doclets is missing.");
  96             }
  97         }















  98     }
  99 
 100     /**
 101      * Get and format message string from resource
 102      *
 103      * @param key selects message from resource
 104      * @param args arguments to be replaced in the message.
 105      * @return the composed text
 106      * @throws MissingResourceException when the key does not
 107      * exist in the properties file.
 108      */
 109     public String getText(String key, Object... args) throws MissingResourceException {
 110         initRB();
 111         String message = messageRB.getString(key);
 112         return MessageFormat.format(message, args);
 113     }
 114 
 115     /**
 116      * Print error message, increment error count.
 117      *
 118      * @param pos the position of the source
 119      * @param msg message to print
 120      */
 121     private void printError(DocTreePath path, String msg) {
 122         configuration.reporter.print(ERROR, path, msg);
 123     }
 124 
 125     /**
 126      * Print error message, increment error count.
 127      *
 128      * @param msg message to print
 129      */
 130     private void printError(String msg) {
 131         configuration.reporter.print(ERROR, msg);




  69      * @param rb the resource bundle to read.
  70      */
  71     public MessageRetriever(ResourceBundle rb) {
  72         this.configuration = null;
  73         this.messageRB = rb;
  74         this.resourcelocation = null;
  75     }
  76 
  77     /**
  78      * Initialize the ResourceBundle with the given resource.
  79      *
  80      * @param configuration the configuration
  81      * @param resourcelocation Resource.
  82      */
  83     public MessageRetriever(Configuration configuration,
  84                             String resourcelocation) {
  85         this.configuration = configuration;
  86         this.resourcelocation = resourcelocation;
  87     }
  88 
  89     private ResourceBundle initRB() {
  90         ResourceBundle bundle = messageRB;
  91         if (bundle == null) {
  92             try {
  93                 messageRB = bundle =
  94                         ResourceBundle.getBundle(resourcelocation, configuration.getLocale());
  95             } catch (MissingResourceException e) {
  96                 throw new Error("Fatal: Resource (" + resourcelocation
  97                         + ") for javadoc doclets is missing.");
  98             }
  99         }
 100         return bundle;
 101     }
 102 
 103     /**
 104      * Determines whether the given <code>key</code> can be retrieved
 105      * from this <code>MessageRetriever</code>
 106      *
 107      * @param key
 108      *        the resource <code>key</code>
 109      * @return <code>true</code> if the given <code>key</code> is
 110      *        contained in the underlying <code>ResourceBundle</code>.
 111      */
 112     public boolean containsKey(String key) {
 113         ResourceBundle bundle = initRB();
 114         return bundle.containsKey(key);
 115     }
 116 
 117     /**
 118      * Get and format message string from resource
 119      *
 120      * @param key selects message from resource
 121      * @param args arguments to be replaced in the message.
 122      * @return the composed text
 123      * @throws MissingResourceException when the key does not
 124      * exist in the properties file.
 125      */
 126     public String getText(String key, Object... args) throws MissingResourceException {
 127         ResourceBundle bundle = initRB();
 128         String message = bundle.getString(key);
 129         return MessageFormat.format(message, args);
 130     }
 131 
 132     /**
 133      * Print error message, increment error count.
 134      *
 135      * @param pos the position of the source
 136      * @param msg message to print
 137      */
 138     private void printError(DocTreePath path, String msg) {
 139         configuration.reporter.print(ERROR, path, msg);
 140     }
 141 
 142     /**
 143      * Print error message, increment error count.
 144      *
 145      * @param msg message to print
 146      */
 147     private void printError(String msg) {
 148         configuration.reporter.print(ERROR, msg);


< prev index next >