public MessageBundle getBundle(GadgetSpec spec, Locale locale, bool ignoreCache) { MessageBundle parent = getParentBundle(spec, locale, ignoreCache); MessageBundle child = null; LocaleSpec localeSpec = spec.getModulePrefs().getLocale(locale); if (localeSpec == null) { return(parent ?? MessageBundle.EMPTY); } Uri messages = localeSpec.getMessages(); if (messages == null || messages.ToString().Length == 0) { child = localeSpec.getMessageBundle(); } else { child = fetchBundle(localeSpec, ignoreCache); } return(new MessageBundle(parent, child)); }
protected MessageBundle fetchBundle(LocaleSpec locale, bool ignoreCache) { Uri url = locale.getMessages(); sRequest request = new sRequest(url).setIgnoreCache(ignoreCache); // Since we don't allow any variance in cache time, we should just force the cache time // globally. This ensures propagation to shared caches when this is set. request.setCacheTtl((int)(refresh / 1000)); sResponse response = fetcher.fetch(request); if (response.getHttpStatusCode() != (int)HttpStatusCode.OK) { throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, "Unable to retrieve message bundle xml. HTTP error " + response.getHttpStatusCode()); } MessageBundle bundle = new MessageBundle(locale, response.responseString); return(bundle); }
/** * Retrieve the MessageBundle for the given LocaleSpec from the network or cache. */ protected abstract MessageBundle fetchBundle(LocaleSpec locale, bool ignoreCache);
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()); }