lib/rspreadsheet/tools.rb in rspreadsheet-0.2.15 vs lib/rspreadsheet/tools.rb in rspreadsheet-0.3

- old
+ new

@@ -115,11 +115,12 @@ 'drawooo'=>"http://openoffice.org/2010/draw", 'calcext'=>"urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0", 'loext'=>"urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0", 'field'=>"urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0", 'formx'=>"urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0", - 'css3t'=>"http://www.w3.org/TR/css3-text/" + 'css3t'=>"http://www.w3.org/TR/css3-text/", + 'manifest'=>"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" } if @pomnode.nil? @pomnode = LibXML::XML::Node.new('xxx') end if @ns.nil? then @ns={} end @@ -146,10 +147,11 @@ nil end end def self.get_ns_attribute(node,ns_prefix,key,default=:undefined_default) if default==:undefined_default + raise 'Nil does not have any attributes' if node.nil? node.attributes.get_attribute_ns(Tools.get_namespace(ns_prefix).href,key) else node.nil? ? default : node.attributes.get_attribute_ns(Tools.get_namespace(ns_prefix).href,key) || default end end @@ -165,9 +167,26 @@ attr.remove! unless attr.nil? end def self.prepare_ns_node(ns_prefix,nodename,value=nil) LibXML::XML::Node.new(nodename,value, Tools.get_namespace(ns_prefix)) end + def self.insert_as_first_node_child(node,subnode) + if node.first? + node.first.prev = subnode + else + node << subnode + end + end + + + def self.get_unused_filename(zip,prefix, extension) + (1000..9999).each do |ndx| + filename = prefix + ndx.to_s + ((Time.now.to_r*1000000000).to_i.to_s(16)) + extension + return filename if zip.find_entry(filename).nil? + end + raise 'Could not get unused filename within sane times of iterations' + end + end end # @private \ No newline at end of file