http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/impl/GsonFactory.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/impl/GsonFactory.java b/src/com/google/wave/api/impl/GsonFactory.java deleted file mode 100644 index fd9dce1..0000000 --- a/src/com/google/wave/api/impl/GsonFactory.java +++ /dev/null @@ -1,252 +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.impl; - -import com.google.common.collect.Lists; -import com.google.gson.*; -import com.google.gson.reflect.TypeToken; -import com.google.wave.api.Annotation; -import com.google.wave.api.Attachment; -import com.google.wave.api.BlipData; -import com.google.wave.api.Element; -import com.google.wave.api.JsonRpcResponse; -import com.google.wave.api.NonJsonSerializable; -import com.google.wave.api.OperationRequest; -import com.google.wave.api.Range; -import com.google.wave.api.BlipThread; -import com.google.wave.api.SearchResult; - -import org.apache.commons.codec.binary.Base64; -import org.waveprotocol.wave.model.id.WaveletId; - -import java.lang.reflect.Type; -import java.util.*; -import java.util.Map.Entry; -import java.io.UnsupportedEncodingException; - -/** - * A factory to instantiate a {@link Gson} instance, with pre-registered type - * adapters for serializing and deserializing Wave API classes that are used - * as data transfer objects. - */ -public class GsonFactory { - - public static final Type BLIP_MAP_TYPE = new TypeToken<Map<String, BlipData>>(){}.getType(); - public static final Type PARTICIPANT_LIST_TYPE = new TypeToken<List<String>>(){}.getType(); - public static final Type THREAD_MAP_TYPE = new TypeToken<Map<String, BlipThread>>(){}.getType(); - public static final Type STRING_MAP_TYPE = new TypeToken<Map<String, String>>(){}.getType(); - public static final Type WAVELET_ID_LIST_TYPE = new TypeToken<List<WaveletId>>(){}.getType(); - public static final Type RAW_DELTAS_TYPE = new TypeToken<List<byte[]>>(){}.getType(); - public static final Type RAW_ATTACHMENT_MAP_TYPE = new TypeToken<Map<String, RawAttachmentData>>(){} - .getType(); - public static final Type OPERATION_REQUEST_LIST_TYPE = new TypeToken<List<OperationRequest>>(){} - .getType(); - public static final Type JSON_RPC_RESPONSE_LIST_TYPE = new TypeToken<List<JsonRpcResponse>>(){} - .getType(); - - /** Additional type adapters. */ - private final Map<Type, Object> customTypeAdapters = new LinkedHashMap<Type, Object>(); - - /** - * Registers a custom type adapter. - * - * @param type the type that will be handled by the given adapter. - * @param typeAdapter the adapter that performs the serialization and - * deserialization. - */ - public void registerTypeAdapter(Type type, Object typeAdapter) { - customTypeAdapters.put(type, typeAdapter); - } - - /** - * Creates a {@link Gson} instance, with additional type adapters for these - * types: - * <ul> - * <li>{@link EventMessageBundle}</li> - * <li>{@link OperationRequest}</li> - * <li>{@link Element}</li> - * </ul> - * - * @return an instance of {@link Gson} with pre-registered type adapters. - */ - public Gson create() { - return create(""); - } - - /** - * Creates a {@link Gson} instance, with additional type adapters for these - * types: - * <ul> - * <li>{@link EventMessageBundle}</li> - * <li>{@link OperationRequest}</li> - * <li>{@link Element}</li> - * <li>{@link JsonRpcResponse}</li> - * </ul> - * - * @param opNamespace prefix that should be prepended to the operation during - * serialization. - * @return an instance of {@link Gson} with pre-registered type adapters. - */ - public Gson create(String opNamespace) { - ElementGsonAdaptor elementGsonAdaptor = new ElementGsonAdaptor(); - GsonBuilder builder = new GsonBuilder() - .setExclusionStrategies(new NonSerializableExclusionStrategy()) - .registerTypeAdapter(EventMessageBundle.class, new EventMessageBundleGsonAdaptor()) - .registerTypeAdapter(OperationRequest.class, new OperationRequestGsonAdaptor(opNamespace)) - .registerTypeAdapter(Element.class, elementGsonAdaptor) - .registerTypeAdapter(Attachment.class, elementGsonAdaptor) - .registerTypeAdapter(JsonRpcResponse.class, new JsonRpcResponseGsonAdaptor()) - .registerTypeAdapter(Annotation.class, new AnnotationInstanceCreator()) - .registerTypeAdapter(Range.class, new RangeInstanceCreator()) - .registerTypeAdapter(BlipThread.class, new ThreadInstanceCreator()) - .registerTypeAdapter(SearchResult.class, new SearchResultInstanceCreator()) - .registerTypeAdapter(SearchResult.Digest.class, new SearchResultDigestInstanceCreator()) - .registerTypeAdapter(WaveletId.class, new WaveletIdInstanceCreator()) - .registerTypeAdapter(RawAttachmentData.class, new AttachmentDataInstanceCreator()) - .registerTypeAdapter(byte[].class, new ByteArrayGsonAdaptor()); - - // Register custom type adapters. - for (Entry<Type, Object> entry : customTypeAdapters.entrySet()) { - builder.registerTypeAdapter(entry.getKey(), entry.getValue()); - } - - return builder.serializeNulls().create(); - } - - /** - * A strategy definition that excludes all fields that are annotated with - * {@link NonJsonSerializable}. - */ - private static class NonSerializableExclusionStrategy implements ExclusionStrategy { - - @Override - public boolean shouldSkipClass(Class<?> clazz) { - return false; - } - - @Override - public boolean shouldSkipField(FieldAttributes f) { - return f.getAnnotation(NonJsonSerializable.class) != null; - } - } - - /** - * An instance creator that creates an empty {@link Annotation}. - */ - private static class AnnotationInstanceCreator implements InstanceCreator<Annotation> { - @Override - public Annotation createInstance(Type type) { - return new Annotation("", "", -1, -1); - } - } - - /** - * An instance creator that creates an empty {@link Annotation}. - */ - private static class RangeInstanceCreator implements InstanceCreator<Range> { - @Override - public Range createInstance(Type type) { - return new Range(-1, -1); - } - } - - /** - * An instance creator that creates an empty {@link BlipThread}. - */ - private static class ThreadInstanceCreator implements InstanceCreator<BlipThread> { - @Override - public BlipThread createInstance(Type type) { - return new BlipThread(null, -1, null, null); - } - } - - /** - * An instance creator that creates an empty {@link SearchResult}. - */ - private static class SearchResultInstanceCreator implements InstanceCreator<SearchResult> { - @Override - public SearchResult createInstance(Type type) { - return new SearchResult(""); - } - } - - /** - * An instance creator that creates an empty {@link SearchResult.Digest}. - */ - private static class SearchResultDigestInstanceCreator implements - InstanceCreator<SearchResult.Digest> { - @Override - public SearchResult.Digest createInstance(Type type) { - List<String> participants = Lists.newLinkedList(); - return new SearchResult.Digest("", "", "", participants, -1, -1, -1, -1); - } - } - - /** - * An instance creator that creates an empty {@link WaveletId}. - */ - private static class WaveletIdInstanceCreator implements - InstanceCreator<WaveletId> { - @Override - public WaveletId createInstance(Type type) { - return WaveletId.of("dummy", "dummy"); - } - } - - /** - * An instance creator that creates an empty {@link AttachmentData}. - */ - private static class AttachmentDataInstanceCreator implements InstanceCreator<RawAttachmentData> { - @Override - public RawAttachmentData createInstance(Type type) { - return new RawAttachmentData("", "", new byte[0]); - } - } - - /** - * An instance creator serializer and deserializer that creates - * serializes and deserializes an empty {@link ByteString}. - */ - private static class ByteArrayGsonAdaptor implements InstanceCreator<byte[]>, - JsonSerializer<byte[]>, JsonDeserializer<byte[]> { - @Override - public byte[] createInstance(Type type) { - return new byte[0]; - } - - @Override - public JsonElement serialize(byte[] bytes, Type type, JsonSerializationContext jsc) { - try { - return new JsonPrimitive(new String(Base64.encodeBase64(bytes), "UTF-8")); - } catch (UnsupportedEncodingException ex) { - throw new RuntimeException(ex); - } - } - - @Override - public byte[] deserialize(JsonElement je, Type type, JsonDeserializationContext jdc) throws JsonParseException { - try { - return Base64.decodeBase64(je.getAsString().getBytes("UTF-8")); - } catch (UnsupportedEncodingException ex) { - throw new RuntimeException(ex); - } - } - } -}
http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/impl/JsonRpcResponseGsonAdaptor.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/impl/JsonRpcResponseGsonAdaptor.java b/src/com/google/wave/api/impl/JsonRpcResponseGsonAdaptor.java deleted file mode 100644 index f6a02b3..0000000 --- a/src/com/google/wave/api/impl/JsonRpcResponseGsonAdaptor.java +++ /dev/null @@ -1,109 +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.impl; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import com.google.wave.api.JsonRpcResponse; -import com.google.wave.api.JsonRpcConstant.ParamsProperty; -import com.google.wave.api.JsonRpcConstant.ResponseProperty; - -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -/** - * Custom serializer and deserializer that serializes and deserializes a - * {@link JsonRpcResponse}. - * - * @author [email protected] (Marcel Prasetya) - */ -public class JsonRpcResponseGsonAdaptor implements JsonDeserializer<JsonRpcResponse>, - JsonSerializer<JsonRpcResponse>{ - - @Override - public JsonRpcResponse deserialize(JsonElement json, Type type, - JsonDeserializationContext context) throws JsonParseException { - JsonObject jsonObject = json.getAsJsonObject(); - - String id = jsonObject.get(ResponseProperty.ID.key()).getAsString(); - if (jsonObject.has(ResponseProperty.ERROR.key())) { - JsonElement errorObject = jsonObject.get(ResponseProperty.ERROR.key()); - String errorMessage = errorObject.getAsJsonObject().get("message").getAsString(); - return JsonRpcResponse.error(id, errorMessage); - } - - // Deserialize the data. - Map<ParamsProperty, Object> properties = new HashMap<ParamsProperty, Object>(); - JsonElement data = jsonObject.get(ResponseProperty.DATA.key()); - if (data != null && data.isJsonObject()) { - for (Entry<String, JsonElement> parameter : data.getAsJsonObject().entrySet()) { - ParamsProperty parameterType = ParamsProperty.fromKey(parameter.getKey()); - if (parameterType == null) { - // Skip this unknown parameter. - continue; - } - Object object = null; - if (parameterType == ParamsProperty.BLIPS) { - object = context.deserialize(parameter.getValue(), GsonFactory.BLIP_MAP_TYPE); - } else if (parameterType == ParamsProperty.PARTICIPANTS_ADDED || - parameterType == ParamsProperty.PARTICIPANTS_REMOVED) { - object = context.deserialize(parameter.getValue(), GsonFactory.PARTICIPANT_LIST_TYPE); - } else if (parameterType == ParamsProperty.THREADS) { - object = context.deserialize(parameter.getValue(), GsonFactory.THREAD_MAP_TYPE); - } else if (parameterType == ParamsProperty.WAVELET_IDS) { - object = context.deserialize(parameter.getValue(), GsonFactory.WAVELET_ID_LIST_TYPE); - } else if (parameterType == ParamsProperty.RAW_DELTAS) { - object = context.deserialize(parameter.getValue(), GsonFactory.RAW_DELTAS_TYPE); - } else { - object = context.deserialize(parameter.getValue(), parameterType.clazz()); - } - properties.put(parameterType, object); - } - } - - return JsonRpcResponse.result(id, properties); - } - - @Override - public JsonElement serialize(JsonRpcResponse src, Type type, JsonSerializationContext context) { - JsonObject result = new JsonObject(); - result.addProperty(ResponseProperty.ID.key(), src.getId()); - if (src.isError()) { - JsonObject error = new JsonObject(); - error.addProperty(ParamsProperty.MESSAGE.key(), src.getErrorMessage()); - result.add(ResponseProperty.ERROR.key(), error); - } else { - JsonObject data = new JsonObject(); - for (Entry<ParamsProperty, Object> properties : src.getData().entrySet()) { - data.add(properties.getKey().key(), context.serialize(properties.getValue())); - } - result.add(ResponseProperty.DATA.key(), data); - } - return result; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/impl/OperationRequestGsonAdaptor.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/impl/OperationRequestGsonAdaptor.java b/src/com/google/wave/api/impl/OperationRequestGsonAdaptor.java deleted file mode 100644 index 11e225f..0000000 --- a/src/com/google/wave/api/impl/OperationRequestGsonAdaptor.java +++ /dev/null @@ -1,137 +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.impl; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import com.google.wave.api.OperationRequest; -import com.google.wave.api.JsonRpcConstant.ParamsProperty; -import com.google.wave.api.JsonRpcConstant.RequestProperty; -import com.google.wave.api.OperationRequest.Parameter; - -import java.lang.reflect.Type; -import java.util.Map.Entry; - -/** - * Custom serializer and deserializer that serializes and deserializes an - * {@link OperationRequest}. - * - * @author [email protected] (Marcel Prasetya) - */ -public class OperationRequestGsonAdaptor implements JsonSerializer<OperationRequest>, - JsonDeserializer<OperationRequest> { - - /** - * A namespace that should be prepended to the operation method during - * serialization. - */ - private final String operationNamespace; - - /** - * Constructor. - */ - public OperationRequestGsonAdaptor() { - this(""); - } - - /** - * Constructor. - * - * @param operationNamespace namespace that should be prepended to the - * operation method during serialization. - */ - public OperationRequestGsonAdaptor(String operationNamespace) { - if (operationNamespace != null && !operationNamespace.isEmpty() && - !operationNamespace.endsWith(".")) { - operationNamespace += "."; - } - this.operationNamespace = operationNamespace; - } - - @Override - public JsonElement serialize(OperationRequest req, Type type, JsonSerializationContext ctx) { - JsonObject object = new JsonObject(); - object.addProperty(RequestProperty.METHOD.key(), operationNamespace + req.getMethod()); - object.addProperty(RequestProperty.ID.key(), req.getId()); - - JsonObject parameters = new JsonObject(); - for (Entry<ParamsProperty, Object> entry : req.getParams().entrySet()) { - if (entry.getValue() != null) { - parameters.add(entry.getKey().key(), ctx.serialize(entry.getValue())); - } - } - object.add(RequestProperty.PARAMS.key(), parameters); - return object; - } - - @Override - public OperationRequest deserialize(JsonElement json, Type type, JsonDeserializationContext ctx) - throws JsonParseException { - JsonObject jsonObject = json.getAsJsonObject(); - JsonObject parameters = jsonObject.getAsJsonObject(RequestProperty.PARAMS.key()); - - OperationRequest request = new OperationRequest( - jsonObject.get(RequestProperty.METHOD.key()).getAsString(), - jsonObject.get(RequestProperty.ID.key()).getAsString(), - getPropertyAsStringThenRemove(parameters, ParamsProperty.WAVE_ID), - getPropertyAsStringThenRemove(parameters, ParamsProperty.WAVELET_ID), - getPropertyAsStringThenRemove(parameters, ParamsProperty.BLIP_ID)); - - for (Entry<String, JsonElement> parameter : parameters.entrySet()) { - ParamsProperty parameterType = ParamsProperty.fromKey(parameter.getKey()); - if (parameterType != null) { - Object object; - if (parameterType == ParamsProperty.RAW_DELTAS) { - object = ctx.deserialize(parameter.getValue(), GsonFactory.RAW_DELTAS_TYPE); - } else { - object = ctx.deserialize(parameter.getValue(), parameterType.clazz()); - } - request.addParameter(Parameter.of(parameterType, object)); - } - } - - return request; - } - - /** - * Returns a property of {@code JsonObject} as a {@link String}, then remove - * that property. - * - * @param jsonObject the {@code JsonObject} to get the property from. - * @param key the key of the property. - * @return the property as {@link String}, or {@code null} if not found. - */ - private static String getPropertyAsStringThenRemove(JsonObject jsonObject, ParamsProperty key) { - JsonElement property = jsonObject.get(key.key()); - if (property != null) { - jsonObject.remove(key.key()); - if (property.isJsonNull()) { - return null; - } - return property.getAsString(); - } - return null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/impl/RawAttachmentData.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/impl/RawAttachmentData.java b/src/com/google/wave/api/impl/RawAttachmentData.java deleted file mode 100644 index b291086..0000000 --- a/src/com/google/wave/api/impl/RawAttachmentData.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.impl; - -/** - * Attachment data. - * - * @author [email protected] (Andrew Kaplanov) - */ -public class RawAttachmentData { - private final String fileName; - private final String creator; - private final byte[] data; - - /** - * Exported raw attachment data. - * - * @param fileName attachment file name. - * @param creator attachment creator. - * @param data attachment data. - */ - public RawAttachmentData(String fileName, String creator, byte[] data) { - this.fileName = fileName; - this.creator = creator; - this.data = data; - } - - public String getFileName() { - return fileName; - } - - public String getCreator() { - return creator; - } - - public byte[] getData() { - return data; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/impl/RawDeltas.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/impl/RawDeltas.java b/src/com/google/wave/api/impl/RawDeltas.java deleted file mode 100644 index ace58c4..0000000 --- a/src/com/google/wave/api/impl/RawDeltas.java +++ /dev/null @@ -1,43 +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.impl; - -import java.util.List; - -/** - * Exported raw wavelet data. - * - * @author [email protected] (Andrew Kaplanov) - */ -public class RawDeltas { - - private final List<byte[]> rawDeltas; - - /** - * @param rawDeltas serialized ProtocolWaveletDelta. - */ - public RawDeltas(List<byte[]> rawDeltas) { - this.rawDeltas = rawDeltas; - } - - public List<byte[]> getDeltas() { - return rawDeltas; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/impl/RawDeltasListener.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/impl/RawDeltasListener.java b/src/com/google/wave/api/impl/RawDeltasListener.java deleted file mode 100644 index 662e165..0000000 --- a/src/com/google/wave/api/impl/RawDeltasListener.java +++ /dev/null @@ -1,38 +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.impl; - -import java.util.List; - -/** - * Listener to receive exported deltas. - * - * @author [email protected] (Andrew Kaplanov) - */ -public interface RawDeltasListener { - - /** - * @param rawDeltas serialized ProtocolWaveletDelta. - * @param rawTargetVersion serialized ProtocolHashedVersion. - */ - public void onSuccess(List<byte[]> rawDeltas, byte[] rawTargetVersion); - - public void onFailire(String message); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/impl/Tuple.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/impl/Tuple.java b/src/com/google/wave/api/impl/Tuple.java deleted file mode 100644 index af1040f..0000000 --- a/src/com/google/wave/api/impl/Tuple.java +++ /dev/null @@ -1,102 +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.impl; - -import java.util.Arrays; - -/** - * An immutable tuple of values that can be accessed using {@link #get} method. - * - * @author [email protected] (Marcel Prasetya) - * @param <A> Type of the tuple element. - */ -public class Tuple<A> { - - /** - * The elements of the tuple. - */ - private final A[] elements; - - /** - * Factory method to create a tuple. - * - * @param <A> Type of the tuple element. - * @param elements The elements of the tuple - * @return A new tuple that contains {@code elements} - */ - @SuppressWarnings("unchecked") - public static <A> Tuple<A> of(A ... elements) { - return new Tuple<A>(elements); - } - - /** - * Constructor. - * - * @param elements The elements of the tuple. - */ - @SuppressWarnings("unchecked") - public Tuple(A ... elements) { - this.elements = elements; - } - - /** - * Returns the {@code index}th element of the tuple. - * - * @param index The index of the element. - * @return The {@code index}th element of the tuple. - */ - public A get(int index) { - return elements[index]; - } - - /** - * Returns the number of elements in the tuple. - * - * @return the number of elements in the tuple. - */ - public int size() { - return elements.length; - } - - @SuppressWarnings("unchecked") - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - - if (o == null || o.getClass() != this.getClass()) { - return false; - } - - Tuple<A> o2 = (Tuple<A>) o; - return Arrays.equals(elements, o2.elements); - } - - @Override - public int hashCode() { - return Arrays.hashCode(elements); - } - - @Override - public String toString() { - return Arrays.toString(elements); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/impl/WaveletData.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/impl/WaveletData.java b/src/com/google/wave/api/impl/WaveletData.java deleted file mode 100644 index 778d316..0000000 --- a/src/com/google/wave/api/impl/WaveletData.java +++ /dev/null @@ -1,210 +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.impl; - -import com.google.wave.api.BlipThread; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * The data representation of Wavelet metadata used to serialize and send to - * the Robot. - * - * @author [email protected] (Seth Covitz) - */ -public class WaveletData { - - private long creationTime = -1L; - private long lastModifiedTime = -1L; - private long version = -1L; - private List<String> participants = new ArrayList<String>(); - private Map<String, String> participantRoles = new HashMap<String, String>(); - private Map<String, String> dataDocuments = new HashMap<String, String>(); - private List<String> tags = new ArrayList<String>(); - private String creator; - private String rootBlipId; - private String title; - private String waveId; - private String waveletId; - private BlipThread rootThread; - - public WaveletData() { - // TODO(mprasetya): Please remove this ctor. It is currently being used for - // deserialization. - } - - public WaveletData(String waveId, String waveletId, String rootBlipId, - BlipThread rootThread) { - this.waveId = waveId; - this.waveletId = waveletId; - this.rootBlipId = rootBlipId; - this.rootThread = rootThread; - } - - public WaveletData(WaveletData wavelet) { - this.creationTime = wavelet.getCreationTime(); - this.creator = wavelet.getCreator(); - this.lastModifiedTime = wavelet.getLastModifiedTime(); - this.participants = wavelet.getParticipants(); - this.participantRoles = new HashMap<String, String>(wavelet.getParticipantRoles()); - this.rootBlipId = wavelet.getRootBlipId(); - this.title = wavelet.getTitle(); - this.version = wavelet.getVersion(); - this.waveId = wavelet.getWaveId(); - this.waveletId = wavelet.getWaveletId(); - this.dataDocuments = new HashMap<String, String>(wavelet.getDataDocuments()); - this.tags = new ArrayList<String>(wavelet.getTags()); - } - - /** - * @returns a map of participantId to role for participants that don't have - * the default role. - */ - public Map<String, String> getParticipantRoles() { - return participantRoles; - } - - public long getCreationTime() { - return creationTime; - } - - public String getCreator() { - return creator; - } - - public long getLastModifiedTime() { - return lastModifiedTime; - } - - public List<String> getParticipants() { - return participants; - } - - public String getRootBlipId() { - return rootBlipId; - } - - public String getTitle() { - return title; - } - - public long getVersion() { - return version; - } - - public String getWaveId() { - return waveId; - } - - public String getWaveletId() { - return waveletId; - } - - public void setCreationTime(long creationTime) { - this.creationTime = creationTime; - } - - public void setCreator(String creator) { - this.creator = creator; - } - - public void setLastModifiedTime(long lastModifiedTime) { - this.lastModifiedTime = lastModifiedTime; - } - - public void setParticipants(List<String> participants) { - this.participants = participants; - } - - public void setRootBlipId(String rootBlipId) { - this.rootBlipId = rootBlipId; - } - - public void setTitle(String title) { - this.title = title; - } - - public void setVersion(long version) { - this.version = version; - } - - public void setWaveId(String waveId) { - this.waveId = waveId; - } - - public void setWaveletId(String waveletId) { - this.waveletId = waveletId; - } - - public Map<String, String> getDataDocuments() { - return dataDocuments; - } - - public void setDataDocuments(Map<String, String> dataDocuments) { - this.dataDocuments = new HashMap<String, String>(dataDocuments); - } - - public void setDataDocument(String name, String data) { - dataDocuments.put(name, data); - } - - public String getDataDocument(String name) { - if (dataDocuments == null) { - return null; - } else { - return dataDocuments.get(name); - } - } - - public List<String> getTags() { - return tags; - } - - public void setTags(List<String> tags) { - this.tags = new ArrayList<String>(tags); - } - - public void addTag(String tag) { - tags.add(tag); - } - - public void removeTag(String tag) { - tags.remove(tag); - } - - public void addParticipant(String participant) { - participants.add(participant); - } - - public void setParticipantRole(String participant, String role) { - participantRoles.put(participant, role); - } - - public BlipThread getRootThread() { - return rootThread; - } - - public void setRootThread(BlipThread rootThread) { - this.rootThread = rootThread; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/oauth/LoginFormHandler.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/oauth/LoginFormHandler.java b/src/com/google/wave/api/oauth/LoginFormHandler.java deleted file mode 100644 index d1c9ae8..0000000 --- a/src/com/google/wave/api/oauth/LoginFormHandler.java +++ /dev/null @@ -1,40 +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.oauth; - -import com.google.wave.api.Wavelet; - -/** - * Interface that handles the rendering in the wave of a login form in the wave - * to direct the user to authorize access to the service provider's resources. - * - * @author [email protected] (Elizabeth Ford) - */ -public interface LoginFormHandler { - - /** - * Renders a link to the service provider's login page and a confirmation - * button to press when login is complete. - * - * @param userRecordKey The user id. - * @param wavelet The wavelet to which the robot is added. - */ - void renderLogin(String userRecordKey, Wavelet wavelet); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/oauth/OAuthService.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/oauth/OAuthService.java b/src/com/google/wave/api/oauth/OAuthService.java deleted file mode 100644 index faf3813..0000000 --- a/src/com/google/wave/api/oauth/OAuthService.java +++ /dev/null @@ -1,80 +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.oauth; - -import com.google.wave.api.Wavelet; -import com.google.wave.api.oauth.impl.OAuthServiceException; - -import java.util.Map; - -/** - * Generic OAuthService to handle OAuth tokens and to form OAuth urls. - * - * @author [email protected] (Elizabeth Ford) - * @author [email protected] (Kimberly White) - */ -public interface OAuthService { - - /** - * Verifies that the user profile contains a request token (i.e. user has - * logged in). If user profile does not exist or does not contain a request - * token, fetches a request token and renders the login form so the request - * token can be signed. - * - * If the user profile contains a request token and "confirmed" is true, - * exchanges the signed request token with the service provider for an access - * token. - * - * @param wavelet The wavelet on which the robot resides. - * @param loginForm the form that handles user authorization in wave. - * @return boolean True if user is authorized, false if rendering a login form - * to authorize the user is required. - */ - boolean checkAuthorization(Wavelet wavelet, LoginFormHandler loginForm); - - /** - * Checks if the user is authorized. - * - * @return True if the user has an access token. - */ - boolean hasAuthorization(); - - /** - * Performs HTTP POST to the Service provider. - * - * @param url Service provider url to post data. - * @param parameters Service provider parameters. - * @return String of the response message. - * @throws com.google.wave.api.oauth.impl.OAuthServiceException; - */ - String post(String url, Map<String, String> parameters) - throws OAuthServiceException; - - /** - * Performs HTTP GET from the Service provider. - * - * @param url Service provider url to fetch resources. - * @param parameters Service provider parameters. - * @return String of the response message. - * @throws com.google.wave.api.oauth.impl.OAuthServiceException; - */ - String get(String url, Map<String, String> parameters) - throws OAuthServiceException; -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/oauth/impl/OAuthServiceException.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/oauth/impl/OAuthServiceException.java b/src/com/google/wave/api/oauth/impl/OAuthServiceException.java deleted file mode 100644 index 704155f..0000000 --- a/src/com/google/wave/api/oauth/impl/OAuthServiceException.java +++ /dev/null @@ -1,62 +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.oauth.impl; - -/** - * A checked exception thrown by the Java robot oauth library. - * - * @author [email protected] (Kimberly White) - */ -public class OAuthServiceException extends Exception { - - /* - * Class constructor. - */ - public OAuthServiceException() { - } - - /* - * Overloaded constructor. - * - * @param message The exception message. - */ - public OAuthServiceException(String message) { - super(message); - } - - /* - * Overloaded constructor. - * - * @param cause The exception cause. - */ - public OAuthServiceException(Throwable cause) { - super(cause); - } - - /* - * Overloaded constructor. - * - * @param message The exception message. - * @param cause The exception cause. - */ - public OAuthServiceException(String message, Throwable cause) { - super(message, cause); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/oauth/impl/OAuthServiceImpl.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/oauth/impl/OAuthServiceImpl.java b/src/com/google/wave/api/oauth/impl/OAuthServiceImpl.java deleted file mode 100644 index 8375733..0000000 --- a/src/com/google/wave/api/oauth/impl/OAuthServiceImpl.java +++ /dev/null @@ -1,318 +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.oauth.impl; - -import com.google.wave.api.Wavelet; -import com.google.wave.api.oauth.LoginFormHandler; -import com.google.wave.api.oauth.OAuthService; - -import net.oauth.OAuth; -import net.oauth.OAuthAccessor; -import net.oauth.OAuthConsumer; -import net.oauth.OAuthException; -import net.oauth.OAuthMessage; -import net.oauth.OAuthServiceProvider; -import net.oauth.client.OAuthClient; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; -import java.util.logging.Logger; - -import javax.jdo.JDOObjectNotFoundException; -import javax.jdo.PersistenceManager; -import javax.jdo.PersistenceManagerFactory; - -/** - * Implements the OAuthService interface. {@link OAuthService} - * - * @author [email protected] (Kimberly White) - * @author [email protected] (Elizabeth Ford) - */ -public class OAuthServiceImpl implements OAuthService { - - /** Writes application logs. */ - private static final Logger LOG = Logger.getLogger(OAuthServiceImpl.class.getName()); - - /** Key for OAuth request token query parameter. */ - private static final String TOKEN_KEY = "oauth_token"; - - /** Key for OAuth callback url query parameter. */ - private static final String CALLBACK_KEY = "oauth_callback"; - - /** Key to force user to enter credentials. */ - private static final String FORCE_LOGIN_KEY = "force_login"; - - /** Key for HTTP GET method. */ - private static final String GET = "GET"; - - /** Key for HTTP POST method. */ - private static final String POST = "POST"; - - /** Key for Datastore object. Consists of wave creator id and wave id. */ - private final String userRecordKey; - - /** OpenAuth client used to negotiate request/access tokens. */ - private final OAuthClient oauthClient; - - /** OpenAuth accessor that stores request/access/secret tokens. */ - private final OAuthAccessor accessor; - - /** Persistence Manager Factory to retrieve and store Datastore objects. */ - private final PersistenceManagerFactory pmf; - - /** - * Factory method. Initializes OAuthServiceProvider with necessary tokens and - * urls. - * - * @param userRecordKey key consisting of user id and wave id. - * @param consumerKey service provider OAuth consumer key. - * @param consumerSecret service provider OAuth consumer secret. - * @param requestTokenUrl url to get service provider request token. - * @param authorizeUrl url to service provider authorize page. - * @param callbackUrl url to callback page. - * @param accessTokenUrl url to get service provider access token. - * @return OAuthService instance. - */ - public static OAuthService newInstance(String userRecordKey, String consumerKey, - String consumerSecret, String requestTokenUrl, String authorizeUrl, String callbackUrl, - String accessTokenUrl) { - OAuthServiceProvider provider = - new OAuthServiceProvider(requestTokenUrl, authorizeUrl, accessTokenUrl); - OAuthConsumer consumer = new OAuthConsumer(callbackUrl, consumerKey, consumerSecret, provider); - OAuthAccessor accessor = new OAuthAccessor(consumer); - OAuthClient client = new OAuthClient(new OpenSocialHttpClient()); - PersistenceManagerFactory pmf = SingletonPersistenceManagerFactory.get(); - return new OAuthServiceImpl(accessor, client, pmf, userRecordKey); - } - - /** - * Initializes necessary OAuthClient and accessor objects for OAuth handling. - * - * @param accessor Used to store tokesn for OAuth authorization. - * @param client Handles OAuth authorization. - * @param pmf Manages datastore fetching and storing. - * @param recordKey User id for datastore object. - */ - OAuthServiceImpl(OAuthAccessor accessor, OAuthClient client, - PersistenceManagerFactory pmf, String recordKey) { - this.userRecordKey = recordKey; - this.pmf = pmf; - this.accessor = accessor; - this.oauthClient = client; - } - - @Override - public boolean checkAuthorization(Wavelet wavelet, LoginFormHandler loginForm) { - - OAuthUser user = retrieveUserProfile(); - - // Return true if the user already has an access token. - if (user != null && user.getAccessToken() != null) { - return true; - } - - // If the user doesn't have an access token but already has a request token, - // exchange the tokens. - if (user != null && user.getRequestToken() != null) { - String accessToken = exchangeTokens(user); - if (accessToken != null) { - // Yay, we're authorized. - return true; - } - } - - // Need to login. - String requestToken = getAndStoreRequestToken(); - LOG.info("Request token: " + requestToken); - buildAuthUrl(); - loginForm.renderLogin(userRecordKey, wavelet); - return false; - } - - @Override - public boolean hasAuthorization() { - OAuthUser user = retrieveUserProfile(); - return (user != null && user.getAccessToken() != null); - } - - /** - * Applies for a request token from the service provider. - * - * @return the request token. - */ - private String getAndStoreRequestToken() { - // Get the request token. - try { - oauthClient.getRequestToken(accessor); - } catch (IOException e) { - LOG.severe("Could not reach service provider to get request token: " + e); - } catch (OAuthException e) { - LOG.severe("Unable to fetch request token. Authentication error: " + e); - } catch (URISyntaxException e) { - LOG.severe("Unable to fetch request token. Invalid url: " + e); - } - - // Store request token in Datastore via a tokenData object. - String requestToken = accessor.requestToken; - storeUserProfile(new OAuthUser(userRecordKey, requestToken)); - - return accessor.requestToken; - } - - /** - * Builds the url to authenticate the request token with necessary query - * parameters and stores in Datastore. - */ - private void buildAuthUrl() { - OAuthUser userProfile = retrieveUserProfile(); - OpenSocialUrl url = new OpenSocialUrl(accessor.consumer.serviceProvider.userAuthorizationURL); - url.addQueryStringParameter(TOKEN_KEY, userProfile.getRequestToken()); - url.addQueryStringParameter(CALLBACK_KEY, accessor.consumer.callbackURL); - url.addQueryStringParameter(FORCE_LOGIN_KEY, "true"); - userProfile.setAuthUrl(url.toString()); - storeUserProfile(userProfile); - } - - /** - * Exchanges a signed request token for an access token from the service - * provider and stores it in the user profile if access token is successfully - * acquired. - * - * @return String of the access token, might return null if failed. - */ - private String exchangeTokens(OAuthUser userProfile) { - // Re-initialize an accessor with the request token and secret token. - // Request token needs to be in access token field for exchange to work. - accessor.accessToken = userProfile.getRequestToken(); - accessor.tokenSecret = accessor.consumer.consumerSecret; - - // Perform the exchange. - String accessToken = null; - String tokenSecret = null; - try { - OAuthMessage message = - oauthClient.invoke(accessor, GET, accessor.consumer.serviceProvider.accessTokenURL, null); - accessToken = message.getToken(); - tokenSecret = message.getParameter(OAuth.OAUTH_TOKEN_SECRET); - } catch (IOException e) { - LOG.warning("Failed to retrieve access token: " + e.getMessage()); - } catch (OAuthException e) { - LOG.warning("Failed to retrieve access token: " + e.getMessage()); - } catch (URISyntaxException e) { - throw new RuntimeException(e); - } - - if (accessToken != null) { - // Store the access token in the user profile object and put profile back - // in the datastore. - userProfile.setAccessToken(accessToken); - userProfile.setTokenSecret(tokenSecret); - storeUserProfile(userProfile); - } - return accessToken; - } - - @Override - public String post(String url, Map<String, String> parameters) throws OAuthServiceException { - return requestResources(url, POST, parameters); - } - - @Override - public String get(String url, Map<String, String> parameters) throws OAuthServiceException { - return requestResources(url, GET, parameters); - } - - /** - * Get secure resources from the service provider. - * - * @param url service provider resource url. - * @param method Http method. - * @param parameters service provider parameters. - * @return String of the service provider response message. - * @throws OAuthServiceException the HTTP response code was not OK - */ - private String requestResources(String url, String method, Map<String, String> parameters) - throws OAuthServiceException { - - // Convert parameters to OAuth parameters. - Collection<OAuth.Parameter> queryParameters = new ArrayList<OAuth.Parameter>(); - for (Map.Entry<String, String> parameter : parameters.entrySet()) { - queryParameters.add(new OAuth.Parameter(parameter.getKey(), parameter.getValue())); - } - - // Set the accessor's access token with the access token in Datastore. - OAuthUser userProfile = retrieveUserProfile(); - accessor.accessToken = userProfile.getAccessToken(); - accessor.tokenSecret = userProfile.getTokenSecret(); - - // Send request and receive response from service provider. - String messageString = ""; - OAuthMessage message; - try { - message = oauthClient.invoke(accessor, method, url, queryParameters); - messageString = message.readBodyAsString(); - } catch (IOException e) { - LOG.severe("Response message has no body: " + e); - throw new OAuthServiceException(e); - } catch (URISyntaxException e) { - LOG.severe("Unable to fetch resources. Invalid url: " + e); - throw new OAuthServiceException(e); - } catch (OAuthException e){ - throw new OAuthServiceException(e); - } - return messageString; - } - - /** - * Stores user-specific oauth token information in Datastore. - * - * @param user profile consisting of user's request token, access token, and - * consumer secret. - */ - private void storeUserProfile(OAuthUser user) { - PersistenceManager pm = pmf.getPersistenceManager(); - try { - pm.makePersistent(user); - } finally { - pm.close(); - } - } - - /** - * Retrieves user's oauth information from Datastore. - * - * @return the user profile (or null if not found). - */ - private OAuthUser retrieveUserProfile() { - PersistenceManager pm = pmf.getPersistenceManager(); - OAuthUser userProfile = null; - try { - userProfile = pm.getObjectById(OAuthUser.class, userRecordKey); - } catch (JDOObjectNotFoundException e) { - LOG.info("Datastore object not yet initialized with key: " + userRecordKey); - } finally { - pm.close(); - } - return userProfile; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/oauth/impl/OAuthUser.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/oauth/impl/OAuthUser.java b/src/com/google/wave/api/oauth/impl/OAuthUser.java deleted file mode 100644 index 39f0fff..0000000 --- a/src/com/google/wave/api/oauth/impl/OAuthUser.java +++ /dev/null @@ -1,141 +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.oauth.impl; - -import javax.jdo.annotations.IdentityType; -import javax.jdo.annotations.PersistenceCapable; -import javax.jdo.annotations.Persistent; -import javax.jdo.annotations.PrimaryKey; - -/** - * Objects of this class are stored in Datastore to persist an association - * between user's wave id + wave id, the user's access token, - * and the service consumer secret. - * Holds the request token for later retrieval to exchange it for the access token. - * 'Detachable' attribute allows object to be altered even after - * its Persistence Manager is closed. - * - * @author [email protected] (Kimberly White) - */ -@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true") -public class OAuthUser { - - /** - * Datastore key. Consists of the user's wave id and the wave id the robot - * resides on. - */ - @SuppressWarnings("unused") - @PrimaryKey - @Persistent - private String nameKey; - - /** OAuth access token. */ - @Persistent - private String accessToken = null; - - /** OAuth request token. */ - @Persistent - private String requestToken; - - /** - * OAuth authorize url. - * By default passed to gadget to open pop-up window. - */ - @Persistent - private String authUrl = null; - - /** The token secret used to sign requests. */ - @Persistent - private String tokenSecret = null; - - /** - * Creates a new profile with the user id and OAuth request token. - * - * @param userId wave creator's id and wave id. - * @param requestToken the OAuth request token. - */ - public OAuthUser(String userId, String requestToken) { - this.nameKey = userId; - this.requestToken = requestToken; - } - - /** - * Adds the user's access token to the OAuth profile. - * - * @param accessToken the OAuth access token. - */ - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } - - /** - * Returns the access token. - * - * @return the access token. - */ - public String getAccessToken() { - return accessToken; - } - - /** - * Returns the request token. - * - * @return the request token. - */ - public String getRequestToken() { - return requestToken; - } - - /** - * Sets the authorize url. - * - * @param authUrl the url to the service provider authorize page. - */ - public void setAuthUrl(String authUrl) { - this.authUrl = authUrl; - } - - /** - * Returns the authorize url. - * - * @return the url to the service provider authorize page. - */ - public String getAuthUrl() { - return authUrl; - } - - /** - * Sets the oauth_token_secret parameter. - * - * @param tokenSecret Token used to sign requests for protected resources. - */ - public void setTokenSecret(String tokenSecret) { - this.tokenSecret = tokenSecret; - } - - /** - * Returns the oauth_token_secret parameter. - * - * @return the oauth_token_secret parameter - */ - public String getTokenSecret() { - return tokenSecret; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/oauth/impl/OpenSocialHttpClient.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/oauth/impl/OpenSocialHttpClient.java b/src/com/google/wave/api/oauth/impl/OpenSocialHttpClient.java deleted file mode 100644 index 93154df..0000000 --- a/src/com/google/wave/api/oauth/impl/OpenSocialHttpClient.java +++ /dev/null @@ -1,183 +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.oauth.impl; - -import net.oauth.http.HttpMessage; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Map; - - -/** - * A small implementation of HttpClient to serve the needs of the OAuth library - * rather than requiring org.apache.http.client as a dependency. - * - * @author [email protected] (Dan Holevoet) - * @author [email protected] (David Byttow) - */ -public class OpenSocialHttpClient implements net.oauth.http.HttpClient { - - /** Size of data stream buffer. */ - private static final int BUF_SIZE = 0x1000; // 4K - - /** - * Executes the request, sending the request body if applicable. - * - * @param request - * @return Response message - * @throws IOException - */ - @Override - public OpenSocialHttpResponseMessage execute(HttpMessage request, - Map<String,Object> parameters) throws IOException { - - // If a POST message, translates the body into a string. - String body = null; - if (request.getBody() != null) { - body = new String(toByteArray(request.getBody())); - } - - OpenSocialHttpMessage openSocialRequest = new OpenSocialHttpMessage( - request.method, new OpenSocialUrl(request.url.toExternalForm()), body); - return execute(openSocialRequest); - } - - /** - * Executes the request, sending the request body if applicable. - * - * @param request - * @return Response message - * @throws IOException - */ - private OpenSocialHttpResponseMessage execute(OpenSocialHttpMessage request) - throws IOException { - final String method = request.method; - final boolean isPut = PUT.equalsIgnoreCase(method); - final boolean isPost = POST.equalsIgnoreCase(method); - final boolean isDelete = DELETE.equalsIgnoreCase(method); - - final String bodyString = request.getBodyString(); - final String contentType = request.getHeader(HttpMessage.CONTENT_TYPE); - final OpenSocialUrl url = request.getUrl(); - - OpenSocialHttpResponseMessage response = null; - if (isPut) { - response = send("PUT", url, contentType, bodyString); - } else if (isPost) { - response = send("POST", url, contentType, bodyString); - } else if (isDelete) { - response = send("DELETE", url, contentType); - } else { - response = send("GET", url, contentType); - } - - return response; - } - - /** - * Executes a request without writing any data in the request's body. - * - * @param method - * @param url - * @return Response message - */ - private OpenSocialHttpResponseMessage send(String method, OpenSocialUrl url, - String contentType) throws IOException { - return send(method, url, contentType, null); - } - - /** - * Executes a request and writes all data in the request's body to the - * output stream. - * - * @param method - * @param url - * @param body - * @return Response message - */ - private OpenSocialHttpResponseMessage send(String method, OpenSocialUrl url, - String contentType, String body) throws IOException { - HttpURLConnection connection = null; - try { - connection = getConnection(method, url, contentType); - if (body != null) { - OutputStreamWriter out = - new OutputStreamWriter(connection.getOutputStream()); - out.write(body); - out.flush(); - out.close(); - } - - return new OpenSocialHttpResponseMessage(method, url, - connection.getInputStream(), connection.getResponseCode()); - } catch (IOException e) { - throw new IOException("Container returned status " + - connection.getResponseCode() + " \"" + e.getMessage() + "\""); - } - } - - /** - * Opens a new HTTP connection for the URL associated with this object. - * - * @param method - * @param url - * @return Opened connection - * @throws IOException if URL is invalid, or unsupported - */ - private HttpURLConnection getConnection(String method, OpenSocialUrl url, - String contentType) throws IOException { - HttpURLConnection connection = - (HttpURLConnection) new URL(url.toString()).openConnection(); - if (contentType != null && !contentType.equals("")) { - connection.setRequestProperty(HttpMessage.CONTENT_TYPE, contentType); - } - connection.setRequestMethod(method); - connection.setDoOutput(true); - connection.connect(); - - return connection; - } - - private static long copy(InputStream from, OutputStream to) throws IOException { - byte[] buf = new byte[BUF_SIZE]; - long total = 0; - while (true) { - int r = from.read(buf); - if (r == -1) { - break; - } - to.write(buf, 0, r); - total += r; - } - return total; - } - - private static byte[] toByteArray(InputStream in) throws IOException { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - copy(in, out); - return out.toByteArray(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/oauth/impl/OpenSocialHttpMessage.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/oauth/impl/OpenSocialHttpMessage.java b/src/com/google/wave/api/oauth/impl/OpenSocialHttpMessage.java deleted file mode 100644 index ec90fe6..0000000 --- a/src/com/google/wave/api/oauth/impl/OpenSocialHttpMessage.java +++ /dev/null @@ -1,71 +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.oauth.impl; - -import net.oauth.http.HttpMessage; - -import java.util.HashMap; -import java.util.Map; - -/** - * A simple extension of net.oauth.http.HttpMessage using an OpenSocialUrl - * instead of java.net.URL and encoding the body as a String instead of an - * InputStream. - * - * @author [email protected] (Jason Cooper) - */ -class OpenSocialHttpMessage extends HttpMessage { - - protected String body; - protected OpenSocialUrl url; - - public OpenSocialHttpMessage(String method, OpenSocialUrl url) { - this(method, url, null); - } - - public OpenSocialHttpMessage(String method, OpenSocialUrl url, String body) { - this.method = method; - this.body = body; - this.url = url; - } - - public OpenSocialUrl getUrl() { - return url; - } - - public String getBodyString() { - return body; - } - - public void addHeader(String headerName, String value) { - Map<String, String> messageHeaders = new HashMap<String, String>(); - messageHeaders.put(headerName, value); - - for (Map.Entry<String, String> entry : messageHeaders.entrySet()) { - this.headers.add(entry); - } - } - - public void addHeaders(Map<String, String> messageHeaders) { - for (Map.Entry<String, String> entry : messageHeaders.entrySet()) { - this.headers.add(entry); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/oauth/impl/OpenSocialHttpResponseMessage.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/oauth/impl/OpenSocialHttpResponseMessage.java b/src/com/google/wave/api/oauth/impl/OpenSocialHttpResponseMessage.java deleted file mode 100644 index 422784c..0000000 --- a/src/com/google/wave/api/oauth/impl/OpenSocialHttpResponseMessage.java +++ /dev/null @@ -1,84 +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.oauth.impl; - -import net.oauth.http.HttpResponseMessage; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -/** - * A small implementation of an HttpResponseMessage that does not require - * org.apache.http.client as a dependency. - * - * @author [email protected] (Dan Holevoet) - * @author [email protected] (Jason Cooper) - */ -class OpenSocialHttpResponseMessage extends HttpResponseMessage { - - protected int status; - - protected OpenSocialHttpResponseMessage(String method, OpenSocialUrl url, - InputStream responseStream, int status) throws IOException { - super(method, url.toURL()); - - this.body = responseStream; - this.status = status; - } - - /** - * Returns the status code for the response. - * - * @return Status code - */ - @Override - public int getStatusCode() { - return this.status; - } - - /** - * Transforms response output contained in the InputStream object returned by - * the connection into a string representation which can later be parsed into - * a more meaningful object, e.g. OpenSocialPerson. - * - * @return Response body as a String - * @throws IOException if the InputStream is not retrievable or accessible - */ - public String getBodyString() throws IOException { - if (body != null) { - StringBuilder sb = new StringBuilder(); - BufferedReader reader = new BufferedReader( - new InputStreamReader(body)); - - String line = null; - while ((line = reader.readLine()) != null) { - sb.append(line); - } - - body.close(); - - return sb.toString(); - } - - return null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/oauth/impl/OpenSocialUrl.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/oauth/impl/OpenSocialUrl.java b/src/com/google/wave/api/oauth/impl/OpenSocialUrl.java deleted file mode 100644 index 5debc9f..0000000 --- a/src/com/google/wave/api/oauth/impl/OpenSocialUrl.java +++ /dev/null @@ -1,111 +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.oauth.impl; - -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLEncoder; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Vector; - -/** - * An object which represents a simple URL. Once an object is instantiated, - * path components and parameters can be added. Once all of the elements - * are in place, the object can be serialized into a string. This class - * is used by internal classes and not by clients directly. - * - * @author [email protected] (Jason Cooper) - */ -public class OpenSocialUrl { - - private final String base; - private final List<String> components; - private final Map<String, String> queryStringParameters; - - public OpenSocialUrl(String base) { - this.base = base; - this.components = new Vector<String>(); - this.queryStringParameters = new HashMap<String, String>(); - } - - /** - * Adds passed String to the path component queue. - * - * @param component Path component to add - */ - public void addPathComponent(String component) { - components.add(component); - } - - /** - * Creates a new entry in queryStringParameters Map with the passed key and - * value; used for adding URL parameters such as oauth_signature and the - * various other OAuth parameters that are required in order to submit a - * signed request. - * - * @param key Parameter name - * @param value Parameter value - */ - public void addQueryStringParameter(String key, String value) { - try { - queryStringParameters.put(URLEncoder.encode(key, "UTF-8"), - URLEncoder.encode(value, "UTF-8")); - } catch (UnsupportedEncodingException e) { - // "UTF-8" is a supported encoding so this exception should never be - // thrown - } - } - - /** - * Returns a String representing the serialized URL including the base - * followed by any path components added to the path component queue - * and, last but not least, appending any query string parameters as - * name-value pairs after the full path. - */ - @Override - public String toString() { - StringBuilder s = new StringBuilder(this.base); - - for (String pathComponent : this.components) { - if (s.charAt(s.length() - 1) != '/') { - s.append("/"); - } - s.append(pathComponent); - } - - char connector = '?'; - for (Map.Entry<String, String> e : this.queryStringParameters.entrySet()) { - s.append(connector); - s.append(e.getKey()); - s.append('='); - s.append(e.getValue()); - connector = '&'; - } - - return s.toString(); - } - - public URL toURL() throws MalformedURLException { - return new URL(this.toString()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/oauth/impl/PopupLoginFormHandler.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/oauth/impl/PopupLoginFormHandler.java b/src/com/google/wave/api/oauth/impl/PopupLoginFormHandler.java deleted file mode 100644 index 886555b..0000000 --- a/src/com/google/wave/api/oauth/impl/PopupLoginFormHandler.java +++ /dev/null @@ -1,80 +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.oauth.impl; - -import com.google.wave.api.Gadget; -import com.google.wave.api.Wavelet; -import com.google.wave.api.oauth.LoginFormHandler; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.logging.Logger; - -/** - * Adds a gadget that automatically opens a new browser window directed - * to the service provider authorization url. - * - * @author [email protected] (Elizabeth Ford) - * @author [email protected] (Kimberly White) - */ -public class PopupLoginFormHandler implements LoginFormHandler { - - private static final Logger LOG = Logger.getLogger(SimpleLoginFormHandler.class.getName()); - - /** The URL of the gadget we add to handle the popup. */ - private static final String GADGET_PATH = "/popup.xml"; - - //TODO: Have this be passed in by TweetyServlet. - /** Character encoding used to encode query params. */ - private static final String CHARACTER_ENCODING = "UTF-8"; - - /** Robot address. */ - private final String remoteHost; - - /** - * Constructor - * - * @param remoteHost The robot address. - */ - public PopupLoginFormHandler(String remoteHost) { - this.remoteHost = remoteHost; - } - - @Override - public void renderLogin(String userRecordKey, Wavelet wavelet) { - // Clear login form. - wavelet.getRootBlip().all().delete(); - - // TODO (elizabethford): Eventually have buildUrl from within gadget with gadget fetching - // request key from datastore. - // Add the gadget. - String gadgetString = ""; - try { - String gadgetUrl = "http://" + remoteHost + GADGET_PATH; - gadgetString = gadgetUrl + "?" + URLEncoder.encode("key", CHARACTER_ENCODING) + "=" - + URLEncoder.encode(userRecordKey, CHARACTER_ENCODING); - } catch (UnsupportedEncodingException e) { - LOG.warning(e.toString()); - } - Gadget gadget = new Gadget(gadgetString); - LOG.info(gadgetString); - wavelet.getRootBlip().append(gadget); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/oauth/impl/SimpleLoginFormHandler.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/oauth/impl/SimpleLoginFormHandler.java b/src/com/google/wave/api/oauth/impl/SimpleLoginFormHandler.java deleted file mode 100644 index e5aebc0..0000000 --- a/src/com/google/wave/api/oauth/impl/SimpleLoginFormHandler.java +++ /dev/null @@ -1,112 +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.oauth.impl; - -import com.google.wave.api.ElementType; -import com.google.wave.api.FormElement; -import com.google.wave.api.Wavelet; -import com.google.wave.api.event.Event; -import com.google.wave.api.event.EventType; -import com.google.wave.api.event.FormButtonClickedEvent; -import com.google.wave.api.oauth.LoginFormHandler; - -import java.util.List; -import java.util.logging.Logger; - -import javax.jdo.JDOObjectNotFoundException; -import javax.jdo.PersistenceManager; - -/** - * Generates a login form in Wavelet to direct user to OAuth service login. - * Includes a link to the service provider authorization page that opens the - * page in a new window. - * - * @author [email protected] (Elizabeth Ford) - * @author [email protected] (Kimberly White) - */ -public class SimpleLoginFormHandler implements LoginFormHandler { - - private static final Logger LOG = Logger.getLogger(SimpleLoginFormHandler.class.getName()); - - /** The key of a link annotation. */ - private static final String LINK_ANNOTATION_KEY = "link/manual"; - - /** Text for the link to the authorization page. */ - private static final String LOGIN_LINK_TEXT = "Authorization Required"; - - /** The caption of the button element in the table of contents wave. */ - private static final String LOGIN_BUTTON_CAPTION = "Continue"; - - /** The id of the button element. */ - private static final String LOGIN_BUTTON_ID = "successButton"; - - @Override - public void renderLogin(String userRecordKey, Wavelet wavelet) { - // Clear login form. - wavelet.getRootBlip().all().delete(); - - PersistenceManager pm = SingletonPersistenceManagerFactory.get().getPersistenceManager(); - OAuthUser userProfile = null; - try { - userProfile = pm.getObjectById(OAuthUser.class, userRecordKey); - } catch (JDOObjectNotFoundException objectNotFound) { - LOG.severe("Error fetching object from datastore with key: " + userRecordKey); - } finally { - pm.close(); - } - String url = userProfile.getAuthUrl(); - - // Add authentication prompt and insert link to service provider log-in page - // to wavelet. - wavelet.getRootBlip().all().delete(); - StringBuilder b = new StringBuilder(); - b.append("\n"); - int startIndex = b.length(); - b.append(LOGIN_LINK_TEXT + "\n\n"); - wavelet.getRootBlip().append(b.toString()); - - // Add button to click when authentication is complete. - wavelet.getRootBlip().append(new FormElement(ElementType.BUTTON, LOGIN_BUTTON_ID, - LOGIN_BUTTON_CAPTION)); - - // Linkify the authorization link. - wavelet.getRootBlip().range(startIndex, startIndex + LOGIN_LINK_TEXT.length()).annotate( - LINK_ANNOTATION_KEY, url); - } - - /** - * Checks whether a button in a blip was clicked or not. This method will - * reset the state of the button to be "unclicked" at the end of the method - * call. - * - * @param events A list of events received from Google Wave that needs to be - * checked whether it contains form button clicked event or not. - * @return true If the user just clicked on the button. - */ - public boolean isButtonClicked(List<Event> events) { - for (Event event : events) { - if (event.getType() == EventType.FORM_BUTTON_CLICKED - && LOGIN_BUTTON_ID.equals(FormButtonClickedEvent.as(event).getButtonName())) { - return true; - } - } - return false; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/oauth/impl/SingletonPersistenceManagerFactory.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/oauth/impl/SingletonPersistenceManagerFactory.java b/src/com/google/wave/api/oauth/impl/SingletonPersistenceManagerFactory.java deleted file mode 100644 index bc897be..0000000 --- a/src/com/google/wave/api/oauth/impl/SingletonPersistenceManagerFactory.java +++ /dev/null @@ -1,47 +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.oauth.impl; - -import javax.jdo.JDOHelper; -import javax.jdo.PersistenceManagerFactory; - -/** - * PersistenceManagerFactory singleton wrapper class. - * Allows a single instance of PersistenceManagerFactory to save from costly - * initializations. - * - * @author [email protected] (Kimberly White) - */ -public final class SingletonPersistenceManagerFactory { - private static final PersistenceManagerFactory pmfInstance = - JDOHelper.getPersistenceManagerFactory("transactions-optional"); - - /** PMF constructor. */ - private SingletonPersistenceManagerFactory() {} - - /** - * Allows app to reuse a single instance of a PersistenceManagerFactory. - * - * @return instance of persistence manager. - */ - public static PersistenceManagerFactory get() { - return pmfInstance; - } -}
