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); } } }
int location = doc.getLocation(Point.after(doc, line)); ConversationBlip newBlip = parentBlip.addReplyThread(location).appendBlip(); context.putBlip(blipData.getBlipId(), newBlip);
public void testAppendInlineBlip() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append the inline blip to the root blip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.DOCUMENT_APPEND_INLINE_BLIP, rootBlipId, Parameter.of(ParamsProperty.BLIP_DATA, blipData)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); ConversationBlip newBlip = checkAndGetNewBlip(context, conversation, response); Iterator<? extends LocatedReplyThread<? extends ObservableConversationThread>> it = conversation.getRootThread().getFirstBlip().locateReplyThreads().iterator(); LocatedReplyThread<? extends ObservableConversationThread> inlineReplyThread = it.next(); // The inline reply thread should be located just after the last line // element Document doc = conversation.getRootThread().getFirstBlip().getContent(); Doc.E lastLine = DocHelper.getLastElementWithTagName(doc, LineContainers.LINE_TAGNAME); int lastLineLocation = doc.getLocation(Point.after(doc, lastLine)); assertEquals("The inline reply was not located just after the last line element", lastLineLocation, inlineReplyThread.getLocation()); }
public void testAppendInlineBlip() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append the inline blip to the root blip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.DOCUMENT_APPEND_INLINE_BLIP, rootBlipId, Parameter.of(ParamsProperty.BLIP_DATA, blipData)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); ConversationBlip newBlip = checkAndGetNewBlip(context, conversation, response); Iterator<? extends LocatedReplyThread<? extends ObservableConversationThread>> it = conversation.getRootThread().getFirstBlip().locateReplyThreads().iterator(); LocatedReplyThread<? extends ObservableConversationThread> inlineReplyThread = it.next(); // The inline reply thread should be located just after the last line // element Document doc = conversation.getRootThread().getFirstBlip().getContent(); Doc.E lastLine = DocHelper.getLastElementWithTagName(doc, LineContainers.LINE_TAGNAME); int lastLineLocation = doc.getLocation(Point.after(doc, lastLine)); assertEquals("The inline reply was not located just after the last line element", lastLineLocation, inlineReplyThread.getLocation()); }
Document doc = rootBlip.getContent(); Doc.E lastLine = DocHelper.getLastElementWithTagName(doc, LineContainers.LINE_TAGNAME); int lastLineLocation = doc.getLocation(Point.after(doc, lastLine)); ObservableConversationBlip firstInlineBlip = rootBlip.addReplyThread(lastLineLocation).appendBlip();
Document doc = rootBlip.getContent(); Doc.E lastLine = DocHelper.getLastElementWithTagName(doc, LineContainers.LINE_TAGNAME); int lastLineLocation = doc.getLocation(Point.after(doc, lastLine)); ObservableConversationBlip firstInlineBlip = rootBlip.addReplyThread(lastLineLocation).appendBlip();