blob: 1a658fd6a18088ef42bcd864f56464c975033366 [file] [log] [blame]
Adam Lesinski5eeaadd2016-08-25 12:26:56 -07001/*
2 * Copyright (C) 2016 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_COMPILE_INLINEXMLFORMATPARSER_H
18#define AAPT_COMPILE_INLINEXMLFORMATPARSER_H
19
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070020#include <memory>
21#include <vector>
22
Adam Lesinskice5e56e2016-10-21 17:56:45 -070023#include "android-base/macros.h"
24
25#include "process/IResourceTableConsumer.h"
26
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070027namespace aapt {
28
29/**
30 * Extracts Inline XML definitions into their own xml::XmlResource objects.
31 *
32 * Inline XML looks like:
33 *
34 * <animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
35 * xmlns:aapt="http://schemas.android.com/aapt" >
36 * <aapt:attr name="android:drawable" >
37 * <vector
38 * android:height="64dp"
39 * android:width="64dp"
40 * android:viewportHeight="600"
41 * android:viewportWidth="600"/>
42 * </aapt:attr>
43 * </animated-vector>
44 *
Adam Lesinskicacb28f2016-10-19 12:18:14 -070045 * The <vector> will be extracted into its own XML file and <animated-vector>
46 * will
47 * gain an attribute 'android:drawable' set to a reference to the extracted
48 * <vector> resource.
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070049 */
50class InlineXmlFormatParser : public IXmlResourceConsumer {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070051 public:
52 explicit InlineXmlFormatParser() = default;
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070053
Adam Lesinskice5e56e2016-10-21 17:56:45 -070054 bool Consume(IAaptContext* context, xml::XmlResource* doc) override;
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070055
Adam Lesinskicacb28f2016-10-19 12:18:14 -070056 std::vector<std::unique_ptr<xml::XmlResource>>&
Adam Lesinskice5e56e2016-10-21 17:56:45 -070057 GetExtractedInlineXmlDocuments() {
58 return queue_;
Adam Lesinskicacb28f2016-10-19 12:18:14 -070059 }
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070060
Adam Lesinskicacb28f2016-10-19 12:18:14 -070061 private:
62 DISALLOW_COPY_AND_ASSIGN(InlineXmlFormatParser);
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070063
Adam Lesinskice5e56e2016-10-21 17:56:45 -070064 std::vector<std::unique_ptr<xml::XmlResource>> queue_;
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070065};
66
Adam Lesinskicacb28f2016-10-19 12:18:14 -070067} // namespace aapt
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070068
69#endif /* AAPT_COMPILE_INLINEXMLFORMATPARSER_H */