Class: Yast::XMLClass
- Inherits:
-
Module
- Object
- Module
- Yast::XMLClass
- Defined in:
- ../../src/modules/XML.rb
Instance Method Summary (collapse)
- - (Object) main
-
- (void) xmlCreateDoc(doc, docSettings)
define a new doc type with custom settings, if not defined, global settings will be used.
-
- (Object) XMLError
The error string from the xml parser.
-
- (Object) XMLToYCPFile(xmlFile)
Read XML file into YCP.
-
- (Object) XMLToYCPString(xmlString)
Read XML string into YCP.
-
- (Boolean) YCPToXMLFile(docType, contents, outputPath)
YCPToXMLFile() Write YCP data into formated XML file.
-
- (Object) YCPToXMLString(docType, contents)
Write YCP data into formated XML string @param symbol Document type identifier @param [Hash] contents a map with YCP data @return [String] String with XML data.
Instance Method Details
- (Object) main
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File '../../src/modules/XML.rb', line 34 def main # Sections in XML file that should be treated as CDATA when saving @cdataSections = [] # How to call a list entry in the XML output @listEntries = {} # The system ID, or the DTD URI @systemID = "" # root element of the XML file @rootElement = "" # Global Namespace xmlns=... @nameSpace = "http://www.suse.com/1.0/yast2ns" # Type name space xmlns:config for YCP data (http://www.suse.com/1.0/configns) @typeNamespace = "http://www.suse.com/1.0/configns" @docs = {} end |
- (void) xmlCreateDoc(doc, docSettings)
This method returns an undefined value.
define a new doc type with custom settings, if not defined, global settings will be used.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File '../../src/modules/XML.rb', line 61 def xmlCreateDoc(doc, docSettings) docSettings = deep_copy(docSettings) current_settings = { "cdataSections" => Ops.get_list( docSettings, "cdataSections", @cdataSections ), "systemID" => Ops.get_string(docSettings, "systemID", @systemID), "rootElement" => Ops.get_string( docSettings, "rootElement", @rootElement ), "listEntries" => Ops.get_map(docSettings, "listEntries", @listEntries) } if Ops.get_string(docSettings, "typeNamespace", "") != "" Ops.set( current_settings, "typeNamespace", Ops.get_string(docSettings, "typeNamespace", "") ) end if Ops.get_string(docSettings, "nameSpace", "") != "" Ops.set( current_settings, "nameSpace", Ops.get_string(docSettings, "nameSpace", "") ) end Ops.set(@docs, doc, current_settings) nil end |
- (Object) XMLError
The error string from the xml parser. It should be used when the agent did not return content. A reset happens before a new XML parsing starts.
178 179 180 |
# File '../../src/modules/XML.rb', line 178 def XMLError Convert.to_string(SCR.Read(path(".xml.error_message"))) end |
- (Object) XMLToYCPFile(xmlFile)
Read XML file into YCP
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File '../../src/modules/XML.rb', line 136 def XMLToYCPFile(xmlFile) if Ops.greater_than(SCR.Read(path(".target.size"), xmlFile), 0) Builtins.y2milestone("Reading %1", xmlFile) out = Convert.convert( SCR.Read(path(".xml"), xmlFile), from: "any", to: "map <string, any>" ) Builtins.y2debug("XML Agent output: %1", out) return deep_copy(out) else Builtins.y2warning( "XML file %1 (%2) not found", xmlFile, SCR.Read(path(".target.size"), xmlFile) ) return {} end end |
- (Object) XMLToYCPString(xmlString)
Read XML string into YCP
159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File '../../src/modules/XML.rb', line 159 def XMLToYCPString(xmlString) if Ops.greater_than(Builtins.size(xmlString), 0) out = Convert.convert( SCR.Read(path(".xml.string"), xmlString), from: "any", to: "map <string, any>" ) Builtins.y2debug("XML Agent output: %1", out) return deep_copy(out) else Builtins.y2warning("can't convert empty XML string") return {} end end |
- (Boolean) YCPToXMLFile(docType, contents, outputPath)
YCPToXMLFile() Write YCP data into formated XML file
102 103 104 105 106 107 108 109 110 111 112 113 |
# File '../../src/modules/XML.rb', line 102 def YCPToXMLFile(docType, contents, outputPath) contents = deep_copy(contents) if !Builtins.haskey(@docs, docType) Builtins.y2error("doc type %1 undecalred...", docType) return false end docSettings = Ops.get_map(@docs, docType, {}) Ops.set(docSettings, "fileName", outputPath) Builtins.y2debug("Write(.xml, %1, %2)", docSettings, contents) ret = Convert.to_boolean(SCR.Execute(path(".xml"), docSettings, contents)) ret end |
- (Object) YCPToXMLString(docType, contents)
Write YCP data into formated XML string @param symbol Document type identifier @param [Hash] contents a map with YCP data @return [String] String with XML data
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File '../../src/modules/XML.rb', line 119 def YCPToXMLString(docType, contents) contents = deep_copy(contents) return nil if !Builtins.haskey(@docs, docType) docSettings = Ops.get_map(@docs, docType, {}) Ops.set(docSettings, "fileName", "dummy") ret = SCR.Execute(path(".xml.string"), docSettings, contents) if Ops.is_string?(ret) return Convert.to_string(ret) else return "" end end |