http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/robot/Capability.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/robot/Capability.java b/src/com/google/wave/api/robot/Capability.java deleted file mode 100644 index aad22f9..0000000 --- a/src/com/google/wave/api/robot/Capability.java +++ /dev/null @@ -1,171 +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.robot; - -import com.google.common.collect.ImmutableList; -import com.google.common.base.Preconditions; -import com.google.wave.api.Context; -import com.google.wave.api.event.EventType; - -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * A Capability represents a Robot's interest in handling a given event. The - * Robot can request that additional context and document content be sent with - * the event. - * - */ -public class Capability { - - /** - * The context provided by default if non is declared. - */ - public static final List<Context> DEFAULT_CONTEXT = - ImmutableList.of(Context.ROOT, Context.PARENT, Context.CHILDREN); - - /** - * The list of contexts (parent, children, siblings, all) to send to the Robot - * for this capability. - */ - private final List<Context> contexts; - - /** - * The associated eventType. - */ - private EventType eventType; - - /** - * The filter applicable to this event as a regular expression. - */ - private final Pattern filter; - - /** - * Configures a Robot capability with the content, contexts and filter - * specified. - */ - public Capability(EventType eventType, List<Context> contexts, String filter) { - Preconditions.checkNotNull(contexts); - Preconditions.checkNotNull(filter); - this.contexts = ImmutableList.copyOf(contexts); - this.eventType = eventType; - if (filter.isEmpty()) { - this.filter = null; - } else { - this.filter = Pattern.compile(filter); - } - } - - /** - * Convenience constructor with default empty filter. - */ - public Capability(EventType eventType, List<Context> contexts) { - this(eventType, contexts, ""); - } - - /** - * Convenience constructor with default empty filter and default context. - */ - public Capability(EventType eventType) { - this(eventType, DEFAULT_CONTEXT, ""); - } - - /** - * @return the list of contexts requested to be sent for this capability. - */ - public List<Context> getContexts() { - return contexts; - } - - public EventType getEventType() { - return eventType; - } - - /** - * @return whether the set filter matches toMatch - */ - public boolean matches(String toMatch) { - if (filter == null) { - return true; - } else { - Matcher matcher = filter.matcher(toMatch); - return matcher.find(); - } - } - - /** - * @return the filter pattern - */ - public String getFilter() { - if (filter != null) { - return filter.pattern(); - } else { - return ""; - } - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((contexts == null) ? 0 : contexts.hashCode()); - result = prime * result + ((eventType == null) ? 0 : eventType.hashCode()); - result = prime * result + ((filter == null) ? 0 : filter.pattern().hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof Capability)) { - return false; - } - Capability other = (Capability) obj; - if (contexts == null) { - if (other.contexts != null) { - return false; - } - } else if (!contexts.equals(other.contexts)) { - return false; - } - if (eventType == null) { - if (other.eventType != null) { - return false; - } - } else if (!eventType.equals(other.eventType)) { - return false; - } - if (filter == null) { - if (other.filter != null) { - return false; - } - } else if (!filter.pattern().equals(other.filter.pattern())) { - return false; - } - return true; - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/robot/CapabilityFetchException.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/robot/CapabilityFetchException.java b/src/com/google/wave/api/robot/CapabilityFetchException.java deleted file mode 100644 index ca437df..0000000 --- a/src/com/google/wave/api/robot/CapabilityFetchException.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.robot; - -/** - * Exception thrown when retrieving robot capabilities. - * - */ -public class CapabilityFetchException extends Exception { - - public final int httpStatus; - /** - * Constructs a new exception with the given detail message. - */ - public CapabilityFetchException(String message) { - super(message); - httpStatus = 0; - } - - /** - * Constructs a new exception with the given cause. - */ - public CapabilityFetchException(Throwable cause) { - super(cause); - httpStatus = 0; - } - - /** - * Constructs a new exception with the given detail message and cause. - */ - public CapabilityFetchException(String message, Throwable cause) { - super(message, cause); - httpStatus = 0; - } - - public CapabilityFetchException(String message, int status) { - super(message); - httpStatus = status; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/robot/HttpRobotConnection.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/robot/HttpRobotConnection.java b/src/com/google/wave/api/robot/HttpRobotConnection.java deleted file mode 100644 index 706f6fe..0000000 --- a/src/com/google/wave/api/robot/HttpRobotConnection.java +++ /dev/null @@ -1,123 +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.robot; - -import com.google.common.base.Charsets; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.JdkFutureAdapters; -import com.google.common.util.concurrent.ListenableFuture; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpMethod; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.StringRequestEntity; - -import java.io.IOException; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; - -/** - * A {@link RobotConnection} that uses Apache's {@code HTTP Client} for - * communicating with the robot. - * - */ -public class HttpRobotConnection implements RobotConnection { - - /** A user agent client that can execute HTTP methods. */ - private final HttpClient httpClient; - - /** An executor to submit tasks asynchronously. */ - private final ExecutorService executor; - - /** - * Constructor. - * - * @param client the client for executing HTTP methods. - * @param executor the executor for submitting tasks asynchronously. - */ - public HttpRobotConnection(HttpClient client, ExecutorService executor) { - this.httpClient = client; - this.executor = executor; - } - - @Override - public String get(String url) throws RobotConnectionException { - GetMethod method = new GetMethod(url); - return fetch(url, method); - } - - @Override - public ListenableFuture<String> asyncGet(final String url) { - return JdkFutureAdapters.listenInPoolThread(executor.submit(new Callable<String>() { - @Override - public String call() throws RobotConnectionException { - return get(url); - } - })); - } - - @Override - public String postJson(String url, String body) throws RobotConnectionException { - PostMethod method = new PostMethod(url); - try { - method.setRequestEntity(new StringRequestEntity(body, RobotConnection.JSON_CONTENT_TYPE, - Charsets.UTF_8.name())); - return fetch(url, method); - } catch (IOException e) { - String msg = "Robot fetch http failure: " + url + ": " + e; - throw new RobotConnectionException(msg, e); - } - } - - @Override - public ListenableFuture<String> asyncPostJson(final String url, final String body) { - return JdkFutureAdapters.listenInPoolThread(executor.submit(new Callable<String>() { - @Override - public String call() throws RobotConnectionException { - return postJson(url, body); - } - })); - } - - /** - * Fetches the given URL, given a method ({@code GET} or {@code POST}). - * - * @param url the URL to be fetched. - * @param method the method to fetch the URL, can be {@code GET} or - * {@code POST}. - * @return the content of the URL. - * - * @throws RobotConnectionException if there is a problem fetching the URL, - * for example, if the response code is not HTTP OK (200). - */ - private String fetch(String url, HttpMethod method) throws RobotConnectionException { - try { - int statusCode = httpClient.executeMethod(method); - return RobotConnectionUtil.validateAndReadResponse(url, statusCode, - method.getResponseBodyAsStream()); - } catch (IOException e) { - String msg = "Robot fetch http failure: " + url + "."; - throw new RobotConnectionException(msg, e); - } finally { - method.releaseConnection(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/robot/Robot.gwt.xml ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/robot/Robot.gwt.xml b/src/com/google/wave/api/robot/Robot.gwt.xml deleted file mode 100644 index cf98e13..0000000 --- a/src/com/google/wave/api/robot/Robot.gwt.xml +++ /dev/null @@ -1,26 +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. - --> -<?xml version="1.0" encoding="utf-8"?> -<module> - <inherits name="com.google.gwt.user.User"/> - <inherits name="org.waveprotocol.wave.model.Model"/> - - <source path=""/> - -</module> http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/robot/RobotCapabilitiesParser.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/robot/RobotCapabilitiesParser.java b/src/com/google/wave/api/robot/RobotCapabilitiesParser.java deleted file mode 100644 index 09a4b1b..0000000 --- a/src/com/google/wave/api/robot/RobotCapabilitiesParser.java +++ /dev/null @@ -1,197 +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.robot; - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.wave.api.Context; -import com.google.wave.api.ProtocolVersion; -import com.google.wave.api.event.EventType; - -import org.jdom.Document; -import org.jdom.Element; -import org.jdom.JDOMException; -import org.jdom.Namespace; -import org.jdom.input.SAXBuilder; - -import java.io.IOException; -import java.io.StringReader; -import java.util.List; -import java.util.Map; - -/** - * RobotCapabilityParser is responsible for parsing Robot's capabilities.xml - * file. - * - */ -public class RobotCapabilitiesParser { - - private static final Namespace XML_NS = - Namespace.getNamespace("w", "http://wave.google.com/extensions/robots/1.0"); - - private static final String CAPABILITIES_TAG = "capabilities"; - private static final String CAPABILITY_TAG = "capability"; - private static final String CAPABILITY_CONTEXT_ATTRIBUTE = "context"; - private static final String CAPABILITY_FILTER_ATTRIBUTE = "filter"; - private static final String CAPABILITY_NAME_ATTRIBUTE = "name"; - - private static final String ROBOT_VERSION_TAG = "version"; - private static final String PROTOCOL_VERSION_TAG = "protocolversion"; - private static final String CONSUMER_KEYS_TAG = "consumer_keys"; - private static final String CONSUMER_KEY_TAG = "consumer_key"; - private static final String CONSUMER_KEY_FOR_ATTRIBUTE = "for"; - - private final String capabilitiesXmlUrl; - - private final Map<EventType, Capability> capabilities; - - private final RobotConnection connection; - - private String capabilitiesHash; - - private ProtocolVersion protocolVersion; - - private String consumerKey; // null if no consumer key - - private final String activeRobotApiUrl; - - public RobotCapabilitiesParser(String capabilitiesXmlUrl, RobotConnection connection, - String activeRobotApiUrl) - throws CapabilityFetchException { - this.capabilitiesXmlUrl = capabilitiesXmlUrl; - this.activeRobotApiUrl = activeRobotApiUrl; - this.capabilities = Maps.newHashMap(); - this.connection = connection; - parseRobotDescriptionXmlFile(); - } - - public Map<EventType, Capability> getCapabilities() { - return capabilities; - } - - public String getCapabilitiesHash() { - return capabilitiesHash; - } - - public ProtocolVersion getProtocolVersion() { - return protocolVersion; - } - - public String getConsumerKey() { - return consumerKey; - } - - private void parseRobotDescriptionXmlFile() throws CapabilityFetchException { - // Fetch the XML file that defines the Robot capabilities. - try { - String xmlContent = connection.get(capabilitiesXmlUrl); - if (xmlContent == null || xmlContent.isEmpty()) { - throw new CapabilityFetchException("Empty capabilities.xml"); - } - StringReader reader = new StringReader(xmlContent); - Document document = new SAXBuilder().build(reader); - - // Parse all "<w:capability>" tags. - List<Element> capabilities = getElements(document, CAPABILITIES_TAG, CAPABILITY_TAG, XML_NS); - for (Element capability : capabilities) { - parseCapabilityTag(capability); - } - - // Always react to SELF_ADDED: - if (!this.capabilities.containsKey(EventType.WAVELET_SELF_ADDED)) { - this.capabilities.put(EventType.WAVELET_SELF_ADDED, - new Capability(EventType.WAVELET_SELF_ADDED, Capability.DEFAULT_CONTEXT)); - } - - // Parse "<w:version>" tag. - Element capabilitiesHashElement = - document.getRootElement().getChild(ROBOT_VERSION_TAG, XML_NS); - if (capabilitiesHashElement != null) { - capabilitiesHash = capabilitiesHashElement.getText(); - } - - // Parse "<w:protocolversion>" tag. - Element protocolVersionElement = - document.getRootElement().getChild(PROTOCOL_VERSION_TAG, XML_NS); - if (protocolVersionElement != null) { - protocolVersion = ProtocolVersion.fromVersionString(protocolVersionElement.getText()); - } else { - // In V1 API, we don't have <w:protocolversion> tag in the - // capabilities.xml file. - protocolVersion = ProtocolVersion.V1; - } - - // Parse "<w:consumer_key>" tag(s). - for (Element consumerKeyElement : getElements(document, CONSUMER_KEYS_TAG, CONSUMER_KEY_TAG, - XML_NS)) { - String forUrl = consumerKeyElement.getAttributeValue(CONSUMER_KEY_FOR_ATTRIBUTE); - if (forUrl != null && forUrl.equals(activeRobotApiUrl)) { - consumerKey = consumerKeyElement.getText(); - } - } - } catch (IOException iox) { - throw new CapabilityFetchException("Failure reading capabilities for: " + capabilitiesXmlUrl, - iox); - } catch (JDOMException jdomx) { - throw new CapabilityFetchException("Failure parsing capabilities for: " + capabilitiesXmlUrl, - jdomx); - } catch (RobotConnectionException e) { - throw new CapabilityFetchException(e); - } - } - - private void parseCapabilityTag(Element capability) { - // Get the event type. - EventType eventType = EventType.valueOfIgnoreCase( - capability.getAttributeValue(CAPABILITY_NAME_ATTRIBUTE)); - if (eventType == EventType.UNKNOWN) { - return; - } - - // Parse comma separated "context" attribute. - List<Context> contexts; - String contextsString = capability.getAttributeValue(CAPABILITY_CONTEXT_ATTRIBUTE); - if (contextsString != null && !contextsString.isEmpty()) { - try { - contexts = Lists.newArrayList(); - for (String context : contextsString.split(",")) { - contexts.add(Context.valueOfIgnoreCase(context)); - } - } catch (IllegalArgumentException e) { - contexts = Capability.DEFAULT_CONTEXT; - } - } else { - contexts = Capability.DEFAULT_CONTEXT; - } - // Parse optional "filter" attribute. - String filter = capability.getAttributeValue(CAPABILITY_FILTER_ATTRIBUTE); - if (filter == null || filter.isEmpty()) { - filter = ""; - } - - this.capabilities.put(eventType, new Capability(eventType, contexts, filter)); - } - - @SuppressWarnings({"cast", "unchecked"}) - private List<Element> getElements(Document doc, String parentTag, String tag, Namespace ns) { - Element parent = doc.getRootElement().getChild(parentTag, ns); - return (List<Element>) (parent == null ? Lists.newArrayList() : parent.getChildren(tag, ns)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/robot/RobotConnection.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/robot/RobotConnection.java b/src/com/google/wave/api/robot/RobotConnection.java deleted file mode 100644 index 6d0f561..0000000 --- a/src/com/google/wave/api/robot/RobotConnection.java +++ /dev/null @@ -1,81 +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.robot; - -import com.google.common.util.concurrent.ListenableFuture; - -import java.util.concurrent.Future; - -/** - * Interface for sending messages to robots. This utility supports synchronous - * and asynchronous {@code GET} and {@code POST} methods. - * - */ -public interface RobotConnection { - /** Constant for JSON content type. */ - static final String JSON_CONTENT_TYPE = "application/json; charset=utf-8"; - - /** - * Fetches a robot URL using {@code HTTP GET} method. - * - * @param url the robot's URL. - * @return the content of the URL. - * - * @throws RobotConnectionException if there is a problem fetching the URL, - * for example, if the response code is not HTTP OK (200). - */ - String get(String url) throws RobotConnectionException; - - /** - * Asynchronously fetches a robot URL using {@code HTTP GET} method. - * - * @param url the robot's URL. - * @return a {@link Future} that represents the content of the URL. - * - * @throws RobotConnectionException if there is a problem fetching the URL, - * for example, if the response code is not HTTP OK (200). - */ - ListenableFuture<String> asyncGet(String url) throws RobotConnectionException; - - /** - * Fetches a robot URL using {@code HTTP POST} method. - * - * @param url the robot's URL. - * @param jsonBody the POST body of the request, in JSON. - * @return the content of the URL. - * - * @throws RobotConnectionException if there is a problem fetching the URL, - * for example, if the response code is not HTTP OK (200). - */ - String postJson(String url, String jsonBody) throws RobotConnectionException; - - /** - * Asynchronously fetches a robot URL using {@code HTTP POST} method. - * - * @param url the robot's URL. - * @param jsonBody the POST body of the request, in JSON. - * @return a {@link Future} that represents the content of the URL. - * - * @throws RobotConnectionException if there is a problem fetching the URL, - * for example, if the response code is not HTTP OK (200). - */ - ListenableFuture<String> asyncPostJson(String url, String jsonBody) - throws RobotConnectionException; -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/robot/RobotConnectionException.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/robot/RobotConnectionException.java b/src/com/google/wave/api/robot/RobotConnectionException.java deleted file mode 100644 index 38bcc2f..0000000 --- a/src/com/google/wave/api/robot/RobotConnectionException.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.robot; - -/** - * Checked exception when a robot cannot be reached via HTTP. - * - */ -public class RobotConnectionException extends Exception { - - private final int statusCode; - - /** - * Constructor with a detail message. - * - * @param message detail message for this exception. - */ - public RobotConnectionException(String message) { - super(message); - this.statusCode = 0; - } - - /** - * Constructor with a detail message and cause. - * - * @param message detail message for this exception. - * @param cause the exception that caused this. - */ - public RobotConnectionException(String message, Throwable cause) { - super(message, cause); - this.statusCode = 0; - } - - /** - * Constructor with a detail message and status code. - * - * @param message detail message for this exception. - * @param statusCode the status code returned by the robot. - */ - public RobotConnectionException(String message, int statusCode) { - super(message); - this.statusCode = statusCode; - } - - /** @return the status code returned by the robot. */ - public int getStatusCode() { - return statusCode; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/robot/RobotConnectionUtil.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/robot/RobotConnectionUtil.java b/src/com/google/wave/api/robot/RobotConnectionUtil.java deleted file mode 100644 index 45965b9..0000000 --- a/src/com/google/wave/api/robot/RobotConnectionUtil.java +++ /dev/null @@ -1,77 +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.robot; - -import com.google.common.base.Charsets; -import com.google.common.io.ByteStreams; - -import java.io.IOException; -import java.io.InputStream; - -import javax.servlet.http.HttpServletResponse; - -/** - * A helper class that contains utility method to be used by - * {@link RobotConnection}'s subclasses. - * - */ -public class RobotConnectionUtil { - - /** - * Validates and read the response. - * - * @param url the URL where the response was received from. - * @param statusCode the HTTP status code. - * @param response the raw response of fetching the given URL. - * @return the response, as {@link String}. - * - * @throws RobotConnectionException if the response code is not HTTP OK (200). - */ - public static String validateAndReadResponse(String url, int statusCode, byte[] response) - throws RobotConnectionException { - if (statusCode != HttpServletResponse.SC_OK) { - String msg = "Robot fetch http failure: " + url + ": " + statusCode; - throw new RobotConnectionException(msg, statusCode); - } - - // Read the response. - return new String(response, Charsets.UTF_8); - } - - /** - * Validates and read the response. - * - * @param url the URL where the response was received from. - * @param statusCode the HTTP status code. - * @param response the raw response of fetching the given URL. - * @return the response, as {@link String}. - * - * @throws RobotConnectionException if the response code is not HTTP OK (200). - */ - public static String validateAndReadResponse(String url, int statusCode, InputStream response) - throws RobotConnectionException { - try { - return validateAndReadResponse(url, statusCode, ByteStreams.toByteArray(response)); - } catch (IOException e) { - String msg = "Robot fetch http failure: " + url + "."; - throw new RobotConnectionException(msg, statusCode); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/robot/RobotName.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/robot/RobotName.java b/src/com/google/wave/api/robot/RobotName.java deleted file mode 100644 index 94da21d..0000000 --- a/src/com/google/wave/api/robot/RobotName.java +++ /dev/null @@ -1,251 +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.robot; - -import java.util.regex.Pattern; - -/** - * Simple class representing a (parsed) address of a robot. - * The general form of these addresses is: id[+proxyfor][#version]@domain - * where id is the basic identifier of the robot, proxyfor the id on - * that is proxied for and version the appengine version that should be - * used. - * - */ -public final class RobotName { - /** - * Builds {@link RobotName}s. - */ - public static class Builder { - private final String id; - private final String domain; - private String proxyFor; - private String version; - - public Builder(String id, String domain) { - this.id = id; - this.domain = domain; - this.proxyFor = ""; - this.version = ""; - } - - public Builder withProxyFor(String proxyFor) { - this.proxyFor = proxyFor; - return this; - } - - public Builder withVersion(String version) { - this.version = version; - return this; - } - - public RobotName build() { - return new RobotName(id, domain, proxyFor, version); - } - } - - /** - * Regular expression for robot participant id. TLD is between 2 and 6 - * characters long to match the ascii IANA top level domains as of Sept 2010. - */ - // TODO(user): Make this stricter. - private static final Pattern ROBOT_ID_REGEX = - Pattern.compile("^[a-z0-9._%+#-]+?@[a-z0-9.-]+\\.[a-z]{2,6}$", Pattern.CASE_INSENSITIVE); - - /** - * Checks if the given address looks like a well-formed robot id. - * - * @param address the address to check. - * @return {@code true} if the given address is a robot id. - */ - public static boolean isWellFormedAddress(String address) { - return address != null ? ROBOT_ID_REGEX.matcher(address).matches() : false; - } - - /** - * Construct a RobotName from an address. The address must be well-formed as - * described. @see RobotName - * - * @param address the address to parse. - * @return robot name instance, or {@code null} if the address is not a robot - * address. - */ - public static RobotName fromAddress(String address) { - if (!isWellFormedAddress(address)) { - return null; - } - - int index = address.indexOf('@'); - String id = address.substring(0, index); - String domain = address.substring(index + 1); - index = id.indexOf('#'); - String version = ""; - if (index >= 0) { - version = id.substring(index + 1); - id = address.substring(0, index); - } - index = id.indexOf('+'); - String proxyFor = ""; - if (index >= 0) { - proxyFor = id.substring(index + 1); - id = id.substring(0, index); - } - return new RobotName(id, domain, proxyFor, version); - } - - private final String id; - private final String domain; - private String proxyFor; - private String version; - - public RobotName(String id, String domain) { - this.id = id; - this.domain = domain; - this.proxyFor = ""; - this.version = ""; - } - - private RobotName(String id, String domain, String proxyFor, String version) { - this.id = id; - this.domain = domain; - this.proxyFor = proxyFor; - this.version = version; - } - - public boolean hasProxyFor() { - return !proxyFor.isEmpty(); - } - - public boolean hasVersion() { - return !version.isEmpty(); - } - - public String getId() { - return id; - } - - public String getDomain() { - return domain; - } - - public String getProxyFor() { - return proxyFor; - } - - public void setProxyFor(String proxyFor) { - this.proxyFor = proxyFor; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - /** - * Converts the robot name to the participant id form, including proxy and - * version information, for example, {@code foo+proxy#[email protected]}. - * - * @return the robot participant address. - */ - public String toParticipantAddress() { - return toAddress(true, true); - } - - /** - * Converts the robot name to the email address form, excluding proxy and - * version information, for example, {@code [email protected]}. - * - * @return the robot participant address. - */ - public String toEmailAddress() { - return toAddress(false, false); - } - - /** - * Converts the robot name to the email address form, including version but - * excluding proxy information, for example, {@code foo#[email protected]}. - * - * @return the robot participant address. - */ - public String toEmailAddressWithVersion() { - return toAddress(false, true); - } - - /** - * Converts the robot name to address form (e.g. [email protected]). - * - * @param includeVersion whether to include the version or not. - * @return the robot address. - */ - @Deprecated - public String toAddress(boolean includeVersion) { - return toAddress(false, includeVersion); - } - - /** - * Converts the robot name to address form (e.g. foo+proxy#[email protected]). - * - * @param includeProxyFor whether to include the proxy id or not. - * @param includeVersion whether to include the version or not. - * @return the robot address. - */ - private String toAddress(boolean includeProxyFor, boolean includeVersion) { - StringBuilder address = new StringBuilder(id); - if (includeProxyFor && hasProxyFor()) { - address.append('+').append(proxyFor); - } - if (includeVersion && hasVersion()) { - address.append('#').append(version); - } - address.append('@').append(domain); - return address.toString(); - } - - @Override - public boolean equals(Object other) { - if (other == null) { return false; } - if (other == this) { return true; } - if (other instanceof RobotName) { - RobotName o = (RobotName) other; - return id.equals(o.id) && domain.equals(o.domain) && proxyFor.equals(o.proxyFor) - && version.equals(o.version); - } - return false; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + id.hashCode(); - result = prime * result + domain.hashCode(); - result = prime * result + proxyFor.hashCode(); - result = prime * result + version.hashCode(); - return result; - } - - @Override - public String toString() { - return toParticipantAddress(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/v2/ElementGsonAdaptorV2.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/v2/ElementGsonAdaptorV2.java b/src/com/google/wave/api/v2/ElementGsonAdaptorV2.java deleted file mode 100644 index 95b0a4b..0000000 --- a/src/com/google/wave/api/v2/ElementGsonAdaptorV2.java +++ /dev/null @@ -1,105 +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.v2; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.wave.api.Attachment; -import com.google.wave.api.Element; -import com.google.wave.api.ElementType; -import com.google.wave.api.Image; -import com.google.wave.api.impl.ElementGsonAdaptor; -import com.google.wave.api.impl.GsonFactory; - -import java.lang.reflect.Type; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -/** - * Gson adaptor to serialize and deserialize {@link Element}. In v0.2, we still - * use {@link Image} to represents attachment, so we need to convert all - * attachment objects into Image. - * - * @author [email protected] (Jimin Li) - * @author [email protected] (Marcel Prasetya) - */ -public class ElementGsonAdaptorV2 extends ElementGsonAdaptor { - - private static final Set<String> ATTACHMENT_ONLY_PROPERTIES = new HashSet<String>( - Arrays.asList(Attachment.MIME_TYPE, Attachment.DATA, Attachment.ATTACHMENT_URL)); - - @Override - public JsonElement serialize(Element src, Type typeOfSrc, JsonSerializationContext context) { - if (src.getType() == ElementType.ATTACHMENT) { - src = new Element(ElementType.IMAGE, createImageProperties(src.getProperties())); - } - return super.serialize(src, typeOfSrc, context); - } - - @Override - public Element deserialize(JsonElement jsonElement, Type typeOfT, - JsonDeserializationContext context) throws JsonParseException { - JsonObject json = jsonElement.getAsJsonObject(); - String type = json.get(TYPE_TAG).getAsString(); - - if (ElementType.IMAGE.name().equals(type)) { - JsonObject properties = json.getAsJsonObject(PROPERTIES_TAG); - if (!properties.has(Image.URL)) { - json.addProperty(TYPE_TAG, ElementType.ATTACHMENT.name()); - } - } - return super.deserialize(json, typeOfT, context); - } - - static Map<String, String> createImageProperties(Map<String, String> props) { - Map<String, String> imageProps = new HashMap<String, String>(); - Iterator<Entry<String, String>> iter = props.entrySet().iterator(); - while (iter.hasNext()) { - Entry<String, String> next = iter.next(); - // Removes attachment only properties, and provides backward compatible - // image support to python robot with protocol version 0.2 - if (!ATTACHMENT_ONLY_PROPERTIES.contains(next.getKey())) { - imageProps.put(next.getKey(), next.getValue()); - } - } - return imageProps; - } - - /** - * Registers this {@link ElementGsonAdaptorV2} with the given - * {@link GsonFactory}. - * @param factory {@link GsonFactory} to register the type adapters with - * @return the given {@link GsonFactory} with the registered adapters - */ - public static GsonFactory registerTypeAdapters(GsonFactory factory) { - ElementGsonAdaptorV2 elementGsonAdaptorV2 = new ElementGsonAdaptorV2(); - factory.registerTypeAdapter(Element.class, elementGsonAdaptorV2); - factory.registerTypeAdapter(Attachment.class, elementGsonAdaptorV2); - return factory; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/google/protobuf/descriptor.proto ---------------------------------------------------------------------- diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto deleted file mode 100644 index 77eebe0..0000000 --- a/src/google/protobuf/descriptor.proto +++ /dev/null @@ -1,420 +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. -// -// Author: [email protected] (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// The messages in this file describe the definitions found in .proto files. -// A valid .proto file can be translated directly to a FileDescriptorProto -// without any other information (e.g. without reading its imports). - - - -package google.protobuf; -option java_package = "com.google.protobuf"; -option java_outer_classname = "DescriptorProtos"; - -// descriptor.proto must be optimized for speed because reflection-based -// algorithms don't work during bootstrapping. -option optimize_for = SPEED; - -// The protocol compiler can output a FileDescriptorSet containing the .proto -// files it parses. -message FileDescriptorSet { - repeated FileDescriptorProto file = 1; -} - -// Describes a complete .proto file. -message FileDescriptorProto { - optional string name = 1; // file name, relative to root of source tree - optional string package = 2; // e.g. "foo", "foo.bar", etc. - - // Names of files imported by this file. - repeated string dependency = 3; - - // All top-level definitions in this file. - repeated DescriptorProto message_type = 4; - repeated EnumDescriptorProto enum_type = 5; - repeated ServiceDescriptorProto service = 6; - repeated FieldDescriptorProto extension = 7; - - optional FileOptions options = 8; -} - -// Describes a message type. -message DescriptorProto { - optional string name = 1; - - repeated FieldDescriptorProto field = 2; - repeated FieldDescriptorProto extension = 6; - - repeated DescriptorProto nested_type = 3; - repeated EnumDescriptorProto enum_type = 4; - - message ExtensionRange { - optional int32 start = 1; - optional int32 end = 2; - } - repeated ExtensionRange extension_range = 5; - - optional MessageOptions options = 7; -} - -// Describes a field within a message. -message FieldDescriptorProto { - enum Type { - // 0 is reserved for errors. - // Order is weird for historical reasons. - TYPE_DOUBLE = 1; - TYPE_FLOAT = 2; - TYPE_INT64 = 3; // Not ZigZag encoded. Negative numbers - // take 10 bytes. Use TYPE_SINT64 if negative - // values are likely. - TYPE_UINT64 = 4; - TYPE_INT32 = 5; // Not ZigZag encoded. Negative numbers - // take 10 bytes. Use TYPE_SINT32 if negative - // values are likely. - TYPE_FIXED64 = 6; - TYPE_FIXED32 = 7; - TYPE_BOOL = 8; - TYPE_STRING = 9; - TYPE_GROUP = 10; // Tag-delimited aggregate. - TYPE_MESSAGE = 11; // Length-delimited aggregate. - - // New in version 2. - TYPE_BYTES = 12; - TYPE_UINT32 = 13; - TYPE_ENUM = 14; - TYPE_SFIXED32 = 15; - TYPE_SFIXED64 = 16; - TYPE_SINT32 = 17; // Uses ZigZag encoding. - TYPE_SINT64 = 18; // Uses ZigZag encoding. - }; - - enum Label { - // 0 is reserved for errors - LABEL_OPTIONAL = 1; - LABEL_REQUIRED = 2; - LABEL_REPEATED = 3; - // TODO(sanjay): Should we add LABEL_MAP? - }; - - optional string name = 1; - optional int32 number = 3; - optional Label label = 4; - - // If type_name is set, this need not be set. If both this and type_name - // are set, this must be either TYPE_ENUM or TYPE_MESSAGE. - optional Type type = 5; - - // For message and enum types, this is the name of the type. If the name - // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping - // rules are used to find the type (i.e. first the nested types within this - // message are searched, then within the parent, on up to the root - // namespace). - optional string type_name = 6; - - // For extensions, this is the name of the type being extended. It is - // resolved in the same manner as type_name. - optional string extendee = 2; - - // For numeric types, contains the original text representation of the value. - // For booleans, "true" or "false". - // For strings, contains the default text contents (not escaped in any way). - // For bytes, contains the C escaped value. All bytes >= 128 are escaped. - // TODO(kenton): Base-64 encode? - optional string default_value = 7; - - optional FieldOptions options = 8; -} - -// Describes an enum type. -message EnumDescriptorProto { - optional string name = 1; - - repeated EnumValueDescriptorProto value = 2; - - optional EnumOptions options = 3; -} - -// Describes a value within an enum. -message EnumValueDescriptorProto { - optional string name = 1; - optional int32 number = 2; - - optional EnumValueOptions options = 3; -} - -// Describes a service. -message ServiceDescriptorProto { - optional string name = 1; - repeated MethodDescriptorProto method = 2; - - optional ServiceOptions options = 3; -} - -// Describes a method of a service. -message MethodDescriptorProto { - optional string name = 1; - - // Input and output type names. These are resolved in the same way as - // FieldDescriptorProto.type_name, but must refer to a message type. - optional string input_type = 2; - optional string output_type = 3; - - optional MethodOptions options = 4; -} - -// =================================================================== -// Options - -// Each of the definitions above may have "options" attached. These are -// just annotations which may cause code to be generated slightly differently -// or may contain hints for code that manipulates protocol messages. -// -// Clients may define custom options as extensions of the *Options messages. -// These extensions may not yet be known at parsing time, so the parser cannot -// store the values in them. Instead it stores them in a field in the *Options -// message called uninterpreted_option. This field must have the same name -// across all *Options messages. We then use this field to populate the -// extensions when we build a descriptor, at which point all protos have been -// parsed and so all extensions are known. -// -// Extension numbers for custom options may be chosen as follows: -// * For options which will only be used within a single application or -// organization, or for experimental options, use field numbers 50000 -// through 99999. It is up to you to ensure that you do not use the -// same number for multiple options. -// * For options which will be published and used publicly by multiple -// independent entities, e-mail [email protected] to reserve extension -// numbers. Simply tell me how many you need and I'll send you back a -// set of numbers to use -- there's no need to explain how you intend to -// use them. If this turns out to be popular, a web service will be set up -// to automatically assign option numbers. - - -message FileOptions { - - // Sets the Java package where classes generated from this .proto will be - // placed. By default, the proto package is used, but this is often - // inappropriate because proto packages do not normally start with backwards - // domain names. - optional string java_package = 1; - - - // If set, all the classes from the .proto file are wrapped in a single - // outer class with the given name. This applies to both Proto1 - // (equivalent to the old "--one_java_file" option) and Proto2 (where - // a .proto always translates to a single class, but you may want to - // explicitly choose the class name). - optional string java_outer_classname = 8; - - // If set true, then the Java code generator will generate a separate .java - // file for each top-level message, enum, and service defined in the .proto - // file. Thus, these types will *not* be nested inside the outer class - // named by java_outer_classname. However, the outer class will still be - // generated to contain the file's getDescriptor() method as well as any - // top-level extensions defined in the file. - optional bool java_multiple_files = 10 [default=false]; - - // Generated classes can be optimized for speed or code size. - enum OptimizeMode { - SPEED = 1; // Generate complete code for parsing, serialization, - // etc. - CODE_SIZE = 2; // Use ReflectionOps to implement these methods. - LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime. - } - optional OptimizeMode optimize_for = 9 [default=SPEED]; - - - - - // Should generic services be generated in each language? "Generic" services - // are not specific to any particular RPC system. They are generated by the - // main code generators in each language (without additional plugins). - // Generic services were the only kind of service generation supported by - // early versions of proto2. - // - // Generic services are now considered deprecated in favor of using plugins - // that generate code specific to your particular RPC system. If you are - // using such a plugin, set these to false. In the future, we may change - // the default to false, so if you explicitly want generic services, you - // should explicitly set these to true. - optional bool cc_generic_services = 16 [default=true]; - optional bool java_generic_services = 17 [default=true]; - optional bool py_generic_services = 18 [default=true]; - - // The parser stores options it doesn't recognize here. See above. - repeated UninterpretedOption uninterpreted_option = 999; - - // Clients can define custom options in extensions of this message. See above. - extensions 1000 to max; -} - -message MessageOptions { - // Set true to use the old proto1 MessageSet wire format for extensions. - // This is provided for backwards-compatibility with the MessageSet wire - // format. You should not use this for any other reason: It's less - // efficient, has fewer features, and is more complicated. - // - // The message must be defined exactly as follows: - // message Foo { - // option message_set_wire_format = true; - // extensions 4 to max; - // } - // Note that the message cannot have any defined fields; MessageSets only - // have extensions. - // - // All extensions of your type must be singular messages; e.g. they cannot - // be int32s, enums, or repeated messages. - // - // Because this is an option, the above two restrictions are not enforced by - // the protocol compiler. - optional bool message_set_wire_format = 1 [default=false]; - - // Disables the generation of the standard "descriptor()" accessor, which can - // conflict with a field of the same name. This is meant to make migration - // from proto1 easier; new code should avoid fields named "descriptor". - optional bool no_standard_descriptor_accessor = 2 [default=false]; - - // The parser stores options it doesn't recognize here. See above. - repeated UninterpretedOption uninterpreted_option = 999; - - // Clients can define custom options in extensions of this message. See above. - extensions 1000 to max; -} - -message FieldOptions { - // The ctype option instructs the C++ code generator to use a different - // representation of the field than it normally would. See the specific - // options below. This option is not yet implemented in the open source - // release -- sorry, we'll try to include it in a future version! - optional CType ctype = 1 [default = STRING]; - enum CType { - // Default mode. - STRING = 0; - - CORD = 1; - - STRING_PIECE = 2; - } - // The packed option can be enabled for repeated primitive fields to enable - // a more efficient representation on the wire. Rather than repeatedly - // writing the tag and type for each element, the entire array is encoded as - // a single length-delimited blob. - optional bool packed = 2; - - - // Is this field deprecated? - // Depending on the target platform, this can emit Deprecated annotations - // for accessors, or it will be completely ignored; in the very least, this - // is a formalization for deprecating fields. - optional bool deprecated = 3 [default=false]; - - // EXPERIMENTAL. DO NOT USE. - // For "map" fields, the name of the field in the enclosed type that - // is the key for this map. For example, suppose we have: - // message Item { - // required string name = 1; - // required string value = 2; - // } - // message Config { - // repeated Item items = 1 [experimental_map_key="name"]; - // } - // In this situation, the map key for Item will be set to "name". - // TODO: Fully-implement this, then remove the "experimental_" prefix. - optional string experimental_map_key = 9; - - // The parser stores options it doesn't recognize here. See above. - repeated UninterpretedOption uninterpreted_option = 999; - - // Clients can define custom options in extensions of this message. See above. - extensions 1000 to max; -} - -message EnumOptions { - - // The parser stores options it doesn't recognize here. See above. - repeated UninterpretedOption uninterpreted_option = 999; - - // Clients can define custom options in extensions of this message. See above. - extensions 1000 to max; -} - -message EnumValueOptions { - // The parser stores options it doesn't recognize here. See above. - repeated UninterpretedOption uninterpreted_option = 999; - - // Clients can define custom options in extensions of this message. See above. - extensions 1000 to max; -} - -message ServiceOptions { - - // Note: Field numbers 1 through 32 are reserved for Google's internal RPC - // framework. We apologize for hoarding these numbers to ourselves, but - // we were already using them long before we decided to release Protocol - // Buffers. - - // The parser stores options it doesn't recognize here. See above. - repeated UninterpretedOption uninterpreted_option = 999; - - // Clients can define custom options in extensions of this message. See above. - extensions 1000 to max; -} - -message MethodOptions { - - // Note: Field numbers 1 through 32 are reserved for Google's internal RPC - // framework. We apologize for hoarding these numbers to ourselves, but - // we were already using them long before we decided to release Protocol - // Buffers. - - // The parser stores options it doesn't recognize here. See above. - repeated UninterpretedOption uninterpreted_option = 999; - - // Clients can define custom options in extensions of this message. See above. - extensions 1000 to max; -} - -// A message representing a option the parser does not recognize. This only -// appears in options protos created by the compiler::Parser class. -// DescriptorPool resolves these when building Descriptor objects. Therefore, -// options protos in descriptor objects (e.g. returned by Descriptor::options(), -// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions -// in them. -message UninterpretedOption { - // The name of the uninterpreted option. Each string represents a segment in - // a dot-separated name. is_extension is true iff a segment represents an - // extension (denoted with parentheses in options specs in .proto files). - // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents - // "foo.(bar.baz).qux". - message NamePart { - required string name_part = 1; - required bool is_extension = 2; - } - repeated NamePart name = 2; - - // The value of the uninterpreted option, in whatever type the tokenizer - // identified it as during parsing. Exactly one of these should be set. - optional string identifier_value = 3; - optional uint64 positive_int_value = 4; - optional int64 negative_int_value = 5; - optional double double_value = 6; - optional bytes string_value = 7; -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/attachment/Attachment.gwt.xml ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/attachment/Attachment.gwt.xml b/src/org/waveprotocol/box/attachment/Attachment.gwt.xml deleted file mode 100644 index 2783343..0000000 --- a/src/org/waveprotocol/box/attachment/Attachment.gwt.xml +++ /dev/null @@ -1,26 +0,0 @@ -<?xml version='1.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. - ---> - -<module> - <inherits name="org.waveprotocol.wave.communication.Communication"/> - <source path="" excludes="gson/** proto/**"/> -</module> http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/attachment/attachment.proto ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/attachment/attachment.proto b/src/org/waveprotocol/box/attachment/attachment.proto deleted file mode 100644 index 78c95cc..0000000 --- a/src/org/waveprotocol/box/attachment/attachment.proto +++ /dev/null @@ -1,50 +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. -// -// The image attachment metadata. -// -// Author: [email protected] (Kaplanov A.) - -syntax = "proto2"; - -package attachment; - -option java_package = "org.waveprotocol.box.attachment"; -option java_outer_classname = "AttachmentProto"; - -message AttachmentsResponse { - repeated AttachmentMetadata attachment = 1; -} - -message AttachmentMetadata { - required string attachmentId = 1; - required string waveRef = 2; - required string fileName = 3; - required string mimeType = 4; - required int64 size = 5; - required string creator = 6; - required string attachmentUrl = 7; - required string thumbnailUrl = 8; - optional ImageMetadata imageMetadata = 9; - optional ImageMetadata thumbnailMetadata = 10; - optional bool malware = 11; -} - -message ImageMetadata { - required int32 width = 1; - required int32 height = 2; -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/build.xml ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/build.xml b/src/org/waveprotocol/box/build.xml deleted file mode 100644 index 1511084..0000000 --- a/src/org/waveprotocol/box/build.xml +++ /dev/null @@ -1,25 +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. ---> -<project name="box"> - <import file="${build.common.path}"/> - <property name="libname" value="box"/> - <patternset id="srcs"> - <include name="org/waveprotocol/box/**"/> - </patternset> -</project> http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/common/Common.gwt.xml ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/common/Common.gwt.xml b/src/org/waveprotocol/box/common/Common.gwt.xml deleted file mode 100644 index b19784d..0000000 --- a/src/org/waveprotocol/box/common/Common.gwt.xml +++ /dev/null @@ -1,27 +0,0 @@ -<?xml version='1.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. - ---> - -<module> - <inherits name="com.google.common.collect.Collect"/> - <inherits name="org.waveprotocol.wave.model.Model"/> - <source path="" /> -</module> http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/common/DeltaSequence.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/common/DeltaSequence.java b/src/org/waveprotocol/box/common/DeltaSequence.java deleted file mode 100644 index df0523f..0000000 --- a/src/org/waveprotocol/box/common/DeltaSequence.java +++ /dev/null @@ -1,134 +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 org.waveprotocol.box.common; - -import com.google.common.base.Preconditions; -import com.google.common.collect.ForwardingList; -import com.google.common.collect.ImmutableList; - -import org.waveprotocol.wave.model.operation.wave.TransformedWaveletDelta; -import org.waveprotocol.wave.model.version.HashedVersion; - -import java.util.List; -import java.util.RandomAccess; - -/** - * An immutable sequence of transformed deltas. - * - * This class enforces that the deltas are contiguous. - */ -public final class DeltaSequence extends ForwardingList<TransformedWaveletDelta> - implements RandomAccess { - private final ImmutableList<TransformedWaveletDelta> deltas; - - /** - * Creates an empty delta sequence. This sequence will not have an end version. - */ - public static DeltaSequence empty() { - return new DeltaSequence(ImmutableList.<TransformedWaveletDelta>of(), false); - } - - /** Creates a delta sequence from contiguous deltas. */ - public static DeltaSequence of(Iterable<TransformedWaveletDelta> deltas) { - return new DeltaSequence(ImmutableList.copyOf(deltas), true); - } - - /** Creates a delta sequence from contiguous deltas. */ - public static DeltaSequence of(TransformedWaveletDelta... deltas) { - return new DeltaSequence(ImmutableList.copyOf(deltas), true); - } - - /** Creates a delta sequence by concatenating contiguous sequences. */ - public static DeltaSequence join(DeltaSequence first, DeltaSequence... rest) { - ImmutableList.Builder<TransformedWaveletDelta> builder = ImmutableList.builder(); - builder.addAll(first); - long expectedBeginVersion = first.getEndVersion().getVersion(); - for (DeltaSequence s : rest) { - Preconditions.checkArgument(s.getStartVersion() == expectedBeginVersion, - "Sequences are not contiguous, expected start version %s for sequence %s", - expectedBeginVersion, s); - builder.addAll(s); - expectedBeginVersion = s.getEndVersion().getVersion(); - } - return new DeltaSequence(builder.build(), false); - } - - private DeltaSequence(ImmutableList<TransformedWaveletDelta> deltas, boolean checkVersions) { - this.deltas = deltas; - if (checkVersions) { - checkDeltaVersions(); - } - } - - /** - * @throws IllegalArgumentException if any of the deltas' end version disagrees - * with the next delta's version. - */ - private void checkDeltaVersions() { - for (int i = 0; i < deltas.size(); i++) { - TransformedWaveletDelta delta = deltas.get(i); - long deltaEndVersion = delta.getResultingVersion().getVersion(); - if (i + 1 < deltas.size()) { - long nextVersion = deltas.get(i + 1).getAppliedAtVersion(); - Preconditions.checkArgument(deltaEndVersion == nextVersion, - "Delta %s / %s ends at version %s, next begins at %s", - i + 1, deltas.size(), deltaEndVersion, nextVersion); - } - } - } - - @Override - protected List<TransformedWaveletDelta> delegate() { - return deltas; - } - - @Override - public DeltaSequence subList(int start, int end) { - return new DeltaSequence(deltas.subList(start, end), false); - } - - /** - * Gets the version at which the first delta applied. - * - * @precondition the sequence is non-empty - */ - public long getStartVersion() { - Preconditions.checkState(!deltas.isEmpty(), "Empty delta sequence has no start version"); - return deltas.get(0).getAppliedAtVersion(); - } - - /** - * Gets the resulting version of this sequence. - * - * @precondition the sequence is non-empty - */ - public HashedVersion getEndVersion() { - Preconditions.checkState(!deltas.isEmpty(), "Empty delta sequence has no end version"); - return deltas.get(deltas.size() - 1).getResultingVersion(); - } - - @Override - public String toString() { - if (isEmpty()) { - return "[DeltaSequence empty]"; - } - return "[DeltaSequence " + deltas.size() + " deltas, v " + getStartVersion() + " -> " - + getEndVersion() + ": " + deltas + "]"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/common/DocumentConstants.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/common/DocumentConstants.java b/src/org/waveprotocol/box/common/DocumentConstants.java deleted file mode 100644 index a3d6b01..0000000 --- a/src/org/waveprotocol/box/common/DocumentConstants.java +++ /dev/null @@ -1,49 +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 org.waveprotocol.box.common; - -/** - * Constants relating to the document model. - * - * TODO: put in org.waveprotocol.wave.document or similar - */ -public class DocumentConstants { - - public static final String BLIP = "blip"; - - public static final String BLIP_ID = "id"; - - public static final String BODY = "body"; - - public static final String CONTRIBUTOR = "contributor"; - - public static final String CONTRIBUTOR_NAME = "name"; - - public static final String CONVERSATION = "conversation"; - - public static final String LINE = "line"; - - public static final String MANIFEST_DOCUMENT_ID = "conversation"; - - public static final String THREAD = "thread"; - - private DocumentConstants() { - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/common/ExceptionalIterator.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/common/ExceptionalIterator.java b/src/org/waveprotocol/box/common/ExceptionalIterator.java deleted file mode 100644 index 773361f..0000000 --- a/src/org/waveprotocol/box/common/ExceptionalIterator.java +++ /dev/null @@ -1,146 +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 org.waveprotocol.box.common; - -import java.util.Iterator; -import java.util.NoSuchElementException; - -/** - * A iterator which may throw a checked exception from query methods. - * - * If an exception is thrown the iterator becomes invalid. - * - * @author [email protected] (Alex North) - * @param <T> type iterated over - * @param <E> type of the exception thrown on failure - */ -public interface ExceptionalIterator<T, E extends Exception> { - /** - * An empty iterator. - */ - final static class Empty { - /** Creates an empty iterator. */ - public static <T, E extends Exception> ExceptionalIterator<T, E> create() { - return new ExceptionalIterator<T, E>() { - @Override - public boolean hasNext() { - return false; - } - - @Override - public T next() { - throw new NoSuchElementException(); - } - }; - } - private Empty() {} - } - - /** - * An exceptional iterator which wraps an ordinary iterator. - */ - final static class FromIterator { - /** - * Creates an iterator which adapts an ordinary iterator. It never throws - * {@code E}. - * - * @param it iterator to adapt - */ - public static <T, E extends Exception> ExceptionalIterator<T, E> create(final Iterator<T> it) { - return new ExceptionalIterator<T, E>() { - @Override - public boolean hasNext() { - return it.hasNext(); - } - - @Override - public T next() { - return it.next(); - } - }; - } - - /** - * Creates an iterator which adapts an ordinary iterator but throws an - * exception when the adapted iterator finishes, when hasNext() returns - * false. - * - * @param it iterator to adapt - * @param exception exception to throw when the iterator is finished - */ - public static <T, E extends Exception> ExceptionalIterator<T, E> create(final Iterator<T> it, - final E exception) { - return new ExceptionalIterator<T, E>() { - @Override - public boolean hasNext() throws E { - if (it.hasNext()) { - return true; - } - throw exception; - } - - @Override - public T next() { - return it.next(); - } - }; - } - - private FromIterator() {} - } - - /** - * An exceptional iterator which always throws an exception. - */ - final static class Failing { - /** - * Creates an iterator which just throws an exception. - * - * @param exception exception to throw - */ - public static <T, E extends Exception> ExceptionalIterator<T, E> create(final E exception) { - return new ExceptionalIterator<T, E>() { - @Override - public boolean hasNext() throws E { - throw exception; - } - - @Override - public T next() throws E { - throw exception; - } - }; - } - } - - /** - * Returns true if the iteration has more elements. - * - * @throws E if an underlying query fails - */ - boolean hasNext() throws E; - - /** - * Returns the next element in the iteration. - * - * @throws E if an underlying query fails - */ - T next() throws E; -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/common/ListReceiver.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/common/ListReceiver.java b/src/org/waveprotocol/box/common/ListReceiver.java deleted file mode 100644 index 347fbe5..0000000 --- a/src/org/waveprotocol/box/common/ListReceiver.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.waveprotocol.box.common; -/* - * - * 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. - * -*/ - - -import java.util.ArrayList; - -/** - * Callback interface to sequential reception objects to list. - * - * @author [email protected] (Andrew Kaplanov) - */ -public class ListReceiver<T> extends ArrayList<T> implements Receiver<T> { - - @Override - public boolean put(T obj) { - add(obj); - return true; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/common/Receiver.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/common/Receiver.java b/src/org/waveprotocol/box/common/Receiver.java deleted file mode 100644 index a90c48f..0000000 --- a/src/org/waveprotocol/box/common/Receiver.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.waveprotocol.box.common; -/* - * - * 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. - * -*/ - - -/** - * Callback interface to sequential reception objects. - * - * @author [email protected] (Andrew Kaplanov) - */ -public interface Receiver<T> { - /** - * Receives objects. - * - * @param the object. - * @return true to continue, false to cancel transmission. - */ - public boolean put(T obj); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/common/SessionConstants.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/common/SessionConstants.java b/src/org/waveprotocol/box/common/SessionConstants.java deleted file mode 100644 index 9fab195..0000000 --- a/src/org/waveprotocol/box/common/SessionConstants.java +++ /dev/null @@ -1,45 +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 org.waveprotocol.box.common; - -/** - * Session constants for FedOne clients. - * - * @author [email protected] (Benjamin Kalman) - */ -public interface SessionConstants { - - /** - * The domain the wave server serves waves for. - */ - public final static String DOMAIN = "domain"; - - /** - * The user's logged in address. - */ - public final static String ADDRESS = "address"; - - /** - * A globally unique id that the client can use to seed unique ids of the session. - * It has no relationship with the application session or http session or authentication, and - * is not guaranteed to be cryptographically strong. - */ - public final static String ID_SEED = "id"; -}
