2 * Copyright (C) 2009 The Android Open Source Project
\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
8 * http://www.eclipse.org/org/documents/epl-v10.php
\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
17 package com.android.ide.eclipse.adt.internal.sdk;
\r
20 import org.xml.sax.ErrorHandler;
\r
21 import org.xml.sax.SAXException;
\r
23 import java.io.InputStream;
\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
32 * Public constants for the layout device description XML Schema.
\r
34 public class LayoutDevicesXsd {
\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
41 * The "layout-devices" element is the root element of this schema.
\r
43 * It must contain one or more "device" elements that each define the configurations
\r
44 * available for a given device.
\r
46 * These definitions are used in the Graphical Layout Editor in the
\r
47 * Android Development Tools (ADT) plugin for Eclipse.
\r
49 public static final String NODE_LAYOUT_DEVICES = "layout-devices"; //$NON-NLS-1$
\r
52 * A device element must contain at most one "default" element followed
\r
53 * by one or more ""config" elements.
\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
59 * A "device" element also has a required "name" attribute that represents
\r
60 * the user-interface name of this device.
\r
62 public static final String NODE_DEVICE = "device"; //$NON-NLS-1$
\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
69 public static final String NODE_DEFAULT = "default"; //$NON-NLS-1$
\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
76 public static final String NODE_CONFIG = "config"; //$NON-NLS-1$
\r
79 public static final String NODE_COUNTRY_CODE = "country-code"; //$NON-NLS-1$
\r
81 public static final String NODE_NETWORK_CODE = "network-code"; //$NON-NLS-1$
\r
83 public static final String NODE_SCREEN_SIZE = "screen-size"; //$NON-NLS-1$
\r
85 public static final String NODE_SCREEN_RATIO = "screen-ratio"; //$NON-NLS-1$
\r
87 public static final String NODE_SCREEN_ORIENTATION = "screen-orientation"; //$NON-NLS-1$
\r
89 public static final String NODE_PIXEL_DENSITY = "pixel-density"; //$NON-NLS-1$
\r
91 public static final String NODE_TOUCH_TYPE = "touch-type"; //$NON-NLS-1$
\r
93 public static final String NODE_KEYBOARD_STATE = "keyboard-state"; //$NON-NLS-1$
\r
95 public static final String NODE_TEXT_INPUT_METHOD = "text-input-method"; //$NON-NLS-1$
\r
97 public static final String NODE_NAV_STATE = "nav-state"; //$NON-NLS-1$
\r
99 public static final String NODE_NAV_METHOD = "nav-method"; //$NON-NLS-1$
\r
101 public static final String NODE_SCREEN_DIMENSION = "screen-dimension"; //$NON-NLS-1$
\r
103 /** The screen-dimension element has 2 size element children. */
\r
104 public static final String NODE_SIZE = "size"; //$NON-NLS-1$
\r
106 public static final String NODE_XDPI = "xdpi"; //$NON-NLS-1$
\r
108 public static final String NODE_YDPI = "ydpi"; //$NON-NLS-1$
\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
114 public static final String ATTR_NAME = "name"; //$NON-NLS-1$
\r
117 * Helper to get an input stream of the layout config XML schema.
\r
119 public static InputStream getXsdStream() {
\r
120 return LayoutDevicesXsd.class.getResourceAsStream("layout-devices.xsd"); //$NON-NLS-1$
\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