Exemplo n.º 1
0
 /**
  * Faz uma busca a partir do cep enviado, no site <a href="http://www.republicavirtual.com.br"
  * target="_blank">republicavirtual.com.br</a>, retornando o resultado em um objeto {@link
  * WebServiceCep}. <br>
  * <br>
  * N�o se faz necess�rio formata��es, a string pode ser enviada em qualquer formata��o, pois s�
  * ser�o consideradas os primeiros 8 numeros da string. <br>
  * Por Exemplo: <br>
  * Uma <tt>{@link String} "14.568-910"</tt> � automaticamente passada para <tt>"14568910"</tt>.
  * <br>
  * Uma <tt>{@link String} "1%4#5?55%16a8&910"</tt> � automaticamente passada para
  * <tt>"14555168"</tt>, s� levando em conta os primeiros 8 n�meros.
  *
  * @param cep N�mero do cep a ser carregado. S� ser�o considerados os primeiros 8 n�meros da
  *     {@link String} enviada. Todos os caracters n�o num�ricos ser�o removidos, e a string ser�
  *     truncada caso seja maior que 8 caracters.
  * @return {@link WebServiceCep} contendo as informa��es da pesquisa.
  */
 public static WebServiceCep searchCep(String cep) {
   cep = cep.replaceAll("\\D*", ""); // To numeric digits only
   if (cep.length() > 8) cep = cep.substring(0, 8);
   WebServiceCep loadCep = new WebServiceCep(cep);
   try {
     XmlEnums enums = new XmlEnums();
     for (Element e : getElements(cep))
       enums.getXml(e.getQualifiedName()).setCep(e.getText(), loadCep);
   } catch (DocumentException ex) {
     if (ex.getNestedException() != null
         && ex.getNestedException() instanceof java.net.UnknownHostException) {
       loadCep.setResultText("Site não encontrado.");
       loadCep.setResulCode(-14);
     } else {
       loadCep.setResultText("Não foi possivel ler o documento xml.");
       loadCep.setResulCode(-15);
     }
     loadCep.setExceptio(ex);
   } catch (MalformedURLException ex) {
     loadCep.setExceptio(ex);
     loadCep.setResultText("Erro na formação da url.");
     loadCep.setResulCode(-16);
   } catch (Exception ex) {
     loadCep.setExceptio(ex);
     loadCep.setResultText("Erro inesperado.");
     loadCep.setResulCode(-17);
   }
   return loadCep;
 }
Exemplo n.º 2
0
 /* 526:    */
 /* 527:    */ protected void startElement(Element element, AttributesImpl namespaceAttributes)
     /* 528:    */ throws SAXException
       /* 529:    */ {
   /* 530:810 */ this.contentHandler.startElement(
       element.getNamespaceURI(),
       element.getName(),
       element.getQualifiedName(),
       createAttributes(element, namespaceAttributes));
   /* 531:    */ }
Exemplo n.º 3
0
  private static Map<String, Element> parseDrawXml(Set transitionSet, Element rootEl) {
    Map map = new LinkedHashMap();

    List<Element> figures = rootEl.selectNodes("/drawing/figures/*");

    for (Element el : figures) {
      String id = el.attributeValue("id");
      String ref = el.attributeValue("ref");

      if ("transition".equals(el.getQualifiedName())) {
        transitionSet.add(el);
      } else if (id != null) {
        map.put(id, el);
      } else if (ref != null) {
        Node figureNode = rootEl.selectSingleNode("/drawing/figures//*[@id='" + ref + "']");
        map.put(ref, figureNode);
      }
    }

    return map;
  }
Exemplo n.º 4
0
  public void consultar(String cep) throws MalformedURLException, DocumentException {

    URL url = new URL("http://cep.republicavirtual.com.br/web_cep.php?cep=" + cep + "&formato=xml");

    Document document = getDocumento(url);

    Element root = document.getRootElement();

    for (Iterator i = root.elementIterator(); i.hasNext(); ) {
      Element element = (Element) i.next();

      if (element.getQualifiedName().equals("uf")) {
        setEstado(element.getText());
      }

      if (element.getQualifiedName().equals("cidade")) {
        setCidade(element.getText());
      }

      if (element.getQualifiedName().equals("bairro")) {
        setBairro(element.getText());
      }

      if (element.getQualifiedName().equals("tipo_logradouro")) {
        setTipoLogradouro(element.getText());
      }

      if (element.getQualifiedName().equals("logradouro")) {
        setLogradouro(element.getText());
      }

      if (element.getQualifiedName().equals("resultado")) {
        setResultado(Integer.parseInt(element.getText()));
      }
    }
  }
Exemplo n.º 5
0
  public static String JpdlGen(String drawXml, String processName) {
    if (logger.isDebugEnabled()) {
      logger.debug("drawXml:" + drawXml);
    }

    Document jpdlDoc = DocumentHelper.createDocument();

    jpdlDoc.setXMLEncoding("utf-8");

    Element processEl = jpdlDoc.addElement("process");

    processEl.addAttribute("name", processName);

    Document drawDoc = XmlUtil.stringToDocument(drawXml);
    Element orgRootEl = drawDoc.getRootElement();

    Set transitionSet = new HashSet();

    Map nodeMap = parseDrawXml(transitionSet, orgRootEl);

    Map newNodeMap = new LinkedHashMap();
    Iterator ids = nodeMap.keySet().iterator();

    while (ids.hasNext()) {
      String id = (String) ids.next();
      Element pNode = (Element) nodeMap.get(id);
      Element curNewNode = processEl.addElement(pNode.getQualifiedName());
      String x = pNode.attributeValue("x");
      String y = pNode.attributeValue("y");

      String width = pNode.attributeValue("w");
      Integer intWidth = Integer.valueOf(new Integer(width).intValue() + 5);

      String height = pNode.attributeValue("h");
      Integer intHeight = Integer.valueOf(new Integer(height).intValue() + 15);

      curNewNode.addAttribute("name", pNode.attributeValue("name"));
      curNewNode.addAttribute(
          "g",
          new Integer(x).intValue()
              - 12
              + ","
              + (new Integer(y).intValue() - 8)
              + ","
              + intWidth
              + ","
              + intHeight);

      newNodeMap.put(id, curNewNode);
    }

    Iterator tranIt = transitionSet.iterator();

    while (tranIt.hasNext()) {
      Element tranEl = (Element) tranIt.next();
      String g = tranEl.attributeValue("g");
      String name = tranEl.attributeValue("name");

      Element startNode = (Element) tranEl.selectSingleNode("./startConnector/rConnector/Owner/*");
      Element endNode = (Element) tranEl.selectSingleNode("./endConnector/rConnector/Owner/*");

      if ((startNode != null) && (endNode != null)) {
        String startRef = startNode.attributeValue("ref");
        String endRef = endNode.attributeValue("ref");
        Element newEndNode;
        Element newStartNode;
        if ((startRef != null) && (endRef != null)) {
          newStartNode = (Element) newNodeMap.get(startRef);
          newEndNode = (Element) newNodeMap.get(endRef);
        } else {
          String startId = startNode.attributeValue("id");
          String endId = startNode.attributeValue("id");
          newStartNode = (Element) newNodeMap.get(startId);
          newEndNode = (Element) newNodeMap.get(endId);
        }

        Element transitionEl = newStartNode.addElement("transition");
        transitionEl.addAttribute("name", name);
        transitionEl.addAttribute("to", newEndNode.attributeValue("name"));
        transitionEl.addAttribute("g", g);

        if ("decision".equals(newStartNode.getQualifiedName())) {
          Element conditionEl =
              (Element)
                  orgRootEl.selectSingleNode(
                      "/drawing/figures//decision/conditions/condition[@to='" + name + "']");
          if (conditionEl != null) {
            Element newConditionEl = transitionEl.addElement("condition");
            newConditionEl.addAttribute("expr", conditionEl.attributeValue("expr"));
          }
        }
      }
    }

    if (logger.isDebugEnabled()) {
      logger.debug("after convter jbpm xml:" + processEl.asXML());
    }

    return jpdlDoc.asXML();
  }
Exemplo n.º 6
0
  // Implementation methods
  // -------------------------------------------------------------------------
  protected void writeElement(Element element) throws IOException {
    int size = element.nodeCount();
    String qualifiedName = element.getQualifiedName();

    writePrintln();
    indent();

    writer.write("<");
    writer.write(qualifiedName);

    int previouslyDeclaredNamespaces = namespaceStack.size();
    Namespace ns = element.getNamespace();

    if (isNamespaceDeclaration(ns)) {
      namespaceStack.push(ns);
      writeNamespace(ns);
    }

    // Print out additional namespace declarations
    boolean textOnly = true;

    for (int i = 0; i < size; i++) {
      Node node = element.node(i);

      if (node instanceof Namespace) {
        Namespace additional = (Namespace) node;

        if (isNamespaceDeclaration(additional)) {
          namespaceStack.push(additional);
          writeNamespace(additional);
        }
      } else if (node instanceof Element) {
        textOnly = false;
      } else if (node instanceof Comment) {
        textOnly = false;
      }
    }

    writeAttributes(element);

    lastOutputNodeType = Node.ELEMENT_NODE;

    if (size <= 0) {
      writeEmptyElementClose(qualifiedName);
    } else {
      writer.write(">");

      if (textOnly) {
        // we have at least one text node so lets assume
        // that its non-empty
        writeElementContent(element);
      } else {
        // we know it's not null or empty from above
        ++indentLevel;

        writeElementContent(element);

        --indentLevel;

        writePrintln();
        indent();
      }

      writer.write("</");
      writer.write(qualifiedName);
      writer.write(">");
    }

    // remove declared namespaceStack from stack
    while (namespaceStack.size() > previouslyDeclaredNamespaces) {
      namespaceStack.pop();
    }

    lastOutputNodeType = Node.ELEMENT_NODE;
  }
Exemplo n.º 7
0
 /**
  * Writes the closing tag of an {@link Element}
  *
  * @param element <code>Element</code> to output.
  * @throws IOException DOCUMENT ME!
  */
 public void writeClose(Element element) throws IOException {
   writeClose(element.getQualifiedName());
 }
Exemplo n.º 8
0
 /**
  * Writes the opening tag of an {@link Element}, including its {@link Attribute}s but without its
  * content.
  *
  * @param element <code>Element</code> to output.
  * @throws IOException DOCUMENT ME!
  */
 public void writeOpen(Element element) throws IOException {
   writer.write("<");
   writer.write(element.getQualifiedName());
   writeAttributes(element);
   writer.write(">");
 }
Exemplo n.º 9
0
 /* 532:    */
 /* 533:    */ protected void endElement(Element element) /* 534:    */ throws SAXException
       /* 535:    */ {
   /* 536:816 */ this.contentHandler.endElement(
       element.getNamespaceURI(), element.getName(), element.getQualifiedName());
   /* 537:    */ }