Skip to content

Commit 515f582

Browse files
committed
- Fixed several bugs in the html parser.
- Updated default headers in the HTTP Request class. - Updated logic in the Recordset class to use Prepared Statements. - Fixed bug inserting/updating null values in the Recordset class. - Added support for SQL functions git-svn-id: svn://192.168.0.80/JavaXT/javaxt-core@665 2c7b0aa6-e0b2-3c4e-bb4a-8b65b6c465ff
1 parent 3338bbc commit 515f582

File tree

7 files changed

+282
-286
lines changed

7 files changed

+282
-286
lines changed

src/javaxt/html/Element.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public String getAttributeValue(String attributeName){
9494
}
9595
catch(Exception e){
9696
try{
97-
return getAttributeValue2(attributeName);
97+
return getAttributeValue2(tag, attributeName);
9898
}
9999
catch(Exception ex){
100100
return "";
@@ -106,7 +106,7 @@ public String getAttributeValue(String attributeName){
106106

107107

108108

109-
private String getAttributeValue2(String attributeName){
109+
private String getAttributeValue2(String tag, String attributeName){
110110

111111
tag = tag.trim();
112112

src/javaxt/html/Parser.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void setHTML(String html){
3636
//** getAbsolutePath
3737
//**************************************************************************
3838

39-
public String getAbsolutePath(String RelPath, String url){
39+
public static String getAbsolutePath(String RelPath, String url){
4040

4141
//Check whether RelPath is actually relative
4242
try{
@@ -125,7 +125,10 @@ public Element[] getElementsByTagName(String tagName){
125125
Element e = getElementByTagName(tagName);
126126
while (e!=null){
127127
elements.add(e);
128-
html = html.replace(e.outerHTML, "");
128+
int idx = html.indexOf(e.outerHTML);
129+
String a = html.substring(0, idx);
130+
String b = html.substring(idx+e.outerHTML.length());
131+
html = a + b;
129132
e = getElementByTagName(tagName);
130133
}
131134

@@ -147,8 +150,11 @@ public Element[] getElements(String tagName, String attributeName, String attrib
147150
Element e = getElementByAttributes(tagName, attributeName, attributeValue);
148151
while (e!=null){
149152
elements.add(e);
150-
html = html.replace(e.outerHTML, "");
151-
e = getElementByTagName(tagName);
153+
int idx = html.indexOf(e.outerHTML);
154+
String a = html.substring(0, idx);
155+
String b = html.substring(idx+e.outerHTML.length());
156+
html = a + b;
157+
e = getElementByAttributes(tagName, attributeName, attributeValue);
152158
}
153159

154160
html = orgHTML;

src/javaxt/http/Request.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,21 @@ public Request(java.net.URL url, String httpProxy){
146146

147147
private void initHeaders(){
148148
this.setUseCache(false);
149+
this.setHeader("Accept", "*/*");
149150
this.setHeader("Accept-Encoding", "gzip,deflate");
150151
this.setHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
151-
this.setHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.10)");
152+
//this.setHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.10)"); //windows xp
153+
this.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0"); //windows 7
154+
//this.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0"); //windows 8
152155
}
153156

154157

155158
//**************************************************************************
156159
//** getURL
157160
//**************************************************************************
158-
/** Used to return the URL used to instantiate this class.
161+
/** Used to return the URL used to make the request. Note that the URL
162+
* may be different from the URL used to invoke this class if the request
163+
* encounters a redirect. See setNumRedirects() for more information.
159164
*/
160165
public java.net.URL getURL(){
161166
return url;

src/javaxt/http/Response.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public String[] getHeaders(String headerName){
6666
//**************************************************************************
6767
//** getHeader
6868
//**************************************************************************
69-
/** Returns the value of a given key in the HTTP header.
69+
/** Returns the value of a given key in the HTTP header. Returns null if the
70+
* header is not found in the response.
7071
* @param headerName A String specifying the header name (e.g. "Content-Encoding")
7172
*/
7273
public String getHeader(String headerName){

src/javaxt/sql/Function.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package javaxt.sql;
2+
3+
//******************************************************************************
4+
//** Function Class
5+
//******************************************************************************
6+
/**
7+
* Used to encapsulate SQL functions for database inserts and updates. This
8+
* class is used in conjunction with the Recordset class. Example:
9+
* <pre>rs.setValue("LAST_UPDATE", new javaxt.sql.Function("NOW()"));</pre>
10+
*
11+
* Functions can be parameterized for more efficient inserts and updates. This
12+
* is especially important for batch inserts. For example, instead of this:
13+
* <pre>rs.setValue("DATEDIFF_TEST", new javaxt.sql.Function("DATEDIFF(year, '2012/04/28', '2014/04/28')"));</pre>
14+
* The function can be parameterized like this:
15+
* <pre>rs.setValue("DATEDIFF_TEST", new javaxt.sql.Function("DATEDIFF(year, ?, ?)", new Object[]{"2012/04/28", "2014/04/28"}));</pre>
16+
*
17+
******************************************************************************/
18+
19+
public class Function {
20+
21+
private String function;
22+
private Object[] values;
23+
24+
25+
public Function(String function, Object[] values){
26+
this.function = function;
27+
this.values = values;
28+
}
29+
30+
public Function(String function){
31+
this.function = function;
32+
}
33+
34+
public String getFunction(){
35+
return function;
36+
}
37+
38+
public boolean hasValues(){
39+
if (values!=null){
40+
return (values.length>0);
41+
}
42+
return false;
43+
}
44+
45+
public Object[] getValues(){
46+
return values;
47+
}
48+
}

0 commit comments

Comments
 (0)