wirispluginengine 3.62.0.1322 → 7.14.0.1422
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +34 -34
- data/app/assets/javascripts/wirispluginengine/WIRISplugins.js +1040 -64
- data/app/controllers/wirispluginengine/application_controller.rb +84 -75
- data/app/helpers/wirispluginengine/application_helper.rb +4 -4
- data/config/routes.rb +4 -4
- data/lib/com/wiris/common/WInteger.rb +52 -51
- data/lib/com/wiris/plugin/api/Cas.rb +5 -5
- data/lib/com/wiris/plugin/api/CleanCache.rb +5 -5
- data/lib/com/wiris/plugin/api/Configuration.rb +5 -5
- data/lib/com/wiris/plugin/api/ConfigurationKeys.rb +94 -91
- data/lib/com/wiris/plugin/api/Editor.rb +5 -5
- data/lib/com/wiris/plugin/api/Filter.rb +5 -5
- data/lib/com/wiris/plugin/api/ImageFormatController.rb +5 -5
- data/lib/com/wiris/plugin/api/ParamsProvider.rb +5 -5
- data/lib/com/wiris/plugin/api/PluginBuilder.rb +88 -74
- data/lib/com/wiris/plugin/api/Render.rb +5 -5
- data/lib/com/wiris/plugin/api/ServiceResourceLoader.rb +5 -5
- data/lib/com/wiris/plugin/api/Test.rb +5 -5
- data/lib/com/wiris/plugin/api/TextService.rb +5 -5
- data/lib/com/wiris/plugin/configuration/ConfigurationUpdater.rb +5 -5
- data/lib/com/wiris/plugin/impl/CacheFormulaImpl.rb +15 -0
- data/lib/com/wiris/plugin/impl/CacheImpl.rb +124 -0
- data/lib/com/wiris/plugin/impl/CasImpl.rb +140 -138
- data/lib/com/wiris/plugin/impl/CleanCacheImpl.rb +103 -101
- data/lib/com/wiris/plugin/impl/ConfigurationImpl.rb +165 -166
- data/lib/com/wiris/plugin/impl/CustomConfigurationUpdater.rb +32 -30
- data/lib/com/wiris/plugin/impl/DefaultConfigurationUpdater.rb +24 -22
- data/lib/com/wiris/plugin/impl/EditorImpl.rb +80 -78
- data/lib/com/wiris/plugin/impl/FileConfigurationUpdater.rb +29 -27
- data/lib/com/wiris/plugin/impl/FileStorageAndCache.rb +55 -53
- data/lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb +65 -134
- data/lib/com/wiris/plugin/impl/GenericParamsProviderImpl.rb +50 -48
- data/lib/com/wiris/plugin/impl/HttpImpl.rb +49 -48
- data/lib/com/wiris/plugin/impl/HttpListener.rb +5 -5
- data/lib/com/wiris/plugin/impl/ImageFormatControllerPng.rb +71 -63
- data/lib/com/wiris/plugin/impl/ImageFormatControllerSvg.rb +37 -28
- data/lib/com/wiris/plugin/impl/PluginBuilderImpl.rb +280 -248
- data/lib/com/wiris/plugin/impl/RenderImpl.rb +303 -257
- data/lib/com/wiris/plugin/impl/ServiceResourceLoaderImpl.rb +41 -39
- data/lib/com/wiris/plugin/impl/TestImpl.rb +177 -157
- data/lib/com/wiris/plugin/impl/TextFilter.rb +210 -194
- data/lib/com/wiris/plugin/impl/TextFilterTags.rb +57 -50
- data/lib/com/wiris/plugin/impl/TextServiceImpl.rb +158 -107
- data/lib/com/wiris/plugin/storage/StorageAndCache.rb +5 -5
- data/lib/com/wiris/util/json/JSon.rb +505 -493
- data/lib/com/wiris/util/json/JSonIntegerFormat.rb +17 -16
- data/lib/com/wiris/util/json/JsonAPIResponse.rb +70 -0
- data/lib/com/wiris/util/json/StringParser.rb +57 -56
- data/lib/com/wiris/util/sys/AccessProvider.rb +8 -0
- data/lib/com/wiris/util/sys/Cache.rb +8 -0
- data/lib/com/wiris/util/sys/HttpConnection.rb +14 -13
- data/lib/com/wiris/util/sys/HttpConnectionListener.rb +5 -5
- data/lib/com/wiris/util/sys/HttpSync.rb +28 -0
- data/lib/com/wiris/util/sys/IniFile.rb +132 -131
- data/lib/com/wiris/util/sys/Lock.rb +8 -0
- data/lib/com/wiris/util/sys/LockProvider.rb +8 -0
- data/lib/com/wiris/util/sys/Store.rb +126 -101
- data/lib/com/wiris/util/sys/StoreCache.rb +63 -0
- data/lib/com/wiris/util/sys/TimerProxy.rb +21 -0
- data/lib/com/wiris/util/sys/TimerTask.rb +8 -0
- data/lib/com/wiris/util/type/Arrays.rb +275 -0
- data/lib/com/wiris/util/type/ByteBuffer.rb +69 -0
- data/lib/com/wiris/util/type/Comparator.rb +8 -0
- data/lib/com/wiris/util/type/DataUtils.rb +24 -0
- data/lib/com/wiris/util/type/DoubleTools.rb +14 -0
- data/lib/com/wiris/util/type/HashCache.rb +43 -0
- data/lib/com/wiris/util/type/IntegerTools.rb +32 -0
- data/lib/com/wiris/util/type/Queue.rb +31 -0
- data/lib/com/wiris/util/type/SortArrayByStringLength.rb +26 -0
- data/lib/com/wiris/util/type/SortStringByLength.rb +26 -0
- data/lib/com/wiris/util/type/SortedHash.rb +45 -0
- data/lib/com/wiris/util/type/Stack.rb +31 -0
- data/lib/com/wiris/util/type/StringUtils.rb +56 -0
- data/lib/com/wiris/util/type/Tokenizer.rb +40 -0
- data/lib/com/wiris/util/type/UrlUtils.rb +78 -0
- data/lib/com/wiris/util/xml/ContentHandler.rb +8 -0
- data/lib/com/wiris/util/xml/DefaultHandler.rb +25 -0
- data/lib/com/wiris/util/xml/EntityResolver.rb +8 -0
- data/lib/com/wiris/util/xml/MathMLEntityResolver.rb +19 -0
- data/lib/com/wiris/util/xml/SAXParser.rb +470 -0
- data/lib/com/wiris/util/xml/SerializableImpl.rb +16 -15
- data/lib/com/wiris/util/xml/WCharacterBase.rb +968 -627
- data/lib/com/wiris/util/xml/WEntities.rb +11 -9
- data/lib/com/wiris/util/xml/WXmlUtils.rb +660 -490
- data/lib/com/wiris/util/xml/XmlSerializer.rb +517 -471
- data/lib/com/wiris/util/xml/XmlWriter.rb +260 -262
- data/lib/loader.rb +15 -12
- data/lib/src-generic/Array.rb +22 -22
- data/lib/src-generic/ArrayInt.rb +31 -31
- data/lib/src-generic/Base64.rb +14 -14
- data/lib/src-generic/BaseCode.rb +93 -93
- data/lib/src-generic/Boolean.rb +27 -0
- data/lib/src-generic/Bytes.rb +50 -50
- data/lib/src-generic/BytesInput.rb +37 -37
- data/lib/src-generic/EReg.rb +55 -55
- data/lib/src-generic/File.rb +35 -35
- data/lib/src-generic/FileLock.rb +26 -26
- data/lib/src-generic/FileSystem.rb +37 -37
- data/lib/src-generic/Hash.rb +42 -42
- data/lib/src-generic/Http.rb +111 -107
- data/lib/src-generic/HttpRequest.rb +25 -25
- data/lib/src-generic/HttpResponse.rb +70 -70
- data/lib/src-generic/Iterator.rb +20 -19
- data/lib/src-generic/Math.rb +14 -14
- data/lib/src-generic/Md5.rb +8 -8
- data/lib/src-generic/Md5Tools.rb +11 -11
- data/lib/src-generic/PropertiesTools.rb +32 -32
- data/lib/src-generic/Reflect.rb +16 -16
- data/lib/src-generic/RubyConfigurationUpdater.rb +49 -45
- data/lib/src-generic/Serializer.rb +84 -84
- data/lib/src-generic/Std.rb +74 -74
- data/lib/src-generic/Storage.rb +152 -152
- data/lib/src-generic/StringBuf.rb +40 -40
- data/lib/src-generic/StringTools.rb +44 -46
- data/lib/src-generic/Timer.rb +6 -6
- data/lib/src-generic/Type.rb +18 -18
- data/lib/src-generic/TypeTools.rb +31 -31
- data/lib/src-generic/Unserializer.rb +72 -72
- data/lib/src-generic/Utf8.rb +26 -26
- data/lib/src-generic/Xml.rb +199 -198
- data/lib/src-generic/extended/Integer.rb +5 -5
- data/lib/src-generic/extended/Math.rb +6 -6
- data/lib/src-generic/extended/Properties.rb +11 -11
- data/lib/src-generic/extended/String.rb +38 -38
- data/lib/src-generic/settings/PlatformSettings.rb +18 -18
- data/lib/src-generic/system/HttpProxy.rb +23 -0
- data/lib/src-generic/system/HttpProxyAuth.rb +10 -0
- data/lib/wirispluginengine.rb +5 -5
- data/lib/wirispluginengine/engine.rb +5 -5
- data/lib/wirispluginengine/integration/cleancache.rb +8 -8
- data/lib/wirispluginengine/integration/configurationjs.rb +8 -15
- data/lib/wirispluginengine/integration/configurationjson.rb +6 -6
- data/lib/wirispluginengine/integration/createimage.rb +7 -7
- data/lib/wirispluginengine/integration/getmathml.rb +18 -18
- data/lib/wirispluginengine/integration/resource.rb +8 -8
- data/lib/wirispluginengine/integration/service.rb +5 -5
- data/lib/wirispluginengine/integration/showimage.rb +28 -21
- data/lib/wirispluginengine/integration/test.rb +5 -5
- data/lib/wirispluginengine/integration/testfilter.rb +10 -0
- data/lib/wirispluginengine/version.rb +2 -2
- data/resources/VERSION +1 -1
- data/resources/WEB-INF/web.xml +25 -0
- data/resources/WIRISplugins.js +3809 -0
- data/resources/default-configuration.ini +47 -45
- data/resources/tech.txt +1 -1
- data/resources/wirisplugin.css +43 -42
- metadata +40 -4
- data/configuration.ini.dist +0 -104
@@ -0,0 +1,78 @@
|
|
1
|
+
module WirisPlugin
|
2
|
+
include Wiris
|
3
|
+
class UrlUtils
|
4
|
+
include Wiris
|
5
|
+
|
6
|
+
def initialize()
|
7
|
+
super()
|
8
|
+
end
|
9
|
+
@@charCodeA;
|
10
|
+
def self.charCodeA
|
11
|
+
@@charCodeA
|
12
|
+
end
|
13
|
+
def self.charCodeA=(charCodeA)
|
14
|
+
@@charCodeA = charCodeA
|
15
|
+
end
|
16
|
+
@@charCodeZ;
|
17
|
+
def self.charCodeZ
|
18
|
+
@@charCodeZ
|
19
|
+
end
|
20
|
+
def self.charCodeZ=(charCodeZ)
|
21
|
+
@@charCodeZ = charCodeZ
|
22
|
+
end
|
23
|
+
@@charCodea;
|
24
|
+
def self.charCodea
|
25
|
+
@@charCodea
|
26
|
+
end
|
27
|
+
def self.charCodea=(charCodea)
|
28
|
+
@@charCodea = charCodea
|
29
|
+
end
|
30
|
+
@@charCodez;
|
31
|
+
def self.charCodez
|
32
|
+
@@charCodez
|
33
|
+
end
|
34
|
+
def self.charCodez=(charCodez)
|
35
|
+
@@charCodez = charCodez
|
36
|
+
end
|
37
|
+
@@charCode0;
|
38
|
+
def self.charCode0
|
39
|
+
@@charCode0
|
40
|
+
end
|
41
|
+
def self.charCode0=(charCode0)
|
42
|
+
@@charCode0 = charCode0
|
43
|
+
end
|
44
|
+
@@charCode9;
|
45
|
+
def self.charCode9
|
46
|
+
@@charCode9
|
47
|
+
end
|
48
|
+
def self.charCode9=(charCode9)
|
49
|
+
@@charCode9 = charCode9
|
50
|
+
end
|
51
|
+
def self.isAllowed(c)
|
52
|
+
allowedChars = "-_.!~*\'()"::indexOf(Std::fromCharCode(c)) != -1
|
53
|
+
return ((((c >= @@charCodeA) && (c <= @@charCodeZ)) || ((c >= @@charCodea) && (c <= @@charCodez))) || ((c >= @@charCode0) && (c <= @@charCode9))) || allowedChars
|
54
|
+
end
|
55
|
+
def self.urlComponentEncode(uriComponent)
|
56
|
+
sb = StringBuf.new()
|
57
|
+
buf = Bytes::ofData(Utf8::toBytes(uriComponent))
|
58
|
+
for i in 0..buf::length() - 1
|
59
|
+
b = buf::get(i)&255
|
60
|
+
if UrlUtils.isAllowed(b)
|
61
|
+
sb::add(Std::fromCharCode(b))
|
62
|
+
else
|
63
|
+
sb::add("%")
|
64
|
+
sb::add(StringTools::hex(b,2))
|
65
|
+
end
|
66
|
+
i+=1
|
67
|
+
end
|
68
|
+
return sb::toString()
|
69
|
+
end
|
70
|
+
|
71
|
+
@@charCodeA = Std::charCodeAt("A",0)
|
72
|
+
@@charCodeZ = Std::charCodeAt("Z",0)
|
73
|
+
@@charCodea = Std::charCodeAt("a",0)
|
74
|
+
@@charCodez = Std::charCodeAt("z",0)
|
75
|
+
@@charCode0 = Std::charCodeAt("0",0)
|
76
|
+
@@charCode9 = Std::charCodeAt("9",0)
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module WirisPlugin
|
2
|
+
include Wiris
|
3
|
+
require('com/wiris/util/xml/ContentHandler.rb')
|
4
|
+
require('com/wiris/util/xml/ContentHandler.rb')
|
5
|
+
class DefaultHandler
|
6
|
+
extend ContentHandlerInterface
|
7
|
+
|
8
|
+
include Wiris
|
9
|
+
|
10
|
+
def initialize()
|
11
|
+
super()
|
12
|
+
end
|
13
|
+
def startElement(uri, localName, qName, atts)
|
14
|
+
end
|
15
|
+
def endElement(uri, localName, qName)
|
16
|
+
end
|
17
|
+
def characters(ch)
|
18
|
+
end
|
19
|
+
def startDocument()
|
20
|
+
end
|
21
|
+
def endDocument()
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module WirisPlugin
|
2
|
+
include Wiris
|
3
|
+
require('com/wiris/util/xml/EntityResolver.rb')
|
4
|
+
require('com/wiris/util/xml/WXmlUtils.rb')
|
5
|
+
require('com/wiris/util/xml/EntityResolver.rb')
|
6
|
+
class MathMLEntityResolver
|
7
|
+
extend EntityResolverInterface
|
8
|
+
|
9
|
+
include Wiris
|
10
|
+
|
11
|
+
def initialize()
|
12
|
+
super()
|
13
|
+
end
|
14
|
+
def resolveEntity(name)
|
15
|
+
return WXmlUtils::resolveMathMLEntity(name)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,470 @@
|
|
1
|
+
module WirisPlugin
|
2
|
+
include Wiris
|
3
|
+
require('com/wiris/util/xml/WCharacterBase.rb')
|
4
|
+
class SAXParser
|
5
|
+
include Wiris
|
6
|
+
|
7
|
+
CHAR_HASH = 35
|
8
|
+
CHAR_AT = 64
|
9
|
+
CHAR_OPEN_BRACKET = 123
|
10
|
+
CHAR_CLOSE_BRACKET = 125
|
11
|
+
CHAR_LINE_FEED = 10
|
12
|
+
CHAR_CARRIAGE_RETURN = 13
|
13
|
+
CHAR_SPACE = 32
|
14
|
+
CHAR_TAB = 9
|
15
|
+
CHAR_BACKSLASH = 92
|
16
|
+
CHAR_DOUBLE_QUOT = 34
|
17
|
+
CHAR_DOT = 46
|
18
|
+
CHAR_LESS_THAN = 60
|
19
|
+
CHAR_GREATER_THAN = 62
|
20
|
+
CHAR_BAR = 47
|
21
|
+
CHAR_EXCLAMATION = 33
|
22
|
+
CHAR_INTERROGATION = 63
|
23
|
+
CHAR_QUOT = 39
|
24
|
+
CHAR_OPEN_SQUARE_BRACKET = 91
|
25
|
+
CHAR_HYPHEN = 45
|
26
|
+
CHAR_UNDERSCORE = 95
|
27
|
+
CHAR_COLON = 58
|
28
|
+
CHAR_X = 120
|
29
|
+
CHAR_AMPERSAND = 38
|
30
|
+
CHAR_SEMICOLON = 59
|
31
|
+
BEGIN = 0
|
32
|
+
BEGIN_NODE = 1
|
33
|
+
TAG_NAME = 2
|
34
|
+
ATTRIB = 3
|
35
|
+
BODY = 4
|
36
|
+
HEADER = 5
|
37
|
+
COMMENT = 6
|
38
|
+
IGNORE_SPACES = 7
|
39
|
+
CHILDS = 8
|
40
|
+
TAG_NAME_CLOSE = 9
|
41
|
+
CDATA = 10
|
42
|
+
attr_accessor :lineNumber
|
43
|
+
attr_accessor :columnNumber
|
44
|
+
attr_accessor :entityResolvers
|
45
|
+
MALFORMED_XML = "Error: Malformed xml file."
|
46
|
+
attr_accessor :index
|
47
|
+
attr_accessor :current
|
48
|
+
attr_accessor :last
|
49
|
+
attr_accessor :xml
|
50
|
+
attr_accessor :iterator
|
51
|
+
def initialize()
|
52
|
+
super()
|
53
|
+
@lineNumber = -1
|
54
|
+
@columnNumber = -1
|
55
|
+
@entityResolvers = Array.new()
|
56
|
+
end
|
57
|
+
def getLineNumber()
|
58
|
+
return @lineNumber
|
59
|
+
end
|
60
|
+
def getColumnNumber()
|
61
|
+
return @columnNumber
|
62
|
+
end
|
63
|
+
def addEntityResolver(e)
|
64
|
+
@entityResolvers::push(e)
|
65
|
+
end
|
66
|
+
def parse(source, c)
|
67
|
+
if source::length() > 0
|
68
|
+
@lineNumber = 1
|
69
|
+
@columnNumber = 0
|
70
|
+
end
|
71
|
+
self.xml = source
|
72
|
+
@iterator = Utf8::getIterator(self.xml)
|
73
|
+
c::startDocument()
|
74
|
+
state = IGNORE_SPACES
|
75
|
+
nextState = BEGIN
|
76
|
+
names = Array.new()
|
77
|
+
attribs = Attributes.new()
|
78
|
+
self.index = 0
|
79
|
+
lastIndex = 0
|
80
|
+
characters = StringBuf.new()
|
81
|
+
nextChar()
|
82
|
+
while self.current != -1
|
83
|
+
if state == BEGIN
|
84
|
+
if self.current == CHAR_LESS_THAN
|
85
|
+
state = BEGIN_NODE
|
86
|
+
nextState = BEGIN
|
87
|
+
else
|
88
|
+
raise Exception,MALFORMED_XML
|
89
|
+
end
|
90
|
+
else
|
91
|
+
if state == BEGIN_NODE
|
92
|
+
if self.current == CHAR_EXCLAMATION
|
93
|
+
nextChar()
|
94
|
+
if self.current == CHAR_HYPHEN
|
95
|
+
nextChar()
|
96
|
+
if self.current == CHAR_HYPHEN
|
97
|
+
state = COMMENT
|
98
|
+
next
|
99
|
+
else
|
100
|
+
raise Exception,MALFORMED_XML
|
101
|
+
end
|
102
|
+
else
|
103
|
+
if self.current == CHAR_OPEN_SQUARE_BRACKET
|
104
|
+
if self.searchString("CDATA[")
|
105
|
+
state = CDATA
|
106
|
+
else
|
107
|
+
raise Exception,MALFORMED_XML
|
108
|
+
end
|
109
|
+
else
|
110
|
+
raise Exception,MALFORMED_XML
|
111
|
+
end
|
112
|
+
end
|
113
|
+
else
|
114
|
+
ch = characters::toString()
|
115
|
+
if !(ch == "")
|
116
|
+
@columnNumber -= 2
|
117
|
+
c::characters(ch)
|
118
|
+
@columnNumber += 2
|
119
|
+
end
|
120
|
+
characters = StringBuf.new()
|
121
|
+
if self.current == CHAR_INTERROGATION
|
122
|
+
state = HEADER
|
123
|
+
else
|
124
|
+
if self.current == CHAR_BAR
|
125
|
+
state = TAG_NAME_CLOSE
|
126
|
+
else
|
127
|
+
if SAXParser.isValidInitCharacter(self.current)
|
128
|
+
state = TAG_NAME
|
129
|
+
next
|
130
|
+
else
|
131
|
+
raise Exception,MALFORMED_XML
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
else
|
137
|
+
if state == TAG_NAME
|
138
|
+
sb = StringBuf.new()
|
139
|
+
while SAXParser.isValidCharacter(self.current)
|
140
|
+
sb::addChar(self.current)
|
141
|
+
nextChar()
|
142
|
+
end
|
143
|
+
tagName = sb::toString()
|
144
|
+
names::push(tagName)
|
145
|
+
if self.currentIsBlank()
|
146
|
+
state = IGNORE_SPACES
|
147
|
+
nextState = BODY
|
148
|
+
else
|
149
|
+
if self.current == CHAR_BAR
|
150
|
+
state = BODY
|
151
|
+
next
|
152
|
+
else
|
153
|
+
if self.current == CHAR_GREATER_THAN
|
154
|
+
c::startElement("","",tagName,Attributes.new())
|
155
|
+
state = CHILDS
|
156
|
+
else
|
157
|
+
raise Exception,MALFORMED_XML
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
else
|
162
|
+
if state == TAG_NAME_CLOSE
|
163
|
+
sb = StringBuf.new()
|
164
|
+
while SAXParser.isValidCharacter(self.current)
|
165
|
+
sb::addChar(self.current)
|
166
|
+
nextChar()
|
167
|
+
end
|
168
|
+
tagName = sb::toString()
|
169
|
+
self.ignoreSpaces()
|
170
|
+
name = names::_(names::length() - 1)
|
171
|
+
if (self.current == CHAR_GREATER_THAN) && (tagName == name)
|
172
|
+
names::pop()
|
173
|
+
c::endElement("","",tagName)
|
174
|
+
state = CHILDS
|
175
|
+
else
|
176
|
+
raise Exception,("Expected </" + tagName) + ">"
|
177
|
+
end
|
178
|
+
else
|
179
|
+
if state == IGNORE_SPACES
|
180
|
+
if !self.currentIsBlank()
|
181
|
+
state = nextState
|
182
|
+
next
|
183
|
+
end
|
184
|
+
else
|
185
|
+
if state == COMMENT
|
186
|
+
if self.searchString("-->")
|
187
|
+
state = nextState
|
188
|
+
else
|
189
|
+
raise Exception,"Comment not closed."
|
190
|
+
end
|
191
|
+
else
|
192
|
+
if state == BODY
|
193
|
+
if self.current == CHAR_BAR
|
194
|
+
nextChar()
|
195
|
+
if self.current == CHAR_GREATER_THAN
|
196
|
+
tagName = names::pop()
|
197
|
+
c::startElement("","",tagName,attribs)
|
198
|
+
attribs = Attributes.new()
|
199
|
+
c::endElement("","",tagName)
|
200
|
+
state = CHILDS
|
201
|
+
else
|
202
|
+
raise Exception,MALFORMED_XML
|
203
|
+
end
|
204
|
+
else
|
205
|
+
if self.current == CHAR_GREATER_THAN
|
206
|
+
c::startElement("","",names::_(names::length() - 1),attribs)
|
207
|
+
attribs = Attributes.new()
|
208
|
+
state = CHILDS
|
209
|
+
else
|
210
|
+
if SAXParser.isValidInitCharacter(self.current)
|
211
|
+
state = ATTRIB
|
212
|
+
next
|
213
|
+
else
|
214
|
+
raise Exception,MALFORMED_XML
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
else
|
219
|
+
if state == HEADER
|
220
|
+
if self.searchString("?>")
|
221
|
+
state = IGNORE_SPACES
|
222
|
+
nextState = BEGIN
|
223
|
+
else
|
224
|
+
raise Exception,MALFORMED_XML
|
225
|
+
end
|
226
|
+
else
|
227
|
+
if state == ATTRIB
|
228
|
+
if self.searchString("=")
|
229
|
+
attribName = Std::substr(self.xml,lastIndex,(self.index - lastIndex) - 1)
|
230
|
+
nextChar()
|
231
|
+
ignoreSpaces()
|
232
|
+
lastIndex = self.index
|
233
|
+
if self.current == CHAR_DOUBLE_QUOT
|
234
|
+
nextChar()
|
235
|
+
if !self.searchString("\"")
|
236
|
+
raise Exception,MALFORMED_XML
|
237
|
+
end
|
238
|
+
else
|
239
|
+
if self.current == CHAR_QUOT
|
240
|
+
nextChar()
|
241
|
+
if !self.searchString("\'")
|
242
|
+
raise Exception,MALFORMED_XML
|
243
|
+
end
|
244
|
+
else
|
245
|
+
raise Exception,MALFORMED_XML
|
246
|
+
end
|
247
|
+
end
|
248
|
+
value = Std::substr(self.xml,lastIndex,(self.index - lastIndex) - 1)
|
249
|
+
value = SAXParser.formatLineEnds(value)
|
250
|
+
if attribs::getValueFromName(attribName) != nil
|
251
|
+
raise Exception,("Attribute " + attribName) + " already used in this tag."
|
252
|
+
else
|
253
|
+
attribs::add(attribName,parseEntities(value))
|
254
|
+
end
|
255
|
+
else
|
256
|
+
raise Exception,MALFORMED_XML
|
257
|
+
end
|
258
|
+
state = IGNORE_SPACES
|
259
|
+
nextState = BODY
|
260
|
+
else
|
261
|
+
if state == CHILDS
|
262
|
+
if self.searchString("<")
|
263
|
+
pcdata = Std::substr(self.xml,lastIndex,(self.index - lastIndex) - 1)
|
264
|
+
parsedPCData = parseEntities(pcdata)
|
265
|
+
parsedPCData = SAXParser.formatLineEnds(parsedPCData)
|
266
|
+
characters::add(parsedPCData)
|
267
|
+
state = BEGIN_NODE
|
268
|
+
nextState = CHILDS
|
269
|
+
else
|
270
|
+
if self.current != -1
|
271
|
+
raise Exception,MALFORMED_XML
|
272
|
+
end
|
273
|
+
end
|
274
|
+
else
|
275
|
+
if state == CDATA
|
276
|
+
if self.searchString("]]>")
|
277
|
+
cdata = Std::substr(self.xml,lastIndex,(self.index - lastIndex) - 3)
|
278
|
+
cdata = SAXParser.formatLineEnds(cdata)
|
279
|
+
characters::add(cdata)
|
280
|
+
state = CHILDS
|
281
|
+
nextState = BEGIN
|
282
|
+
else
|
283
|
+
raise Exception,MALFORMED_XML
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
296
|
+
lastIndex = self.index
|
297
|
+
nextChar()
|
298
|
+
end
|
299
|
+
remainder = characters::toString()
|
300
|
+
if !(remainder == "")
|
301
|
+
c::characters(remainder)
|
302
|
+
end
|
303
|
+
if names::length() > 0
|
304
|
+
raise Exception,MALFORMED_XML
|
305
|
+
end
|
306
|
+
c::endDocument()
|
307
|
+
end
|
308
|
+
def self.isValidInitCharacter(c)
|
309
|
+
return ((WCharacterBase::isLetter(c) || (c == CHAR_UNDERSCORE)) || (c == CHAR_COLON))
|
310
|
+
end
|
311
|
+
def self.isValidCharacter(c)
|
312
|
+
return (((((WCharacterBase::isLetter(c) || WCharacterBase::isDigit(c)) || (c == CHAR_UNDERSCORE)) || (c == CHAR_HYPHEN)) || (c == CHAR_DOT)) || (c == CHAR_COLON))
|
313
|
+
end
|
314
|
+
def parseEntities(pcdata)
|
315
|
+
if (pcdata == nil) || (pcdata == "")
|
316
|
+
return ""
|
317
|
+
end
|
318
|
+
in1 = pcdata::indexOf("&")
|
319
|
+
if in1 == -1
|
320
|
+
return pcdata
|
321
|
+
end
|
322
|
+
in2 = pcdata::indexOf(";",in1)
|
323
|
+
parsed = StringBuf.new()
|
324
|
+
parsed::add(Std::substr(pcdata,0,in1))
|
325
|
+
while ((in2 != -1) && (in1 < pcdata::length())) && (in2 < pcdata::length())
|
326
|
+
in1+=1
|
327
|
+
entity = Std::substr(pcdata,in1,in2 - in1)
|
328
|
+
in2+=1
|
329
|
+
if (entity == "quot")
|
330
|
+
parsed::add("\"")
|
331
|
+
else
|
332
|
+
if (entity == "lt")
|
333
|
+
parsed::add("<")
|
334
|
+
else
|
335
|
+
if (entity == "gt")
|
336
|
+
parsed::add(">")
|
337
|
+
else
|
338
|
+
if (entity == "apos")
|
339
|
+
parsed::add("\'")
|
340
|
+
else
|
341
|
+
if (entity == "amp")
|
342
|
+
parsed::add("&")
|
343
|
+
else
|
344
|
+
if Std::charCodeAt(entity,0) == CHAR_HASH
|
345
|
+
utfvalue = 0
|
346
|
+
if Std::charCodeAt(entity,1) == CHAR_X
|
347
|
+
value = Std::substr(entity,2)
|
348
|
+
utfvalue = Std::parseInt("0x" + value)
|
349
|
+
else
|
350
|
+
value = Std::substr(entity,1)
|
351
|
+
utfvalue = Std::parseInt(value)
|
352
|
+
end
|
353
|
+
if utfvalue == 0
|
354
|
+
raise Exception,"Invalid numeric entity."
|
355
|
+
end
|
356
|
+
newvalue = Utf8::uchr(utfvalue)
|
357
|
+
parsed::add(newvalue)
|
358
|
+
else
|
359
|
+
r = 0
|
360
|
+
sol = -1
|
361
|
+
while (r < @entityResolvers::length()) && (sol == -1)
|
362
|
+
sol = @entityResolvers::_(r)::resolveEntity(entity)
|
363
|
+
r+=1
|
364
|
+
end
|
365
|
+
if sol != -1
|
366
|
+
parsed::add(Utf8::uchr(sol))
|
367
|
+
else
|
368
|
+
parsed::add(("&" + entity) + ";")
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|
372
|
+
end
|
373
|
+
end
|
374
|
+
end
|
375
|
+
end
|
376
|
+
in1 = pcdata::indexOf('&',in2)
|
377
|
+
if in1 == -1
|
378
|
+
parsed::add(Std::substr(pcdata,in2))
|
379
|
+
in2 = pcdata::length()
|
380
|
+
else
|
381
|
+
parsed::add(Std::substr(pcdata,in2,in1 - in2))
|
382
|
+
in2 = pcdata::indexOf(';',in1)
|
383
|
+
end
|
384
|
+
end
|
385
|
+
return parsed::toString()
|
386
|
+
end
|
387
|
+
def nextChar()
|
388
|
+
if self.iterator::hasNext()
|
389
|
+
self.last = self.current
|
390
|
+
self.current = self.iterator::next()
|
391
|
+
self.index += (Utf8::uchr(self.current))::length()
|
392
|
+
if (self.last == CHAR_LINE_FEED) || ((self.last == CHAR_CARRIAGE_RETURN) && (self.current != CHAR_LINE_FEED))
|
393
|
+
self.columnNumber = 1
|
394
|
+
self.lineNumber+=1
|
395
|
+
else
|
396
|
+
self.columnNumber+=1
|
397
|
+
end
|
398
|
+
else
|
399
|
+
self.current = -1
|
400
|
+
end
|
401
|
+
end
|
402
|
+
def searchString(search)
|
403
|
+
n = search::length()
|
404
|
+
if n == 0
|
405
|
+
return true
|
406
|
+
end
|
407
|
+
i = 0
|
408
|
+
while self.current != -1
|
409
|
+
if self.current == Utf8::charCodeAt(search,i)
|
410
|
+
i+=1
|
411
|
+
if i == n
|
412
|
+
return true
|
413
|
+
end
|
414
|
+
else
|
415
|
+
while i > 0
|
416
|
+
if self.current == Utf8::charCodeAt(search,i - 1)
|
417
|
+
j = i - 1
|
418
|
+
while j > 1
|
419
|
+
if Utf8::charCodeAt(search,j) != Utf8::charCodeAt(search,j - 1)
|
420
|
+
i-=1
|
421
|
+
break
|
422
|
+
end
|
423
|
+
j-=1
|
424
|
+
end
|
425
|
+
break
|
426
|
+
else
|
427
|
+
i-=1
|
428
|
+
end
|
429
|
+
end
|
430
|
+
end
|
431
|
+
nextChar()
|
432
|
+
end
|
433
|
+
return false
|
434
|
+
end
|
435
|
+
def self.formatLineEnds(data)
|
436
|
+
if (data == "")
|
437
|
+
return data
|
438
|
+
end
|
439
|
+
sb = StringBuf.new()
|
440
|
+
it = Utf8::getIterator(data)
|
441
|
+
carriageReturn = false
|
442
|
+
while it::hasNext()
|
443
|
+
c = it::next()
|
444
|
+
if c == CHAR_CARRIAGE_RETURN
|
445
|
+
carriageReturn = true
|
446
|
+
sb::addChar(CHAR_LINE_FEED)
|
447
|
+
else
|
448
|
+
if carriageReturn
|
449
|
+
carriageReturn = false
|
450
|
+
if c != CHAR_LINE_FEED
|
451
|
+
sb::addChar(c)
|
452
|
+
end
|
453
|
+
else
|
454
|
+
sb::addChar(c)
|
455
|
+
end
|
456
|
+
end
|
457
|
+
end
|
458
|
+
return sb::toString()
|
459
|
+
end
|
460
|
+
def currentIsBlank()
|
461
|
+
return ((((self.current == CHAR_SPACE) || (self.current == CHAR_LINE_FEED)) || (self.current == CHAR_CARRIAGE_RETURN)) || (self.current == CHAR_TAB))
|
462
|
+
end
|
463
|
+
def ignoreSpaces()
|
464
|
+
while self.currentIsBlank()
|
465
|
+
nextChar()
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
469
|
+
end
|
470
|
+
end
|