-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: parse script data source reference (#74)
- Loading branch information
Showing
21 changed files
with
278 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use crate::utils::attributes::parse_unescaped_attribute; | ||
use quick_xml::events::{BytesStart, Event}; | ||
use quick_xml::Reader; | ||
|
||
#[derive(Debug, Default)] | ||
pub struct DataSourceReference { | ||
pub id: Option<String>, | ||
pub name: Option<String>, | ||
} | ||
|
||
impl DataSourceReference { | ||
pub fn from_xml(reader: &mut Reader<&[u8]>, _e: &BytesStart) -> Option<DataSourceReference> { | ||
let mut depth = 1; | ||
let mut item = DataSourceReference { | ||
id: None, | ||
name: None, | ||
}; | ||
|
||
let mut buf: Vec<u8> = Vec::new(); | ||
loop { | ||
match reader.read_event_into(&mut buf) { | ||
Err(_) => continue, | ||
Ok(Event::Eof) => break, | ||
Ok(Event::Start(e)) => { | ||
depth += 1; | ||
if e.name().as_ref() == b"DataSourceReference" { | ||
item.id = parse_unescaped_attribute(&e, "id"); | ||
item.name = parse_unescaped_attribute(&e, "name"); | ||
} | ||
} | ||
Ok(Event::End(_)) => { | ||
depth -= 1; | ||
if depth == 0 { | ||
break; | ||
} | ||
} | ||
_ => {} | ||
} | ||
buf.clear(); | ||
} | ||
|
||
Some(item) | ||
} | ||
|
||
pub fn display(&self) -> Option<String> { | ||
if let Some(name) = &self.name { | ||
if self.id == Some(String::from("0")) { | ||
Some(name.clone()) | ||
} else { | ||
Some(format!("\"{}\"", name)) | ||
} | ||
} else { | ||
None | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use crate::utils::attributes::parse_unescaped_attribute; | ||
use quick_xml::events::{BytesStart, Event}; | ||
use quick_xml::Reader; | ||
|
||
#[derive(Debug, Default)] | ||
pub struct ScriptReference { | ||
pub data_source_name: Option<String>, | ||
pub script_name: Option<String>, | ||
} | ||
|
||
impl ScriptReference { | ||
pub fn from_xml(reader: &mut Reader<&[u8]>, _e: &BytesStart) -> Option<ScriptReference> { | ||
let mut depth = 1; | ||
let mut item = ScriptReference { | ||
data_source_name: None, | ||
script_name: None, | ||
}; | ||
|
||
let mut buf: Vec<u8> = Vec::new(); | ||
loop { | ||
match reader.read_event_into(&mut buf) { | ||
Err(_) => continue, | ||
Ok(Event::Eof) => break, | ||
Ok(Event::Start(e)) => { | ||
depth += 1; | ||
match e.name().as_ref() { | ||
b"DataSourceReference" => { | ||
item.data_source_name = parse_unescaped_attribute(&e, "name") | ||
} | ||
b"ScriptReference" => { | ||
item.script_name = parse_unescaped_attribute(&e, "name") | ||
} | ||
_ => {} | ||
} | ||
} | ||
Ok(Event::End(_)) => { | ||
depth -= 1; | ||
if depth == 0 { | ||
break; | ||
} | ||
} | ||
_ => {} | ||
} | ||
buf.clear(); | ||
} | ||
|
||
Some(item) | ||
} | ||
|
||
pub fn display(&self) -> Option<String> { | ||
let mut parameters = vec![]; | ||
|
||
if let Some(script_name) = &self.script_name { | ||
parameters.push(format!("\"{}\"", script_name)); | ||
} | ||
if let Some(data_source_name) = &self.data_source_name { | ||
parameters.push(format!("from file \"{}\"", data_source_name)); | ||
} | ||
|
||
if !parameters.is_empty() { | ||
Some(parameters.join(" ")) | ||
} else { | ||
None | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.