protected FormElement createFormElement(Document doc, E element) { return createFormElement(doc, element, null); }
private static String getAttachmentUrl(String dataDocument) { String rawURL = extractValue(dataDocument, ATTACHMENT_URL_PATTERN); return rawURL == null ? "" : rawURL.replace("&", "&"); }
public static Element xmlToApiElement(Document doc, Doc.E element, Wavelet wavelet) { if (element == null) { return null; } ElementSerializer serializer = tagToSerializer.get(doc.getTagName(element)); if (serializer == null) { return null; } return serializer.fromXml(doc, element, wavelet); }
public void insert(int pos, Element element) { XmlStringBuilder xml = ElementSerializer.apiElementToXml(element); int beforeSize = doc.size(); Pair<Integer, Integer> where = locate(pos);
private static Element createApiElementFromXml(String xml, Wavelet wavelet) { Document document = BasicFactories.documentProvider().parse( LineContainers.debugContainerWrap(xml)); Map<Integer, Element> elements = ElementSerializer.serialize(document, wavelet); assertEquals(2, elements.size()); return elements.get(1); }
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; }
public static XmlStringBuilder apiElementToXml(Element e) { ElementSerializer serializer = typeToSerializer.get(e.getType()); if (serializer == null) { return null; } return serializer.toXml(e); }
protected XmlStringBuilder wrapWithContent(String content, String... attributes) { if (Strings.isNullOrEmpty(content)) { return wrap(attributes); } return XmlStringBuilder.createText(content).wrap(tagName, attributes); }
/** * Test that the passed xml string deserializes into exactly two elements and * that the second element is the one we're after and serialized back to the * passed xml. */ private void convertBackAndForth(String xml) { Element element = createApiElementFromXml(xml); String resultXml = ElementSerializer.apiElementToXml(element).getXmlString(); assertEquals(xml, resultXml); }
private static Element createApiElementFromXml(String xml, Wavelet wavelet) { Document document = BasicFactories.documentProvider().parse( LineContainers.debugContainerWrap(xml)); Map<Integer, Element> elements = ElementSerializer.serialize(document, wavelet); assertEquals(2, elements.size()); return elements.get(1); }
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); } } }
/** * Test that the passed xml string deserializes into exactly two elements and * that the second element is the one we're after and serialized back to the * passed xml. */ private void convertBackAndForth(String xml) { Element element = createApiElementFromXml(xml); String resultXml = ElementSerializer.apiElementToXml(element).getXmlString(); assertEquals(xml, resultXml); }
@Override public BlipData toBlipData(ConversationBlip blip, Wavelet wavelet, EventMessageBundle eventMessageBundle) { ConversationBlip parentBlip = findBlipParent(blip); BlipData blipData = new BlipData(); blipData.setCreator(blip.getAuthorId().getAddress()); blipData.setContributors(idsToParticipantIdList(blip.getContributorIds())); blipData.setBlipId(blip.getId()); blipData.setLastModifiedTime(blip.getLastModifiedTime()); blipData.setVersion(blip.getLastModifiedVersion()); blipData.setParentBlipId(parentBlip == null ? null : parentBlip.getId()); blipData.setWaveId(ApiIdSerializer.instance().serialiseWaveId(wavelet.getWaveId())); blipData.setWaveletId(ApiIdSerializer.instance().serialiseWaveletId(wavelet.getId())); blipData.setChildBlipIds(toBlipIdList(findBlipChildren(blip))); ApiView apiView = new ApiView(blip.getContent(), wavelet); // Set content. blipData.setContent(apiView.apiContents()); // Set Annotations. blipData.setAnnotations(extractAnnotations(blip.getContent(), apiView)); // blip.getContent().rangedAnnotations(0, blip.getContent().size(), null), // Set Form Elements. blipData.setElements(ElementSerializer.serialize(blip.getContent(), wavelet)); return blipData; }
XmlStringBuilder xml = ElementSerializer.apiElementToXml(element); LineContainers.appendLine(doc, xml); } else {
public void testCheckboxSerialization() { String xml = "<check name=\"include\" submit=\"true\" value=\"false\"></check>"; FormElement element = (FormElement) createApiElementFromXml(xml); assertEquals("include", element.getName()); assertEquals("false", element.getValue()); assertEquals("true", element.getDefaultValue()); assertEquals(xml, ElementSerializer.apiElementToXml(element).getXmlString()); }
public void testCheckboxSerialization() { String xml = "<check name=\"include\" submit=\"true\" value=\"false\"></check>"; FormElement element = (FormElement) createApiElementFromXml(xml); assertEquals("include", element.getName()); assertEquals("false", element.getValue()); assertEquals("true", element.getDefaultValue()); assertEquals(xml, ElementSerializer.apiElementToXml(element).getXmlString()); }