JSON assets) throws Exception { List<AssetMetaData> abc = Collections.emptyList(); if (assets != null && assets.getSize() > 0) { abc = new ArrayList<AssetMetaData>(); for (String id : assets.names()) { JSON asset = assets.getJSON(id); AssetLocation location = AssetLocation.safeValueOf(asset.getString("location")); String type = asset.getString("type"); String value = asset.getString("value"); if (location == AssetLocation.APPLICATION && !value.startsWith("/")) { value = "/" + application.getPackageName().replace('.', '/') + "/" + packageName.replace('.', '/') + "/" + value; String minified = asset.getString("minified"); if (location == AssetLocation.APPLICATION && minified != null && !minified.startsWith("/")) { minified = "/" + application.getPackageName().replace('.', '/') + "/" + packageName.replace('.', '/') + "/" + minified; Boolean header = asset.getBoolean("header"); Integer maxAge = asset.getInteger("max-age"); minified, maxAge, asset.getArray("depends", String.class) ); abc.add(descriptor);
public RouteDescriptor(JSON config) { HashMap<String, ParamDescriptor> parameters = null; JSON foo = config.getJSON("parameters"); if (foo != null) { parameters = new HashMap<String, ParamDescriptor>(); for (String name : foo.names()) { String pattern = foo.getJSON(name).getString("pattern"); Boolean preservePath = foo.getJSON(name).getBoolean("preserve-path"); Boolean captureGroup = foo.getJSON(name).getBoolean("capture-group"); parameters.put(name, new ParamDescriptor(pattern, preservePath, captureGroup)); } } // this.path = config.getString("path"); this.handle = MethodHandle.parse(config.getString("handle")); this.parameters = parameters; }
@Test public void testBuild() throws Exception { CompilerAssert<File, File> helper = incrementalCompiler("metamodel.path"); helper.assertCompile(); // File ser = helper.getSourceOutput().getPath("juzu", "metamodel.ser"); ModuleMetaModel mm = (ModuleMetaModel)Tools.unserialize(MetaModelState.class, ser).metaModel; // JSON expected = json() .set("applications", json(). list("values", json(). list("controllers"). set("handle", "ElementHandle.Package[qn=metamodel.path]"). list("templates", json(). set("path", "foo.gtmpl"). list("refs") ) ) ); assertEquals(expected, mm.toJSON()); }
@Test public void testWriteIndented() throws Exception { assertEquals("{\n" + " \"a\":\"a_value\",\n" + " \"b\":2,\n" + " \"c\":[1,2,3],\n" + " \"d\":{\n" + " \"e\":true\n" + " }\n" + "}", JSON.toString(new JSON().set("a", "a_value").set("b", 2).list("c", 1, 2, 3).set("d", new JSON().set("e", true)), new StringBuilder(), 2).toString()); } }
@Test public void testCastToList() throws Exception { assertEquals(Arrays.asList("bar"), new JSON().map("foo", Arrays.asList("bar")).getList("foo")); assertEquals(Arrays.asList("bar"), new JSON().map("foo", Arrays.asList("bar")).getList("foo", String.class)); assertNull(new JSON().getList("foo")); assertNull(new JSON().getList("foo", Boolean.class)); try { new JSON().set("foo", true).getList("foo"); fail(); } catch (ClassCastException ignore) { } try { new JSON().set("foo", true).getList("foo", String.class); fail(); } catch (ClassCastException ignore) { } try { new JSON().map("foo", Arrays.asList("String")).getList("foo", Boolean.class); fail(); } catch (ClassCastException ignore) { } }
JSON json = (JSON)JSON.parse(url); JSON jsonParams = json.getJSON("parameters"); Map<String, String[]> parameters = new HashMap<String, String[]>(); for (String name : jsonParams.names()) { List<? extends String> value = jsonParams.getList(name, String.class); parameters.put(name, value.toArray(new String[value.size()])); if (json.getString("target") != null) { MethodHandle target = MethodHandle.parse(json.getString("target")); handler = controllerPlugin.getDescriptor().getMethodByHandle(target);
Map<AnnotationKey, AnnotationState> annotations = controllers.get(controller.getHandle()); if (annotations != null) { JSON controllerJSON = new JSON(); config.set(controller.getHandle().getName().toString(), controllerJSON); if (controllerJSON.get("require") != null) { throw new UnsupportedOperationException("Unsupported multiple requirements at " + key.getElement()); controllerJSON.set("require", "guest"); } else if (key.getType().equals(Name.create(RequiresAuthentication.class))) { controllerJSON.set("require", "authenticate"); } else if (key.getType().equals(Name.create(RequiresUser.class))) { controllerJSON.set("require", "user"); JSON controllerJSON = config.getJSON(controller.getHandle().getName().toString()); if (controllerJSON == null) { controllerJSON = new JSON(); config.set(controller.getHandle().getName().toString(), controllerJSON); JSON methodJSON = new JSON();; for (Map.Entry<AnnotationKey, AnnotationState> entry : annotations.entrySet()) { emitConfig(methodJSON, entry.getKey(), entry.getValue()); JSON methodsJSON = controllerJSON.getJSON("methods"); if (methodsJSON == null) { methodsJSON = new JSON(); controllerJSON.set("methods", methodsJSON); methodsJSON.set(methodId.substring(methodId.lastIndexOf('#') + 1), methodJSON);
private boolean hasPermissions(Request request, JSON config) { if (!SecurityUtils.getSubject().isAuthenticated()) { return false; } JSON foo = config.getJSON("permissions"); Logical logical = Logical.valueOf(foo.getString("logical")); List<String> permissions = (List<String>)foo.get("value"); if (permissions.size() == 1) { return ShiroTools.isPermitted(permissions.get(0)); } else if (permissions.size() > 1) { switch (logical) { case AND : return SecurityUtils.getSubject().isPermittedAll(permissions.toArray(new String[permissions.size()])); case OR : return ShiroTools.isPermitted(permissions.toArray(new String[permissions.size()])); } } return false; }
public <A extends Appendable> A toString(A appendable, int indent) throws IOException { return toString(this, appendable, indent); }
@Test public void testEscapeXML() throws Exception { MockApplication<?> app = application("plugin.controller.url.escapexml"); app.init(); // MockClient client = app.client(); MockViewBridge render = client.render(); JSON url = (JSON)JSON.parse(render.assertStringResponse()); assertEquals(Boolean.TRUE, url.getJSON("properties").get(PropertyType.ESCAPE_XML.getClass().getName())); }
for (String fqn : config.getList("controllers", String.class)) { Class<?> clazz = loader.loadClass(fqn); Field f = clazz.getField("DESCRIPTOR"); Boolean escapeXML = config.getBoolean("escapeXML"); String defaultControllerName = config.getString("default"); if (defaultControllerName != null) { defaultController = loader.loadClass(defaultControllerName); String errorControllerName = config.getString("error"); if (errorControllerName != null) { errorController = (Class<? extends juzu.Handler<Response.Error,Response>>)loader.loadClass(errorControllerName);