@Override protected boolean removeAttr(Gadget gadget, Attr attr, Uri ctx) { if ("img".equalsIgnoreCase(attr.getOwnerElement().getNodeName()) && "src".equalsIgnoreCase(attr.getName())) { try { Uri uri = Uri.parse(attr.getValue()); ProxyUriManager.ProxyUri proxiedUri = ProxyUriManager.ProxyUri.fromList( gadget, ImmutableList.of(uri)).get(0); proxiedUri.setHtmlTagContext(attr.getOwnerElement().getNodeName().toLowerCase()); attr.setValue(imageRewriter.make(ImmutableList.of(proxiedUri), null) .get(0).toString()); } catch (IllegalArgumentException e) { // Invalid Uri, remove. return true; } } return false; } }
@Override protected boolean removeTag(Gadget gadget, Element elem, Uri ctx) { if (!elem.getNodeName().equalsIgnoreCase("link")) { return false; } boolean hasType = false; for (Attr attr : toList(elem.getAttributes())) { if ("rel".equalsIgnoreCase(attr.getName())) { hasType |= "stylesheet".equalsIgnoreCase(attr.getValue()); } else if ("type".equalsIgnoreCase(attr.getName())) { hasType |= "text/css".equalsIgnoreCase(attr.getValue()); } else if ("href".equalsIgnoreCase(attr.getName())) { try { ProxyUriManager.ProxyUri proxiedUri = ProxyUriManager.ProxyUri.fromList(gadget, ImmutableList.of(Uri.parse(attr.getValue()))).get(0); proxiedUri.setHtmlTagContext(elem.getNodeName().toLowerCase()); attr.setValue(cssImportRewriter.make(ImmutableList.of(proxiedUri), null) .get(0).toString()); } catch (IllegalArgumentException e) { return true; } } } return !hasType; }
@Override protected boolean removeTag(Gadget gadget, Element elem, Uri ctx) { if (!elem.getNodeName().equalsIgnoreCase("link")) { return false; } boolean hasType = false; for (Attr attr : toList(elem.getAttributes())) { if ("rel".equalsIgnoreCase(attr.getName())) { hasType |= "stylesheet".equalsIgnoreCase(attr.getValue()); } else if ("type".equalsIgnoreCase(attr.getName())) { hasType |= "text/css".equalsIgnoreCase(attr.getValue()); } else if ("href".equalsIgnoreCase(attr.getName())) { try { ProxyUriManager.ProxyUri proxiedUri = ProxyUriManager.ProxyUri.fromList(gadget, ImmutableList.of(Uri.parse(attr.getValue()))).get(0); proxiedUri.setHtmlTagContext(elem.getNodeName().toLowerCase()); attr.setValue(cssImportRewriter.make(ImmutableList.of(proxiedUri), null) .get(0).toString()); } catch (IllegalArgumentException e) { return true; } } } return !hasType; }
@Override protected boolean removeTag(Gadget gadget, Element elem, Uri ctx) { if (!elem.getNodeName().equalsIgnoreCase("link")) { return false; } boolean hasType = false; for (Attr attr : toList(elem.getAttributes())) { if ("rel".equalsIgnoreCase(attr.getName())) { hasType |= "stylesheet".equalsIgnoreCase(attr.getValue()); } else if ("type".equalsIgnoreCase(attr.getName())) { hasType |= "text/css".equalsIgnoreCase(attr.getValue()); } else if ("href".equalsIgnoreCase(attr.getName())) { try { ProxyUriManager.ProxyUri proxiedUri = ProxyUriManager.ProxyUri.fromList(gadget, ImmutableList.of(Uri.parse(attr.getValue()))).get(0); proxiedUri.setHtmlTagContext(elem.getNodeName().toLowerCase()); attr.setValue(cssImportRewriter.make(ImmutableList.of(proxiedUri), null) .get(0).toString()); } catch (IllegalArgumentException e) { return true; } } } return !hasType; }
private void checkValidate(String path, UriStatus status, String version) throws Exception { String host = "host.com"; // Pass null for status if version is null, since null version shouldn't result // in a check to the versioner. ProxyUriManager.Versioner versioner = makeVersioner(version == null ? null : status, version); DefaultProxyUriManager manager = makeManager(host, path, versioner); Gadget gadget = mockGadget(false, false); List<Uri> resources = ImmutableList.of(RESOURCE_1); List<Uri> uris = manager.make( ProxyUriManager.ProxyUri.fromList(gadget, resources), 123); assertEquals(1, uris.size()); ProxyUriManager.ProxyUri proxyUri = manager.process(uris.get(0)); assertEquals(RESOURCE_1, proxyUri.getResource()); assertEquals(CONTAINER, proxyUri.getContainer()); assertEquals(SPEC_URI.toString(), proxyUri.getGadget()); assertEquals(123, (int)proxyUri.getRefresh()); assertEquals(status, proxyUri.getStatus()); assertEquals(false, proxyUri.isDebug()); assertEquals(false, proxyUri.isNoCache()); }
private void checkValidate(String path, UriStatus status, String version) throws Exception { String host = "host.com"; // Pass null for status if version is null, since null version shouldn't result // in a check to the versioner. ProxyUriManager.Versioner versioner = makeVersioner(version == null ? null : status, version); DefaultProxyUriManager manager = makeManager(host, path, versioner); Gadget gadget = mockGadget(false, false); List<Uri> resources = ImmutableList.of(RESOURCE_1); List<Uri> uris = manager.make( ProxyUriManager.ProxyUri.fromList(gadget, resources), 123); assertEquals(1, uris.size()); ProxyUriManager.ProxyUri proxyUri = manager.process(uris.get(0)); assertEquals(RESOURCE_1, proxyUri.getResource()); assertEquals(CONTAINER, proxyUri.getContainer()); assertEquals(SPEC_URI.toString(), proxyUri.getGadget()); assertEquals(123, (int)proxyUri.getRefresh()); assertEquals(status, proxyUri.getStatus()); assertEquals(false, proxyUri.isDebug()); assertEquals(false, proxyUri.isNoCache()); }
private void checkValidate(String path, UriStatus status, String version) throws Exception { String host = "host.com"; // Pass null for status if version is null, since null version shouldn't result // in a check to the versioner. ProxyUriManager.Versioner versioner = makeVersioner(version == null ? null : status, version); DefaultProxyUriManager manager = makeManager(host, path, versioner); Gadget gadget = mockGadget(false, false); List<Uri> resources = ImmutableList.of(RESOURCE_1); List<Uri> uris = manager.make( ProxyUriManager.ProxyUri.fromList(gadget, resources), 123); assertEquals(1, uris.size()); ProxyUriManager.ProxyUri proxyUri = manager.process(uris.get(0)); assertEquals(RESOURCE_1, proxyUri.getResource()); assertEquals(CONTAINER, proxyUri.getContainer()); assertEquals(SPEC_URI.toString(), proxyUri.getGadget()); assertEquals(123, (int)proxyUri.getRefresh()); assertEquals(status, proxyUri.getStatus()); assertEquals(false, proxyUri.isDebug()); assertEquals(false, proxyUri.isNoCache()); }
@Override protected boolean removeAttr(Gadget gadget, Attr attr, Uri ctx) { if ("img".equalsIgnoreCase(attr.getOwnerElement().getNodeName()) && "src".equalsIgnoreCase(attr.getName())) { try { Uri uri = Uri.parse(attr.getValue()); ProxyUriManager.ProxyUri proxiedUri = ProxyUriManager.ProxyUri.fromList( gadget, ImmutableList.of(uri)).get(0); proxiedUri.setHtmlTagContext(attr.getOwnerElement().getNodeName().toLowerCase()); attr.setValue(imageRewriter.make(ImmutableList.of(proxiedUri), null) .get(0).toString()); } catch (IllegalArgumentException e) { // Invalid Uri, remove. return true; } } return false; } }
@Override protected boolean removeAttr(Gadget gadget, Attr attr, Uri ctx) { if ("img".equalsIgnoreCase(attr.getOwnerElement().getNodeName()) && "src".equalsIgnoreCase(attr.getName())) { try { Uri uri = Uri.parse(attr.getValue()); ProxyUriManager.ProxyUri proxiedUri = ProxyUriManager.ProxyUri.fromList( gadget, ImmutableList.of(uri)).get(0); proxiedUri.setHtmlTagContext(attr.getOwnerElement().getNodeName().toLowerCase()); attr.setValue(imageRewriter.make(ImmutableList.of(proxiedUri), null) .get(0).toString()); } catch (IllegalArgumentException e) { // Invalid Uri, remove. return true; } } return false; } }
private List<Uri> makeAndGetWithRefresh(String host, String path, boolean debug, boolean noCache, List<Uri> resources, Integer refresh, String... version) { ProxyUriManager.Versioner versioner = makeVersioner(null, version); DefaultProxyUriManager manager = makeManager(host, path, versioner); Gadget gadget = mockGadget(debug, noCache); return manager.make( ProxyUriManager.ProxyUri.fromList(gadget, resources), refresh); }
private List<Uri> makeAndGetWithRefresh(String host, String path, boolean debug, boolean noCache, List<Uri> resources, Integer refresh, String... version) { ProxyUriManager.Versioner versioner = makeVersioner(null, version); DefaultProxyUriManager manager = makeManager(host, path, versioner); Gadget gadget = mockGadget(debug, noCache); return manager.make( ProxyUriManager.ProxyUri.fromList(gadget, resources), refresh); }
private List<Uri> makeAndGetWithRefresh(String host, String path, boolean debug, boolean noCache, List<Uri> resources, Integer refresh, String... version) { ProxyUriManager.Versioner versioner = makeVersioner(null, version); DefaultProxyUriManager manager = makeManager(host, path, versioner); Gadget gadget = mockGadget(debug, noCache); return manager.make( ProxyUriManager.ProxyUri.fromList(gadget, resources), refresh); }