Author: chabotc
Date: Wed Dec 3 01:32:36 2008
New Revision: 722821
URL: http://svn.apache.org/viewvc?rev=722821&view=rev
Log:
SHINDIG-724 by Pan Jie - Fixes inlined messages support
Modified:
incubator/shindig/trunk/php/src/gadgets/GadgetServer.php
incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php
incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php
Modified: incubator/shindig/trunk/php/src/gadgets/GadgetServer.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetServer.php?rev=722821&r1=722820&r2=722821&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetServer.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetServer.php Wed Dec 3
01:32:36 2008
@@ -45,7 +45,8 @@
$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));
+ $messagesArray = $this->getMessagesArrayForSpecs($context,
array($localeSpec, $language_allSpec,
+ $all_allSpec));
if (count($messagesArray) == 0) {
return null;
}
@@ -65,16 +66,29 @@
foreach ($specs as $spec) {
if ($spec == null) continue;
$uri = $spec->getURI();
- if ($uri == null) continue;
+ if ($uri == null) {
+ if ($spec->getLocaleMessageBundles() != null) {
+ $messagesArray[] = $spec->getLocaleMessageBundles();
+ } else {
+ $messagesArray[] = array();
+ }
+ continue;
+ }
$requestArray[] = new RemoteContentRequest($uri);
$contextArray[] = $context;
+ $messagesArray[] = null;
+ }
+ if (count($messagesArray) == 0) {
+ return array();
}
- 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());
+ for ($i = 0, $j = 0; $i < count($messagesArray); ++ $i) {
+ if ($messagesArray[$i] == null) {
+ $messagesArray[$i] =
$parser->parse($responseArray[$j]->getResponseContent());
+ ++ $j;
+ }
}
return $messagesArray;
}
@@ -92,7 +106,7 @@
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
- // get the message bundle for this gadget
+ // 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);
@@ -102,7 +116,7 @@
$substitutor->addSubstitution('MODULE', "ID",
$gadget->getId()->getModuleId());
if ($bundle) {
$gadget->getSubstitutions()->addSubstitutions('MSG',
$bundle->getMessages());
- }
+ }
// Bidi support
$rtl = false;
$locale = $context->getLocale();
@@ -113,7 +127,7 @@
$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) {
@@ -178,6 +192,3 @@
$gadget->preloads = $preloads;
}
}
-
-
-
Modified: incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php?rev=722821&r1=722820&r2=722821&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php Wed Dec 3
01:32:36 2008
@@ -29,26 +29,23 @@
}
// make sure we can generate a detailed error report
libxml_use_internal_errors(true);
- //TODO add libxml_get_errors() functionality so we can have a bit more
understandable errors..
if (($doc = simplexml_load_string($xml, 'SimpleXMLElement',
LIBXML_NOCDATA)) == false) {
- $errors = libxml_get_errors();
+ $errors = @libxml_get_errors();
$xmlErrors = '';
foreach ($errors as $error) {
$xmlErrors .= $this->displayXmlError($error);
}
- libxml_clear_errors();
- throw new SpecParserException("<b>Invalid XML Document</b> <br>" .
$xmlErrors);
+ @libxml_clear_errors();
+ throw new SpecParserException("<b>Invalid XML Document</b><br/>\n" .
$xmlErrors);
}
if (count($doc->ModulePrefs) != 1) {
throw new SpecParserException("Missing or duplicated <ModulePrefs>");
}
$gadget = new Gadget($context->getGadgetId(), $context);
-
// record Checksum to trace xml version
$gadget->setChecksum($xml);
-
// process ModulePref attributes
- $this->processModulePrefs($gadget, $doc->ModulePrefs, $context);
+ $this->processModulePrefs($gadget, $doc->ModulePrefs);
if (isset($doc->ModulePrefs->OAuth)) {
// process OAuthPref attributes
$this->processOAuthSpec($gadget, $doc->ModulePrefs->OAuth, $context);
@@ -75,7 +72,7 @@
return $gadget;
}
- private function processModulePrefs(&$gadget, $ModulePrefs, $context) {
+ private function processModulePrefs(&$gadget, $ModulePrefs) {
$attributes = $ModulePrefs->attributes();
if (empty($attributes['title'])) {
throw new SpecParserException("Missing or empty \"title\" attribute.");
@@ -135,22 +132,11 @@
$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;
- }
- }
- }
+ $parser = new MessageBundleParser();
+ $localeMessageBundles = $parser->getMessages($locale);
}
$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);
Modified: incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php?rev=722821&r1=722820&r2=722821&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php Wed Dec 3
01:32:36 2008
@@ -29,6 +29,10 @@
public function parse($xml) {
$doc = @simplexml_load_string($xml);
+ return $this->getMessages($doc);
+ }
+
+ public function getMessages(SimpleXMLElement $doc) {
if (! $doc) {
throw new Exception("Invalid XML structure in message bundle");
}
@@ -40,4 +44,4 @@
}
return $messages;
}
-}
\ No newline at end of file
+}