OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / sdk / eclipse / plugins / com.android.ide.eclipse.adt / src / com / android / ide / eclipse / adt / internal / sdk / LayoutDevicesXsd.java
1 /*\r
2  * Copyright (C) 2009 The Android Open Source Project\r
3  *\r
4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *      http://www.eclipse.org/org/documents/epl-v10.php\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 package com.android.ide.eclipse.adt.internal.sdk;\r
18 \r
19 \r
20 import org.xml.sax.ErrorHandler;\r
21 import org.xml.sax.SAXException;\r
22 \r
23 import java.io.InputStream;\r
24 \r
25 import javax.xml.XMLConstants;\r
26 import javax.xml.transform.stream.StreamSource;\r
27 import javax.xml.validation.Schema;\r
28 import javax.xml.validation.SchemaFactory;\r
29 import javax.xml.validation.Validator;\r
30 \r
31 /**\r
32  * Public constants for the layout device description XML Schema.\r
33  */\r
34 public class LayoutDevicesXsd {\r
35 \r
36     /** The XML namespace of the layout-configs XML. */\r
37     public static final String NS_LAYOUT_DEVICE_XSD =\r
38         "http://schemas.android.com/sdk/android/layout-devices/1";                  //$NON-NLS-1$\r
39 \r
40     /**\r
41      * The "layout-devices" element is the root element of this schema.\r
42      *\r
43      * It must contain one or more "device" elements that each define the configurations\r
44      * available for a given device.\r
45      *\r
46      * These definitions are used in the Graphical Layout Editor in the\r
47      * Android Development Tools (ADT) plugin for Eclipse.\r
48      */\r
49     public static final String NODE_LAYOUT_DEVICES = "layout-devices";              //$NON-NLS-1$\r
50 \r
51     /**\r
52      * A device element must contain at most one "default" element followed\r
53      * by one or more ""config" elements.\r
54      *\r
55      * The "default" element defines all the default parameters inherited\r
56      * by the following "config" elements. Each "config" element can override\r
57      * the default values, if any.\r
58      *\r
59      * A "device" element also has a required "name" attribute that represents\r
60      * the user-interface name of this device.\r
61      */\r
62     public static final String NODE_DEVICE = "device";                              //$NON-NLS-1$\r
63 \r
64     /**\r
65      * The "default" element contains zero or more of all the parameter elements\r
66      * listed below. It defines all the parameters that are common to all\r
67      * declared "config" elements.\r
68      */\r
69     public static final String NODE_DEFAULT = "default";                            //$NON-NLS-1$\r
70 \r
71     /**\r
72      * The "config" element contains zero or more of all the parameter elements\r
73      * listed below. The parameters from the "default" element (if present) are\r
74      * automatically inherited and can be overridden.\r
75      */\r
76     public static final String NODE_CONFIG = "config";                              //$NON-NLS-1$\r
77 \r
78 \r
79     public static final String NODE_COUNTRY_CODE = "country-code";                  //$NON-NLS-1$\r
80 \r
81     public static final String NODE_NETWORK_CODE = "network-code";                  //$NON-NLS-1$\r
82 \r
83     public static final String NODE_SCREEN_SIZE = "screen-size";                    //$NON-NLS-1$\r
84 \r
85     public static final String NODE_SCREEN_RATIO = "screen-ratio";                  //$NON-NLS-1$\r
86 \r
87     public static final String NODE_SCREEN_ORIENTATION = "screen-orientation";      //$NON-NLS-1$\r
88 \r
89     public static final String NODE_PIXEL_DENSITY = "pixel-density";                //$NON-NLS-1$\r
90 \r
91     public static final String NODE_TOUCH_TYPE = "touch-type";                      //$NON-NLS-1$\r
92 \r
93     public static final String NODE_KEYBOARD_STATE = "keyboard-state";              //$NON-NLS-1$\r
94 \r
95     public static final String NODE_TEXT_INPUT_METHOD = "text-input-method";        //$NON-NLS-1$\r
96 \r
97     public static final String NODE_NAV_STATE = "nav-state";                        //$NON-NLS-1$\r
98 \r
99     public static final String NODE_NAV_METHOD = "nav-method";                      //$NON-NLS-1$\r
100 \r
101     public static final String NODE_SCREEN_DIMENSION = "screen-dimension";          //$NON-NLS-1$\r
102 \r
103     /** The screen-dimension element has 2 size element children. */\r
104     public static final String NODE_SIZE = "size";                                  //$NON-NLS-1$\r
105 \r
106     public static final String NODE_XDPI = "xdpi";                                  //$NON-NLS-1$\r
107 \r
108     public static final String NODE_YDPI = "ydpi";                                  //$NON-NLS-1$\r
109 \r
110     /**\r
111      * The "name" attribute, used by both the "device" and the "config"\r
112      * elements. It represents the user-interface name of these objects.\r
113      */\r
114     public static final String ATTR_NAME = "name";                                  //$NON-NLS-1$\r
115 \r
116     /**\r
117      * Helper to get an input stream of the layout config XML schema.\r
118      */\r
119     public static InputStream getXsdStream() {\r
120         return LayoutDevicesXsd.class.getResourceAsStream("layout-devices.xsd");    //$NON-NLS-1$\r
121     }\r
122 \r
123     /** Helper method that returns a {@link Validator} for our XSD */\r
124     public static Validator getValidator(ErrorHandler handler) throws SAXException {\r
125         InputStream xsdStream = getXsdStream();\r
126         SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);\r
127         Schema schema = factory.newSchema(new StreamSource(xsdStream));\r
128         Validator validator = schema.newValidator();\r
129         if (handler != null) {\r
130             validator.setErrorHandler(handler);\r
131         }\r
132 \r
133         return validator;\r
134     }\r
135 \r
136 }\r