CFPropertyList 2.0.7
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.
- data/README +34 -0
- data/lib/rbBinaryCFPropertyList.rb +669 -0
- data/lib/rbCFPlistError.rb +19 -0
- data/lib/rbCFPropertyList.rb +316 -0
- data/lib/rbCFTypes.rb +233 -0
- data/lib/rbXMLCFPropertyList.rb +122 -0
- metadata +79 -0
@@ -0,0 +1,122 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# CFPropertyList implementation
|
3
|
+
# parser class to read, manipulate and write XML property list files (plist(5)) as defined by Apple
|
4
|
+
#
|
5
|
+
# Author:: Christian Kruse (mailto:cjk@wwwtech.de)
|
6
|
+
# Copyright:: Copyright (c) 2010
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
8
|
+
|
9
|
+
module CFPropertyList
|
10
|
+
# XML parser
|
11
|
+
class XML < ParserInterface
|
12
|
+
# read a XML file
|
13
|
+
# opts::
|
14
|
+
# * :file - The filename of the file to load
|
15
|
+
# * :data - The data to parse
|
16
|
+
def load(opts)
|
17
|
+
if(opts.has_key?(:file)) then
|
18
|
+
doc = LibXML::XML::Document.file(opts[:file],:options => LibXML::XML::Parser::Options::NOBLANKS|LibXML::XML::Parser::Options::NOENT)
|
19
|
+
else
|
20
|
+
doc = LibXML::XML::Document.string(opts[:data],:options => LibXML::XML::Parser::Options::NOBLANKS|LibXML::XML::Parser::Options::NOENT)
|
21
|
+
end
|
22
|
+
|
23
|
+
root = doc.root.first
|
24
|
+
return import_xml(root)
|
25
|
+
end
|
26
|
+
|
27
|
+
# serialize CFPropertyList object to XML
|
28
|
+
# opts = {}:: Specify options: :formatted - Use indention and line breaks
|
29
|
+
def to_str(opts={})
|
30
|
+
doc = LibXML::XML::Document.new
|
31
|
+
|
32
|
+
doc.root = LibXML::XML::Node.new('plist')
|
33
|
+
doc.encoding = LibXML::XML::Encoding::UTF_8
|
34
|
+
|
35
|
+
doc.root['version'] = '1.0'
|
36
|
+
doc.root << opts[:root].to_xml()
|
37
|
+
|
38
|
+
# ugly hack, but there's no other possibility I know
|
39
|
+
str = doc.to_s(:indent => opts[:formatted])
|
40
|
+
str1 = String.new
|
41
|
+
first = false
|
42
|
+
str.each_line do
|
43
|
+
|line|
|
44
|
+
str1 << line
|
45
|
+
unless(first) then
|
46
|
+
str1 << "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" if line =~ /^\s*<\?xml/
|
47
|
+
end
|
48
|
+
|
49
|
+
first = true
|
50
|
+
end
|
51
|
+
|
52
|
+
return str1
|
53
|
+
end
|
54
|
+
|
55
|
+
protected
|
56
|
+
|
57
|
+
# get the value of a DOM node
|
58
|
+
def get_value(n)
|
59
|
+
return n.first.content if n.children?
|
60
|
+
return n.content
|
61
|
+
end
|
62
|
+
|
63
|
+
# import the XML values
|
64
|
+
def import_xml(node)
|
65
|
+
ret = nil
|
66
|
+
|
67
|
+
case node.name
|
68
|
+
when 'dict'
|
69
|
+
hsh = Hash.new
|
70
|
+
key = nil
|
71
|
+
|
72
|
+
if node.children? then
|
73
|
+
node.children.each do
|
74
|
+
|n|
|
75
|
+
next if n.text? # avoid a bug of libxml
|
76
|
+
|
77
|
+
if n.name == "key" then
|
78
|
+
key = get_value(n)
|
79
|
+
else
|
80
|
+
raise CFFormatError.new("Format error!") if key.nil?
|
81
|
+
hsh[key] = import_xml(n)
|
82
|
+
key = nil
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
ret = CFDictionary.new(hsh)
|
88
|
+
|
89
|
+
when 'array'
|
90
|
+
ary = Array.new
|
91
|
+
|
92
|
+
if node.children? then
|
93
|
+
node.children.each do
|
94
|
+
|n|
|
95
|
+
ary.push import_xml(n)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
ret = CFArray.new(ary)
|
100
|
+
|
101
|
+
when 'true'
|
102
|
+
ret = CFBoolean.new(true)
|
103
|
+
when 'false'
|
104
|
+
ret = CFBoolean.new(false)
|
105
|
+
when 'real'
|
106
|
+
ret = CFReal.new(get_value(node).to_f)
|
107
|
+
when 'integer'
|
108
|
+
ret = CFInteger.new(get_value(node).to_i)
|
109
|
+
when 'string'
|
110
|
+
ret = CFString.new(get_value(node))
|
111
|
+
when 'data'
|
112
|
+
ret = CFData.new(get_value(node))
|
113
|
+
when 'date'
|
114
|
+
ret = CFDate.new(CFDate.parse_date(get_value(node)))
|
115
|
+
end
|
116
|
+
|
117
|
+
return ret
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# eof
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: CFPropertyList
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christian Kruse
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-07-05 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: libxml-ruby
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.1.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.7.0
|
34
|
+
version:
|
35
|
+
description: This is a module to read, write and manipulate both binary and XML property lists as defined by apple.
|
36
|
+
email: cjk@wwwtech.de
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README
|
43
|
+
files:
|
44
|
+
- lib/rbBinaryCFPropertyList.rb
|
45
|
+
- lib/rbCFPlistError.rb
|
46
|
+
- lib/rbCFPropertyList.rb
|
47
|
+
- lib/rbCFTypes.rb
|
48
|
+
- lib/rbXMLCFPropertyList.rb
|
49
|
+
- README
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://github.com/ckruse/CFPropertyList
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project: cfpropertylist
|
74
|
+
rubygems_version: 1.3.5
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Read, write and manipulate both binary and XML property lists as defined by apple
|
78
|
+
test_files: []
|
79
|
+
|