List of usage examples for org.jdom2.input SAXBuilder SAXBuilder
public SAXBuilder()
From source file:codigoFonte.Sistema.java
public boolean autentica(User u) { File file = new File("Sistema.xml"); Document newDocument = null;//from www. j a v a 2s . c o m Element root = null; boolean autenticado = false; if (file.exists()) { SAXBuilder builder = new SAXBuilder(); try { newDocument = builder.build(file); } catch (JDOMException ex) { Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex); } root = newDocument.getRootElement(); } else { root = new Element("sistema"); newDocument = new Document(root); } User user = null; List<Element> listusers = root.getChildren(); for (Element e : listusers) { if (e.getAttributeValue("matrcula").equals(u.getMatricula()) && e.getAttributeValue("senha").equals(u.getPassword())) { autenticado = true; return autenticado; } } return autenticado; }
From source file:codigoFonte.Sistema.java
public boolean autenticaAdmin(String username, String password) { File file = new File("Sistema.xml"); Document newDocument = null;/*from w ww . j a v a 2 s . com*/ Element root = null; boolean autenticado = false; if (file.exists()) { SAXBuilder builder = new SAXBuilder(); try { newDocument = builder.build(file); } catch (JDOMException ex) { Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex); } root = newDocument.getRootElement(); } else { root = new Element("sistema"); newDocument = new Document(root); } if (root.getAttributeValue("username").equals(username) && root.getAttributeValue("password").equals(password)) { autenticado = true; return autenticado; } return autenticado; }
From source file:com.abyala.decisiontree.SimpleDecisionTreeParser.java
License:Open Source License
@Override public DecisionTree parse(final Reader inputReader) throws DecisionTreeParserException { try {//from www .j ava 2 s .co m final Document doc = new SAXBuilder().build(inputReader); return parseDocument(doc); } catch (JDOMException e) { throw new DecisionTreeParserException(e); } catch (IOException e) { throw new DecisionTreeParserException(e); } }
From source file:com.abyala.decisiontree.SimpleDecisionTreeParser.java
License:Open Source License
@Override public DecisionTree parse(final InputStream inputStream) throws DecisionTreeParserException { try {/* ww w.j a v a2 s .c om*/ final Document doc = new SAXBuilder().build(inputStream); return parseDocument(doc); } catch (JDOMException e) { throw new DecisionTreeParserException(e); } catch (IOException e) { throw new DecisionTreeParserException(e); } }
From source file:com.accenture.control.Xml.java
public List<Plano> lerXML() { List<CtAlm> listCtALM = new ArrayList<CtAlm>(); List<Plano> listPlano = new ArrayList<Plano>(); try {/*w w w. ja v a 2 s . c o m*/ String valor = null; //Aqui voc informa o nome do arquivo XML. logger.info("Inicio mtodo: new File(FILE);"); File f = new File(FILE); logger.info("Inicio mtodo: new FileInputStream(f);"); // logger.info("Inicio mtodo: new FileInputStream(f);"); // InputStream inputStream = new FileInputStream(f); // logger.info("Inicio mtodo: new InputStreamReader(inputStream, \"UTF-8\";"); // Reader reader = new InputStreamReader(inputStream, "UTF-8"); // // InputSource is = new InputSource(reader); logger.info( "Inicio do mtodo: new BufferedReader(new InputStreamReader(new FileInputStream(f), \"UTF-8\"))"); BufferedReader myBuffer = new BufferedReader(new InputStreamReader(new FileInputStream(f))); logger.info( "Fim do mtodo: new BufferedReader(new InputStreamReader(new FileInputStream(f), \"UTF-8\"))"); logger.info("Inicio do mtodo: new InputSource(myBuffer)"); InputSource is = new InputSource(myBuffer); logger.info("Fim do mtodo: new InputSource(myBuffer)"); logger.info("Arquivo xml: " + FILE); logger.info("Criando objeto Document doc"); Document doc = null; logger.info("Criado objeto Document doc e setado como null"); logger.info("Criando objeto SAXBuilder builder"); SAXBuilder builder = new SAXBuilder(); logger.info("Criado objeto SAXBuilder builder new SAXBuilder()"); logger.info("inicio - doc = builder.build(is);"); doc = builder.build(is); logger.info("fim - doc = builder.build(is);"); logger.info("inicio - org.jdom2.Element ct = doc.getRootElement();"); org.jdom2.Element ct = doc.getRootElement(); logger.info("fim - org.jdom2.Element ct = doc.getRootElement();"); // org.jdom2.Element ct = doc.getRootElement().getChild("Entity").getChild("Fields"); if (Integer.parseInt(ct.getAttributeValue("TotalResults")) == 0) { logger.info("Nenhum CT foi encontrado no arquivo XML"); System.out.println("A busca no retornou resultados"); JOptionPane.showMessageDialog(null, "Nenhum CT foi encontrado.", "ALM", JOptionPane.INFORMATION_MESSAGE); return null; } else { List<org.jdom2.Element> lista = ct.getChildren(); logger.info("Tamanho da listaroot do xml: " + lista.size()); List<org.jdom2.Element> lista2 = ct.getChild("Entity").getChild("Fields").getChildren(); logger.info("Tamanho da lista de campo do xml: " + lista2.size()); Iterator i = lista.iterator(); while (i.hasNext()) { logger.info("Iniciando o loop das entity"); CtAlm ctALM = new CtAlm(); Plano p = new Plano(); org.jdom2.Element element = (org.jdom2.Element) i.next(); System.out.println("Type:" + element.getAttributeValue("Type")); Iterator j = lista2.iterator(); int cont = 0; while (j.hasNext()) { logger.info("Iniciando o loop dos fields"); org.jdom2.Element element2 = (org.jdom2.Element) j.next(); // System.out.println("Name:" + element2.getAttributeValue("Name")); System.out.println("Name:" + element.getChild("Fields").getChildren().get(cont).getAttributeValue("Name")); ctALM.setCampo( element.getChild("Fields").getChildren().get(cont).getAttributeValue("Name")); System.out.println("Value:" + element.getChild("Fields").getChildren().get(cont).getChildText("Value")); ctALM.setValor(element.getChild("Fields").getChildren().get(cont).getChildText("Value")); String nomeCampo = element.getChild("Fields").getChildren().get(cont) .getAttributeValue("Name"); String valorCampo = element.getChild("Fields").getChildren().get(cont) .getChildText("Value"); switch (nomeCampo) { case "user-template-08": p.setQtdSistemas(Integer.parseInt(valorCampo)); break; case "user-template-09": p.setQtdStep(Integer.parseInt(valorCampo)); break; case "user-template-01": p.setSistemaMaster(valorCampo); break; case "user-template-03": p.setCenarioTeste(valorCampo); break; case "user-template-06": p.setRequisito(valorCampo); break; case "user-template-05": p.setFornecedor(valorCampo); break; case "description": String descricao = valorCampo; // convertFromUTF8(descricao); logger.debug("Campo Descrio: " + descricao); // try{ // logger.debug("Parse no campo Descrio: "+ descricao ); // descricao = Jsoup.parse(descricao).text(); // }catch(Exception ex){ // logger.error("Erro parser ",ex); // } logger.debug("Setando no objeto plano: p.setDescCasoTeste(descricao);"); p.setDescCasoTeste(descricao); logger.debug("Setado no objeto plano: p.setDescCasoTeste(descricao);"); break; case "user-template-28": p.setTpRequisito(valorCampo); break; case "user-template-22": p.setSistemasEnvolvidos(valorCampo); break; case "user-template-24": p.setComplexidade(valorCampo); break; case "name": p.setCasoTeste(valorCampo); break; case "subtype-id": p.setType(valorCampo); break; } logger.info("Fim do loop dos fields - nome do campo: " + nomeCampo); logger.info("contador do campo: " + cont); cont++; } logger.info("Adicionando CT na lista de plano"); listPlano.add(p); logger.info("Adicionando " + p.getCasoTeste() + " CT adicoando na lista"); logger.info("Fim do loop das entity"); } } } catch (JDOMException ex) { JOptionPane.showMessageDialog(null, "Ocorreu o erro: " + ex.getMessage() + ex.getLocalizedMessage(), "Erro", JOptionPane.ERROR_MESSAGE); logger.error("Erro : ", ex); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Ocorreu o erro: " + ex.getMessage() + ex.getLocalizedMessage(), "Erro", JOptionPane.ERROR_MESSAGE); logger.error("Erro : ", ex); } logger.info("Tamanho da Lista de CTS extraidos do XML : " + listPlano.size()); return listPlano; }
From source file:com.archimatetool.jdom.JDOMUtils.java
License:Open Source License
/** * Reads and returns a JDOM Document from file without Schema Validation * @param file The XML File/* w w w . j av a 2s.c om*/ * @return The JDOM Document or null if not found * @throws JDOMException * @throws IOException */ public static Document readXMLFile(File file) throws IOException, JDOMException { SAXBuilder builder = new SAXBuilder(); // This allows UNC mapped locations to load return builder.build(new FileInputStream(file)); }
From source file:com.archimatetool.jdom.JDOMUtils.java
License:Open Source License
/** * Reads and returns a JDOM Document from String without Schema Validation * @param xmlString// ww w .j a va2 s .c om * @return * @throws JDOMException * @throws IOException */ public static Document readXMLString(String xmlString) throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); return builder.build(new StringReader(xmlString)); }
From source file:com.archimatetool.model.util.RelationshipsMatrix.java
License:Open Source License
private void loadKeyLetters() { //URL url = Platform.getBundle(BUNDLE_ID).getResource(RELATIONSHIPS_KEYS_FILE); URL url = Platform.getBundle(BUNDLE_ID).getEntry(RELATIONSHIPS_KEYS_FILE); // Load the JDOM Document from XML Document doc = null;/* w w w . j a v a2s. c o m*/ try { doc = new SAXBuilder().build(url); } catch (Exception ex) { ex.printStackTrace(); return; } for (Object object : doc.getRootElement().getChildren(XML_ELEMENT_KEY)) { Element elementKey = (Element) object; String keyLetter = elementKey.getAttributeValue(XML_ATTRIBUTE_CHAR); if (keyLetter == null || keyLetter.length() != 1) { System.err.println(getClass() + ": Key letter incorrect: " + keyLetter); //$NON-NLS-1$ continue; } String relationName = elementKey.getAttributeValue(XML_ATTRIBUTE_RELATIONSHIP); if (relationName == null) { System.err.println(getClass() + ": Relationship name incorrect: " + relationName); //$NON-NLS-1$ continue; } EClass relationship = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(relationName); if (relationship == null) { System.err.println(getClass() + ": Couldn't find relationship " + relationName); //$NON-NLS-1$ continue; } relationsKeyMap.put(keyLetter.charAt(0), relationship); relationsValueMap.put(relationship, keyLetter.charAt(0)); } }
From source file:com.archimatetool.model.util.RelationshipsMatrix.java
License:Open Source License
private void loadRelationships() { //URL url = Platform.getBundle(BUNDLE_ID).getResource(RELATIONSHIPS_FILE); URL url = Platform.getBundle(BUNDLE_ID).getEntry(RELATIONSHIPS_FILE); // Load the JDOM Document from XML Document doc = null;//w ww . java 2 s . c o m try { doc = new SAXBuilder().build(url); } catch (Exception ex) { ex.printStackTrace(); return; } // Iterate through all "source" elements Element elementElements = doc.getRootElement().getChild(XML_ELEMENT_ELEMENTS); if (elementElements == null) { // oops System.err.println(getClass() + ": Couldn't find elements element."); //$NON-NLS-1$ return; } for (Object object : elementElements.getChildren(XML_ELEMENT_SOURCE)) { Element elementSource = (Element) object; // Source element name String sourceName = elementSource.getAttributeValue(XML_ATTRIBUTE_ELEMENT); if (sourceName == null) { continue; } // Get EClass source from mapping EClass source = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(sourceName); if (source == null) { System.err.println(getClass() + ": Couldn't find source " + sourceName); //$NON-NLS-1$ continue; } // Create a new list of type TargetMatrix List<TargetMatrix> matrixList = new ArrayList<TargetMatrix>(); // Put it in the main matrix map matrixMap.put(source, matrixList); // Iterate through all child "target" elements for (Object objectChild : elementSource.getChildren(XML_ELEMENT_TARGET)) { Element elementTarget = (Element) objectChild; // Target element name String targetName = elementTarget.getAttributeValue(XML_ATTRIBUTE_ELEMENT); if (targetName == null) { continue; } // Get EClass target from mapping EClass target = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(targetName); if (target == null) { System.err.println(getClass() + ": Couldn't find target " + targetName); //$NON-NLS-1$ continue; } // Create a new TargetMatrix and add it to the list TargetMatrix matrix = new TargetMatrix(); matrixList.add(matrix); // Set target class matrix.targetClass = target; // Get relations string String relations = elementTarget.getAttributeValue(XML_ATTRIBUTE_RELATIONS); if (relations == null) { continue; } // Take each character and add the relationship from the mapping for (int i = 0; i < relations.length(); i++) { char key = relations.charAt(i); EClass relationship = relationsKeyMap.get(key); if (relationship != null) { matrix.getRelationships().add(relationship); } else { System.err.println(getClass() + ": Found unmapped key char: " + key); //$NON-NLS-1$ } } } } }
From source file:com.archimatetool.model.viewpoints.ViewpointManager.java
License:Open Source License
/** * Load viewpoints from XML file//from w w w . j a v a 2s . c o m */ void loadDefaultViewpointsFile() throws IOException, JDOMException { URL url = Platform.getBundle(BUNDLE_ID).getEntry(VIEWPOINTS_FILE); Document doc = new SAXBuilder().build(url); Element rootElement = doc.getRootElement(); for (Element xmlViewpoint : rootElement.getChildren("viewpoint")) { //$NON-NLS-1$ String id = xmlViewpoint.getAttributeValue("id"); //$NON-NLS-1$ if (id == null || "".equals(id)) { //$NON-NLS-1$ System.err.println("Blank id for viewpoint"); //$NON-NLS-1$ continue; } Element xmlName = xmlViewpoint.getChild("name"); //$NON-NLS-1$ if (xmlName == null) { System.err.println("No name element for viewpoint"); //$NON-NLS-1$ continue; } String name = xmlName.getText(); if (name == null || "".equals(name)) { //$NON-NLS-1$ System.err.println("Blank name for viewpoint"); //$NON-NLS-1$ continue; } Viewpoint vp = new Viewpoint(id, name); for (Element xmlConcept : xmlViewpoint.getChildren("concept")) { //$NON-NLS-1$ String conceptName = xmlConcept.getText(); if (conceptName == null || "".equals(conceptName)) { //$NON-NLS-1$ System.err.println("Blank concept name for viewpoint"); //$NON-NLS-1$ continue; } if (ELEMENTS_MAP.containsKey(conceptName)) { addCollection(vp, conceptName); } else { EClass eClass = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(conceptName); if (eClass != null) { addConcept(vp, eClass); } else { System.err.println("Couldn't get eClass: " + conceptName); //$NON-NLS-1$ } } } VIEWPOINTS.put(id, vp); } }