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