/** * Retrieves the object contents in parsed form, if a * {@code GadgetHtmlParser} is configured and is able to parse the string * contents appropriately. To modify the object's * contents by parse tree after setting new String contents, * this method must be called again. However, this practice is highly * discouraged, as parsing a tree from String is a costly operation and should * be done at most once per rewrite. */ public Document getDocument() { // TODO - Consider actually imposing one parse limit on rewriter pipeline if (document != null) { return document; } try { document = contentParser.parseDom(getContent()); document.setUserData(MUTABLE_CONTENT_LISTENER, this, null); } catch (GadgetException e) { logger.log(Level.WARNING, "Got GadgetException when parsing content", e); return null; } return document; }
boolean shouldCache = shouldCache(); String key = null; if (shouldCache) { DocumentFragment cachedFragment = fragmentCache.getElement(key); if (cachedFragment != null) { copyFragment(cachedFragment, result); return; fragment = parseFragmentImpl(source); } catch (DOMException e) { appendParseException(result, e); return; reprocessScriptForOpenSocial(fragment); if (shouldCache) { fragmentCache.addElement(key, fragment); copyFragment(fragment, result);
String key = null; boolean shouldCache = shouldCache(); if (shouldCache) { document = parseDomImpl(source); } catch (DOMException e) { document = errorDom(e); HtmlSerialization.attach(document, serializerProvider.get(), source); return document; } else { transferChildren(head, child); transferChildren(body, child); prependToNode(head, beforeHead); prependToNode(body, beforeBody); Node bodyKid = bodyKids.item(i); if (bodyKid.getNodeType() == Node.ELEMENT_NODE && isStyleElement((Element)bodyKid)) { styleNodes.add(bodyKid); reprocessScriptForOpenSocial(html);
public String domToJson(String xml) { try { Document doc = domImpl.createDocument(null, null, null); Element container = doc.createElement("template"); parser.parseFragment(xml, container); return jsonFromElement(container).toString(); } catch (GadgetException e) { return jsonError("Gadget Exception: " + e).toString(); } catch (JSONException e) { return jsonError("JSON Exception: " + e).toString(); } }
protected Document errorDom(DOMException e) { // Create a bare-bones DOM whose body is just error text. // We do this to echo information to the developer that originally // supplied the data, since doing so is more useful than simply // returning a black-box HTML error code stemming from an NPE or other condition downstream. // The method is protected to allow overriding of this behavior. Document doc = documentFactory.createDocument(null, null, null); Node html = doc.createElement("html"); html.appendChild(doc.createElement("head")); Node body = doc.createElement("body"); appendParseException(body, e); html.appendChild(body); doc.appendChild(html); return doc; }
next.removeChild(next.getFirstChild()); DocumentFragment osFragment = parseFragmentImpl(sb.toString()); while (osFragment.hasChildNodes()) { Node osKid = osFragment.removeChild(osFragment.getFirstChild());
public String domToJson(String xml) { try { Document doc = domImpl.createDocument(null, null, null); Element container = doc.createElement("template"); parser.parseFragment(xml, container); return jsonFromElement(container).toString(); } catch (GadgetException e) { return jsonError("Gadget Exception: " + e).toString(); } catch (JSONException e) { return jsonError("JSON Exception: " + e).toString(); } }
protected Document errorDom(DOMException e) { // Create a bare-bones DOM whose body is just error text. // We do this to echo information to the developer that originally // supplied the data, since doing so is more useful than simply // returning a black-box HTML error code stemming from an NPE or other condition downstream. // The method is protected to allow overriding of this behavior. Document doc = documentFactory.createDocument(null, null, null); Node html = doc.createElement("html"); html.appendChild(doc.createElement("head")); Node body = doc.createElement("body"); appendParseException(body, e); html.appendChild(body); doc.appendChild(html); return doc; }
next.removeChild(next.getFirstChild()); DocumentFragment osFragment = parseFragmentImpl(sb.toString()); while (osFragment.hasChildNodes()) { Node osKid = osFragment.removeChild(osFragment.getFirstChild());
/** * Retrieves the object contents in parsed form, if a * {@code GadgetHtmlParser} is configured and is able to parse the string * contents appropriately. To modify the object's * contents by parse tree after setting new String contents, * this method must be called again. However, this practice is highly * discouraged, as parsing a tree from String is a costly operation and should * be done at most once per rewrite. */ public Document getDocument() { // TODO - Consider actually imposing one parse limit on rewriter pipeline if (document != null) { return document; } try { document = contentParser.parseDom(getContent()); document.setUserData(MUTABLE_CONTENT_LISTENER, this, null); } catch (GadgetException e) { logger.log(Level.WARNING, "Got GadgetException when parsing content", e); return null; } return document; }
String key = null; boolean shouldCache = shouldCache(); if (shouldCache) { document = parseDomImpl(source); } catch (DOMException e) { document = errorDom(e); HtmlSerialization.attach(document, serializerProvider.get(), source); return document; } else { transferChildren(head, child); transferChildren(body, child); prependToNode(head, beforeHead); prependToNode(body, beforeBody); Node bodyKid = bodyKids.item(i); if (bodyKid.getNodeType() == Node.ELEMENT_NODE && isStyleElement((Element)bodyKid)) { styleNodes.add(bodyKid); reprocessScriptForOpenSocial(html);
boolean shouldCache = shouldCache(); String key = null; if (shouldCache) { DocumentFragment cachedFragment = fragmentCache.getElement(key); if (cachedFragment != null) { copyFragment(cachedFragment, result); return; fragment = parseFragmentImpl(source); } catch (DOMException e) { appendParseException(result, e); return; reprocessScriptForOpenSocial(fragment); if (shouldCache) { fragmentCache.addElement(key, fragment); copyFragment(fragment, result);
public String domToJson(String xml) { try { Document doc = domImpl.createDocument(null, null, null); Element container = doc.createElement("template"); parser.parseFragment(xml, container); return jsonFromElement(container).toString(); } catch (GadgetException e) { return jsonError("Gadget Exception: " + e).toString(); } catch (JSONException e) { return jsonError("JSON Exception: " + e).toString(); } }
protected Document errorDom(DOMException e) { // Create a bare-bones DOM whose body is just error text. // We do this to echo information to the developer that originally // supplied the data, since doing so is more useful than simply // returning a black-box HTML error code stemming from an NPE or other condition downstream. // The method is protected to allow overriding of this behavior. Document doc = documentFactory.createDocument(null, null, null); Node html = doc.createElement("html"); html.appendChild(doc.createElement("head")); Node body = doc.createElement("body"); appendParseException(body, e); html.appendChild(body); doc.appendChild(html); return doc; }
DocumentFragment osFragment = parseFragmentImpl(sb.toString()); while (osFragment.hasChildNodes()) { Node osKid = osFragment.removeChild(osFragment.getFirstChild());
private Element parseTemplate(String markup) throws GadgetException { String content = "<script type=\"text/os-template\" xmlns:foo=\"" + TEST_NS + "\" xmlns:os=\"" + TagHandler.OPENSOCIAL_NAMESPACE + "\">" + markup + "</script>"; Document document = parser.parseDom(content); return SocialDataTags.getTags(document, SocialDataTags.OSML_TEMPLATE_TAG).get(0); }
String key = null; boolean shouldCache = shouldCache(); if (shouldCache) { document = parseDomImpl(source); } catch (DOMException e) { document = errorDom(e); HtmlSerialization.attach(document, serializerProvider.get(), source); return document; } else { transferChildren(head, child); transferChildren(body, child); prependToNode(head, beforeHead); prependToNode(body, beforeBody); Node bodyKid = bodyKids.item(i); if (bodyKid.getNodeType() == Node.ELEMENT_NODE && isStyleElement((Element)bodyKid)) { styleNodes.add(bodyKid); reprocessScriptForOpenSocial(html);
boolean shouldCache = shouldCache(); String key = null; if (shouldCache) { DocumentFragment cachedFragment = fragmentCache.getElement(key); if (cachedFragment != null) { copyFragment(cachedFragment, result); return; fragment = parseFragmentImpl(source); } catch (DOMException e) { appendParseException(result, e); return; reprocessScriptForOpenSocial(fragment); if (shouldCache) { fragmentCache.addElement(key, fragment); copyFragment(fragment, result);
public void process(Node result, Element tag, TemplateProcessor processor) { String code = getValueFromTag(tag, ATTR_CODE, processor, String.class); if ((code == null) || "".equals(code)) { return; } try { parser.parseFragment(code, result); } catch (GadgetException ge) { try { StringBuilder sb = new StringBuilder("Error: "); HtmlSerialization.printEscapedText(ge.getMessage(), sb); Node comment = result.getOwnerDocument().createComment(sb.toString()); result.appendChild(comment); } catch (IOException e) { throw new RuntimeException(e); } } } }
/** * Retrieves the object contents in parsed form, if a * {@code GadgetHtmlParser} is configured and is able to parse the string * contents appropriately. To modify the object's * contents by parse tree after setting new String contents, * this method must be called again. However, this practice is highly * discouraged, as parsing a tree from String is a costly operation and should * be done at most once per rewrite. */ public Document getDocument() { // TODO - Consider actually imposing one parse limit on rewriter pipeline if (document != null) { return document; } try { document = contentParser.parseDom(getContent()); document.setUserData(MUTABLE_CONTENT_LISTENER, this, null); } catch (GadgetException e) { if (LOG.isLoggable(Level.WARNING)) { LOG.logp(Level.WARNING, classname, "getDocument", MessageKeys.EXCEPTION_PARSING_CONTENT); LOG.log(Level.WARNING, e.getMessage(), e); } return null; } return document; }