-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclsFilePDF.cls
More file actions
140 lines (115 loc) · 4.36 KB
/
Copy pathclsFilePDF.cls
File metadata and controls
140 lines (115 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "clsFilePDF"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' ==================================================================
' EJEMPLO DE IMPLEMENTACIÓN FUTURA
' ==================================================================
' Demuestra cómo clsFileManager puede gestionar diferentes tipos
' de archivos sin modificar su código
' ==================================================================
' ==================================================================
' USO DESDE clsFileManager
' ==================================================================
' Dim pdfFile As clsFilePDF
' Set pdfFile = New clsFilePDF
' pdfFile.BindTo "C:\Oportunidades\ABC\documento.pdf"
'
' ' FileManager lo trackea sin saber que es PDF
' mFileMgr.TrackFile pdfFile
' ==================================================================
'@Folder "2-Infraestructura.FS"
'@Implements IFile
Option Explicit
Private Const MODULE_NAME As String = "clsFilePDF"
Private p_filePath As String
Private p_fileInfo As Object ' Podría ser metadatos del PDF
Private p_ObjectKey As Double
' ==================================================================
' IMPLEMENTA LA INTERFAZ IFile
' ==================================================================
Implements IFile
' ==================================================================
' PROPIEDADES PÚBLICAS (API pública de la clase)
' ==================================================================
' Propiedades públicas
Public Property Get ObjectKey() As Double
ObjectKey = p_ObjectKey
End Property
Public Property Get path() As String
path = p_filePath
End Property
Public Property Get Name() As String
Name = IFile_Name
End Property
Public Property Get IsOpportunityFile() As Boolean
' Si está en una carpeta de oportunidad... o es de gasnet, valoracion, oferta, ...
End Property
'--------------------------------------------------------------
' Estas propiedades Private son generadas automáticamente por VBA
' cuando escribes "Implements IFile"
' Delegan a las propiedades públicas
'--------------------------------------------------------------
Private Property Get IFile_ObjectKey() As Double
IFile_ObjectKey = p_ObjectKey
End Property
Private Property Get IFile_Path() As String
IFile_Path = p_filePath
End Property
Private Property Get IFile_Name() As String
On Error GoTo ErrHandler
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
IFile_Name = fso.GetFileName(p_filePath)
Exit Property
ErrHandler:
LogCurrentError MODULE_NAME, "[IFile_Name]"
IFile_Name = "(error)"
End Property
Private Property Get IFile_IsOpportunityFile() As Boolean
IFile_IsOpportunityFile = Me.IsOpportunityFile
End Property
' ==================================================================
' Metodos publicos: vinculo entre Documento PDF y fichero
' ==================================================================
' Método específico de PDF
Public Sub BindTo(filePath As String)
On Error GoTo ErrHandler
If p_ObjectKey <> 0 Then
Err.Raise vbObjectError + 580, TypeName(Me), "Ya está asociado a un archivo."
End If
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(filePath) Then
Err.Raise vbObjectError + 581, TypeName(Me), "El archivo no existe: " & filePath
End If
p_filePath = filePath
' Para archivos en disco, usar hash del path como ObjectKey
p_ObjectKey = GetPathHashCode(filePath)
LogInfo MODULE_NAME, "[BindTo] Asociado a: " & filePath
Exit Sub
ErrHandler:
LogCurrentError MODULE_NAME, "[BindTo]"
Err.Raise Err.Number, MODULE_NAME & " [BindTo]", Err.Description
End Sub
' Helper para generar ObjectKey consistente desde path
Private Function GetPathHashCode(path As String) As Double
' Implementación simple: sum de códigos ASCII
Dim i As Long, hash As Double
For i = 1 To Len(path)
hash = hash + Asc(Mid(path, i, 1)) * i
Next i
GetPathHashCode = hash
End Function
' Métodos específicos de PDF
Public Function ExtractText() As String
' Implementación futura: usar librería de PDF
End Function
Public Function GetPageCount() As Long
' Implementación futura
End Function