Module: T2Server::XML::Methods
- Included in:
- Administrator, OutputPort, Port, Run, Server, XPathCache
- Defined in:
- lib/t2-server/xml/methods.rb
Instance Method Summary collapse
-
#get_uris_from_doc(doc, keys) ⇒ Object
Given a list of xpath keys, extract the href URIs from those elements.
- #xml_children(doc, &block) ⇒ Object
- #xml_document(string) ⇒ Object
- #xml_first_child(node) ⇒ Object
- #xml_input_fragment(input, type = :value) ⇒ Object
- #xml_keypair_cred_fragment(uri, name, key, type, password) ⇒ Object
- #xml_mkdir_fragment(name) ⇒ Object
- #xml_node_attribute(node, attribute) ⇒ Object
- #xml_node_content(node) ⇒ Object
- #xml_node_name(node) ⇒ Object
- #xml_password_cred_fragment(uri, username, password) ⇒ Object
- #xml_permissions_fragment(username, permission) ⇒ Object
- #xml_trust_fragment(contents, type) ⇒ Object
- #xml_upload_fragment(name, data) ⇒ Object
- #xpath_attr(doc, expr, attribute) ⇒ Object
- #xpath_compile(xpath) ⇒ Object
- #xpath_find(doc, expr) ⇒ Object
- #xpath_first(doc, expr) ⇒ Object
Instance Method Details
#get_uris_from_doc(doc, keys) ⇒ Object
Given a list of xpath keys, extract the href URIs from those elements.
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/t2-server/xml/methods.rb', line 83 def get_uris_from_doc(doc, keys) cache = XPathCache.instance uris = {} keys.each do |key| uri = xpath_attr(doc, cache[key], "href") uris[key] = uri.nil? ? nil : URI.parse(uri) end uris end |
#xml_children(doc, &block) ⇒ Object
49 50 51 |
# File 'lib/t2-server/xml/methods.rb', line 49 def xml_children(doc, &block) doc.each { |node| yield node } end |
#xml_document(string) ⇒ Object
41 42 43 |
# File 'lib/t2-server/xml/methods.rb', line 41 def xml_document(string) LibXML::XML::Document.string(string) end |
#xml_first_child(node) ⇒ Object
45 46 47 |
# File 'lib/t2-server/xml/methods.rb', line 45 def xml_first_child(node) node.first end |
#xml_input_fragment(input, type = :value) ⇒ Object
95 96 97 98 |
# File 'lib/t2-server/xml/methods.rb', line 95 def xml_input_fragment(input, type = :value) node = create_node("nsr:runInput", ["nsr:#{type}", input.to_s]) create_document(node).to_s end |
#xml_keypair_cred_fragment(uri, name, key, type, password) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/t2-server/xml/methods.rb', line 128 def xml_keypair_cred_fragment(uri, name, key, type, password) node = create_node("nsr:credential", ["nss:keypair", ["nss:serviceURI", uri], ["nss:credentialName", name], ["nss:credentialBytes", key], ["nss:fileType", type], ["nss:unlockPassword", password] ] ) create_document(node).to_s end |
#xml_mkdir_fragment(name) ⇒ Object
100 101 102 103 |
# File 'lib/t2-server/xml/methods.rb', line 100 def xml_mkdir_fragment(name) node = create_node("nsr:mkdir", { "nsr:name" => name }) create_document(node).to_s end |
#xml_node_attribute(node, attribute) ⇒ Object
61 62 63 |
# File 'lib/t2-server/xml/methods.rb', line 61 def xml_node_attribute(node, attribute) node.attributes[attribute] end |
#xml_node_content(node) ⇒ Object
57 58 59 |
# File 'lib/t2-server/xml/methods.rb', line 57 def xml_node_content(node) node.content end |
#xml_node_name(node) ⇒ Object
53 54 55 |
# File 'lib/t2-server/xml/methods.rb', line 53 def xml_node_name(node) node.name end |
#xml_password_cred_fragment(uri, username, password) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/t2-server/xml/methods.rb', line 116 def xml_password_cred_fragment(uri, username, password) node = create_node("nsr:credential", ["nss:userpass", ["nss:serviceURI", uri], ["nss:username", username], ["nss:password", password] ] ) create_document(node).to_s end |
#xml_permissions_fragment(username, permission) ⇒ Object
110 111 112 113 114 |
# File 'lib/t2-server/xml/methods.rb', line 110 def (username, ) node = create_node("nsr:permissionUpdate", ["nsr:userName", username], ["nsr:permission", ]) create_document(node).to_s end |
#xml_trust_fragment(contents, type) ⇒ Object
142 143 144 145 146 |
# File 'lib/t2-server/xml/methods.rb', line 142 def xml_trust_fragment(contents, type) node = create_node("nss:trustedIdentity", ["nss:certificateBytes", contents], ["nss:fileType", type]) create_document(node).to_s end |
#xml_upload_fragment(name, data) ⇒ Object
105 106 107 108 |
# File 'lib/t2-server/xml/methods.rb', line 105 def xml_upload_fragment(name, data) node = create_node("nsr:upload", { "nsr:name" => name }, data) create_document(node).to_s end |
#xpath_attr(doc, expr, attribute) ⇒ Object
77 78 79 80 |
# File 'lib/t2-server/xml/methods.rb', line 77 def xpath_attr(doc, expr, attribute) node = xpath_first(doc, expr) node.nil? ? nil : node.attributes[attribute] end |
#xpath_compile(xpath) ⇒ Object
65 66 67 |
# File 'lib/t2-server/xml/methods.rb', line 65 def xpath_compile(xpath) LibXML::XML::XPath::Expression.new(xpath) end |
#xpath_find(doc, expr) ⇒ Object
69 70 71 |
# File 'lib/t2-server/xml/methods.rb', line 69 def xpath_find(doc, expr) doc.find(expr, Namespaces::MAP) end |
#xpath_first(doc, expr) ⇒ Object
73 74 75 |
# File 'lib/t2-server/xml/methods.rb', line 73 def xpath_first(doc, expr) doc.find_first(expr, Namespaces::MAP) end |