Preconditions.checkArgument(xmlOffset <= doc.size());
/** * Erases the content of the provided document. * * @param wavelet the wavelet containing the document to erase * @param documentId the id of the document to erase */ public static void clearDocument(Wavelet wavelet, String documentId) { Document document = wavelet.getDocument(documentId); if (document.size() != 0) { document.emptyElement(document.getDocumentElement()); } }
public void insert(int pos, Element element) { XmlStringBuilder xml = ElementSerializer.apiElementToXml(element); int beforeSize = doc.size(); Pair<Integer, Integer> where = locate(pos); int index = where.first; Point<Doc.N> point = doc.locate(last.xmlPos + last.xmlSize); doc.insertXml(point, xml); bits.add(new Bit(element, last.xmlPos + last.xmlSize, doc.size() - beforeSize)); return; Point<Doc.N> point = doc.locate(bit.xmlPos + offset); doc.insertXml(point, xml); int xmlSize = doc.size() - beforeSize; if (bit.string != null && offset > 0) { shift(index + 1, xmlSize);
/** * Deletes the content of this blip's document. */ void clearContent() { if (blip.getContent().size() != 0) { blip.getContent().emptyElement(blip.getContent().getDocumentElement()); } }
/** * Extracts all annotations that span inside the body tag of the given * document. * * @param doc the document to get the annotations from. * @param apiView provides a utility function to convert an xml offset point * into text offset. * @return the annotations represented as a list of {@link Annotation}. */ private static List<Annotation> extractAnnotations(Document doc, ApiView apiView) { List<Annotation> result = Lists.newArrayList(); for (RangedAnnotation<String> annotation : doc.rangedAnnotations(0, doc.size(), null)) { if (annotation.key() != null && annotation.value() != null) { int start = apiView.transformToTextOffset(annotation.start()); int end = apiView.transformToTextOffset(annotation.end()); result.add(new Annotation(annotation.key(), annotation.value(), new Range(start, end))); } } 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); } } }
void populate(ConversationThread thread, FakeThreadView threadUi) { for (BlipBuilder blipBuilder : blipBuilders) { ConversationBlip blip = thread.appendBlip(); blip.getContent().insertText(blip.getContent().size() - 1, "Blip " + blipCount++); blipBuilder.populate(blip, threadUi.insertBlipBefore(null, blip)); } }
void populate(ConversationThread thread, FakeThreadView threadUi) { for (BlipBuilder blipBuilder : blipBuilders) { ConversationBlip blip = thread.appendBlip(); blip.getContent().insertText(blip.getContent().size() - 1, "Blip " + blipCount++); blipBuilder.populate(blip, threadUi.insertBlipBefore(null, blip)); } }
void populate(ConversationBlip blip, FakeBlipView blipUi) { for (ThreadBuilder threadBuilder : unanchored) { ConversationThread thread = blip.addReplyThread(); threadBuilder.populate(thread, blipUi.insertDefaultAnchorBefore(null, thread).getThread()); } for (ThreadBuilder threadBuilder : anchored) { ConversationThread thread = blip.addReplyThread(blip.getContent().size() - 1); FakeAnchor anchor = blipUi.insertDefaultAnchorBefore(null, thread); FakeInlineThreadView threadUi = anchor.getThread(); threadBuilder.populate(thread, threadUi); anchor.detach(threadUi); blipUi.getMeta().createInlineAnchorBefore(null, thread).attach(threadUi); } for (ConversationBuilder conversationBuilder : privates) { Conversation conversation = wave.createConversation(); conversation.setAnchor(blip.getConversation().createAnchor(blip)); assert conversation.hasAnchor(); conversationBuilder.populate( conversation, blipUi.insertConversationBefore(null, conversation)); } }
void populate(ConversationBlip blip, FakeBlipView blipUi) { for (ThreadBuilder threadBuilder : unanchored) { ConversationThread thread = blip.addReplyThread(); threadBuilder.populate(thread, blipUi.insertDefaultAnchorBefore(null, thread).getThread()); } for (ThreadBuilder threadBuilder : anchored) { ConversationThread thread = blip.addReplyThread(blip.getContent().size() - 1); FakeAnchor anchor = blipUi.insertDefaultAnchorBefore(null, thread); FakeInlineThreadView threadUi = anchor.getThread(); threadBuilder.populate(thread, threadUi); anchor.detach(threadUi); blipUi.getMeta().createInlineAnchorBefore(null, thread).attach(threadUi); } for (ConversationBuilder conversationBuilder : privates) { Conversation conversation = wave.createConversation(); conversation.setAnchor(blip.getConversation().createAnchor(blip)); assert conversation.hasAnchor(); conversationBuilder.populate( conversation, blipUi.insertConversationBefore(null, conversation)); } }