preloadScript.append(String.format(PRELOAD_TPL, id, converter.domToJson(value)));
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(); } }
case Node.DOCUMENT_NODE: case Node.ELEMENT_NODE: children.put(jsonFromElement((Element)child)); break; default:
case Node.DOCUMENT_NODE: case Node.ELEMENT_NODE: children.put(jsonFromElement((Element)child)); break; default:
case Node.DOCUMENT_NODE: case Node.ELEMENT_NODE: children.put(jsonFromElement((Element)child)); break; default:
preloadScript.append(String.format(PRELOAD_TPL, id, converter.domToJson(value)));
preloadScript.append(String.format(PRELOAD_TPL, id, converter.domToJson(value)));
@Before public void setUp() { Injector injector = Guice.createInjector(new ParseModule(), new PropertiesModule()); parser = injector.getInstance(GadgetHtmlParser.class); domImpl = injector.getInstance(DOMImplementation.class); doc = domImpl.createDocument(null, null, null); converter = new Converter(parser, domImpl); }
@Test public void convertMixedTreeWithIgnorables() throws Exception { String xml = "<b>Some ${viewer} content</b> <img/><!-- comment --><os:Html/>"; assertEquals( new JSONObject("{n:\"template\",a:[],c:[{n:\"b\",a:[],c:" + "[\"Some ${viewer} content\"]},\" \",{n:\"img\",a:[],c:[]}," + "{n:\"os:Html\",a:[],c:[]}]}").toString(), converter.domToJson(xml)); }
public boolean rewrite(HttpRequest request, HttpResponse original, MutableContent content) throws RewritingException { String mimeType = RewriterUtils.getMimeType(request, original); if (OS_TEMPLATE_MIME.equalsIgnoreCase(mimeType)) { content.setContent(converter.domToJson(content.getContent())); return true; } return false; }
@Before public void setUp() { Injector injector = Guice.createInjector(new ParseModule(), new PropertiesModule()); parser = injector.getInstance(GadgetHtmlParser.class); domImpl = injector.getInstance(DOMImplementation.class); doc = domImpl.createDocument(null, null, null); converter = new Converter(parser, domImpl); }
@Test public void convertMixedTreeWithIgnorables() throws Exception { String xml = "<b>Some ${viewer} content</b> <img/><!-- comment --><os:Html/>"; assertEquals( new JSONObject("{n:\"template\",a:[],c:[{n:\"b\",a:[],c:" + "[\"Some ${viewer} content\"]},\" \",{n:\"img\",a:[],c:[]}," + "{n:\"os:Html\",a:[],c:[]}]}").toString(), converter.domToJson(xml)); }
@Test public void convertSingleElement() throws Exception { String xml = "<os:elem id=\"id\" foo=\"bar\">String value</os:elem>"; assertEquals( new JSONObject("{n:\"template\",a:[],c:[{n:\"os:elem\",a:[{n:\"foo\",v:\"bar\"}," + "{n:\"id\",v:\"id\"}],c:[\"String value\"]}]}").toString(), converter.domToJson(xml)); }
public boolean rewrite(HttpRequest request, HttpResponse original, MutableContent content) throws RewritingException { String mimeType = RewriterUtils.getMimeType(request, original); if (OS_TEMPLATE_MIME.equalsIgnoreCase(mimeType)) { content.setContent(converter.domToJson(content.getContent())); return true; } return false; }
public boolean rewrite(HttpRequest request, HttpResponse original, MutableContent content) throws RewritingException { String mimeType = RewriterUtils.getMimeType(request, original); if (OS_TEMPLATE_MIME.equalsIgnoreCase(mimeType)) { content.setContent(converter.domToJson(content.getContent())); return true; } return false; }
private Converter mockConverter(String xml, String result, int times) { Converter converter = createMock(Converter.class); expect(converter.domToJson(xml)).andReturn(result).times(times); replay(converter); return converter; }
private Converter mockConverter(String xml, String result, int times) { Converter converter = createMock(Converter.class); expect(converter.domToJson(xml)).andReturn(result).times(times); replay(converter); return converter; }
@Test public void convertSingleElement() throws Exception { String xml = "<os:elem id=\"id\" foo=\"bar\">String value</os:elem>"; assertEquals( new JSONObject("{n:\"template\",a:[],c:[{n:\"os:elem\",a:[{n:\"foo\",v:\"bar\"}," + "{n:\"id\",v:\"id\"}],c:[\"String value\"]}]}").toString(), converter.domToJson(xml)); }
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(); } }
private Converter mockConverter(String xml, String result, int times) { Converter converter = createMock(Converter.class); expect(converter.domToJson(xml)).andReturn(result).times(times); replay(converter); return converter; }