Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: test/com/dom_distiller/client/SimpleContentHandler.java

Issue 296113004: Start using computed style instead of default tag actions. (Closed) Base URL: https://code.google.com/p/dom-distiller/@master
Patch Set: Fixed nit. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/com/dom_distiller/client/DomToSaxVisitorTest.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package com.dom_distiller.client; 5 package com.dom_distiller.client;
6 6
7 import com.dom_distiller.client.sax.Attributes; 7 import com.dom_distiller.client.sax.Attributes;
8 import com.dom_distiller.client.sax.ContentHandler; 8 import com.dom_distiller.client.sax.ContentHandler;
9 import com.google.gwt.core.client.JsArray;
10 import com.google.gwt.dom.client.Element;
11 import com.google.gwt.dom.client.Node;
9 12
10 /** 13 /**
11 * This is a simple SAX content handler that converts sax events to an xml docum ent. It only handles 14 * This is a simple SAX content handler that converts sax events to an xml docum ent. It only handles
12 * a small subset of those events. 15 * a small subset of those events.
13 */ 16 */
14 class SimpleContentHandler implements ContentHandler { 17 class SimpleContentHandler implements ContentHandler {
15 18
19 private StringBuilder documentStringBuilder;
20
16 SimpleContentHandler() { 21 SimpleContentHandler() {
17 documentStringBuilder = new StringBuilder(); 22 documentStringBuilder = new StringBuilder();
18 } 23 }
19 24
20 String getDocumentString() { 25 String getDocumentString() {
21 return documentStringBuilder.toString(); 26 return documentStringBuilder.toString();
22 } 27 }
23 28
24 @Override 29 @Override
25 public void endDocument() {} 30 public void endDocument() {}
26 31
27 @Override 32 @Override
28 public void ignorableWhitespace(char[] ch, int start, int length) {} 33 public void ignorableWhitespace(char[] ch, int start, int length) {}
29 34
30 @Override 35 @Override
31 public void startDocument() {} 36 public void startDocument() {}
32 37
33 @Override 38 @Override
34 public void startElement(String uri, String localName, String qName, Attribu tes atts) { 39 public void startElement(Element element, Attributes atts) {
35 documentStringBuilder.append("<" + localName); 40 documentStringBuilder.append("<");
36 for (int i = 0; i < atts.getLength(); i++) { 41 documentStringBuilder.append(element.getTagName());
42 JsArray<Node> attributes = DomUtil.getAttributes(element);
43 for (int i = 0; i < attributes.length(); i++) {
44 Node node = attributes.get(i);
37 documentStringBuilder.append(" "); 45 documentStringBuilder.append(" ");
38 documentStringBuilder.append(atts.getLocalName(i)); 46 documentStringBuilder.append(node.getNodeName());
39 documentStringBuilder.append("=\""); 47 documentStringBuilder.append("=\"");
40 documentStringBuilder.append(atts.getValue(i)); 48 documentStringBuilder.append(node.getNodeValue());
41 documentStringBuilder.append("\""); 49 documentStringBuilder.append("\"");
42
43 } 50 }
44 documentStringBuilder.append(">"); 51 documentStringBuilder.append(">");
45 } 52 }
46 53
47 @Override 54 @Override
48 public void endElement(String uri, String localName, String qName) { 55 public void endElement(Element element) {
49 documentStringBuilder.append("</" + localName + ">"); 56 documentStringBuilder.append("</" + element.getTagName() + ">");
50 } 57 }
51 58
52 @Override 59 @Override
53 public void characters(char[] ch, int start, int length) { 60 public void characters(char[] ch, int start, int length) {
54 documentStringBuilder.append(ch, start, length); 61 documentStringBuilder.append(ch, start, length);
55 } 62 }
56
57 private StringBuilder documentStringBuilder;
58 } 63 }
OLDNEW
« no previous file with comments | « test/com/dom_distiller/client/DomToSaxVisitorTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698