1// Copyright 2018 The Bazel Authors. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package res 16 17import ( 18 "encoding/xml" 19) 20 21var ( 22 // IDAttrName is the android:id attribute xml name. 23 // It appears anywhere an xml document wishes to associate a tag to a given android id. 24 IDAttrName = xml.Name{Space: "http://schemas.android.com/apk/res/android", Local: "id"} 25 26 // ResourcesTagName <resources> tag wraps all xml documents in res/values directory. These 27 // documents are reasonably well structured, and its children _normally_ end up becoming 28 // ResourceValues in Android. The exception being <declare-styleable> and <attr> which 29 // define how to interpret and store attributes in xml files outside of res/values. 30 ResourcesTagName = xml.Name{Local: "resources"} 31 32 // ItemTagName is used in various ways in a <resources> tag. If it is a direct child, it can 33 // only denote an id resource. Otherwise, it can be a child of array/*-array and denotes the 34 // type and wraps the value of the item of the array. 35 ItemTagName = xml.Name{Local: "item"} 36 37 // NameAttrName is an attribute that is expected to be encountered on every tag that is a 38 // direct child of <resources>. The value of this tag is the name of the resource that is 39 // being generated. 40 NameAttrName = xml.Name{Local: "name"} 41 42 // TypeAttrName is the type attribute xml name. 43 // It appears in the <item> tag when the item wants to specify its type. 44 TypeAttrName = xml.Name{Local: "type"} 45 46 // EnumTagName <enum> appears beneath <attr/> tags to define valid enum values for an attribute. 47 EnumTagName = xml.Name{Local: "enum"} 48 49 // FlagTagName <flag> appears beneath <attr/> tags to define valid flag values for an attribute. 50 FlagTagName = xml.Name{Local: "flag"} 51 52 // ResourcesTagToType maps the child tag name of resources to the resource type it will generate. 53 ResourcesTagToType = map[string]Type{ 54 "array": Array, 55 "integer-array": Array, 56 "string-array": Array, 57 "attr": Attr, 58 "^attr-private": AttrPrivate, 59 "bool": Bool, 60 "color": Color, 61 "configVarying": ConfigVarying, 62 "dimen": Dimen, 63 "drawable": Drawable, 64 "fraction": Fraction, 65 "id": ID, 66 "integer": Integer, 67 "layout": Layout, 68 "plurals": Plurals, 69 "string": String, 70 "style": Style, 71 "declare-styleable": Styleable, 72 } 73 74 // ResourcesChildToSkip a map containing child tags that can be skipped while parsing resources. 75 ResourcesChildToSkip = map[xml.Name]bool{ 76 {Local: "skip"}: true, 77 {Local: "eat-comment"}: true, 78 {Local: "public"}: true, 79 } 80) 81 82const ( 83 // GeneratedIDPrefix prefixes an attribute value whose name is IDAttrName, it indicates that 84 // this id likely does not exist outside of the current document and a new Id Resource for 85 // this value. 86 GeneratedIDPrefix = "@+id" 87) 88