http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/data/DocumentHitIterator.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/data/DocumentHitIterator.java b/src/com/google/wave/api/data/DocumentHitIterator.java deleted file mode 100644 index 42a03c6..0000000 --- a/src/com/google/wave/api/data/DocumentHitIterator.java +++ /dev/null @@ -1,177 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package com.google.wave.api.data; - -import com.google.common.base.Preconditions; -import com.google.wave.api.ElementType; -import com.google.wave.api.Range; - -import java.util.Map; -import java.util.Map.Entry; - -/** - * A interface encapsulating iterating through a document. - * - * <p> - * At some point we could consider turning this into an actual Iterable/Iterator - * thing - * - */ -public interface DocumentHitIterator { - - /** - * @returns the next range yielded by this Iterator or null if we're done. - */ - Range next(); - - /** - * Notify the iterator that the underlying document has changed; a change with - * size delta has been applied at where. - */ - void shift(int where, int delta); - - /** - * Singleshot returns a single range. - */ - class Singleshot implements DocumentHitIterator { - - private final Range range; - private boolean called; - - public Singleshot(Range range) { - this.called = false; - this.range = range; - } - - @Override - public Range next() { - if (called) { - return null; - } - called = true; - return this.range; - } - - @Override - public void shift(int where, int delta) { - } - } - - /** - * TextMatcher yields all ranges in the document matching the searched for - * string. - */ - class TextMatcher implements DocumentHitIterator { - - private final ApiView apiView; - private final String searchFor; - private int from; - private int hitsLeft; - - public TextMatcher(ApiView apiView, String searchFor, int maxHits) { - Preconditions.checkNotNull(apiView, "Api view must not be null"); - Preconditions.checkNotNull(searchFor, "The string to search for must not be null"); - - this.apiView = apiView; - this.searchFor = searchFor; - this.from = -1; - this.hitsLeft = maxHits; - } - - @Override - public Range next() { - if (hitsLeft == 0) { - return null; - } - hitsLeft--; - String searchIn = apiView.apiContents(); - int next = searchIn.indexOf(searchFor, from + 1); - if (next == -1) { - return null; - } - from = next; - return new Range(from, from + searchFor.length()); - } - - @Override - public void shift(int where, int delta) { - if (from != -1) { - if (where - 1 <= from) { - from += delta; - } - } - } - } - - /** - * ElementMatcher yields all ranges in the document matching the searched for - * element type. - */ - class ElementMatcher implements DocumentHitIterator { - - private int hitsLeft; - private int index; - private final ApiView apiView; - private final ElementType elementType; - private final Map<String, String> restrictions; - - public ElementMatcher( - ApiView apiView, ElementType elementType, Map<String, String> restrictions, int maxRes) { - Preconditions.checkNotNull(apiView, "Api view must not be null"); - Preconditions.checkNotNull(elementType, "The type of element to search for must not be null"); - Preconditions.checkNotNull(restrictions, "The search restricitions must not be null"); - - this.elementType = elementType; - this.apiView = apiView; - this.index = -1; - this.hitsLeft = maxRes; - this.restrictions = restrictions; - } - - @Override - public Range next() { - if (hitsLeft == 0) { - return null; - } - hitsLeft--; - - for (ApiView.ElementInfo elementInfo : apiView.getElements()) { - if (elementInfo.element.getType().equals(elementType) && elementInfo.apiPosition > index) { - boolean allMatched = true; - for (Entry<String, String> entry : restrictions.entrySet()) { - if (!entry.getValue().equals(elementInfo.element.getProperty(entry.getKey()))) { - allMatched = false; - break; - } - } - if (!allMatched) { - continue; - } - index = elementInfo.apiPosition; - return new Range(index, index + 1); - } - } - return null; - } - - @Override - public void shift(int where, int delta) { - } - } -}
http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/data/ElementSerializer.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/data/ElementSerializer.java b/src/com/google/wave/api/data/ElementSerializer.java deleted file mode 100644 index 42c14b5..0000000 --- a/src/com/google/wave/api/data/ElementSerializer.java +++ /dev/null @@ -1,647 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.data; - -import com.google.common.base.CharMatcher; -import com.google.common.base.Splitter; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.wave.api.Attachment; -import com.google.wave.api.Element; -import com.google.wave.api.ElementType; -import com.google.wave.api.FormElement; -import com.google.wave.api.Gadget; -import com.google.wave.api.Image; -import com.google.wave.api.Installer; -import com.google.wave.api.Line; - -import org.waveprotocol.wave.model.conversation.Blips; -import org.waveprotocol.wave.model.document.Doc; -import org.waveprotocol.wave.model.document.Doc.E; -import org.waveprotocol.wave.model.document.Doc.N; -import org.waveprotocol.wave.model.document.Document; -import org.waveprotocol.wave.model.document.util.LineContainers; -import org.waveprotocol.wave.model.document.util.XmlStringBuilder; -import org.waveprotocol.wave.model.id.IdConstants; -import org.waveprotocol.wave.model.wave.Wavelet; - -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Class to support serializing Elements from and to XML. - * - * - */ -public abstract class ElementSerializer { - - // Two maps to easily look up what to serialize - private static final Map<ElementType, ElementSerializer> typeToSerializer = Maps.newHashMap(); - private static final Map<String, ElementSerializer> tagToSerializer = Maps.newHashMap(); - - private static final String CAPTION_TAG = "caption"; - private static final String CLICK_TAG = "click"; - private static final String ATTACHMENT_STR = "attachment"; - private static final String CAPTION_STR = "caption"; - - /** The attachment URL regular expression */ - private static final Pattern ATTACHMENT_URL_PATTERN = Pattern.compile( - "attachment_url\\\"\\ value\\=\\\"([^\\\"]*)\\\""); - - /** The attachment MIME type regular expression */ - private static final Pattern MIME_TYPE_PATTERN = Pattern.compile( - "mime_type\\\"\\ value\\=\\\"([^\\\"]*)\\\""); - - /** Attachment Download Host URL */ - private static String attachmentDownloadHostUrl = ""; - - public static void setAttachmentDownloadHostUrl(String attachmentDownloadHostUrl){ - ElementSerializer.attachmentDownloadHostUrl = attachmentDownloadHostUrl; - } - - public static XmlStringBuilder apiElementToXml(Element e) { - ElementSerializer serializer = typeToSerializer.get(e.getType()); - if (serializer == null) { - return null; - } - return serializer.toXml(e); - } - - 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 static String tagNameForElementType(ElementType lookup) { - ElementSerializer serializer = typeToSerializer.get(lookup); - if (serializer != null) { - return serializer.tagName; - } - return null; - } - - 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 static void register(ElementSerializer serializer) { - typeToSerializer.put(serializer.elementType, serializer); - tagToSerializer.put(serializer.tagName, serializer); - } - - static { - register(new ElementSerializer("label", ElementType.LABEL) { - @Override - public XmlStringBuilder toXml(Element e) { - String value = e.getProperty("value"); - if (value == null) { - value = e.getProperty("defaultValue"); - } - return wrapWithContent(value, "for", e.getProperty("name")); - } - - @Override - public Element fromXml(Document doc, E element, Wavelet wavelet) { - FormElement formElement = createFormElement(doc, element); - formElement.setName(doc.getAttribute(element, "for")); - if (doc.getFirstChild(element) != null) { - formElement.setDefaultValue(doc.getData(doc.asText(doc.getFirstChild(element)))); - formElement.setValue(doc.getData(doc.asText(doc.getFirstChild(element)))); - } - return formElement; - } - }); - - register(new ElementSerializer("input", ElementType.INPUT) { - @Override - public XmlStringBuilder toXml(Element e) { - String value = e.getProperty("value"); - if (value == null) { - value = e.getProperty("defaultValue"); - } - return wrapWithContent(value, "name", e.getProperty("name")); - } - - @Override - public Element fromXml(Document doc, E element, Wavelet wavelet) { - FormElement formElement = createFormElement( - doc, element, doc.getAttribute(element, "submit")); - // Set the text content. - if (doc.getFirstChild(element) != null) { - formElement.setValue(doc.getData(doc.asText(doc.getFirstChild(element)))); - } - return formElement; - } - }); - - register(new ElementSerializer("password", ElementType.PASSWORD) { - @Override - public XmlStringBuilder toXml(Element e) { - String value = e.getProperty("value"); - if (value == null) { - value = e.getProperty("defaultValue"); - } - return wrap("name", e.getProperty("name"), "value", value); - } - - @Override - public Element fromXml(Document doc, E element, Wavelet wavelet) { - return createFormElement(doc, element, doc.getAttribute(element, "value")); - } - }); - - register(new ElementSerializer("textarea", ElementType.TEXTAREA) { - @Override - public XmlStringBuilder toXml(Element e) { - XmlStringBuilder res = XmlStringBuilder.createEmpty(); - String value = e.getProperty("value"); - if (isEmptyOrWhitespace(value)) { - res.append(XmlStringBuilder.createEmpty().wrap(LineContainers.LINE_TAGNAME)); - } else { - Splitter splitter = Splitter.on("\n"); - for (String paragraph : splitter.split(value)) { - res.append(XmlStringBuilder.createEmpty().wrap(LineContainers.LINE_TAGNAME)); - res.append(XmlStringBuilder.createText(paragraph)); - } - } - return res.wrap("textarea", "name", e.getProperty("name")); - } - - @Override - public Element fromXml(Document doc, E element, Wavelet wavelet) { - // Set the text content. We're doing a little mini textview here. - StringBuilder value = new StringBuilder(); - Doc.N node = doc.getFirstChild(element); - boolean first = true; - while (node != null) { - Doc.T text = doc.asText(node); - if (text != null) { - value.append(doc.getData(text)); - } - Doc.E docElement = doc.asElement(node); - if (docElement != null && - doc.getTagName(docElement).equals(LineContainers.LINE_TAGNAME)) { - if (first) { - first = false; - } else { - value.append('\n'); - } - } - node = doc.getNextSibling(node); - } - return createFormElement(doc, element, value.toString()); - } - }); - - register(new ElementSerializer("button", ElementType.BUTTON) { - @Override - public XmlStringBuilder toXml(Element element) { - XmlStringBuilder res = XmlStringBuilder.createEmpty(); - res.append(XmlStringBuilder.createText(element.getProperty("value")).wrap(CAPTION_TAG)); - res.append(XmlStringBuilder.createEmpty().wrap("events")); - return res.wrap("button", "name", element.getProperty("name")); - } - - @Override - public Element fromXml(Document doc, E element, Wavelet wavelet) { - FormElement formElement = createFormElement(doc, element); - - Doc.N firstChild = doc.getFirstChild(element); - // Get the default value from the caption. - if (firstChild != null && doc.getTagName(doc.asElement(firstChild)).equals(CAPTION_TAG) && - doc.getFirstChild(doc.asElement(firstChild)) != null) { - formElement.setDefaultValue(doc.getData(doc.asText(doc.getFirstChild( - doc.asElement(firstChild))))); - } - - // Get the value from the last click event. - if (firstChild != null && - doc.getNextSibling(firstChild) != null && - doc.asElement(doc.getFirstChild(doc.getNextSibling(firstChild))) != null && - doc.getTagName(doc.asElement(doc.getFirstChild(doc.getNextSibling( - firstChild)))).equals(CLICK_TAG)) { - formElement.setValue("clicked"); - } else { - formElement.setValue(formElement.getDefaultValue()); - } - return formElement; - } - }); - - register(new ElementSerializer("radiogroup", ElementType.RADIO_BUTTON_GROUP) { - @Override - public XmlStringBuilder toXml(Element e) { - return wrap("name", e.getProperty("name")); - } - - @Override - public Element fromXml(Document doc, E element, Wavelet wavelet) { - FormElement formElement = createFormElement( - doc, element, doc.getAttribute(element, "value")); - return formElement; - } - }); - - register(new ElementSerializer("radio", ElementType.RADIO_BUTTON) { - @Override - public XmlStringBuilder toXml(Element e) { - return wrap("name", e.getProperty("name"), "group", e.getProperty("value")); - } - - @Override - public Element fromXml(Document doc, E element, Wavelet wavelet) { - return new FormElement(getElementType(), - doc.getAttribute(element, "name"), - doc.getAttribute(element, "group")); - } - }); - - register(new ElementSerializer("check", ElementType.CHECK) { - @Override - public XmlStringBuilder toXml(Element e) { - return wrap("name", e.getProperty("name"), - "submit", e.getProperty("defaultValue"), - "value", e.getProperty("value")); - } - - @Override - public Element fromXml(Document doc, E element, Wavelet wavelet) { - FormElement formElement = createFormElement( - doc, element, doc.getAttribute(element, "value")); - formElement.setDefaultValue(doc.getAttribute(element, "submit")); - return formElement; - } - }); - - register(new ElementSerializer("extension_installer", ElementType.INSTALLER) { - @Override - public XmlStringBuilder toXml(Element e) { - return wrap("manifest", e.getProperty("manifest")); - } - - @Override - public Element fromXml(Document doc, E element, Wavelet wavelet) { - Installer installer = new Installer(); - installer.setManifest(doc.getAttribute(element, "manifest")); - - return installer; - } - }); - - register(new ElementSerializer("gadget", ElementType.GADGET) { - @Override - public XmlStringBuilder toXml(Element element) { - XmlStringBuilder res = XmlStringBuilder.createEmpty(); - if (element.getProperties().containsKey("category")) { - res.append(XmlStringBuilder.createEmpty().wrap( - "category", "name", element.getProperty("category"))); - } - if (element.getProperties().containsKey("title")) { - res.append(XmlStringBuilder.createEmpty().wrap( - "title", "value", element.getProperty("title"))); - } - if (element.getProperties().containsKey("thumbnail")) { - res.append(XmlStringBuilder.createEmpty().wrap( - "thumbnail", "value", element.getProperty("thumbnail"))); - } - for (Map.Entry<String, String> property : element.getProperties().entrySet()) { - if (property.getKey().equals("category") || property.getKey().equals("url") || - property.getKey().equals("title") || property.getKey().equals("thumbnail") || - property.getKey().equals("author")) { - continue; - } else if (property.getKey().equals("pref")) { - res.append(XmlStringBuilder.createEmpty().wrap("pref", "value", property.getValue())); - } else { - res.append(XmlStringBuilder.createEmpty().wrap("state", - "name", property.getKey(), - "value", property.getValue())); - } - } - List<String> attributes = Lists.newArrayList("url", element.getProperty("url")); - if (element.getProperties().containsKey("author")) { - attributes.add("author"); - attributes.add(element.getProperty("author")); - } - if (element.getProperties().containsKey("ifr")) { - attributes.add("ifr"); - attributes.add(element.getProperty("ifr")); - } - String[] asArray = new String[attributes.size()]; - attributes.toArray(asArray); - return res.wrap("gadget", asArray); - } - - @Override - public Element fromXml(Document doc, E element, Wavelet wavelet) { - Gadget gadget = new Gadget(); - - gadget.setUrl(doc.getAttribute(element, "url")); - String author = doc.getAttribute(element, "author"); - if (author != null) { - gadget.setAuthor(author); - } - String ifr = doc.getAttribute(element, "ifr"); - if (ifr != null) { - gadget.setIframe(ifr); - } - - // TODO(user): Streamline this. Maybe use SchemaConstraints.java to - // get a list of child elements or attributes, then automate this. - E child = doc.asElement(doc.getFirstChild(element)); - while (child != null) { - if (doc.getTagName(child).equals("name")) { - gadget.setProperty("name", doc.getAttribute(child, "value")); - } else if (doc.getTagName(child).equals("title")) { - gadget.setProperty("title", doc.getAttribute(child, "value")); - } else if (doc.getTagName(child).equals("thumbnail")) { - gadget.setProperty("thumbnail", doc.getAttribute(child, "value")); - } else if (doc.getTagName(child).equals("pref")) { - gadget.setProperty("pref", doc.getAttribute(child, "value")); - } else if (doc.getTagName(child).equals("state")) { - gadget.setProperty(doc.getAttribute(child, "name"), doc.getAttribute(child, "value")); - } else if (doc.getTagName(child).equals("category")) { - gadget.setProperty("category", doc.getAttribute(child, "name")); - } - child = doc.asElement(doc.getNextSibling(child)); - } - - return gadget; - } - }); - - register(new ElementSerializer("img", ElementType.IMAGE) { - @Override - public XmlStringBuilder toXml(Element element) { - XmlStringBuilder res = XmlStringBuilder.createEmpty(); - List<String> attributes = Lists.newArrayList("src", element.getProperty("url")); - if (element.getProperty("width") != null) { - attributes.add("width"); - attributes.add(element.getProperty("width")); - } - if (element.getProperty("height") != null) { - attributes.add("height"); - attributes.add(element.getProperty("height")); - } - if (element.getProperty("caption") != null) { - attributes.add("alt"); - attributes.add(element.getProperty("caption")); - } - String[] asArray = new String[attributes.size()]; - attributes.toArray(asArray); - return res.wrap("img", asArray); - } - - @Override - public Element fromXml(Document doc, E element, Wavelet wavelet) { - Image image = new Image(); - - if (doc.getAttribute(element, "src") != null) { - image.setUrl(doc.getAttribute(element, "src")); - } - if (doc.getAttribute(element, "alt") != null) { - image.setCaption(doc.getAttribute(element, "alt")); - } - if (doc.getAttribute(element, "width") != null) { - image.setWidth(Integer.parseInt(doc.getAttribute(element, "width"))); - } - if (doc.getAttribute(element, "height") != null) { - image.setHeight(Integer.parseInt(doc.getAttribute(element, "height"))); - } - - return image; - } - }); - - register(new ElementSerializer("image", ElementType.ATTACHMENT) { - @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; - } - - @Override - public Element fromXml(Document doc, E element, Wavelet wavelet) { - Map<String, String> properties = Maps.newHashMap(); - - String attachmentId = doc.getAttribute(element, ATTACHMENT_STR); - if (attachmentId != null) { - properties.put(Attachment.ATTACHMENT_ID, attachmentId); - } - String caption = getCaption(doc, element); - if (caption != null) { - properties.put(Attachment.CAPTION, caption); - } - if (wavelet != null && attachmentId != null) { - Document attachmentDataDoc = - wavelet.getDocument(IdConstants.ATTACHMENT_METADATA_PREFIX + "+" + attachmentId); - if (attachmentDataDoc != null) { - String dataDocument = attachmentDataDoc.toXmlString(); - if (dataDocument != null) { - properties.put(Attachment.MIME_TYPE, extractValue(dataDocument, MIME_TYPE_PATTERN)); - properties.put(Attachment.ATTACHMENT_URL, - ElementSerializer.attachmentDownloadHostUrl - + getAttachmentUrl(dataDocument)); - } - } - } - return new Attachment(properties, null); - } - - private String getCaption(Document doc, E element) { - N node = doc.getFirstChild(element); - - while (node != null) { - E cElement = doc.asElement(node); - if (cElement != null && doc.getTagName(cElement).equals(CAPTION_TAG) && - doc.getFirstChild(cElement) != null) { - return doc.getData(doc.asText(doc.getFirstChild(cElement))); - } - node = doc.getNextSibling(node); - } - return null; - } - }); - - register(new ElementSerializer(LineContainers.LINE_TAGNAME, ElementType.LINE) { - - @Override - public Element fromXml(Document doc, E element, Wavelet wavelet) { - Line paragraph = new Line(); - if (doc.getAttribute(element, "t") != null) { - paragraph.setLineType(doc.getAttribute(element, "t")); - } - if (doc.getAttribute(element, "i") != null) { - paragraph.setIndent(doc.getAttribute(element, "i")); - } - if (doc.getAttribute(element, "a") != null) { - paragraph.setAlignment(doc.getAttribute(element, "a")); - } - if (doc.getAttribute(element, "d") != null) { - paragraph.setDirection(doc.getAttribute(element, "d")); - } - return paragraph; - } - - @Override - public XmlStringBuilder toXml(Element element) { - XmlStringBuilder res = XmlStringBuilder.createEmpty(); - // A cast would be nice here, but unfortunately the element - // gets deserialized as an actual Element - Line line = new Line(element.getProperties()); - - List<String> attributes = Lists.newArrayList(); - if (!isEmptyOrWhitespace(line.getLineType())) { - attributes.add("t"); - attributes.add(line.getLineType()); - } - if (!isEmptyOrWhitespace(line.getIndent())) { - attributes.add("i"); - attributes.add(line.getIndent()); - } - if (!isEmptyOrWhitespace(line.getAlignment())) { - attributes.add("a"); - attributes.add(line.getAlignment()); - } - if (!isEmptyOrWhitespace(line.getDirection())) { - attributes.add("d"); - attributes.add(line.getDirection()); - } - String[] asArray = new String[attributes.size()]; - attributes.toArray(asArray); - return res.wrap(LineContainers.LINE_TAGNAME, asArray); - } - - }); - - register(new ElementSerializer(Blips.THREAD_INLINE_ANCHOR_TAGNAME, ElementType.INLINE_BLIP) { - @Override - public XmlStringBuilder toXml(Element e) { - return XmlStringBuilder.createEmpty().wrap( - Blips.THREAD_INLINE_ANCHOR_TAGNAME, - Blips.THREAD_INLINE_ANCHOR_ID_ATTR, e.getProperty("id")); - } - - @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 final String tagName; - private final ElementType elementType; - protected abstract XmlStringBuilder toXml(Element e); - protected abstract Element fromXml(Document doc, E element, Wavelet wavelet); - - public String getTagName() { - return tagName; - } - - public ElementType getElementType() { - return elementType; - } - - protected XmlStringBuilder wrap(String... attributes) { - return XmlStringBuilder.createEmpty().wrap(tagName, attributes); - } - - protected XmlStringBuilder wrapWithContent(String content, String... attributes) { - if (Strings.isNullOrEmpty(content)) { - return wrap(attributes); - } - return XmlStringBuilder.createText(content).wrap(tagName, attributes); - } - - /** - * Helper method to create a form element - * @return a form element of the right type and with the right name and - * optionally an initial value. - */ - - protected FormElement createFormElement(Document doc, E element, String initialValue) { - FormElement formElement = new FormElement(elementType, doc.getAttribute(element, "name")); - if (initialValue != null) { - formElement.setValue(initialValue); - formElement.setDefaultValue(initialValue); - } - return formElement; - } - - protected FormElement createFormElement(Document doc, E element) { - return createFormElement(doc, element, null); - } - - - public ElementSerializer(String tagName, ElementType elementType) { - this.tagName = tagName; - this.elementType = elementType; - } - - private static boolean isEmptyOrWhitespace(String value) { - return value == null || CharMatcher.WHITESPACE.matchesAllOf(value); - } - - private static String getAttachmentUrl(String dataDocument) { - String rawURL = extractValue(dataDocument, ATTACHMENT_URL_PATTERN); - return rawURL == null ? "" : rawURL.replace("&", "&"); - } - - // TODO(user): move away from REGEX - private static String extractValue(String dataDocument, Pattern pattern) { - Matcher matcher = pattern.matcher(dataDocument); - return matcher.find() ? matcher.group(1) : null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/data/converter/ContextResolver.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/data/converter/ContextResolver.java b/src/com/google/wave/api/data/converter/ContextResolver.java deleted file mode 100644 index 5320964..0000000 --- a/src/com/google/wave/api/data/converter/ContextResolver.java +++ /dev/null @@ -1,151 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.data.converter; - -import com.google.wave.api.BlipData; -import com.google.wave.api.BlipThread; -import com.google.wave.api.Context; -import com.google.wave.api.impl.EventMessageBundle; -import com.google.wave.api.impl.WaveletData; - -import org.waveprotocol.wave.model.conversation.Conversation; -import org.waveprotocol.wave.model.conversation.ConversationBlip; -import org.waveprotocol.wave.model.conversation.ConversationBlip.LocatedReplyThread; -import org.waveprotocol.wave.model.conversation.ConversationThread; -import org.waveprotocol.wave.model.wave.Wavelet; - -import java.util.LinkedList; -import java.util.Map; -import java.util.Queue; -import java.util.Set; - -/** - * Class to resolve context for {@link EventMessageBundle}. - * - */ -public class ContextResolver { - - /** - * Resolve an {@link EventMessageBundle}'s context. Meaning that the - * {@link WaveletData}, {@link BlipData} and {@link BlipThread} will be - * resolved as dictated by the {@link EventMessageBundle}'s getRequiredBlips - * method. - * - * @param eventMessageBundle bundle to put the context in - * @param wavelet {@link Wavelet} to put in the {@link EventMessageBundle} - * @param conversation {@link Conversation} to put in the - * {@link EventMessageBundle} - * @param eventDataConverter {@link EventDataConverter} used to convert - * {@link Wavelet}s and {@link ConversationBlip}s. - */ - public static void resolveContext(EventMessageBundle eventMessageBundle, Wavelet wavelet, - Conversation conversation, EventDataConverter eventDataConverter) { - // TODO(user): Refactor. - WaveletData waveletData = - eventDataConverter.toWaveletData(wavelet, conversation, eventMessageBundle); - eventMessageBundle.setWaveletData(waveletData); - for (Map.Entry<String, Set<Context>> entry : eventMessageBundle.getRequiredBlips().entrySet()) { - Set<Context> contextSet = entry.getValue(); - ConversationBlip requiredBlip = conversation.getBlip(entry.getKey()); - if (contextSet.contains(Context.ALL)) { - ContextResolver.addAllBlipsToEventMessages( - eventMessageBundle, conversation, wavelet, eventDataConverter); - // We now have all blips so we're done. - break; - } - if (contextSet.contains(Context.ROOT)) { - ConversationBlip rootBlip = conversation.getRootThread().getFirstBlip(); - if (rootBlip != requiredBlip) { - ContextResolver.addBlipToEventMessages( - eventMessageBundle, rootBlip, wavelet, eventDataConverter); - } - } - - // Required blip might be null, for example, in a blip deleted event. - if (requiredBlip == null) { - continue; - } - - ContextResolver.addBlipToEventMessages( - eventMessageBundle, requiredBlip, wavelet, eventDataConverter); - if (contextSet.contains(Context.CHILDREN)) { - for (ConversationBlip child : eventDataConverter.findBlipChildren(requiredBlip)) { - ContextResolver.addBlipToEventMessages( - eventMessageBundle, child, wavelet, eventDataConverter); - } - } - ConversationThread containingThread = requiredBlip.getThread(); - if (contextSet.contains(Context.PARENT)) { - ConversationBlip parent = eventDataConverter.findBlipParent(requiredBlip); - if (parent != null) { - ContextResolver.addBlipToEventMessages( - eventMessageBundle, parent, wavelet, eventDataConverter); - } - } - if (contextSet.contains(Context.SIBLINGS)) { - for (ConversationBlip blip : containingThread.getBlips()) { - if (blip != requiredBlip) { - ContextResolver.addBlipToEventMessages( - eventMessageBundle, blip, wavelet, eventDataConverter); - } - } - } - } - } - - /** - * Adds a single {@link ConversationBlip} to the {@link EventMessageBundle}. - * - * @param eventMessageBundle to add the blip to - * @param blip {@link ConversationBlip} to add - * @param wavelet {@link Wavelet} that the blip is based on - * @param eventDataConverter {@link EventDataConverter} used for conversion - */ - private static void addBlipToEventMessages(EventMessageBundle eventMessageBundle, - ConversationBlip blip, Wavelet wavelet, EventDataConverter eventDataConverter) { - if (blip != null && !eventMessageBundle.hasBlipId(blip.getId())) { - eventMessageBundle.addBlip( - blip.getId(), eventDataConverter.toBlipData(blip, wavelet, eventMessageBundle)); - } - } - - /** - * Adds all blips in the given conversation to the {@link EventMessageBundle}. - * - * @param eventMessageBundle to add the blips to - * @param conversation {@link Conversation} to get all blips from - * @param wavelet {@link Wavelet} that the {@link Conversation} is based on - * @param eventDataConverter {@link EventDataConverter} used for conversion - */ - public static void addAllBlipsToEventMessages(EventMessageBundle eventMessageBundle, - Conversation conversation, Wavelet wavelet, EventDataConverter eventDataConverter) { - Queue<ConversationThread> threads = new LinkedList<ConversationThread>(); - threads.add(conversation.getRootThread()); - while (!threads.isEmpty()) { - ConversationThread thread = threads.remove(); - for (ConversationBlip blip : thread.getBlips()) { - addBlipToEventMessages(eventMessageBundle, blip, wavelet, eventDataConverter); - for (ConversationThread replyThread : blip.getReplyThreads()) { - threads.add(replyThread); - } - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/data/converter/EventDataConverter.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/data/converter/EventDataConverter.java b/src/com/google/wave/api/data/converter/EventDataConverter.java deleted file mode 100644 index 3d8e91b..0000000 --- a/src/com/google/wave/api/data/converter/EventDataConverter.java +++ /dev/null @@ -1,93 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.data.converter; - -import com.google.wave.api.BlipData; -import com.google.wave.api.impl.EventMessageBundle; -import com.google.wave.api.impl.WaveletData; - -import org.waveprotocol.wave.model.conversation.Conversation; -import org.waveprotocol.wave.model.conversation.ConversationBlip; -import org.waveprotocol.wave.model.wave.ParticipantId; -import org.waveprotocol.wave.model.wave.Wavelet; - -import java.util.Collection; -import java.util.List; - -/** - * A utility that handles the conversion from server side model objects, for - * example, {@link Wavelet}, {@link ConversationBlip}, and so on, to the - * API model objects that are serializable to JSON. - * - */ -public interface EventDataConverter { - - /** - * Converts a {@link Wavelet} into a serializable {@link WaveletData} - * object so that it can be serialized into JSON, and sent to the robot. - * - * @param wavelet the wavelet to convert. - * @param conversation the conversation manifest. - * @param eventMessageBundle the event bundle where this {@link WaveletData} - * will be added to. - * @return the converted {@link WaveletData} object. - */ - WaveletData toWaveletData(Wavelet wavelet, - Conversation conversation, EventMessageBundle eventMessageBundle); - - /** - * Converts a {@link ConversationBlip} into a serializable {@link BlipData} - * object so that it can be serialized into JSON, and sent to the robot. - * - * @param blip the blip to convert. - * @param wavelet the wavelet that contains the blip. - * @param eventMessageBundle the event bundle where this {@link BlipData} - * will be added to. - * @return the converted {@link BlipData} object. - */ - BlipData toBlipData(ConversationBlip blip, Wavelet wavelet, - EventMessageBundle eventMessageBundle); - - /** - * Finds the parent of a blip. - * - * @param blip the blip. - * @return the blip's parent, or {@code null} if blip is the first blip in a - * conversation. - */ - ConversationBlip findBlipParent(ConversationBlip blip); - - /** - * Finds the children of a blip. - * - * @param blip the blip. - * @return a list of the blip's children. - */ - List<ConversationBlip> findBlipChildren(ConversationBlip blip); - - /** - * Converts a collection of {@link ParticipantId}s to a list of addresses. - * - * @param participantIds the participant ids to convert. - * @return a list of addresses. - */ - List<String> idsToParticipantIdList(Collection<ParticipantId> participantIds); - -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/data/converter/EventDataConverterManager.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/data/converter/EventDataConverterManager.java b/src/com/google/wave/api/data/converter/EventDataConverterManager.java deleted file mode 100644 index e23af85..0000000 --- a/src/com/google/wave/api/data/converter/EventDataConverterManager.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.data.converter; - -import com.google.wave.api.ProtocolVersion; - -import java.util.Map.Entry; -import java.util.NavigableMap; - -/** - * A simple utility class that manages the {@link EventDataConverter} for - * various protocol versions. - * - */ -public class EventDataConverterManager { - - /** A map of protocol version to {@link EventDataConverter}. */ - private final NavigableMap<ProtocolVersion, EventDataConverter> eventDataConverters; - - /** - * Constructor. - * - * @param eventDataConverters a map of {@link EventDataConverter}. - */ - public EventDataConverterManager( - NavigableMap<ProtocolVersion, EventDataConverter> eventDataConverters) { - this.eventDataConverters = eventDataConverters; - } - - /** - * Returns an instance of an {@link EventDataConverter} for the given - * protocol version. - * - * @param protocolVersion the protocol version. - * @return an instance of an {@link EventDataConverter}, or {@code null} if - * there is no converter for the given version. - */ - public EventDataConverter getEventDataConverter(ProtocolVersion protocolVersion) { - // Get the latest instance of {@link EventDataConverter} for a protocol - // version that is less than or equal to the given version, as not every - // protocol version will have a versioned {@link EventDataConverter}. - Entry<ProtocolVersion, EventDataConverter> entry = eventDataConverters.floorEntry( - protocolVersion); - if (entry == null) { - return null; - } - return entry.getValue(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/data/converter/EventDataConverterModule.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/data/converter/EventDataConverterModule.java b/src/com/google/wave/api/data/converter/EventDataConverterModule.java deleted file mode 100644 index 9916ec7..0000000 --- a/src/com/google/wave/api/data/converter/EventDataConverterModule.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.data.converter; - -import com.google.common.collect.Maps; -import com.google.inject.AbstractModule; -import com.google.inject.Provides; -import com.google.inject.Singleton; -import com.google.wave.api.ProtocolVersion; -import com.google.wave.api.data.converter.v21.EventDataConverterV21; -import com.google.wave.api.data.converter.v22.EventDataConverterV22; - -import java.util.NavigableMap; - -/** - * Guice module for setting up the data conversion part of the {@link RobotSerializer}. - * - */ -public class EventDataConverterModule extends AbstractModule { - - /** - * @return A singleton instance of a {@link EventDataConverterManager}. - */ - @Singleton - @Provides - static EventDataConverterManager provideEventDataConverterManager() { - // v0.1 till v0.21 use the same event data converter. - NavigableMap<ProtocolVersion, EventDataConverter> converters = Maps.newTreeMap(); - EventDataConverterV21 eventDataConverterV21 = new EventDataConverterV21(); - converters.put(ProtocolVersion.V1, eventDataConverterV21); - converters.put(ProtocolVersion.V2, eventDataConverterV21); - converters.put(ProtocolVersion.V2_1, eventDataConverterV21); - converters.put(ProtocolVersion.V2_2, new EventDataConverterV22()); - return new EventDataConverterManager(converters); - } - - @Override - protected void configure() { - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/data/converter/v21/EventDataConverterV21.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/data/converter/v21/EventDataConverterV21.java b/src/com/google/wave/api/data/converter/v21/EventDataConverterV21.java deleted file mode 100644 index 694567a..0000000 --- a/src/com/google/wave/api/data/converter/v21/EventDataConverterV21.java +++ /dev/null @@ -1,293 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.data.converter.v21; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; -import com.google.wave.api.Annotation; -import com.google.wave.api.ApiIdSerializer; -import com.google.wave.api.BlipData; -import com.google.wave.api.Range; -import com.google.wave.api.data.ApiView; -import com.google.wave.api.data.ElementSerializer; -import com.google.wave.api.data.converter.EventDataConverter; -import com.google.wave.api.impl.EventMessageBundle; -import com.google.wave.api.impl.WaveletData; - -import org.waveprotocol.wave.model.account.DocumentBasedRoles; -import org.waveprotocol.wave.model.conversation.Conversation; -import org.waveprotocol.wave.model.conversation.ConversationBlip; -import org.waveprotocol.wave.model.conversation.ConversationThread; -import org.waveprotocol.wave.model.conversation.TagsDocument; -import org.waveprotocol.wave.model.conversation.TitleHelper; -import org.waveprotocol.wave.model.document.Document; -import org.waveprotocol.wave.model.document.ObservableDocument; -import org.waveprotocol.wave.model.document.RangedAnnotation; -import org.waveprotocol.wave.model.document.util.XmlStringBuilder; -import org.waveprotocol.wave.model.id.IdConstants; -import org.waveprotocol.wave.model.id.IdUtil; -import org.waveprotocol.wave.model.wave.ParticipantId; -import org.waveprotocol.wave.model.wave.Wavelet; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -/** - * An implementation of {@link EventDataConverter} for all protocol versions - * that are less than or equal to v0.21. - * - */ -public class EventDataConverterV21 implements EventDataConverter { - - @Override - public WaveletData toWaveletData(Wavelet wavelet, Conversation conversation, - EventMessageBundle eventMessageBundle) { - final WaveletData waveletData = new WaveletData(); - waveletData.setCreationTime(wavelet.getCreationTime()); - waveletData.setCreator(wavelet.getCreatorId().getAddress()); - waveletData.setWaveId(ApiIdSerializer.instance().serialiseWaveId(wavelet.getWaveId())); - waveletData.setWaveletId(ApiIdSerializer.instance().serialiseWaveletId(wavelet.getId())); - waveletData.setLastModifiedTime(wavelet.getLastModifiedTime()); - waveletData.setParticipants(idsToParticipantIdList(wavelet.getParticipantIds())); - waveletData.setRootBlipId(conversation.getRootThread().getFirstBlip().getId()); - waveletData.setTitle(getTitle(wavelet, conversation)); - waveletData.setVersion(wavelet.getVersion()); - - // Add Data Docs. All data documents are silently name spaced under the - // robot prefix to avoid conflicts. Any docId containing a '+' will be - // ignored for now. - for (String documentId : wavelet.getDocumentIds()) { - if (IdUtil.isRobotDocId(documentId)) { - String[] parts = IdUtil.split(documentId); - if (parts.length == 2) { - Document document = wavelet.getDocument(documentId); - String val = XmlStringBuilder.innerXml(document).getXmlString(); - waveletData.setDataDocument(parts[1], val); - } - } - } - - // Add the tags. - if (wavelet.getDocument(IdConstants.TAGS_DOC_ID) != null) { - @SuppressWarnings({"unchecked", "rawtypes"}) - TagsDocument tags = new TagsDocument(wavelet.getDocument(IdConstants.TAGS_DOC_ID)); - tags.addListener(new TagsDocument.Listener() { - @Override - public void onAdd(String tagName) { - waveletData.addTag(tagName); - } - @Override - public void onRemove(int tagPosition) { - // Not called. - }}); - tags.processInitialState(); - } - - // Add the participant roles. - ObservableDocument rolesDocument = wavelet.getDocument(IdConstants.ROLES_DATA_DOC_ID); - if (rolesDocument != null) { - DocumentBasedRoles roles = DocumentBasedRoles.create(rolesDocument); - for (ParticipantId participantId : wavelet.getParticipantIds()) { - waveletData.setParticipantRole(participantId.getAddress(), - roles.getRole(participantId).name()); - } - } - return waveletData; - } - - @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; - } - - /** - * Finds the children of a blip, defined as the next sibling blip and the - * first blip in each reply thread. - * - * @param blip the blip. - * @return the children of the given blip. - */ - @Override - public List<ConversationBlip> findBlipChildren(ConversationBlip blip) { - List<ConversationBlip> siblings = Lists.newArrayList(); - ConversationBlip nextSibling = findNextSibling(blip); - if (nextSibling != null) { - siblings.add(nextSibling); - } - for (ConversationThread reply : blip.getReplyThreads()) { - if (reply.getFirstBlip() != null) { - siblings.add(reply.getFirstBlip()); - } - } - return siblings; - } - - /** - * Finds the parent of a blip. The parent is the preceding blip in the thread, - * or the blip to which the thread is a reply for the first blip in a thread. - * The first blip of the root thread has no parent. - * - * @param blip the blip. - * @return the blip's parent, or {@code null} if the blip is the first blip - * in a conversation. - */ - @Override - public ConversationBlip findBlipParent(ConversationBlip blip) { - ConversationThread containingThread = blip.getThread(); - if (containingThread.getFirstBlip() == blip - && containingThread != blip.getConversation().getRootThread()) { - return containingThread.getParentBlip(); - } - return findPreviousSibling(blip); - } - - /** - * Converts a collection of {@link ParticipantId}s to a list of addresses. - * - * @param participantIds the participant ids to convert. - * @return a list of addresses. - */ - public List<String> idsToParticipantIdList(Collection<ParticipantId> participantIds) { - List<String> addresses = Lists.newArrayListWithCapacity(participantIds.size()); - for (ParticipantId id : participantIds) { - addresses.add(id.getAddress()); - } - return addresses; - } - - /** - * Finds the previous sibling of a blip in a thread. The first blip in a - * thread has no previous sibling. - * - * @param blip the blip. - * @return the previous sibling of the blip, or {@code null}. - */ - @VisibleForTesting - static ConversationBlip findPreviousSibling(ConversationBlip blip) { - ConversationThread thread = blip.getThread(); - ConversationBlip previous = null; - for (ConversationBlip sibling : thread.getBlips()) { - if (sibling == blip) { - break; - } - previous = sibling; - } - return previous; - } - - /** - * Finds the next sibling of a blip in a thread. The last blip in a thread has - * no next sibling. - * - * @param blip the blip. - * @return the next sibling of the blip, or {@code null} if blip is the last - * blip in a thread. - */ - @VisibleForTesting - static ConversationBlip findNextSibling(ConversationBlip blip) { - ConversationThread thread = blip.getThread(); - Iterator<? extends ConversationBlip> blips = thread.getBlips().iterator(); - boolean foundBlip = false; - while (!foundBlip && blips.hasNext()) { - if (blips.next() == blip) { - foundBlip = true; - } - } - return blips.hasNext() ? blips.next() : null; - } - - /** - * Retrieves the title of a {@link Wavelet}. - * - * @param wavelet The {@link Wavelet} to retrieve the title from. - * @param conversation The wavelet conversation - * @return the title of the {@link Wavelet}, or an empty string if it has - * no title. - */ - private static String getTitle(Wavelet wavelet, Conversation conversation) { - ConversationThread rootThread = conversation.getRootThread(); - if (rootThread == null) { - return ""; - } - ConversationBlip firstBlip = rootThread.getFirstBlip(); - if (firstBlip == null) { - return ""; - } - Document doc = firstBlip.getContent(); - return TitleHelper.extractTitle(doc); - } - - /** - * Extracts the blip ids of the given list of blips. - * - * @param children the blips. - * @return the blip ids of the blips. - */ - private static List<String> toBlipIdList(List<ConversationBlip> children) { - List<String> ids = Lists.newArrayListWithCapacity(children.size()); - for (ConversationBlip child : children) { - ids.add(child.getId()); - } - return ids; - } - - /** - * 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; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/data/converter/v22/EventDataConverterV22.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/data/converter/v22/EventDataConverterV22.java b/src/com/google/wave/api/data/converter/v22/EventDataConverterV22.java deleted file mode 100644 index 185a9b2..0000000 --- a/src/com/google/wave/api/data/converter/v22/EventDataConverterV22.java +++ /dev/null @@ -1,164 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.data.converter.v22; - -import com.google.common.collect.Lists; -import com.google.wave.api.BlipData; -import com.google.wave.api.BlipThread; -import com.google.wave.api.data.ApiView; -import com.google.wave.api.data.converter.EventDataConverter; -import com.google.wave.api.data.converter.v21.EventDataConverterV21; -import com.google.wave.api.impl.EventMessageBundle; -import com.google.wave.api.impl.WaveletData; - -import org.waveprotocol.wave.model.conversation.Conversation; -import org.waveprotocol.wave.model.conversation.ConversationBlip; -import org.waveprotocol.wave.model.conversation.ConversationBlip.LocatedReplyThread; -import org.waveprotocol.wave.model.conversation.ConversationThread; -import org.waveprotocol.wave.model.wave.Wavelet; - -import java.util.List; - -/** - * An implementation of {@link EventDataConverter} for protocol version v0.22. - * - * The previous converter implementation, {@link EventDataConverterV21}, does - * not expose the proper blip hierarchy, for example, parent blip can be the - * blip that contains the container thread, or the previous sibling blip. This - * implementation, however, is purely based on the {@link ConversationThread}. - * - */ -public class EventDataConverterV22 extends EventDataConverterV21 { - - @Override - public WaveletData toWaveletData(Wavelet wavelet, Conversation conversation, - EventMessageBundle eventMessageBundle) { - WaveletData waveletData = super.toWaveletData(wavelet, conversation, - eventMessageBundle); - List<String> blipIds = Lists.newLinkedList(); - for (ConversationBlip conversationBlip : conversation.getRootThread().getBlips()) { - blipIds.add(conversationBlip.getId()); - } - waveletData.setRootThread(new BlipThread("", -1 , blipIds, null)); - return waveletData; - } - - @Override - public BlipData toBlipData(ConversationBlip blip, Wavelet wavelet, - EventMessageBundle eventMessageBundle) { - BlipData blipData = super.toBlipData(blip, wavelet, eventMessageBundle); - String threadId = blip.getThread().getId(); - blipData.setThreadId(threadId); - - // If it's the root thread, that doesn't have thread id, then skip. - if (!threadId.isEmpty()) { - ConversationThread thread = blip.getThread(); - addThread(eventMessageBundle, thread, -1, wavelet); - } - - // Add the inline reply threads. - List<String> threadIds = Lists.newLinkedList(); - for (LocatedReplyThread<? extends ConversationThread> thread : blip.locateReplyThreads()) { - String replyThreadId = thread.getThread().getId(); - threadIds.add(replyThreadId); - addThread(eventMessageBundle, thread.getThread(), thread.getLocation(), wavelet); - } - - blipData.setReplyThreadIds(threadIds); - return blipData; - } - - /** - * Finds the children of a blip, defined as all blips in all reply threads. - * - * @param blip the blip. - * @return the children of the given blip. - */ - @Override - public List<ConversationBlip> findBlipChildren(ConversationBlip blip) { - List<ConversationBlip> children = Lists.newArrayList(); - // Add all children from the inline reply threads. - for (LocatedReplyThread<? extends ConversationThread> thread : blip.locateReplyThreads()) { - for (ConversationBlip child : thread.getThread().getBlips()) { - children.add(child); - } - } - return children; - } - - /** - * Finds the parent of a blip. - * - * @param blip the blip. - * @return the blip's parent, or {@code null} if the blip is the first blip - * in a conversation. - */ - @Override - public ConversationBlip findBlipParent(ConversationBlip blip) { - return blip.getThread().getParentBlip(); - } - - /** - * Converts a {@link ConversationThread} into API {@link BlipThread}, then add it - * to the given {@link EventMessageBundle}. - * - * @param eventMessageBundle the event message bundle to add the thread to. - * @param thread the {@link ConversationThread} to convert. - * @param location the anchor location of the thread, or -1 if it's not an - * inline reply thread. - * @param wavelet the wavelet to which the given thread belongs. - */ - private static void addThread(EventMessageBundle eventMessageBundle, ConversationThread thread, - int location, Wavelet wavelet) { - String threadId = thread.getId(); - if (eventMessageBundle.hasThreadId(threadId)) { - // The bundle already has the thread, so we don't need to do the - // conversion. - return; - } - - // Convert the XML offset into the text offset. - ConversationBlip parent = thread.getParentBlip(); - - // Locate the thread, if necessary. - if (location == -1) { - for (LocatedReplyThread<? extends ConversationThread> inlineReplyThread : - parent.locateReplyThreads()) { - if (thread.getId().equals(inlineReplyThread.getThread().getId())) { - location = inlineReplyThread.getLocation(); - break; - } - } - } - - // Use ApiView to convert the offset. - if (location != -1) { - ApiView apiView = new ApiView(parent.getContent(), wavelet); - location = apiView.transformToTextOffset(location); - } - - // Get the ids of the contained blips. - List<String> blipIds = Lists.newLinkedList(); - for (ConversationBlip blip : thread.getBlips()) { - blipIds.add(blip.getId()); - } - eventMessageBundle.addThread(threadId, new BlipThread(thread.getId(), location, blipIds, null)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/event/AbstractEvent.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/AbstractEvent.java b/src/com/google/wave/api/event/AbstractEvent.java deleted file mode 100644 index 65c7986..0000000 --- a/src/com/google/wave/api/event/AbstractEvent.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Blip; -import com.google.wave.api.NonJsonSerializable; -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -/** - * The base class for all events. - */ -public abstract class AbstractEvent implements Event { - - /** The wavelet in which this event occurs. */ - @NonJsonSerializable protected final Wavelet wavelet; - - /** The type of the event. */ - private final EventType type; - - /** The id of the participant that triggered this event. */ - private final String modifiedBy; - - /** The timestamp of the event. */ - private final long timestamp; - - /** - * The id of the blip in which this event occurs, or the root blip id in the - * case of a wavelet event. - */ - private final String blipId; - - /** - * The message bundle this event belongs to. - */ - @NonJsonSerializable private final EventMessageBundle bundle; - - /** - * Constructor. - * - * @param eventType the type of the event. - * @param wavelet the wavelet in which this event occurs. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that triggered this event. - * @param timestamp the timestamp of this event. - */ - protected AbstractEvent(EventType eventType, Wavelet wavelet, EventMessageBundle bundle, - String modifiedBy, long timestamp, String blipId) { - this.type = eventType; - this.wavelet = wavelet; - this.modifiedBy = modifiedBy; - this.timestamp = timestamp; - this.blipId = blipId; - this.bundle = bundle; - } - - /** - * Constructor for deserialization. - */ - protected AbstractEvent() { - this(null, null, null, null, -1, null); - } - - @Override - public EventType getType() { - return type; - } - - @Override - public Wavelet getWavelet() { - return wavelet; - } - - @Override - public Blip getBlip() { - return wavelet.getBlip(blipId); - } - - @Override - public String getModifiedBy() { - return modifiedBy; - } - - @Override - public long getTimestamp() { - return timestamp; - } - - @Override - public EventMessageBundle getBundle() { - return bundle; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/event/AnnotatedTextChangedEvent.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/AnnotatedTextChangedEvent.java b/src/com/google/wave/api/event/AnnotatedTextChangedEvent.java deleted file mode 100644 index c86d215..0000000 --- a/src/com/google/wave/api/event/AnnotatedTextChangedEvent.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -/** - * Event triggered when text with an annotation has changed. - */ -public class AnnotatedTextChangedEvent extends AbstractEvent { - - /** The name of the annotation. */ - private final String name; - - /** The value of the annotation that changed. */ - private final String value; - - /** - * Constructor. - * - * @param wavelet the wavelet where this event occurred. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that triggered this event. - * @param timestamp the timestamp of this event. - * @param blipId the id of the blip that holds the text. - * @param name the name of the annotation. - * @param value the value of the annotation that changed. - */ - public AnnotatedTextChangedEvent(Wavelet wavelet, EventMessageBundle bundle, String modifiedBy, - Long timestamp, String blipId, String name, String value) { - super(EventType.ANNOTATED_TEXT_CHANGED, wavelet, bundle, modifiedBy, timestamp, blipId); - this.name = name; - this.value = value; - } - - /** - * Constructor for deserialization. - */ - AnnotatedTextChangedEvent() { - this.name = null; - this.value = null; - } - - /** - * Returns the name of the annotation. - * - * @return the name of the annotation. - */ - public String getName() { - return name; - } - - /** - * Returns the value of the annotation that changed. - * - * @return the value of the annotation that changed. - */ - public String getValue() { - return value; - } - - /** - * Helper method for type conversion. - * - * @return the concrete type of this event, or {@code null} if it is of a - * different event type. - */ - public static AnnotatedTextChangedEvent as(Event event) { - if (!(event instanceof AnnotatedTextChangedEvent)) { - return null; - } - return AnnotatedTextChangedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/event/BlipContributorsChangedEvent.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/BlipContributorsChangedEvent.java b/src/com/google/wave/api/event/BlipContributorsChangedEvent.java deleted file mode 100644 index 4079f84..0000000 --- a/src/com/google/wave/api/event/BlipContributorsChangedEvent.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -import java.util.ArrayList; -import java.util.List; - -/** - * Event triggered when contributors are added and/or removed from a blip. - */ -public class BlipContributorsChangedEvent extends AbstractEvent { - - /** The newly added contributors. */ - private final List<String> contributorsAdded; - - /** The removed contributors. */ - private final List<String> contributorsRemoved; - - /** - * Constructor. - * - * @param wavelet the wavelet where this event occurred. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that triggered this event. - * @param timestamp the timestamp of this event. - * @param blipId the id of the blip in which the the contributors were added - * and/or removed from. - * @param contributorsAdded the added contributors. - * @param contributorsRemoved the removed contributors. - */ - public BlipContributorsChangedEvent(Wavelet wavelet, EventMessageBundle bundle, - String modifiedBy, Long timestamp, String blipId, List<String> contributorsAdded, - List<String> contributorsRemoved) { - super(EventType.BLIP_CONTRIBUTORS_CHANGED, wavelet, bundle, modifiedBy, timestamp, blipId); - this.contributorsAdded = new ArrayList<String>(contributorsAdded); - this.contributorsRemoved = new ArrayList<String>(contributorsRemoved); - } - - /** - * Constructor for deserialization. - */ - BlipContributorsChangedEvent() { - this.contributorsAdded = null; - this.contributorsRemoved = null; - } - - /** - * Returns a list of the new contributors. - * - * @return the added contributors. - */ - public List<String> getContributorsAdded() { - return contributorsAdded; - } - - /** - * Returns a list of the removed contributors. - * - * @return the removed contributors. - */ - public List<String> getContributorsRemoved() { - return contributorsRemoved; - } - - /** - * Helper method for type conversion. - * - * @return the concrete type of this event, or {@code null} if it is of a - * different event type. - */ - public static BlipContributorsChangedEvent as(Event event) { - if (!(event instanceof BlipContributorsChangedEvent)) { - return null; - } - return BlipContributorsChangedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/event/BlipSubmittedEvent.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/BlipSubmittedEvent.java b/src/com/google/wave/api/event/BlipSubmittedEvent.java deleted file mode 100644 index f0fa302..0000000 --- a/src/com/google/wave/api/event/BlipSubmittedEvent.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -/** - * Event triggered when a blip is submitted. - */ -public class BlipSubmittedEvent extends AbstractEvent { - - /** - * Constructor. - * - * @param wavelet the wavelet where this event occurred. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that triggered this event. - * @param timestamp the timestamp of this event. - * @param blipId the id of the submitted blip. - */ - public BlipSubmittedEvent(Wavelet wavelet, EventMessageBundle bundle, String modifiedBy, - Long timestamp, String blipId) { - super(EventType.BLIP_SUBMITTED, wavelet, bundle, modifiedBy, timestamp, blipId); - } - - /** - * Constructor for deserialization. - */ - BlipSubmittedEvent() {} - - /** - * Helper method for type conversion. - * - * @return the concrete type of this event, or {@code null} if it is of a - * different event type. - */ - public static BlipSubmittedEvent as(Event event) { - if (!(event instanceof BlipSubmittedEvent)) { - return null; - } - return BlipSubmittedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/event/DocumentChangedEvent.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/DocumentChangedEvent.java b/src/com/google/wave/api/event/DocumentChangedEvent.java deleted file mode 100644 index 90b57b3..0000000 --- a/src/com/google/wave/api/event/DocumentChangedEvent.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -/** - * Event triggered when a blip content is changed. - */ -public class DocumentChangedEvent extends AbstractEvent { - - /** - * Constructor. - * - * @param wavelet the wavelet where this event occurred. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that triggered this event. - * @param timestamp the timestamp of this event. - * @param blipId the id of the submitted blip. - */ - public DocumentChangedEvent(Wavelet wavelet, EventMessageBundle bundle, String modifiedBy, - Long timestamp, String blipId) { - super(EventType.DOCUMENT_CHANGED, wavelet, bundle, modifiedBy, timestamp, blipId); - } - - /** - * Constructor for deserialization. - */ - DocumentChangedEvent() {} - - /** - * Helper method for type conversion. - * - * @return the concrete type of this event, or {@code null} if it is of a - * different event type. - */ - public static DocumentChangedEvent as(Event event) { - if (!(event instanceof DocumentChangedEvent)) { - return null; - } - return DocumentChangedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/event/Event.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/Event.java b/src/com/google/wave/api/event/Event.java deleted file mode 100644 index dad08f0..0000000 --- a/src/com/google/wave/api/event/Event.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Blip; -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -/** - * Object describing a single event, that captures changes made to a - * wavelet or blip in a wave. - */ -public interface Event { - - /** - * Returns the type of the event. - * - * @return the type of the event. - */ - EventType getType(); - - /** - * Returns the wavelet in which this event occurs. - * - * @return the wavelet in which this event occurs. - */ - Wavelet getWavelet(); - - /** - * Returns the blip in which this event occurs, or the root blip for a wavelet - * event. - * - * @return the blip in which this event occurs, or the root blip. - */ - Blip getBlip(); - - /** - * Returns the id of the participant that triggered this event. - * - * @return the id of the participant that triggered this event. - */ - String getModifiedBy(); - - /** - * Returns the timestamp when this event occurred on the server. - * - * @return the timestamp of the event. - */ - long getTimestamp(); - - /** - * Returns the message bundle which this event belongs to. - * - * @return the message bundle object. - */ - EventMessageBundle getBundle(); -}
