github.com/boki/go-xmp@v1.0.1/models/cc/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 // Creative Commons Metadata 16 // 17 // - URL: https://wiki.creativecommons.org/wiki/XMP 18 // - Namespace: http://creativecommons.org/ns# 19 // - prefix: cc 20 21 // Package cc implements Creative Commons licensing metadata. 22 package cc 23 24 import ( 25 "fmt" 26 "trimmer.io/go-xmp/xmp" 27 ) 28 29 var ( 30 NsCC = xmp.NewNamespace("cc", "http://creativecommons.org/ns#", NewModel) 31 ) 32 33 func init() { 34 xmp.Register(NsCC, xmp.RightsMetadata) 35 } 36 37 func NewModel(name string) xmp.Model { 38 return &CC{} 39 } 40 41 func MakeModel(d *xmp.Document) (*CC, error) { 42 m, err := d.MakeModel(NsCC) 43 if err != nil { 44 return nil, err 45 } 46 x, _ := m.(*CC) 47 return x, nil 48 } 49 50 func FindModel(d *xmp.Document) *CC { 51 if m := d.FindModel(NsCC); m != nil { 52 return m.(*CC) 53 } 54 return nil 55 } 56 57 type CC struct { 58 License xmp.Uri `xmp:"cc:license"` 59 MorePermissions xmp.Uri `xmp:"cc:morePermissions"` 60 AttributionURL xmp.Uri `xmp:"cc:attributionURL"` 61 AttributionName string `xmp:"cc:attributionName"` 62 } 63 64 func (x CC) Can(nsName string) bool { 65 return NsCC.GetName() == nsName 66 } 67 68 func (x CC) Namespaces() xmp.NamespaceList { 69 return xmp.NamespaceList{NsCC} 70 } 71 72 func (x *CC) SyncModel(d *xmp.Document) error { 73 return nil 74 } 75 76 func (x *CC) SyncFromXMP(d *xmp.Document) error { 77 return nil 78 } 79 80 func (x CC) SyncToXMP(d *xmp.Document) error { 81 return nil 82 } 83 84 func (x *CC) CanTag(tag string) bool { 85 _, err := xmp.GetNativeField(x, tag) 86 return err == nil 87 } 88 89 func (x *CC) GetTag(tag string) (string, error) { 90 if v, err := xmp.GetNativeField(x, tag); err != nil { 91 return "", fmt.Errorf("%s: %v", NsCC.GetName(), err) 92 } else { 93 return v, nil 94 } 95 } 96 97 func (x *CC) SetTag(tag, value string) error { 98 if err := xmp.SetNativeField(x, tag, value); err != nil { 99 return fmt.Errorf("%s: %v", NsCC.GetName(), err) 100 } 101 return nil 102 }