[cc-commits] [SCM] GSoC 2010 Firefox Extension project (branch master) updated. 8b28da1f6288e50bc6b8a591f55bb004a1e8bedd

git version control git at a7.creativecommons.org
Thu Jul 15 02:15:57 EDT 2010


The branch, master has been updated
       via  8b28da1f6288e50bc6b8a591f55bb004a1e8bedd (commit)
      from  51bfc83687a3535fbaa59a3c7a9e588d61704828 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 8b28da1f6288e50bc6b8a591f55bb004a1e8bedd
Author: Igor Lukanin <mail at igor.lukanin.name>
Date:   Thu Jul 15 12:15:48 2010 +0600

    The "Page Info" dialog update: the license name for an object is displayed using CC API

-----------------------------------------------------------------------

Summary of changes (followed by patch):
 content/browser.xul  |    8 +------
 content/pageInfo.xul |    4 +-
 doc/FUNCSPEC         |   12 +++++-----
 module/ccffext.js    |   52 +++++++++++++++++++++++++++++++++++--------------
 4 files changed, 46 insertions(+), 30 deletions(-)

diff --git a/content/browser.xul b/content/browser.xul
index e01968d..f5bee4c 100644
--- a/content/browser.xul
+++ b/content/browser.xul
@@ -56,13 +56,7 @@
 
 							ccffext.objects.callbackify(doc,ccffext.ui.icon.show,function(document,callbackDocument)
 							{
-								XH.transform(document.getElementsByTagName("body")[0]);
-								XH.transform(document.getElementsByTagName("head")[0]);
-
-								RDFA.reset();
-								RDFA.parse(document);
-
-								ccffext.cache.put(document.location.href,RDFA.triplestore);
+								ccffext.objects.parse(document.location.href,document,RDFA,XH);
 							});
 						}
 					}
diff --git a/content/pageInfo.xul b/content/pageInfo.xul
index 661ca3b..6a40a7c 100644
--- a/content/pageInfo.xul
+++ b/content/pageInfo.xul
@@ -99,7 +99,7 @@
 						sourceTitle.setAttribute("value",ccffext.l10n.get("object.source.title.label"));
 						sourceLine.appendChild(sourceTitle);
 
-						const source = ccffext.objects.getSource(doc,objects[i]);
+						var source = ccffext.objects.getSource(doc,objects[i]);
 						const sourceValue = document.createElement("label");
 						sourceValue.setAttribute("class","anchor");
 						sourceValue.setAttribute("value",source);
@@ -118,7 +118,7 @@
 						licenseTitle.setAttribute("value",ccffext.l10n.get("object.license.title.label"));
 						licenseLine.appendChild(licenseTitle);
 
-						const license = ccffext.objects.getLicense(doc,objects[i],window.opener.content);
+						var license = ccffext.objects.getLicense(doc,objects[i],window.opener.content,RDFA,XH);
 						const licenseValue = document.createElement("label");
 						licenseValue.setAttribute("class","anchor");
 						licenseValue.setAttribute("value",license.name);
diff --git a/doc/FUNCSPEC b/doc/FUNCSPEC
index eaf45b5..b0884fc 100644
--- a/doc/FUNCSPEC
+++ b/doc/FUNCSPEC
@@ -14,19 +14,19 @@ Any software is made to provide ways to solve a specific problem of its end user
 		- The context menu should provide a way to highlight licensed objects
 + The tab in the "Page Info" dialog
 	+ The tab image should also refer to CC and reflect the extension`s purpose
-	± There`re should be a checkbox to turn the highlighting on/off
-	± There`re should be a label showing the number of all licensed objects
-	+ There`re should be a list displaying an entry for any of licensed objects
+	± There should be a checkbox to turn the highlighting on/off
+	+ There should be a label showing the number of all licensed objects
+	+ There should be a list displaying an entry for any of licensed objects
 		+ The name of the object should be displayed
 		± Some information about the object should be shown:
 			- The type of the object
 			- The information about object`s creator
 			- The information about object`s rights holder
 			+ The hyperlink to the soure
-		- Some licensing information should be shown:
-			- The name of the license
+		± Some licensing information should be shown:
+			+ The name of the license
 			- Standard СС icon(s)
-			- Hyperlink to the extended information about the license
+			+ Hyperlink to the extended information about the license
 			- The summary of permissions, requirements and prohibitions
 			- The way to obtain the attribution information (a context menu-enabled button)
 - Licensed objects` highlighting
diff --git a/module/ccffext.js b/module/ccffext.js
index 4210b9b..61a1810 100644
--- a/module/ccffext.js
+++ b/module/ccffext.js
@@ -190,6 +190,24 @@ var ccffext =
 		},
 
 		/**
+		 * Parses RDFa data of the given document and stores it in the cache
+		 *
+		 * @param document The document to be parsed
+		 * @param RDFA RDFA object
+		 * @param XH XH object
+		 */
+		parse : function(location,document,RDFA,XH)
+		{
+			XH.transform(document.getElementsByTagName("body")[0]);
+			XH.transform(document.getElementsByTagName("head")[0]);
+
+			RDFA.reset();
+			RDFA.parse(document);
+
+			ccffext.cache.put(location,RDFA.triplestore);
+		},
+
+		/**
 		 * Checks if the cache contains the information for a document, calling a callback if not. Then calls a callback
 		 * if the document has any licensed objects
 		 */
@@ -247,24 +265,16 @@ var ccffext =
 		 * @param object The object
 		 * @param window The context window
 		 */
-		getLicense : function(document,object,window)
+		getLicense : function(document,object,window,RDFA,XH)
 		{
 			var license =
 			{
-				name : "Yandex OSS License",
-				uri : "http://ya.ru"
+				name : undefined,
+				uri : undefined
 			};
 
 			for (let i = 0, pairs = ccffext.objects.getPairs(document,object); i < pairs.length; ++i)
 			{
-//				ccffext.log(pairs[i]);
-
-				var license =
-				{
-					name : undefined,
-					uri : undefined
-				};
-
 				if ((pairs[i][0].uri == "http://www.w3.org/1999/xhtml/vocab#copyright"
 						|| pairs[i][0].uri == "http://www.w3.org/1999/xhtml/vocab#license"))
 				{
@@ -273,18 +283,30 @@ var ccffext =
 				}
 			}
 
+			ccffext.log("http://api.creativecommons.org/rest/1.5/details?license-uri=" + license.uri);
+
 			if ("undefined" != typeof license.uri)
 			{
 				var xhr = new window.XMLHttpRequest();
-				xhr.open("GET","http://api.creativecommons.org/rest/1.5/details?license-uri=" + license.uri,false);
-				xhr.send(null);
+				let uri = "http://api.creativecommons.org/rest/1.5/details?license-uri=" + license.uri;
+				xhr.open("GET",uri,false);
+				xhr.send();
 				if (4 == xhr.readyState && 200 == xhr.status)
-				{
+				{				
+
 					ccffext.log(xhr.responseText);
+
+					var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
+							.createInstance(Components.interfaces.nsIDOMParser);
+					var doc = parser.parseFromString(xhr.responseText,"text/xml");
+					license.name = doc.getElementsByTagName("license-name")[0].textContent;
 				}
 			}
 
-			license.name = license.uri;
+			if ("undefined" == license.name)
+			{
+				license.name = license.uri;
+			}
 
 			return license;
 		}


hooks/post-receive
-- 
GSoC 2010 Firefox Extension project



More information about the cc-commits mailing list