@Test public void getMarkupLanguageNull() { IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> locator.getMarkupLanguage(null)); assertTrue(e.getMessage().contains("Must provide a languageName")); }
public MarkupLanguage getMarkupLanguage(final String languageName) throws IllegalArgumentException { checkArgument(!Strings.isNullOrEmpty(languageName), "Must provide a languageName"); Pattern classNamePattern = Pattern.compile("\\s*([^\\s#]+)?#?.*"); final List<String> names = new ArrayList<>(); final List<MarkupLanguage> languages = new ArrayList<>(); final MarkupLanguage[] result = new MarkupLanguage[1]; loadMarkupLanguages(language -> { if (languageName.equals(language.getName())) { result[0] = language; return false; } languages.add(language); names.add(language.getName()); return true; }); if (result[0] != null) { return result[0]; } Matcher matcher = classNamePattern.matcher(languageName); if (matcher.matches()) { String className = matcher.group(1); if (className != null) { for (MarkupLanguage language : languages) { if (className.equals(language.getClass().getName())) { return language; } } try { Class<?> clazz = Class.forName(className, true, classLoader); if (MarkupLanguage.class.isAssignableFrom(clazz)) { MarkupLanguage instance = (MarkupLanguage) clazz.getConstructor().newInstance(); return instance; } } catch (Exception e) { } } } Collections.sort(names); StringBuilder buf = new StringBuilder(); for (String name : names) { if (buf.length() != 0) { buf.append(", "); } buf.append('\''); buf.append(name); buf.append('\''); } throw new IllegalArgumentException(MessageFormat.format(Messages.getString("ServiceLocator.4"), languageName, buf.length() == 0 ? Messages.getString("ServiceLocator.5") : Messages.getString("ServiceLocator.6") + buf)); }
ServiceLocator { public MarkupLanguage getMarkupLanguage(final String languageName) throws IllegalArgumentException { checkArgument(!Strings.isNullOrEmpty(languageName), "Must provide a languageName"); Pattern classNamePattern = Pattern.compile("\\s*([^\\s#]+)?#?.*"); final List<String> names = new ArrayList<>(); final List<MarkupLanguage> languages = new ArrayList<>(); final MarkupLanguage[] result = new MarkupLanguage[1]; loadMarkupLanguages(language -> { if (languageName.equals(language.getName())) { result[0] = language; return false; } languages.add(language); names.add(language.getName()); return true; }); if (result[0] != null) { return result[0]; } Matcher matcher = classNamePattern.matcher(languageName); if (matcher.matches()) { String className = matcher.group(1); if (className != null) { for (MarkupLanguage language : languages) { if (className.equals(language.getClass().getName())) { return language; } } try { Class<?> clazz = Class.forName(className, true, classLoader); if (MarkupLanguage.class.isAssignableFrom(clazz)) { MarkupLanguage instance = (MarkupLanguage) clazz.getConstructor().newInstance(); return instance; } } catch (Exception e) { } } } Collections.sort(names); StringBuilder buf = new StringBuilder(); for (String name : names) { if (buf.length() != 0) { buf.append(", "); } buf.append('\''); buf.append(name); buf.append('\''); } throw new IllegalArgumentException(MessageFormat.format(Messages.getString("ServiceLocator.4"), languageName, buf.length() == 0 ? Messages.getString("ServiceLocator.5") : Messages.getString("ServiceLocator.6") + buf)); } }
ServiceLocator { public MarkupLanguage getMarkupLanguage(final String languageName) throws IllegalArgumentException { checkArgument(!Strings.isNullOrEmpty(languageName), "Must provide a languageName"); Pattern classNamePattern = Pattern.compile("\\s*([^\\s#]+)?#?.*"); final List<String> names = new ArrayList<>(); final List<MarkupLanguage> languages = new ArrayList<>(); final MarkupLanguage[] result = new MarkupLanguage[1]; loadMarkupLanguages(language -> { if (languageName.equals(language.getName())) { result[0] = language; return false; } languages.add(language); names.add(language.getName()); return true; }); if (result[0] != null) { return result[0]; } Matcher matcher = classNamePattern.matcher(languageName); if (matcher.matches()) { String className = matcher.group(1); if (className != null) { for (MarkupLanguage language : languages) { if (className.equals(language.getClass().getName())) { return language; } } try { Class<?> clazz = Class.forName(className, true, classLoader); if (MarkupLanguage.class.isAssignableFrom(clazz)) { MarkupLanguage instance = (MarkupLanguage) clazz.getConstructor().newInstance(); return instance; } } catch (Exception e) { } } } Collections.sort(names); StringBuilder buf = new StringBuilder(); for (String name : names) { if (buf.length() != 0) { buf.append(", "); } buf.append('\''); buf.append(name); buf.append('\''); } throw new IllegalArgumentException(MessageFormat.format(Messages.getString("ServiceLocator.4"), languageName, buf.length() == 0 ? Messages.getString("ServiceLocator.5") : Messages.getString("ServiceLocator.6") + buf)); } protected  ServiceLocator(ClassLoader classLoader); }
ServiceLocator { public MarkupLanguage getMarkupLanguage(final String languageName) throws IllegalArgumentException { checkArgument(!Strings.isNullOrEmpty(languageName), "Must provide a languageName"); Pattern classNamePattern = Pattern.compile("\\s*([^\\s#]+)?#?.*"); final List<String> names = new ArrayList<>(); final List<MarkupLanguage> languages = new ArrayList<>(); final MarkupLanguage[] result = new MarkupLanguage[1]; loadMarkupLanguages(language -> { if (languageName.equals(language.getName())) { result[0] = language; return false; } languages.add(language); names.add(language.getName()); return true; }); if (result[0] != null) { return result[0]; } Matcher matcher = classNamePattern.matcher(languageName); if (matcher.matches()) { String className = matcher.group(1); if (className != null) { for (MarkupLanguage language : languages) { if (className.equals(language.getClass().getName())) { return language; } } try { Class<?> clazz = Class.forName(className, true, classLoader); if (MarkupLanguage.class.isAssignableFrom(clazz)) { MarkupLanguage instance = (MarkupLanguage) clazz.getConstructor().newInstance(); return instance; } } catch (Exception e) { } } } Collections.sort(names); StringBuilder buf = new StringBuilder(); for (String name : names) { if (buf.length() != 0) { buf.append(", "); } buf.append('\''); buf.append(name); buf.append('\''); } throw new IllegalArgumentException(MessageFormat.format(Messages.getString("ServiceLocator.4"), languageName, buf.length() == 0 ? Messages.getString("ServiceLocator.5") : Messages.getString("ServiceLocator.6") + buf)); } protected  ServiceLocator(ClassLoader classLoader); static ServiceLocator getInstance(ClassLoader classLoader); static ServiceLocator getInstance(); MarkupLanguage getMarkupLanguage(final String languageName); Set<MarkupLanguage> getAllMarkupLanguages(); static void setImplementation(Class<? extends ServiceLocator> implementationClass); }
ServiceLocator { public MarkupLanguage getMarkupLanguage(final String languageName) throws IllegalArgumentException { checkArgument(!Strings.isNullOrEmpty(languageName), "Must provide a languageName"); Pattern classNamePattern = Pattern.compile("\\s*([^\\s#]+)?#?.*"); final List<String> names = new ArrayList<>(); final List<MarkupLanguage> languages = new ArrayList<>(); final MarkupLanguage[] result = new MarkupLanguage[1]; loadMarkupLanguages(language -> { if (languageName.equals(language.getName())) { result[0] = language; return false; } languages.add(language); names.add(language.getName()); return true; }); if (result[0] != null) { return result[0]; } Matcher matcher = classNamePattern.matcher(languageName); if (matcher.matches()) { String className = matcher.group(1); if (className != null) { for (MarkupLanguage language : languages) { if (className.equals(language.getClass().getName())) { return language; } } try { Class<?> clazz = Class.forName(className, true, classLoader); if (MarkupLanguage.class.isAssignableFrom(clazz)) { MarkupLanguage instance = (MarkupLanguage) clazz.getConstructor().newInstance(); return instance; } } catch (Exception e) { } } } Collections.sort(names); StringBuilder buf = new StringBuilder(); for (String name : names) { if (buf.length() != 0) { buf.append(", "); } buf.append('\''); buf.append(name); buf.append('\''); } throw new IllegalArgumentException(MessageFormat.format(Messages.getString("ServiceLocator.4"), languageName, buf.length() == 0 ? Messages.getString("ServiceLocator.5") : Messages.getString("ServiceLocator.6") + buf)); } protected  ServiceLocator(ClassLoader classLoader); static ServiceLocator getInstance(ClassLoader classLoader); static ServiceLocator getInstance(); MarkupLanguage getMarkupLanguage(final String languageName); Set<MarkupLanguage> getAllMarkupLanguages(); static void setImplementation(Class<? extends ServiceLocator> implementationClass);  }