protected String getViewContent(Gadget gadget) { View currentView = gadget.getCurrentView(); return currentView.getContent(); } }
/** * Should the gadget content be sanitized on output * @return */ public boolean sanitizeOutput() { return (getCurrentView() != null && getCurrentView().getType() == View.ContentType.HTML_SANITIZED) || "1".equals(getContext().getParameter(UriCommon.Param.SANITIZE.getKey())); } }
@Override public String render(Gadget gadget) throws RenderingException { if (exception != null) { throw exception; } if (runtimeException != null) { throw runtimeException; } return gadget.getCurrentView().getContent(); } }
@Override public String render(Gadget gadget) throws RenderingException { if (exception != null) { throw exception; } if (runtimeException != null) { throw runtimeException; } return gadget.getCurrentView().getContent(); } }
protected void injectBaseTag(Gadget gadget, Node headTag) { GadgetContext context = gadget.getContext(); if (containerConfig.getBool(context.getContainer(), INSERT_BASE_ELEMENT_KEY)) { Uri base = gadget.getSpec().getUrl(); View view = gadget.getCurrentView(); if (view != null && view.getHref() != null) { base = view.getHref(); } Element baseTag = headTag.getOwnerDocument().createElement("base"); baseTag.setAttribute("href", base.toString()); headTag.insertBefore(baseTag, headTag.getFirstChild()); } }
/** * Convenience method that returns Map of features to load for gadget's current view * * @return a map of ModuleSpec/Require and ModuleSpec/Optional elements to Feature */ public Map<String, Feature> getViewFeatures() { View view = getCurrentView(); String name = (view == null) ? GadgetSpec.DEFAULT_VIEW : view.getName(); return spec.getModulePrefs().getViewFeatures(name); }
protected void injectBaseTag(Gadget gadget, Node headTag) { GadgetContext context = gadget.getContext(); if (containerConfig.getBool(context.getContainer(), INSERT_BASE_ELEMENT_KEY)) { Uri base = gadget.getSpec().getUrl(); View view = gadget.getCurrentView(); if (view != null && view.getHref() != null) { base = view.getHref(); } Element baseTag = headTag.getOwnerDocument().createElement("base"); baseTag.setAttribute("href", base.toString()); headTag.insertBefore(baseTag, headTag.getFirstChild()); } }
protected void injectBaseTag(Gadget gadget, Node headTag) { GadgetContext context = gadget.getContext(); if (containerConfig.getBool(context.getContainer(), INSERT_BASE_ELEMENT_KEY)) { Uri base = gadget.getSpec().getUrl(); View view = gadget.getCurrentView(); if (view != null && view.getHref() != null) { base = view.getHref(); } Element baseTag = headTag.getOwnerDocument().createElement("base"); baseTag.setAttribute("href", base.toString()); headTag.insertBefore(baseTag, headTag.getFirstChild()); } }
/** * Convenience function for getting the locale spec for the current context. * * Identical to: * Locale locale = gadget.getContext().getLocale(); * gadget.getSpec().getModulePrefs().getLocale(locale); */ public LocaleSpec getLocale() { View view = getCurrentView(); String viewName = (view == null) ? GadgetSpec.DEFAULT_VIEW : view.getName(); return spec.getModulePrefs().getLocale(context.getLocale(), viewName); }
@Test public void noSupportedViewHasNoCurrentView() throws Exception { expect(gadgetAdminStore.isWhitelisted(isA(String.class), isA(String.class))).andReturn(true); replay(); Gadget gadget = processor.process(makeContext("not-real-view")); assertNull(gadget.getCurrentView()); }
@Test public void noSupportedViewHasNoCurrentView() throws Exception { expect(gadgetAdminStore.isWhitelisted(isA(String.class), isA(String.class))).andReturn(true); replay(); Gadget gadget = processor.process(makeContext("not-real-view")); assertNull(gadget.getCurrentView()); }
@Test public void typeUrlViewsAreSkippedForSanitizedGadget() throws Exception { expect(gadgetAdminStore.isWhitelisted(isA(String.class), isA(String.class))) .andReturn(true).anyTimes(); replay(); Gadget gadget = processor.process(makeContext("url", SPEC_URL, true)); assertNull(gadget.getCurrentView()); gadget = processor.process(makeContext("html", SPEC_URL, true)); assertEquals(BASIC_HTML_CONTENT, gadget.getCurrentView().getContent()); }
@Test public void typeUrlViewsAreSkippedForSanitizedGadget() throws Exception { expect(gadgetAdminStore.isWhitelisted(isA(String.class), isA(String.class))) .andReturn(true).anyTimes(); replay(); Gadget gadget = processor.process(makeContext("url", SPEC_URL, true)); assertNull(gadget.getCurrentView()); gadget = processor.process(makeContext("html", SPEC_URL, true)); assertEquals(BASIC_HTML_CONTENT, gadget.getCurrentView().getContent()); }
@Test public void doViewAliasing() throws Exception { expect(gadgetAdminStore.isWhitelisted(isA(String.class), isA(String.class))).andReturn(true); replay(); Gadget gadget = processor.process(makeContext("aliased")); assertEquals(BASIC_HTML_CONTENT, gadget.getCurrentView().getContent()); }
@Test public void normalProcessing() throws Exception { expect(gadgetAdminStore.isWhitelisted(isA(String.class), isA(String.class))).andReturn(true); replay(); Gadget gadget = processor.process(makeContext("html")); assertEquals(BASIC_HTML_CONTENT, gadget.getCurrentView().getContent()); }
@Test public void doViewAliasing() throws Exception { expect(gadgetAdminStore.isWhitelisted(isA(String.class), isA(String.class))).andReturn(true); replay(); Gadget gadget = processor.process(makeContext("aliased")); assertEquals(BASIC_HTML_CONTENT, gadget.getCurrentView().getContent()); }
@Test public void normalProcessing() throws Exception { Gadget gadget = processor.process(makeContext("html")); assertEquals(BASIC_HTML_CONTENT, gadget.getCurrentView().getContent()); }
private void setupGadget(String gadgetXml) throws SpecParserException { gadgetSpec = new GadgetSpec(GADGET_URI, gadgetXml); gadget = new Gadget(); gadget.setSpec(gadgetSpec); gadget.setContext(new GadgetContext() {}); gadget.setCurrentView(gadgetSpec.getView("default")); content = new MutableContent(new NekoSimplifiedHtmlParser( new ParseModule.DOMImplementationProvider().get()), gadget.getCurrentView().getContent()); }
private void setupGadget(String gadgetXml) throws SpecParserException { gadgetSpec = new GadgetSpec(GADGET_URI, gadgetXml); gadget = new Gadget(); gadget.setSpec(gadgetSpec); gadget.setContext(new GadgetContext() {}); gadget.setCurrentView(gadgetSpec.getView("default")); content = new MutableContent(new NekoSimplifiedHtmlParser( new ParseModule.DOMImplementationProvider().get()), gadget.getCurrentView().getContent()); }
private void setupGadget(String gadgetXml) throws SpecParserException { gadgetSpec = new GadgetSpec(GADGET_URI, gadgetXml); gadget = new Gadget(); gadget.setSpec(gadgetSpec); gadget.setContext(new GadgetContext() {}); gadget.setCurrentView(gadgetSpec.getView("default")); content = new MutableContent(new NekoSimplifiedHtmlParser( new ParseModule.DOMImplementationProvider().get()), gadget.getCurrentView().getContent()); }