@Test public void getHtmlForSpreadsheet() { when(context.getParameters()).thenReturn("https: assertEquals("<iframe class=\"googledocs-document\" src=\"" + "https: "\" allowfullscreen=\"true\" mozallowfullscreen=\"true\" webkitallowfullscreen=\"true\"></iframe>", runnable.getHtml(context)); }
@Override public String getHtml(IMacroContext macroContext) { String macroParams = macroContext.getParameters(); String googleUrl = StringUtils.substringBefore(macroParams, " ").trim(); String width = StringUtils.substringAfter(macroParams, " ").trim(); UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(googleUrl).build(); String path = uriComponents.getPath(); MultiValueMap<String, String> params = uriComponents.getQueryParams(); if (path.startsWith("/spreadsheet/")) { String key = params.get("key").get(0); UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("key", key) .queryParam("output", "html") .queryParam("widget", "true") .build(); return buildIframe(components); } else if (path.startsWith("/document/")) { String id = params.get("id").get(0); UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("id", id) .queryParam("embedded", "true") .build(); return buildIframe(components); } else if (path.startsWith("/presentation/")) { String id = params.get("id").get(0); UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("id", id) .queryParam("start", "false") .queryParam("loop", "false") .queryParam("delayms", String.valueOf(TimeUnit.MILLISECONDS.convert(3, TimeUnit.SECONDS))) .build(); return buildIframe(components); } else if (path.startsWith("/drawings/")) { String id = params.get("id").get(0); if (StringUtils.isBlank(width)) { width = "960"; } UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("id", id) .queryParam("w", width) .build(); return buildImg(components); } else { return null; } }
GoogleDocsMacro implements IMacroRunnable { @Override public String getHtml(IMacroContext macroContext) { String macroParams = macroContext.getParameters(); String googleUrl = StringUtils.substringBefore(macroParams, " ").trim(); String width = StringUtils.substringAfter(macroParams, " ").trim(); UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(googleUrl).build(); String path = uriComponents.getPath(); MultiValueMap<String, String> params = uriComponents.getQueryParams(); if (path.startsWith("/spreadsheet/")) { String key = params.get("key").get(0); UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("key", key) .queryParam("output", "html") .queryParam("widget", "true") .build(); return buildIframe(components); } else if (path.startsWith("/document/")) { String id = params.get("id").get(0); UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("id", id) .queryParam("embedded", "true") .build(); return buildIframe(components); } else if (path.startsWith("/presentation/")) { String id = params.get("id").get(0); UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("id", id) .queryParam("start", "false") .queryParam("loop", "false") .queryParam("delayms", String.valueOf(TimeUnit.MILLISECONDS.convert(3, TimeUnit.SECONDS))) .build(); return buildIframe(components); } else if (path.startsWith("/drawings/")) { String id = params.get("id").get(0); if (StringUtils.isBlank(width)) { width = "960"; } UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("id", id) .queryParam("w", width) .build(); return buildImg(components); } else { return null; } } }
GoogleDocsMacro implements IMacroRunnable { @Override public String getHtml(IMacroContext macroContext) { String macroParams = macroContext.getParameters(); String googleUrl = StringUtils.substringBefore(macroParams, " ").trim(); String width = StringUtils.substringAfter(macroParams, " ").trim(); UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(googleUrl).build(); String path = uriComponents.getPath(); MultiValueMap<String, String> params = uriComponents.getQueryParams(); if (path.startsWith("/spreadsheet/")) { String key = params.get("key").get(0); UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("key", key) .queryParam("output", "html") .queryParam("widget", "true") .build(); return buildIframe(components); } else if (path.startsWith("/document/")) { String id = params.get("id").get(0); UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("id", id) .queryParam("embedded", "true") .build(); return buildIframe(components); } else if (path.startsWith("/presentation/")) { String id = params.get("id").get(0); UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("id", id) .queryParam("start", "false") .queryParam("loop", "false") .queryParam("delayms", String.valueOf(TimeUnit.MILLISECONDS.convert(3, TimeUnit.SECONDS))) .build(); return buildIframe(components); } else if (path.startsWith("/drawings/")) { String id = params.get("id").get(0); if (StringUtils.isBlank(width)) { width = "960"; } UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("id", id) .queryParam("w", width) .build(); return buildImg(components); } else { return null; } }  }
GoogleDocsMacro implements IMacroRunnable { @Override public String getHtml(IMacroContext macroContext) { String macroParams = macroContext.getParameters(); String googleUrl = StringUtils.substringBefore(macroParams, " ").trim(); String width = StringUtils.substringAfter(macroParams, " ").trim(); UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(googleUrl).build(); String path = uriComponents.getPath(); MultiValueMap<String, String> params = uriComponents.getQueryParams(); if (path.startsWith("/spreadsheet/")) { String key = params.get("key").get(0); UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("key", key) .queryParam("output", "html") .queryParam("widget", "true") .build(); return buildIframe(components); } else if (path.startsWith("/document/")) { String id = params.get("id").get(0); UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("id", id) .queryParam("embedded", "true") .build(); return buildIframe(components); } else if (path.startsWith("/presentation/")) { String id = params.get("id").get(0); UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("id", id) .queryParam("start", "false") .queryParam("loop", "false") .queryParam("delayms", String.valueOf(TimeUnit.MILLISECONDS.convert(3, TimeUnit.SECONDS))) .build(); return buildIframe(components); } else if (path.startsWith("/drawings/")) { String id = params.get("id").get(0); if (StringUtils.isBlank(width)) { width = "960"; } UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("id", id) .queryParam("w", width) .build(); return buildImg(components); } else { return null; } }  @Override String getHtml(IMacroContext macroContext); @Override String cleanupHtml(String html); }
GoogleDocsMacro implements IMacroRunnable { @Override public String getHtml(IMacroContext macroContext) { String macroParams = macroContext.getParameters(); String googleUrl = StringUtils.substringBefore(macroParams, " ").trim(); String width = StringUtils.substringAfter(macroParams, " ").trim(); UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(googleUrl).build(); String path = uriComponents.getPath(); MultiValueMap<String, String> params = uriComponents.getQueryParams(); if (path.startsWith("/spreadsheet/")) { String key = params.get("key").get(0); UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("key", key) .queryParam("output", "html") .queryParam("widget", "true") .build(); return buildIframe(components); } else if (path.startsWith("/document/")) { String id = params.get("id").get(0); UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("id", id) .queryParam("embedded", "true") .build(); return buildIframe(components); } else if (path.startsWith("/presentation/")) { String id = params.get("id").get(0); UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("id", id) .queryParam("start", "false") .queryParam("loop", "false") .queryParam("delayms", String.valueOf(TimeUnit.MILLISECONDS.convert(3, TimeUnit.SECONDS))) .build(); return buildIframe(components); } else if (path.startsWith("/drawings/")) { String id = params.get("id").get(0); if (StringUtils.isBlank(width)) { width = "960"; } UriComponents components = UriComponentsBuilder.fromHttpUrl("https: .queryParam("id", id) .queryParam("w", width) .build(); return buildImg(components); } else { return null; } }  @Override String getHtml(IMacroContext macroContext); @Override String cleanupHtml(String html);  }