Return-Path: Delivered-To: apmail-incubator-shindig-dev-archive@locus.apache.org Received: (qmail 56139 invoked from network); 2 Dec 2008 06:55:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Dec 2008 06:55:08 -0000 Received: (qmail 71806 invoked by uid 500); 2 Dec 2008 06:55:19 -0000 Delivered-To: apmail-incubator-shindig-dev-archive@incubator.apache.org Received: (qmail 71784 invoked by uid 500); 2 Dec 2008 06:55:19 -0000 Mailing-List: contact shindig-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: shindig-dev@incubator.apache.org Delivered-To: mailing list shindig-commits@incubator.apache.org Received: (qmail 71775 invoked by uid 99); 2 Dec 2008 06:55:19 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Dec 2008 22:55:19 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Dec 2008 06:53:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 41E4A2388892; Mon, 1 Dec 2008 22:54:47 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r722390 - in /incubator/shindig/trunk/php: src/common/sample/CacheFile.php src/gadgets/GadgetServer.php src/gadgets/MessageBundleParser.php test/gadgets/MessageBundleParserTest.php Date: Tue, 02 Dec 2008 06:54:47 -0000 To: shindig-commits@incubator.apache.org From: chabotc@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081202065447.41E4A2388892@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: chabotc Date: Mon Dec 1 22:54:46 2008 New Revision: 722390 URL: http://svn.apache.org/viewvc?rev=722390&view=rev Log: SHINDIG-541 by Impetus technologies and improved upon by Pan Jie - Support Tiered message bundles Modified: incubator/shindig/trunk/php/src/common/sample/CacheFile.php incubator/shindig/trunk/php/src/gadgets/GadgetServer.php incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php incubator/shindig/trunk/php/test/gadgets/MessageBundleParserTest.php Modified: incubator/shindig/trunk/php/src/common/sample/CacheFile.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/sample/CacheFile.php?rev=722390&r1=722389&r2=722390&view=diff ============================================================================== --- incubator/shindig/trunk/php/src/common/sample/CacheFile.php (original) +++ incubator/shindig/trunk/php/src/common/sample/CacheFile.php Mon Dec 1 22:54:46 2008 @@ -96,7 +96,7 @@ } if (File::exists($cacheFile) && File::readable($cacheFile)) { $now = time(); - if (($mtime = filemtime($cacheFile)) !== false && ($now - $mtime) < $expiration) { + if (($mtime = @filemtime($cacheFile)) !== false && ($now - $mtime) < $expiration) { if (($data = @file_get_contents($cacheFile)) !== false) { $data = unserialize($data); return $data; @@ -135,4 +135,4 @@ throw new CacheException("Cache file could not be deleted"); } } -} \ 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=722390&r1=722389&r2=722390&view=diff ============================================================================== --- incubator/shindig/trunk/php/src/gadgets/GadgetServer.php (original) +++ incubator/shindig/trunk/php/src/gadgets/GadgetServer.php Mon Dec 1 22:54:46 2008 @@ -40,24 +40,43 @@ return $gadget; } - private function getBundle(LocaleSpec $localeSpec = null, $context) { - if ($localeSpec != null) { - $uri = $localeSpec->getURI(); - if ($uri != null) { - $fetcher = $context->getHttpFetcher(); - $response = $fetcher->fetch(new RemoteContentRequest($uri), $context); - $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); - } + private function getBundle($context, $gadget) { + $locale = $context->getLocale(); + $localeSpec = $this->localeSpec($gadget, $locale); // en-US + $language_allSpec = $this->localeSpec($gadget, new Locale($locale->getLanguage(), "all")); // en-all + $all_allSpec = $this->localeSpec($gadget, new Locale("all", "all")); // all-all + $messagesArray = $this->getMessagesArrayForSpecs($context, array($localeSpec, $language_allSpec, $all_allSpec)); + if (count($messagesArray) == 0) { + return null; + } + for ($i = 1; $i < count($messagesArray); ++ $i) { + $diff = array_diff_key($messagesArray[$i], $messagesArray[0]); + foreach ($diff as $diffKey => $diffValue) { + $messagesArray[0][$diffKey] = $diffValue; + } + } + return new MessageBundle($messagesArray[0]); + } + + private function getMessagesArrayForSpecs($context, Array $specs) { + $requestArray = array(); + $contextArray = array(); + $messagesArray = array(); + foreach ($specs as $spec) { + if ($spec == null) continue; + $uri = $spec->getURI(); + if ($uri == null) continue; + $requestArray[] = new RemoteContentRequest($uri); + $contextArray[] = $context; + } + if (count($requestArray) == 0) return array(); + $fetcher = $context->getHttpFetcher(); + $responseArray = $fetcher->multiFetch($requestArray, $contextArray); + $parser = new MessageBundleParser(); + foreach ($responseArray as $response) { + $messagesArray[] = $parser->parse($response->getResponseContent()); } - return null; + return $messagesArray; } private function localeSpec($gadget, $locale) { @@ -71,53 +90,30 @@ return null; } - private function getLocaleSpec($gadget, $context) { - $locale = $context->getLocale(); - // en-US - $localeSpec = $this->localeSpec($gadget, $locale); - if ($localeSpec == null) { - // en-all - $localeSpec = $this->localeSpec($gadget, new Locale($locale->getLanguage(), "all")); - } - if ($localeSpec == null) { - // all-all - $localeSpec = $this->localeSpec($gadget, new Locale("all", "all")); - } - return $localeSpec; - } - private function featuresLoad(Gadget $gadget, $context) { //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); - + // get the message bundle for this gadget + $bundle = $this->getBundle($context, $gadget); //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; + $locale = $context->getLocale(); + $localeSpec = $this->localeSpec($gadget, $locale); // en-US if ($localeSpec != null) { $rtl = $localeSpec->isRightToLeft(); } $substitutor->addSubstitution('BIDI', "START_EDGE", $rtl ? "right" : "left"); $substitutor->addSubstitution('BIDI', "END_EDGE", $rtl ? "left" : "right"); $substitutor->addSubstitution('BIDI', "DIR", $rtl ? "rtl" : "ltr"); - $substitutor->addSubstitution('BIDI', "REVERSE_DIR", $rtl ? "ltr" : "rtl"); - + $substitutor->addSubstitution('BIDI', "REVERSE_DIR", $rtl ? "ltr" : "rtl"); // userPref's $upValues = $gadget->getUserPrefValues(); foreach ($gadget->getUserPrefs() as $pref) { @@ -131,9 +127,7 @@ } $substitutor->addSubstitution('UP', $name, $value); } - $this->substitutePreloads($gadget, $substitutor); - // Process required / desired features $requires = $gadget->getRequires(); $needed = array(); Modified: incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php?rev=722390&r1=722389&r2=722390&view=diff ============================================================================== --- incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php (original) +++ incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php Mon Dec 1 22:54:46 2008 @@ -38,6 +38,6 @@ $this->processMessage($messages, $msg); } } - return new MessageBundle($messages); + return $messages; } } \ No newline at end of file Modified: incubator/shindig/trunk/php/test/gadgets/MessageBundleParserTest.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/gadgets/MessageBundleParserTest.php?rev=722390&r1=722389&r2=722390&view=diff ============================================================================== --- incubator/shindig/trunk/php/test/gadgets/MessageBundleParserTest.php (original) +++ incubator/shindig/trunk/php/test/gadgets/MessageBundleParserTest.php Mon Dec 1 22:54:46 2008 @@ -46,7 +46,6 @@ $this->MessageBundleParser = null; $this->MessageBundle = null; - parent::tearDown(); } @@ -65,8 +64,10 @@ $this->MessageBundle = $this->MessageBundleParser->parse($xml); - $this->assertTrue($this->MessageBundle instanceof MessageBundle); - + $this->assertEquals('Message 1', $this->MessageBundle['name1']); + $this->assertEquals('Message 2', $this->MessageBundle['name2']); + $this->assertEquals('Message 3', $this->MessageBundle['name3']); + $this->assertEquals('Message 4', $this->MessageBundle['name4']); } }