Author: chabotc
Date: Thu Jun  5 00:31:33 2008
New Revision: 663490

URL: http://svn.apache.org/viewvc?rev=663490&view=rev
Log:
SHINDIG-335 implements inline message bundles

Added:
    incubator/shindig/trunk/php/src/gadgets/LocaleMessageBundle.php
Modified:
    incubator/shindig/trunk/php/src/common/Locale.php
    incubator/shindig/trunk/php/src/gadgets/GadgetServer.php
    incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php
    incubator/shindig/trunk/php/src/gadgets/LocaleSpec.php
    incubator/shindig/trunk/php/src/gadgets/http/GadgetRenderingServlet.php
    incubator/shindig/trunk/php/src/gadgets/http/JsonRpcServlet.php

Modified: incubator/shindig/trunk/php/src/common/Locale.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Locale.php?rev=663490&r1=663489&r2=663490&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/Locale.php (original)
+++ incubator/shindig/trunk/php/src/common/Locale.php Thu Jun  5 00:31:33 2008
@@ -1,4 +1,22 @@
 <?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.
+ *
+ */
 
 /**
  * Locale class doesn't exist in php, so to allow the code base to be closer 
to the java and it's spec
@@ -31,4 +49,5 @@
        {
                return $this->country;
        }
+
 }
\ No newline at end of file

Modified: incubator/shindig/trunk/php/src/gadgets/GadgetServer.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetServer.php?rev=663490&r1=663489&r2=663490&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetServer.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetServer.php Thu Jun  5 
00:31:33 2008
@@ -15,7 +15,7 @@
  * "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.
- * 
+ *
  */
 
 /*
@@ -47,7 +47,7 @@
                return $gadget;
        }
 
-       private function getBundle($localeSpec, $context)
+       private function getBundle(LocaleSpec $localeSpec=null, $context)
        {
                if ($localeSpec != null) {
                        $uri = $localeSpec->getURI();
@@ -57,6 +57,12 @@
                                $parser = new MessageBundleParser();
                                $bundle = 
$parser->parse($response->getResponseContent());
                                return $bundle;
+                       } else {
+                               $messages = array();
+                               foreach ($localeSpec->getLocaleMessageBundles() 
as $messageBundle) {
+                                       $messages[$messageBundle->getName()] = 
$messageBundle->getDesc();
+                               }
+                               return new MessageBundle($messages);
                        }
                }
                return null;
@@ -95,24 +101,24 @@
                //NOTE i've been a bit liberal here with folding code into this 
function, while it did get a bit long, the many include()'s are slowing us down
                // Should really clean this up a bit in the future though
                $localeSpec = $this->getLocaleSpec($gadget, $context);
-               
+
                // get the message bundle for this gadget
                $bundle = $this->getBundle($localeSpec, $context);
-               
+
                //FIXME this is a half-assed solution between following the 
refactoring and maintaining some of the old code, fixing this up later
                $gadget->setMessageBundle($bundle);
-               
+
                // perform substitutions
                $substitutor = $gadget->getSubstitutions();
-               
+
                // Module ID
                $substitutor->addSubstitution('MODULE', "ID", 
$gadget->getId()->getModuleId());
-               
+
                // Messages (multi-language)
                if ($bundle) {
                        $gadget->getSubstitutions()->addSubstitutions('MSG', 
$bundle->getMessages());
                }
-               
+
                // Bidi support
                $rtl = false;
                if ($localeSpec != null) {
@@ -122,7 +128,7 @@
                $substitutor->addSubstitution('BIDI', "END_EDGE", $rtl ? "left" 
: "right");
                $substitutor->addSubstitution('BIDI', "DIR", $rtl ? "rtl" : 
"ltr");
                $substitutor->addSubstitution('BIDI', "REVERSE_DIR", $rtl ? 
"ltr" : "rtl");
-               
+
                // userPref's
                $upValues = $gadget->getUserPrefValues();
                foreach ($gadget->getUserPrefs() as $pref) {
@@ -136,7 +142,7 @@
                        }
                        $substitutor->addSubstitution('USER_PREF', $name, 
$value);
                }
-               
+
                // Process required / desired features
                $requires = $gadget->getRequires();
                $needed = array();

Modified: incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php?rev=663490&r1=663489&r2=663490&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php Thu Jun  5 
00:31:33 2008
@@ -15,7 +15,7 @@
  * "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.
- * 
+ *
  */
 
 class SpecParserException extends Exception {}
@@ -61,7 +61,7 @@
                        throw new SpecParserException("Missing or empty 
\"title\" attribute.");
                }
                // Get ModulePrefs base and extended attributes
-               // See 
http://code.google.com/apis/gadgets/docs/gadgets-extended-xsd.html 
+               // See 
http://code.google.com/apis/gadgets/docs/gadgets-extended-xsd.html
                // (trim is used here since it not only cleans up the text, but 
also auto-casts the SimpleXMLElement to a string)
                $gadget->title = trim($attributes['title']);
                $gadget->author = isset($attributes['author']) ? 
trim($attributes['author']) : '';
@@ -102,10 +102,25 @@
                $countryAttr = isset($attributes['country']) ? 
trim($attributes['country']) : 'all';
                $rtlAttr = isset($attributes['language_direction']) ? 
trim($attributes['language_direction']) : '';
                $rightToLeft = $rtlAttr == 'rtl';
+               $localeMessageBundles = array();
+               if ($messageAttr == '') {
+                       $messageBundle = $locale->messagebundle;
+                       if (!empty($messageBundle)) {
+                               $messageName = $messageBundle->msg;
+                               if (!empty($messageName)) {
+                                       foreach ($messageName as $name) {
+                                               $attrs = $name->attributes();
+                                               $localeMessageBundle = new 
LocalMessageBundle((string)$attrs['name'], (string)$name);
+                                               $localeMessageBundles[] = 
$localeMessageBundle;
+                                       }
+                               }
+                       }
+               }
                $locale = new LocaleSpec();
                $locale->rightToLeft = $rightToLeft;
                //FIXME java seems to use a baseurl here, probably for the 
http:// part but i'm not sure yet. Should verify behavior later to see if i got 
it right
                $locale->url = $messageAttr;
+               $locale->localeMessageBundles = $localeMessageBundles;
                $locale->locale = new Locale($languageAttr, $countryAttr);
                return $locale;
        }
@@ -127,7 +142,7 @@
                                $attr = $enum->attributes();
                                // java based shindig doesn't throw an 
exception here, but it -is- invalid and should trigger a parse error?
                                /*if (empty($attr['value'])) {
-                                       throw new 
SpecParserException("EnumValue must have a value field.");
+                               throw new SpecParserException("EnumValue must 
have a value field.");
                                }*/
                                $valueText = trim($attr['value']);
                                $displayText = ! empty($attr['display_value']) 
? trim($attr['display_value']) : $valueText;

Added: incubator/shindig/trunk/php/src/gadgets/LocaleMessageBundle.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/LocaleMessageBundle.php?rev=663490&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/LocaleMessageBundle.php (added)
+++ incubator/shindig/trunk/php/src/gadgets/LocaleMessageBundle.php Thu Jun  5 
00:31:33 2008
@@ -0,0 +1,40 @@
+<?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.
+ *
+ */
+
+/**
+ * Used by the LocaleSpec to extract from the xml the locales inline
+ * */
+class LocalMessageBundle {
+       private $name;
+       private $desc;
+
+       public function __construct($name, $desc) {
+               $this->name = $name;
+               $this->desc = $desc;
+       }
+
+       public function getName() {
+               return $this->name;
+       }
+
+       public function getDesc() {
+               return $this->desc;
+       }
+}
\ No newline at end of file

Modified: incubator/shindig/trunk/php/src/gadgets/LocaleSpec.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/LocaleSpec.php?rev=663490&r1=663489&r2=663490&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/LocaleSpec.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/LocaleSpec.php Thu Jun  5 00:31:33 
2008
@@ -15,13 +15,18 @@
  * "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.
- * 
+ *
  */
 
 class LocaleSpec {
        public $url;
        public $locale;
        public $rightToLeft;
+       public $localeMessageBundles = array();
+
+       public function getLocaleMessageBundles() {
+               return $this->localeMessageBundles;
+       }
 
        public function getURI()
        {
@@ -37,4 +42,4 @@
        {
                return $this->rightToLeft;
        }
-}
+}
\ No newline at end of file

Modified: 
incubator/shindig/trunk/php/src/gadgets/http/GadgetRenderingServlet.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/http/GadgetRenderingServlet.php?rev=663490&r1=663489&r2=663490&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/http/GadgetRenderingServlet.php 
(original)
+++ incubator/shindig/trunk/php/src/gadgets/http/GadgetRenderingServlet.php Thu 
Jun  5 00:31:33 2008
@@ -15,7 +15,7 @@
  * "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.
- * 
+ *
  */
 require 'src/common/HttpServlet.php';
 require 'src/gadgets/GadgetContext.php';
@@ -30,6 +30,7 @@
 require 'src/gadgets/UserPrefs.php';
 require 'src/gadgets/Substitutions.php';
 require 'src/gadgets/LocaleSpec.php';
+require 'src/gadgets/LocaleMessageBundle.php';
 require 'src/common/Locale.php';
 require 'src/gadgets/UserPref.php';
 require 'src/gadgets/ViewSpec.php';
@@ -48,7 +49,7 @@
  * This class deals with the gadget rendering requests (in default config this
  * would be /gadgets/ifr?url=<some gadget's url>). It uses the gadget server 
and
  * gadget context to render the xml to a valid html file, and outputs it.
- * 
+ *
  */
 class GadgetRenderingServlet extends HttpServlet {
        private $context;
@@ -63,11 +64,11 @@
                        if (empty($_GET['url'])) {
                                throw new GadgetException("Missing required 
parameter: url");
                        }
-                       // GadgetContext builds up all the contextual variables 
(based on the url or post) 
+                       // GadgetContext builds up all the contextual variables 
(based on the url or post)
                        // plus instances all required classes (feature 
registry, fetcher, blacklist, etc)
                        $this->context = new GadgetContext('GADGET');
                        // Unfortunatly we can't do caja content filtering 
here, hoping we'll have a RPC service
-                       // or command line caja to use for this at some point 
+                       // or command line caja to use for this at some point
                        $gadgetServer = new GadgetServer();
                        $gadget = $gadgetServer->processGadget($this->context);
                        $this->outputGadget($gadget, $this->context);
@@ -176,7 +177,7 @@
                        echo $externJs;
                }
                echo "<script><!--\n" . $this->appendJsConfig($context, 
$gadget) . $this->appendMessages($gadget) . "-->\n</script>\n";
-               
+
                $gadgetExceptions = array();
                $content = 
$gadget->getSubstitutions()->substitute($view->getContent());
                if (empty($content)) {

Modified: incubator/shindig/trunk/php/src/gadgets/http/JsonRpcServlet.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/http/JsonRpcServlet.php?rev=663490&r1=663489&r2=663490&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/http/JsonRpcServlet.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/http/JsonRpcServlet.php Thu Jun  5 
00:31:33 2008
@@ -15,7 +15,7 @@
  * "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.
- * 
+ *
  */
 require 'src/common/HttpServlet.php';
 require 'src/gadgets/JsonRpcHandler.php';
@@ -41,6 +41,7 @@
 require 'src/common/UrlGenerator.php';
 require 'src/gadgets/http/HttpUtil.php';
 require 'src/gadgets/LocaleSpec.php';
+require 'src/gadgets/LocaleMessageBundle.php';
 require 'src/gadgets/UserPref.php';
 require 'src/gadgets/FeatureSpec.php';
 require 'src/gadgets/MessageBundleParser.php';


Reply via email to