Browse CVS Repository
Contents of /exerb/exerb-studio/model/project.rb
Parent Directory
| Revision Log
| Revision Graph
Revision 1.3 -
( show annotations)
( download)
Tue Jun 17 04:25:16 2003 UTC
(20 years, 9 months ago)
by yuya
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +19 -0 lines
* XMLの保存処理を試験的に実装
| 1 |
|
| 2 |
module Model |
| 3 |
|
| 4 |
class Project < Base |
| 5 |
|
| 6 |
def initialize |
| 7 |
@name = nil |
| 8 |
@basedir = nil |
| 9 |
@corefile = nil |
| 10 |
@outfile = nil |
| 11 |
@compress = false |
| 12 |
@files = [] |
| 13 |
end |
| 14 |
|
| 15 |
attr_accessor :name, :basedir, :corefile, :outfile, :compress, :files |
| 16 |
|
| 17 |
def self.uconv(node) |
| 18 |
if node.kind_of?(REXML::Element) |
| 19 |
return Uconv.u8tosjis(node.text) |
| 20 |
elsif node.kind_of?(String) |
| 21 |
return Uconv.u8tosjis(node) |
| 22 |
else |
| 23 |
return nil |
| 24 |
end |
| 25 |
end |
| 26 |
|
| 27 |
def self.loadxml(filepath) |
| 28 |
return ::File.open(filepath) { |file| |
| 29 |
self.new_from_xmlnode(REXML::Document.new(file).get_elements('project').first) |
| 30 |
} |
| 31 |
end |
| 32 |
|
| 33 |
def self.new_from_xmlnode(node) |
| 34 |
model = self.new |
| 35 |
model.name = uconv(node.attributes['name']) |
| 36 |
model.corefile = uconv(node.elements['corefile']) |
| 37 |
model.outfile = uconv(node.elements['outfile']) |
| 38 |
model.compress = uconv(node.elements['compress']) |
| 39 |
model.files = Group.new_from_xmlnode(node.elements['files']).files |
| 40 |
|
| 41 |
return model |
| 42 |
end |
| 43 |
|
| 44 |
def create_node(tree, parent) |
| 45 |
@files.each { |file| |
| 46 |
file.create_node(tree, parent) |
| 47 |
} |
| 48 |
end |
| 49 |
|
| 50 |
def savexmlfile(filepath) |
| 51 |
::File.open(filepath, "w") { |file| |
| 52 |
savexml(file) |
| 53 |
} |
| 54 |
end |
| 55 |
|
| 56 |
def savexml(io) |
| 57 |
io.puts(%|<project name="#{@name}">|) |
| 58 |
io.puts(%|<corefile>#{@corefile}</corefile>|) |
| 59 |
io.puts(%|<outfile>#{@outfile}</outfile>|) |
| 60 |
io.puts(%|<compress>#{@compress}</compress>|) |
| 61 |
io.puts(%|<files>|) |
| 62 |
@files.each { |child| |
| 63 |
child.savexml(io) |
| 64 |
} |
| 65 |
io.puts(%|</files>|) |
| 66 |
io.puts(%|</project>|) |
| 67 |
end |
| 68 |
|
| 69 |
end |
| 70 |
|
| 71 |
end |
|