private ParametersType extractParamTypes(Node node, boolean isDefaultNode) { // add parameters ParametersType paramTypes = isDefaultNode ? ObjectFactory.getInstance().createParametersType() : ObjectFactory.getInstance().createConfigType(); NodeList paramsList = node.getChildNodes(); for (int z = 0; z < paramsList.getLength(); z++) { Node paramNode = paramsList.item(z); if ((paramNode != null) && (paramNode.getNodeType() == Node.ELEMENT_NODE)) { String paramName = paramNode.getNodeName(); Node valueNode = paramNode.getFirstChild(); String paramValue = valueNode.getNodeValue(); if (paramName.equalsIgnoreCase("d:country-code")) { paramTypes.setCountryCode(Float.parseFloat(paramValue)); } else if (paramName.equalsIgnoreCase("d:network-code")) { paramTypes.setNetworkCode(Float.parseFloat(paramValue)); } else if (paramName.equalsIgnoreCase("d:screen-size")) { paramTypes.setScreenSize(paramValue); } else if (paramName.equalsIgnoreCase("d:screen-ratio")) { paramTypes.setScreenRatio(paramValue); } else if (paramName.equalsIgnoreCase("d:screen-orientation")) { paramTypes.setScreenOrientation(paramValue); } else if (paramName.equalsIgnoreCase("d:pixel-density")) { paramTypes.setPixelDensity(paramValue); } else if (paramName.equalsIgnoreCase("d:touch-type")) { paramTypes.setTouchType(paramValue); } else if (paramName.equalsIgnoreCase("d:keyboard-state")) { paramTypes.setKeyboardState(paramValue); } else if (paramName.equalsIgnoreCase("d:text-input-method")) { paramTypes.setTextInputMethod(paramValue); } else if (paramName.equalsIgnoreCase("d:nav-state")) { paramTypes.setNavState(paramValue); } else if (paramName.equalsIgnoreCase("d:nav-method")) { paramTypes.setNavMethod(paramValue); } else if (paramName.equalsIgnoreCase("d:screen-dimension")) { ScreenDimension dim = ObjectFactory.getInstance().createParametersTypeScreenDimension(); NodeList dimensionList = paramNode.getChildNodes(); for (int w = 0; w < dimensionList.getLength(); w++) { Node dimensionNode = dimensionList.item(w); if ((dimensionNode != null) && (dimensionNode.getNodeType() == Node.ELEMENT_NODE)) { Node sizeNode = dimensionNode.getFirstChild(); String dimValue = sizeNode.getNodeValue(); dim.addSize(Integer.parseInt(dimValue)); } } paramTypes.setScreenDimension(dim); } else if (paramName.equalsIgnoreCase("d:xdpi")) { paramTypes.setXdpi(Float.parseFloat(paramValue)); } else if (paramName.equalsIgnoreCase("d:ydpi")) { paramTypes.setYdpi(Float.parseFloat(paramValue)); } } } return paramTypes; }
/** * Reads XML that contains the specifications of a given device. * * @return {@link LayoutDevicesType} representing the device read. * @throws ParserConfigurationException * @throws SAXException * @throws IOException */ public LayoutDevicesType read() throws ParserConfigurationException, SAXException, IOException { LayoutDevicesType layoutDevicesType = ObjectFactory.getInstance().createLayoutDevicesType(); NodeList deviceList = document.getElementsByTagName(D_DEVICE); for (int i = 0; i < deviceList.getLength(); i++) { Node deviceNode = deviceList.item(i); NamedNodeMap deviceNodeAttrs = deviceNode.getAttributes(); Node deviceIdAtr = deviceNodeAttrs.getNamedItem("id"); if ((deviceIdAtr != null) && !deviceIdAtr.getNodeValue().trim().equals("")) // $NON-NLS-1$ { // add device Device dev = new Device(); dev.setId(deviceIdAtr.getNodeValue()); dev.setName(extractValueFromAttributes(deviceNodeAttrs, "name")); dev.setProvider(extractValueFromAttributes(deviceNodeAttrs, "provider")); NodeList defaultOrConfigList = deviceNode.getChildNodes(); for (int j = 0; j < defaultOrConfigList.getLength(); j++) { Node defaultOrConfigNode = defaultOrConfigList.item(j); if ((defaultOrConfigNode != null) && (defaultOrConfigNode.getNodeType() == Node.ELEMENT_NODE)) { if (defaultOrConfigNode.getNodeName().equalsIgnoreCase(D_SUPPORTED_FEATURES)) { NodeList paramsList = defaultOrConfigNode.getChildNodes(); for (int z = 0; z < paramsList.getLength(); z++) { Node supportedFeatureNode = paramsList.item(z); if ((supportedFeatureNode != null) && (supportedFeatureNode.getNodeType() == Node.ELEMENT_NODE)) { Node valueNode = supportedFeatureNode.getFirstChild(); String supportedFeatureValue = valueNode.getNodeValue(); if ((supportedFeatureValue != null) && !supportedFeatureValue.equals("")) { dev.getSupportedFeatures().add(new Feature(supportedFeatureValue)); } } } } else { boolean isDefault = defaultOrConfigNode.getNodeName().equalsIgnoreCase(D_DEFAULT); ParametersType paramTypes = extractParamTypes(defaultOrConfigNode, isDefault); if (!(paramTypes instanceof ConfigType)) { // default dev.setDefault(paramTypes); } else { // config NamedNodeMap configAttrs = defaultOrConfigNode.getAttributes(); Node configAtr = configAttrs.getNamedItem("name"); if ((configAtr != null) && !configAtr.getNodeValue().trim().equals("")) { ConfigType type = (ConfigType) paramTypes; type.setName(configAtr.getNodeValue()); dev.addConfig(type); } } } } } layoutDevicesType.getDevices().add(dev); } } return layoutDevicesType; }