blob: 22ed7ccd1d6f9de420d7ef05ee32297f60c4cf53 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#!/usr/bin/ruby -w
require 'rexml/document'
require 'find'
include REXML
def isXml? (filename)
filename =~ /\.xml$/
end
class Documentation
attr_reader :role, :title, :uri
attr_writer :role, :title, :uri
def initialize(role, title, uri)
self.role = role
self.title = title
self.uri = uri
end
end
def findDocumentation(target)
documents = []
Find.find("/home/jnichols/checkouts/gentoo/xml/htdocs") do |filename|
if isXml? filename
file = File.new(filename)
begin
doc = Document.new(file)
root = doc.root
title_text = nil
case doc.doctype.system
when "/dtd/guide.dtd":
title = root.elements['title']
title_text = title.text unless title.nil?
when "/dtd/project.dtd":
longname = root.elements['longname']
title_text = longname.text unless longname.nil?
else next
end
root.elements.each('author') do |author|
role = author.attributes['title']
email = author.elements['mail'].attributes['link']
if email == target
documents.push Documentation.new(role, title_text, filename)
end
end
rescue Exception
# catching all exceptions probably is bad :)
end
end
Find.prune if filename =~ /CVS/
end
return documents
end
|