Parser(Reader r, Map<String, String> map) { this.reader = r; this.map = map; TokenStream ts = new TokenStream(reader); tokenList = ts.tokenize(); }
void read(Reader r) throws IOException { Parser p = new Parser(r, map); p.parseAndPopulate(); }
public String[] getLocaleNames() { String[] localeNameArray = annotationExtractor.extractLocaleNames(); return localeNameArray; }
private CAL10NBundle makePropertyResourceBundle(String resourceCandidate, String charset) { CAL10NBundle prb = null; URL url = getResource(resourceCandidate); if (url != null) { try { InputStream in = openConnectionForUrl(url); Reader reader = toReader(in, charset); if (charset == null || charset.length() == 0) reader = new InputStreamReader(in); else reader = new InputStreamReader(in, charset); prb = new CAL10NBundle(reader, MiscUtil.urlToFile(url)); in.close(); } catch (IOException e) { } } return prb; }
private <E extends Enum<?>> CAL10NBundle lookupResourceBundleByEnumClassAndLocale(Class<E> declaringClass) throws MessageConveyorException { AnnotationExtractorViaEnumClass annotationExtractor = new AnnotationExtractorViaEnumClass(declaringClass); // basename is declared via an annotation on the declaringClass String baseName = annotationExtractor.getBaseName(); if (baseName == null) { throw new MessageConveyorException( "Missing @BaseName annotation in enum type [" + declaringClass.getName() + "]. See also " + CAL10NConstants.MISSING_BN_ANNOTATION_URL); } String charset = annotationExtractor.extractCharset(locale); // use the declaring class' loader instead of // this.getClass().getClassLoader() // see also http://jira.qos.ch/browse/CAL-8 CAL10NBundleFinderByClassloader cal10NBundleFinderByClassloader = new CAL10NBundleFinderByClassloader(declaringClass.getClassLoader()); CAL10NBundle rb = cal10NBundleFinderByClassloader.getBundle( baseName, locale, charset); if (rb == null) { throw new MessageConveyorException( "Failed to locate resource bundle [" + baseName + "] for locale [" + locale + "] for enum type [" + declaringClass.getName() + "]"); } return rb; }
public CAL10NBundle getBundle(String baseName, Locale locale, String charset) { // same as the JDK convention // // It generates a path name from the candidate bundle name by replacing all // "." // characters with "/" and appending the string ".properties". // / see also http: // tinyurl.com/ldgej8 baseName = baseName.replace('.', '/'); String languageAndCountryCandidate = computeLanguageAndCountryCandidate( baseName, locale); String languageOnlyCandidate = computeLanguageOnlyCandidate(baseName, locale); CAL10NBundle cprbLanguageOnly = makePropertyResourceBundle(languageOnlyCandidate, charset); CAL10NBundle cprbLanguageAndCountry = null; if (languageAndCountryCandidate != null) { cprbLanguageAndCountry = makePropertyResourceBundle(languageAndCountryCandidate, charset); } if (cprbLanguageAndCountry != null) { cprbLanguageAndCountry.setParent(cprbLanguageOnly); return cprbLanguageAndCountry; } return cprbLanguageOnly; }
private void E() { Token t = getNextToken(); if (t == null) { // we are done return; } switch (t.tokenType) { case EOL: break; case KEY: String k = t.getValue(); t = getNextToken(); if (t.tokenType != TokenType.SEPARATOR) { throw new IllegalStateException("Unexpected token " + t); } StringBuilder buf = new StringBuilder(); V(buf); map.put(k, buf.toString()); break; } E(); }
private void V(StringBuilder buf) { Token t = getNextToken(); if (t.tokenType != TokenType.VALUE) { throw new IllegalStateException("Unexpected token " + t); } buf.append(t.getValue()); t = getNextToken(); if (t.tokenType == TokenType.EOL) { return; } else if (t.tokenType == TokenType.TRAILING_BACKSLASH) { Vopt(buf); } }
private void Vopt(StringBuilder buf) { Token t = getNextToken(); if (t.tokenType != TokenType.EOL) { throw new IllegalStateException("Unexpected token " + t); } V(buf); }
@Override public int hashCode() { return tokenType.hashCode(); }
void parseAndPopulate() { E(); }
public String getBaseName() { String rbName = annotationExtractor.getBaseName(); return rbName; }
protected String extractCharsetForLocale(Locale locale) { return annotationExtractor.extractCharset(locale); }
public CAL10NBundle(Reader r, File file) throws IOException { read(r); this.hostFile = file; nextCheck = System.currentTimeMillis() + CHECK_DELAY; }
public MessageKeyVerifier(Class<? extends Enum<?>> enumClass) { super(enumClass.getName(), new AnnotationExtractorViaEnumClass(enumClass)); this.enumClass = enumClass; }
@Override protected CAL10NBundleFinder getResourceBundleFinder() { return new CAL10NBundleFinderByClassloader(enumClass.getClassLoader()); }
boolean isTrailingBackSlash(String line, int next) { int len = line.length(); for(int i = next; i < len; i++) { char c = line.charAt(i); if(!isWhiteSpace(c)) return false; } return true; }
@Override protected Object handleGetObject(String key) { if (key == null) { throw new NullPointerException(); } Object o = map.get(key); if(o == null && parent != null) { o = parent.handleGetObject(key); } return o; } }
public Locale[] extractLocales() { LocaleData localeData = extractLocaleData(); if (localeData == null) { return null; } return localeData.value(); }
public String[] extractLocaleNames() { Locale[] localeDataArray = extractLocales(); if (localeDataArray == null) { return null; } String[] names = new String[localeDataArray.length]; for (int i = 0; i < localeDataArray.length; i++) { names[i] = localeDataArray[i].value(); } return names; }