@Test public void protected_asset_client_URL() { ResourceCache cache = mockResourceCache(); ClasspathAssetAliasManager aliasManager = mockClasspathAssetAliasManager(); Resource r = new ClasspathResource("foo/Bar.txt"); train_requiresDigest(cache, r, true); expect(cache.getDigest(r)).andReturn("ABC123"); String expectedClientURL = "/context/asset/foo/Bar.ABC123.txt"; train_toClientURL(aliasManager, "foo/Bar.ABC123.txt", expectedClientURL); EasyMock.expectLastCall().times(2); // 2nd time is the toString() call replay(); AssetFactory factory = new ClasspathAssetFactory(cache, aliasManager); Asset asset = factory.createAsset(r); assertSame(asset.getResource(), r); assertEquals(asset.toClientURL(), expectedClientURL); assertEquals(asset.toString(), expectedClientURL); verify(); }
public Resource getResourceFormStylesheetLink(StylesheetLink link) { String[] path = link.getURL().split("/"); StringBuilder sb = new StringBuilder(); Boolean flag = false; for (int i = 0; i < path.length; i++) { if (path[i].equalsIgnoreCase("css")) flag = true; if (flag) { sb.append("/"); sb.append(path[i]); } } String ctxPath = "context:" + sb.toString().substring(1); Asset a = assetSource.getExpandedAsset(ctxPath); return a.getResource(); }
@Test public void asset_client_URL_is_cached() { ResourceCache cache = mockResourceCache(); Resource r = new ClasspathResource("foo/Bar.txt"); ClasspathAssetAliasManager aliasManager = mockClasspathAssetAliasManager(); train_requiresDigest(cache, r, false); String expectedClientURL = "/context/asset/foo/Bar.txt"; train_toClientURL(aliasManager, "foo/Bar.txt", expectedClientURL); EasyMock.expectLastCall() .times(2); // Cache of the raw path, not the final path which may be optimized replay(); ClasspathAssetFactory factory = new ClasspathAssetFactory(cache, aliasManager); Asset asset = factory.createAsset(r); assertEquals(asset.toClientURL(), expectedClientURL); // Now, to check the cache: assertEquals(asset.toClientURL(), expectedClientURL); verify(); // Now, to test cache clearing: train_requiresDigest(cache, r, false); train_toClientURL(aliasManager, "foo/Bar.txt", expectedClientURL); replay(); factory.objectWasInvalidated(); assertEquals(asset.toClientURL(), expectedClientURL); verify(); }
/** * Writes an icon for field after the field. The icon has the same id as the field, with ":icon" * appended. This is expected by the default client-side JavaScript. The icon's src is a blank * spacer image (this is to allow the image displayed to be overridden via CSS). The icon's CSS * class is "t-error-icon", with "t-invisible" added if the field is not in error when rendered. * If client validation is not enabled for the form containing the field and the field is not in * error, then the error icon itself is not rendered. * * @param field which just completed rendering itself */ @Override public void afterField(Field field) { boolean inError = inError(field); boolean clientValidationEnabled = getFormSupport().isClientValidationEnabled(); if (inError || clientValidationEnabled) { String iconId = field.getClientId() + "_icon"; String cssClass = inError ? "t-error-icon" : "t-error-icon t-invisible"; markupWriter.element( "img", "src", spacerAsset.toClientURL(), "alt", "", "class", cssClass, "id", iconId); markupWriter.end(); } }
public void beginRender(MarkupWriter writer) { String value = tracker.getInput(this); if (value == null) { value = formatCurrentValue(); } String clientId = getClientId(); String triggerId = clientId + "-trigger"; writer.element( "input", "type", hideTextField ? "hidden" : "text", "name", getControlName(), "id", clientId, "value", value); if (isDisabled()) { writer.attributes("disabled", "disabled"); } validate.render(writer); resources.renderInformalParameters(writer); decorateInsideField(); writer.end(); // Now the trigger icon. writer.element( "img", "id", triggerId, "class", "t-calendar-trigger", "src", icon.toClientURL(), "alt", "[Show]"); writer.end(); // img writeTimeZone(writer); JSONObject spec = new JSONObject( "clientId", clientId, "clientDateFormat", formatConverter.convertToClient(format)) .put("time", time) .put("singleClick", singleClick); if (max != null) { spec.put("max", convertDateToClientTimeZone(max).getTime()); } if (min != null) { spec.put("min", convertDateToClientTimeZone(min).getTime()); } javascriptSupport.addInitializerCall("tapxDateField", spec); }