parser

package
v0.2.0-dev Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Defaults
	DefaultCounter        = 1            // DefaultCounter is the default counter
	DefaultFilenamePrefix = "diagram"    // DefaultFilenamePrefix is the default filename prefix
	DefaultPathBPMN       = "files/bpmn" // DefaultPathBPMN is the default path to the bpmn files
	DefaultPathJSON       = "files/json" // DefaultPathJSON is the default path to the json files
	DefaultPathXML        = "files/xml"  // DefaultPathXML is the default path to the xml files

	// Errors
	ErrPathNotFound        = errors.New("path not found")                                   // ErrPathNotFound is the error for the path not found
	ErrEmptyFilePathBPMN   = errors.New("empty file path for bpmn")                         // ErrEmptyFilePathBPMN is the error for the empty file path for bpmn
	ErrUnsupportedFileType = errors.New("unsupported file type")                            // ErrUnsupportedFileType is the error for the unsupported file type
	ErrInvalidDefinitions  = errors.New("invalid DefinitionsRepository: repository is nil") // ErrInvalidDefinitions is the error for the invalid definitions
)

Functions

func ToPlainXML

func ToPlainXML(bytes []byte) []byte

Types

type BPMNParser

type BPMNParser struct {
	Counter        int                              // Counter is the number of created files
	FilenamePrefix string                           // FilenamePrefix is a part of the name of the current file
	FilePathBPMN   string                           // FilePathBPMN is the path to the bpmn files
	FilePathJSON   string                           // FilePathJSON is the path to the json files
	FilePathXML    string                           // FilePathXML is the path to the xml files
	Def            *foundation.Definitions          // Def is the pointer definition of the model
	Repo           foundation.DefinitionsRepository // Repo is the repository of the model
}

BPMNParser ...

func (BPMNParser) GetFilename

func (parser BPMNParser) GetFilename() string

GetFilename returns the current bpmn filename It is a helper method to get the current bpmn filename, which relies on the same instance

func (BPMNParser) Marshal

func (parser BPMNParser) Marshal() error

Marshal builds the bpmn, json and xml files and returns an error, if an error occurs during the process. The method calls the MarshalBPMN and MarshalJSON methods. NOTE: Actually no option pattern is used here. Should be done later.

func (*BPMNParser) MarshalJson

func (parser *BPMNParser) MarshalJson() ([]byte, error)

MarshalJSON marshals the repository data to JSON and saves it as a file.

func (*BPMNParser) MarshalXml

func (parser *BPMNParser) MarshalXml() ([]byte, error)

MarshalXML marshals the repository data to xml and saves it as a file.

func (BPMNParser) Validate

func (parser BPMNParser) Validate() error

Validate checks, if all incoming, outgoing, sourceRef and targetRef values are valid.

type BPMNParserRepository

type BPMNParserRepository interface {
	Marshal() error
	Validate() error
}

BPMNParserRepository ...

func NewBPMNParser

func NewBPMNParser(opts ...Option) (BPMNParserRepository, error)

NewBPMNParser initializes the parser with the given options and returns the bpmn parser repository. The method sets the default values and applies the options to the parser.

type Element

type Element struct {
	Name      string
	Attrs     map[string]string
	Children  []*Element
	Text      string
	Namespace string
}

func FindElementsByPath

func FindElementsByPath(root *Element, path string) ([]*Element, error)

func XMLParser

func XMLParser(filePath string) (*Element, error)

type Option

type Option = func(parser *BPMNParser) error

Option is a functional option type for the Parser

func WithCounter

func WithCounter() Option

WithCounter counts .bpmn files in the provided path and updates the Counter

func WithDefinitions

func WithDefinitions(repo foundation.DefinitionsRepository) Option

WithDefinitions assigns a DefinitionsRepository to the parser.

func WithFilenamePrefix

func WithFilenamePrefix(filenamePrefix string) Option

WithFilenamePrefix sets the filename prefix for the parser

func WithPath

func WithPath(paths ...string) Option

WithPath validates and sets paths for bpmn, json and xml files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL