Skip to content

Commit 4a64f6e

Browse files
committed
Merge pull request littleyoda#1 from rac2030/wip
Added base64 js lib and minimize operation for packaging
2 parents 965f3c5 + 4384ea6 commit 4a64f6e

3 files changed

Lines changed: 171 additions & 1 deletion

File tree

pom.xml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1010
<modelVersion>4.0.0</modelVersion>
1111

12-
<groupId>SeleniumDownloadHelper</groupId>
12+
<groupId>ch.racic.selenium.helper</groupId>
1313
<artifactId>SeleniumDownloadHelper</artifactId>
1414
<version>0.1-SNAPSHOT</version>
15+
<packaging>jar</packaging>
1516

1617
<properties>
1718
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -51,4 +52,20 @@
5152
</dependency>
5253
</dependencies>
5354

55+
<build>
56+
<plugins>
57+
<plugin>
58+
<groupId>net.alchim31.maven</groupId>
59+
<artifactId>yuicompressor-maven-plugin</artifactId>
60+
<executions>
61+
<execution>
62+
<goals>
63+
<goal>compress</goal>
64+
</goals>
65+
</execution>
66+
</executions>
67+
</plugin>
68+
</plugins>
69+
</build>
70+
5471
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyleft (c) 2014. This code is for learning purposes only. Do whatever you like with it but don't take it as perfect code.
3+
* Michel Racic (http://rac.su/+) => github.com/rac2030
4+
*/
5+
6+
package ch.racic.selenium.helper.download;
7+
8+
/**
9+
* Created by rac on 08.06.14.
10+
*/
11+
public class SeleniumDownloadHelper {
12+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
Copyright Vassilis Petroulias [DRDigit]
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
Project info and source @ http://jsbase64.codeplex.com
17+
18+
Usage: B64.encode(PlainString) returns Base64String
19+
B64.decode(Base64String) returns PlainString
20+
*/
21+
var B64 = {
22+
alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
23+
lookup: null,
24+
ie: /MSIE /.test(navigator.userAgent),
25+
ieo: /MSIE [67]/.test(navigator.userAgent),
26+
encode: function (s) {
27+
var buffer = B64.toUtf8(s),
28+
position = -1,
29+
len = buffer.length,
30+
nan0, nan1, nan2, enc = [, , , ];
31+
if (B64.ie) {
32+
var result = [];
33+
while (++position < len) {
34+
nan0 = buffer[position];
35+
nan1 = buffer[++position];
36+
enc[0] = nan0 >> 2;
37+
enc[1] = ((nan0 & 3) << 4) | (nan1 >> 4);
38+
if (isNaN(nan1))
39+
enc[2] = enc[3] = 64;
40+
else {
41+
nan2 = buffer[++position];
42+
enc[2] = ((nan1 & 15) << 2) | (nan2 >> 6);
43+
enc[3] = (isNaN(nan2)) ? 64 : nan2 & 63;
44+
}
45+
result.push(B64.alphabet.charAt(enc[0]), B64.alphabet.charAt(enc[1]), B64.alphabet.charAt(enc[2]), B64.alphabet.charAt(enc[3]));
46+
}
47+
return result.join('');
48+
} else {
49+
var result = '';
50+
while (++position < len) {
51+
nan0 = buffer[position];
52+
nan1 = buffer[++position];
53+
enc[0] = nan0 >> 2;
54+
enc[1] = ((nan0 & 3) << 4) | (nan1 >> 4);
55+
if (isNaN(nan1))
56+
enc[2] = enc[3] = 64;
57+
else {
58+
nan2 = buffer[++position];
59+
enc[2] = ((nan1 & 15) << 2) | (nan2 >> 6);
60+
enc[3] = (isNaN(nan2)) ? 64 : nan2 & 63;
61+
}
62+
result += B64.alphabet[enc[0]] + B64.alphabet[enc[1]] + B64.alphabet[enc[2]] + B64.alphabet[enc[3]];
63+
}
64+
return result;
65+
}
66+
},
67+
decode: function (s) {
68+
if (s.length % 4)
69+
throw new Error("InvalidCharacterError: 'B64.decode' failed: The string to be decoded is not correctly encoded.");
70+
var buffer = B64.fromUtf8(s),
71+
position = 0,
72+
len = buffer.length;
73+
if (B64.ieo) {
74+
var result = [];
75+
while (position < len) {
76+
if (buffer[position] < 128)
77+
result.push(String.fromCharCode(buffer[position++]));
78+
else if (buffer[position] > 191 && buffer[position] < 224)
79+
result.push(String.fromCharCode(((buffer[position++] & 31) << 6) | (buffer[position++] & 63)));
80+
else
81+
result.push(String.fromCharCode(((buffer[position++] & 15) << 12) | ((buffer[position++] & 63) << 6) | (buffer[position++] & 63)));
82+
}
83+
return result.join('');
84+
} else {
85+
var result = '';
86+
while (position < len) {
87+
if (buffer[position] < 128)
88+
result += String.fromCharCode(buffer[position++]);
89+
else if (buffer[position] > 191 && buffer[position] < 224)
90+
result += String.fromCharCode(((buffer[position++] & 31) << 6) | (buffer[position++] & 63));
91+
else
92+
result += String.fromCharCode(((buffer[position++] & 15) << 12) | ((buffer[position++] & 63) << 6) | (buffer[position++] & 63));
93+
}
94+
return result;
95+
}
96+
},
97+
toUtf8: function (s) {
98+
var position = -1,
99+
len = s.length,
100+
chr, buffer = [];
101+
if (/^[\x00-\x7f]*$/.test(s)) while (++position < len)
102+
buffer.push(s.charCodeAt(position));
103+
else while (++position < len) {
104+
chr = s.charCodeAt(position);
105+
if (chr < 128)
106+
buffer.push(chr);
107+
else if (chr < 2048)
108+
buffer.push((chr >> 6) | 192, (chr & 63) | 128);
109+
else
110+
buffer.push((chr >> 12) | 224, ((chr >> 6) & 63) | 128, (chr & 63) | 128);
111+
}
112+
return buffer;
113+
},
114+
fromUtf8: function (s) {
115+
var position = -1,
116+
len, buffer = [],
117+
enc = [, , , ];
118+
if (!B64.lookup) {
119+
len = B64.alphabet.length;
120+
B64.lookup = {};
121+
while (++position < len)
122+
B64.lookup[B64.alphabet.charAt(position)] = position;
123+
position = -1;
124+
}
125+
len = s.length;
126+
while (++position < len) {
127+
enc[0] = B64.lookup[s.charAt(position)];
128+
enc[1] = B64.lookup[s.charAt(++position)];
129+
buffer.push((enc[0] << 2) | (enc[1] >> 4));
130+
enc[2] = B64.lookup[s.charAt(++position)];
131+
if (enc[2] == 64)
132+
break;
133+
buffer.push(((enc[1] & 15) << 4) | (enc[2] >> 2));
134+
enc[3] = B64.lookup[s.charAt(++position)];
135+
if (enc[3] == 64)
136+
break;
137+
buffer.push(((enc[2] & 3) << 6) | enc[3]);
138+
}
139+
return buffer;
140+
}
141+
};

0 commit comments

Comments
 (0)