public RewriterResults rewrite(Gadget gadget, MutableContent content) { if (gadget.getSpec().getModulePrefs().getFeatures().ContainsKey("caja") || "1".Equals(gadget.getContext().getParameter("caja"))) { URI retrievedUri = gadget.getContext().getUrl(); UriCallback2 cb = new UriCallback2(retrievedUri); MessageQueue mq = new SimpleMessageQueue(); DefaultGadgetRewriter rw = new DefaultGadgetRewriter(mq); CharProducer input = CharProducer.Factory.create( new java.io.StringReader(content.getContent()), FilePosition.instance(new InputSource(new java.net.URI(retrievedUri.ToString())), 2, 1, 1)); java.lang.StringBuilder output = new java.lang.StringBuilder(); try { rw.rewriteContent(new java.net.URI(retrievedUri.ToString()), input, cb, output); } catch (GadgetRewriteException e) { throwCajolingException(e, mq); return(RewriterResults.notCacheable()); } catch (IOException e) { throwCajolingException(e, mq); return(RewriterResults.notCacheable()); } content.setContent(tameCajaClientApi() + output.ToString()); } return(null); }
public virtual RewriterResults rewrite(sRequest request, sResponse original, MutableContent content) { ByteArrayOutputStream baos = new ByteArrayOutputStream((content.getContent().Length * 110) / 100); OutputStreamWriter output = new OutputStreamWriter(baos); String mimeType = original.getHeader("Content-Type"); if (request.RewriteMimeType != null) { mimeType = request.RewriteMimeType; } GadgetSpec spec = null; if (request.Gadget != null) { spec = _specFactory.getGadgetSpec(request.Gadget.toJavaUri(), false); } if (rewrite(spec, request.getUri(), content, mimeType, output)) { content.setContent(Encoding.Default.GetString(baos.toByteArray())); return(RewriterResults.cacheableIndefinitely()); } return(null); }
public RewriterResults rewrite(sRequest req, sResponse resp, MutableContent content) { return(RewriterResults.cacheableIndefinitely()); }
public RewriterResults rewrite(Gadget gadget, MutableContent mutableContent) { Document document = mutableContent.getDocument(); Element head = (Element)DomUtil.getFirstNamedChildNode(document.getDocumentElement(), "head"); // Remove all the elements currently in head and add them back after we inject content NodeList children = head.getChildNodes(); List <Node> existingHeadContent = new List <Node>(children.getLength()); for (int i = 0; i < children.getLength(); i++) { existingHeadContent.Add(children.item(i)); } foreach (Node n in existingHeadContent) { head.removeChild(n); } // Only inject default styles if no doctype was specified. if (document.getDoctype() == null) { Element defaultStyle = document.createElement("style"); defaultStyle.setAttribute("type", "text/css"); head.appendChild(defaultStyle); defaultStyle.appendChild(defaultStyle.getOwnerDocument(). createTextNode(DEFAULT_CSS)); } InjectBaseTag(gadget, head); InjectFeatureLibraries(gadget, head); // This can be one script block. Element mainScriptTag = document.createElement("script"); InjectMessageBundles(gadget, mainScriptTag); InjectDefaultPrefs(gadget, mainScriptTag); InjectPreloads(gadget, mainScriptTag); // We need to inject our script before any developer scripts. head.appendChild(mainScriptTag); Element body = (Element)DomUtil.getFirstNamedChildNode(document.getDocumentElement(), "body"); LocaleSpec localeSpec = gadget.getLocale(); if (localeSpec != null) { body.setAttribute("dir", localeSpec.getLanguageDirection()); } // re append head content foreach (Node node in existingHeadContent) { head.appendChild(node); } InjectOnLoadHandlers(body); mutableContent.documentChanged(); return(RewriterResults.notCacheable()); }