List of usage examples for org.dom4j Node valueOf
String valueOf(String xpathExpression);
valueOf
evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.
From source file:edu.umd.cs.findbugs.PluginLoader.java
License:Open Source License
private void loadPluginComponents() throws PluginException { Document pluginDescriptor = getPluginDescriptor(); List<Document> messageCollectionList = getMessageDocuments(); List<Node> cloudNodeList = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/Cloud"); for (Node cloudNode : cloudNodeList) { String cloudClassname = cloudNode.valueOf("@cloudClass"); String cloudId = cloudNode.valueOf("@id"); String usernameClassname = cloudNode.valueOf("@usernameClass"); boolean onlineStorage = Boolean.valueOf(cloudNode.valueOf("@onlineStorage")); String propertiesLocation = cloudNode.valueOf("@properties"); boolean disabled = Boolean.valueOf(cloudNode.valueOf("@disabled")) && !cloudId.equals(CloudFactory.DEFAULT_CLOUD); if (disabled) { continue; }/*from w ww . j a v a2 s. c om*/ boolean hidden = Boolean.valueOf(cloudNode.valueOf("@hidden")) && !cloudId.equals(CloudFactory.DEFAULT_CLOUD); Class<? extends Cloud> cloudClass = getClass(classLoader, cloudClassname, Cloud.class); Class<? extends NameLookup> usernameClass = getClass(classLoader, usernameClassname, NameLookup.class); Node cloudMessageNode = findMessageNode(messageCollectionList, "/MessageCollection/Cloud[@id='" + cloudId + "']", "Missing Cloud description for cloud " + cloudId); String description = getChildText(cloudMessageNode, "Description").trim(); String details = getChildText(cloudMessageNode, "Details").trim(); PropertyBundle properties = new PropertyBundle(); if (propertiesLocation != null && propertiesLocation.length() > 0) { URL properiesURL = classLoader.getResource(propertiesLocation); if (properiesURL == null) { continue; } properties.loadPropertiesFromURL(properiesURL); } List<Node> propertyNodes = XMLUtil.selectNodes(cloudNode, "Property"); for (Node node : propertyNodes) { String key = node.valueOf("@key"); String value = node.getText().trim(); properties.setProperty(key, value); } CloudPlugin cloudPlugin = new CloudPluginBuilder().setFindbugsPluginId(plugin.getPluginId()) .setCloudid(cloudId).setClassLoader(classLoader).setCloudClass(cloudClass) .setUsernameClass(usernameClass).setHidden(hidden).setProperties(properties) .setDescription(description).setDetails(details).setOnlineStorage(onlineStorage) .createCloudPlugin(); plugin.addCloudPlugin(cloudPlugin); } // Create PluginComponents try { List<Node> componentNodeList = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/PluginComponent"); for (Node componentNode : componentNodeList) { @DottedClassName String componentKindname = componentNode.valueOf("@componentKind"); if (componentKindname == null) { throw new PluginException( "Missing @componentKind for " + plugin.getPluginId() + " loaded from " + loadedFrom); } @DottedClassName String componentClassname = componentNode.valueOf("@componentClass"); if (componentClassname == null) { throw new PluginException("Missing @componentClassname for " + plugin.getPluginId() + " loaded from " + loadedFrom); } String componentId = componentNode.valueOf("@id"); if (componentId == null) { throw new PluginException( "Missing @id for " + plugin.getPluginId() + " loaded from " + loadedFrom); } try { String propertiesLocation = componentNode.valueOf("@properties"); boolean disabled = Boolean.valueOf(componentNode.valueOf("@disabled")); Node filterMessageNode = findMessageNode(messageCollectionList, "/MessageCollection/PluginComponent[@id='" + componentId + "']", "Missing Cloud description for PluginComponent " + componentId); String description = getChildText(filterMessageNode, "Description").trim(); String details = getChildText(filterMessageNode, "Details").trim(); PropertyBundle properties = new PropertyBundle(); if (propertiesLocation != null && propertiesLocation.length() > 0) { URL properiesURL = classLoaderForResources.getResource(propertiesLocation); if (properiesURL == null) { AnalysisContext.logError("Could not load properties for " + plugin.getPluginId() + " component " + componentId + " from " + propertiesLocation); continue; } properties.loadPropertiesFromURL(properiesURL); } List<Node> propertyNodes = XMLUtil.selectNodes(componentNode, "Property"); for (Node node : propertyNodes) { String key = node.valueOf("@key"); String value = node.getText(); properties.setProperty(key, value); } Class<?> componentKind = classLoader.loadClass(componentKindname); loadComponentPlugin(plugin, componentKind, componentClassname, componentId, disabled, description, details, properties); } catch (RuntimeException e) { AnalysisContext.logError("Unable to load ComponentPlugin " + componentId + " : " + componentClassname + " implementing " + componentKindname, e); } } // Create FindBugsMains if (!FindBugs.isNoMains()) { List<Node> findBugsMainList = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/FindBugsMain"); for (Node main : findBugsMainList) { String className = main.valueOf("@class"); if (className == null) { throw new PluginException("Missing @class for FindBugsMain in plugin" + plugin.getPluginId() + " loaded from " + loadedFrom); } String cmd = main.valueOf("@cmd"); if (cmd == null) { throw new PluginException("Missing @cmd for for FindBugsMain in plugin " + plugin.getPluginId() + " loaded from " + loadedFrom); } String kind = main.valueOf("@kind"); boolean analysis = Boolean.valueOf(main.valueOf("@analysis")); Element mainMessageNode = (Element) findMessageNode(messageCollectionList, "/MessageCollection/FindBugsMain[@cmd='" + cmd // + " and @class='" + className + "']/Description", "Missing FindBugsMain description for cmd " + cmd); String description = mainMessageNode.getTextTrim(); try { Class<?> mainClass = classLoader.loadClass(className); plugin.addFindBugsMain(mainClass, cmd, description, kind, analysis); } catch (Exception e) { String msg = "Unable to load FindBugsMain " + cmd + " : " + className + " in plugin " + plugin.getPluginId() + " loaded from " + loadedFrom; PluginException e2 = new PluginException(msg, e); AnalysisContext.logError(msg, e2); } } } List<Node> detectorNodeList = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/Detector"); int detectorCount = 0; for (Node detectorNode : detectorNodeList) { String className = detectorNode.valueOf("@class"); String speed = detectorNode.valueOf("@speed"); String disabled = detectorNode.valueOf("@disabled"); String reports = detectorNode.valueOf("@reports"); String requireJRE = detectorNode.valueOf("@requirejre"); String hidden = detectorNode.valueOf("@hidden"); if (speed == null || speed.length() == 0) { speed = "fast"; } // System.out.println("Found detector: class="+className+", disabled="+disabled); // Create DetectorFactory for the detector Class<?> detectorClass = null; if (!FindBugs.isNoAnalysis()) { detectorClass = classLoader.loadClass(className); if (!Detector.class.isAssignableFrom(detectorClass) && !Detector2.class.isAssignableFrom(detectorClass)) { throw new PluginException( "Class " + className + " does not implement Detector or Detector2"); } } DetectorFactory factory = new DetectorFactory(plugin, className, detectorClass, !"true".equals(disabled), speed, reports, requireJRE); if (Boolean.valueOf(hidden).booleanValue()) { factory.setHidden(true); } factory.setPositionSpecifiedInPluginDescriptor(detectorCount++); plugin.addDetectorFactory(factory); // Find Detector node in one of the messages files, // to get the detail HTML. Node node = findMessageNode(messageCollectionList, "/MessageCollection/Detector[@class='" + className + "']/Details", "Missing Detector description for detector " + className); Element details = (Element) node; String detailHTML = details.getText(); StringBuilder buf = new StringBuilder(); buf.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"); buf.append("<HTML><HEAD><TITLE>Detector Description</TITLE></HEAD><BODY>\n"); buf.append(detailHTML); buf.append("</BODY></HTML>\n"); factory.setDetailHTML(buf.toString()); } } catch (ClassNotFoundException e) { throw new PluginException("Could not instantiate detector class: " + e, e); } // Create ordering constraints Node orderingConstraintsNode = pluginDescriptor.selectSingleNode("/FindbugsPlugin/OrderingConstraints"); if (orderingConstraintsNode != null) { // Get inter-pass and intra-pass constraints List<Element> elements = XMLUtil.selectNodes(orderingConstraintsNode, "./SplitPass|./WithinPass"); for (Element constraintElement : elements) { // Create the selectors which determine which detectors are // involved in the constraint DetectorFactorySelector earlierSelector = getConstraintSelector(constraintElement, plugin, "Earlier"); DetectorFactorySelector laterSelector = getConstraintSelector(constraintElement, plugin, "Later"); // Create the constraint DetectorOrderingConstraint constraint = new DetectorOrderingConstraint(earlierSelector, laterSelector); // Keep track of which constraints are single-source constraint.setSingleSource(earlierSelector instanceof SingleDetectorFactorySelector); // Add the constraint to the plugin if ("SplitPass".equals(constraintElement.getName())) { plugin.addInterPassOrderingConstraint(constraint); } else { plugin.addIntraPassOrderingConstraint(constraint); } } } // register global Category descriptions List<Node> categoryNodeListGlobal = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/BugCategory"); for (Node categoryNode : categoryNodeListGlobal) { String key = categoryNode.valueOf("@category"); if ("".equals(key)) { throw new PluginException("BugCategory element with missing category attribute"); } BugCategory bc = plugin.addOrCreateBugCategory(key); boolean hidden = Boolean.valueOf(categoryNode.valueOf("@hidden")); if (hidden) { bc.setHidden(hidden); } } for (Document messageCollection : messageCollectionList) { List<Node> categoryNodeList = XMLUtil.selectNodes(messageCollection, "/MessageCollection/BugCategory"); if (DEBUG) { System.out.println("found " + categoryNodeList.size() + " categories in " + plugin.getPluginId()); } for (Node categoryNode : categoryNodeList) { String key = categoryNode.valueOf("@category"); if ("".equals(key)) { throw new PluginException("BugCategory element with missing category attribute"); } BugCategory bc = plugin.addOrCreateBugCategory(key); String shortDesc = getChildText(categoryNode, "Description"); bc.setShortDescription(shortDesc); try { String abbrev = getChildText(categoryNode, "Abbreviation"); if (bc.getAbbrev() == null) { bc.setAbbrev(abbrev); if (DEBUG) { System.out.println("category " + key + " abbrev -> " + abbrev); } } else if (DEBUG) { System.out.println( "rejected abbrev '" + abbrev + "' for category " + key + ": " + bc.getAbbrev()); } } catch (PluginException pe) { if (DEBUG) { System.out.println("missing Abbreviation for category " + key + "/" + shortDesc); // do nothing else -- Abbreviation is required, but handle // its omission gracefully } } try { String details = getChildText(categoryNode, "Details"); if (bc.getDetailText() == null) { bc.setDetailText(details); if (DEBUG) { System.out.println("category " + key + " details -> " + details); } } else if (DEBUG) { System.out.println("rejected details [" + details + "] for category " + key + ": [" + bc.getDetailText() + ']'); } } catch (PluginException pe) { // do nothing -- LongDescription is optional } } } // Create BugPatterns List<Node> bugPatternNodeList = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/BugPattern"); for (Node bugPatternNode : bugPatternNodeList) { String type = bugPatternNode.valueOf("@type"); String abbrev = bugPatternNode.valueOf("@abbrev"); String category = bugPatternNode.valueOf("@category"); boolean experimental = Boolean.parseBoolean(bugPatternNode.valueOf("@experimental")); // Find the matching element in messages.xml (or translations) String query = "/MessageCollection/BugPattern[@type='" + type + "']"; Node messageNode = findMessageNode(messageCollectionList, query, "messages.xml missing BugPattern element for type " + type); Node bugsUrlNode = messageNode.getDocument() .selectSingleNode("/MessageCollection/Plugin/" + (experimental ? "AllBugsUrl" : "BugsUrl")); String bugsUrl = bugsUrlNode == null ? null : bugsUrlNode.getText(); String shortDesc = getChildText(messageNode, "ShortDescription"); String longDesc = getChildText(messageNode, "LongDescription"); String detailText = getChildText(messageNode, "Details"); int cweid = 0; try { String cweString = bugPatternNode.valueOf("@cweid"); if (cweString.length() > 0) { cweid = Integer.parseInt(cweString); } } catch (RuntimeException e) { assert true; // ignore } BugPattern bugPattern = new BugPattern(type, abbrev, category, experimental, shortDesc, longDesc, detailText, bugsUrl, cweid); try { String deprecatedStr = bugPatternNode.valueOf("@deprecated"); boolean deprecated = deprecatedStr.length() > 0 && Boolean.valueOf(deprecatedStr).booleanValue(); if (deprecated) { bugPattern.setDeprecated(deprecated); } } catch (RuntimeException e) { assert true; // ignore } plugin.addBugPattern(bugPattern); } // Create BugCodes Set<String> definedBugCodes = new HashSet<String>(); for (Document messageCollection : messageCollectionList) { List<Node> bugCodeNodeList = XMLUtil.selectNodes(messageCollection, "/MessageCollection/BugCode"); for (Node bugCodeNode : bugCodeNodeList) { String abbrev = bugCodeNode.valueOf("@abbrev"); if ("".equals(abbrev)) { throw new PluginException("BugCode element with missing abbrev attribute"); } if (definedBugCodes.contains(abbrev)) { continue; } String description = bugCodeNode.getText(); String query = "/FindbugsPlugin/BugCode[@abbrev='" + abbrev + "']"; Node fbNode = pluginDescriptor.selectSingleNode(query); int cweid = 0; if (fbNode != null) { try { cweid = Integer.parseInt(fbNode.valueOf("@cweid")); } catch (RuntimeException e) { assert true; // ignore } } BugCode bugCode = new BugCode(abbrev, description, cweid); plugin.addBugCode(bugCode); definedBugCodes.add(abbrev); } } // If an engine registrar is specified, make a note of its classname Node node = pluginDescriptor.selectSingleNode("/FindbugsPlugin/EngineRegistrar"); if (node != null) { String engineClassName = node.valueOf("@class"); if (engineClassName == null) { throw new PluginException("EngineRegistrar element with missing class attribute"); } try { Class<?> engineRegistrarClass = classLoader.loadClass(engineClassName); if (!IAnalysisEngineRegistrar.class.isAssignableFrom(engineRegistrarClass)) { throw new PluginException( engineRegistrarClass + " does not implement IAnalysisEngineRegistrar"); } plugin.setEngineRegistrarClass( engineRegistrarClass.<IAnalysisEngineRegistrar>asSubclass(IAnalysisEngineRegistrar.class)); } catch (ClassNotFoundException e) { throw new PluginException("Could not instantiate analysis engine registrar class: " + e, e); } } try { URL bugRankURL = getResource(BugRanker.FILENAME); if (bugRankURL == null) { // see // https://sourceforge.net/tracker/?func=detail&aid=2816102&group_id=96405&atid=614693 // plugin can not have bugrank.txt. In this case, an empty // bugranker will be created if (DEBUG) { System.out.println("No " + BugRanker.FILENAME + " for plugin " + plugin.getPluginId()); } } BugRanker ranker = new BugRanker(bugRankURL); plugin.setBugRanker(ranker); } catch (IOException e) { throw new PluginException("Couldn't parse \"" + BugRanker.FILENAME + "\"", e); } }
From source file:edu.umd.cs.findbugs.PluginLoader.java
License:Open Source License
private Plugin constructMinimalPlugin(Document pluginDescriptor, List<Document> messageCollectionList) throws DuplicatePluginIdError { // Get the unique plugin id (or generate one, if none is present) // Unique plugin id String pluginId = pluginDescriptor.valueOf(XPATH_PLUGIN_PLUGINID); if ("".equals(pluginId)) { synchronized (PluginLoader.class) { pluginId = "plugin" + nextUnknownId++; }/*from w ww .j av a2s . c o m*/ } cannotDisable = Boolean.parseBoolean(pluginDescriptor.valueOf("/FindbugsPlugin/@cannotDisable")); String de = pluginDescriptor.valueOf("/FindbugsPlugin/@defaultenabled"); if (de != null && "false".equals(de.toLowerCase().trim())) { optionalPlugin = true; } if (optionalPlugin) { cannotDisable = false; } if (!loadedPluginIds.add(pluginId)) { Plugin existingPlugin = Plugin.getByPluginId(pluginId); URL u = existingPlugin == null ? null : existingPlugin.getPluginLoader().getURL(); if (cannotDisable && initialPlugin) { throw new DuplicatePluginIdError(pluginId, loadedFrom, u); } else { throw new DuplicatePluginIdException(pluginId, loadedFrom, u); } } parentId = pluginDescriptor.valueOf("/FindbugsPlugin/@parentid"); String version = pluginDescriptor.valueOf("/FindbugsPlugin/@version"); String releaseDate = pluginDescriptor.valueOf("/FindbugsPlugin/@releaseDate"); if ((releaseDate == null || releaseDate.length() == 0) && isCorePlugin()) { releaseDate = Version.CORE_PLUGIN_RELEASE_DATE; } // Create the Plugin object (but don't assign to the plugin field yet, // since we're still not sure if everything will load correctly) Date parsedDate = parseDate(releaseDate); Plugin constructedPlugin = new Plugin(pluginId, version, parsedDate, this, !optionalPlugin, cannotDisable); // Set provider and website, if specified String provider = pluginDescriptor.valueOf(XPATH_PLUGIN_PROVIDER).trim(); if (!"".equals(provider)) { constructedPlugin.setProvider(provider); } String website = pluginDescriptor.valueOf(XPATH_PLUGIN_WEBSITE).trim(); if (!"".equals(website)) { try { constructedPlugin.setWebsite(website); } catch (URISyntaxException e1) { AnalysisContext.logError( "Plugin " + constructedPlugin.getPluginId() + " has invalid website: " + website, e1); } } String updateUrl = pluginDescriptor.valueOf("/FindbugsPlugin/@update-url").trim(); if (!"".equals(updateUrl)) { try { constructedPlugin.setUpdateUrl(updateUrl); } catch (URISyntaxException e1) { AnalysisContext.logError( "Plugin " + constructedPlugin.getPluginId() + " has invalid update check URL: " + website, e1); } } // Set short description, if specified Node pluginShortDesc = null; try { pluginShortDesc = findMessageNode(messageCollectionList, XPATH_PLUGIN_SHORT_DESCRIPTION, "no plugin description"); } catch (PluginException e) { // Missing description is not fatal, so ignore } if (pluginShortDesc != null) { constructedPlugin.setShortDescription(pluginShortDesc.getText().trim()); } Node detailedDescription = null; try { detailedDescription = findMessageNode(messageCollectionList, "/MessageCollection/Plugin/Details", "no plugin description"); } catch (PluginException e) { // Missing description is not fatal, so ignore } if (detailedDescription != null) { constructedPlugin.setDetailedDescription(detailedDescription.getText().trim()); } List<Node> globalOptionNodes = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/GlobalOptions/Property"); for (Node optionNode : globalOptionNodes) { String key = optionNode.valueOf("@key"); String value = optionNode.getText().trim(); constructedPlugin.setMyGlobalOption(key, value); } return constructedPlugin; }
From source file:edu.umd.cs.findbugs.PluginLoader.java
License:Open Source License
private static DetectorFactorySelector getConstraintSelector(Element constraintElement, Plugin plugin, String singleDetectorElementName/* * , String * detectorCategoryElementName */) throws PluginException { Node node = constraintElement.selectSingleNode("./" + singleDetectorElementName); if (node != null) { String detectorClass = node.valueOf("@class"); return new SingleDetectorFactorySelector(plugin, detectorClass); }/*from w w w .j av a 2 s . c o m*/ node = constraintElement.selectSingleNode("./" + singleDetectorElementName + "Category"); if (node != null) { boolean spanPlugins = Boolean.valueOf(node.valueOf("@spanplugins")).booleanValue(); String categoryName = node.valueOf("@name"); if (!"".equals(categoryName)) { if ("reporting".equals(categoryName)) { return new ReportingDetectorFactorySelector(spanPlugins ? null : plugin); } else if ("training".equals(categoryName)) { return new ByInterfaceDetectorFactorySelector(spanPlugins ? null : plugin, TrainingDetector.class); } else if ("interprocedural".equals(categoryName)) { return new ByInterfaceDetectorFactorySelector(spanPlugins ? null : plugin, InterproceduralFirstPassDetector.class); } else { throw new PluginException( "Invalid category name " + categoryName + " in constraint selector node"); } } } node = constraintElement.selectSingleNode("./" + singleDetectorElementName + "Subtypes"); if (node != null) { boolean spanPlugins = Boolean.valueOf(node.valueOf("@spanplugins")).booleanValue(); String superName = node.valueOf("@super"); if (!"".equals(superName)) { try { Class<?> superClass = Class.forName(superName); return new ByInterfaceDetectorFactorySelector(spanPlugins ? null : plugin, superClass); } catch (ClassNotFoundException e) { throw new PluginException("Unknown class " + superName + " in constraint selector node"); } } } throw new PluginException("Invalid constraint selector node"); }
From source file:edu.umd.cs.findbugs.tools.ComparePerfomance.java
License:Open Source License
public void foo(File f, int i) throws DocumentException, IOException { Document doc;// w w w .j a v a 2 s . c o m SAXReader reader = new SAXReader(); String fName = f.getName(); InputStream in = new FileInputStream(f); try { if (fName.endsWith(".gz")) { in = new GZIPInputStream(in); } doc = reader.read(in); Node summary = doc.selectSingleNode("/BugCollection/FindBugsSummary"); double cpu_seconds = Double.parseDouble(summary.valueOf("@cpu_seconds")); putStats("cpu_seconds", i, (int) (cpu_seconds * 1000)); double gc_seconds = Double.parseDouble(summary.valueOf("@gc_seconds")); putStats("gc_seconds", i, (int) (gc_seconds * 1000)); List<Node> profileNodes = XMLUtil.selectNodes(doc, "/BugCollection/FindBugsSummary/FindBugsProfile/ClassProfile"); for (Node n : profileNodes) { String name = n.valueOf("@name"); int totalMilliseconds = Integer.parseInt(n.valueOf("@totalMilliseconds")); int invocations = Integer.parseInt(n.valueOf("@invocations")); putStats(name, i, totalMilliseconds); // System.out.printf("%6d %10d %s%n", invocations, totalMilliseconds, simpleName); } } finally { in.close(); } }
From source file:Emporium.Servlet.ServImportaImpressaoPLP.java
public static String leXmlPLP(String xml, String idPLP, int idCliente, int idDepto, String nomeBD) throws DocumentException, HeadlessException { String ret = ""; xml = xml.replaceAll("&", "E"); //System.out.println(xml); if (xml != null && !xml.isEmpty()) { SAXReader reader = new SAXReader(); StringReader sr = new StringReader(xml); Document doc = reader.read(sr); List<Node> eventos = (List<Node>) doc.selectNodes("//correioslog"); // processa eventos for (Node node : eventos) { String contrato = node.valueOf("remetente/numero_contrato"); String cartaoPostagem = "";//node.valueOf(""); String codigoAdministrativo = node.valueOf("remetente/codigo_administrativo"); String nomeRemetente = node.valueOf("remetente/nome_remetente"); String cepRemetente = node.valueOf("remetente/cep_remetente"); String enderecoRemetente = node.valueOf("remetente/logradouro_remetente"); String numeroRemetente = node.valueOf("remetente/numero_remetente"); String complementoRemetente = node.valueOf("remetente/complemento_remetente"); String bairroRemetente = node.valueOf("remetente/bairro_remetente"); String cidadeRemetente = node.valueOf("remetente/cidade_remetente"); String ufRemetente = node.valueOf("remetente/uf_remetente"); Endereco endRemetente = new Endereco(nomeRemetente, enderecoRemetente, numeroRemetente, complementoRemetente, bairroRemetente, cidadeRemetente, ufRemetente, cepRemetente); List<Node> evnt = (List<Node>) node.selectNodes("objeto_postal"); for (Node nd : evnt) { String notaFiscal = nd.valueOf("nacional/numero_nota_fiscal"); int codECT = Integer.parseInt(nd.valueOf("codigo_servico_postagem").trim()); String servico = ContrServicoECT.consultaGrupoServicoByCodECT(codECT); String nomeDestinatario = nd.valueOf("destinatario/nome_destinatario"); String cepDestinatario = nd.valueOf("nacional/cep_destinatario"); String enderecoDestinatario = nd.valueOf("destinatario/logradouro_destinatario"); String numeroDestinatario = nd.valueOf("destinatario/numero_end_destinatario"); String complementoDestinatario = nd.valueOf("destinatario/complemento_destinatario"); String bairroDestinatario = nd.valueOf("nacional/bairro_destinatario"); String cidadeDestinatario = nd.valueOf("nacional/cidade_destinatario"); String ufDestinatario = nd.valueOf("nacional/uf_destinatario"); Endereco endDestinatario = new Endereco(nomeDestinatario, enderecoDestinatario, numeroDestinatario, complementoDestinatario, bairroDestinatario, cidadeDestinatario, ufDestinatario, cepDestinatario); int ar = 0; int mp = 0; int rg = 0; int rm = 0; int pr = 0; float vd = 0; List<Node> evtAdicionais = (List<Node>) node.selectNodes("servico_adicional"); for (Node nda : evtAdicionais) { int codAd = Integer.parseInt(nda.valueOf("codigo_servico_adicional").trim()); switch (codAd) { case 1: ar = 1;/*w w w . j a va2s . c o m*/ break; case 2: mp = 1; break; case 4: rm = 1; break; case 15: pr = 1; break; case 19: case 35: vd = Float.parseFloat(nda.valueOf("valor_declarado").trim().replace(",", ".")); break; default: break; } } String sro = nd.valueOf("numero_etiqueta"); ContrImpressaoPLP.inserePLP(sro, idPLP, 0, contrato, cartaoPostagem, codigoAdministrativo, codECT, servico, idCliente, idDepto, ar, mp, vd, pr, rg, rm, notaFiscal, endRemetente, endDestinatario, nomeBD); } } } else { ret = "XML da PLP est vazio!"; } return ret; }
From source file:feedForwardNetwork.FeedForwardNetwork.java
License:Open Source License
@Override public AbstractRepresentation loadFromXML(Node nd) { try {//from w ww . j a v a 2 s .c om String fitnessString = nd.valueOf("./@fitness"); if (!fitnessString.isEmpty()) { this.setFitness(Double.parseDouble(fitnessString)); } // load activation function XMLFieldEntry afprop = getProperties().get("activationFunction"); if (afprop == null) { activationFunction = DEFAULT_ACTIVATION_FUNCTION; } else { activationFunction = ActivationFunction.valueOf(afprop.getValue()); } this.input_nodes = Integer.parseInt(nd.valueOf("./@input_nodes")); this.output_nodes = Integer.parseInt(nd.valueOf("./@output_nodes")); this.nodes = Integer.parseInt(nd.valueOf("./@nodes")); this.weight_range = Float.parseFloat(nd.valueOf("./@weight_range")); this.bias_range = Float.parseFloat(nd.valueOf("./@bias_range")); this.layers = Integer.parseInt(nd.valueOf("./@layers")); // this.iteration = // Integer.parseInt(nd.valueOf("./simulation/@iteration")); // this.score = Integer.parseInt(nd.valueOf("./simulation/@score")); this.activation = new float[this.nodes]; this.output = new float[this.nodes]; this.bias = new float[this.nodes]; this.weight = new float[this.nodes][this.nodes]; Node dnodes = nd.selectSingleNode("./nodes"); for (int nr = this.input_nodes; nr < this.nodes; nr++) { Node curnode = dnodes.selectSingleNode("./node[@nr='" + nr + "']"); if (curnode == null) throw new IllegalArgumentException("ThreeLayerNetwork: node tags inconsistent!" + "\ncheck 'nr' attributes and nodes count in nnetwork!"); this.bias[nr] = Float.parseFloat(curnode.valueOf("./bias")); Node dweights = curnode.selectSingleNode("./weights"); for (int from = 0; from < this.nodes; from++) { String ws = dweights.valueOf("./weight[@from='" + from + "']"); if (ws.length() == 0) throw new IllegalArgumentException("ThreeLayerNetwork: weight tags inconsistent!" + "\ncheck 'from' attributes and nodes count in nnetwork!"); float val = Float.parseFloat(ws); this.weight[from][nr] = val; } } // this.gahist = new GAHistory(this.config, nd); } catch (NumberFormatException e) { throw new IllegalArgumentException("ThreeLayerNetwork: NumberFormatException! Check XML File"); } return this; }
From source file:fr.cph.stock.language.Language.java
License:Apache License
/** * Get the language map/*w w w. j a v a 2s . co m*/ * * @return a map */ public final Map<String, String> getLanguage() { Node menuNode = xml.getNode(BASE + MENU); @SuppressWarnings("unchecked") List<Node> menuNodes = (List<Node>) xml.getListNode(BASE + MENU); for (Node node : menuNodes) { String name = node.valueOf("@name"); map.put(menuNode.getName().toUpperCase() + "_" + name.toUpperCase(), node.getStringValue()); } Node node = xml.getNode(BASE + PORTFOLIO); List<String> nodes = new ArrayList<>(); Node node2; nodes.add(BASE + PORTFOLIO + "/title"); nodes.add(BASE + PORTFOLIO + "/review/liquidity"); nodes.add(BASE + PORTFOLIO + "/review/yieldYear"); nodes.add(BASE + PORTFOLIO + "/review/shareValue"); nodes.add(BASE + PORTFOLIO + "/add"); nodes.add(BASE + PORTFOLIO + "/equities/company"); nodes.add(BASE + PORTFOLIO + "/equities/quantity"); nodes.add(BASE + PORTFOLIO + "/equities/unitCostPrice"); nodes.add(BASE + PORTFOLIO + "/equities/quote"); nodes.add(BASE + PORTFOLIO + "/equities/currency"); nodes.add(BASE + PORTFOLIO + "/equities/parities"); nodes.add(BASE + PORTFOLIO + "/equities/value"); nodes.add(BASE + PORTFOLIO + "/equities/percentTotal"); nodes.add(BASE + PORTFOLIO + "/equities/yieldTtm"); nodes.add(BASE + PORTFOLIO + "/equities/yieldPerUnitCostPrice"); nodes.add(BASE + PORTFOLIO + "/equities/valueGained"); nodes.add(BASE + PORTFOLIO + "/equities/stopLoss"); nodes.add(BASE + PORTFOLIO + "/equities/objective"); nodes.add(BASE + PORTFOLIO + "/equities/info"); nodes.add(BASE + PORTFOLIO + "/equities/info"); nodes.add(BASE + PORTFOLIO + "/equities/modify"); nodes.add(BASE + PORTFOLIO + "/chartTitle"); nodes.add(BASE + PORTFOLIO + "/chartTitleValue"); nodes.add(BASE + PORTFOLIO + "/chart/all"); nodes.add(BASE + PORTFOLIO + "/chart/fiveYears"); nodes.add(BASE + PORTFOLIO + "/chart/twoYears"); nodes.add(BASE + PORTFOLIO + "/chart/oneYear"); nodes.add(BASE + PORTFOLIO + "/chart/sixMonths"); nodes.add(BASE + PORTFOLIO + "/chart/threeMonths"); nodes.add(BASE + PORTFOLIO + "/chart/oneMonth"); nodes.add(BASE + PORTFOLIO + "/chart/oneWeek"); for (String n : nodes) { node2 = xml.getNode(n); addToMap(map, node, node2); } node = xml.getNode(BASE + CONSTANT); nodes = new ArrayList<>(); nodes.add(BASE + CONSTANT + "/added"); nodes.add(BASE + CONSTANT + "/updated"); nodes.add(BASE + CONSTANT + "/modified"); nodes.add(BASE + CONSTANT + "/deleted"); for (String n : nodes) { node2 = xml.getNode(n); addToMap(map, node, node2); } node = xml.getNode(BASE + PORTFOLIO_HIDDEN); nodes = new ArrayList<>(); nodes.add(BASE + PORTFOLIO_HIDDEN + "/refresh"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/add"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/updateCurrencies"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/yahooId"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/quantity"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/unitCostPrice"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/modifyEquity"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/customizeName"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/customizeName"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/customizeSector"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/customizeIndustry"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/customizeMarketCap"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/defautParity"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/personalParity"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/yahooYield"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/personalYield"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/stopLoss"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/objective"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/modify"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/or"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/delete"); nodes.add(BASE + PORTFOLIO_HIDDEN + "/deleteConfirm"); for (String n : nodes) { node2 = xml.getNode(n); addToMap(map, node, node2); } node = xml.getNode(BASE + HISTORY); nodes = new ArrayList<>(); nodes.add(BASE + HISTORY + "/title"); nodes.add(BASE + HISTORY + "/update"); nodes.add(BASE + HISTORY + "/date"); nodes.add(BASE + HISTORY + "/account"); nodes.add(BASE + HISTORY + "/liquidityMovement"); nodes.add(BASE + HISTORY + "/dividends"); nodes.add(BASE + HISTORY + "/buy"); nodes.add(BASE + HISTORY + "/sell"); nodes.add(BASE + HISTORY + "/taxe"); nodes.add(BASE + HISTORY + "/portfolioValue"); nodes.add(BASE + HISTORY + "/shareQuantity"); nodes.add(BASE + HISTORY + "/shareValue"); nodes.add(BASE + HISTORY + "/monthlyYield"); nodes.add(BASE + HISTORY + "/commentary"); nodes.add(BASE + HISTORY + "/option"); nodes.add(BASE + HISTORY + "/details"); nodes.add(BASE + HISTORY + "/all"); nodes.add(BASE + HISTORY + "/delete"); for (String n : nodes) { node2 = xml.getNode(n); addToMap(map, node, node2); } node = xml.getNode(BASE + HISTORY_HIDDEN); nodes = new ArrayList<>(); nodes.add(BASE + HISTORY_HIDDEN + "/refresh"); nodes.add(BASE + HISTORY_HIDDEN + "/account"); nodes.add(BASE + HISTORY_HIDDEN + "/movement"); nodes.add(BASE + HISTORY_HIDDEN + "/yield"); nodes.add(BASE + HISTORY_HIDDEN + "/buy"); nodes.add(BASE + HISTORY_HIDDEN + "/sell"); nodes.add(BASE + HISTORY_HIDDEN + "/taxe"); nodes.add(BASE + HISTORY_HIDDEN + "/commentary"); nodes.add(BASE + HISTORY_HIDDEN + "/update"); for (String n : nodes) { node2 = xml.getNode(n); addToMap(map, node, node2); } node = xml.getNode(BASE + ACCOUNTS); nodes = new ArrayList<>(); nodes.add(BASE + ACCOUNTS + "/title"); nodes.add(BASE + ACCOUNTS + "/add"); nodes.add(BASE + ACCOUNTS + "/account"); nodes.add(BASE + ACCOUNTS + "/currency"); nodes.add(BASE + ACCOUNTS + "/liquidity"); nodes.add(BASE + ACCOUNTS + "/parity"); nodes.add(BASE + ACCOUNTS + "/value"); nodes.add(BASE + ACCOUNTS + "/option"); nodes.add(BASE + ACCOUNTS + "/modify"); nodes.add(BASE + ACCOUNTS + "/total"); for (String n : nodes) { node2 = xml.getNode(n); addToMap(map, node, node2); } node = xml.getNode(BASE + ACCOUNTS_HIDDEN); nodes = new ArrayList<>(); nodes.add(BASE + ACCOUNTS_HIDDEN + "/add"); nodes.add(BASE + ACCOUNTS_HIDDEN + "/accountName"); nodes.add(BASE + ACCOUNTS_HIDDEN + "/currency"); nodes.add(BASE + ACCOUNTS_HIDDEN + "/liquidity"); for (String n : nodes) { node2 = xml.getNode(n); addToMap(map, node, node2); } node = xml.getNode(BASE + LIST); nodes = new ArrayList<>(); nodes.add(BASE + LIST + "/title"); nodes.add(BASE + LIST + "/add"); nodes.add(BASE + LIST + "/date"); nodes.add(BASE + LIST + "/company"); nodes.add(BASE + LIST + "/quote"); nodes.add(BASE + LIST + "/lowMaxYear"); nodes.add(BASE + LIST + "/yield"); nodes.add(BASE + LIST + "/lowerLimit"); nodes.add(BASE + LIST + "/higherLimit"); nodes.add(BASE + LIST + "/info"); nodes.add(BASE + LIST + "/modify"); for (String n : nodes) { node2 = xml.getNode(n); addToMap(map, node, node2); } node = xml.getNode(BASE + LIST_HIDDEN); nodes = new ArrayList<>(); nodes.add(BASE + LIST_HIDDEN + "/refresh"); nodes.add(BASE + LIST_HIDDEN + "/confirm"); nodes.add(BASE + LIST_HIDDEN + "/add"); nodes.add(BASE + LIST_HIDDEN + "/yahooId"); nodes.add(BASE + LIST_HIDDEN + "/lowerLimit"); nodes.add(BASE + LIST_HIDDEN + "/higherLimit"); nodes.add(BASE + LIST_HIDDEN + "/modify"); for (String n : nodes) { node2 = xml.getNode(n); addToMap(map, node, node2); } node = xml.getNode(BASE + CHARTS); nodes = new ArrayList<>(); nodes.add(BASE + CHARTS + "/title"); for (String n : nodes) { node2 = xml.getNode(n); addToMap(map, node, node2); } node = xml.getNode(BASE + CURRENCIES); nodes = new ArrayList<>(); nodes.add(BASE + CURRENCIES + "/title"); nodes.add(BASE + CURRENCIES + "/portfolioCurrency"); nodes.add(BASE + CURRENCIES + "/currency"); nodes.add(BASE + CURRENCIES + "/lastUpdate"); for (String n : nodes) { node2 = xml.getNode(n); addToMap(map, node, node2); } node = xml.getNode(BASE + CURRENCIES_HIDDEN); nodes = new ArrayList<>(); nodes.add(BASE + CURRENCIES_HIDDEN + "/refresh"); nodes.add(BASE + CURRENCIES_HIDDEN + "/confirm"); for (String n : nodes) { node2 = xml.getNode(n); addToMap(map, node, node2); } node = xml.getNode(BASE + OPTIONS); nodes = new ArrayList<>(); nodes.add(BASE + OPTIONS + "/title"); nodes.add(BASE + OPTIONS + "/defautCurrency"); nodes.add(BASE + OPTIONS + "/format"); nodes.add(BASE + OPTIONS + "/timeZone"); nodes.add(BASE + OPTIONS + "/datePattern"); nodes.add(BASE + OPTIONS + "/portfolioColumn"); nodes.add(BASE + OPTIONS + "/loadHistory"); nodes.add(BASE + OPTIONS + "/liquidity"); nodes.add(BASE + OPTIONS + "/account"); nodes.add(BASE + OPTIONS + "/load"); for (String n : nodes) { node2 = xml.getNode(n); addToMap(map, node, node2); } node = xml.getNode(BASE + OPTIONS_HIDDEN); nodes = new ArrayList<>(); nodes.add(BASE + OPTIONS_HIDDEN + "/currency"); nodes.add(BASE + OPTIONS_HIDDEN + "/format"); nodes.add(BASE + OPTIONS_HIDDEN + "/timeZone"); nodes.add(BASE + OPTIONS_HIDDEN + "/datePattern"); nodes.add(BASE + OPTIONS_HIDDEN + "/columns"); nodes.add(BASE + OPTIONS_HIDDEN + "/quote"); nodes.add(BASE + OPTIONS_HIDDEN + "/parities"); nodes.add(BASE + OPTIONS_HIDDEN + "/yieldTTM"); nodes.add(BASE + OPTIONS_HIDDEN + "/yieldPerUnitCostPrice"); nodes.add(BASE + OPTIONS_HIDDEN + "/stopLoss"); nodes.add(BASE + OPTIONS_HIDDEN + "/objective"); for (String n : nodes) { node2 = xml.getNode(n); addToMap(map, node, node2); } return map; }
From source file:fr.isima.ponge.wsprotocol.xml.XmlIOManager.java
License:Open Source License
/** * Reads a business protocol./*from w ww . ja va 2s . c o m*/ * * @param reader The reader object for the XML source. * @return The protocol. * @throws DocumentException Thrown if an error occurs. */ @SuppressWarnings("unchecked") public BusinessProtocol readBusinessProtocol(Reader reader) throws DocumentException { // Vars Iterator it; Node node; // Parsing SAXReader saxReader = new SAXReader(); Document document = saxReader.read(reader); // Protocol BusinessProtocol protocol = factory.createBusinessProtocol(document.valueOf("/business-protocol/name")); //$NON-NLS-1$ readExtraProperties(protocol, document.selectSingleNode("/business-protocol")); //$NON-NLS-1$ // States Map<String, State> states = new HashMap<String, State>(); it = document.selectNodes("/business-protocol/state").iterator(); //$NON-NLS-1$ while (it.hasNext()) { node = (Node) it.next(); State s = factory.createState(node.valueOf("name"), "true" //$NON-NLS-1$ //$NON-NLS-2$ .equals(node.valueOf("final"))); //$NON-NLS-1$ readExtraProperties(s, node); protocol.addState(s); states.put(s.getName(), s); if (node.selectSingleNode("initial-state") != null) //$NON-NLS-1$ { protocol.setInitialState(s); } } // Operations & messages int legacyOperationNameCounter = 0; it = document.selectNodes("/business-protocol/operation").iterator(); //$NON-NLS-1$ while (it.hasNext()) { node = (Node) it.next(); String opName = node.valueOf("name"); //$NON-NLS-1$ if ("".equals(opName)) { opName = "T" + legacyOperationNameCounter++; } String msgName = node.valueOf("message/name"); //$NON-NLS-1$ String msgPol = node.valueOf("message/polarity"); //$NON-NLS-1$ State s1 = states.get(node.valueOf("source")); //$NON-NLS-1$ State s2 = states.get(node.valueOf("target")); //$NON-NLS-1$ Polarity pol; if (msgPol.equals("positive")) //$NON-NLS-1$ { pol = Polarity.POSITIVE; } else if (msgPol.equals("negative")) //$NON-NLS-1$ { pol = Polarity.NEGATIVE; } else { pol = Polarity.NULL; } String opKindValue = node.valueOf("kind"); OperationKind kind; if ("".equals(opKindValue) || "explicit".equals(opKindValue)) { kind = OperationKind.EXPLICIT; } else { kind = OperationKind.IMPLICIT; } Message msg = factory.createMessage(msgName, pol); readExtraProperties(msg, node.selectSingleNode("message")); //$NON-NLS-1$ Operation op = factory.createOperation(opName, s1, s2, msg, kind); readExtraProperties(op, node); protocol.addOperation(op); } return protocol; }
From source file:fr.isima.ponge.wsprotocol.xml.XmlIOManager.java
License:Open Source License
/** * Reads extra properties./*from w w w . j a v a 2s. c o m*/ * * @param keeper The object having extra properties. * @param rootNode The XML node to gather the properties from. */ protected void readExtraProperties(ExtraPropertiesKeeper keeper, Node rootNode) { for (Object o : rootNode.selectNodes("extra-property")) { Node node = (Node) o; String className = node.valueOf("@type"); if (className == null) { className = String.class.getName(); } ExtraPropertyHandler handler = getExtraPropertyHandler(className); if (handler != null) { handler.readExtraProperty((Element) node, keeper); } } }
From source file:fullyMeshedNet.FullyMeshedNet.java
License:Open Source License
public FullyMeshedNet(File xmlfile, int popid) { // loads properties super(xmlfile); // load actual data (from CEA2D now) // get population root node Document doc = SafeSAX.read(xmlfile, true); Node dpopulations = doc.selectSingleNode("/frevo/populations"); List<?> npops = dpopulations.selectNodes(".//population"); Node pop = (Node) npops.get(popid); List<?> nets = pop.selectNodes("./*"); // return the one with the highest fitness int bestID = 0; Node net = (Node) nets.get(bestID); String fitnessString = net.valueOf("./@fitness"); double bestfitness = Double.parseDouble(fitnessString); for (int i = 1; i < nets.size(); i++) { net = (Node) nets.get(i); fitnessString = net.valueOf("./@fitness"); double fitness = Double.parseDouble(fitnessString); if (fitness > bestfitness) { bestID = i;/*w w w . j a v a2 s .c o m*/ bestfitness = fitness; } } //loadFromXML((Node)nets.get(0)); loadFromXML((Node) nets.get(bestID)); }