public ResultValue(Node node) { NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); if (n.getNodeName().equals("class")) { matlabClass = n.getTextContent(); } if (n.getNodeName().equals("size")) { size = string2intList(n.getTextContent()); numdims = size.size(); numel = 1; for (int d : size) { numel *= d; } } if (n.getNodeName().equals("matrix")) { resultType = RESULT_TYPE.MATRIX; matrixResult = string2doubleList(n.getTextContent()); } if (n.getNodeName().equals("imagMatrix")) { isReal = false; resultType = RESULT_TYPE.MATRIX; imagMatrixResult = string2doubleList(n.getTextContent()); } if (n.getNodeName().equals("char")) { resultType = RESULT_TYPE.CHAR; charResult = n.getTextContent(); } if (n.getNodeName().equals("logical")) { resultType = RESULT_TYPE.LOGICAL; logicalResult = string2booleanList(n.getTextContent()); } if (n.getNodeName().equals("handle")) { resultType = RESULT_TYPE.HANDLE; } if (n.getNodeName().equals("struct")) { resultType = RESULT_TYPE.STRUCT; // create struct list for first occurence of struct if (structResult == null) { structResult = new ArrayList<HashMap<String, ResultValue>>(); } // build struct HashMap<String, ResultValue> struct = new HashMap<String, ResultValue>(); NodeList children = n.getChildNodes(); for (int j = 0; j < children.getLength(); j++) { Node child = children.item(j); if (child.getNodeType() == Node.ELEMENT_NODE) { struct.put(child.getNodeName(), new ResultValue(child)); } } structResult.add(struct); } if (n.getNodeName().equals("cell")) { resultType = RESULT_TYPE.CELL; } } }
private void loadFromXml(String fileName) throws ParserConfigurationException, SAXException, IOException, ParseException { System.out.println("NeuralNetwork : loading network topology from file " + fileName); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser = factory.newDocumentBuilder(); Document doc = parser.parse(fileName); Node nodeNeuralNetwork = doc.getDocumentElement(); if (!nodeNeuralNetwork.getNodeName().equals("neuralNetwork")) throw new ParseException( "[Error] NN-Load: Parse error in XML file, neural network couldn't be loaded.", 0); // nodeNeuralNetwork ok // indexNeuralNetworkContent -> indexStructureContent -> indexLayerContent -> indexNeuronContent // -> indexNeuralInputContent NodeList nodeNeuralNetworkContent = nodeNeuralNetwork.getChildNodes(); for (int innc = 0; innc < nodeNeuralNetworkContent.getLength(); innc++) { Node nodeStructure = nodeNeuralNetworkContent.item(innc); if (nodeStructure.getNodeName().equals("structure")) { // for structure element NodeList nodeStructureContent = nodeStructure.getChildNodes(); for (int isc = 0; isc < nodeStructureContent.getLength(); isc++) { Node nodeLayer = nodeStructureContent.item(isc); if (nodeLayer.getNodeName().equals("layer")) { // for layer element NeuralLayer neuralLayer = new NeuralLayer(this); this.listLayers.add(neuralLayer); NodeList nodeLayerContent = nodeLayer.getChildNodes(); for (int ilc = 0; ilc < nodeLayerContent.getLength(); ilc++) { Node nodeNeuron = nodeLayerContent.item(ilc); if (nodeNeuron.getNodeName().equals("neuron")) { // for neuron in layer Neuron neuron = new Neuron( Double.parseDouble(((Element) nodeNeuron).getAttribute("threshold")), neuralLayer); neuralLayer.listNeurons.add(neuron); NodeList nodeNeuronContent = nodeNeuron.getChildNodes(); for (int inc = 0; inc < nodeNeuronContent.getLength(); inc++) { Node nodeNeuralInput = nodeNeuronContent.item(inc); // if (nodeNeuralInput==null) System.out.print("-"); else System.out.print("*"); if (nodeNeuralInput.getNodeName().equals("input")) { // System.out.println("neuron at // STR:"+innc+" LAY:"+isc+" NEU:"+ilc+" INP:"+inc); NeuralInput neuralInput = new NeuralInput( Double.parseDouble(((Element) nodeNeuralInput).getAttribute("weight")), neuron); neuron.listInputs.add(neuralInput); } } } } } } } } }
static { try { URL url = SpellCheckActivator.bundleContext.getBundle().getResource(RESOURCE_LOC); InputStream stream = url.openStream(); if (stream == null) throw new IOException(); // strict parsing options DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); // parses configuration xml /*- * Warning: Felix is unable to import the com.sun.rowset.internal * package, meaning this can't use the XmlErrorHandler. This causes * a warning and a default handler to be attached. Otherwise this * should have: builder.setErrorHandler(new XmlErrorHandler()); */ DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(stream); // iterates over nodes, parsing contents Node root = doc.getChildNodes().item(1); NodeList categories = root.getChildNodes(); for (int i = 0; i < categories.getLength(); ++i) { Node node = categories.item(i); if (node.getNodeName().equals(NODE_DEFAULTS)) { parseDefaults(node.getChildNodes()); } else if (node.getNodeName().equals(NODE_LOCALES)) { parseLocales(node.getChildNodes()); } else { logger.warn("Unrecognized category: " + node.getNodeName()); } } } catch (IOException exc) { logger.error("Unable to load spell checker parameters", exc); } catch (SAXException exc) { logger.error("Unable to parse spell checker parameters", exc); } catch (ParserConfigurationException exc) { logger.error("Unable to parse spell checker parameters", exc); } }
public static final Map parseFrame(Node node) { NodeList bones = node.getChildNodes(); Map bone_infos = new HashMap(); for (int i = 0; i < bones.getLength(); i++) { Node bone = bones.item(i); if (bone.getNodeName().equals("transform")) { String name = bone.getAttributes().getNamedItem("name").getNodeValue(); float[] matrix = new float[16]; matrix[0 * 4 + 0] = getAttrFloat(bone, "m00"); matrix[0 * 4 + 1] = getAttrFloat(bone, "m01"); matrix[0 * 4 + 2] = getAttrFloat(bone, "m02"); matrix[0 * 4 + 3] = getAttrFloat(bone, "m03"); matrix[1 * 4 + 0] = getAttrFloat(bone, "m10"); matrix[1 * 4 + 1] = getAttrFloat(bone, "m11"); matrix[1 * 4 + 2] = getAttrFloat(bone, "m12"); matrix[1 * 4 + 3] = getAttrFloat(bone, "m13"); matrix[2 * 4 + 0] = getAttrFloat(bone, "m20"); matrix[2 * 4 + 1] = getAttrFloat(bone, "m21"); matrix[2 * 4 + 2] = getAttrFloat(bone, "m22"); matrix[2 * 4 + 3] = getAttrFloat(bone, "m23"); matrix[3 * 4 + 0] = getAttrFloat(bone, "m30"); matrix[3 * 4 + 1] = getAttrFloat(bone, "m31"); matrix[3 * 4 + 2] = getAttrFloat(bone, "m32"); matrix[3 * 4 + 3] = getAttrFloat(bone, "m33"); bone_infos.put(name, matrix); } } return bone_infos; }
private static Command parseCommand(Node n) { NamedNodeMap atts = n.getAttributes(); String name = atts.getNamedItem("name").getNodeValue(); String desc = atts.getNamedItem("description").getNodeValue(); String command = atts.getNamedItem("command").getNodeValue(); Command com = new Command(name, desc, command); NodeList children = n.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (!child.getNodeName().equals("Argument")) continue; NamedNodeMap childAtts = child.getAttributes(); String childName = childAtts.getNamedItem("name").getNodeValue(); String childDesc = childAtts.getNamedItem("description").getNodeValue(); String childVal = ""; if (childAtts.getNamedItem("default") != null) childVal = childAtts.getNamedItem("default").getNodeValue(); Argument arg = new Argument(childName, childDesc, childVal); com.addArgument(arg); } return com; }
/** * Honey, can you just check on the kids? Thanks. * * <p>Internal function; not included in reference. */ protected void checkChildren() { if (children == null) { NodeList kids = node.getChildNodes(); int childCount = kids.getLength(); children = new XML[childCount]; for (int i = 0; i < childCount; i++) { children[i] = new XML(this, kids.item(i)); } } }
private static String getTextContent(Node n) { NodeList nodeList = n.getChildNodes(); String textContent = ""; for (int j = 0; j < nodeList.getLength(); j++) { Node k = nodeList.item(j); if (k.getNodeType() == Node.TEXT_NODE) { textContent = k.getNodeValue(); break; } } return textContent; }
public static void traverseAMLforObjectNames( HashMap partialMap, Node currentNode, HashMap ObjDef_LinkId, HashMap ModelId_ModelType) { if (currentNode.hasChildNodes()) { for (int i = 0; i < currentNode.getChildNodes().getLength(); i++) { Node currentChild = currentNode.getChildNodes().item(i); if (currentChild.getNodeName().equals("Group")) { traverseAMLforObjectNames(partialMap, currentChild, ObjDef_LinkId, ModelId_ModelType); } if (currentChild.getNodeName().equals("Model")) { if (currentChild.hasAttributes()) { String mid = currentChild.getAttributes().getNamedItem("Model.ID").getNodeValue(); String type = currentChild.getAttributes().getNamedItem("Model.Type").getNodeValue(); ModelId_ModelType.put(mid, type); } // traverseAMLforObjectNames(partialMap, currentChild, // ObjDef_LinkId); } if (currentChild.getNodeName().equals("ObjDef")) { String id = currentChild.getAttributes().getNamedItem("ObjDef.ID").getNodeValue(); NodeList currentChildren = currentChild.getChildNodes(); String ObjName = ""; for (int k = 0; k < currentChildren.getLength(); k++) { Node Child = currentChildren.item(k); if (!Child.getNodeName().equals("AttrDef")) { continue; } else if (!Child.getAttributes() .getNamedItem("AttrDef.Type") .getNodeValue() .equals("AT_NAME")) { continue; } else if (Child.hasChildNodes()) { for (int l = 0; l < Child.getChildNodes().getLength(); l++) { if (!(Child.getChildNodes().item(l).getNodeName().equals("AttrValue"))) { continue; } else { ObjName = getTextContent(Child.getChildNodes().item(l)); ObjName = ObjName.replaceAll("\n", "\\\\n"); break; } } } } partialMap.put(id, ObjName); for (int j = 0; j < currentChild.getAttributes().getLength(); j++) { if (currentChild.getAttributes().item(j).getNodeName().equals("LinkedModels.IdRefs")) { String links = currentChild.getAttributes().getNamedItem("LinkedModels.IdRefs").getNodeValue(); /* * if (links.indexOf(" ") > -1) { * Message.add("yes, yes, yes"); links = * links.substring(0, links.indexOf(" ")); } */ ObjDef_LinkId.put(id, links); } } } } } }
private static Category parseCategory(Node n) { NamedNodeMap atts = n.getAttributes(); String name = atts.getNamedItem("name").getNodeValue(); String desc = atts.getNamedItem("description").getNodeValue(); Category cat = new Category(name, desc); NodeList children = n.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { parseNode(children.item(i), cat); } return cat; }
private String sustraerInformacionNodo(CliGol cliGol, Node nodo) { String[] excluye = { "CLI_ID", "CLI_SAP", "CliApePat", "CliApeMat", "CliNom", "CLI_FEC_NAC", "CLI_DOM_CAL", "CLI_DOM_NUM_EXT", "CLI_DOM_NUM_INT", "CLI_DOM_COL", "CLI_POS_ID", "CliGolP1", "CliGolP8", "CliGolP10", "CliGolP11", "CliGolP15", "CliGolP17", "CliGolP18", "CliGolP25", "CliGolResAct", "CliGolNumTar", "CliGolCtaChe", "CliGolCrePer", "CliGolCreAut", "CliGolCreHip", "CliGolOtrCre", "CliBurMens", "PagRnt", "CliGolBurCre", "CliBurValr", "CliGolIng", "CliGolImpRen" }; NodeList variables = nodo.getChildNodes(); LinkedHashMap[] mapas = obtenerMapeos(cliGol, variables, excluye); Dao dao = new Dao(); Object[] descripciones = dao.ObtenLista(mapas[0], Arrays.asList(excluye)); // <variable,puntos>,descripciones return unirMapeos(mapas[1], descripciones); }
/* return the value of the XML text node (never null) */ protected static String GetNodeText(Node root) { StringBuffer sb = new StringBuffer(); if (root != null) { NodeList list = root.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); if (n.getNodeType() == Node.CDATA_SECTION_NODE) { // CDATA Section sb.append(n.getNodeValue()); } else if (n.getNodeType() == Node.TEXT_NODE) { sb.append(n.getNodeValue()); } else { // Print.logWarn("Unrecognized node type: " + n.getNodeType()); } } } return sb.toString(); }
public static XMLResult readResult(GenericFile file) { Node node = readXmlFile(file); XMLResult result = new XMLResult(); NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); if (n.getNodeName().equals("success")) { result.success = string2booleanList(n.getTextContent()).get(0); } if (n.getNodeName().equals("result")) { result.resultValue = new ResultValue(n); } if (n.getNodeName().equals("error")) { result.resultValue = new ResultValue(n); result.error = result.resultValue.structResult.get(0).get("identifier").charResult; result.message = result.resultValue.structResult.get(0).get("message").charResult; } } return result; }
private static final Map[] parseAnimation(Node node) { NodeList frames = node.getChildNodes(); Map anim_infos_map = new HashMap(); for (int i = 0; i < frames.getLength(); i++) { Node frame = frames.item(i); if (frame.getNodeName().equals("frame")) { int frame_index = getAttrInt(frame, "index"); assert frame_index >= 0; anim_infos_map.put(new Integer(frame_index), parseFrame(frame)); } } Map[] anim_infos = new Map[anim_infos_map.size()]; Iterator it = anim_infos_map.keySet().iterator(); while (it.hasNext()) { Integer frame_index_obj = (Integer) it.next(); Map frame = (Map) anim_infos_map.get(frame_index_obj); int index = frame_index_obj.intValue(); assert anim_infos[index] == null; anim_infos[index] = frame; } return anim_infos; }
private static void parseXML() { try { Document doc = DocumentBuilderFactory.newInstance() .newDocumentBuilder() .parse(CommandBuilder.class.getResourceAsStream("/CommandMap.xml")); NodeList nodes = doc.getElementsByTagName("CommandMap"); for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); NamedNodeMap atts = n.getAttributes(); String rootCommand = atts.getNamedItem("rootCommand").getNodeValue(); rootNode = new Category(rootCommand, ""); NodeList children = n.getChildNodes(); for (int p = 0; p < children.getLength(); p++) { parseNode(children.item(p), rootNode); } } } catch (Exception e) { e.printStackTrace(); } }
/** Возвращает список методов класса. */ public List<MethodNode> getMethods() { ArrayList<MethodNode> methods = new ArrayList<MethodNode>(); /** * Получаем список дочерних узлов для данного узла XML, который соответствует классу class. * Здесь будут располагаться все узлы Node, каждый из которых является объектным * представлением тега method для текущего тега class. */ NodeList methodNodes = node.getChildNodes(); for (int i = 0; i < methodNodes.getLength(); i++) { node = methodNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { /** Создаем на основе Node узла своё объектное представление метода. */ MethodNode methodNode = new MethodNode(node); methods.add(methodNode); } } return methods; }
public List<ClassNode> getClasses() { ArrayList<ClassNode> classes = new ArrayList<ClassNode>(); /** * Получаем список дочерних узлов для данного узла XML, который соответствует приложению * application. Здесь будут располагаться все узлы Node, каждый из которых является объектным * представлением тега class для текущего тега application. */ NodeList classNodes = node.getChildNodes(); for (int i = 0; i < classNodes.getLength(); i++) { Node node = classNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { /** Создаем на основе Node узла своё объектное представление класса. */ ClassNode classNode = new ClassNode(node); classes.add(classNode); } } return classes; }
private static void parseNet( Node node, EPC net, HashMap ObjDef_Name, HashMap ObjDef_LinkId, HashMap function_LinkId, String ModelName) throws Exception { HashMap mapping = new HashMap(); // read all nodes NodeList nodes = node.getChildNodes(); net.setIdentifier(ModelName); // Message.add("here I am still happy"); for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); if (!n.getNodeName().equals("ObjOcc")) { continue; } if (n.getAttributes().getNamedItem("SymbolNum") == null) { continue; } String symbolnum = n.getAttributes().getNamedItem("SymbolNum").getNodeValue(); if (!(symbolnum.equals("ST_FUNC") || symbolnum.equals("ST_EV") || symbolnum.equals("ST_OPR_AND_1") || symbolnum.equals("ST_OPR_OR_1") || symbolnum.equals("ST_OPR_XOR_1"))) { continue; } String ObjDef = n.getAttributes().getNamedItem("ObjDef.IdRef").getNodeValue(); String ownName = (String) ObjDef_Name.get(ObjDef); // Message.add("YES " + // n.getAttributes().getNamedItem("ObjOcc.ID").getNodeValue()); String id = n.getAttributes().getNamedItem("ObjOcc.ID").getNodeValue(); // Message.add(id + " " + ownName); if (ownName == null || ownName == "") { ownName = id.substring(7, 11); } if (symbolnum.equals("ST_FUNC")) { if (ObjDef_LinkId.containsKey(ObjDef)) { EPCSubstFunction sf = (EPCSubstFunction) net.addFunction( new EPCSubstFunction(new LogEvent(ownName, "unknown:normal"), net, null)); sf.setIdentifier(ownName); mapping.put(id, sf); function_LinkId.put(sf, ObjDef_LinkId.get(ObjDef)); } else { EPCFunction f = net.addFunction(new EPCFunction(new LogEvent(ownName, "unknown:normal"), net)); f.setIdentifier(ownName); mapping.put(id, f); } } else if (symbolnum.equals("ST_EV")) { EPCEvent e = net.addEvent(new EPCEvent(ownName, net)); e.setIdentifier(ownName); mapping.put(id, e); } else if (symbolnum.equals("ST_OPR_AND_1")) { EPCConnector c = net.addConnector(new EPCConnector(EPCConnector.AND, net)); mapping.put(id, c); } else if (symbolnum.equals("ST_OPR_OR_1")) { // EPCConnector c = net.addConnector(new // EPCConnector(EPCConnector.OR, net)); EPCConnector c = net.addConnector(new EPCConnector(EPCConnector.AND, net)); mapping.put(id, c); } else if (symbolnum.equals("ST_OPR_XOR_1")) { EPCConnector c = net.addConnector(new EPCConnector(EPCConnector.XOR, net)); mapping.put(id, c); } } for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); if (!n.getNodeName().equals("ObjOcc")) { continue; } if (n.getAttributes().getNamedItem("SymbolNum") == null) { continue; } String symbolnum = n.getAttributes().getNamedItem("SymbolNum").getNodeValue(); if (!(symbolnum.equals("ST_FUNC") || symbolnum.equals("ST_EV") || symbolnum.equals("ST_OPR_AND_1") || symbolnum.equals("ST_OPR_OR_1") || symbolnum.equals("ST_OPR_XOR_1"))) { continue; } String source = n.getAttributes().getNamedItem("ObjOcc.ID").getNodeValue(); if (n.hasChildNodes()) { for (int j = 0; j < n.getChildNodes().getLength(); j++) { if (n.getChildNodes().item(j).getNodeName().equals("CxnOcc")) { Node CxnOcc = n.getChildNodes().item(j); String dest = CxnOcc.getAttributes().getNamedItem("ToObjOcc.IdRef").getNodeValue(); if (mapping.get(dest) == null) { continue; } if (net.addEdge((EPCObject) mapping.get(source), (EPCObject) mapping.get(dest)) == null) { throw (new Exception( "<html>Structural properties of EPCs are violated in input file.<br>" + "The following edge could not be added:<br><br>" + mapping.get(source).toString() + " ==> " + mapping.get(dest).toString() + "<br><br>Import aborted.</html>")); } } } } } }
public static EPCResult traverseAML( EPCResult partialResult, Node currentNode, Object parent, HashMap ObjDef_Name, HashMap ObjDef_LinkId, HashMap modelid_net, HashMap function_LinkId) throws Exception { if (currentNode.hasChildNodes()) { for (int i = 0; i < currentNode.getChildNodes().getLength(); i++) { Node currentChild = currentNode.getChildNodes().item(i); if (currentChild.getNodeName().equals("Group")) { String id = currentChild.getAttributes().getNamedItem("Group.ID").getNodeValue(); String GroupName = ""; if (currentChild.hasChildNodes()) { NodeList currentChildren = currentChild.getChildNodes(); for (int j = 0; j < currentChildren.getLength(); j++) { Node Child = currentChildren.item(j); if (!(Child.getNodeName().equals("AttrDef"))) { continue; } if (Child.getAttributes() .getNamedItem("AttrDef.Type") .getNodeValue() .equals("AT_NAME")) { if (Child.hasChildNodes()) { for (int l = 0; l < Child.getChildNodes().getLength(); l++) { if (!(Child.getChildNodes().item(l).getNodeName().equals("AttrValue"))) { continue; } else { GroupName = getTextContent(Child.getChildNodes().item(l)); } } break; } } } if (GroupName.equals("")) { GroupName = id; } } ModelHierarchyDirectory dir = new ModelHierarchyDirectory(id, GroupName); partialResult.addInHierarchy(dir, parent, GroupName); partialResult = traverseAML( partialResult, currentChild, dir, ObjDef_Name, ObjDef_LinkId, modelid_net, function_LinkId); } if (currentChild.getNodeName().equals("Model") && currentChild .getAttributes() .getNamedItem("Model.Type") .getNodeValue() .equals("MT_EEPC")) { String ModelName = "gaga"; if (currentChild.hasChildNodes()) { NodeList currentChildren = currentChild.getChildNodes(); for (int j = 0; j < currentChildren.getLength(); j++) { Node Child = currentChildren.item(j); if (!(Child.getNodeName().equals("AttrDef"))) { continue; } if (Child.getAttributes() .getNamedItem("AttrDef.Type") .getNodeValue() .equals("AT_NAME")) { if (Child.hasChildNodes()) { for (int l = 0; l < Child.getChildNodes().getLength(); l++) { if (!(Child.getChildNodes().item(l).getNodeName().equals("AttrValue"))) { continue; } else { ModelName = getTextContent(Child.getChildNodes().item(l)); } } } break; } } } try { ModelName = ModelName.replaceAll("\n", " "); EPC net = read(currentChild, ObjDef_Name, ObjDef_LinkId, function_LinkId, ModelName); partialResult.addInHierarchy(net, parent, ModelName); modelid_net.put( currentChild.getAttributes().getNamedItem("Model.ID").getNodeValue(), net); } catch (Throwable x) { Message.add(x.getClass().getName()); // throw new IOException(x.getMessage()); } } } } return partialResult; }