public static Map<Integer, Element> serialize(Document doc, Wavelet wavelet) { Map<Integer, Element> result = Maps.newHashMap(); ApiView apiView = new ApiView(doc, wavelet); Doc.N node = Blips.getBody(doc); if (node != null) { // The node is the body; we're after its children node = doc.getFirstChild(node); } while (node != null) { E element = doc.asElement(node); if (element != null) { Element apiElement = xmlToApiElement(doc, element, wavelet); if (apiElement != null) { result.put(apiView.transformToTextOffset(doc.getLocation(element)), apiElement); } } node = doc.getNextSibling(node); } return result; }
private void parse(Document doc) { E bodyElement = Blips.getBody(doc); if (bodyElement != null) { N child = doc.getFirstChild(bodyElement); while (child != null) { T asText = doc.asText(child); int xmlPos = doc.getLocation(child); if (asText != null) { bits.add(new Bit(doc.getData(asText), xmlPos)); } else { E xmlElement = doc.asElement(child); if (xmlElement != null) { Element element = ElementSerializer.xmlToApiElement(doc, xmlElement, wavelet); // element can be null, but we still want to note that there // was something unknown. N next = doc.getNextSibling(child); int xmlSize; if (next != null) { xmlSize = doc.getLocation(next) - xmlPos; } else { // At the end of the document. XmlSize is the rest. xmlSize = doc.size() - 1 - xmlPos; } bits.add(new Bit(element, xmlPos, xmlSize)); } } child = doc.getNextSibling(child); } } }
E firstLineReached = null; outer: for (N node : DocIterate.deep(doc, Blips.getBody(doc), null)) { E el = doc.asElement(node); if (el == null) {