http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/BlipContentRefs.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/BlipContentRefs.java b/wave/src/main/java/com/google/wave/api/BlipContentRefs.java deleted file mode 100644 index 542c171..0000000 --- a/wave/src/main/java/com/google/wave/api/BlipContentRefs.java +++ /dev/null @@ -1,717 +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.Function.BlipContentFunction; -import com.google.wave.api.Function.MapFunction; -import com.google.wave.api.JsonRpcConstant.ParamsProperty; -import com.google.wave.api.OperationRequest.Parameter; -import com.google.wave.api.impl.DocumentModifyAction; -import com.google.wave.api.impl.DocumentModifyQuery; -import com.google.wave.api.impl.DocumentModifyAction.BundledAnnotation; -import com.google.wave.api.impl.DocumentModifyAction.ModifyHow; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -/** - * A class that represents a set of references to contents in a blip. - * - * A {@link BlipContentRefs} instance for example can represent the - * results of a search, an explicitly set range, a regular expression, or refer - * to the entire blip. - * - * {@link BlipContentRefs} are used to express operations on a blip in a - * consistent way that can be easily transfered to the server. - */ -public class BlipContentRefs implements Iterable<Range> { - - /** The blip that this blip references are pointing to. */ - private final Blip blip; - - /** The iterator to iterate over the blip content. */ - private final BlipIterator<?> iterator; - - /** The additional parameters that need to be supplied in the outgoing op. */ - private final List<Parameter> parameters; - - /** - * Constructs an instance representing the search for text {@code target}. - * - * @param blip the blip to find {@code target} in. - * @param target the target to search. - * @param maxResult the maximum number of results. - * @return an instance of blip references. - */ - public static BlipContentRefs all(Blip blip, String target, int maxResult) { - return new BlipContentRefs(blip, - new BlipIterator.TextIterator(blip, target, maxResult), - Parameter.of(ParamsProperty.MODIFY_QUERY, new DocumentModifyQuery(target, maxResult))); - } - - /** - * Constructs an instance representing the search for element - * {@code ElementType}, that has the properties specified in - * {@code restrictions}. - * - * @param blip the blip to find {@code target} in. - * @param target the element type to search. - * @param maxResult the maximum number of results. - * @param restrictions the additional properties filter that need to be - * matched. - * @return an instance of blip references. - */ - public static BlipContentRefs all(Blip blip, ElementType target, int maxResult, - Restriction... restrictions) { - Map<String, String> restrictionsAsMap = new HashMap<String, String>(restrictions.length); - for (Restriction restriction : restrictions) { - restrictionsAsMap.put(restriction.getKey(), restriction.getValue()); - } - - return new BlipContentRefs(blip, - new BlipIterator.ElementIterator(blip, target, restrictionsAsMap, maxResult), - Parameter.of(ParamsProperty.MODIFY_QUERY, - new DocumentModifyQuery(target, restrictionsAsMap, maxResult))); - } - - /** - * Constructs an instance representing the entire blip content. - * - * @param blip the blip to represent. - * @return an instance of blip references. - */ - public static BlipContentRefs all(Blip blip) { - return new BlipContentRefs(blip, - new BlipIterator.SingleshotIterator(blip, 0, blip.getContent().length())); - } - - /** - * Constructs an instance representing an explicitly set range. - * - * @param blip the blip to represent. - * @param start the start index of the range. - * @param end the end index of the range. - * @return an instance of blip references. - */ - public static BlipContentRefs range(Blip blip, int start, int end) { - return new BlipContentRefs(blip, - new BlipIterator.SingleshotIterator(blip, start, end), - Parameter.of(ParamsProperty.RANGE, new Range(start, end))); - } - - /** - * Private constructor. - * - * @param blip the blip to navigate. - * @param iterator the iterator to iterate over blip content. - * @param parameters the additional parameters to be passed in the outgoing - * operation. - */ - private BlipContentRefs(Blip blip, BlipIterator<?> iterator, Parameter... parameters) { - this.blip = blip; - this.iterator = iterator; - this.parameters = Arrays.asList(parameters); - } - - /** - * Executes this BlipRefs object. - * - * @param modifyHow the operation to be executed. - * @param bundledAnnotations optional list of annotations to immediately - * apply to newly added text. - * @param arguments a list of arguments for the operation. The arguments vary - * depending on the operation: - * <ul> - * <li>For DELETE: none (the supplied arguments will be ignored)</li> - * <li>For ANNOTATE: a list of {@link Annotation} objects</li> - * <li>For CLEAR_ANNOTATION: the key of the annotation to be - * cleared. Only the first argument will be used.</li> - * <li>For UPDATE_ELEMENT: a list of {@link Map}, each represents - * new element properties.</li> - * <li>For INSERT, INSERT_AFTER, or REPLACE: a list of - * {@link BlipContent}s. - * </ul> - * For operations that take a list of entities as the argument, once - * this method hits the end of the argument list, it will wrap around. - * For example, if this {@link BlipContentRefs} object has 5 hits, when - * applying an ANNOTATE operation with 4 arguments, the first argument - * will be applied to the 5th hit. - * @return this instance of blip references, for chaining. - */ - @SuppressWarnings({"unchecked", "fallthrough"}) - private BlipContentRefs execute( - ModifyHow modifyHow, List<BundledAnnotation> bundledAnnotations, Object... arguments) { - // If there is no match found, return immediately without generating op. - if (!iterator.hasNext()) { - return this; - } - - int nextIndex = 0; - Object next = null; - List<BlipContent> computed = new ArrayList<BlipContent>(); - List<Element> updatedElements = new ArrayList<Element>(); - boolean useMarkup = false; - - while (iterator.hasNext()) { - Range range = iterator.next(); - int start = range.getStart(); - int end = range.getEnd(); - - if (blip.length() == 0 && (start != 0 || end != 0)) { - throw new IndexOutOfBoundsException("Start and end have to be 0 for empty blip."); - } else if (start < 0 || end < 1) { - throw new IndexOutOfBoundsException("Position outside the blip."); - } else if ((start >= blip.length() || end > blip.length()) && - modifyHow != ModifyHow.INSERT) { - throw new IndexOutOfBoundsException("Position outside the blip."); - } else if (start > blip.length() && modifyHow == ModifyHow.INSERT) { - throw new IndexOutOfBoundsException("Position outside the blip."); - } else if (start >= end){ - throw new IndexOutOfBoundsException("Start has to be less than end."); - } - - // Get the next argument. - if (nextIndex < arguments.length) { - next = arguments[nextIndex]; - - // If the next argument is a function, call the function. - if (next instanceof Function) { - // Get the matched content. - BlipContent source; - if (end - start == 1 && blip.getElements().containsKey(start)) { - source = blip.getElements().get(start); - } else { - source = Plaintext.of(blip.getContent().substring(start, end)); - } - // Compute the new content. - next = ((Function) next).call(source); - if (next instanceof BlipContent) { - computed.add((BlipContent) next); - } - } - nextIndex = ++nextIndex % arguments.length; - } - - switch (modifyHow) { - case DELETE: - // You can't delete the first newline. - if (start == 0) { - start = 1; - } - - // Delete all elements that fall into this range. - Iterator<Integer> elementIterator = - blip.getElements().subMap(start, end).keySet().iterator(); - while(elementIterator.hasNext()) { - elementIterator.next(); - elementIterator.remove(); - } - - blip.deleteAnnotations(start, end); - blip.shift(end, start - end); - iterator.shift(-1); - blip.setContent(blip.getContent().substring(0, start) + - blip.getContent().substring(end)); - break; - case ANNOTATE: - Annotation annotation = Annotation.class.cast(next); - blip.getAnnotations().add(annotation.getName(), annotation.getValue(), start, end); - break; - case CLEAR_ANNOTATION: - String annotationName = arguments[0].toString(); - blip.getAnnotations().delete(annotationName, start, end); - break; - case UPDATE_ELEMENT: - Element existingElement = blip.getElements().get(start); - if (existingElement == null) { - throw new IllegalArgumentException("No element found at index " + start + "."); - } - Map<String, String> properties = Map.class.cast(next); - updatedElements.add(new Element(existingElement.getType(), properties)); - for (Entry<String, String> entry : properties.entrySet()) { - existingElement.setProperty(entry.getKey(), entry.getValue()); - } - break; - case INSERT: - end = start; - case INSERT_AFTER: - start = end; - case REPLACE: - // Get the plain-text version of next. - String text = BlipContent.class.cast(next).getText(); - - // Compute the shift amount for the iterator. - int iteratorShiftAmount = text.length() - 1; - if (end == start) { - iteratorShiftAmount += range.getEnd() - range.getStart(); - } - iterator.shift(iteratorShiftAmount); - - // In the case of a replace, and the replacement text is shorter, - // delete the delta. - if (start != end && text.length() < end - start) { - blip.deleteAnnotations(start + text.length(), end); - } - - blip.shift(end, text.length() + start - end); - blip.setContent(blip.getContent().substring(0, start) + text + - blip.getContent().substring(end)); - - if (next instanceof Element) { - blip.getElements().put(start, Element.class.cast(next)); - } else if (bundledAnnotations != null) { - for (BundledAnnotation bundled : bundledAnnotations) { - blip.getAnnotations().add(bundled.key, bundled.value, start, start + text.length()); - } - } - break; - } - } - - OperationRequest op = blip.getOperationQueue().modifyDocument(blip); - - for (Parameter parameter : parameters) { - op.addParameter(parameter); - } - - // Prepare the operation parameters. - List<String> values = null; - String annotationName = null; - List<Element> elements = null; - switch (modifyHow) { - case UPDATE_ELEMENT: - elements = updatedElements; - break; - case ANNOTATE: - values = new ArrayList<String>(arguments.length); - for (Object item : arguments) { - values.add(Annotation.class.cast(item).getValue()); - } - annotationName = Annotation.class.cast(arguments[0]).getName(); - break; - case CLEAR_ANNOTATION: - annotationName = arguments[0].toString(); - break; - case INSERT: - case INSERT_AFTER: - case REPLACE: - values = new ArrayList<String>(arguments.length); - elements = new ArrayList<Element>(arguments.length); - Object[] toBeAdded = arguments; - if (arguments[0] instanceof Function) { - toBeAdded = computed.toArray(); - } - for (Object argument : toBeAdded) { - if (argument instanceof Element) { - elements.add(Element.class.cast(argument)); - values.add(null); - } else if (argument instanceof Plaintext){ - values.add(BlipContent.class.cast(argument).getText()); - elements.add(null); - } - } - break; - } - - op.addParameter(Parameter.of(ParamsProperty.MODIFY_ACTION, - new DocumentModifyAction( - modifyHow, values, annotationName, elements, bundledAnnotations, useMarkup))); - - iterator.reset(); - return this; - } - - /** - * Inserts the given arguments at the matched positions. - * - * @param arguments the new contents to be inserted. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs insert(BlipContent... arguments) { - return insert(null, arguments); - } - - /** - * Inserts computed contents at the matched positions. - * - * @param functions the functions to compute the new contents based on the - * matched contents. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs insert(BlipContentFunction... functions) { - return insert(null, functions); - } - - /** - * Inserts the given strings at the matched positions. - * - * @param arguments the new strings to be inserted. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs insert(String... arguments) { - return insert(null, arguments); - } - - /** - * Inserts the given arguments at the matched positions. - * - * @param bundledAnnotations annotations to immediately apply to the inserted - * text. - * @param arguments the new contents to be inserted. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs insert( - List<BundledAnnotation> bundledAnnotations, BlipContent... arguments) { - return execute(ModifyHow.INSERT, bundledAnnotations, ((Object[]) arguments)); - } - - /** - * Inserts computed contents at the matched positions. - * - * @param bundledAnnotations annotations to immediately apply to the inserted - * text. - * @param functions the functions to compute the new contents based on the - * matched contents. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs insert( - List<BundledAnnotation> bundledAnnotations, BlipContentFunction... functions) { - return execute(ModifyHow.INSERT, bundledAnnotations, ((Object[]) functions)); - } - - /** - * Inserts the given strings at the matched positions. - * - * @param bundledAnnotations annotations to immediately apply to the inserted - * text. - * @param arguments the new strings to be inserted. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs insert(List<BundledAnnotation> bundledAnnotations, String... arguments) { - Object[] array = new Plaintext[arguments.length]; - for (int i = 0; i < arguments.length; ++i) { - array[i] = Plaintext.of(arguments[i]); - } - return execute(ModifyHow.INSERT, bundledAnnotations, array); - } - - /** - * Inserts the given arguments just after the matched positions. - * - * @param arguments the new contents to be inserted. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs insertAfter(BlipContent... arguments) { - return insertAfter(null, arguments); - } - - /** - * Inserts computed contents just after the matched positions. - * - * @param functions the functions to compute the new contents based on the - * matched contents. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs insertAfter(BlipContentFunction... functions) { - return insertAfter(null, functions); - } - - /** - * Inserts the given strings just after the matched positions. - * - * @param arguments the new strings to be inserted. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs insertAfter(String... arguments) { - return insertAfter(null, arguments); - } - - /** - * Inserts the given arguments just after the matched positions. - * - * @param bundledAnnotations annotations to immediately apply to the inserted - * text. - * @param arguments the new contents to be inserted. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs insertAfter( - List<BundledAnnotation> bundledAnnotations, BlipContent... arguments) { - return execute(ModifyHow.INSERT_AFTER, bundledAnnotations, (Object[]) arguments); - } - - /** - * Inserts computed contents just after the matched positions. - * - * @param bundledAnnotations annotations to immediately apply to the inserted - * text. - * @param functions the functions to compute the new contents based on the - * matched contents. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs insertAfter( - List<BundledAnnotation> bundledAnnotations, BlipContentFunction... functions) { - return execute(ModifyHow.INSERT_AFTER, bundledAnnotations, (Object[]) functions); - } - - /** - * Inserts the given strings just after the matched positions. - * - * @param bundledAnnotations annotations to immediately apply to the inserted - * text. - * @param arguments the new strings to be inserted. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs insertAfter( - List<BundledAnnotation> bundledAnnotations, String... arguments) { - Object[] array = new Plaintext[arguments.length]; - for (int i = 0; i < arguments.length; ++i) { - array[i] = Plaintext.of(arguments[i]); - } - return execute(ModifyHow.INSERT_AFTER, bundledAnnotations, array); - } - - /** - * Replaces the matched positions with the given arguments. - * - * @param arguments the new contents to replace the original contents. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs replace(BlipContent... arguments) { - return replace(null, arguments); - } - - /** - * Replaces the matched positions with computed contents. - * - * @param functions the functions to compute the new contents. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs replace(BlipContentFunction... functions) { - return replace(null, functions); - } - - /** - * Replaces the matched positions with the given strings. - * - * @param arguments the new strings to replace the original contents. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs replace(String... arguments) { - return replace(null, arguments); - } - - /** - * Replaces the matched positions with the given arguments. - * - * @param bundledAnnotations annotations to immediately apply to the inserted - * text. - * @param arguments the new contents to replace the original contents. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs replace( - List<BundledAnnotation> bundledAnnotations, BlipContent... arguments) { - return execute(ModifyHow.REPLACE, bundledAnnotations, (Object[]) arguments); - } - - /** - * Replaces the matched positions with computed contents. - * - * @param bundledAnnotations annotations to immediately apply to the inserted - * text. - * @param functions the functions to compute the new contents. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs replace( - List<BundledAnnotation> bundledAnnotations, BlipContentFunction... functions) { - return execute(ModifyHow.REPLACE, bundledAnnotations, (Object[]) functions); - } - - /** - * Replaces the matched positions with the given strings. - * - * @param bundledAnnotations annotations to immediately apply to the inserted - * text. - * @param arguments the new strings to replace the original contents. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs replace(List<BundledAnnotation> bundledAnnotations, String... arguments) { - Object[] array = new Plaintext[arguments.length]; - for (int i = 0; i < arguments.length; ++i) { - array[i] = Plaintext.of(arguments[i]); - } - return execute(ModifyHow.REPLACE, bundledAnnotations, array); - } - - /** - * Deletes the contents at the matched positions. - * - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs delete() { - return execute(ModifyHow.DELETE, null); - } - - /** - * Annotates the contents at the matched positions. - * - * @param key the annotation key. - * @param values the annotation values. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs annotate(String key, String... values) { - if (values.length == 0) { - values = new String[]{key}; - } - - Annotation[] annotations = new Annotation[values.length]; - for (int i = 0; i < values.length; ++i) { - annotations[i] = new Annotation(key, values[i], 0, 1); - } - return execute(ModifyHow.ANNOTATE, null, (Object[]) annotations); - } - - /** - * Clears the annotations at the matched positions. - * - * @param key the annotation key to be cleared. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs clearAnnotation(String key) { - return execute(ModifyHow.CLEAR_ANNOTATION, null, key); - } - - /** - * Updates the properties of all elements at the matched positions with the - * given properties map. - * - * Note: The purpose of this overloaded version is because the version that - * takes a var-args generates compiler warning due to the way generics and - * var-args are implemented in Java. Most of the time, robot only needs to - * update one gadget at at time, and it can use this version to avoid the - * compiler warning. - * - * @param newProperties the new properties map. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs updateElement(Map<String, String> newProperties) { - return execute(ModifyHow.UPDATE_ELEMENT, null, new Object[] {newProperties}); - } - - /** - * Updates the properties of all elements at the matched positions with - * computed properties map. - * - * Note: The purpose of this overloaded version is because the version that - * takes a var-args generates compiler warning due to the way generics and - * var-args are implemented in Java. Most of the time, robot only needs to - * update one gadget at at time, and it can use this version to avoid the - * compiler warning. - * - * @param function the function to compute the new properties map. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs updateElement(MapFunction function) { - return execute(ModifyHow.UPDATE_ELEMENT, null, new Object[] {function}); - } - - /** - * Updates the properties of all elements at the matched positions with the - * given properties maps. - * - * @param newProperties an array of new properties map. - * @return an instance of this blip references, for chaining. - */ - @SuppressWarnings("unchecked") - public BlipContentRefs updateElement(Map<String, String>... newProperties) { - return execute(ModifyHow.UPDATE_ELEMENT, null, (Object[]) newProperties); - } - - /** - * Updates the properties of all elements at the matched positions with - * computed properties maps. - * - * @param functions an array of function to compute new properties maps. - * @return an instance of this blip references, for chaining. - */ - public BlipContentRefs updateElement(MapFunction... functions) { - return execute(ModifyHow.UPDATE_ELEMENT, null, (Object[]) functions); - } - - /** - * Checks whether this blip references contains any matches or not. - * - * @return {@code true} if it has any more matches. Otherwise, returns - * {@code false}. - */ - public boolean isEmpty() { - return iterator.hasNext(); - } - - /** - * Returns all matches. - * - * @return a list of {@link BlipContent} that represents the hits. - */ - public List<BlipContent> values() { - List<BlipContent> result = new ArrayList<BlipContent>(); - while (iterator.hasNext()) { - Range range = iterator.next(); - if (range.getEnd() - range.getStart() == 1 && - blip.getElements().containsKey(range.getStart())) { - result.add(blip.getElements().get(range.getStart())); - } else { - result.add(Plaintext.of(blip.getContent().substring(range.getStart(), range.getEnd()))); - } - } - iterator.reset(); - return result; - } - - /** - * Returns the first hit. - * - * @return an instance of {@link BlipContent}, that represents the first hit. - */ - public BlipContent value() { - BlipContent result = null; - if (iterator.hasNext()) { - Range range = iterator.next(); - if (range.getEnd() - range.getStart() == 1 && - blip.getElements().containsKey(range.getStart())) { - result = blip.getElements().get(range.getStart()); - } else { - result = Plaintext.of(blip.getContent().substring(range.getStart(), range.getEnd())); - } - } - iterator.reset(); - return result; - } - - @Override - public Iterator<Range> iterator() { - iterator.reset(); - return iterator; - } -}
http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/BlipData.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/BlipData.java b/wave/src/main/java/com/google/wave/api/BlipData.java deleted file mode 100644 index 6aa9466..0000000 --- a/wave/src/main/java/com/google/wave/api/BlipData.java +++ /dev/null @@ -1,491 +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.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -/** - * BlipData is the serializable data representation of a Blip. It contains - * metadata, a text-only representation of the document content, and a list of - * annotations. - * - * @author [email protected] (Seth Covitz) - * @author [email protected] (Marcel Prasetya) - */ -public class BlipData { - - /** - * The list of annotations for the document content. - */ - private List<Annotation> annotations; - - /** - * The list of elements embedded within the document. - */ - private Map<Integer, Element> elements; - - /** - * The blip id for this blip. - */ - private String blipId; - - /** - * A list of child blip ids for this blip. - */ - private List<String> childBlipIds; - - /** - * A list of contributors to this blip. - */ - private List<String> contributors; - - /** - * The creator of this blip. - */ - private String creator; - - /** - * The text document content for this blip. - */ - private String content; - - /** - * The time this blip was last modified. - */ - private long lastModifiedTime; - - /** - * The parent blip id for this blip. - */ - private String parentBlipId; - - /** - * The latest version number for this blip. - */ - private long version; - - /** - * The Wave ID for the wave containing this blip. - */ - private String waveId; - - /** - * The Wavelet ID for the wavelet containing this blip. - */ - private String waveletId; - - /** - * The inline and non-inline reply thread ids. - */ - private List<String> replyThreadIds; - - /** - * Get the thread to which this blip belongs. - */ - private String threadId; - - /** - * Constructs an empty BlipData object. - */ - public BlipData() { - annotations = new ArrayList<Annotation>(); - elements = new HashMap<Integer, Element>(); - childBlipIds = new ArrayList<String>(); - content = "\n"; - contributors = new ArrayList<String>(); - lastModifiedTime = -1L; - version = -1L; - replyThreadIds = new ArrayList<String>(); - } - - /** - * Constructs a BlipData object. - * - * @param waveId the wave id of the blip. - * @param waveletId the wavelet id of the blip. - * @param blipId the blip id. - * @param initialContent the initial content of the blip. If the supplied - * content doesn't start with a newline character, this constructor will - * auto-prepend that. - */ - public BlipData(String waveId, String waveletId, String blipId, String initialContent) { - this.annotations = new ArrayList<Annotation>(); - this.elements = new HashMap<Integer, Element>(); - this.childBlipIds = new ArrayList<String>(); - this.contributors = new ArrayList<String>(); - this.waveId = waveId; - this.waveletId = waveletId; - this.blipId = blipId; - - // Make sure that initial content is valid, and starts with newline. - if (initialContent == null || initialContent.isEmpty()) { - initialContent = "\n"; - } else if (!initialContent.startsWith("\n")) { - initialContent = "\n" + initialContent; - } - - this.content = initialContent; - } - - /** - * Creates a deep copy/clone of a blip's data. - * - * @param blip The original blip to be copied. - */ - public BlipData(BlipData blip) { - // Deep copy annotations. - annotations = new ArrayList<Annotation>(); - for (Annotation annotation : blip.getAnnotations()) { - Range range = annotation.getRange(); - annotations.add(new Annotation(annotation.getName(), annotation.getValue(), - range.getStart(), range.getEnd())); - } - - // Deep copy form elements. - elements = new HashMap<Integer, Element>(); - for (Entry<Integer, Element> entry : blip.getElements().entrySet()) { - ElementType type = entry.getValue().getType(); - Element result = null; - if (FormElement.getFormElementTypes().contains(type)) { - result = new FormElement(type, entry.getValue().getProperties()); - } else if (type == ElementType.GADGET) { - result = new Gadget(entry.getValue().getProperties()); - } else if (type == ElementType.IMAGE) { - result = new Image(entry.getValue().getProperties()); - } else if (type == ElementType.LINE) { - result = new Line(entry.getValue().getProperties()); - } else { - result = new Element(type, entry.getValue().getProperties()); - } - elements.put(entry.getKey(), result); - } - - creator = blip.getCreator(); - childBlipIds = blip.getChildBlipIds(); - content = blip.getContent(); - contributors = blip.getContributors(); - blipId = blip.getBlipId(); - lastModifiedTime = blip.getLastModifiedTime(); - version = blip.getVersion(); - parentBlipId = blip.getParentBlipId(); - waveId = blip.getWaveId(); - waveletId = blip.getWaveletId(); - replyThreadIds = blip.getReplyThreadIds(); - threadId = blip.getThreadId(); - } - - /** - * Adds an annotation to the end of the list of annotations. - * - * @param annotation the annotation to be added. - */ - public void addAnnotation(Annotation annotation) { - annotations.add(annotation); - } - - /** - * Returns the list of annotations modifying this document's content. - * - * @return a list of annotations. - */ - public List<Annotation> getAnnotations() { - return annotations == null ? new ArrayList<Annotation>() : annotations; - } - - /** - * Adds an element to the blip at a given index into the text document. - * - * @param position The character position / index into the document to insert - * the form element. - * @param element The form element to be added. - */ - public void addElement(int position, Element element) { - elements.put(position, element); - } - - /** - * Returns a map of the elements in the blip and the positions where - * they have been inserted. - * - * @return the map of form elements to document positions. - */ - public Map<Integer, Element> getElements() { - return elements; - } - - /** - * Returns the Blip ID for this blip. - * - * @return the blip id for this blip. - */ - public String getBlipId() { - return blipId; - } - - /** - * Returns a list of child Blip IDs for this blip. - * - * @return a list of child Blip IDs. - */ - public List<String> getChildBlipIds() { - return childBlipIds; - } - - /** - * Returns the list of email addresses corresponding to the contributors who - * have modified this blip's content. - * - * @return the list of contributors. - */ - public List<String> getContributors() { - return contributors; - } - - /** - * Returns the email address corresponding to the creator of this blip. - * - * @return the creator of this blip. - */ - public String getCreator() { - return creator; - } - - /** - * Returns the text document content for this blip. - * - * @return the text document content for this blip. - */ - public String getContent() { - return content; - } - - /** - * Returns the time in milliseconds since the UNIX epoch when this blip was - * last modified. - * - * @return the last modified time for this blip. - */ - public long getLastModifiedTime() { - return lastModifiedTime; - } - - /** - * Returns the parent Blip ID for this blip. - * - * @return the parent Blip ID for this blip. - */ - public String getParentBlipId() { - return parentBlipId; - } - - /** - * Returns the version number for this blip. - * - * @return the version number for this blip. - */ - public long getVersion() { - return version; - } - - /** - * Returns the Wave ID for the wave containing this blip. - * - * @return the Wave ID for the wave containing this blip. - */ - public String getWaveId() { - return waveId; - } - - /** - * Returns the Wavelet ID for the wavelet containing this blip. - * - * @return the Wavelet ID for the wavelet containing this blip. - */ - public String getWaveletId() { - return waveletId; - } - - /** - * Replaces the blip's list of annotations with a new list of annotations. - * - * @param annotations the new list of annotations. - */ - public void setAnnotations(List<Annotation> annotations) { - this.annotations = annotations; - } - - /** - * Replaces the blip's list of elements with a new list of elements. - * - * @param map the new list of elements. - */ - public void setElements(Map<Integer, Element> map) { - this.elements = map; - } - - /** - * Returns the Blip ID for this blip. - * - * @param blipId the Blip ID for this blip. - */ - public void setBlipId(String blipId) { - this.blipId = blipId; - } - - /** - * Replaces the blip's list of child Blip IDs with a new list. - * - * @param childBlipIds the new list of child Blip IDs. - */ - public void setChildBlipIds(List<String> childBlipIds) { - this.childBlipIds = childBlipIds; - } - - /** - * Adds a new child blip id to this blip's list of child id's. - * - * @param blipId the Blip ID to be added. - */ - public void addChildBlipId(String blipId) { - this.childBlipIds.add(blipId); - } - - /** - * Replaces the blip's list of contributors with a new list. - * - * @param contributors the new list of contributors. - */ - public void setContributors(List<String> contributors) { - this.contributors = contributors; - } - - /** - * Adds a contributor to this blip's list of contributors. - * - * @param contributor a new contributor to the blip. - */ - public void addContributor(String contributor) { - this.contributors.add(contributor); - } - - /** - * Sets the creator of the blip. - * - * @param creator the creator of the blip. - */ - public void setCreator(String creator) { - this.creator = creator; - } - - /** - * Replaces the blip's text document content. - * - * @param content the new text content for the blip. - */ - public void setContent(String content) { - this.content = content; - } - - /** - * Sets the last modified time measured in milliseconds since the UNIX epoch - * when the blip was last modified. - * - * @param lastModifiedTime the last modified time of the blip. - */ - public void setLastModifiedTime(long lastModifiedTime) { - this.lastModifiedTime = lastModifiedTime; - } - - /** - * Set's the parent Blip ID for the blip. - * - * @param parentBlipId the parent blip id. - */ - public void setParentBlipId(String parentBlipId) { - this.parentBlipId = parentBlipId; - } - - /** - * Sets the version of the blip. - * - * @param version the version of the blip. - */ - public void setVersion(long version) { - this.version = version; - } - - /** - * Sets the Wave ID of the blip. - * - * @param waveId the Wave ID of the blip. - */ - public void setWaveId(String waveId) { - this.waveId = waveId; - } - - /** - * Sets the Wavelet ID of the blip. - * - * @param waveletId the Wavelet ID of the blip. - */ - public void setWaveletId(String waveletId) { - this.waveletId = waveletId; - } - - public void removeChildBlipId(String blipId) { - childBlipIds.remove(blipId); - } - - /** - * @return the inline and non-inline reply threads' ids. - */ - public List<String> getReplyThreadIds() { - return replyThreadIds; - } - - /** - * Sets the list of inline and non-inline reply threads' ids. - * - * @param replyThreadIds a list of ids of the reply threads. - */ - public void setReplyThreadIds(List<String> replyThreadIds) { - this.replyThreadIds = replyThreadIds; - } - - /** - * @return the id of the thread to which this blip belongs to. - */ - public String getThreadId() { - return threadId; - } - - /** - * Sets the id of the thread to which this blip belongs to. - - * @param threadId the id of the parent thread. - */ - public void setThreadId(String threadId) { - this.threadId = threadId; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/BlipIterator.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/BlipIterator.java b/wave/src/main/java/com/google/wave/api/BlipIterator.java deleted file mode 100644 index f76d789..0000000 --- a/wave/src/main/java/com/google/wave/api/BlipIterator.java +++ /dev/null @@ -1,238 +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.Iterator; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Map.Entry; - -/** - * An iterator over blip content, that consists of text or element. - * - * Please note that this iterator does not support {@code remove} operation at - * the moment. - * - * @param <T> the generic type of the target entity to match. - */ -public abstract class BlipIterator<T> implements Iterator<Range> { - - /** The blip to be iterated. */ - protected final Blip blip; - - /** The target to be matched. */ - protected final T target; - - /** The maximum number of iterations allowed. */ - private final int maxHits; - - /** The range size of a match. */ - private final int rangeSize; - - /** The number of allowed iterations left. */ - private int hitsLeft; - - /** The current position of the iterator. */ - protected int position; - - /** - * Constructor. - * - * @param blip the blip to be iterated. - * @param target the target to be matched. - * @param maxHits the maximum number of iterations allowed. - * @param rangeSize the size of a matching range, for example, 1 for element - * iteration, or the length of the {@code target} for text/string - * iteration. - */ - protected BlipIterator(Blip blip, T target, int maxHits, int rangeSize) { - this.blip = blip; - this.target = target; - this.maxHits = maxHits; - this.rangeSize = rangeSize; - reset(); - } - - @Override - public boolean hasNext() { - return hitsLeft != 0 && getNextIndex() != -1; - } - - @Override - public Range next() { - if (hitsLeft == 0) { - throw new NoSuchElementException(); - } - - int index = getNextIndex(); - if (index == -1) { - throw new NoSuchElementException(); - } - - hitsLeft--; - position = index; - return new Range(position, position + rangeSize); - } - - /** - * {@code remove} is not supported. - * - * @throws UnsupportedOperationException this operation is not supported yet. - * it will throw {@link UnsupportedOperationException} on all invocations. - */ - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - /** - * Shifts the iterator cursor. - * - * @param shiftAmount the shift amount. - */ - void shift(int shiftAmount) { - this.position += shiftAmount; - } - - /** - * Shifts the iterator cursor to beginning, to reset iteration. - */ - void reset() { - this.position = -1; - this.hitsLeft = maxHits; - } - - /** - * Returns the index of the next match. - * - * @return the index of the next match, or -1 if there is no more match. - */ - protected abstract int getNextIndex(); - - /** - * A blip iterator that allows a single iteration over a given range. - */ - static final class SingleshotIterator extends BlipIterator<Void> { - - /** The starting index of the range. */ - private final int start; - - /** - * Constructor. - * - * @param blip the blip to iterate. - * @param start the start index of the range to iterate. - * @param end the end index of the range to iterate. - */ - public SingleshotIterator(Blip blip, int start, int end) { - super(blip, null, 1, end - start); - int length = blip.getContent().length(); - this.start = start; - } - - @Override - protected int getNextIndex() { - return start; - } - } - - /** - * A blip iterator that allows iteration over text/string content. - */ - static final class TextIterator extends BlipIterator<String> { - - /** - * Constructor. - * - * @param blip the blip to be iterated. - * @param target the string to be matched. - * @param maxHits the maximum number of iterations allowed. - */ - public TextIterator(Blip blip, String target, int maxHits) { - super(blip, target, maxHits, target.length()); - } - - @Override - protected int getNextIndex() { - return blip.getContent().indexOf(target, position + 1); - } - } - - /** - * A blip iterator that allows iteration over element content, such as, - * gadget, form element, image, and so on. - */ - static final class ElementIterator extends BlipIterator<ElementType> { - - /** A map of restrictions that would be applied during iteration. */ - private final Map<String, String> restrictions; - - /** - * Constructor. - * - * @param blip the blip to be iterated. - * @param target the string to be matched. - * @param restrictions a map of restrictions. - * @param maxHits the maximum number of iterations allowed. - */ - public ElementIterator(Blip blip, ElementType target, Map<String, String> restrictions, - int maxHits) { - super(blip, target, maxHits, 1); - this.restrictions = restrictions; - } - - @Override - protected int getNextIndex() { - int index = -1; - for (Entry<Integer, Element> entry : blip.getElements().tailMap(position + 1).entrySet()) { - if (match(entry.getValue())) { - index = entry.getKey(); - break; - } - } - return index; - } - - /** - * Checks whether the given {@code element} is a match or not, by checking - * the type and the properties. - * - * @param element the element to check. - * @return {@code true} if the element type matches the target type, and - * the all filters/restrictions are satisfied. - */ - private boolean match(Element element) { - if (element.getType() != target) { - return false; - } - - if (restrictions == null) { - return true; - } - - for (Entry<String, String> entry : restrictions.entrySet()) { - if (!entry.getValue().equals(element.getProperty(entry.getKey()))) { - return false; - } - } - return true; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/BlipThread.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/BlipThread.java b/wave/src/main/java/com/google/wave/api/BlipThread.java deleted file mode 100644 index f8053f9..0000000 --- a/wave/src/main/java/com/google/wave/api/BlipThread.java +++ /dev/null @@ -1,132 +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.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * A thread represents a group of blips in a wave. - */ -public class BlipThread implements Serializable { - - /** The id of the thread. */ - private final String id; - - /** The offset of the parent blip where this thread is inlined. */ - private int location; - - /** A list of ids of all blips that are in this thread. */ - private final List<String> blipIds; - - /** A map of blips of the wavelet to which this thread belongs to. */ - @NonJsonSerializable private final Map<String, Blip> blips; - - /** - * Constructor. - * - * @param id the id of the thread. - * @param location the location or offset of this thread in the containing - * blip. This should be {@code -1} if this is not an inline thread. - * @param blipIds the ids of the blips that are in this thread. - * @param blips a map of blips of the wavelet to which this thread belongs to. - */ - public BlipThread(String id, int location, List<String> blipIds, Map<String, Blip> blips) { - this.id = id; - this.location = location; - this.blipIds = blipIds; - this.blips = blips; - } - - /** - * @return the id of the thread. - */ - public String getId() { - return id; - } - - /** - * @return the location or offset of this thread in the containing or parent - * blip. This method will return {@code -1} if this {@link BlipThread} is not - * an inline thread. - */ - public int getLocation() { - return location; - } - - /** - * Sets the location of the thread. - * - * @param location the new location. - */ - public void setLocation(int location) { - this.location = location; - } - - /** - * @return a list of all blip ids that are in this thread. - */ - public List<String> getBlipIds() { - return blipIds; - } - - /** - * @return all available blips that are in this thread. - */ - public List<Blip> getBlips() { - List<Blip> result = new ArrayList<Blip>(blipIds.size()); - for (String blipId : blipIds) { - Blip blip = blips.get(blipId); - if (blip != null) { - result.add(blips.get(blipId)); - } - } - return result; - } - - /** - * Appends a blip to the end of this thread. - * - * @param blip the blip to append. - */ - void appendBlip(Blip blip) { - blipIds.add(blip.getBlipId()); - } - - /** - * Removes a blip from this thread. - * - * @param blip the blip to remove. - * @return {@code true} if this thread contained the given id, and removal was - * successful. - */ - boolean removeBlip(Blip blip) { - return blipIds.remove(blip.getBlipId()); - } - - /** - * @return {@code true} if this thread has no blips. - */ - boolean isEmpty() { - return blipIds.isEmpty(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/Context.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/Context.java b/wave/src/main/java/com/google/wave/api/Context.java deleted file mode 100644 index 7d05928..0000000 --- a/wave/src/main/java/com/google/wave/api/Context.java +++ /dev/null @@ -1,44 +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; - -/** - * Enumeration that represents the context that the robot needs to provide when - * calling the Robot's event handler. This is specified in the Robot's - * capabilities.xml. - */ -public enum Context { - /** The first blip in the root thread. */ - ROOT, - /** The preceeding blip in the thread, or parent blip for a new thread. */ - PARENT, - /** The blips in the same thread. */ - SIBLINGS, - /** The next blip in the thread and the first blip in each reply. */ - CHILDREN, - /** Just one blip. */ - SELF, - /** All blips .*/ - ALL; - - public static Context valueOfIgnoreCase(String name) { - return valueOf(name.toUpperCase()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/DataDocuments.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/DataDocuments.java b/wave/src/main/java/com/google/wave/api/DataDocuments.java deleted file mode 100644 index e6ee6f6..0000000 --- a/wave/src/main/java/com/google/wave/api/DataDocuments.java +++ /dev/null @@ -1,129 +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.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; - -/** - * A class that represents wavelet's data documents. This class supports various - * data document related operations, such as, getting, setting, or removing - * data document value from a wavelet. - */ -public class DataDocuments implements Iterable<Entry<String,String>>, Serializable { - - /** A map of data documents values. */ - private final Map<String, String> dataDocuments; - - /** The wavelet that this data document represents. */ - private final Wavelet wavelet; - - /** The operation queue to queue operation to the robot proxy. */ - private final OperationQueue operationQueue; - - /** - * Constructor. - * - * @param dataDocuments a map of initial data documents. - * @param wavelet the wavelet that this data documents represents. - * @param operationQueue the operation queue to queue operation to the robot - * proxy. - */ - public DataDocuments(Map<String, String> dataDocuments, Wavelet wavelet, - OperationQueue operationQueue) { - this.dataDocuments = new HashMap<String, String>(dataDocuments); - this.wavelet = wavelet; - this.operationQueue = operationQueue; - } - - /** - * Associates the given name/key with the given value in the data documents. - * - * @param name the key with which the specified value is to be associated. - * @param value the value to be associated with the given name/key. - * @return the previous value for the given name/key. - */ - public String set(String name, String value) { - if (value == null) { - throw new IllegalArgumentException("Value should not be null."); - } - operationQueue.setDatadocOfWavelet(wavelet, name, value); - return dataDocuments.put(name, value); - } - - /** - * Removes the value of the given key from the data documents. - * - * @param name the key whose value will be removed. - * @return the previous value for the given name/key. - */ - public String remove(String name) { - operationQueue.setDatadocOfWavelet(wavelet, name, null); - return dataDocuments.remove(name); - } - - /** - * Checks whether the given key exists in the data documents. - * - * @param name the key to check. - * @return {@code true} if the set contains the given name/key. - * Otherwise, returns {@code false}. - */ - public boolean contains(String name) { - return dataDocuments.containsKey(name); - } - - /** - * Returns the number of values in the data documents. - * - * @return the size of the data documents. - */ - public int size() { - return dataDocuments.size(); - } - - /** - * Checks whether this data documents is empty or not. - * - * @return {@code true} if the data documents is empty. Otherwise, returns - * {@code false}. - */ - public boolean isEmpty() { - return dataDocuments.isEmpty(); - } - - /** - * Returns the data document by its name. - * @param name the name of the data document. - * - * @return The data document, or {@code null} if it does not exist. - */ - public String get(String name) { - return dataDocuments.get(name); - } - - @Override - public Iterator<Entry<String, String>> iterator() { - return dataDocuments.entrySet().iterator(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/Element.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/Element.java b/wave/src/main/java/com/google/wave/api/Element.java deleted file mode 100644 index 23817b3..0000000 --- a/wave/src/main/java/com/google/wave/api/Element.java +++ /dev/null @@ -1,172 +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.HashMap; -import java.util.Map; - -/** - * Elements are non-text content within a document. What the represent is - * generally abstracted from the Robot. Although a Robot can query the - * properties of an element it can only interact with the specific types that - * the element represents. - */ -public class Element extends BlipContent implements Serializable { - - /** The type of an element. */ - private final ElementType type; - - /** A map of properties representing details of the element. */ - private final Map<String, String> properties; - - /** - * Creates an element of the given type. - * - * @param type the type of element to construct. - */ - public Element(ElementType type) { - this.type = type; - this.properties = new HashMap<String, String>(); - } - - /** - * Constructs an Element of the given type with an initial set of properties. - * - * @param type the type of element to construct. - * @param properties the properties of the element. - */ - public Element(ElementType type, Map<String, String> properties) { - this.type = type; - this.properties = properties; - } - - /** - * Returns the type of the element. - * - * @return the type of the element. - */ - public ElementType getType() { - return type; - } - - /** - * Returns the map of properties for this element. - * - * @return the map of properties for this element. - */ - public Map<String, String> getProperties() { - return properties; - } - - /** - * Creates/replaces a property with the given to a new value. - * - * @param name the name of the property to create/replace. - * @param value the value to be set on this property. - */ - public void setProperty(String name, String value) { - this.properties.put(name, value); - } - - /** - * Returns the named property of this element. - * - * @param name the name of the property. - * @return the value of the property or null if the property was not found. - */ - public String getProperty(String name) { - return getProperty(name, null); - } - - /** - * Returns the named property of this element, or the default value if the - * property was not found. - * - * @param name the name of the property. - * @param defaultValue the default value of the property. - * @return the value of the property or the default value if the property was - * not found. - */ - public String getProperty(String name, String defaultValue) { - Object property = this.properties.get(name); - if (property != null) { - // We can't safely assume that the property is of type String, so we need - // to call toString(). - return property.toString(); - } - return defaultValue; - } - - /** - * Returns whether this element is a form element. - * - * @return true if the element is a form element, false otherwise. - */ - public boolean isFormElement() { - return FormElement.getFormElementTypes().contains(type); - } - - /** - * Returns whether this element is a gadget. - * - * @return true if the element is a gadget, false otherwise. - */ - public boolean isGadget() { - return type == ElementType.GADGET; - } - - /** - * Returns whether this element is an inline blip. - * - * @return true if the element is an inline blip, false otherwise. - */ - public boolean isInlineBlip() { - return type == ElementType.INLINE_BLIP; - } - - /** - * Returns whether this element is an image. - * - * @return true if the element is an image, false otherwise. - */ - public boolean isImage() { - return type == ElementType.IMAGE; - } - - /** - * Returns whether this element is an attachment. - * - * @return true if the element is an attachment, false otherwise. - */ - public boolean isAttachment() { - return type == ElementType.ATTACHMENT; - } - - @Override - public String toString() { - return "{'type':'" + type + "','properties':" + properties + "}"; - } - - @Override - public String getText() { - return type == ElementType.LINE ? "\n" : " "; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/ElementType.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/ElementType.java b/wave/src/main/java/com/google/wave/api/ElementType.java deleted file mode 100644 index d613589..0000000 --- a/wave/src/main/java/com/google/wave/api/ElementType.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; - -/** - * Element Types. - * - * @author [email protected] (Seth Covitz) - * @author [email protected] (Marcel Prasetya) - */ -public enum ElementType { - // Form Elements - INPUT("INPUT"), - PASSWORD("PASSWORD"), - CHECK("CHECK"), - LABEL("LABEL"), - BUTTON("BUTTON"), - RADIO_BUTTON("RADIO_BUTTON"), - RADIO_BUTTON_GROUP("RADIO_BUTTON_GROUP"), - TEXTAREA("TEXTAREA"), - // Other - INLINE_BLIP("INLINE_BLIP"), - GADGET("GADGET"), - INSTALLER("INSTALLER"), - IMAGE("IMAGE"), - LINE("LINE"), - ATTACHMENT("ATTACHMENT"); - - private final String text; - - private ElementType(String text) { - this.text = text; - } - - @Override - public String toString() { - return text; - } - - /** - * Converts a string into an ElementType. This is used primarily during - * deserialization from JSON. - * - * @param name the name of the ElementType. - * @return the ElementType representing that name. - */ - public static ElementType valueOfIgnoreCase(String name) { - return valueOf(name.toUpperCase()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/FetchProfilesRequest.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/FetchProfilesRequest.java b/wave/src/main/java/com/google/wave/api/FetchProfilesRequest.java deleted file mode 100644 index a5ac531..0000000 --- a/wave/src/main/java/com/google/wave/api/FetchProfilesRequest.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; - -import java.util.List; - -/** - * FetchProfilesRequest contain the request for one or more profiles. - */ -public class FetchProfilesRequest { - - private final List<String> participantIds; - private final String language; - - /** - * No-args constructor to keep gson happy. - */ - public FetchProfilesRequest() { - this(null, null); - } - - public FetchProfilesRequest(List<String> participantIds) { - this(participantIds, null); - } - - public FetchProfilesRequest(List<String> participantIds, String language) { - this.participantIds = participantIds; - this.language = language; - } - - /** - * @return the requested language of the profile. - */ - public String getLanguage() { - return language; - } - - /** - * @return the participant ids of the requested profile. - */ - public List<String> getParticipantIds() { - return participantIds; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/FetchProfilesResult.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/FetchProfilesResult.java b/wave/src/main/java/com/google/wave/api/FetchProfilesResult.java deleted file mode 100644 index 8444594..0000000 --- a/wave/src/main/java/com/google/wave/api/FetchProfilesResult.java +++ /dev/null @@ -1,54 +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.List; - -/** - * FetchProfilesResult contains the results of a fetch profile request. - */ -public class FetchProfilesResult { - - /** The requested profile. */ - private final List<ParticipantProfile> profiles; - - /** - * Constructor. - * - * @param profiles the requested profile. - */ - public FetchProfilesResult(List<ParticipantProfile> profiles) { - this.profiles = profiles; - } - - /** - * @return the requested profiles. - */ - public List<ParticipantProfile> getProfiles() { - return profiles; - } - - /** - * No-args constructor to keep GSON happy. - */ - FetchProfilesResult() { - this.profiles = null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/FormElement.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/FormElement.java b/wave/src/main/java/com/google/wave/api/FormElement.java deleted file mode 100644 index c0830bd..0000000 --- a/wave/src/main/java/com/google/wave/api/FormElement.java +++ /dev/null @@ -1,199 +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.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * Form Elements allow users and robots to build forms for other users to - * interact with. For each element you can specify its type, name, a default - * value and a label. The current value of the element is stored with in. - */ -public class FormElement extends Element { - - public static final String DEFAULT_VALUE = "defaultValue"; - public static final String NAME = "name"; - public static final String VALUE = "value"; - - private static final List<ElementType> FORM_ELEMENT_TYPES = new ArrayList<ElementType>(8); - static { - Collections.addAll(FORM_ELEMENT_TYPES, ElementType.BUTTON, ElementType.CHECK, - ElementType.INPUT, ElementType.PASSWORD, ElementType.LABEL, ElementType.RADIO_BUTTON, - ElementType.RADIO_BUTTON_GROUP, ElementType.TEXTAREA); - } - - /** - * Constructs a form element of the given type. - */ - public FormElement(ElementType type) { - this(type, "", "", ""); - } - - /** - * Constructs a form element given a type and name. - */ - public FormElement(ElementType type, String name) { - this(type, name, "", ""); - } - - /** - * Constructs a form element given a type, name and default value. - */ - public FormElement(ElementType type, String name, String defaultValue) { - this(type, name, defaultValue, defaultValue); - } - - /** - * Creates a copy of an existing form element. - */ - public FormElement(FormElement formElement) { - this(formElement.getType(), - formElement.getName(), - formElement.getDefaultValue(), - formElement.getValue()); - } - - /** - * Constructs a form element specifying all fields. - */ - public FormElement(ElementType type, String name, String defaultValue, String value) { - super(type); - setProperty(NAME, name); - setProperty(DEFAULT_VALUE, defaultValue); - setProperty(VALUE, value); - } - - /** - * Constructs a form element with a given set of properties. - * - * @param type the type of the form element. - * @param properties the properties of the form element. - */ - public FormElement(ElementType type, Map<String, String> properties) { - super(type, properties); - } - - /** - * Returns the name of the form element. - * - * @return the name of the form element. - */ - public String getName() { - return getPropertyNullCheck(NAME); - } - - private String getPropertyNullCheck(String name) { - String property = getProperty(name); - return property == null ? "" : property; - } - - /** - * Sets the name of the form element. - * - * @param name the new name of the form element. - */ - public void setName(String name) { - setProperty(NAME, name); - } - - /** - * Returns the default value of the form element. - * - * @return the default value. - */ - public String getDefaultValue() { - return getPropertyNullCheck(DEFAULT_VALUE); - } - - /** - * Sets the default value of the form element. The default value is used - * to initialize the form element and to test whether or not it has been - * modified. - * - * @param defaultValue the new default value of the form element. - */ - public void setDefaultValue(String defaultValue) { - setProperty(DEFAULT_VALUE, defaultValue); - } - - /** - * Returns the current value of the form element. - * - * @return the current value of the form element. - */ - public String getValue() { - return getPropertyNullCheck(VALUE); - } - - /** - * Sets the value of the form element. - * - * @param value the new value of the form element. - */ - public void setValue(String value) { - setProperty(VALUE, value); - } - - /** - * Returns a collection of form element types. - * - * @return a collection of form element types. - */ - public static Collection<ElementType> getFormElementTypes() { - return Collections.unmodifiableCollection(FORM_ELEMENT_TYPES); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * gadget with the given default value. - * - * @param defaultValue the default value to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByDefaultValue(String defaultValue) { - return Restriction.of(DEFAULT_VALUE, defaultValue); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * gadget with the given value. - * - * @param value the value to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByValue(String value) { - return Restriction.of(VALUE, value); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * gadget with the given name. - * - * @param name the name to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByName(String name) { - return Restriction.of(NAME, name); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/Function.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/Function.java b/wave/src/main/java/com/google/wave/api/Function.java deleted file mode 100644 index 64e67ae..0000000 --- a/wave/src/main/java/com/google/wave/api/Function.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; - -import java.util.Map; - -/** - * A function that computes a result object of type {@code V} from an input of - * type {@code K}. - * - * @param <K> the type of the function input. - * @param <V> the type of the function output. - */ -public interface Function<K, V> { - - /** - * Computes {@code V} from the given {@code K}. - * - * @param source the source object. - * @return an instance of {@code V}, based on {@code source}. - */ - V call(K source); - - /** - * A {@link Function} that computes a {@link BlipContent} from another - * {@link BlipContent}. - * - * Note: The sole purpose of this interface is to eliminate compiler warning - * about generic array of {@link Function} creation, since the {@code insert}, - * {@code insertAfter}, {@code replace}, and {@code updateElements} method - * inside {@link BlipContentRefs} take a varargs of functions. - */ - static interface BlipContentFunction extends Function<BlipContent, BlipContent> { } - - /** - * A {@link Function} that computes a {@link Map} from a {@link BlipContent}. - * - * Note: The sole purpose of this interface is to eliminate compiler warning - * about generic array of {@link Function} creation, since the {@code insert}, - * {@code insertAfter}, {@code replace}, and {@code updateElements} method - * inside {@link BlipContentRefs} take a varargs of functions. - */ - static interface MapFunction extends Function<BlipContent, Map<String, String>> { } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/Gadget.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/Gadget.java b/wave/src/main/java/com/google/wave/api/Gadget.java deleted file mode 100644 index a60f67c..0000000 --- a/wave/src/main/java/com/google/wave/api/Gadget.java +++ /dev/null @@ -1,282 +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; - -/** - * Gadgets are external code that can be executed within a protected - * environment within a Wave. Gadgets are indentified by the url that points to - * their gadget specification. Gadgets can also maintain state that both they - * and Robots can modify. - */ -public class Gadget extends Element { - - public static final String AUTHOR = "author"; - public static final String CATEGORY = "category"; - public static final String IFRAME = "ifr"; - public static final String PREF = "pref"; - public static final String THUMBNAIL = "thumbnail"; - public static final String TITLE = "title"; - public static final String URL = "url"; - - /** - * Constructs an empty gadget. - */ - public Gadget() { - super(ElementType.GADGET); - setUrl(""); - } - - /** - * Constructs a gadget with a given set of properties. - * - * @param properties the properties of the gadget. - */ - public Gadget(Map<String, String> properties) { - super(ElementType.GADGET, properties); - } - - /** - * Constructs a gadget for the specified url. - * - * @param url the url of the gadget specification. - */ - public Gadget(String url) { - super(ElementType.GADGET); - setUrl(url); - } - - /** - * Returns the author of the gadget. - * - * @return the author of the gadget. - */ - public String getAuthor() { - return getProperty(AUTHOR); - } - - /** - * Changes the author of the gadget to the given author. - * - * @param author the new gadget author. - */ - public void setAuthor(String author) { - setProperty(AUTHOR, author); - } - - /** - * Returns the category of the gadget. - * - * @return the category of the gadget. - */ - public String getCategory() { - return getProperty(CATEGORY); - } - - /** - * Changes the cached IFrame source of the gadget. - * - * @param iframe the new cached gadget iframe source. - */ - public void setIframe(String iframe) { - setProperty(IFRAME, iframe); - } - - /** - * Returns the cached iframe source of the gadget. - * - * @return the cached iframe source of the gadget. - */ - public String getIframe() { - return getProperty(IFRAME); - } - - /** - * Changes the category of the gadget to the given category. - * - * @param category the new gadget category. - */ - public void setCategory(String category) { - setProperty(CATEGORY, category); - } - - /** - * Returns the pref of the gadget. - * - * @return the pref of the gadget. - */ - public String getPref() { - return getProperty(PREF); - } - - /** - * Changes the pref of the gadget to the given pref. - * - * @param pref the new gadget pref. - */ - public void setPref(String pref) { - setProperty(PREF, pref); - } - - /** - * Returns the thumbnail of the gadget. - * - * @return the thumbnail of the gadget. - */ - public String getThumbnail() { - return getProperty(THUMBNAIL); - } - - /** - * Changes the thumbnail of the gadget to the given thumbnail. - * - * @param thumbnail the new gadget thumbnail. - */ - public void setThumbnail(String thumbnail) { - setProperty(THUMBNAIL, thumbnail); - } - - /** - * Returns the title of the gadget. - * - * @return the title of the gadget. - */ - public String getTitle() { - return getProperty(TITLE); - } - - /** - * Changes the title of the gadget to the given title. - * - * @param title the new gadget title. - */ - public void setTitle(String title) { - setProperty(TITLE, title); - } - - /** - * Returns the URL for the gadget. - * - * @return the URL for the gadget. - */ - public String getUrl() { - return getProperty(URL); - } - - /** - * Changes the URL for the gadget to the given url. This will cause the new - * gadget to be initialized and loaded. - * - * @param url the new gadget url. - */ - public void setUrl(String url) { - setProperty(URL, url); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * gadget with the given author. - * - * @param author the author to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByAuthor(String author) { - return Restriction.of(AUTHOR, author); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * gadget with the given category. - * - * @param category the category to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByCategory(String category) { - return Restriction.of(CATEGORY, category); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * gadget with the given cached iframe source. - * - * @param iframe the iframe source to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByIframe(String iframe) { - return Restriction.of(IFRAME, iframe); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * gadget with the given pref. - * - * @param pref the pref to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByPref(String pref) { - return Restriction.of(PREF, pref); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * gadget with the given thumbnail. - * - * @param thumbnail the thumbnail to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByThumbnail(String thumbnail) { - return Restriction.of(THUMBNAIL, thumbnail); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * gadget with the given title. - * - * @param title the title to filter. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByTitle(String title) { - return Restriction.of(TITLE, title); - } - - /** - * Creates an instance of {@link Restriction} that can be used to search for - * gadget 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 - * gadget with the given property. - * - * @param key the property key. - * @param value the property value. - * @return an instance of {@link Restriction}. - */ - public static Restriction restrictByProperty(String key, String value) { - return Restriction.of(key, value); - } -}
