Skip to content

Commit 9aa06ea

Browse files
Merge remote-tracking branch 'origin/master' into release
2 parents b756e22 + 1e7cdfb commit 9aa06ea

File tree

8 files changed

+320
-5
lines changed

8 files changed

+320
-5
lines changed

AsposeWordsCloud.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'AsposeWordsCloud'
3-
s.version = '22.3'
3+
s.version = '22.4'
44
s.summary = 'Aspose Words for Cloud.'
55
s.homepage = 'https://github.com/aspose-words-cloud/aspose-words-cloud-swift.git'
66
s.license = { :type => 'MIT', :file => 'LICENSE' }

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ This repository contains Aspose.Words Cloud SDK for Swift source code. This SDK
1313
* Watermarks and protection
1414
* Full read & write access to Document Object Model, including sections, paragraphs, text, images, tables, headers/footers and many others
1515

16+
## Enhancements in Version 22.4
17+
18+
- Added ExportShapesAsSvg to HtmlSaveOption.
19+
- Added new endpoint '~/styles/copy_from'.
20+
21+
1622
## Enhancements in Version 22.3
1723

1824
- Online methods returns the dictionary of files with included original filename as key instead of single file content in responses.
@@ -198,7 +204,7 @@ Add link to this repository as dependency to your Package.swift:
198204

199205
dependencies: [
200206
// Dependencies declare other packages that this package depends on.
201-
.package(url: "https://github.com/aspose-words-cloud/aspose-words-cloud-swift", from: "22.3"),
207+
.package(url: "https://github.com/aspose-words-cloud/aspose-words-cloud-swift", from: "22.4"),
202208
],
203209
targets: [
204210
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
@@ -216,7 +222,7 @@ targets: [
216222
Add link to git repository as dependency to your Podfile:
217223

218224
```ruby
219-
pod 'AsposeWordsCloud', :git => 'https://github.com/aspose-words-cloud/aspose-words-cloud-swift.git', :tag => '22.3'
225+
pod 'AsposeWordsCloud', :git => 'https://github.com/aspose-words-cloud/aspose-words-cloud-swift.git', :tag => '22.4'
220226
```
221227

222228
## Getting Started

Sources/AsposeWordsCloud/Api/Configuration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,6 @@ public class Configuration : Codable {
188188

189189
// Returns SDK version for using in statistics headers
190190
public func getSdkVersion() -> String {
191-
return "22.3";
191+
return "22.4";
192192
}
193193
}

Sources/AsposeWordsCloud/Api/WordsAPI.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,52 @@ public class WordsAPI : Encryptor {
867867
return responseObject!;
868868
}
869869

870+
// Async representation of copyStylesFromTemplate method
871+
// Copies styles from the origin document to the target document.
872+
public func copyStylesFromTemplate(request : CopyStylesFromTemplateRequest, callback : @escaping (_ response : WordsResponse?, _ error : Error?) -> ()) {
873+
do {
874+
apiInvoker.invoke(
875+
apiRequestData: try request.createApiRequestData(apiInvoker: self.apiInvoker, configuration: self.configuration),
876+
callback: { response, headers, error in
877+
if (error != nil) {
878+
callback(nil, error);
879+
}
880+
else {
881+
do {
882+
callback(try request.deserializeResponse(data: response!, headers: headers) as? WordsResponse, nil);
883+
}
884+
catch let deserializeError {
885+
callback(nil, deserializeError);
886+
}
887+
}
888+
}
889+
);
890+
}
891+
catch let error {
892+
callback(nil, error);
893+
}
894+
}
895+
896+
// Sync representation of copyStylesFromTemplate method
897+
// Copies styles from the origin document to the target document.
898+
public func copyStylesFromTemplate(request : CopyStylesFromTemplateRequest) throws -> WordsResponse {
899+
let semaphore = DispatchSemaphore(value: 0);
900+
var responseObject : WordsResponse? = nil;
901+
var responseError : Error? = nil;
902+
self.copyStylesFromTemplate(request : request, callback: { response, error in
903+
responseObject = response;
904+
responseError = error;
905+
semaphore.signal();
906+
});
907+
908+
_ = semaphore.wait();
909+
910+
if (responseError != nil) {
911+
throw responseError!;
912+
}
913+
return responseObject!;
914+
}
915+
870916
// Async representation of createDocument method
871917
// Supported extensions: ".doc", ".docx", ".docm", ".dot", ".dotm", ".dotx", ".flatopc", ".fopc", ".flatopc_macro", ".fopc_macro", ".flatopc_template", ".fopc_template", ".flatopc_template_macro", ".fopc_template_macro", ".wordml", ".wml", ".rtf".
872918
public func createDocument(request : CreateDocumentRequest, callback : @escaping (_ response : DocumentResponse?, _ error : Error?) -> ()) {

Sources/AsposeWordsCloud/Model/PdfSaveOptionsData.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public class PdfSaveOptionsData : FixedPageSaveOptionsData {
5151
// Enum value "pdfA2u"
5252
case pdfA2u = "PdfA2u"
5353

54+
// Enum value "pdfA4"
55+
case pdfA4 = "PdfA4"
56+
5457
// Enum value "pdfUa1"
5558
case pdfUa1 = "PdfUa1"
5659
}
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
/*
2+
* --------------------------------------------------------------------------------
3+
* <copyright company="Aspose" file="CopyStylesFromTemplateRequest.swift">
4+
* Copyright (c) 2022 Aspose.Words for Cloud
5+
* </copyright>
6+
* <summary>
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
* </summary>
25+
* --------------------------------------------------------------------------------
26+
*/
27+
28+
import Foundation
29+
30+
// Request model for copyStylesFromTemplate operation.
31+
@available(macOS 10.12, iOS 10.3, watchOS 3.3, tvOS 12.0, *)
32+
public class CopyStylesFromTemplateRequest : WordsApiRequest {
33+
private let name : String;
34+
private let templateName : String;
35+
private let folder : String?;
36+
private let storage : String?;
37+
private let loadEncoding : String?;
38+
private let password : String?;
39+
private let encryptedPassword : String?;
40+
private let destFileName : String?;
41+
private let revisionAuthor : String?;
42+
private let revisionDateTime : String?;
43+
44+
private enum CodingKeys: String, CodingKey {
45+
case name;
46+
case templateName;
47+
case folder;
48+
case storage;
49+
case loadEncoding;
50+
case password;
51+
case encryptedPassword;
52+
case destFileName;
53+
case revisionAuthor;
54+
case revisionDateTime;
55+
case invalidCodingKey;
56+
}
57+
58+
// Initializes a new instance of the CopyStylesFromTemplateRequest class.
59+
public init(name : String, templateName : String, folder : String? = nil, storage : String? = nil, loadEncoding : String? = nil, password : String? = nil, encryptedPassword : String? = nil, destFileName : String? = nil, revisionAuthor : String? = nil, revisionDateTime : String? = nil) {
60+
self.name = name;
61+
self.templateName = templateName;
62+
self.folder = folder;
63+
self.storage = storage;
64+
self.loadEncoding = loadEncoding;
65+
self.password = password;
66+
self.encryptedPassword = encryptedPassword;
67+
self.destFileName = destFileName;
68+
self.revisionAuthor = revisionAuthor;
69+
self.revisionDateTime = revisionDateTime;
70+
}
71+
72+
// The filename of the target document.
73+
public func getName() -> String {
74+
return self.name;
75+
}
76+
77+
// The filename of the origin document.
78+
public func getTemplateName() -> String {
79+
return self.templateName;
80+
}
81+
82+
// Original document folder.
83+
public func getFolder() -> String? {
84+
return self.folder;
85+
}
86+
87+
// Original document storage.
88+
public func getStorage() -> String? {
89+
return self.storage;
90+
}
91+
92+
// Encoding that will be used to load an HTML (or TXT) document if the encoding is not specified in HTML.
93+
public func getLoadEncoding() -> String? {
94+
return self.loadEncoding;
95+
}
96+
97+
// Password of protected Word document. Use the parameter to pass a password via SDK. SDK encrypts it automatically. We don't recommend to use the parameter to pass a plain password for direct call of API.
98+
public func getPassword() -> String? {
99+
return self.password;
100+
}
101+
102+
// Password of protected Word document. Use the parameter to pass an encrypted password for direct calls of API. See SDK code for encyption details.
103+
public func getEncryptedPassword() -> String? {
104+
return self.encryptedPassword;
105+
}
106+
107+
// Result path of the document after the operation. If this parameter is omitted then result of the operation will be saved as the source document.
108+
public func getDestFileName() -> String? {
109+
return self.destFileName;
110+
}
111+
112+
// Initials of the author to use for revisions.If you set this parameter and then make some changes to the document programmatically, save the document and later open the document in MS Word you will see these changes as revisions.
113+
public func getRevisionAuthor() -> String? {
114+
return self.revisionAuthor;
115+
}
116+
117+
// The date and time to use for revisions.
118+
public func getRevisionDateTime() -> String? {
119+
return self.revisionDateTime;
120+
}
121+
122+
// Creates the api request data
123+
public func createApiRequestData(apiInvoker : ApiInvoker, configuration : Configuration) throws -> WordsApiRequestData {
124+
var rawPath = "/words/{name}/styles/copy_from";
125+
rawPath = rawPath.replacingOccurrences(of: "{name}", with: try ObjectSerializer.serializeToString(value: self.getName()));
126+
127+
rawPath = rawPath.replacingOccurrences(of: "//", with: "/");
128+
129+
let urlPath = (try configuration.getApiRootUrl()).appendingPathComponent(rawPath);
130+
var urlBuilder = URLComponents(url: urlPath, resolvingAgainstBaseURL: false)!;
131+
var queryItems : [URLQueryItem] = [];
132+
#if os(Linux)
133+
queryItems.append(URLQueryItem(name: "templateName", value: try ObjectSerializer.serializeToString(value: self.getTemplateName())));
134+
#else
135+
queryItems.append(URLQueryItem(name: "templateName", value: try ObjectSerializer.serializeToString(value: self.getTemplateName())));
136+
#endif
137+
138+
139+
if (self.getFolder() != nil) {
140+
141+
#if os(Linux)
142+
queryItems.append(URLQueryItem(name: "folder", value: try ObjectSerializer.serializeToString(value: self.getFolder()!)));
143+
144+
#else
145+
queryItems.append(URLQueryItem(name: "folder", value: try ObjectSerializer.serializeToString(value: self.getFolder()!)));
146+
147+
#endif
148+
}
149+
150+
151+
if (self.getStorage() != nil) {
152+
153+
#if os(Linux)
154+
queryItems.append(URLQueryItem(name: "storage", value: try ObjectSerializer.serializeToString(value: self.getStorage()!)));
155+
156+
#else
157+
queryItems.append(URLQueryItem(name: "storage", value: try ObjectSerializer.serializeToString(value: self.getStorage()!)));
158+
159+
#endif
160+
}
161+
162+
163+
if (self.getLoadEncoding() != nil) {
164+
165+
#if os(Linux)
166+
queryItems.append(URLQueryItem(name: "loadEncoding", value: try ObjectSerializer.serializeToString(value: self.getLoadEncoding()!)));
167+
168+
#else
169+
queryItems.append(URLQueryItem(name: "loadEncoding", value: try ObjectSerializer.serializeToString(value: self.getLoadEncoding()!)));
170+
171+
#endif
172+
}
173+
174+
175+
if (self.getPassword() != nil) {
176+
177+
#if os(Linux)
178+
queryItems.append(URLQueryItem(name: "password", value: try ObjectSerializer.serializeToString(value: self.getPassword()!)));
179+
180+
#else
181+
queryItems.append(URLQueryItem(name: apiInvoker.isEncryptionAllowed() ? "encryptedPassword" : "password", value: try apiInvoker.encryptString(value: self.getPassword()!)));
182+
183+
#endif
184+
}
185+
186+
187+
if (self.getEncryptedPassword() != nil) {
188+
189+
#if os(Linux)
190+
queryItems.append(URLQueryItem(name: "encryptedPassword", value: try ObjectSerializer.serializeToString(value: self.getEncryptedPassword()!)));
191+
192+
#else
193+
queryItems.append(URLQueryItem(name: "encryptedPassword", value: try ObjectSerializer.serializeToString(value: self.getEncryptedPassword()!)));
194+
195+
#endif
196+
}
197+
198+
199+
if (self.getDestFileName() != nil) {
200+
201+
#if os(Linux)
202+
queryItems.append(URLQueryItem(name: "destFileName", value: try ObjectSerializer.serializeToString(value: self.getDestFileName()!)));
203+
204+
#else
205+
queryItems.append(URLQueryItem(name: "destFileName", value: try ObjectSerializer.serializeToString(value: self.getDestFileName()!)));
206+
207+
#endif
208+
}
209+
210+
211+
if (self.getRevisionAuthor() != nil) {
212+
213+
#if os(Linux)
214+
queryItems.append(URLQueryItem(name: "revisionAuthor", value: try ObjectSerializer.serializeToString(value: self.getRevisionAuthor()!)));
215+
216+
#else
217+
queryItems.append(URLQueryItem(name: "revisionAuthor", value: try ObjectSerializer.serializeToString(value: self.getRevisionAuthor()!)));
218+
219+
#endif
220+
}
221+
222+
223+
if (self.getRevisionDateTime() != nil) {
224+
225+
#if os(Linux)
226+
queryItems.append(URLQueryItem(name: "revisionDateTime", value: try ObjectSerializer.serializeToString(value: self.getRevisionDateTime()!)));
227+
228+
#else
229+
queryItems.append(URLQueryItem(name: "revisionDateTime", value: try ObjectSerializer.serializeToString(value: self.getRevisionDateTime()!)));
230+
231+
#endif
232+
}
233+
234+
if (queryItems.count > 0) {
235+
urlBuilder.queryItems = queryItems;
236+
}
237+
238+
let result = WordsApiRequestData(url: urlBuilder.url!, method: "PUT");
239+
return result;
240+
}
241+
242+
// Deserialize response of this request
243+
public func deserializeResponse(data : Data, headers : [String: String]) throws -> Any? {
244+
return try ObjectSerializer.deserialize(type: WordsResponse.self, from: data);
245+
}
246+
}
11.8 KB
Binary file not shown.

Tests/AsposeWordsCloudTests/StylesTests.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class StylesTests: BaseTestContext {
4545
("testGetStyleFromDocumentElement", testGetStyleFromDocumentElement),
4646
("testGetStyleFromDocumentElementOnline", testGetStyleFromDocumentElementOnline),
4747
("testApplyStyleToDocumentElement", testApplyStyleToDocumentElement),
48-
("testApplyStyleToDocumentElementOnline", testApplyStyleToDocumentElementOnline)
48+
("testApplyStyleToDocumentElementOnline", testApplyStyleToDocumentElementOnline),
49+
("testCopyStylesFromTemplate", testCopyStylesFromTemplate)
4950
];
5051

5152
let remoteDataFolder = BaseTestContext.getRemoteTestDataFolder() + "/DocumentElements/Styles";
@@ -200,4 +201,17 @@ class StylesTests: BaseTestContext {
200201
let request = ApplyStyleToDocumentElementOnlineRequest(document: requestDocument, styledNodePath: "paragraphs/1/paragraphFormat", styleApply: requestStyleApply);
201202
_ = try super.getApi().applyStyleToDocumentElementOnline(request: request);
202203
}
204+
205+
// Test for copying styles from a template.
206+
func testCopyStylesFromTemplate() throws {
207+
let remoteFileName = "TestCopyStylesFromTemplate.docx";
208+
let templateFolder = "DocumentElements/Styles";
209+
let templateName = "StyleTemplate.docx";
210+
211+
try super.uploadFile(fileContent: getLocalTestDataFolder().appendingPathComponent(localFile, isDirectory: false), path: remoteDataFolder + "/" + remoteFileName);
212+
try super.uploadFile(fileContent: getLocalTestDataFolder().appendingPathComponent(templateFolder + "/" + templateName, isDirectory: false), path: remoteDataFolder + "/" + templateName);
213+
214+
let request = CopyStylesFromTemplateRequest(name: remoteFileName, templateName: templateName, folder: remoteDataFolder);
215+
_ = try super.getApi().copyStylesFromTemplate(request: request);
216+
}
203217
}

0 commit comments

Comments
 (0)