blob: 540a5ef002829920c81ed9df6aabf98737e32af3 [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
26namespace aapt {
27
28/**
29 * Flattens an XML file into a binary representation parseable by
30 * the Android resource system. References to resources are checked
31 * and string values are transformed to typed data where possible.
32 */
33class XmlFlattener {
34public:
35 struct Options {
36 /**
37 * If set, tells the XmlFlattener to strip out
38 * attributes that have been introduced after
39 * max SDK.
40 */
41 Maybe<size_t> maxSdkAttribute;
42 };
43
44 /**
45 * Creates a flattener with a Resolver to resolve references
46 * and attributes.
47 */
Adam Lesinski769de982015-04-10 19:43:55 -070048 XmlFlattener(const std::shared_ptr<ResourceTable>& table,
49 const std::shared_ptr<Resolver>& resolver);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080050
51 XmlFlattener(const XmlFlattener&) = delete; // Not copyable.
52
53 /**
54 * Flatten an XML file, reading from the XML parser and writing to the
55 * BigBuffer. The source object is mainly for logging errors. If the
56 * function succeeds, returns the smallest SDK version of an attribute that
57 * was stripped out. If no attributes were stripped out, the return value
58 * is 0.
59 */
60 Maybe<size_t> flatten(const Source& source, const std::shared_ptr<XmlPullParser>& parser,
61 BigBuffer* outBuffer, Options options);
62
63private:
Adam Lesinski769de982015-04-10 19:43:55 -070064 std::shared_ptr<ResourceTable> mTable;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080065 std::shared_ptr<Resolver> mResolver;
66};
67
68} // namespace aapt
69
70#endif // AAPT_XML_FLATTENER_H