1 #ifndef __XMPUtils_hpp__
2 #define __XMPUtils_hpp__
3 
4 // =================================================================================================
5 // Copyright 2002-2007 Adobe Systems Incorporated
6 // All Rights Reserved.
7 //
8 // NOTICE:	Adobe permits you to use, modify, and distribute this file in accordance with the terms
9 // of the Adobe license agreement accompanying it.
10 // =================================================================================================
11 
12 #include "XMP_Environment.h"
13 #include "XMP_Const.h"
14 
15 #include "XMPMeta.hpp"
16 #include "XMPCore_Impl.hpp"
17 #include "client-glue/WXMPUtils.hpp"
18 
19 // -------------------------------------------------------------------------------------------------
20 
21 extern XMP_VarString * sComposedPath;		// *** Only really need 1 string. Shrink periodically?
22 extern XMP_VarString * sConvertedValue;
23 extern XMP_VarString * sBase64Str;
24 extern XMP_VarString * sCatenatedItems;
25 extern XMP_VarString * sStandardXMP;
26 extern XMP_VarString * sExtendedXMP;
27 extern XMP_VarString * sExtendedDigest;
28 
29 // -------------------------------------------------------------------------------------------------
30 
31 class	XMPUtils {
32 public:
33 
34 	static bool
35 	Initialize();	// ! For internal use only!
36 
37 	static void
38 	Terminate() RELEASE_NO_THROW;	// ! For internal use only!
39 
40 	static void
41 	Unlock ( XMP_OptionBits options );
42 
43 	// ---------------------------------------------------------------------------------------------
44 
45 	static void
46 	ComposeArrayItemPath ( XMP_StringPtr   schemaNS,
47 						   XMP_StringPtr   arrayName,
48 						   XMP_Index	   itemIndex,
49 						   XMP_StringPtr * fullPath,
50 						   XMP_StringLen * pathSize );
51 
52 	static void
53 	ComposeStructFieldPath ( XMP_StringPtr	 schemaNS,
54 							 XMP_StringPtr	 structName,
55 							 XMP_StringPtr	 fieldNS,
56 							 XMP_StringPtr	 fieldName,
57 							 XMP_StringPtr * fullPath,
58 							 XMP_StringLen * pathSize );
59 
60 	static void
61 	ComposeQualifierPath ( XMP_StringPtr   schemaNS,
62 						   XMP_StringPtr   propName,
63 						   XMP_StringPtr   qualNS,
64 						   XMP_StringPtr   qualName,
65 						   XMP_StringPtr * fullPath,
66 						   XMP_StringLen * pathSize );
67 
68 	static void
69 	ComposeLangSelector ( XMP_StringPtr		schemaNS,
70 						  XMP_StringPtr		arrayName,
71 						  XMP_StringPtr		langName,
72 						  XMP_StringPtr *	fullPath,
73 						  XMP_StringLen *	pathSize );
74 
75 	static void
76 	ComposeFieldSelector ( XMP_StringPtr   schemaNS,
77 						   XMP_StringPtr   arrayName,
78 						   XMP_StringPtr   fieldNS,
79 						   XMP_StringPtr   fieldName,
80 						   XMP_StringPtr   fieldValue,
81 						   XMP_StringPtr * fullPath,
82 						   XMP_StringLen * pathSize );
83 
84 	// ---------------------------------------------------------------------------------------------
85 
86 	static void
87 	ConvertFromBool ( bool			  binValue,
88 					  XMP_StringPtr * strValue,
89 					  XMP_StringLen * strSize );
90 
91 	static void
92 	ConvertFromInt ( XMP_Int32		 binValue,
93 					 XMP_StringPtr	 format,
94 					 XMP_StringPtr * strValue,
95 					 XMP_StringLen * strSize );
96 
97 	static void
98 	ConvertFromInt64 ( XMP_Int64	   binValue,
99 					   XMP_StringPtr   format,
100 					   XMP_StringPtr * strValue,
101 					   XMP_StringLen * strSize );
102 
103 	static void
104 	ConvertFromFloat ( double		   binValue,
105 					   XMP_StringPtr   format,
106 					   XMP_StringPtr * strValue,
107 					   XMP_StringLen * strSize );
108 
109 	static void
110 	ConvertFromDate ( const XMP_DateTime & binValue,
111 					  XMP_StringPtr *	   strValue,
112 					  XMP_StringLen *	   strSize );
113 
114 	// ---------------------------------------------------------------------------------------------
115 
116 	static bool
117 	ConvertToBool ( XMP_StringPtr strValue );
118 
119 	static XMP_Int32
120 	ConvertToInt ( XMP_StringPtr strValue );
121 
122 	static XMP_Int64
123 	ConvertToInt64 ( XMP_StringPtr strValue );
124 
125 	static double
126 	ConvertToFloat ( XMP_StringPtr strValue );
127 
128 	static void
129 	ConvertToDate  ( XMP_StringPtr	strValue,
130 					 XMP_DateTime * binValue );
131 
132 	// ---------------------------------------------------------------------------------------------
133 
134 	static void
135 	CurrentDateTime ( XMP_DateTime * time );
136 
137 	static void
138 	SetTimeZone ( XMP_DateTime * time );
139 
140 	static void
141 	ConvertToUTCTime ( XMP_DateTime * time );
142 
143 	static void
144 	ConvertToLocalTime ( XMP_DateTime * time );
145 
146 	static int
147 	CompareDateTime ( const XMP_DateTime & left,
148 					  const XMP_DateTime & right );
149 	// ---------------------------------------------------------------------------------------------
150 
151 	static void
152 	EncodeToBase64 ( XMP_StringPtr	 rawStr,
153 					 XMP_StringLen	 rawLen,
154 					 XMP_StringPtr * encodedStr,
155 					 XMP_StringLen * encodedLen );
156 
157 	static void
158 	DecodeFromBase64 ( XMP_StringPtr   encodedStr,
159 					   XMP_StringLen   encodedLen,
160 					   XMP_StringPtr * rawStr,
161 					   XMP_StringLen * rawLen );
162 
163 	// ---------------------------------------------------------------------------------------------
164 
165 	static void
166 	PackageForJPEG ( const XMPMeta & xmpObj,
167 					 XMP_StringPtr * stdStr,
168 					 XMP_StringLen * stdLen,
169 					 XMP_StringPtr * extStr,
170 					 XMP_StringLen * extLen,
171 					 XMP_StringPtr * digestStr,
172 					 XMP_StringLen * digestLen );
173 
174 	static void
175 	MergeFromJPEG ( XMPMeta *       fullXMP,
176                     const XMPMeta & extendedXMP );
177 
178 	// ---------------------------------------------------------------------------------------------
179 
180 	static void
181 	CatenateArrayItems ( const XMPMeta & xmpObj,
182 						 XMP_StringPtr	 schemaNS,
183 						 XMP_StringPtr	 arrayName,
184 						 XMP_StringPtr	 separator,
185 						 XMP_StringPtr	 quotes,
186 						 XMP_OptionBits	 options,
187 						 XMP_StringPtr * catedStr,
188 						 XMP_StringLen * catedLen );
189 
190 	static void
191 	SeparateArrayItems ( XMPMeta *		xmpObj,
192 						 XMP_StringPtr	schemaNS,
193 						 XMP_StringPtr	arrayName,
194 						 XMP_OptionBits options,
195 						 XMP_StringPtr	catedStr );
196 
197 	static void
198 	RemoveProperties ( XMPMeta *	  xmpObj,
199 					   XMP_StringPtr  schemaNS,
200 					   XMP_StringPtr  propName,
201 					   XMP_OptionBits options );
202 
203 	static void
204 	AppendProperties ( const XMPMeta & source,
205 					   XMPMeta *	   dest,
206 					   XMP_OptionBits  options );
207 
208 	static void
209 	DuplicateSubtree ( const XMPMeta & source,
210 					   XMPMeta *	   dest,
211 					   XMP_StringPtr   sourceNS,
212 					   XMP_StringPtr   sourceRoot,
213 					   XMP_StringPtr   destNS,
214 					   XMP_StringPtr   destRoot,
215 					   XMP_OptionBits  options );
216 
217 };	// XMPUtils
218 
219 // =================================================================================================
220 
221 #endif	// __XMPUtils_hpp__
222