Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 1 | /* |
| 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 Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 24 | #include "XmlDom.h" |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 25 | |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 26 | #include <string> |
| 27 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 28 | namespace aapt { |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 29 | namespace xml { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Flattens an XML file into a binary representation parseable by |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 33 | * the Android resource system. |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 34 | */ |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 35 | bool flatten(Node* root, const std::u16string& defaultPackage, BigBuffer* outBuffer); |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 36 | |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 37 | /** |
| 38 | * Options for flattenAndLink. |
| 39 | */ |
| 40 | struct FlattenOptions { |
| 41 | /** |
| 42 | * Keep attribute raw string values along with typed values. |
| 43 | */ |
| 44 | bool keepRawValues = false; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 45 | |
| 46 | /** |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 47 | * If set, any attribute introduced in a later SDK will not be encoded. |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 48 | */ |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 49 | Maybe<size_t> maxSdkAttribute; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 50 | }; |
| 51 | |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 52 | /** |
| 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 | */ |
| 61 | Maybe<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 Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 67 | } // namespace aapt |
| 68 | |
| 69 | #endif // AAPT_XML_FLATTENER_H |