blob: 60a500e0d7cd28d90be6ad8e521bcf36bf070d44 [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"
24#include "XmlPullParser.h"
25
Adam Lesinski24aad162015-04-24 19:19:30 -070026#include <string>
27
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080028namespace aapt {
29
30/**
31 * Flattens an XML file into a binary representation parseable by
32 * the Android resource system. References to resources are checked
33 * and string values are transformed to typed data where possible.
34 */
35class XmlFlattener {
36public:
37 struct Options {
38 /**
Adam Lesinski24aad162015-04-24 19:19:30 -070039 * The package to use when a reference has no package specified
40 * (or a namespace URI equals "http://schemas.android.com/apk/res-auto").
41 */
42 std::u16string defaultPackage;
43
44 /**
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080045 * If set, tells the XmlFlattener to strip out
46 * attributes that have been introduced after
47 * max SDK.
48 */
49 Maybe<size_t> maxSdkAttribute;
50 };
51
52 /**
53 * Creates a flattener with a Resolver to resolve references
54 * and attributes.
55 */
Adam Lesinski769de982015-04-10 19:43:55 -070056 XmlFlattener(const std::shared_ptr<ResourceTable>& table,
Adam Lesinski24aad162015-04-24 19:19:30 -070057 const std::shared_ptr<IResolver>& resolver);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080058
59 XmlFlattener(const XmlFlattener&) = delete; // Not copyable.
60
61 /**
62 * Flatten an XML file, reading from the XML parser and writing to the
63 * BigBuffer. The source object is mainly for logging errors. If the
64 * function succeeds, returns the smallest SDK version of an attribute that
65 * was stripped out. If no attributes were stripped out, the return value
66 * is 0.
67 */
68 Maybe<size_t> flatten(const Source& source, const std::shared_ptr<XmlPullParser>& parser,
69 BigBuffer* outBuffer, Options options);
70
71private:
Adam Lesinski769de982015-04-10 19:43:55 -070072 std::shared_ptr<ResourceTable> mTable;
Adam Lesinski24aad162015-04-24 19:19:30 -070073 std::shared_ptr<IResolver> mResolver;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080074};
75
76} // namespace aapt
77
78#endif // AAPT_XML_FLATTENER_H