http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/Image.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/Image.java b/wave/src/main/java/com/google/wave/api/Image.java deleted file mode 100644 index dd876cf..0000000 --- a/wave/src/main/java/com/google/wave/api/Image.java +++ /dev/null @@ -1,239 +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; - -import java.util.Map; - -/** - * Represents an image within a Wave. The image can either refer to an external - * resource or a Wave attachment. An external image is defined by the 'url' - * property, while the Wave attachment is defined by the 'attachmentId' - * property. - */ -public class Image extends Element { - - public static final String ATTACHMENT_ID = "attachmentId"; - public static final String CAPTION = "caption"; - public static final String HEIGHT = "height"; - public static final String URL = "url"; - public static final String WIDTH = "width"; - - /** - * Constructs an empty image. - */ - public Image() { - super(ElementType.IMAGE); - } - - /** - * Constructs an image with a given set of properties. - * - * @param properties the properties of the image. - */ - public Image(Map<String, String> properties) { - super(ElementType.IMAGE, properties); - } - - /** - * Constructs a Wave image given an attachment id and a caption. - * - * @param attachmentId the attachment id of the wave image. - * @param caption the caption for the image. - */ - public Image(String attachmentId, String caption) { - this(); - setAttachmentId(attachmentId); - setCaption(caption); - } - - /** - * Constructs an external image given a url, image dimensions, and a caption. - * - * @param url the url for the external image. - * @param width the width of the image. - * @param height the height of the image. - * @param caption the caption for the image. - */ - public Image(String url, int width, int height, String caption) { - this(); - setUrl(url); - setWidth(width); - setHeight(height); - setCaption(caption); - } - - /** - * Returns the URL for the image. - * - * @return the URL for the image. - */ - public String getUrl() { - return getProperty(URL); - } - - /** - * Changes the URL for the image to the given url. This will cause the new - * image to be initialized and loaded. - * - * @param url the new image url. - */ - public void setUrl(String url) { - setProperty(URL, url); - } - - /** - * Sets the fixed width of the image to be displayed. - * - * @param width the fixed width of the image. - */ - public void setWidth(int width) { - setProperty(WIDTH, Integer.toString(width)); - } - - /** - * Returns the fixed width of the image. - * - * @return the fixed width of the image or -1 if no width was specified. - * - * @throws IllegalStateException if no width was specified. - */ - public int getWidth() { - String width = getProperty(WIDTH); - if (width == null) { - throw new IllegalStateException("This image's width has not been set."); - } - return Integer.parseInt(width); - } - - /** - * Sets the fixed height of the image to be displayed. - * - * @param height the fixed height of the image. - */ - public void setHeight(int height) { - setProperty(HEIGHT, Integer.toString(height)); - } - - /** - * Returns the fixed height of the image. - * - * @return the fixed height of the image. - * - * @throws IllegalStateException if no height was specified. - */ - public int getHeight() { - String height = getProperty(HEIGHT); - if (height == null) { - throw new IllegalStateException("This image's height has not been set."); - } - return Integer.parseInt(height); - } - - /** - * Sets the attacmentId for the Wave image. - * - * @param attachmentId the attachment id for the image. - */ - public void setAttachmentId(String attachmentId) { - setProperty(ATTACHMENT_ID, attachmentId); - } - - /** - * Returns the attachmentId for the image. - * - * @return the attachmentId for the image. - */ - public String getAttachmentId() { - return getProperty(ATTACHMENT_ID); - } - - /** - * Sets the caption for the image. - * - * @param caption the caption to display for the image. - */ - public void setCaption(String caption) { - setProperty(CAPTION, caption); - } - - /** - * Returns the caption for the image. - * - * @return the caption for the image. - */ - public String getCaption() { - return getProperty(CAPTION); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * image with the given attachment id. - * - * @param attachmentId the attachment id to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByAttachmentId(String attachmentId) { - return Restriction.of(ATTACHMENT_ID, attachmentId); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * image with the given caption. - * - * @param caption the caption to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByCaption(String caption) { - return Restriction.of(CAPTION, caption); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * image with the given URL. - * - * @param url the URL to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByUrl(String url) { - return Restriction.of(URL, url); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * image with the given width. - * - * @param width the width to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByWidth(int width) { - return Restriction.of(WIDTH, Integer.toString(width)); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * image with the given height. - * - * @param height the height to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByHeight(int height) { - return Restriction.of(HEIGHT, Integer.toString(height)); - } -}
http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/Installer.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/Installer.java b/wave/src/main/java/com/google/wave/api/Installer.java deleted file mode 100644 index ba2aea8..0000000 --- a/wave/src/main/java/com/google/wave/api/Installer.java +++ /dev/null @@ -1,67 +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; - -/** - * Installers are widgets that let Wave users install extensions on - * their account. Installers are identified by the URL that points to - * their manifest specification. - * - * @author [email protected] (Pamela Fox) - */ -public class Installer extends Element { - - /** - * Constructs an empty installer. - */ - public Installer() { - super(ElementType.INSTALLER); - setManifest(""); - } - - /** - * Constructs an installer for the specified manifest url. - * - * @param url the url of the manifest XML. - */ - public Installer(String manifest) { - super(ElementType.INSTALLER); - setManifest(manifest); - } - - /** - * Returns the URL of the manifest XML. - * - * @return the URL for the manifest XML. - */ - public String getManifest() { - return getProperty("manifest"); - } - - /** - * Changes the URL for the manifest to the given url. - * This will cause the installer puzzle piece to be re-loaded. - * - * @param manifest the new manifest url. - */ - public void setManifest(String manifest) { - setProperty("manifest", manifest); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/InvalidRequestException.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/InvalidRequestException.java b/wave/src/main/java/com/google/wave/api/InvalidRequestException.java deleted file mode 100644 index f9f81fe..0000000 --- a/wave/src/main/java/com/google/wave/api/InvalidRequestException.java +++ /dev/null @@ -1,56 +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; - - -/** - * Checked exception for signaling invalid input supplied by a robot for an - * operation request. - * - * @author [email protected] (David Byttow) - */ -public class InvalidRequestException extends Exception { - - private final OperationRequest invalidOperation; - - /** - * Constructor with a detail message. - * - * @param message detail message for this exception. - */ - public InvalidRequestException(String message, OperationRequest operation) { - super(message); - this.invalidOperation = operation; - } - - public InvalidRequestException(String message, OperationRequest operation, Exception e) { - super(message, e); - this.invalidOperation = operation; - } - - public InvalidRequestException(String message) { - super(message); - this.invalidOperation = null; - } - - public OperationRequest getInvalidOperation() { - return invalidOperation; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/JsonRpcConstant.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/JsonRpcConstant.java b/wave/src/main/java/com/google/wave/api/JsonRpcConstant.java deleted file mode 100644 index 376982f..0000000 --- a/wave/src/main/java/com/google/wave/api/JsonRpcConstant.java +++ /dev/null @@ -1,205 +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; - -import com.google.wave.api.impl.RawAttachmentData; -import com.google.wave.api.impl.DocumentModifyAction; -import com.google.wave.api.impl.DocumentModifyQuery; -import com.google.wave.api.impl.WaveletData; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.Logger; - -/** - * Enumeration for Google Wave JSON-RPC request properties. - * - * @author [email protected] (Marcel Prasetya) - */ -public class JsonRpcConstant { - - /** - * Enumeration for JSON-RPC request properties. - * - * @author [email protected] (Marcel Prasetya) - */ - public enum RequestProperty { - METHOD("method"), - ID("id"), - PARAMS("params"); - - private final String key; - - private RequestProperty(String key) { - this.key = key; - } - - /** - * Returns the string key to access the property. - * - * @return A string key to access the property. - */ - public String key() { - return key; - } - } - - /** - * Enumeration for JSON-RPC response properties. - * - * @author [email protected] (Marcel Prasetya) - */ - public enum ResponseProperty { - ID("id"), - DATA("data"), - ERROR("error"); - - private final String key; - - private ResponseProperty(String key) { - this.key = key; - } - - /** - * Returns the string key to access the property. - * - * @return A string key to access the property. - */ - public String key() { - return key; - } - } - - /** - * Enumeration for Google Wave specific JSON-RPC request parameters. - * - * @author [email protected] (Marcel Prasetya) - */ - public enum ParamsProperty { - // TODO(mprasetya): Consider combining this with OperationType, or at least - // each OperationType should have a list of ParamsProperty. - - // Commonly used parameters. - WAVE_ID("waveId", String.class), - WAVELET_ID("waveletId", String.class), - BLIP_ID("blipId", String.class), - ATTACHMENT_ID("attachmentId", String.class), - - // Operation specific parameters. - ANNOTATION("annotation", Annotation.class), - BLIP_AUTHOR("blipAuthor", String.class), - BLIP_CREATION_TIME("blipCreationTime", Long.class), - BLIP_DATA("blipData", BlipData.class), - BLIPS("blips", Map.class), - CAPABILITIES_HASH("capabilitiesHash", String.class), - CHILD_BLIP_ID("childBlipId", String.class), - CONTENT("content", String.class), - DATADOC_NAME("datadocName", String.class), - DATADOC_VALUE("datadocValue", String.class), - DATADOC_WRITEBACK("datadocWriteback", String.class), - ELEMENT("element", Element.class), - FETCH_PROFILES_REQUEST("fetchProfilesRequest", FetchProfilesRequest.class), - FETCH_PROFILES_RESULT("fetchProfilesResult", FetchProfilesResult.class), - INDEX("index", Integer.class), - LANGUAGE("language", String.class), - MESSAGE("message", String.class), - MODIFY_ACTION("modifyAction", DocumentModifyAction.class), - MODIFY_HOW("modifyHow", String.class), - MODIFY_QUERY("modifyQuery", DocumentModifyQuery.class), - NAME("name", String.class), - NEW_BLIP_ID("newBlipId", String.class), - NUM_RESULTS("numResults", Integer.class), - PARTICIPANT_ID("participantId", String.class), - PARTICIPANT_PROFILE("participantProfile", ParticipantProfile.class), - PARTICIPANT_ROLE("participantRole", String.class), - PARTICIPANTS_ADDED("participantsAdded", List.class), - PARTICIPANTS_REMOVED("participantsRemoved", List.class), - PROTOCOL_VERSION("protocolVersion", String.class), - PROXYING_FOR("proxyingFor", String.class), - QUERY("query", String.class), - RANGE("range", Range.class), - SEARCH_RESULTS("searchResults", SearchResult.class), - STYLE_TYPE("styleType", String.class), - THREADS("threads", Map.class), - WAVELET_DATA("waveletData", WaveletData.class), - WAVELET_TITLE("waveletTitle", String.class), - RETURN_WAVELET_IDS("returnWaveletIds", Boolean.class), - WAVELET_IDS("waveletIds", List.class), - RAW_SNAPSHOT("rawSnapshot", String.class), - FROM_VERSION("fromVersion", byte[].class), - TO_VERSION("toVersion", byte[].class), - RAW_DELTAS("rawDeltas", List.class), - TARGET_VERSION("targetVersion", byte[].class), - ATTACHMENT_DATA("attachmentData", RawAttachmentData.class), - IMPORTED_FROM_VERSION("importedFromVersion", Long.class); - - private static final Logger LOG = Logger.getLogger(ParamsProperty.class.getName()); - - private static final Map<String, ParamsProperty> reverseLookupMap = - new HashMap<String, ParamsProperty>(); - - static { - for (ParamsProperty property : ParamsProperty.values()) { - if (reverseLookupMap.containsKey(property.key)) { - LOG.warning("Parameter with key " + property.key + " already exist."); - } - reverseLookupMap.put(property.key, property); - } - } - - private final String key; - private final Class<? extends Object> clazz; - - private ParamsProperty(String key, Class<? extends Object> clazz) { - this.key = key; - this.clazz = clazz; - } - - /** - * Returns the string key to access the property. - * - * @return A string key to access the property. - */ - public String key() { - return key; - } - - /** - * Returns the {@link Class} object that represents the type of this - * property. - * - * @return A {@link Class} object that represents the type of this property. - */ - public Class<? extends Object> clazz() { - return clazz; - } - - /** - * Returns a {@link ParamsProperty} enumeration that has the given key. - * - * @param key The method name of a property. - * @return An {@link ParamsProperty} that has the given key. - */ - public static ParamsProperty fromKey(String key) { - return reverseLookupMap.get(key); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/JsonRpcResponse.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/JsonRpcResponse.java b/wave/src/main/java/com/google/wave/api/JsonRpcResponse.java deleted file mode 100644 index d675392..0000000 --- a/wave/src/main/java/com/google/wave/api/JsonRpcResponse.java +++ /dev/null @@ -1,82 +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; - -import com.google.wave.api.JsonRpcConstant.ParamsProperty; - -import java.util.Map; - -/** - * Encapsulates the response of a JSON-RPC call. - * - * @author [email protected] (Douwe Osinga) - */ -public class JsonRpcResponse { - - private final String id; - private final Map<ParamsProperty, Object> data; - private final String errorMessage; - - /** - * Construct a JSON-RPC error response. - * - * @param id the id of the operation request. - * @param errorMessage the error message. - * @return an instance of {@link JsonRpcResponse} that represents an error. - */ - public static JsonRpcResponse error(String id, String errorMessage) { - return new JsonRpcResponse(id, null, errorMessage); - } - - /** - * Construct a JSON-RPC response. - * - * @param id the id of the operation request. - * @param data a key value pairs of data that was returned as a result of - * operation. - * @return an instance of {@link JsonRpcResponse} that represents a success - * case. - */ - public static JsonRpcResponse result(String id, Map<ParamsProperty, Object> data) { - return new JsonRpcResponse(id, data, null); - } - - private JsonRpcResponse(String id, Map<ParamsProperty, Object> result, String errorMessage) { - this.id = id; - this.data = result; - this.errorMessage = errorMessage; - } - - public Map<ParamsProperty, Object> getData() { - return data; - } - - public String getErrorMessage() { - return errorMessage; - } - - public String getId() { - return id; - } - - public boolean isError() { - return data == null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/Line.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/Line.java b/wave/src/main/java/com/google/wave/api/Line.java deleted file mode 100644 index 2d11909..0000000 --- a/wave/src/main/java/com/google/wave/api/Line.java +++ /dev/null @@ -1,157 +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; - -import java.util.Map; - -/** - * Represents a line within a Wave. - */ -public class Line extends Element { - - public static final String ALIGNMENT = "alignment"; - public static final String DIRECTION = "direction"; - public static final String INDENT = "indent"; - public static final String LINE_TYPE = "lineType"; - - /** - * Constructs an unstyled line. - */ - public Line() { - super(ElementType.LINE); - } - - /** - * Constructs a line with a given set of properties. - * - * @param properties the properties of the line. - */ - public Line(Map<String, String> properties) { - super(ElementType.LINE, properties); - } - - /** - * The type of the line. Allowed values are 'h1', 'h2', 'h3', 'h4', - * 'h5', and 'li', where h[1-5] is a heading and 'li' an item in a list. - * - * @return the type of the line. - */ - public String getLineType() { - return getProperty(LINE_TYPE); - } - - /** - * Set the type of the line. - */ - public void setLineType(String lineType) { - setProperty(LINE_TYPE, lineType); - } - - /** - * The indentation level (0,1,2,...). This attribute is only meaningful when - * applied to lines of type t="li". - * @return the indent - */ - public String getIndent() { - return getProperty(INDENT); - } - - /** - * Set the indent for the line. - */ - public void setIndent(String value) { - setProperty(INDENT, value); - } - - /** - * The alignment of the text in the line. (a, m, r, j) a = align - * left = centered = aligned right = justified - * @return the alignment - */ - public String getAlignment() { - return getProperty(ALIGNMENT); - } - - /** - * Set the alignment for the line. - */ - public void setAlignment(String attribute) { - setProperty(ALIGNMENT, attribute); - } - - /** - * The display direction of the line l = left to right, r = right to left - * @return the direction - */ - public String getDirection() { - return getProperty(DIRECTION); - } - - /** - * Set the direction for the line. - */ - public void setDirection(String value) { - setProperty(DIRECTION, value); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * line with the given alignment. - * - * @param alignment the alignment to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByAlignment(String alignment) { - return Restriction.of(ALIGNMENT, alignment); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * line with the given direction. - * - * @param direction the direction to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByDirection(String direction) { - return Restriction.of(DIRECTION, direction); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * line with the given indentation. - * - * @param indent the indentation to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByIndent(String indent) { - return Restriction.of(INDENT, indent); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * line with the given line type. - * - * @param lineType the line type to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restricByLineType(String lineType) { - return Restriction.of(LINE_TYPE, lineType); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/Markup.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/Markup.java b/wave/src/main/java/com/google/wave/api/Markup.java deleted file mode 100644 index 68509de..0000000 --- a/wave/src/main/java/com/google/wave/api/Markup.java +++ /dev/null @@ -1,98 +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; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Holds a piece of markup to be applied to a blip. - * - * Insert/Append/Replace all can take a {@link Markup} instance instead of - * text. The markup should be {@code HTML} and will be converted to wave - * in a similar fashion as what happened when {@code HTML} is pasted directly - * into a wave. - */ -public class Markup extends BlipContent { - - /** The {@link Pattern} object used to search markup content. */ - private static final Pattern MARKUP_PATTERN = Pattern.compile("\\<.*?\\>"); - - /** The {@code HTML} content of this markup. */ - private final String markup; - - /** The plain text version of this markup. */ - private final String plain; - - /** - * Convenience factory method. - * - * @param markup the {@code HTML} content. - * @return an instance of {@link Markup} that represents the given markup. - */ - public static Markup of(String markup) { - return new Markup(markup); - } - - /** - * Constructor. - * - * @param markup the {@code HTML} content. - */ - public Markup(String markup) { - this.markup = markup; - this.plain = convertToPlainText(markup); - } - - /** - * Returns the {@code HTML} content of this markup. - * - * @return the {@code HTML} content. - */ - public String getMarkup() { - return markup; - } - - @Override - public String getText() { - return plain; - } - - /** - * Converts the given {@code HTML} into robot compatible plain text. - * - * @param html the text to convert. - * @return a plain text version of the given html text. - */ - private static String convertToPlainText(String html) { - StringBuffer result = new StringBuffer(); - Matcher matcher = MARKUP_PATTERN.matcher(html); - while (matcher.find()) { - String replacement = ""; - String tag = matcher.group().substring(1, matcher.group().length() - 1).split(" ")[0]; - if ("p".equals(tag) || "br".equals(tag)) { - replacement = "\n"; - } - matcher.appendReplacement(result, replacement); - } - matcher.appendTail(result); - return result.toString(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/NonJsonSerializable.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/NonJsonSerializable.java b/wave/src/main/java/com/google/wave/api/NonJsonSerializable.java deleted file mode 100644 index 986d431..0000000 --- a/wave/src/main/java/com/google/wave/api/NonJsonSerializable.java +++ /dev/null @@ -1,30 +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; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * Marks a field to be non-serializable. When serializing the object to JSON, - * this field should not be included. - */ -@Retention(RetentionPolicy.RUNTIME) -public @interface NonJsonSerializable {} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/OperationQueue.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/OperationQueue.java b/wave/src/main/java/com/google/wave/api/OperationQueue.java deleted file mode 100644 index 9e27aa1..0000000 --- a/wave/src/main/java/com/google/wave/api/OperationQueue.java +++ /dev/null @@ -1,714 +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; - -import com.google.wave.api.JsonRpcConstant.ParamsProperty; -import com.google.wave.api.OperationRequest.Parameter; -import com.google.wave.api.impl.RawAttachmentData; - -import org.waveprotocol.wave.model.id.InvalidIdException; -import org.waveprotocol.wave.model.id.WaveId; -import org.waveprotocol.wave.model.id.WaveletId; -import org.waveprotocol.wave.media.model.AttachmentId; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.Set; - -/** - * A utility class that abstracts the queuing of operations, represented by - * {@link OperationRequest}, using easily callable functions. The - * {@link OperationQueue} queues the resulting operations in order. - * - * Typically there shouldn't be a need to call this directly unless operations - * are needed on entities outside of the scope of the robot. For example, to - * modify a blip that does not exist in the current context, you might specify - * the wave, wavelet, and blip id to generate an operation. - * - * Any calls to this will not be reflected in the robot in any way. For example, - * calling wavelet_append_blip will not result in a new blip being added to the - * robot current context, only an operation to be sent to the robot proxy. - */ -public class OperationQueue implements Serializable { - - /** A random number generator for the temporary ids. */ - private static final Random ID_GENERATOR = new Random(); - - /** The format of temporary blip ids. */ - private static final String TEMP_BLIP_ID_FORMAT = "TBD_%s_%s"; - - /** The format of temporary wave ids. */ - private static final String TEMP_WAVE_ID_FORMAT = "%s!TBD_%s"; - - /** The format of wavelet ids. */ - private static final String TEMP_WAVELET_ID_FORMAT = "%s!conv+root"; - - /** The format of new operation ids. */ - private static final String OP_ID_FORMAT = "op%d"; - - /** Some class global counters. */ - private static long nextOpId = 1; - - /** The id that can be set for {@code proxyingFor} parameter. */ - private final String proxyForId; - - /** The operation queue. */ - private List<OperationRequest> pendingOperations; - - /** - * Constructor that creates a new instance of {@link OperationQueue} with - * an empty queue and no proxying information set. - */ - public OperationQueue() { - this(new ArrayList<OperationRequest>(), null); - } - - /** - * Constructor that creates a new instance of {@link OperationQueue} with - * a specified proxying information. - * - * @param proxyForId the proxying information. - */ - public OperationQueue(String proxyForId) { - this(new ArrayList<OperationRequest>(), proxyForId); - } - - /** - * Constructor that creates a new instance of {@link OperationQueue} with - * a specified queue and proxying information. - * - * @param operations the underlying operation queue that should be used for - * this {@link OperationQueue}. - * @param proxyForId the proxying information. - */ - public OperationQueue(List<OperationRequest> operations, String proxyForId) { - this.pendingOperations = operations; - this.proxyForId = proxyForId; - } - - /** - * Returns a list of the pending operations that have been queued up. - * - * @return the pending operations. - */ - public List<OperationRequest> getPendingOperations() { - return pendingOperations; - } - - /** - * Returns the id for {@code proxyingFor} parameter. - * - * @return the proxying id. - */ - public String getProxyForId() { - return proxyForId; - } - - /** - * Creates a view of this {@link OperationQueue} with the proxying for set to - * the given id. - * - * This method returns a new instance of an operation queue that shares the - * operation list, but has a different {@link #proxyForId} set so when the - * robot uses this new queue, subsequent operations will be sent out with the - * {@code proxying_for} field set. - * - * @param proxyForId the proxying information. - * @return a view of this {@link OperationQueue} with the proxying information - * set. - */ - public OperationQueue proxyFor(String proxyForId) { - return new OperationQueue(pendingOperations, proxyForId); - } - - /** - * Clears this operation queue. - */ - public void clear() { - pendingOperations.clear(); - } - - /** - * Appends a blip to a wavelet. - * - * @param wavelet the wavelet to append the new blip to. - * @param initialContent the initial content of the new blip. - * @return an instance of {@link Blip} that represents the new blip. - */ - public Blip appendBlipToWavelet(Wavelet wavelet, String initialContent) { - Blip newBlip = newBlip(wavelet, initialContent, null, generateTempBlipId(wavelet), - wavelet.getRootThread().getId()); - appendOperation(OperationType.WAVELET_APPEND_BLIP, wavelet, - Parameter.of(ParamsProperty.BLIP_DATA, newBlip.serialize())); - return newBlip; - } - - /** - * Adds a participant to a wavelet. - * - * @param wavelet the wavelet that the new participant should be added to. - * @param participantId the id of the new participant. - */ - public void addParticipantToWavelet(Wavelet wavelet, String participantId) { - appendOperation(OperationType.WAVELET_ADD_PARTICIPANT_NEWSYNTAX, wavelet, - Parameter.of(ParamsProperty.PARTICIPANT_ID, participantId)); - } - - /** - * Removes a participant from a wavelet. - * - * @param wavelet the wavelet that the participant should be removed from. - * @param participantId the id of the participant to be removed. - */ - public void removeParticipantFromWavelet(Wavelet wavelet, String participantId) { - appendOperation(OperationType.WAVELET_REMOVE_PARTICIPANT_NEWSYNTAX, wavelet, - Parameter.of(ParamsProperty.PARTICIPANT_ID, participantId)); - } - - /** - * Creates a new wavelet. - * - * @param domain the domain to create the wavelet in. - * @param participants the initial participants on this new wavelet. - * @return an instance of {@link Wavelet} that represents the new wavelet. - */ - public Wavelet createWavelet(String domain, Set<String> participants) { - return createWavelet(domain, participants, ""); - } - - /** - * Creates a new wavelet with an optional message. - * - * @param domain the domain to create the wavelet in. - * @param participants the initial participants on this new wavelet. - * @param message an optional payload that is returned with the corresponding - * event. - * @return an instance of {@link Wavelet} that represents the new wavelet. - */ - public Wavelet createWavelet(String domain, Set<String> participants, String message) { - Wavelet newWavelet = newWavelet(domain, participants, this); - OperationRequest operation = appendOperation(OperationType.ROBOT_CREATE_WAVELET, - newWavelet, Parameter.of(ParamsProperty.WAVELET_DATA, newWavelet.serialize())); - - // Don't add the message if it's null or empty. - if (message != null && !message.isEmpty()) { - operation.addParameter(Parameter.of(ParamsProperty.MESSAGE, message)); - } - return newWavelet; - } - - /** - * Appends search operation for specified query. - * - * @param query the query to execute. - * @param index the index from which to return results. - * @param numresults the number of results to return. - */ - public void search(String query, Integer index, Integer numresults) { - Parameter queryParam = Parameter.of(ParamsProperty.QUERY, query); - Parameter indexParam = Parameter.of(ParamsProperty.INDEX, index); - Parameter numresultsParam = Parameter.of(ParamsProperty.NUM_RESULTS, numresults); - appendOperation(OperationType.ROBOT_SEARCH, queryParam, indexParam, numresultsParam); - } - - /** - * Sets a key-value pair on the data document of a wavelet. - * - * @param wavelet to set the data document on. - * @param name the name of this data. - * @param value the value of this data. - */ - public void setDatadocOfWavelet(Wavelet wavelet, String name, String value) { - appendOperation(OperationType.WAVELET_SET_DATADOC, wavelet, - Parameter.of(ParamsProperty.DATADOC_NAME, name), - Parameter.of(ParamsProperty.DATADOC_VALUE, value)); - } - - /** - * Requests a snapshot of the specified wave. - * - * @param waveId the id of the wave that should be fetched. - * @param waveletId the wavelet id that should be fetched. - */ - public void fetchWavelet(WaveId waveId, WaveletId waveletId) { - appendOperation(OperationType.ROBOT_FETCH_WAVE, waveId, waveletId, null); - } - - /** - * Retrieves list of wave wavelets ids. - * - * @param waveId the id of the wave. - */ - public void retrieveWaveletIds(WaveId waveId) { - appendOperation(OperationType.ROBOT_FETCH_WAVE, waveId, null, null, - Parameter.of(ParamsProperty.RETURN_WAVELET_IDS, true)); - } - - /** - * Exports snapshot of wavelet. - * - * @param waveId the id of the wave that should be exported. - * @param waveletId the id of the wavelet that should be exported. - */ - public void exportSnapshot(WaveId waveId, WaveletId waveletId) { - appendOperation(OperationType.ROBOT_EXPORT_SNAPSHOT, waveId, waveletId, null); - } - - /** - * Exports deltas of wavelet. - * - * @param waveId the id of the wave that should be exported. - * @param waveletId the id of the wavelet that should be exported. - * @param fromVersion start version. - * @param toVersion to version. - */ - public void exportRawDeltas(WaveId waveId, WaveletId waveletId, - byte[] fromVersion, byte[] toVersion) { - appendOperation(OperationType.ROBOT_EXPORT_DELTAS, waveId, waveletId, null, - Parameter.of(ParamsProperty.FROM_VERSION, fromVersion), - Parameter.of(ParamsProperty.TO_VERSION, toVersion)); - } - - /** - * Export attachment. - * - * @param attachmentId the id of attachment. - */ - public void exportAttachment(AttachmentId attachmentId) { - appendOperation(OperationType.ROBOT_EXPORT_ATTACHMENT, - Parameter.of(ParamsProperty.ATTACHMENT_ID, attachmentId.serialise())); - } - - /** - * Imports deltas of wavelet. - * - * @param waveId the id of the wave that should be imported. - * @param waveletId the id of the wavelet that should be imported. - * @param history the history in deltas. - */ - public void importRawDeltas(WaveId waveId, WaveletId waveletId, List<byte[]> history) { - appendOperation(OperationType.ROBOT_IMPORT_DELTAS, - waveId, waveletId, null, Parameter.of(ParamsProperty.RAW_DELTAS, history)); - } - - /** - * Imports attachment. - * - * @param waveId the id of the wave that should be imported. - * @param waveletId the id of the wavelet that should be imported. - * @param attachmentId the id of attachment. - * @param attachmentData the attachment data. - */ - public void importAttachment(WaveId waveId, WaveletId waveletId, - AttachmentId attachmentId, RawAttachmentData attachmentData) { - appendOperation(OperationType.ROBOT_IMPORT_ATTACHMENT, - waveId, waveletId, null, - Parameter.of(ParamsProperty.ATTACHMENT_ID, attachmentId.serialise()), - Parameter.of(ParamsProperty.ATTACHMENT_DATA, attachmentData)); - } - - /** - * Sets the title of a wavelet. - * - * @param wavelet the wavelet whose title will be changed. - * @param title the new title to be set. - */ - public void setTitleOfWavelet(Wavelet wavelet, String title) { - appendOperation(OperationType.WAVELET_SET_TITLE, wavelet, - Parameter.of(ParamsProperty.WAVELET_TITLE, title)); - } - - /** - * Modifies a tag in a wavelet. - * - * @param wavelet the wavelet to modify the tag from. - * @param tag the name of the tag to be modified - * @param modifyHow how to modify the tag. The default behavior is to add the - * tag. Specify {@code remove} to remove, or specify {@code null} or - * {@code add} to add. - */ - public void modifyTagOfWavelet(Wavelet wavelet, String tag, String modifyHow) { - appendOperation(OperationType.WAVELET_MODIFY_TAG, wavelet, - Parameter.of(ParamsProperty.NAME, tag), - Parameter.of(ParamsProperty.MODIFY_HOW, modifyHow)); - } - - /** - * Creates a child blip of another blip. - * - * @param blip the parent blip. - * @return an instance of {@link Blip} that represents the new child blip. - */ - public Blip createChildOfBlip(Blip blip) { - // Create a new thread. - String tempBlipId = generateTempBlipId(blip.getWavelet()); - Wavelet wavelet = blip.getWavelet(); - BlipThread thread = new BlipThread(tempBlipId, -1, new ArrayList<String>(), - wavelet.getBlips()); - - // Add the new thread to the blip and wavelet. - blip.addThread(thread); - wavelet.addThread(thread); - - // Create a new blip in the new thread. - Blip newBlip = newBlip(blip.getWavelet(), "", blip.getBlipId(), tempBlipId, thread.getId()); - appendOperation(OperationType.BLIP_CREATE_CHILD, blip, - Parameter.of(ParamsProperty.BLIP_DATA, newBlip.serialize())); - return newBlip; - } - - /** - * Appends a new blip to the end of the thread of the given blip. - * - * @param blip the blip whose thread will be appended. - * @return an instance of {@link Blip} that represents the new blip. - */ - public Blip continueThreadOfBlip(Blip blip) { - Blip newBlip = newBlip(blip.getWavelet(), "", blip.getParentBlipId(), - generateTempBlipId(blip.getWavelet()), blip.getThread().getId()); - appendOperation(OperationType.BLIP_CONTINUE_THREAD, blip, - Parameter.of(ParamsProperty.BLIP_DATA, newBlip.serialize())); - return newBlip; - } - - /** - * Deletes the specified blip. - * - * @param wavelet the wavelet that owns the blip. - * @param blipId the id of the blip that will be deleted. - */ - public void deleteBlip(Wavelet wavelet, String blipId) { - appendOperation(OperationType.BLIP_DELETE, wavelet.getWaveId(), wavelet.getWaveletId(), - blipId); - } - - /** - * Appends content with markup to a blip. - * - * @param blip the blip where this markup content should be added to. - * @param content the markup content that should be added to the blip. - */ - public void appendMarkupToDocument(Blip blip, String content) { - appendOperation(OperationType.DOCUMENT_APPEND_MARKUP, blip, - Parameter.of(ParamsProperty.CONTENT, content)); - } - - /** - * Submits this operation queue when the given {@code other} operation queue - * is submitted. - * - * @param other the other operation queue to merge this operation queue with. - */ - public void submitWith(OperationQueue other) { - other.pendingOperations.addAll(this.pendingOperations); - this.pendingOperations = other.pendingOperations; - } - - /** - * Creates and queues a document modify operation. - * - * @param blip the blip to modify. - * @return an instance of {@code OperationRequest} that represents this - * operation. The caller of this method should append the required and/or - * optional parameters, such as: - * <ul> - * <li>{@code modifyAction}</li> - * <li>{@code modifyQuery}</li> - * <li>{@code index}</li> - * <li>{@code range}</li> - * </ul> - */ - public OperationRequest modifyDocument(Blip blip) { - return appendOperation(OperationType.DOCUMENT_MODIFY, blip); - } - - /** - * Inserts a new inline blip at a specified location. - * - * @param blip the blip to anchor this inline blip from. - * @param position the position in the given blip to insert this new inline - * blip. - * @return an instance of {@link Blip} that represents the inline blip. - */ - public Blip insertInlineBlipToDocument(Blip blip, int position) { - // Create a new thread. - String tempBlipId = generateTempBlipId(blip.getWavelet()); - Wavelet wavelet = blip.getWavelet(); - BlipThread thread = new BlipThread(tempBlipId, position, new ArrayList<String>(), - wavelet.getBlips()); - - // Add the new thread to the blip and wavelet. - blip.addThread(thread); - wavelet.addThread(thread); - - // Create a new blip in the new thread. - Blip inlineBlip = newBlip(blip.getWavelet(), "", blip.getBlipId(), tempBlipId, - thread.getId()); - appendOperation(OperationType.DOCUMENT_INSERT_INLINE_BLIP, blip, - Parameter.of(ParamsProperty.INDEX, position), - Parameter.of(ParamsProperty.BLIP_DATA, inlineBlip.serialize())); - return inlineBlip; - } - - /** - * Creates and appends a new operation to the operation queue. - * - * @param opType the type of the operation. - * @param parameters the parameters that should be added as a property of - * the operation. - * @return an instance of {@link OperationRequest} that represents the queued - * operation. - */ - OperationRequest appendOperation(OperationType opType, Parameter... parameters) { - return appendOperation(opType, null, null, null, parameters); - } - - /** - * Creates and appends a new operation to the operation queue. - * - * @param opType the type of the operation. - * @param wavelet the wavelet to apply the operation to. - * @param parameters the parameters that should be added as a property of - * the operation. - * @return an instance of {@link OperationRequest} that represents the queued - * operation. - */ - OperationRequest appendOperation(OperationType opType, Wavelet wavelet, - Parameter... parameters) { - return appendOperation(opType, wavelet.getWaveId(), wavelet.getWaveletId(), null, parameters); - } - - /** - * Creates and appends a new operation to the operation queue. - * - * @param opType the type of the operation. - * @param blip the blip to apply this operation to. - * @param parameters the parameters that should be added as a property of - * the operation. - * @return an instance of {@link OperationRequest} that represents the queued - * operation. - */ - OperationRequest appendOperation(OperationType opType, Blip blip, Parameter... parameters) { - return appendOperation(opType, blip.getWaveId(), blip.getWaveletId(), blip.getBlipId(), - parameters); - } - - /** - * Creates and appends a new operation to the operation queue. - * - * @param opType the type of the operation. - * @param waveId the wave id in which the operation should be applied to. - * @param waveletId the wavelet id of the given wave in which the operation - * should be applied to. - * @param blipId the optional blip id of the given wave in which the operation - * should be applied to. Not all operations require blip id. - * @param parameters the parameters that should be added as a property of - * the operation. - * @return an instance of {@link OperationRequest} that represents the queued - * operation. - */ - OperationRequest appendOperation(OperationType opType, WaveId waveId, WaveletId waveletId, - String blipId, Parameter... parameters) { - return addOperation(opType, waveId, waveletId, blipId, pendingOperations.size(), parameters); - } - - /** - * Creates and prepends a new operation to the operation queue. - * - * @param opType the type of the operation. - * @param waveId the wave id in which the operation should be applied to. - * @param waveletId the wavelet id of the given wave in which the operation - * should be applied to. - * @param blipId the optional blip id of the given wave in which the operation - * should be applied to. Not all operations require blip id. - * @param parameters the parameters that should be added as a property of - * the operation. - * @return an instance of {@link OperationRequest} that represents the queued - * operation. - */ - OperationRequest prependOperation(OperationType opType, WaveId waveId, WaveletId waveletId, - String blipId, Parameter... parameters) { - return addOperation(opType, waveId, waveletId, blipId, 0, parameters); - } - - /** - * Creates and adds a new operation to the operation queue. - * - * @param opType the type of the operation. - * @param waveId the wave id in which the operation should be applied to. - * @param waveletId the wavelet id of the given wave in which the operation - * should be applied to. - * @param blipId the optional blip id of the given wave in which the operation - * should be applied to. Not all operations require blip id. - * @param index the index where this new operation should be added to in the - * queue. - * @param parameters the parameters that should be added as a property of - * the operation. - * @return an instance of {@link OperationRequest} that represents the queued - * operation. - */ - OperationRequest addOperation(OperationType opType, WaveId waveId, WaveletId waveletId, - String blipId, int index, Parameter... parameters) { - String waveIdString = null; - if (waveId != null) { - waveIdString = ApiIdSerializer.instance().serialiseWaveId(waveId); - } - - String waveletIdString = null; - if (waveletId != null) { - waveletIdString = ApiIdSerializer.instance().serialiseWaveletId(waveletId); - } - - OperationRequest operation = new OperationRequest(opType.method(), - String.format(OP_ID_FORMAT, nextOpId++), - waveIdString, waveletIdString, blipId, parameters); - - // Set the proxying for parameter, if necessary. - if (proxyForId != null && !proxyForId.isEmpty()) { - operation.addParameter(Parameter.of(ParamsProperty.PROXYING_FOR, proxyForId)); - } - - pendingOperations.add(index, operation); - return operation; - } - - /** - * Generates a temporary blip id. - * - * @param wavelet the wavelet to seed the temporary id. - * @return a temporary blip id. - */ - private static String generateTempBlipId(Wavelet wavelet) { - return String.format(TEMP_BLIP_ID_FORMAT, - ApiIdSerializer.instance().serialiseWaveletId(wavelet.getWaveletId()), - ID_GENERATOR.nextInt()); - } - - /** - * Creates a new {@code Blip} object used for this session. A temporary - * id will be assigned to the newly created {@code Blip} object. - * - * @param wavelet the wavelet that owns this blip. - * @param initialContent the initial content of the new blip. - * @param parentBlipId the parent of this blip. - * @return an instance of new {@code Blip} object used for this session. - */ - private static Blip newBlip(Wavelet wavelet, String initialContent, String parentBlipId, - String blipId, String threadId) { - Blip newBlip = new Blip(blipId, initialContent, parentBlipId, threadId, wavelet); - if (parentBlipId != null) { - Blip parentBlip = wavelet.getBlips().get(parentBlipId); - if (parentBlip != null) { - parentBlip.getChildBlipIds().add(newBlip.getBlipId()); - } - } - wavelet.getBlips().put(newBlip.getBlipId(), newBlip); - - BlipThread thread = wavelet.getThread(threadId); - if (thread != null) { - thread.appendBlip(newBlip); - } - return newBlip; - } - - /** - * Creates a new {@code Wavelet} object used for this session. A temporary - * wave id will be assigned to this newly created {@code Wavelet} object. - * - * @param domain the domain that is used for the wave and wavelet ids. - * @param participants the participants that should be added to the new - * wavelet. - * @param opQueue the operation queue of the new wavelet. - * @return an instance of new {@code Wavelet} object used for this - * session. - */ - private static Wavelet newWavelet(String domain, Set<String> participants, - OperationQueue opQueue) { - // Make sure that participant list is not null; - if (participants == null) { - participants = Collections.emptySet(); - } - - WaveId waveId; - WaveletId waveletId; - try { - waveId = ApiIdSerializer.instance().deserialiseWaveId( - String.format(TEMP_WAVE_ID_FORMAT, domain, ID_GENERATOR.nextInt())); - waveletId = ApiIdSerializer.instance().deserialiseWaveletId( - String.format(TEMP_WAVELET_ID_FORMAT, domain)); - } catch (InvalidIdException e) { - throw new IllegalStateException("Invalid temporary id", e); - } - - String rootBlipId = String.format(TEMP_BLIP_ID_FORMAT, - ApiIdSerializer.instance().serialiseWaveletId(waveletId), - ID_GENERATOR.nextInt()); - Map<String, Blip> blips = new HashMap<String, Blip>(); - Map<String, String> roles = new HashMap<String, String>(); - Map<String, BlipThread> threads = new HashMap<String, BlipThread>(); - - List<String> blipIds = new ArrayList<String>(); - blipIds.add(rootBlipId); - BlipThread rootThread = new BlipThread("", -1, blipIds, blips); - - Wavelet wavelet = new Wavelet(waveId, waveletId, rootBlipId, rootThread, participants, - roles, blips, threads, opQueue); - - Blip rootBlip = new Blip(rootBlipId, "", null, "", wavelet); - blips.put(rootBlipId, rootBlip); - - return wavelet; - } - - /** - * Modifies the role of a participant in a wavelet. - * - * @param wavelet the wavelet that the participant is on - * @param participant whose role to modify - * @param role to set for the participant - */ - public void modifyParticipantRoleOfWavelet(Wavelet wavelet, String participant, String role) { - appendOperation(OperationType.WAVELET_MODIFY_PARTICIPANT_ROLE, wavelet, - Parameter.of(ParamsProperty.PARTICIPANT_ID, participant), - Parameter.of(ParamsProperty.PARTICIPANT_ROLE, role)); - } - - /** - * Notifies the robot information. - * - * @param protocolVersion the wire protocol version of the robot. - * @param capabilitiesHash the capabilities hash of the robot. - */ - public void notifyRobotInformation(ProtocolVersion protocolVersion, String capabilitiesHash) { - prependOperation(OperationType.ROBOT_NOTIFY, null, null, null, - Parameter.of(ParamsProperty.PROTOCOL_VERSION, protocolVersion.getVersionString()), - Parameter.of(ParamsProperty.CAPABILITIES_HASH, capabilitiesHash)); - } - - public void fetchProfiles(FetchProfilesRequest request) { - appendOperation(OperationType.ROBOT_FETCH_PROFILES, - Parameter.of(ParamsProperty.FETCH_PROFILES_REQUEST, request)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/OperationRequest.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/OperationRequest.java b/wave/src/main/java/com/google/wave/api/OperationRequest.java deleted file mode 100644 index d12ba80..0000000 --- a/wave/src/main/java/com/google/wave/api/OperationRequest.java +++ /dev/null @@ -1,270 +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; - -import com.google.wave.api.JsonRpcConstant.ParamsProperty; - -import java.util.HashMap; -import java.util.Map; - -/** - * A class that represents an operation request. - * - * @author [email protected] (Marcel Prasetya) - */ -public class OperationRequest { - - /** - * A helper inner class that represents an operation parameter. Useful for - * constructing the operation. - * - * @author [email protected] (Marcel Prasetya) - */ - public static class Parameter { - - private final ParamsProperty key; - private final Object value; - - /** - * Factory method. - * - * @param key the key of the parameter - * @param value the value of the parameter - * @return a parameter with the specified key and value - */ - public static Parameter of(ParamsProperty key, Object value) { - return new Parameter(key, value); - } - - /** - * Constructor. - * - * @param key the key of the parameter. - * @param value the value of the parameter. - */ - private Parameter(ParamsProperty key, Object value) { - this.key = key; - this.value = value; - } - - /** - * Returns the key of the parameter. - * - * @return the key of the parameter. - */ - public ParamsProperty getKey() { - return key; - } - - /** - * Returns the value of the parameter. - * - * @return the value of the parameter. - */ - public Object getValue() { - return value; - } - } - - private final String method; - private final String id; - private final Map<ParamsProperty, Object> parameters; - - /** - * Constructor. - * - * @param method the method or operation to be executed. - * See {@link OperationType}. - * @param id the id of the request. - * @param waveId the wave id to apply this operation to. - * @param waveletId the wavelet id to apply this operation to. - * @param blipId the blip id to apply this operation to. - * @param params additional parameters for this operation. See - * {@link ParamsProperty}. - */ - public OperationRequest(String method, String id, String waveId, String waveletId, String blipId, - Parameter... params) { - this.method = method; - this.id = id; - this.parameters = new HashMap<ParamsProperty, Object>(params.length + 3); - setWaveId(waveId); - setWaveletId(waveletId); - setBlipId(blipId); - for (Parameter parameter : params) { - this.parameters.put(parameter.getKey(), parameter.getValue()); - } - } - - /** - * Constructor without {@code blipId}. - * - * @param method the method or operation to be executed. - * See {@link OperationType}. - * @param id the id of the request. - * @param waveId the wave id to apply this operation to. - * @param waveletId the wavelet id to apply this operation to. - * @param parameters additional parameters for this operation. See - * {@link ParamsProperty}. - */ - public OperationRequest(String method, String id, String waveId, String waveletId, - Parameter... parameters) { - this(method, id, waveId, waveletId, null, parameters); - } - - /** - * Constructor without {@code waveId}, {@code waveletId}, and {@code blipId}. - * - * @param method the method or operation to be executed. - * See {@link OperationType}. - * @param id the id of the request. - * @param parameters additional parameters for this operation. See - * {@link ParamsProperty}. - */ - public OperationRequest(String method, String id, Parameter... parameters) { - this(method, id, null, null, null, parameters); - } - - /** - * Constructor that extracts {@code waveId}, {@code waveletId}, and - * {@code blipId} from the given {@code BlipData}. - * - * @param method the method or operation to be executed. - * See {@link OperationType}. - * @param id the id of the request. - * @param blipData the {@code BlipData} to extract {@code waveId}, - * {@code waveletId}, and {@code blipId} from. - * @param parameters additional parameters for this operation. See - * {@link ParamsProperty}. - */ - public OperationRequest(String method, String id, BlipData blipData, Parameter...parameters) { - this(method, id, blipData.getWaveId(), blipData.getWaveletId(), blipData.getBlipId(), - parameters); - } - - /** - * Returns the method name that should be invoked. - * - * @return the method name. - */ - public String getMethod() { - return method; - } - - /** - * Returns the id of this request. - * - * @return the id of this request. - */ - public String getId() { - return id; - } - - /** - * Returns the parameters of this request. - * - * @return the parameters of this request. - */ - public Map<ParamsProperty, Object> getParams() { - return parameters; - } - - /** - * @param waveId to set - */ - private void setWaveId(String waveId) { - if (waveId != null) { - parameters.put(ParamsProperty.WAVE_ID, waveId); - } - } - - /** - * Returns the wave id where this request should be invoked on. This might not - * be applicable to all requests. - * - * @return the wave id. - */ - public String getWaveId() { - return (String) getParameter(ParamsProperty.WAVE_ID); - } - - /** - * @param waveletId to set - */ - private void setWaveletId(String waveletId) { - if (waveletId != null) { - parameters.put(ParamsProperty.WAVELET_ID, waveletId); - } - } - - /** - * Returns the wavelet id where this request should be invoked on. This might - * not be applicable to all requests. - * - * @return the wavelet id. - */ - public String getWaveletId() { - return (String) getParameter(ParamsProperty.WAVELET_ID); - } - - /** - * @param blipId to set - */ - private void setBlipId(String blipId) { - if (blipId != null) { - parameters.put(ParamsProperty.BLIP_ID, blipId); - } - } - - /** - * Returns the blip id where this request should be invoked on. This might not - * be applicable to all requests. - * - * @return the blip id. - */ - public String getBlipId() { - return (String) getParameter(ParamsProperty.BLIP_ID); - } - - /** - * Returns a parameter of this request. - * - * @param property the key of the parameter. - * @return a parameter of this request, that is keyed by the given input, or - * {@code null} if the parameter doesn't exist. - */ - public Object getParameter(ParamsProperty property) { - return parameters.get(property); - } - - /** - * Adds a parameter to this request. - * - * @param parameter to be added. - */ - public void addParameter(Parameter parameter) { - parameters.put(parameter.getKey(), parameter.getValue()); - } - - @Override - public String toString() { - return String.format("{'method':'%s','id':'%s','waveId':'%s','waveletId':'%s','blipId':'%s'," + - "'parameters':%s}", method, id, getWaveId(), getWaveletId(), getBlipId(), parameters); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/OperationType.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/OperationType.java b/wave/src/main/java/com/google/wave/api/OperationType.java deleted file mode 100644 index d295a2e..0000000 --- a/wave/src/main/java/com/google/wave/api/OperationType.java +++ /dev/null @@ -1,162 +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; - -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Logger; - -/** - * The Operation types supported by Robots. - * - * @author [email protected] (Seth Covitz) - * @author [email protected] (Marcel Prasetya) - */ -public enum OperationType { - UNKNOWN("unknown"), - WAVELET_APPEND_BLIP("wavelet.appendBlip"), - WAVELET_CREATE("wavelet.create"), - WAVELET_REMOVE_SELF("wavelet.removeSelf"), - WAVELET_SET_TITLE("wavelet.setTitle"), - - // TODO(mprasetya): Remove the "newsyntax" suffix once renaming is complete. - WAVELET_ADD_PARTICIPANT_NEWSYNTAX("wavelet.addParticipant"), - WAVELET_REMOVE_PARTICIPANT_NEWSYNTAX("wavelet.removeParticipant"), - - WAVELET_APPEND_DATADOC("wavelet.appendDatadoc"), - WAVELET_SET_DATADOC("wavelet.setDatadoc"), - WAVELET_MODIFY_TAG("wavelet.modifyTag"), - WAVELET_MODIFY_PARTICIPANT_ROLE("wavelet.modifyParticipantRole"), - - BLIP_CONTINUE_THREAD("blip.continueThread"), - BLIP_CREATE_CHILD("blip.createChild"), - BLIP_DELETE("blip.delete"), - BLIP_SET_AUTHOR("blip.setAuthor"), - BLIP_SET_CREATION_TIME("blip.setCreationTime"), - - DOCUMENT_DELETE_ANNOTATION("document.deleteAnnotation"), - DOCUMENT_SET_ANNOTATION("document.setAnnotation"), - DOCUMENT_SET_ANNOTATION_NORANGE("document.setAnnotationNoRange"), - - DOCUMENT_APPEND("document.append"), - DOCUMENT_APPEND_MARKUP("document.appendMarkup"), - DOCUMENT_APPEND_STYLED_TEXT("document.appendStyledText"), - DOCUMENT_DELETE("document.delete"), - DOCUMENT_INSERT("document.insert"), - DOCUMENT_MODIFY("document.modify"), - DOCUMENT_REPLACE("document.replace"), - - DOCUMENT_APPEND_ELEMENT("document.appendElement"), - DOCUMENT_DELETE_ELEMENT("document.deleteElement"), - DOCUMENT_INSERT_ELEMENT("document.insertElement"), - DOCUMENT_INSERT_ELEMENT_AFTER("document.insertElementAfter"), - DOCUMENT_INSERT_ELEMENT_BEFORE("document.insertElementBefore"), - DOCUMENT_MODIFY_ELEMENT_ATTRS("document.modifyElementAttrs"), - DOCUMENT_REPLACE_ELEMENT("document.replaceElement"), - - DOCUMENT_APPEND_INLINE_BLIP("document.appendInlineBlip"), - DOCUMENT_INSERT_INLINE_BLIP("document.insertInlineBlip"), - DOCUMENT_INSERT_INLINE_BLIP_AFTER_ELEMENT("document.insertInlineBlipAfterElement"), - - // Some operations not associated with a context - ROBOT_FOLDER_ACTION("robot.folderAction"), - ROBOT_CREATE_WAVELET("robot.createWavelet"), - ROBOT_FETCH_MY_PROFILE("robot.fetchMyProfile"), - ROBOT_FETCH_PROFILES("robot.fetchProfiles"), - ROBOT_FETCH_WAVE("robot.fetchWave"), - ROBOT_NOTIFY("robot.notify"), - ROBOT_SEARCH("robot.search"), - - ROBOT_EXPORT_SNAPSHOT("robot.exportSnapshot"), - ROBOT_EXPORT_DELTAS("robot.exportDeltas"), - ROBOT_EXPORT_ATTACHMENT("robot.exportAttachment"), - ROBOT_IMPORT_SNAPSHOT("robot.importSnapshot"), - ROBOT_IMPORT_DELTAS("robot.importDeltas"), - ROBOT_IMPORT_ATTACHMENT("robot.importAttachment"), - - // Remove these deprecated operations once all robots are upgraded to v0.21. - @Deprecated WAVELET_ADD_PARTICIPANT("wavelet.participant.add"), - @Deprecated WAVELET_REMOVE_PARTICIPANT("wavelet.participant.remove"), - - @Deprecated WAVELET_DATADOC_APPEND("wavelet.datadoc.append"), - @Deprecated WAVELET_DATADOC_SET("wavelet.datadoc.set"), - - @Deprecated DOCUMENT_ANNOTATION_DELETE("document.annotation.delete"), - @Deprecated DOCUMENT_ANNOTATION_SET("document.annotation.set"), - @Deprecated DOCUMENT_ANNOTATION_SET_NORANGE("document.annotation.setNoRange"), - - @Deprecated DOCUMENT_ELEMENT_APPEND("document.element.append"), - @Deprecated DOCUMENT_ELEMENT_DELETE("document.element.delete"), - @Deprecated DOCUMENT_ELEMENT_INSERT("document.element.insert"), - @Deprecated DOCUMENT_ELEMENT_INSERT_AFTER("document.element.insertAfter"), - @Deprecated DOCUMENT_ELEMENT_INSERT_BEFORE("document.element.insertBefore"), - @Deprecated DOCUMENT_ELEMENT_MODIFY_ATTRS("document.element.modifyAttrs"), - @Deprecated DOCUMENT_ELEMENT_REPLACE("document.element.replace"), - - @Deprecated DOCUMENT_INLINE_BLIP_APPEND("document.inlineBlip.append"), - @Deprecated DOCUMENT_INLINE_BLIP_INSERT("document.inlineBlip.insert"), - @Deprecated DOCUMENT_INLINE_BLIP_INSERT_AFTER_ELEMENT("document.inlineBlip.insertAfterElement"), - - @Deprecated ROBOT_NOTIFY_CAPABILITIES_HASH("robot.notifyCapabilitiesHash"); - - private static final Logger LOG = Logger.getLogger(OperationType.class.getName()); - - private static final Map<String, OperationType> reverseLookupMap = - new HashMap<String, OperationType>(); - - static { - for (OperationType operationType : OperationType.values()) { - if (reverseLookupMap.containsKey(operationType.method)) { - LOG.warning("Operation with method name " + operationType.method + " already exist."); - } - reverseLookupMap.put(operationType.method, operationType); - } - } - - private final String method; - - private OperationType(String method) { - this.method = method; - } - - /** - * Returns the method name of an operation type. - * - * @return The method name of an operation type. - */ - public String method() { - return method; - } - - /** - * Returns an {@link OperationType} enumeration that has the given method - * name. If no match is found, UNKNOWN is returned. - * - * @param methodName The method name of an operation. - * @return An {@link OperationType} that has the given method name. - */ - public static OperationType fromMethodName(String methodName) { - OperationType operationType = reverseLookupMap.get(methodName); - if (operationType == null) { - return UNKNOWN; - } - return operationType; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/ParticipantProfile.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/ParticipantProfile.java b/wave/src/main/java/com/google/wave/api/ParticipantProfile.java deleted file mode 100644 index 7b9709a..0000000 --- a/wave/src/main/java/com/google/wave/api/ParticipantProfile.java +++ /dev/null @@ -1,101 +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; - -import java.io.Serializable; - -/** - * ParticipantProfile represents participant information. It contains display - * name, avatar's URL, and an external URL to view the participant's profile - * page. This is a data transfer object that is being sent from Robot when Rusty - * queries a profile. A participant can be the Robot itself, or a user in the - * Robot's domain. - * - * @author [email protected] (Marcel Prasetya) - */ -public final class ParticipantProfile implements Serializable { - - private final String address; - private final String name; - private final String imageUrl; - private final String profileUrl; - - /** - * Constructs an empty profile. - */ - public ParticipantProfile() { - this("", "", "", ""); - } - - /** - * Constructs a profile. - * - * @param name the name of the participant. - * @param imageUrl the URL of the participant's avatar. - * @param profileUrl the URL of the participant's external profile page. - */ - public ParticipantProfile(String name, String imageUrl, String profileUrl) { - this("", name, imageUrl, profileUrl); - } - - /** - * Constructs a profile. - * - * @param address the address of the participant. - * @param name the name of the participant. - * @param imageUrl the URL of the participant's avatar. - * @param profileUrl the URL of the participant's external profile page. - */ - public ParticipantProfile(String address, String name, String imageUrl, - String profileUrl) { - this.address = address; - this.name = name; - this.imageUrl = imageUrl; - this.profileUrl = profileUrl; - } - - /** - * @return the address of the participant. - */ - public String getAddress() { - return address; - } - - /** - * @return the name of the participant. - */ - public String getName() { - return name; - } - - /** - * @return the URL of the participant's avatar. - */ - public String getImageUrl() { - return imageUrl; - } - - /** - * @return the URL of the profile page. - */ - public String getProfileUrl() { - return profileUrl; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/Participants.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/Participants.java b/wave/src/main/java/com/google/wave/api/Participants.java deleted file mode 100644 index e11aae2..0000000 --- a/wave/src/main/java/com/google/wave/api/Participants.java +++ /dev/null @@ -1,222 +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; - - -import java.io.Serializable; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; - -/** - * A class that represents wavelet's participants. This class supports various - * participant related operations, such as, adding participant to a wavelet. - */ -public class Participants implements Set<String>, Serializable { - - /** - * Roles to use for the participants - */ - public enum Role { - /** Full member. */ - FULL, - /** Can only view the wave. */ - READ_ONLY, - /** Not recognized. Probably a newer server version. */ - UNKNOWN; - } - - /** A set of participant id that represents wavelet participants. */ - private final Set<String> participants; - - /** The wavelet that this participant set represents. */ - private final Wavelet wavelet; - - /** The operation queue to queue operation to the robot proxy. */ - private final OperationQueue operationQueue; - - /** The roles of the participants. The values are strings to match the wire - * protocol. - */ - private final Map<String, String> roles; - - /** - * Constructor. - * - * @param participants a collection of initial participants of the wavelet. - * @param wavelet the wavelet that this participants list represents. - * @param operationQueue the operation queue to queue operation to the robot - * proxy. - */ - public Participants(Collection<String> participants, Map<String, String> roles, - Wavelet wavelet, OperationQueue operationQueue) { - this.participants = new LinkedHashSet<String>(participants); - this.roles = roles; - this.wavelet = wavelet; - this.operationQueue = operationQueue; - } - - /** - * Add the given participant id if it doesn't exist. - * - * @param participantId the id of the participant that will be added. - * @return {@code true} if the given participant id does not exist yet - * in the set of participants, which means that a new - * {@code wavelet.addParticipant()} has been queued. Otherwise, returns - * {@code false}. - */ - @Override - public boolean add(String participantId) { - if (participants.contains(participantId)) { - return false; - } - - operationQueue.addParticipantToWavelet(wavelet, participantId); - participants.add(participantId); - return true; - } - - /** - * Checks whether the given participant id exists in the set or not. - * - * @param participantId the participant id to check. - * @return {@code true} if the set contains the given participant id. - * Otherwise, returns {@code false}. - */ - @Override - public boolean contains(Object participantId) { - return participants.contains(participantId); - } - - /** - * Returns the number of participants of the wavelet that owns this - * participant set. - * - * @return the number of participants. - */ - @Override - public int size() { - return participants.size(); - } - - /** - * Checks whether this participant set is empty or not. - * - * @return {@code true} if the participant set is empty. Otherwise, returns - * {@code false}. - */ - @Override - public boolean isEmpty() { - return participants.isEmpty(); - } - - @Override - public Iterator<String> iterator() { - return participants.iterator(); - } - - @Override - public boolean addAll(Collection<? extends String> c) { - boolean retval = false; - for (String participant : c) { - retval = retval || add(participant); - } - return retval; - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean containsAll(Collection<?> c) { - boolean retval = true; - for (Object participant : c) { - retval = retval && contains(participant); - } - return retval; - } - - /** - * Remove the given participant id if it exist. - * - * @param participantId the id of the participant that will be removed. - * @return {@code true} if the given participant id does exist in the set - * of participants, which means that the - * {@code wavelet.removeParticipant()} has been dequeued. Otherwise, returns - * {@code false}. - */ - @Override - public boolean remove(Object oParticipantId) { - - if(!(oParticipantId instanceof String)) { - throw new IllegalArgumentException("ParticipantId must be a string."); - } - String participantId = (String) oParticipantId; - - if (!participants.contains(participantId)) { - return false; - } - - operationQueue.removeParticipantFromWavelet(wavelet, participantId); - participants.remove(participantId); - return true; - } - - @Override - public boolean removeAll(Collection<?> c) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean retainAll(Collection<?> c) { - throw new UnsupportedOperationException(); - } - - @Override - public Object[] toArray() { - return participants.toArray(); - } - - @Override - public <T> T[] toArray(T[] a) { - return participants.toArray(a); - } - - public void setParticipantRole(String participant, Role role) { - operationQueue.modifyParticipantRoleOfWavelet(wavelet, participant, role.name()); - roles.put(participant, role.name()); - } - - public Role getParticipantRole(String participant) { - String stringRole = roles.get(participant); - if (stringRole == null) { - return Role.FULL; - } - try { - return Role.valueOf(stringRole); - } catch (IllegalArgumentException e) { - return Role.UNKNOWN; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/Plaintext.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/Plaintext.java b/wave/src/main/java/com/google/wave/api/Plaintext.java deleted file mode 100644 index 742dec2..0000000 --- a/wave/src/main/java/com/google/wave/api/Plaintext.java +++ /dev/null @@ -1,95 +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; - -/** - * A class that models a plain-text content of a blip. - */ -public class Plaintext extends BlipContent { - - /** The text content. */ - private final StringBuilder text; - - /** - * Convenience factory method. - * - * @param text the text to construct the {@link Plaintext} object. - * @return an instance of {@link Plaintext} that represents the given string. - */ - public static Plaintext of(String text) { - return new Plaintext(text); - } - - /** - * Constructor. - * - * @param text the text content. - */ - public Plaintext(String text) { - this.text = new StringBuilder(text); - } - - /** - * Appends the given text to this {@link Plaintext} instance. - * - * @param text the text to be appended. - * @return an instance of this {@link Plaintext}, for chaining. - */ - public Plaintext append(String text) { - this.text.append(text); - return this; - } - - @Override - public String getText() { - return text.toString(); - } - - @Override - public int hashCode() { - return text.toString().hashCode(); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - - if (o == null) { - return false; - } - - if (getClass() != o.getClass()) { - return false; - } - - Plaintext other = (Plaintext) o; - if (text == null && other.text == null) { - return true; - } - - if ((text == null && other.text != null) || (text != null && other.text == null)) { - return false; - } - - return text.toString().equals(other.text.toString()); - } -}
