org.osgl.util.Keyword Java Examples
The following examples show how to use
org.osgl.util.Keyword.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GH54.java From java-di with Apache License 2.0 | 6 votes |
@Test public void test() { Genie genie = Genie.create(new Module() { @Override protected void configure() { bind(TypedElementLoader.class).to(new TypedElementLoader() { @Override protected List<Class> load(Class type, boolean loadNonPublic, boolean loadAbstract, boolean loadRoot) { List<Class> list = new ArrayList<>(); list.add(Color.class); return list; } }); } }); GH54 gh54 = genie.get(GH54.class); eq(Color.DarkBlue, gh54.colors.get(Keyword.of("dark-blue"))); }
Example #2
Source File: UrlPath.java From actframework with Apache License 2.0 | 6 votes |
private UrlPath(CharSequence path) { String s = path.toString(); String[] sa = s.split("/"); for (String item: sa) { if (S.notBlank(item)) { Keyword kw = null; if (item.startsWith("{") || item.contains(":")) { item = DYNA_PART; } else if (item.startsWith("~") && item.endsWith("~")) { kw = Keyword.of(S.strip(item, "~", "~")); } if (null != kw) { parts.add(kw); } else { parts.add(item); } } } }
Example #3
Source File: UrlPath.java From actframework with Apache License 2.0 | 6 votes |
private static boolean matches(Object cs1, Object cs2) { if (DYNA_PART.equals(cs1)) { return true; } if (cs1 instanceof Keyword) { return matches((Keyword) cs1, cs2); } else if (cs2 instanceof Keyword) { return matches((Keyword) cs2, cs1); } String s1 = S.string(cs1); String s2 = S.string(cs2); int len = s1.length(); if (len != s2.length()) { return false; } for (int i = len - 1; i >= 0; --i) { if (s1.charAt(i) != s2.charAt(i)) { return false; } } return true; }
Example #4
Source File: ScenarioDebugHelper.java From actframework with Apache License 2.0 | 6 votes |
@GetAction({"e2e/{testId}", "test/{testId}", "tests/{testId}"}) public List<Scenario> runTest(App app, Keyword testId, ActionContext context, ProgressGauge gauge) { if (context.accept().isSameTypeWith(H.Format.HTML)) { context.templatePath("/~test.html"); } List<Scenario> results = test.run(app, testId, null, false, gauge); boolean failure = false; for (Scenario scenario : results) { if ($.not(scenario.ignore) && !scenario.status.pass()) { failure = true; break; } } context.renderArg("failure", failure); gauge.markAsDone(); return results; }
Example #5
Source File: CliDispatcher.java From actframework with Apache License 2.0 | 6 votes |
private void resolveCommandPrefix() { Map<Keyword, CliHandler> temp = new HashMap<>(registry); registry.clear(); App app = app(); for (Map.Entry<Keyword, CliHandler> pair : temp.entrySet()) { Keyword keyword = pair.getKey(); String name = rawNameRepo.get(keyword); CliHandler handler = pair.getValue(); if (handler instanceof CliHandlerProxy) { CliHandlerProxy proxy = $.cast(handler); Class<?> type = app.classForName(proxy.classMetaInfo().className()); CommandPrefix prefix = type.getAnnotation(CommandPrefix.class); if (null != prefix) { String pre = prefix.value(); if (S.notBlank(pre)) { name = S.pathConcat(pre, '.', rawNameRepo.get(keyword)); } } } addToRegistry(name, handler); } }
Example #6
Source File: NamedLogicRegister.java From actframework with Apache License 2.0 | 5 votes |
static <T extends NamedLogic> T get(Class<? extends NamedLogic> logicType, String name) { NamedLogicRegister register = Act.getInstance(NamedLogicRegister.class); Map<Keyword, NamedLogic> lookup = register.registry.get(logicType); if (null == lookup) { return null; } return (T) lookup.get(Keyword.of(name)); }
Example #7
Source File: NamedLogicRegister.java From actframework with Apache License 2.0 | 5 votes |
void register(Keyword keyword, NamedLogic logic, boolean force) { Class<? extends NamedLogic> type = logic.type(); Map<Keyword, NamedLogic> lookup = registry.get(type); if (null == lookup) { lookup = new HashMap<>(); registry.put(type, lookup); } NamedLogic existing = lookup.put(keyword, logic); E.unexpectedIf(!force && null != existing && logic != existing, "Keyword already used: " + keyword.hyphenated()); }
Example #8
Source File: RequestTemplateManager.java From actframework with Apache License 2.0 | 5 votes |
private void addAjax() { Keyword key = Keyword.of("ajax"); if (store.containsKey(key)) { return; } RequestSpec spec = new RequestSpec(); spec.ajax = true; spec.json = true; store.put(key, spec); }
Example #9
Source File: CliDispatcher.java From actframework with Apache License 2.0 | 5 votes |
private List<String> commands0(boolean sys, boolean app, boolean withShortcut) { C.List<String> list = C.newList(); Act.Mode mode = Act.mode(); boolean all = !sys && !app; for (Keyword keyword : registry.keySet()) { String s = rawNameRepo.get(keyword); boolean isSysCmd = s.startsWith("act."); if (isSysCmd && !sys && !all) { continue; } if (!isSysCmd && !app && !all) { continue; } CliHandler h = registry.get(keyword); if (h.appliedIn(mode)) { if (withShortcut) { List<String> shortcuts = shortCuts(h); if (null != shortcuts && !shortcuts.isEmpty()) { s = s + " | " + shortcuts.get(0); } } list.add(s); } } return list.sorted(new $.Comparator<String>() { @Override public int compare(String o1, String o2) { boolean b1 = (o1.startsWith("act.")); boolean b2 = (o2.startsWith("act.")); if (b1 & !b2) { return -1; } if (!b1 & b2) { return 1; } return o1.compareTo(o2); } }); }
Example #10
Source File: CliDispatcher.java From actframework with Apache License 2.0 | 5 votes |
public SortedSet<CliCmdInfo> commandInfoList(boolean sys, boolean app) { SortedSet<CliCmdInfo> list = new TreeSet<>(); boolean all = !sys && !app; for (Map.Entry<Keyword, CliHandler> entry : registry.entrySet()) { Keyword keyword = entry.getKey(); String s = rawNameRepo.get(keyword); boolean isSysCmd = s.startsWith("act."); if (isSysCmd && !sys && !all) { continue; } if (!isSysCmd && !app && !all) { continue; } CliHandler h = entry.getValue(); CliCmdInfo info = new CliCmdInfo(); info.help = h.commandLine()._2; info.name = s; List<String> shortcuts = shortCuts(h); if (null != shortcuts && !shortcuts.isEmpty()) { info.shortcut = shortcuts.get(0); } else { info.shortcut = info.name; } if (info.shortcut.length() > s.length()) { info.shortcut = s; } if (info.shortcut.startsWith("act.")) { info.shortcut = info.shortcut.substring(4); } list.add(info); } return list; }
Example #11
Source File: EnumLookupCache.java From actframework with Apache License 2.0 | 5 votes |
private Map<Keyword, Map<String, String>> ensureWithoutProperties(Locale locale) { Map<Keyword, Map<String, String>> map = withoutProperties.get(locale); if (null == map) { map = new HashMap<>(); withoutProperties.put(locale, map); } if (map.size() < eligibleEnumSize) { populateWithoutProperties(map, locale); } return map; }
Example #12
Source File: HeaderValueLoader.java From actframework with Apache License 2.0 | 5 votes |
@Override public void init(Map<String, Object> map, BeanSpec beanSpec) { this.headerName = (String) map.get("value"); if (S.blank(headerName)) { this.headerName = beanSpec.name(); } E.unexpectedIf(S.blank(headerName), "header name not found"); this.headerName = Keyword.of(this.headerName).httpHeader(); this.targetType = beanSpec.rawType(); }
Example #13
Source File: HeaderValueLoader.java From actframework with Apache License 2.0 | 5 votes |
private String key(String name, BeanSpec spec) { if (S.notBlank(name)) { return name; } name = spec.name(); return Keyword.of(name).httpHeader(); }
Example #14
Source File: Tags.java From act-doc with Apache License 2.0 | 5 votes |
public String substitude(String line) { String key = line; if (line.startsWith("<")) { key = S.ensureStrippedOff(line, S.ANGLE_BRACKETS); } String substitute = mapping.get(Keyword.of(key)); return null == substitute ? line : substitute; }
Example #15
Source File: HelpPage.java From actframework with Apache License 2.0 | 5 votes |
@GetAction("{cmdName}") public void help(String cmdName) { CliHandler handler = dispatcher.handler(cmdName); notFoundIfNull(handler); CliCmdInfo cmd = getCmdInfo(handler); notFoundIfNull(cmd); cmd.name = Keyword.of(cmdName).kebabCase(); render("~cmd_help.html", cmd); }
Example #16
Source File: EnumLookupCache.java From actframework with Apache License 2.0 | 5 votes |
private void populateWithProperties(Map<Keyword, Map<String, Map<String, Object>>> withProperties, Locale locale) { for (Map.Entry<String, Class<? extends Enum>> entry: eligibleEnums.entrySet()) { String key = entry.getKey(); if (!withProperties.containsKey(key)) { Map<String, Map<String, Object>> map = $.cast(I18n.i18n(locale, entry.getValue(), true)); withProperties.put(Keyword.of(key), map); } } }
Example #17
Source File: EnumLookupCache.java From actframework with Apache License 2.0 | 5 votes |
private void populateWithoutProperties(Map<Keyword, Map<String, String>> withoutProperties, Locale locale) { for (Map.Entry<String, Class<? extends Enum>> entry: eligibleEnums.entrySet()) { String key = entry.getKey(); if (!withoutProperties.containsKey(key)) { Map<String, String> map = $.cast(I18n.i18n(locale, entry.getValue())); withoutProperties.put(Keyword.of(key), map); } } }
Example #18
Source File: EnumLookupCache.java From actframework with Apache License 2.0 | 5 votes |
private Map<Keyword, Map<String, Map<String, Object>>> ensureWithProperties(Locale locale) { Map<Keyword, Map<String, Map<String, Object>>> map = withProperties.get(locale); if (null == map) { map = new HashMap<>(); withProperties.put(locale, map); } if (map.size() < eligibleEnumSize) { populateWithProperties(map, locale); } return map; }
Example #19
Source File: FastJsonKeywordCodec.java From actframework with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) { JSONLexer lexer = parser.getLexer(); if (lexer.token() == JSONToken.LITERAL_STRING) { String text = lexer.stringVal(); lexer.nextToken(JSONToken.COMMA); return (T) Keyword.of(text); } else { throw new UnsupportedOperationException(); } }
Example #20
Source File: FastJsonKeywordCodec.java From actframework with Apache License 2.0 | 5 votes |
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { SerializeWriter out = serializer.getWriter(); if (object == null) { out.writeNull(); return; } out.writeString(keywordCodec.toString((Keyword) object)); }
Example #21
Source File: ParamKey.java From actframework with Apache License 2.0 | 5 votes |
private ParamKey(String[] seq) { this.seq = seq; this.size = seq.length; if (Act.appConfig().paramBindingKeywordMatching()) { keywordSeq = new Keyword[seq.length]; for (int i = 0; i < seq.length; ++i) { keywordSeq[i] = Keyword.of(seq[i]); } } calcHashCode(); }
Example #22
Source File: EnumLookupCache.java From actframework with Apache License 2.0 | 4 votes |
public Map<String, String> withoutProperties(String enumTypeName, Locale locale) { Map<Keyword, Map<String, String>> map = ensureWithoutProperties(locale); return map.get(Keyword.of(enumTypeName)); }
Example #23
Source File: EnumLookupCache.java From actframework with Apache License 2.0 | 4 votes |
public Map<Keyword, Map<String, Map<String, Object>>> withProperties(Locale locale) { return ensureWithProperties(locale); }
Example #24
Source File: EnumLookupCache.java From actframework with Apache License 2.0 | 4 votes |
public Map<String, Map<String, Object>> withProperties(String enumTypeName, Locale locale) { Map<Keyword, Map<String, Map<String, Object>>> map = ensureWithProperties(locale); return map.get(Keyword.of(enumTypeName)); }
Example #25
Source File: EnumLookupCache.java From actframework with Apache License 2.0 | 4 votes |
public Map<Keyword, Map<String, String>> withoutProperties(Locale locale) { return ensureWithoutProperties(locale); }
Example #26
Source File: UrlPath.java From actframework with Apache License 2.0 | 4 votes |
private static boolean matches(Keyword keyword, Object o) { return keyword.matches(S.string(o)); }
Example #27
Source File: ErrorDispatcher.java From java-di with Apache License 2.0 | 4 votes |
String handle3(String errorType) { ErrorHandler handler = registry3.get(Keyword.of(errorType)); return null == handler ? "unknown" : handler.toString(); }
Example #28
Source File: Config.java From actframework with Apache License 2.0 | 4 votes |
public static boolean matches(String k1, String k2) { return $.eq(Keyword.of(k1), Keyword.of(k2)); }
Example #29
Source File: LoadResourceTest.java From actframework with Apache License 2.0 | 4 votes |
@Test public void testTagsByKeyword() { eq("foo_tag", testBed.tagsByKeyword.get(Keyword.of("foo"))); eq("bar_tag", testBed.tagsByKeyword.get(Keyword.of("bar"))); }
Example #30
Source File: Config.java From actframework with Apache License 2.0 | 4 votes |
public static String canonical(String key) { return Keyword.of(key).dotted().toLowerCase(); }