[mashup-dev] svn commit r9597 - in trunk/mashup/java/modules/www: .
js/wso2
svn at wso2.org
svn at wso2.org
Thu Nov 8 22:20:14 PST 2007
Author: tyrell
Date: Thu Nov 8 22:20:10 2007
New Revision: 9597
Modified:
trunk/mashup/java/modules/www/js/wso2/scraper.js
trunk/mashup/java/modules/www/scraper.html
Log:
Adding http parameter and variable support
Modified: trunk/mashup/java/modules/www/js/wso2/scraper.js
==============================================================================
--- trunk/mashup/java/modules/www/js/wso2/scraper.js (original)
+++ trunk/mashup/java/modules/www/js/wso2/scraper.js Thu Nov 8 22:20:10 2007
@@ -24,6 +24,8 @@
var currentUrlVariable = "";
+var variableCount = 0;
+
wso2.mashup.Scraper = function() {
};
@@ -45,9 +47,9 @@
//Adding html-xml tag with the given url
currentUrlVariable = "page_" + ++urlCount;
- scraperConfig.appendChild(new XML("<var-def name='" + currentUrlVariable +
+ /*scraperConfig.appendChild(new XML("<var-def name='" + currentUrlVariable +
"'><html-to-xml><http method='get' url='" + url +
- "'/></html-to-xml></var-def>"));
+ "'/></html-to-xml></var-def>"));*/
scraperConfigTextArea.value = scraperConfig;
wso2.mashup.services.getUrlContents(url, navigator.userAgent, getUrlContentsCallback);
@@ -222,19 +224,55 @@
var selText = scraperConfigTextArea.value.substring(scraperConfigTextArea.selectionStart, scraperConfigTextArea.selectionEnd);
if (tag == "empty") {
- scraperConfigTextArea.value = before + "<empty>" + selText + "</empty>" + after;
+ selText = "<empty>" + selText + "</empty>";
} else if (tag == "text") {
- scraperConfigTextArea.value = before + "<text>" + selText + "</text>" + after;
+ selText = "<text>" + selText + "</text>";
} else if (tag == "file") {
- scraperConfigTextArea.value = before +
- '<file action="file_action" path="file_path" type="file_type" charset="UTF-8">' +
- selText + "</file>" + after;
+ selText =
+ '<file action="file_action" path="file_path" type="file_type" charset="UTF-8">' +
+ selText + "</file>";
+ } else if (tag == "var-def") {
+ selText = '<var-def name="variable_' + ++variableCount + '">' + selText + "</var-def>";
+ }
+
+ try {
+ scraperConfig = new XML(before + selText + after);
+ scraperConfigTextArea.value = scraperConfig;
+ } catch (e) {
+ alert(e.message);
}
}
};
wso2.mashup.Scraper.addHttpRequest = function () {
- scraperConfig.prependChild(new XML('<http url="url-to-fetch" method="post" charset="UTF-8" cookie-policy="cookie_policy" username="username" password="password"></http>'));
+ scraperConfig.prependChild(new XML('<http url="url-to-fetch" method="post" charset="UTF-8" cookie-policy="cookie_policy" username="username" password="password"><!-- TODO: Add additional request parameters --></http>'));
scraperConfigTextArea.value = scraperConfig;
+};
+
+wso2.mashup.Scraper.addHttpParam = function () {
+ var before = scraperConfigTextArea.value.substring(0, scraperConfigTextArea.selectionStart);
+ var after = scraperConfigTextArea.value.substring(scraperConfigTextArea.selectionEnd, scraperConfigTextArea.value.length);
+ var selText = scraperConfigTextArea.value.substring(scraperConfigTextArea.selectionStart, scraperConfigTextArea.selectionEnd);
+
+ try {
+ var httpRequestElement = new XML(selText);
+ httpRequestElement.appendChild(new XML('<http-param name="param_name"></http-param>'));
+
+ scraperConfig = new XML(before + httpRequestElement + after);
+ scraperConfigTextArea.value = scraperConfig;
+
+ } catch(e) {
+ alert(e.message)
+ }
+};
+
+wso2.mashup.Scraper.formatXML = function () {
+ try {
+ scraperConfig = new XML(scraperConfigTextArea.value);
+ scraperConfigTextArea.value = scraperConfig;
+ } catch(e) {
+ alert(e.message);
+ }
+
};
\ No newline at end of file
Modified: trunk/mashup/java/modules/www/scraper.html
==============================================================================
--- trunk/mashup/java/modules/www/scraper.html (original)
+++ trunk/mashup/java/modules/www/scraper.html Thu Nov 8 22:20:10 2007
@@ -106,18 +106,20 @@
<div id="hd">
<!-- URL Entry Section -->
<div id="url-section" class="url-section">
- Entrer a URL to scrape <input type="text" id="txtUrl" name="txtUrl" width="100">
- <input type="button" id="cmdGo" name="cmdGo" value="Add 'html-to-xml'"
+ Entrer a URL to gather XPath expressions <input type="text" id="txtUrl" name="txtUrl" width="100">
+ <input type="button" id="cmdGo" name="cmdGo" value="Fetch"
onclick="wso2.mashup.Scraper.getHTML(document.getElementById('txtUrl').value); return false;">
<br>
<br>
<div id="tool-bar">Tool Bar<br>
+ <input type="button" value="Add HTTP request" onclick="wso2.mashup.Scraper.addHttpRequest();">
+ <input type="button" value="Add HTTP request parameter" onclick="wso2.mashup.Scraper.addHttpParam();">
+ <input type="button" value="Convert to variable" onclick="wso2.mashup.Scraper.SurroundWith('var-def');">
<input type="button" value="Surround with <empty></empty>" onclick="wso2.mashup.Scraper.SurroundWith('empty');">
<input type="button" value="Surround with <text></text>" onclick="wso2.mashup.Scraper.SurroundWith('text');">
<input type="button" value="Surround with <file></file>" onclick="wso2.mashup.Scraper.SurroundWith('file');">
- <input type="button" value="Add HTTP request" onclick="wso2.mashup.Scraper.addHttpRequest();">
- <input type="button" value="Button" onclick="return false;">
- <input type="button" value="Button" onclick="return false;">
+
+ <input type="button" value="Apply formatting" onclick="wso2.mashup.Scraper.formatXML();">
</div>
</div>
</div>
More information about the Mashup-dev
mailing list