mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-08-30 12:12:40 +08:00
refactor(重构代码): 提升代码质量
This commit is contained in:
+196
-17
@@ -23,26 +23,32 @@ type Document struct {
|
||||
Pages Pages `xml:"Pages"`
|
||||
Outlines Outlines `xml:"Outlines"`
|
||||
Permissions Permissions `xml:"Permissions"`
|
||||
Actions []Action `xml:"Actions>Action"`
|
||||
Bookmarks Bookmarks `xml:"Bookmarks"`
|
||||
Annotations string `xml:"Annotations"`
|
||||
Signatures string `xml:"Signatures"`
|
||||
Attachments Attachments `xml:"Attachments"`
|
||||
CustomTags CustomTags `xml:"CustomTags"`
|
||||
Extensions Extensions `xml:"Extensions"`
|
||||
}
|
||||
|
||||
// Extensions 扩展集合
|
||||
type Extensions struct {
|
||||
XMLName xml.Name `xml:"Extensions"`
|
||||
Path string `xml:",chardata"`
|
||||
Extension []Extension `xml:"Extension"`
|
||||
}
|
||||
|
||||
// Extension 扩展信息
|
||||
type Extension struct {
|
||||
AppName string `xml:"AppName,attr"`
|
||||
Company string `xml:"Company,attr"`
|
||||
AppVersion string `xml:"AppVersion,attr"`
|
||||
Date string `xml:"Date,attr"`
|
||||
RefID string `xml:"RefId,attr"`
|
||||
Property []Property `xml:"Property"`
|
||||
Data string `xml:"Data"`
|
||||
AppName string `xml:"AppName,attr"`
|
||||
Company string `xml:"Company,attr"`
|
||||
AppVersion string `xml:"AppVersion,attr"`
|
||||
Date string `xml:"Date,attr"`
|
||||
RefID string `xml:"RefId,attr"`
|
||||
Property []Property `xml:"Property"`
|
||||
ExtendData []string `xml:"ExtendData"`
|
||||
Data []ExtensionData `xml:"Data"`
|
||||
}
|
||||
|
||||
// Property 扩展属性
|
||||
@@ -52,16 +58,45 @@ type Property struct {
|
||||
Type string `xml:"Type,attr"`
|
||||
}
|
||||
|
||||
// ExtensionData 扩展数据
|
||||
type ExtensionData struct {
|
||||
Attr []xml.Attr `xml:",any,attr"`
|
||||
Content string `xml:",innerxml"`
|
||||
}
|
||||
|
||||
// Attachments 附件集合
|
||||
type Attachments struct {
|
||||
XMLName xml.Name `xml:"Attachments"`
|
||||
Path string `xml:",chardata"`
|
||||
Attachment []Attachment `xml:"Attachment"`
|
||||
}
|
||||
|
||||
// Attachment 附件信息
|
||||
type Attachment struct {
|
||||
Name string `xml:"Name,attr"`
|
||||
File string `xml:"File,attr"`
|
||||
ID string `xml:"ID,attr"`
|
||||
ID string `xml:"ID,attr"`
|
||||
Name string `xml:"Name,attr"`
|
||||
Format string `xml:"Format,attr"`
|
||||
CreationDate string `xml:"CreationDate,attr"`
|
||||
ModDate string `xml:"ModDate,attr"`
|
||||
Size *float64 `xml:"Size,attr"`
|
||||
Visible bool `xml:"Visible,attr"`
|
||||
Usage string `xml:"Usage,attr"`
|
||||
FileLoc string `xml:"FileLoc"`
|
||||
}
|
||||
|
||||
// CustomTags 自定义标引集合
|
||||
type CustomTags struct {
|
||||
XMLName xml.Name `xml:"CustomTags"`
|
||||
Path string `xml:",chardata"`
|
||||
CustomTag []CustomTag `xml:"CustomTag"`
|
||||
}
|
||||
|
||||
// CustomTag 自定义标引
|
||||
type CustomTag struct {
|
||||
TypeID string `xml:"TypeID,attr"`
|
||||
NameSpace string `xml:"NameSpace,attr"`
|
||||
SchemaLoc string `xml:"SchemaLoc"`
|
||||
FileLoc string `xml:"FileLoc"`
|
||||
}
|
||||
|
||||
// CommonData 文档公共数据
|
||||
@@ -101,6 +136,17 @@ type TemplatePage struct {
|
||||
ZOrder string `xml:"ZOrder,attr"`
|
||||
}
|
||||
|
||||
// Bookmarks 书签集合
|
||||
type Bookmarks struct {
|
||||
Bookmark []Bookmark `xml:"Bookmark"`
|
||||
}
|
||||
|
||||
// Bookmark 书签
|
||||
type Bookmark struct {
|
||||
Name string `xml:"Name,attr"`
|
||||
Dest Dest `xml:"Dest"`
|
||||
}
|
||||
|
||||
// Outlines 大纲集合
|
||||
type Outlines struct {
|
||||
OutlineElem []OutlineElem `xml:"OutlineElem"`
|
||||
@@ -108,15 +154,148 @@ type Outlines struct {
|
||||
|
||||
// OutlineElem 大纲节点
|
||||
type OutlineElem struct {
|
||||
Title string `xml:"Title,attr"`
|
||||
Count int `xml:"Count,attr"`
|
||||
Actions string `xml:"Actions"`
|
||||
Title string `xml:"Title,attr"`
|
||||
Count int `xml:"Count,attr"`
|
||||
Expanded bool `xml:"Expanded,attr"`
|
||||
Actions []Action `xml:"Actions>Action"`
|
||||
OutlineElem []OutlineElem `xml:"OutlineElem"`
|
||||
}
|
||||
|
||||
// Permissions 权限声明
|
||||
type Permissions struct {
|
||||
Edit bool `xml:"Edit"`
|
||||
Print bool `xml:"Print"`
|
||||
Export bool `xml:"Export"`
|
||||
Copy bool `xml:"Copy"`
|
||||
Edit bool `xml:"Edit"`
|
||||
Annot bool `xml:"Annot"`
|
||||
Export bool `xml:"Export"`
|
||||
Signature bool `xml:"Signature"`
|
||||
Watermark bool `xml:"Watermark"`
|
||||
PrintScreen bool `xml:"PrintScreen"`
|
||||
Print bool `xml:"-"`
|
||||
Copies int `xml:"-"`
|
||||
Copy bool `xml:"CopyText"`
|
||||
ContentRegist bool `xml:"ContentRegist"`
|
||||
ValidPeriod *ValidPeriod `xml:"ValidPeriod"`
|
||||
}
|
||||
|
||||
// ValidPeriod 文档访问有效期
|
||||
type ValidPeriod struct {
|
||||
StartDate string `xml:"StartDate,attr"`
|
||||
EndDate string `xml:"EndDate,attr"`
|
||||
}
|
||||
|
||||
// UnmarshalXML 解析文档并应用权限默认值
|
||||
// 入参: d XML解码器, start 起始节点
|
||||
// 返回: error 错误信息
|
||||
func (doc *Document) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
type document Document
|
||||
value := document{Permissions: defaultPermissions()}
|
||||
if err := d.DecodeElement(&value, &start); err != nil {
|
||||
return err
|
||||
}
|
||||
*doc = Document(value)
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalXML 解析附件并应用默认值
|
||||
// 入参: d XML解码器, start 起始节点
|
||||
// 返回: error 错误信息
|
||||
func (a *Attachment) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
type attachment Attachment
|
||||
value := attachment{Visible: true, Usage: "none"}
|
||||
if err := d.DecodeElement(&value, &start); err != nil {
|
||||
return err
|
||||
}
|
||||
*a = Attachment(value)
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalXML 解析大纲节点并应用默认值
|
||||
// 入参: d XML解码器, start 起始节点
|
||||
// 返回: error 错误信息
|
||||
func (o *OutlineElem) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
type outlineElem OutlineElem
|
||||
value := outlineElem{Expanded: true}
|
||||
if err := d.DecodeElement(&value, &start); err != nil {
|
||||
return err
|
||||
}
|
||||
*o = OutlineElem(value)
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalXML 解析文档权限并应用默认值
|
||||
// 入参: d XML解码器, start 起始节点
|
||||
// 返回: error 错误信息
|
||||
func (p *Permissions) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
var value struct {
|
||||
Edit *bool `xml:"Edit"`
|
||||
Annot *bool `xml:"Annot"`
|
||||
Export *bool `xml:"Export"`
|
||||
Signature *bool `xml:"Signature"`
|
||||
Watermark *bool `xml:"Watermark"`
|
||||
PrintScreen *bool `xml:"PrintScreen"`
|
||||
Copy *bool `xml:"CopyText"`
|
||||
ContentRegist *bool `xml:"ContentRegist"`
|
||||
Print *print `xml:"Print"`
|
||||
ValidPeriod *ValidPeriod `xml:"ValidPeriod"`
|
||||
}
|
||||
if err := d.DecodeElement(&value, &start); err != nil {
|
||||
return err
|
||||
}
|
||||
*p = defaultPermissions()
|
||||
if value.Edit != nil {
|
||||
p.Edit = *value.Edit
|
||||
}
|
||||
if value.Annot != nil {
|
||||
p.Annot = *value.Annot
|
||||
}
|
||||
if value.Export != nil {
|
||||
p.Export = *value.Export
|
||||
}
|
||||
if value.Signature != nil {
|
||||
p.Signature = *value.Signature
|
||||
}
|
||||
if value.Watermark != nil {
|
||||
p.Watermark = *value.Watermark
|
||||
}
|
||||
if value.PrintScreen != nil {
|
||||
p.PrintScreen = *value.PrintScreen
|
||||
}
|
||||
if value.Copy != nil {
|
||||
p.Copy = *value.Copy
|
||||
}
|
||||
if value.ContentRegist != nil {
|
||||
p.ContentRegist = *value.ContentRegist
|
||||
}
|
||||
if value.Print != nil {
|
||||
if value.Print.Printable != nil {
|
||||
p.Print = *value.Print.Printable
|
||||
}
|
||||
if value.Print.Copies != nil {
|
||||
p.Copies = *value.Print.Copies
|
||||
}
|
||||
}
|
||||
p.ValidPeriod = value.ValidPeriod
|
||||
return nil
|
||||
}
|
||||
|
||||
// print 打印权限节点
|
||||
type print struct {
|
||||
Printable *bool `xml:"Printable,attr"`
|
||||
Copies *int `xml:"Copies,attr"`
|
||||
}
|
||||
|
||||
// defaultPermissions 获取默认文档权限
|
||||
// 返回: Permissions 文档权限
|
||||
func defaultPermissions() Permissions {
|
||||
return Permissions{
|
||||
Edit: true,
|
||||
Annot: true,
|
||||
Export: true,
|
||||
Signature: true,
|
||||
Watermark: true,
|
||||
PrintScreen: true,
|
||||
Print: true,
|
||||
Copies: -1,
|
||||
Copy: true,
|
||||
ContentRegist: true,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user