Author: chabotc
Date: Fri Jul 4 09:00:49 2008
New Revision: 674078
URL: http://svn.apache.org/viewvc?rev=674078&view=rev
Log:
added missing files of last commit
Added:
incubator/shindig/trunk/php/src/gadgets/BasicGadgetSpecFactory.php
incubator/shindig/trunk/php/src/gadgets/GadgetSpecFactory.php
Modified:
incubator/shindig/trunk/php/src/common/RemoteContentRequest.php
Modified: incubator/shindig/trunk/php/src/common/RemoteContentRequest.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/RemoteContentRequest.php?rev=674078&r1=674077&r2=674078&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/RemoteContentRequest.php (original)
+++ incubator/shindig/trunk/php/src/common/RemoteContentRequest.php Fri Jul 4
09:00:49 2008
@@ -32,6 +32,7 @@
private $contentType = null;
private $options;
private $created;
+ private static $SC_OK = 200; //Please, use only for testing!
public $handle = false;
public static $DEFAULT_CONTENT_TYPE =
"application/x-www-form-urlencoded; charset=utf-8";
@@ -196,6 +197,23 @@
$options->ignoreCache = $ignoreCache;
return $this->createRemoteContentRequestWithUriOptions($uri,
$options);
}
+
+ /**
+ * Simple constructor for setting a basic response from a string.
Mostly used
+ * for testing.
+ *
+ * @param body
+ */
+ public function getHttpFalseResponseBody($body) {
+ return $this->createFalseResponse(RemoteContentRequest::$SC_OK,
$body, null);
+ }
+
+ private function createFalseResponse($httpCode, $body, $headers) {
+ $this->httpCode = $httpCode;
+ $this->responseContent = $body;
+ $this->headers = $headers;
+ return $this;
+ }
// returns a hash code which identifies this request, used for caching
// takes url and postbody into account for constructing the sha1
checksum
Added: incubator/shindig/trunk/php/src/gadgets/BasicGadgetSpecFactory.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/BasicGadgetSpecFactory.php?rev=674078&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/BasicGadgetSpecFactory.php (added)
+++ incubator/shindig/trunk/php/src/gadgets/BasicGadgetSpecFactory.php Fri Jul
4 09:00:49 2008
@@ -0,0 +1,60 @@
+<?php
+/*
+ * 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.
+ */
+
+/**
+ * Basic implementation of a gadget spec factory.
+ */
+class BasicGadgetSpecFactory implements GadgetSpecFactory {
+
+ private $fetcher;
+
+ public function __construct($fetcher) {
+ $this->fetcher = $fetcher;
+ }
+
+ public function getGadgetSpec(GadgetContext $context) {
+ return $this->getGadgetSpecUri($context->getUrl(),
$context->getIgnoreCache());
+ }
+
+ /**
+ * Retrieves a gadget specification from the cache or from the Internet.
+ */
+ public function getGadgetSpecUri($url, $ignoreCache) {
+ if ($ignoreCache) {
+ return $this->fetchFromWeb($url, true);
+ }
+ return $this->fetchFromWeb($url, false);
+ }
+
+ /**
+ * Retrieves a gadget specification from the Internet, processes its
views and
+ * adds it to the cache.
+ */
+ private function fetchFromWeb($url, $ignoreCache) {
+ $remoteContentRequest = new RemoteContentRequest($url);
+ $remoteContentRequest->getRequest($url, $ignoreCache);
+ $spec = $this->fetcher->fetchRequest($remoteContentRequest);
+ $specParser = new GadgetSpecParser();
+ $context = new ProxyGadgetContext($url);
+ $gadgetSpec = $specParser->parse($spec->getResponseContent(),
$context);
+ return $gadgetSpec;
+ }
+
+}
Added: incubator/shindig/trunk/php/src/gadgets/GadgetSpecFactory.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetSpecFactory.php?rev=674078&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetSpecFactory.php (added)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetSpecFactory.php Fri Jul 4
09:00:49 2008
@@ -0,0 +1,30 @@
+<?php
+/*
+ * 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.
+ */
+
+/** Factory of gadget specs */
+interface GadgetSpecFactory {
+
+ /** Return a gadget spec for a context */
+ public function getGadgetSpec(GadgetContext $context);
+
+ /** Return a gadget spec for a URI */
+ public function getGadgetSpecUri($url, $ignoreCache);
+
+}