List of usage examples for org.jdom2 Element getAttributeValue
public String getAttributeValue(final String attname)
This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.
From source file:ataraxis.passwordmanager.XMLHandler.java
License:Open Source License
/** * Get a AccountEntry with the given id. * /*from w ww. jav a 2s . c o m*/ * @param id * @return the requested AccountEntry * @throws EntryDoesNotExistException */ public AccountEntry getAccountEntry(String id) throws EntryDoesNotExistException { AccountEntry accountEntry = null; try { Element accountElement = getElement(id); if (accountElement != null) { if (!isGroupElement(id)) { String entryId = accountElement.getAttributeValue("id"); accountEntry = new AccountEntry(entryId); accountEntry.setName(accountElement.getChildText("name")); accountEntry.setPassword(accountElement.getChildText("password")); accountEntry.setLink(accountElement.getChildText("link")); accountEntry.setComment(accountElement.getChildText("comment")); String parentId = accountElement.getParentElement().getAttributeValue("id"); if (parentId != null && isGroupElement(parentId)) { GroupEntry group = new GroupEntry(parentId); accountEntry.setParentEntry(group); } } } /*else { throw new EntryDoesNotExistException("entry not found"); }*/ } catch (JDOMException e) { logger.fatal(e); throw new EntryDoesNotExistException("entry not found"); } return accountEntry; }
From source file:ataraxis.passwordmanager.XMLHandler.java
License:Open Source License
/** * Return a List of all account entries. * * @return//from ww w . java 2 s . c o m */ @SuppressWarnings("rawtypes") public List<AccountEntry> getAccountEntryList() { List<AccountEntry> accountList = new ArrayList<AccountEntry>(); try { List accounts = getAccountList(); for (int i = 0; i < accounts.size(); i++) { Element current = (Element) accounts.get(i); accountList.add(getAccountEntry(current.getAttributeValue("id"))); } } catch (JDOMException e) { logger.fatal(e); } catch (EntryDoesNotExistException e) { logger.fatal(e); } return accountList; }
From source file:ataraxis.passwordmanager.XMLHandler.java
License:Open Source License
private List<PasswordEntry> getElementSubTree(Element parent) { List<PasswordEntry> allChildEntries = new ArrayList<PasswordEntry>(); Iterator<Element> topElements = parent.getChildren().iterator(); while (topElements.hasNext()) { Element currentElement = topElements.next(); PasswordEntry entry;/*w ww . j a v a 2 s .co m*/ try { entry = getEntry(currentElement.getAttributeValue("id")); if (entry != null) { allChildEntries.add(entry); } String elementType = currentElement.getName(); if (elementType.equals("group")) { List<PasswordEntry> childs = getElementSubTree(currentElement); if (childs != null && childs.size() > 0) { allChildEntries.addAll(childs); } } } catch (EntryDoesNotExistException e) { logger.fatal(e.getMessage()); } } return allChildEntries; }
From source file:BL.Servlets.AddNode.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . j av a 2 s . c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet AddUser</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet AddUser at " + request.getContextPath() + "</h1>"); String NodeType = "residentialProperties"; Boolean isFound = false; try { String note_id = keyin("Please Enter note id you need to search: "); SAXBuilder saxBuilder = new SAXBuilder(); String xmlFile = "src\\database.xml"; Document xmlDoc = saxBuilder.build(new File(xmlFile)); Element rootElement = xmlDoc.getRootElement(); // List<Element> ListNodeType = rootElement.getChildren(NodeType); // List<Element> lstNotes = rootElement.getChildren(); for (int i = 0; i < lstNotes.size(); i++) { Element note = (Element) lstNotes.get(i); String n_id = note.getAttributeValue("id"); System.out.println("Note id: " + n_id); if (note_id.equalsIgnoreCase(n_id)) { isFound = true; String name = note.getChildText("name"); String value = note.getAttributeValue("value"); System.out.println( "We found a note with id " + note_id + "; name: " + name + "Value: " + value); break; } } if (!isFound) { System.out.println("Sorry, we don't find out any note with id: " + note_id); } System.out.println("Finished search!"); } catch (Exception e) { // TODO: handle exception } out.println("</body>"); out.println("</html>"); } finally { out.close(); } }
From source file:br.com.nfe.util.Chave.java
@Override public void run() { while (true) { String chave = ""; Document doc = null;// w ww . j a v a 2s.co m SAXBuilder builder = new SAXBuilder(); Path path = Paths.get("c:/unimake/uninfe/" + pasta + "/Retorno"); WatchService watchService = null; try { watchService = FileSystems.getDefault().newWatchService(); path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE); } catch (IOException io) { io.printStackTrace(); } WatchKey key = null; while (true) { try { key = watchService.take(); for (WatchEvent<?> event : key.pollEvents()) { Kind<?> kind = event.kind(); System.out.println("Evento em " + event.context().toString() + " " + kind); try { doc = builder.build( "c:/unimake/uninfe/" + pasta + "/Retorno/" + cNf + "-ret-gerar-chave.xml"); Element retorno = doc.getRootElement(); List<Element> lista = retorno.getChildren(); for (Element e : lista) { chave = e.getAttributeValue("chaveNFe"); chave = e.getText(); } mudaChave(chave); if (chave.isEmpty() == false) { allDone = true; } } catch (Exception e) { e.printStackTrace(); } } } catch (InterruptedException ie) { ie.printStackTrace(); } boolean reset = key.reset(); if (!reset) { break; } if (allDone) { return; } } } }
From source file:br.com.sicoob.cro.cop.util.JobXMLLoader.java
/** * Le o arquivo {@code jobXMLName} e cria os objetos para o processamento. * * @throws BatchStartException para algum erro de leitura e inicializacao. *//*from w ww . j ava 2 s .c o m*/ public void loadJSL() throws BatchStartException { try { ClassLoader tccl = Thread.currentThread().getContextClassLoader(); InputStream inputStream = tccl.getResourceAsStream(PREFIX.concat(this.jobXMlName.concat(XML_SUFFIX))); if (Validation.isNull(inputStream)) { throw new BatchStartException( BatchPropertiesUtil.getInstance().getMessage(FILENOTFOUND, this.jobXMlName)); } SAXBuilder builder = new SAXBuilder(); Document document = (Document) builder.build(inputStream); Element rootNode = document.getRootElement(); this.job = new Job(rootNode.getAttributeValue(ID), Job.Mode.ASYNC); loadSteps(rootNode); // valida se o job pode est completo if (Validation.notNull(this.job.getId()) && Validation.notNull(this.job.getSteps()) && this.job.getSteps().size() > 0) { LOG.info(BatchPropertiesUtil.getInstance().getMessage(BatchKeys.BATCH_LOADER_SUCCESS.getKey(), this.job.getId())); } else { throw new BatchStartException(BatchPropertiesUtil.getInstance() .getMessage(BatchKeys.BATCH_LOADER_FAIL.getKey(), this.job.getId())); } } catch (Exception excecao) { LOG.fatal(excecao); throw new BatchStartException(excecao); } }
From source file:br.com.sicoob.cro.cop.util.JobXMLLoader.java
/** * Le o XML e cria o objeto de Step.//from w w w . ja v a2s . c o m * * @param rootNode Nodo princiapl * @throws Exception para algum erro. */ private void loadSteps(Element rootNode) throws Exception { List steps = rootNode.getChildren(STEP); List<Step> jobSteps = new ArrayList(); for (Object obj : steps) { Element stepNode = (Element) obj; StepParameters stepParameters = parseParameters(); Element taskletNode = stepNode.getChild(TASKLET); Element chunkNode = stepNode.getChild(CHUNK); if (Validation.notNull(taskletNode)) { Step step = new Step(getTasklet(taskletNode), Step.Type.TASKLET, stepParameters); step.setId(stepNode.getAttributeValue(ID)); getListener(stepNode, step); jobSteps.add(step); } else if (Validation.notNull(chunkNode)) { Step step = new Step(getReader(chunkNode), getProcessor(chunkNode), getWriter(chunkNode), Step.Type.CHUNK, stepParameters, getCommitInterval(chunkNode)); step.setId(stepNode.getAttributeValue(ID)); getListener(stepNode, step); jobSteps.add(step); } } this.job.setSteps(jobSteps); }
From source file:br.com.sicoob.cro.cop.util.JobXMLLoader.java
private void getListener(Element stepNode, Step step) throws Exception { Element listenerNode = stepNode.getChild(LISTENER); if (Validation.notNull(listenerNode)) { step.setListener((BatchStepListener) Class.forName(listenerNode.getAttributeValue(REF)).newInstance()); }//from w ww . java 2 s . co m }
From source file:br.com.sicoob.cro.cop.util.JobXMLLoader.java
/** * Obtem o Objeto Reader do XML.// w w w .ja v a2 s . c om * * @param chunk Elemento que contem os dados para o reader. * @return um {@link AbstractItemReader}. * @throws Exception para algum erro. */ private AbstractItemReader getReader(Element chunk) throws Exception { return (AbstractItemReader) Class.forName(chunk.getAttributeValue(READER)).newInstance(); }
From source file:br.com.sicoob.cro.cop.util.JobXMLLoader.java
/** * Obtem o Objeto Processor do XML./*from ww w . ja v a 2s . co m*/ * * @param chunk Elemento que contem os dados para o processor. * @return um {@link AbstractItemProcessor}. * @throws Exception para algum erro. */ private AbstractItemProcessor getProcessor(Element chunk) throws Exception { return (AbstractItemProcessor) Class.forName(chunk.getAttributeValue(PROCESSOR)).newInstance(); }