1// Copyright 2014 Richard Lehane. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// This file contains struct mappings to unmarshal three different PRONOM XML formats: the signature file format, the report format, and the container format
16package mappings
17
18import (
19	"encoding/xml"
20)
21
22// Droid Signature File
23
24type Droid struct {
25	XMLName     xml.Name            `xml:"FFSignatureFile"`
26	Version     int                 `xml:",attr"`
27	Signatures  []InternalSignature `xml:"InternalSignatureCollection>InternalSignature"`
28	FileFormats []FileFormat        `xml:"FileFormatCollection>FileFormat"`
29}
30
31type InternalSignature struct {
32	Id            int       `xml:"ID,attr"`
33	ByteSequences []ByteSeq `xml:"ByteSequence"`
34}
35
36type ByteSeq struct {
37	Reference    string        `xml:"Reference,attr"`
38	SubSequences []SubSequence `xml:"SubSequence"`
39}
40
41type SubSequence struct {
42	Position        int    `xml:",attr"`
43	SubSeqMinOffset string `xml:",attr"` // and empty int values are unmarshalled to 0
44	SubSeqMaxOffset string `xml:",attr"` // uses string rather than int because value might be empty
45	Sequence        string
46	LeftFragments   []Fragment `xml:"LeftFragment"`
47	RightFragments  []Fragment `xml:"RightFragment"`
48}
49
50type Fragment struct {
51	Value     string `xml:",chardata"`
52	MinOffset string `xml:",attr"`
53	MaxOffset string `xml:",attr"`
54	Position  int    `xml:",attr"`
55}
56
57type FileFormat struct {
58	XMLName    xml.Name `xml:"FileFormat"`
59	Id         int      `xml:"ID,attr"`
60	Puid       string   `xml:"PUID,attr"`
61	Name       string   `xml:",attr"`
62	Version    string   `xml:",attr"`
63	MIMEType   string   `xml:",attr"`
64	Extensions []string `xml:"Extension"`
65	Signatures []int    `xml:"InternalSignatureID"`
66	Priorities []int    `xml:"HasPriorityOverFileFormatID"`
67}
68