github.com/boki/go-xmp@v1.0.1/models/xmp_mm/types.go (about) 1 // Copyright (c) 2017-2018 Alexander Eichhorn 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 // not use this file except in compliance with the License. You may obtain 5 // 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, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations 13 // under the License. 14 15 // Package xmpmm implements the XMP Media Management namespace as defined by XMP Specification Part 2. 16 package xmpmm 17 18 import ( 19 "trimmer.io/go-xmp/models/xmp_dm" 20 "trimmer.io/go-xmp/xmp" 21 ) 22 23 // Part 1: 8.2.2.9 ResourceRef + Part 2: 1.2.4.1 ResourceRef 24 type ResourceRef struct { 25 AlternatePaths xmp.UriArray `xmp:"stRef:alternatePaths"` 26 OriginalDocumentID xmp.GUID `xmp:"stRef:originalDocumentID,attr"` 27 DocumentID xmp.GUID `xmp:"stRef:documentID,attr"` 28 FilePath xmp.Uri `xmp:"stRef:filePath,attr"` 29 FromPart *xmpdm.Part `xmp:"stRef:fromPart,attr"` 30 InstanceID xmp.GUID `xmp:"stRef:instanceID,attr"` 31 LastModifyDate xmp.Date `xmp:"stRef:lastModifyDate,attr"` 32 Manager xmp.AgentName `xmp:"stRef:manager,attr"` 33 ManagerVariant string `xmp:"stRef:managerVariant,attr"` 34 ManageTo xmp.Uri `xmp:"stRef:manageTo,attr"` 35 ManageUI xmp.Uri `xmp:"stRef:manageUI,attr"` 36 MaskMarkers xmpdm.MaskType `xmp:"stRef:maskMarkers,attr"` 37 PartMapping string `xmp:"stRef:partMapping,attr"` 38 RenditionClass xmpdm.RenditionClass `xmp:"stRef:renditionClass,attr"` 39 RenditionParams string `xmp:"stRef:renditionParams,attr"` 40 ToPart *xmpdm.Part `xmp:"stRef:toPart,attr"` 41 VersionID string `xmp:"stRef:versionID,attr"` 42 } 43 44 func (x ResourceRef) IsZero() bool { 45 return len(x.AlternatePaths) == 0 && 46 x.OriginalDocumentID.IsZero() && 47 x.DocumentID.IsZero() && 48 x.FilePath == "" && 49 (x.FromPart == nil || x.FromPart.IsZero()) && 50 x.InstanceID.IsZero() && 51 x.LastModifyDate.IsZero() && 52 x.Manager.IsZero() && 53 x.ManagerVariant == "" && 54 x.ManageTo == "" && 55 x.MaskMarkers == "" && 56 x.PartMapping == "" && 57 x.RenditionClass == "" && 58 x.RenditionParams == "" && 59 (x.ToPart == nil || x.ToPart.IsZero()) && 60 x.VersionID == "" 61 } 62 63 func (x ResourceRef) MarshalXMP(e *xmp.Encoder, node *xmp.Node, m xmp.Model) error { 64 if x.IsZero() { 65 return nil 66 } 67 type _t ResourceRef 68 return e.EncodeElement(_t(x), node) 69 } 70 71 type ResourceRefArray []*ResourceRef 72 73 func (x ResourceRefArray) Index(did xmp.GUID) int { 74 for i, v := range x { 75 if v.DocumentID == did { 76 return i 77 } 78 } 79 return -1 80 } 81 82 func (x *ResourceRefArray) DeleteIndex(idx int) { 83 if idx < 0 || idx > len(*x) { 84 return 85 } 86 *x = append((*x)[:idx], ((*x)[idx+1:])...) 87 } 88 89 func (x ResourceRefArray) Typ() xmp.ArrayType { 90 return xmp.ArrayTypeUnordered 91 } 92 93 func (x ResourceRefArray) MarshalXMP(e *xmp.Encoder, node *xmp.Node, m xmp.Model) error { 94 return xmp.MarshalArray(e, node, x.Typ(), x) 95 } 96 97 func (x *ResourceRefArray) UnmarshalXMP(d *xmp.Decoder, node *xmp.Node, m xmp.Model) error { 98 return xmp.UnmarshalArray(d, node, x.Typ(), x) 99 } 100 101 // Part 2: 1.2.4.2 Version 102 type StVersion struct { 103 Comments string `xmp:"stVer:comments,attr"` 104 Event ResourceEvent `xmp:"stVer:event"` 105 Modifier string `xmp:"stVer:modifier,attr"` 106 ModifyDate xmp.Date `xmp:"stVer:modifyDate,attr"` 107 Version string `xmp:"stVer:version,attr"` 108 } 109 110 type StVersionArray []*StVersion 111 112 func (x StVersionArray) Typ() xmp.ArrayType { 113 return xmp.ArrayTypeUnordered 114 } 115 116 func (x StVersionArray) MarshalXMP(e *xmp.Encoder, node *xmp.Node, m xmp.Model) error { 117 return xmp.MarshalArray(e, node, x.Typ(), x) 118 } 119 120 func (x *StVersionArray) UnmarshalXMP(d *xmp.Decoder, node *xmp.Node, m xmp.Model) error { 121 return xmp.UnmarshalArray(d, node, x.Typ(), x) 122 } 123 124 // 1.2.4 ResourceEvent 125 type ResourceEvent struct { 126 Action ActionType `xmp:"stEvt:action,attr"` 127 Changed xmpdm.PartList `xmp:"stEvt:changed,attr"` 128 InstanceID xmp.GUID `xmp:"stEvt:instanceID,attr"` 129 Parameters string `xmp:"stEvt:parameters,attr"` 130 SoftwareAgent xmp.AgentName `xmp:"stEvt:softwareAgent,attr"` 131 When xmp.Date `xmp:"stEvt:when,attr"` 132 } 133 134 type ResourceEventArray []*ResourceEvent 135 136 func (x ResourceEventArray) Typ() xmp.ArrayType { 137 return xmp.ArrayTypeOrdered 138 } 139 140 func (x ResourceEventArray) MarshalXMP(e *xmp.Encoder, node *xmp.Node, m xmp.Model) error { 141 return xmp.MarshalArray(e, node, x.Typ(), x) 142 } 143 144 func (x *ResourceEventArray) UnmarshalXMP(d *xmp.Decoder, node *xmp.Node, m xmp.Model) error { 145 return xmp.UnmarshalArray(d, node, x.Typ(), x) 146 } 147 148 type ActionType string 149 150 const ( 151 ActionConverted ActionType = "converted" 152 ActionCopied ActionType = "copied" 153 ActionCreated ActionType = "created" 154 ActionCropped ActionType = "cropped" 155 ActionEdited ActionType = "edited" 156 ActionFiltered ActionType = "filtered" 157 ActionFormatted ActionType = "formatted" 158 ActionVersionUpdated ActionType = "version_updated" 159 ActionPrinted ActionType = "printed" 160 ActionPublished ActionType = "published" 161 ActionManaged ActionType = "managed" 162 ActionProduced ActionType = "produced" 163 ActionResized ActionType = "resized" 164 ActionSaved ActionType = "saved" 165 // more types not in XMP standard 166 ActionAdded ActionType = "media_added" 167 ActionRemoved ActionType = "media_removed" 168 ActionForked ActionType = "forked" 169 ActionMerged ActionType = "merged" 170 )