class LANSA::XML::Splitter

Attributes

depth[R]

Public Class Methods

new(interceptor) click to toggle source
# File xml/splitter.rb, line 13
def initialize interceptor

  @interceptor = interceptor
  @output = nil
  @xmldecl = nil
  @depth = 0

  @split_element = SimpleElement.new

  @intercept_start_method = get_existing_method(interceptor, :intercept_start_element)
  @intercept_end_method = get_existing_method(interceptor, :intercept_end_element)

  # For compatibility reasons, we need to collect all "characters" and add
  # them as an additional 'value' argument to the 'intercept_end_element'
  # call.
  # Now, in order to reduce wasted memory, we only do that, if the
  # 'intercept_end_method' actually makes use of it by checking the number
  # of expected arguments.
  #
  # The default would actually be:
  # name, prefix, uri
  #
  # Our legacy code however expects:
  # name, attrs, prefix, uri, ns, value
  #
  # So we check, if the method defined 6 parameters.
  #
  # Note: Variable *args will NOT work with this legacy mechanism!
  #
  if @intercept_end_method.arity == 6
    @intercept_characters = true
  end

  @start_split_method = get_existing_method(interceptor, :start_split, :split!)
  @split_method = get_existing_method(interceptor, :split?)
  @end_split_method = get_existing_method(interceptor, :end_split)

  @intercepted_start_args = nil
  @intercepted_value = nil

end

Public Instance Methods

cdata_block(s) click to toggle source
# File xml/splitter.rb, line 127
def cdata_block s
  @output.cdata_block s unless @output.nil?
end
characters(s) click to toggle source
# File xml/splitter.rb, line 113
def characters s

  @intercepted_value << s unless @intercepted_value.nil?

  if not @output.nil?
    @output.characters s
  end

end
comment(s) click to toggle source
# File xml/splitter.rb, line 123
def comment s
  @output.comment s unless @output.nil?
end
end_document() click to toggle source
# File xml/splitter.rb, line 103
def end_document

  # Ensure output is 'closed', even though it should already in 'end_element_namespace'
  unless @output.nil?
    @output.end_document
    @output = nil
  end

end
end_element_namespace(*args) click to toggle source
# File xml/splitter.rb, line 84
def end_element_namespace *args

  if not @output.nil?
    @depth -= 1
    @output.end_element_namespace(*args)
    if @depth == 0
      @output.end_document
      @output = nil
      end_split(*args)
    end
  end

  call_optional_method(@intercept_end_method, *(@intercepted_start_args || args))

  @intercepted_start_args = nil
  @intercepted_value = nil

end
error(msg) click to toggle source
# File xml/splitter.rb, line 131
def error msg
  if @interceptor.respond_to? :intercept_error
    @interceptor.intercept_error(msg)
  end
  @output.error msg unless @output.nil?
end
start_element_namespace(*args) click to toggle source
# File xml/splitter.rb, line 59
def start_element_namespace *args

  call_optional_method(@intercept_start_method, *args)

  if @intercept_characters
    @intercepted_value = ''
    @intercepted_start_args = (args | [@intercepted_value])
  end

  if @output.nil?
    @output = start_split(*args)
    if not @output.nil?
      @xmldecl ||= DEFAULT_XML_DECL
      @output.xmldecl(*@xmldecl)
      @output.start_document
    end
  end

  if not @output.nil?
    @output.start_element_namespace(*args)
    @depth += 1
  end

end
warning(msg) click to toggle source
# File xml/splitter.rb, line 138
def warning msg
  if @interceptor.respond_to? :intercept_warning
    @interceptor.intercept_warning(msg)
  end
  @output.warning msg unless @output.nil?
end
xmldecl(*args) click to toggle source
# File xml/splitter.rb, line 55
def xmldecl *args
  @xmldecl = args
end