github.com/boki/go-xmp@v1.0.1/models/xmp_rights/model.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 xmprights implements the XMP Rights management namespace as defined by XMP Specification Part 1. 16 package xmprights 17 18 import ( 19 "fmt" 20 "trimmer.io/go-xmp/xmp" 21 ) 22 23 var ( 24 NsXmpRights = xmp.NewNamespace("xmpRights", "http://ns.adobe.com/xap/1.0/rights/", NewModel) 25 ) 26 27 func init() { 28 xmp.Register(NsXmpRights, xmp.XmpMetadata, xmp.RightsMetadata) 29 } 30 31 func NewModel(name string) xmp.Model { 32 return &XmpRights{} 33 } 34 35 func MakeModel(d *xmp.Document) (*XmpRights, error) { 36 m, err := d.MakeModel(NsXmpRights) 37 if err != nil { 38 return nil, err 39 } 40 x, _ := m.(*XmpRights) 41 return x, nil 42 } 43 44 func FindModel(d *xmp.Document) *XmpRights { 45 if m := d.FindModel(NsXmpRights); m != nil { 46 return m.(*XmpRights) 47 } 48 return nil 49 } 50 51 type XmpRights struct { 52 Certificate string `xmp:"xmpRights:Certificate"` 53 Marked xmp.Bool `xmp:"xmpRights:Marked"` 54 Owner xmp.StringArray `xmp:"xmpRights:Owner"` 55 UsageTerms xmp.AltString `xmp:"xmpRights:UsageTerms"` 56 WebStatement string `xmp:"xmpRights:WebStatement"` 57 } 58 59 func (x XmpRights) Can(nsName string) bool { 60 return NsXmpRights.GetName() == nsName 61 } 62 63 func (x XmpRights) Namespaces() xmp.NamespaceList { 64 return xmp.NamespaceList{NsXmpRights} 65 } 66 67 func (x *XmpRights) SyncModel(d *xmp.Document) error { 68 return nil 69 } 70 71 func (x *XmpRights) SyncFromXMP(d *xmp.Document) error { 72 return nil 73 } 74 75 func (x XmpRights) SyncToXMP(d *xmp.Document) error { 76 return nil 77 } 78 79 func (x *XmpRights) CanTag(tag string) bool { 80 _, err := xmp.GetNativeField(x, tag) 81 return err == nil 82 } 83 84 func (x *XmpRights) GetTag(tag string) (string, error) { 85 if v, err := xmp.GetNativeField(x, tag); err != nil { 86 return "", fmt.Errorf("%s: %v", NsXmpRights.GetName(), err) 87 } else { 88 return v, nil 89 } 90 } 91 92 func (x *XmpRights) SetTag(tag, value string) error { 93 if err := xmp.SetNativeField(x, tag, value); err != nil { 94 return fmt.Errorf("%s: %v", NsXmpRights.GetName(), err) 95 } 96 return nil 97 }