blob: 4ece0a37869dbc6be4a61892b3fab2230705b426 [file] [log] [blame]
Adam Lesinski6f6ceb72014-11-14 14:48:12 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef AAPT_XML_FLATTENER_H
18#define AAPT_XML_FLATTENER_H
19
20#include "BigBuffer.h"
21#include "Maybe.h"
22#include "Resolver.h"
23#include "Source.h"
Adam Lesinski75f3a552015-06-03 14:54:23 -070024#include "XmlDom.h"
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080025
Adam Lesinski24aad162015-04-24 19:19:30 -070026#include <string>
27
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080028namespace aapt {
Adam Lesinski75f3a552015-06-03 14:54:23 -070029namespace xml {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080030
31/**
32 * Flattens an XML file into a binary representation parseable by
Adam Lesinski75f3a552015-06-03 14:54:23 -070033 * the Android resource system.
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080034 */
Adam Lesinski75f3a552015-06-03 14:54:23 -070035bool flatten(Node* root, const std::u16string& defaultPackage, BigBuffer* outBuffer);
Adam Lesinski24aad162015-04-24 19:19:30 -070036
Adam Lesinski75f3a552015-06-03 14:54:23 -070037/**
38 * Options for flattenAndLink.
39 */
40struct FlattenOptions {
41 /**
42 * Keep attribute raw string values along with typed values.
43 */
44 bool keepRawValues = false;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080045
46 /**
Adam Lesinski75f3a552015-06-03 14:54:23 -070047 * If set, any attribute introduced in a later SDK will not be encoded.
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080048 */
Adam Lesinski75f3a552015-06-03 14:54:23 -070049 Maybe<size_t> maxSdkAttribute;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080050};
51
Adam Lesinski75f3a552015-06-03 14:54:23 -070052/**
53 * Like flatten(Node*,BigBuffer*), but references to resources are checked
54 * and string values are transformed to typed data where possible.
55 *
56 * `defaultPackage` is used when a reference has no package or the namespace URI
57 * "http://schemas.android.com/apk/res-auto" is used.
58 *
59 * `resolver` is used to resolve references to resources.
60 */
61Maybe<size_t> flattenAndLink(const Source& source, Node* root,
62 const std::u16string& defaultPackage,
63 const std::shared_ptr<IResolver>& resolver,
64 const FlattenOptions& options, BigBuffer* outBuffer);
65
66} // namespace xml
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080067} // namespace aapt
68
69#endif // AAPT_XML_FLATTENER_H