Class: LibXMLJRuby::XML::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/libxml-jruby/xml/parser.rb

Defined Under Namespace

Classes: ParseError

Constant Summary collapse

VERNUM =
0
VERSION =
'0'

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



43
44
45
46
# File 'lib/libxml-jruby/xml/parser.rb', line 43

def initialize
  @source_type = nil
  @parsed = false
end

Class Attribute Details

.check_lib_versionsObject

Returns the value of attribute check_lib_versions.



12
13
14
# File 'lib/libxml-jruby/xml/parser.rb', line 12

def check_lib_versions
  @check_lib_versions
end

.debug_entitiesObject

Returns the value of attribute debug_entities.



12
13
14
# File 'lib/libxml-jruby/xml/parser.rb', line 12

def debug_entities
  @debug_entities
end

.default_compressionObject

Returns the value of attribute default_compression.



12
13
14
# File 'lib/libxml-jruby/xml/parser.rb', line 12

def default_compression
  @default_compression
end

.default_keep_blanksObject

Returns the value of attribute default_keep_blanks.



12
13
14
# File 'lib/libxml-jruby/xml/parser.rb', line 12

def default_keep_blanks
  @default_keep_blanks
end

.default_line_numbersObject

Returns the value of attribute default_line_numbers.



12
13
14
# File 'lib/libxml-jruby/xml/parser.rb', line 12

def default_line_numbers
  @default_line_numbers
end

.default_substitute_entitiesObject

Returns the value of attribute default_substitute_entities.



12
13
14
# File 'lib/libxml-jruby/xml/parser.rb', line 12

def default_substitute_entities
  @default_substitute_entities
end

.default_tree_indent_stringObject

Returns the value of attribute default_tree_indent_string.



12
13
14
# File 'lib/libxml-jruby/xml/parser.rb', line 12

def default_tree_indent_string
  @default_tree_indent_string
end

.default_validity_checkingObject

Returns the value of attribute default_validity_checking.



12
13
14
# File 'lib/libxml-jruby/xml/parser.rb', line 12

def default_validity_checking
  @default_validity_checking
end

.default_warningsObject

Returns the value of attribute default_warnings.



12
13
14
# File 'lib/libxml-jruby/xml/parser.rb', line 12

def default_warnings
  @default_warnings
end

.featuresObject

Returns the value of attribute features.



12
13
14
# File 'lib/libxml-jruby/xml/parser.rb', line 12

def features
  @features
end

.indent_tree_outputObject

Returns the value of attribute indent_tree_output.



12
13
14
# File 'lib/libxml-jruby/xml/parser.rb', line 12

def indent_tree_output
  @indent_tree_output
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



48
49
50
# File 'lib/libxml-jruby/xml/parser.rb', line 48

def filename
  @filename
end

#ioObject

Returns the value of attribute io.



48
49
50
# File 'lib/libxml-jruby/xml/parser.rb', line 48

def io
  @io
end

#stringObject

Returns the value of attribute string.



48
49
50
# File 'lib/libxml-jruby/xml/parser.rb', line 48

def string
  @string
end

Class Method Details

.file(filename) ⇒ Object



24
25
26
27
28
# File 'lib/libxml-jruby/xml/parser.rb', line 24

def file(filename)
  p = new
  p.filename = filename
  p
end

.io(io) ⇒ Object



36
37
38
39
40
# File 'lib/libxml-jruby/xml/parser.rb', line 36

def io(io)
  p = new
  p.io = io
  p
end

.register_error_handler(handler = nil, &block) ⇒ Object



20
21
22
# File 'lib/libxml-jruby/xml/parser.rb', line 20

def register_error_handler(handler = nil, &block)
  
end

.string(string) ⇒ Object



30
31
32
33
34
# File 'lib/libxml-jruby/xml/parser.rb', line 30

def string(string)
  p = new
  p.string = string
  p
end

Instance Method Details

#document_builderObject



80
81
82
83
# File 'lib/libxml-jruby/xml/parser.rb', line 80

def document_builder
  document_builder_factory.namespace_aware = true
  document_builder_factory.new_document_builder
end

#document_builder_factoryObject



76
77
78
# File 'lib/libxml-jruby/xml/parser.rb', line 76

def document_builder_factory
  @dbf ||= DocumentBuilderFactory.new_instance
end

#input_sourceObject



89
90
91
# File 'lib/libxml-jruby/xml/parser.rb', line 89

def input_source
  InputSource.new(string_reader)
end

#parseObject

Raises:



68
69
70
71
72
73
74
# File 'lib/libxml-jruby/xml/parser.rb', line 68

def parse
  raise ParseError, "You cannot parse twice" if @parsed
  raise ParseError, "No input specified, please specify an input" unless @source_type
  doc = send("parse_#{@source_type.to_s.downcase}")
  @parsed = true
  doc
end

#parse_fileObject



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/libxml-jruby/xml/parser.rb', line 106

def parse_file
  builder = document_builder
  
  begin
    jdoc = builder.parse(@filename)
  rescue
    raise ParseError
  end
  
  LibXMLJRuby::XML::Document.from_java(jdoc)
end

#parse_ioObject



118
119
120
# File 'lib/libxml-jruby/xml/parser.rb', line 118

def parse_io
  parse_string
end

#parse_stringObject

Raises:



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/libxml-jruby/xml/parser.rb', line 93

def parse_string
  raise ParseError if @string.empty?
  builder = document_builder
  
  begin
    jdoc = builder.parse(input_source)
  rescue NativeException
    raise ParseError
  end

  LibXMLJRuby::XML::Document.from_java(jdoc)
end

#string_readerObject



85
86
87
# File 'lib/libxml-jruby/xml/parser.rb', line 85

def string_reader
  StringReader.new(@string)
end