@Override public JsonElement serialize(Element src, Type typeOfSrc, JsonSerializationContext context) { if (src.getType() == ElementType.ATTACHMENT) { src = new Element(ElementType.IMAGE, createImageProperties(src.getProperties())); } return super.serialize(src, typeOfSrc, context); }
/** * Returns the named property of this element. * * @param name the name of the property. * @return the value of the property or null if the property was not found. */ public String getProperty(String name) { return getProperty(name, null); }
public void testIsAttachment() { assertFalse(new Element(ElementType.BUTTON).isAttachment()); assertFalse(new Element(ElementType.CHECK).isAttachment()); assertFalse(new Element(ElementType.INPUT).isAttachment()); assertFalse(new Element(ElementType.PASSWORD).isAttachment()); assertFalse(new Element(ElementType.LABEL).isAttachment()); assertFalse(new Element(ElementType.RADIO_BUTTON).isAttachment()); assertFalse(new Element(ElementType.RADIO_BUTTON_GROUP).isAttachment()); assertFalse(new Element(ElementType.TEXTAREA).isAttachment()); assertFalse(new Element(ElementType.GADGET).isAttachment()); assertFalse(new Element(ElementType.INLINE_BLIP).isAttachment()); assertFalse(new Element(ElementType.IMAGE).isAttachment()); assertTrue(new Element(ElementType.ATTACHMENT).isAttachment()); }
/** * Checks whether the given {@code element} is a match or not, by checking * the type and the properties. * * @param element the element to check. * @return {@code true} if the element type matches the target type, and * the all filters/restrictions are satisfied. */ private boolean match(Element element) { if (element.getType() != target) { return false; } if (restrictions == null) { return true; } for (Entry<String, String> entry : restrictions.entrySet()) { if (!entry.getValue().equals(element.getProperty(entry.getKey()))) { return false; } } return true; } }
@Override public XmlStringBuilder toXml(Element element) { XmlStringBuilder res = XmlStringBuilder.createEmpty(); if (element.getProperties().containsKey("attachmentId")) { if (element.getProperty(CAPTION_STR) != null) { res.append(XmlStringBuilder.createText(element.getProperty(CAPTION_STR)) .wrap("caption")); } return res.wrap("image", ATTACHMENT_STR, element.getProperty("attachmentId")); } return res; }
public void testElementTypeAndPropertyConstruction() { Map<String, String> properties = new HashMap<String, String>(); properties.put(NAME, VALUE); Element element = new Element(ElementType.GADGET, properties); assertEquals(ElementType.GADGET, element.getType()); assertEquals(1, element.getProperties().size()); assertEquals(VALUE, element.getProperty(NAME)); }
Preconditions.checkArgument(element.isGadget(), "Called with non-gadget element type %s", element.getType()); String url = element.getProperty("url"); if (url != null) { doc.setElementAttribute(existingElement, "url", url); for (Map.Entry<String, String> property : element.getProperties().entrySet()) {
/** * Inserts an inline blip at the given position. * * @param position the index to insert the inline blip at. This has to be * greater than 0. * @return an instance of {@link Blip} that represents the new inline blip. */ public Blip insertInlineBlip(int position) { if (position <= 0 || position > content.length()) { throw new IllegalArgumentException("Illegal inline blip position: " + position + ". Position has to be greater than 0 and less than or equal to length."); } // Shift the elements. shift(position, 1); content = content.substring(0, position) + " " + content.substring(position); // Generate the operation. Blip inlineBlip = operationQueue.insertInlineBlipToDocument(this, position); // Insert the inline blip element. Element element = new Element(ElementType.INLINE_BLIP); element.setProperty(INLINE_BLIP_ELEMENT_ID_KEY, inlineBlip.getBlipId()); elements.put(position, element); return inlineBlip; }
@Override public JsonElement serialize(Element src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty(TYPE_TAG, src.getType().toString()); JsonObject properties = new JsonObject(); if (src.isAttachment()) { Attachment attachment = (Attachment) src; if (attachment.hasData()) { for (Entry<String, String> entry : src.getProperties().entrySet()) {
updatedElements.add(new Element(existingElement.getType(), properties)); for (Entry<String, String> entry : properties.entrySet()) { existingElement.setProperty(entry.getKey(), entry.getValue());
public static XmlStringBuilder apiElementToXml(Element e) { ElementSerializer serializer = typeToSerializer.get(e.getType()); if (serializer == null) { return null; } return serializer.toXml(e); }
public void testIsFormElement() { assertTrue(new Element(ElementType.BUTTON).isFormElement()); assertTrue(new Element(ElementType.CHECK).isFormElement()); assertTrue(new Element(ElementType.INPUT).isFormElement()); assertTrue(new Element(ElementType.PASSWORD).isFormElement()); assertTrue(new Element(ElementType.LABEL).isFormElement()); assertTrue(new Element(ElementType.RADIO_BUTTON).isFormElement()); assertTrue(new Element(ElementType.RADIO_BUTTON_GROUP).isFormElement()); assertTrue(new Element(ElementType.TEXTAREA).isFormElement()); assertFalse(new Element(ElementType.GADGET).isFormElement()); assertFalse(new Element(ElementType.INLINE_BLIP).isFormElement()); assertFalse(new Element(ElementType.IMAGE).isFormElement()); assertFalse(new Element(ElementType.ATTACHMENT).isFormElement()); }
public void testIsGadget() { assertFalse(new Element(ElementType.BUTTON).isGadget()); assertFalse(new Element(ElementType.CHECK).isGadget()); assertFalse(new Element(ElementType.INPUT).isGadget()); assertFalse(new Element(ElementType.PASSWORD).isGadget()); assertFalse(new Element(ElementType.LABEL).isGadget()); assertFalse(new Element(ElementType.RADIO_BUTTON).isGadget()); assertFalse(new Element(ElementType.RADIO_BUTTON_GROUP).isGadget()); assertFalse(new Element(ElementType.TEXTAREA).isGadget()); assertTrue(new Element(ElementType.GADGET).isGadget()); assertFalse(new Element(ElementType.INLINE_BLIP).isGadget()); assertFalse(new Element(ElementType.IMAGE).isGadget()); assertFalse(new Element(ElementType.ATTACHMENT).isGadget()); }
public void testIsInlineBlip() { assertFalse(new Element(ElementType.BUTTON).isInlineBlip()); assertFalse(new Element(ElementType.CHECK).isInlineBlip()); assertFalse(new Element(ElementType.INPUT).isInlineBlip()); assertFalse(new Element(ElementType.PASSWORD).isInlineBlip()); assertFalse(new Element(ElementType.LABEL).isInlineBlip()); assertFalse(new Element(ElementType.RADIO_BUTTON).isInlineBlip()); assertFalse(new Element(ElementType.RADIO_BUTTON_GROUP).isInlineBlip()); assertFalse(new Element(ElementType.TEXTAREA).isInlineBlip()); assertFalse(new Element(ElementType.GADGET).isInlineBlip()); assertTrue(new Element(ElementType.INLINE_BLIP).isInlineBlip()); assertFalse(new Element(ElementType.IMAGE).isInlineBlip()); assertFalse(new Element(ElementType.ATTACHMENT).isInlineBlip()); }
public void testIsImage() { assertFalse(new Element(ElementType.BUTTON).isImage()); assertFalse(new Element(ElementType.CHECK).isImage()); assertFalse(new Element(ElementType.INPUT).isImage()); assertFalse(new Element(ElementType.PASSWORD).isImage()); assertFalse(new Element(ElementType.LABEL).isImage()); assertFalse(new Element(ElementType.RADIO_BUTTON).isImage()); assertFalse(new Element(ElementType.RADIO_BUTTON_GROUP).isImage()); assertFalse(new Element(ElementType.TEXTAREA).isImage()); assertFalse(new Element(ElementType.GADGET).isImage()); assertFalse(new Element(ElementType.INLINE_BLIP).isImage()); assertFalse(new Element(ElementType.ATTACHMENT).isImage()); assertTrue(new Element(ElementType.IMAGE).isImage()); }
/** * Updates elements in the document. * <b>Note</b>: Only gadget elements are supported, for now. * * @param operation the operation the operation that wants to update elements. * @param doc the document to update elements in. * @param view the {@link ApiView} of that document. * @param hitIterator the iterator over the places where to update elements. * @param modifyAction the action that specifies what to update. * @throws InvalidRequestException if something goes wrong. */ private void updateElement(OperationRequest operation, Document doc, ApiView view, DocumentHitIterator hitIterator, DocumentModifyAction modifyAction) throws InvalidRequestException { Range range = null; for (int index = 0; ((range = hitIterator.next()) != null); ++index) { Element element = modifyAction.getElement(index); if (element != null) { if (element.isGadget()) { int xmlStart = view.transformToXmlOffset(range.getStart()); Doc.E docElem = Point.elementAfter(doc, doc.locate(xmlStart)); updateExistingGadgetElement(doc, docElem, element); } else { // TODO (Yuri Z.) Updating other elements. throw new UnsupportedOperationException( "Can't update other elements than gadgets at the moment"); } } } }
Element element = modifyAction.getElement(valueIndex); if (element != null) { if (element.isGadget()) { Gadget gadget = (Gadget) element; XmlStringBuilder xml = } else if (element.isFormElement()) { XmlStringBuilder xml = ElementSerializer.apiElementToXml(element); LineContainers.appendLine(doc, xml);
@Override public Element fromXml(Document doc, E element, Wavelet wavelet) { return new Element(ElementType.INLINE_BLIP, ImmutableMap.of("id", doc.getAttribute(element, Blips.THREAD_INLINE_ANCHOR_ID_ATTR))); } });
private boolean elementMatch(Element element1, Element element2) { // TODO(ljvderijk): Elements should define their own equals method for each // different type, improvements to the ElementSerializer can also be made. return element1.getProperties().equals(element2.getProperties()); }
@Override public void setProperty(String name, String value) { if (name.equals(ATTACHMENT_ID) || name.equals(MIME_TYPE) || name.equals(ATTACHMENT_URL) || name.equals(DATA)) { throw new IllegalArgumentException(name + " can not be changed."); } super.setProperty(name, value); }