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.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +34 -34
  3. data/app/assets/javascripts/wirispluginengine/WIRISplugins.js +1040 -64
  4. data/app/controllers/wirispluginengine/application_controller.rb +84 -75
  5. data/app/helpers/wirispluginengine/application_helper.rb +4 -4
  6. data/config/routes.rb +4 -4
  7. data/lib/com/wiris/common/WInteger.rb +52 -51
  8. data/lib/com/wiris/plugin/api/Cas.rb +5 -5
  9. data/lib/com/wiris/plugin/api/CleanCache.rb +5 -5
  10. data/lib/com/wiris/plugin/api/Configuration.rb +5 -5
  11. data/lib/com/wiris/plugin/api/ConfigurationKeys.rb +94 -91
  12. data/lib/com/wiris/plugin/api/Editor.rb +5 -5
  13. data/lib/com/wiris/plugin/api/Filter.rb +5 -5
  14. data/lib/com/wiris/plugin/api/ImageFormatController.rb +5 -5
  15. data/lib/com/wiris/plugin/api/ParamsProvider.rb +5 -5
  16. data/lib/com/wiris/plugin/api/PluginBuilder.rb +88 -74
  17. data/lib/com/wiris/plugin/api/Render.rb +5 -5
  18. data/lib/com/wiris/plugin/api/ServiceResourceLoader.rb +5 -5
  19. data/lib/com/wiris/plugin/api/Test.rb +5 -5
  20. data/lib/com/wiris/plugin/api/TextService.rb +5 -5
  21. data/lib/com/wiris/plugin/configuration/ConfigurationUpdater.rb +5 -5
  22. data/lib/com/wiris/plugin/impl/CacheFormulaImpl.rb +15 -0
  23. data/lib/com/wiris/plugin/impl/CacheImpl.rb +124 -0
  24. data/lib/com/wiris/plugin/impl/CasImpl.rb +140 -138
  25. data/lib/com/wiris/plugin/impl/CleanCacheImpl.rb +103 -101
  26. data/lib/com/wiris/plugin/impl/ConfigurationImpl.rb +165 -166
  27. data/lib/com/wiris/plugin/impl/CustomConfigurationUpdater.rb +32 -30
  28. data/lib/com/wiris/plugin/impl/DefaultConfigurationUpdater.rb +24 -22
  29. data/lib/com/wiris/plugin/impl/EditorImpl.rb +80 -78
  30. data/lib/com/wiris/plugin/impl/FileConfigurationUpdater.rb +29 -27
  31. data/lib/com/wiris/plugin/impl/FileStorageAndCache.rb +55 -53
  32. data/lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb +65 -134
  33. data/lib/com/wiris/plugin/impl/GenericParamsProviderImpl.rb +50 -48
  34. data/lib/com/wiris/plugin/impl/HttpImpl.rb +49 -48
  35. data/lib/com/wiris/plugin/impl/HttpListener.rb +5 -5
  36. data/lib/com/wiris/plugin/impl/ImageFormatControllerPng.rb +71 -63
  37. data/lib/com/wiris/plugin/impl/ImageFormatControllerSvg.rb +37 -28
  38. data/lib/com/wiris/plugin/impl/PluginBuilderImpl.rb +280 -248
  39. data/lib/com/wiris/plugin/impl/RenderImpl.rb +303 -257
  40. data/lib/com/wiris/plugin/impl/ServiceResourceLoaderImpl.rb +41 -39
  41. data/lib/com/wiris/plugin/impl/TestImpl.rb +177 -157
  42. data/lib/com/wiris/plugin/impl/TextFilter.rb +210 -194
  43. data/lib/com/wiris/plugin/impl/TextFilterTags.rb +57 -50
  44. data/lib/com/wiris/plugin/impl/TextServiceImpl.rb +158 -107
  45. data/lib/com/wiris/plugin/storage/StorageAndCache.rb +5 -5
  46. data/lib/com/wiris/util/json/JSon.rb +505 -493
  47. data/lib/com/wiris/util/json/JSonIntegerFormat.rb +17 -16
  48. data/lib/com/wiris/util/json/JsonAPIResponse.rb +70 -0
  49. data/lib/com/wiris/util/json/StringParser.rb +57 -56
  50. data/lib/com/wiris/util/sys/AccessProvider.rb +8 -0
  51. data/lib/com/wiris/util/sys/Cache.rb +8 -0
  52. data/lib/com/wiris/util/sys/HttpConnection.rb +14 -13
  53. data/lib/com/wiris/util/sys/HttpConnectionListener.rb +5 -5
  54. data/lib/com/wiris/util/sys/HttpSync.rb +28 -0
  55. data/lib/com/wiris/util/sys/IniFile.rb +132 -131
  56. data/lib/com/wiris/util/sys/Lock.rb +8 -0
  57. data/lib/com/wiris/util/sys/LockProvider.rb +8 -0
  58. data/lib/com/wiris/util/sys/Store.rb +126 -101
  59. data/lib/com/wiris/util/sys/StoreCache.rb +63 -0
  60. data/lib/com/wiris/util/sys/TimerProxy.rb +21 -0
  61. data/lib/com/wiris/util/sys/TimerTask.rb +8 -0
  62. data/lib/com/wiris/util/type/Arrays.rb +275 -0
  63. data/lib/com/wiris/util/type/ByteBuffer.rb +69 -0
  64. data/lib/com/wiris/util/type/Comparator.rb +8 -0
  65. data/lib/com/wiris/util/type/DataUtils.rb +24 -0
  66. data/lib/com/wiris/util/type/DoubleTools.rb +14 -0
  67. data/lib/com/wiris/util/type/HashCache.rb +43 -0
  68. data/lib/com/wiris/util/type/IntegerTools.rb +32 -0
  69. data/lib/com/wiris/util/type/Queue.rb +31 -0
  70. data/lib/com/wiris/util/type/SortArrayByStringLength.rb +26 -0
  71. data/lib/com/wiris/util/type/SortStringByLength.rb +26 -0
  72. data/lib/com/wiris/util/type/SortedHash.rb +45 -0
  73. data/lib/com/wiris/util/type/Stack.rb +31 -0
  74. data/lib/com/wiris/util/type/StringUtils.rb +56 -0
  75. data/lib/com/wiris/util/type/Tokenizer.rb +40 -0
  76. data/lib/com/wiris/util/type/UrlUtils.rb +78 -0
  77. data/lib/com/wiris/util/xml/ContentHandler.rb +8 -0
  78. data/lib/com/wiris/util/xml/DefaultHandler.rb +25 -0
  79. data/lib/com/wiris/util/xml/EntityResolver.rb +8 -0
  80. data/lib/com/wiris/util/xml/MathMLEntityResolver.rb +19 -0
  81. data/lib/com/wiris/util/xml/SAXParser.rb +470 -0
  82. data/lib/com/wiris/util/xml/SerializableImpl.rb +16 -15
  83. data/lib/com/wiris/util/xml/WCharacterBase.rb +968 -627
  84. data/lib/com/wiris/util/xml/WEntities.rb +11 -9
  85. data/lib/com/wiris/util/xml/WXmlUtils.rb +660 -490
  86. data/lib/com/wiris/util/xml/XmlSerializer.rb +517 -471
  87. data/lib/com/wiris/util/xml/XmlWriter.rb +260 -262
  88. data/lib/loader.rb +15 -12
  89. data/lib/src-generic/Array.rb +22 -22
  90. data/lib/src-generic/ArrayInt.rb +31 -31
  91. data/lib/src-generic/Base64.rb +14 -14
  92. data/lib/src-generic/BaseCode.rb +93 -93
  93. data/lib/src-generic/Boolean.rb +27 -0
  94. data/lib/src-generic/Bytes.rb +50 -50
  95. data/lib/src-generic/BytesInput.rb +37 -37
  96. data/lib/src-generic/EReg.rb +55 -55
  97. data/lib/src-generic/File.rb +35 -35
  98. data/lib/src-generic/FileLock.rb +26 -26
  99. data/lib/src-generic/FileSystem.rb +37 -37
  100. data/lib/src-generic/Hash.rb +42 -42
  101. data/lib/src-generic/Http.rb +111 -107
  102. data/lib/src-generic/HttpRequest.rb +25 -25
  103. data/lib/src-generic/HttpResponse.rb +70 -70
  104. data/lib/src-generic/Iterator.rb +20 -19
  105. data/lib/src-generic/Math.rb +14 -14
  106. data/lib/src-generic/Md5.rb +8 -8
  107. data/lib/src-generic/Md5Tools.rb +11 -11
  108. data/lib/src-generic/PropertiesTools.rb +32 -32
  109. data/lib/src-generic/Reflect.rb +16 -16
  110. data/lib/src-generic/RubyConfigurationUpdater.rb +49 -45
  111. data/lib/src-generic/Serializer.rb +84 -84
  112. data/lib/src-generic/Std.rb +74 -74
  113. data/lib/src-generic/Storage.rb +152 -152
  114. data/lib/src-generic/StringBuf.rb +40 -40
  115. data/lib/src-generic/StringTools.rb +44 -46
  116. data/lib/src-generic/Timer.rb +6 -6
  117. data/lib/src-generic/Type.rb +18 -18
  118. data/lib/src-generic/TypeTools.rb +31 -31
  119. data/lib/src-generic/Unserializer.rb +72 -72
  120. data/lib/src-generic/Utf8.rb +26 -26
  121. data/lib/src-generic/Xml.rb +199 -198
  122. data/lib/src-generic/extended/Integer.rb +5 -5
  123. data/lib/src-generic/extended/Math.rb +6 -6
  124. data/lib/src-generic/extended/Properties.rb +11 -11
  125. data/lib/src-generic/extended/String.rb +38 -38
  126. data/lib/src-generic/settings/PlatformSettings.rb +18 -18
  127. data/lib/src-generic/system/HttpProxy.rb +23 -0
  128. data/lib/src-generic/system/HttpProxyAuth.rb +10 -0
  129. data/lib/wirispluginengine.rb +5 -5
  130. data/lib/wirispluginengine/engine.rb +5 -5
  131. data/lib/wirispluginengine/integration/cleancache.rb +8 -8
  132. data/lib/wirispluginengine/integration/configurationjs.rb +8 -15
  133. data/lib/wirispluginengine/integration/configurationjson.rb +6 -6
  134. data/lib/wirispluginengine/integration/createimage.rb +7 -7
  135. data/lib/wirispluginengine/integration/getmathml.rb +18 -18
  136. data/lib/wirispluginengine/integration/resource.rb +8 -8
  137. data/lib/wirispluginengine/integration/service.rb +5 -5
  138. data/lib/wirispluginengine/integration/showimage.rb +28 -21
  139. data/lib/wirispluginengine/integration/test.rb +5 -5
  140. data/lib/wirispluginengine/integration/testfilter.rb +10 -0
  141. data/lib/wirispluginengine/version.rb +2 -2
  142. data/resources/VERSION +1 -1
  143. data/resources/WEB-INF/web.xml +25 -0
  144. data/resources/WIRISplugins.js +3809 -0
  145. data/resources/default-configuration.ini +47 -45
  146. data/resources/tech.txt +1 -1
  147. data/resources/wirisplugin.css +43 -42
  148. metadata +40 -4
  149. data/configuration.ini.dist +0 -104
@@ -1,21 +1,22 @@
1
1
  module WirisPlugin
2
2
  include Wiris
3
- class JSonIntegerFormat
4
- include Wiris
3
+ class JSonIntegerFormat
4
+ include Wiris
5
+
6
+ HEXADECIMAL = 0
7
+ attr_accessor :n
8
+ attr_accessor :format
9
+ def initialize(n, format)
10
+ super()
11
+ self.n = n
12
+ self.format = format
13
+ end
14
+ def toString()
15
+ if @format == HEXADECIMAL
16
+ return "0x" + StringTools::hex(@n,0).to_s
17
+ end
18
+ return "" + @n.to_s
19
+ end
5
20
 
6
- HEXADECIMAL = 0
7
- attr_accessor :n
8
- attr_accessor :format
9
- def initialize(n,format)
10
- super()
11
- @n = n
12
- @format = format
13
- end
14
- def toString()
15
- if @format==HEXADECIMAL
16
- return "0x"+StringTools::hex(@n,0).to_s
17
- end
18
- return ""+@n.to_s
19
21
  end
20
- end
21
22
  end
@@ -0,0 +1,70 @@
1
+ module WirisPlugin
2
+ include Wiris
3
+ require('com/wiris/util/json/JSon.rb')
4
+ class JsonAPIResponse
5
+ include Wiris
6
+
7
+ STATUS_OK = 0
8
+ STATUS_WARNING = 1
9
+ STATUS_ERROR = -1
10
+ def initialize()
11
+ super()
12
+ self.result = Hash.new()
13
+ self.errors = Array.new()
14
+ self.warnings = Array.new()
15
+ end
16
+ attr_accessor :status
17
+ attr_accessor :result
18
+ attr_accessor :errors
19
+ attr_accessor :warnings
20
+ def getResponse()
21
+ response = Hash.new()
22
+ if self.status == STATUS_ERROR
23
+ response::set("errors",self.errors)
24
+ response::set("status","error")
25
+ end
26
+ if self.status == STATUS_WARNING
27
+ response::set("warnings",self.warnings)
28
+ response::set("result",self.result)
29
+ response::set("status","warning")
30
+ end
31
+ if self.status == STATUS_OK
32
+ response::set("result",self.result)
33
+ response::set("status","ok")
34
+ end
35
+ return JSon::encode(response)
36
+ end
37
+ def addResult(key, value)
38
+ self.result::set(key,value)
39
+ end
40
+ def setResult(obj)
41
+ self.result = obj
42
+ end
43
+ def getResult()
44
+ if self.status == STATUS_ERROR
45
+ return nil
46
+ else
47
+ return self.result
48
+ end
49
+ end
50
+ def addWarning(warning)
51
+ self.warnings::push(warning)
52
+ end
53
+ def addError(error)
54
+ self.errors::push(error)
55
+ end
56
+ def setStatus(status)
57
+ if ((status != STATUS_OK) && (status != STATUS_WARNING)) && (status != STATUS_ERROR)
58
+ raise Exception,"Invalid status code"
59
+ end
60
+ self.status = status
61
+ end
62
+ def getStatus()
63
+ return self.status
64
+ end
65
+ def toString()
66
+ return self.getResponse()
67
+ end
68
+
69
+ end
70
+ end
@@ -1,61 +1,62 @@
1
1
  module WirisPlugin
2
2
  include Wiris
3
- require('com/wiris/common/WInteger.rb')
4
- class StringParser
5
- include Wiris
3
+ require('com/wiris/common/WInteger.rb')
4
+ class StringParser
5
+ include Wiris
6
+
7
+ attr_accessor :i
8
+ attr_accessor :n
9
+ attr_accessor :c
10
+ attr_accessor :str
11
+ def initialize()
12
+ super()
13
+ end
14
+ def init(str)
15
+ self.str = str
16
+ @i = 0
17
+ @n = str::length()
18
+ nextToken()
19
+ end
20
+ def skipBlanks()
21
+ while (@i < @n) && StringParser.isBlank(@c)
22
+ nextToken()
23
+ end
24
+ end
25
+ def nextToken()
26
+ if @c == -1
27
+ raise Exception,"End of string"
28
+ end
29
+ nextSafeToken()
30
+ end
31
+ def nextSafeToken()
32
+ if @i < @n
33
+ @c = Utf8::charCodeAt(Std::substr(@str,@i),0)
34
+ @i += (Utf8::uchr(@c))::length()
35
+ else
36
+ @c = -1
37
+ end
38
+ end
39
+ def self.isBlank(c)
40
+ return ((((c == 32) || (c == 10)) || (c == 13)) || (c == 9)) || (c == 160)
41
+ end
42
+ def getPositionRepresentation()
43
+ i0 = WInteger::min(@i,@n)
44
+ s0 = WInteger::max(0,@i - 20)
45
+ e0 = WInteger::min(@n,@i + 20)
46
+ return (("..." + Std::substr(@str,s0,i0 - s0).to_s) + " >>> . <<<") + Std::substr(@str,i0,e0).to_s
47
+ end
48
+ def isHexDigit(c)
49
+ if (c >= 48) && (c <= 58)
50
+ return true
51
+ end
52
+ if (c >= 97) && (c <= 102)
53
+ return true
54
+ end
55
+ if (c >= 65) && (c <= 70)
56
+ return true
57
+ end
58
+ return false
59
+ end
6
60
 
7
- attr_accessor :i
8
- attr_accessor :n
9
- attr_accessor :c
10
- attr_accessor :str
11
- def initialize()
12
- super()
13
- end
14
- def init(str)
15
- @str = str
16
- @i = 0
17
- @n = str::length()
18
- nextToken()
19
- end
20
- def skipBlanks()
21
- while (@i<@n)&&self.class.isBlank(@c)
22
- nextToken()
23
- end
24
- end
25
- def nextToken()
26
- if @c==-1
27
- raise Exception,"End of string"
28
- end
29
- nextSafeToken()
30
- end
31
- def nextSafeToken()
32
- if @i<@n
33
- @c = Utf8::charCodeAt(Std::substr(@str,@i),0)
34
- @i+=(Utf8::uchr(@c))::length()
35
- else
36
- @c = -1
37
- end
38
- end
39
- def self.isBlank(c)
40
- return ((((c==32)||(c==10))||(c==13))||(c==9))||(c==160)
41
- end
42
- def getPositionRepresentation()
43
- i0 = WInteger::min(@i,@n)
44
- s0 = WInteger::max(0,@i-20)
45
- e0 = WInteger::min(@n,@i+20)
46
- return (("..."+Std::substr(@str,s0,i0-s0).to_s)+" >>> . <<<")+Std::substr(@str,i0,e0).to_s
47
- end
48
- def isHexDigit(c)
49
- if (c>=48)&&(c<=58)
50
- return true
51
- end
52
- if (c>=97)&&(c<=102)
53
- return true
54
- end
55
- if (c>=65)&&(c<=70)
56
- return true
57
- end
58
- return false
59
61
  end
60
- end
61
62
  end
@@ -0,0 +1,8 @@
1
+ module WirisPlugin
2
+ include Wiris
3
+ module AccessProviderInterface
4
+ def AccessProvider
5
+ return true
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module WirisPlugin
2
+ include Wiris
3
+ module CacheInterface
4
+ def Cache
5
+ return true
6
+ end
7
+ end
8
+ end
@@ -1,18 +1,19 @@
1
1
  module WirisPlugin
2
2
  include Wiris
3
- class HttpConnection < Http
4
- include Wiris
3
+ class HttpConnection < Http
4
+ include Wiris
5
+
6
+ attr_accessor :listener
7
+ def initialize(url, listener)
8
+ super(url)
9
+ self.listener = listener
10
+ end
11
+ def onData(data)
12
+ self.listener::onHTTPData(data)
13
+ end
14
+ def onError(error)
15
+ self.listener::onHTTPError(error)
16
+ end
5
17
 
6
- attr_accessor :listener
7
- def initialize(url,listener)
8
- super(url)
9
- @listener = listener
10
- end
11
- def onData(data)
12
- listener::onHTTPData(data)
13
- end
14
- def onError(error)
15
- listener::onHTTPError(error)
16
18
  end
17
- end
18
19
  end
@@ -1,8 +1,8 @@
1
1
  module WirisPlugin
2
2
  include Wiris
3
- module HttpConnectionListenerInterface
4
- def HttpConnectionListener
5
- return true
6
- end
7
- end
3
+ module HttpConnectionListenerInterface
4
+ def HttpConnectionListener
5
+ return true
6
+ end
7
+ end
8
8
  end
@@ -0,0 +1,28 @@
1
+ module WirisPlugin
2
+ include Wiris
3
+ class HttpSync < Http
4
+ include Wiris
5
+
6
+ attr_accessor :data
7
+ attr_accessor :errorMessage
8
+ def initialize(url)
9
+ super(url)
10
+ self.async = false
11
+ self.data = nil
12
+ self.errorMessage = nil
13
+ end
14
+ def onData(data)
15
+ self.data = data
16
+ end
17
+ def onError(msg)
18
+ self.errorMessage = msg
19
+ end
20
+ def getData()
21
+ return self.data
22
+ end
23
+ def getError()
24
+ return self.errorMessage
25
+ end
26
+
27
+ end
28
+ end
@@ -1,143 +1,144 @@
1
1
  module WirisPlugin
2
2
  include Wiris
3
- class IniFile
4
- include Wiris
3
+ class IniFile
4
+ include Wiris
5
5
 
6
- attr_accessor :filename
7
- attr_accessor :props
8
- def initialize()
9
- super()
10
- @props = Hash.new()
11
- end
12
- def self.newIniFileFromFilename(path)
13
- ini = IniFile.new()
14
- ini::filename = path
15
- ini::loadINI()
16
- return ini
17
- end
18
- def self.newIniFileFromString(inifile)
19
- ini = IniFile.new()
20
- ini::filename = ""
21
- ini::loadProperties(inifile)
22
- return ini
23
- end
24
- def getProperties()
25
- return @props
26
- end
27
- def loadINI()
28
- s = Storage::newStorage(@filename)
29
- if !s::exists()
30
- s = Storage::newResourceStorage(@filename)
31
- end
32
- begin
33
- file = s::read()
34
- if file!=nil
35
- loadProperties(file)
36
- end
37
- end
38
- end
39
- def loadPropertiesLine(line,count)
40
- line = StringTools::trim(line)
41
- if line::length()==0
42
- return
43
- end
44
- if StringTools::startsWith(line,";")||StringTools::startsWith(line,"#")
45
- return
46
- end
47
- equals = line::indexOf("=")
48
- if equals==-1
49
- raise Exception,((("Malformed INI file "+@filename)+" in line ")+count.to_s)+" no equal sign found."
50
- end
51
- key = Std::substr(line,0,equals)
52
- key = StringTools::trim(key)
53
- value = Std::substr(line,equals+1)
54
- value = StringTools::trim(value)
55
- if StringTools::startsWith(value,"\"")&&StringTools::endsWith(value,"\"")
56
- value = Std::substr(value,1,value::length()-2)
57
- end
58
- backslash = 0
59
- while (backslash = value::indexOf("\\",backslash))!=-1
60
- if value::length()<=(backslash+1)
61
- next
6
+ attr_accessor :filename
7
+ attr_accessor :props
8
+ def initialize()
9
+ super()
10
+ self.props = Hash.new()
11
+ end
12
+ def self.newIniFileFromFilename(path)
13
+ ini = IniFile.new()
14
+ ini::filename = path
15
+ ini::loadINI()
16
+ return ini
17
+ end
18
+ def self.newIniFileFromString(inifile)
19
+ ini = IniFile.new()
20
+ ini::filename = ""
21
+ ini::loadProperties(inifile)
22
+ return ini
62
23
  end
63
- letter = Std::substr(value,backslash+1,1)
64
- if (letter=="n")
65
- letter = "\n"
66
- else
67
- if (letter=="r")
68
- letter = "\r"
69
- else
70
- if (letter=="t")
71
- letter = "\t"
24
+ def getProperties()
25
+ return @props
26
+ end
27
+ def loadINI()
28
+ s = Storage::newStorage(@filename)
29
+ if !s::exists()
30
+ s = Storage::newResourceStorage(@filename)
31
+ end
32
+ begin
33
+ file = s::read()
34
+ if file != nil
35
+ loadProperties(file)
36
+ end
72
37
  end
73
- end
74
38
  end
75
- value = (Std::substr(value,0,backslash).to_s+letter)+Std::substr(value,backslash+2).to_s
76
- backslash+=1
77
- end
78
- props::set(key,value)
79
- end
80
- def loadProperties(file)
81
- _end = 0
82
- count = 1
83
- while (start = file::indexOf("\n",_end))!=-1
84
- line = Std::substr(file,_end,start-_end)
85
- _end = start+1
86
- loadPropertiesLine(line,count)
87
- count+=1
88
- end
89
- if _end<file::length()
90
- line = Std::substr(file,_end)
91
- loadPropertiesLine(line,count)
92
- end
93
- end
94
- def self.propertiesToString(h)
95
- sb = StringBuf.new()
96
- iter = h::keys()
97
- keys = Array.new()
98
- while iter::hasNext()
99
- keys::push(iter::next())
100
- end
101
- n = keys::length()
102
- for i in 0..n-1
103
- for j in i+1..n-1
104
- s1 = keys::_(i)
105
- s2 = keys::_(j)
106
- if compareStrings(s1,s2)>0
107
- keys::_(i,s2)
108
- keys::_(j,s1)
109
- end
110
- j+=1
39
+ def loadPropertiesLine(line, count)
40
+ line = StringTools::trim(line)
41
+ if line::length() == 0
42
+ return
43
+ end
44
+ if StringTools::startsWith(line,";") || StringTools::startsWith(line,"#")
45
+ return
111
46
  end
112
- i+=1
47
+ equals = line::indexOf("=")
48
+ if equals == -1
49
+ raise Exception,((("Malformed INI file " + @filename) + " in line ") + count.to_s) + " no equal sign found."
50
+ end
51
+ key = Std::substr(line,0,equals)
52
+ key = StringTools::trim(key)
53
+ value = Std::substr(line,equals + 1)
54
+ value = StringTools::trim(value)
55
+ if StringTools::startsWith(value,"\"") && StringTools::endsWith(value,"\"")
56
+ value = Std::substr(value,1,value::length() - 2)
57
+ end
58
+ backslash = 0
59
+ while (backslash = value::indexOf("\\",backslash)) != -1
60
+ if value::length() <= (backslash + 1)
61
+ next
62
+ end
63
+ letter = Std::substr(value,backslash + 1,1)
64
+ if (letter == "n")
65
+ letter = "\n"
66
+ else
67
+ if (letter == "r")
68
+ letter = "\r"
69
+ else
70
+ if (letter == "t")
71
+ letter = "\t"
72
+ end
73
+ end
74
+ end
75
+ value = (Std::substr(value,0,backslash).to_s + letter) + Std::substr(value,backslash + 2).to_s
76
+ backslash+=1
77
+ end
78
+ self.props::set(key,value)
113
79
  end
114
- for i in 0..n-1
115
- key = keys::_(i)
116
- sb::add(key)
117
- sb::add("=")
118
- value = h::get(key)
119
- value = StringTools::replace(value,"\\","\\\\")
120
- value = StringTools::replace(value,"\n","\\n")
121
- value = StringTools::replace(value,"\r","\\r")
122
- value = StringTools::replace(value,"\t","\\t")
123
- sb::add(value)
124
- sb::add("\n")
125
- i+=1
80
+ def loadProperties(file)
81
+ _end = 0
82
+ count = 1
83
+ while (start = file::indexOf("\n",_end)) != -1
84
+ line = Std::substr(file,_end,start - _end)
85
+ _end = start + 1
86
+ self.loadPropertiesLine(line,count)
87
+ count+=1
88
+ end
89
+ if _end < file::length()
90
+ line = Std::substr(file,_end)
91
+ self.loadPropertiesLine(line,count)
92
+ end
126
93
  end
127
- return sb::toString()
128
- end
129
- def self.compareStrings(a,b)
130
- an = a::length()
131
- bn = b::length()
132
- n = (an>bn) ? bn : an
133
- for i in 0..n-1
134
- c = Std::charCodeAt(a,i)-Std::charCodeAt(b,i)
135
- if c!=0
136
- return c
137
- end
138
- i+=1
94
+ def self.propertiesToString(h)
95
+ sb = StringBuf.new()
96
+ iter = h::keys()
97
+ keys = Array.new()
98
+ while iter::hasNext()
99
+ keys::push(iter::next())
100
+ end
101
+ n = keys::length()
102
+ for i in 0..n - 1
103
+ for j in i + 1..n - 1
104
+ s1 = keys::_(i)
105
+ s2 = keys::_(j)
106
+ if IniFile.compareStrings(s1,s2) > 0
107
+ keys::_(i,s2)
108
+ keys::_(j,s1)
109
+ end
110
+ j+=1
111
+ end
112
+ i+=1
113
+ end
114
+ for i in 0..n - 1
115
+ key = keys::_(i)
116
+ sb::add(key)
117
+ sb::add("=")
118
+ value = h::get(key)
119
+ value = StringTools::replace(value,"\\","\\\\")
120
+ value = StringTools::replace(value,"\n","\\n")
121
+ value = StringTools::replace(value,"\r","\\r")
122
+ value = StringTools::replace(value,"\t","\\t")
123
+ sb::add(value)
124
+ sb::add("\n")
125
+ i+=1
126
+ end
127
+ return sb::toString()
139
128
  end
140
- return a::length()-b::length()
129
+ def self.compareStrings(a, b)
130
+ an = a::length()
131
+ bn = b::length()
132
+ n = (an > bn) ? bn : an
133
+ for i in 0..n - 1
134
+ c = Std::charCodeAt(a,i) - Std::charCodeAt(b,i)
135
+ if c != 0
136
+ return c
137
+ end
138
+ i+=1
139
+ end
140
+ return a::length() - b::length()
141
+ end
142
+
141
143
  end
142
- end
143
144
  end