JFLib

diagram_io/src/report.rs#

Source: lib/diagram_io/src/report.rs

report -- (JD19, DA-09) shape report definitions as Visio keeps them: the XML of
VisioReportDefinition (a .vrd file holds the same) and the document sheet's User rows
visPropRpt1, visPropRpt2 ... (Value: that XML as a string, U="STR")

  parse(text) -> Result<ReportDef, ReportError>   a definition read (diagram_core::report's
                                      model; a BOM is skipped, a UTF-16 .vrd is decoded
                                      by the caller, e.g. with text_of)
  to_xml(&def) -> String              the same as Visio writes it: the declaration, the root
                                      with its attributes, Name, Title, the fields,
                                      criteria, the group, the sort keys, then the elements
                                      not known here as they were read
  stored(doc) -> Vec<Stored>          every visPropRptN row in the order of its number, read
  find(doc, name) -> Option<Stored>   the one with this name (case ignored)
  add(tx, &def) -> row name           a new row: the number after the largest one
  replace(tx, row, &def)              the row's definition anew
  rename(tx, row, name)               only the name (and the title, when it was the name)
  remove(tx, row)                     the row goes; the definitions after it move up a row
                                      (visPropRpt3 into visPropRpt2 ...), so the numbers
                                      stay without gaps (Annahme: Visio reads them in order)

Where Visio keeps them ([MS-VSDX] says nothing; two files Visio 16 saved, bvisual.net): the
root VisioReportDefinition in the namespace NS with ReportExists, SelectDrawingDataMethod,
Description, Precision, ShowUnits, CaseSensitive, UserCells, HiddenProperties,
AdvancedFilter, FilterExpression, Version and the children Name, Title, VisioRptDefField (ID,
Display, DisplayOrder, Type, SummaryTypes, Tag; Name, DisplayName), VisioRptDefFilter (ID,
Property, Condition, AndOr, PropertyType, PropertyDataType, Value, Unit), VisioRptDefGroup (ID,
GroupingField, ItemDisplay, GrandSummary, ExcludeDuplicates), VisioRptDefSort (ID, SortField,
Ascending, CaseSensitive).  The codes and what is assumed about them: diagram_core::report.

Reading: the crate's own pull reader (xml.rs: bounded, no DTD, no entity but the five, an
error and never a panic), at most 16 levels and 64 attributes per element, MAX_BYTES of text,
512 fields, criteria, sort keys and unknown elements each.  Elements are taken by their local
name in the default namespace (NS or none); an unknown child of the root is kept as the text
it was (one with a namespace prefix is left out: its declaration may be the root's), an
unknown child of a field is not.  Attributes in no namespace that are not known are kept.
Writing: double quotes as Visio writes them; esc() is the one place that escapes, and leaves
out what XML 1.0 cannot carry.  A row whose text is no definition stays as it is (its
Stored::def is the error); replace and remove take it like any other.
/// the namespace of VisioReportDefinition
NS: &str = "urn:schemas-microsoft-com:office:visio:reportdefinition"
/// the longest definition read (bytes)
MAX_BYTES: usize = 1 << 20
/// the row names' prefix in the document sheet's User section
ROW_PREFIX: &str = "visPropRpt"
  • enum ReportError why a text is no report definition

    • Syntax -- not well-formed XML
    • Limit -- too long, too deep, too many attributes or elements
    • Unsupported -- a DOCTYPE or an encoding the reader does not take
    • NotReport -- well-formed, but no VisioReportDefinition
  • fn parse(text: &str) -> R<ReportDef> read a definition

  • fn to_xml(d: &ReportDef) -> String the definition as XML (the text of a visPropRptN cell and of a .vrd file)

  • struct Stored a definition kept in the document

    • row: String -- the row's name (visPropRpt3)
    • index: u32 -- its number (3)
    • xml: String -- the text of its Value cell
    • def: Result<ReportDef, ReportError> -- the definition read from it
  • fn stored(doc: &Document) -> Vec<Stored> the definitions of the document sheet, by their numbers

  • fn find(doc: &Document, name: &str) -> Option<Stored> the definition named name (case ignored)

  • fn add(tx: &mut Transaction, def: &ReportDef) -> Result<String, EditError> keep a new definition in the document -> its row's name

  • fn replace(tx: &mut Transaction, row: &str, def: &ReportDef) -> Result<(), EditError> give a kept definition's row another definition

  • fn rename(tx: &mut Transaction, row: &str, name: &str) -> Result<(), EditError> rename a kept definition (its title too when it was its name); a row that is no definition is refused (Invalid)

  • fn remove(tx: &mut Transaction, row: &str) -> Result<(), EditError> remove a kept definition; the ones after it move up a row

Source: docs/API.md in the JFLib repository.