Class: Uniword::Validation::Validators::OoxmlPartValidator

Inherits:
LayerValidator
  • Object
show all
Defined in:
lib/uniword/validation/validators/ooxml_part_validator.rb

Overview

Validates OOXML part structure (required/optional parts).

Responsibility: Validate OOXML parts exist per ISO/IEC 29500. Single Responsibility: Only validates part existence.

This is Layer 3 validation - validates that all required OOXML parts are present in the document package.

Checks:

  • Required parts exist (Content Types, document, relationships)

  • Optional but common parts (styles, numbering)

Examples:

Validate OOXML parts

validator = OoxmlPartValidator.new(config)
result = validator.validate('/path/to/document.docx')
puts result.valid? # => true

Constant Summary collapse

REQUIRED_PARTS =

Required parts per ISO/IEC 29500

{
  "[Content_Types].xml" => "Content Types definition",
  "word/document.xml" => "Main document content",
  "_rels/.rels" => "Package relationships",
}.freeze
OPTIONAL_PARTS =

Optional but commonly used parts

{
  "word/styles.xml" => "Styles definition",
  "word/numbering.xml" => "Numbering definition",
  "word/_rels/document.xml.rels" => "Document relationships",
  "word/settings.xml" => "Document settings",
  "word/fontTable.xml" => "Font table",
  "word/theme/theme1.xml" => "Theme definition",
}.freeze

Instance Attribute Summary

Attributes inherited from LayerValidator

#config

Instance Method Summary collapse

Methods inherited from LayerValidator

#enabled?, #initialize

Constructor Details

This class inherits a constructor from Uniword::Validation::LayerValidator

Instance Method Details

#layer_nameObject



43
44
45
# File 'lib/uniword/validation/validators/ooxml_part_validator.rb', line 43

def layer_name
  "OOXML Parts"
end

#validate(path) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/uniword/validation/validators/ooxml_part_validator.rb', line 47

def validate(path)
  result = LayerValidationResult.new(layer_name)

  Zip::File.open(path) do |zip|
    validate_required_parts(zip, result)
    validate_optional_parts(zip, result) if warn_missing_optional?
  end

  result
rescue Zip::Error => e
  result.add_error(
    "Cannot open ZIP file: #{e.message}",
    critical: true,
  )
  result
end