List of usage examples for org.jdom2.input SAXBuilder build
@Override public Document build(final String systemId) throws JDOMException, IOException
This builds a document from the supplied URI.
From source file:ca.nrc.cadc.vodml.VOModelReader.java
License:Open Source License
public Document read(Reader in) throws JDOMException, IOException, SchematronValidationException { SAXBuilder builder = XmlUtil.createBuilder(schemaMap); Document doc = builder.build(in); if (schematronVal) { validateSchematron(doc);/* www . j a v a 2 s .co m*/ } return doc; }
From source file:ca.nrc.cadc.vosi.CapabilitiesParser.java
License:Open Source License
public Document parse(Reader rdr) throws IOException, JDOMException { SAXBuilder sb = XmlUtil.createBuilder(schemaMap); return sb.build(rdr); }
From source file:ca.nrc.cadc.vosi.CapabilitiesParser.java
License:Open Source License
public Document parse(InputStream istream) throws IOException, JDOMException { SAXBuilder sb = XmlUtil.createBuilder(schemaMap); return sb.build(istream); }
From source file:ca.nrc.cadc.vosi.TableSetParser.java
License:Open Source License
public Document parse(Reader rdr) throws IOException, JDOMException { // and again with schema validation SAXBuilder sb = XmlUtil.createBuilder(schemaMap); return sb.build(rdr); }
From source file:ca.nrc.cadc.vosi.TableSetParser.java
License:Open Source License
public Document parse(InputStream istream) throws IOException, JDOMException { // and again with schema validation SAXBuilder sb = XmlUtil.createBuilder(schemaMap); return sb.build(istream); }
From source file:cager.parser.test.SimpleTest2.java
License:Open Source License
private void XMLtoJavaParser() { // Creamos el builder basado en SAX SAXBuilder builder = new SAXBuilder(); try {//w w w . jav a 2 s .c o m String nombreMetodo = null; List<String> atributos = new ArrayList<String>(); String tipoRetorno = null; String nombreArchivo = null; String exportValue = ""; String codigoFuente = ""; HashMap<String, String> tipos = new HashMap<String, String>(); // Construimos el arbol DOM a partir del fichero xml Document doc = builder.build(new FileInputStream(ruta + "VBParser\\ejemplosKDM\\archivo.kdm")); //Document doc = builder.build(new FileInputStream("E:\\WorkspaceParser\\VBParser\\ejemplosKDM\\archivo.kdm")); Namespace xmi = Namespace.getNamespace("xmi", "http://www.omg.org/XMI"); XPathExpression<Element> xpath = XPathFactory.instance().compile("//codeElement", Filters.element()); List<Element> elements = xpath.evaluate(doc); for (Element emt : elements) { if (emt.getAttribute("type", xmi).getValue().compareTo("code:CompilationUnit") == 0) { nombreArchivo = emt.getAttributeValue("name").substring(0, emt.getAttributeValue("name").indexOf('.')); } if (emt.getAttribute("type", xmi).getValue().compareTo("code:LanguageUnit") == 0) { List<Element> hijos = emt.getChildren(); for (Element hijo : hijos) { tipos.put(hijo.getAttributeValue("id", xmi), hijo.getAttributeValue("name")); } } } FileOutputStream fout; fout = new FileOutputStream(ruta + "VBParser\\src\\cager\\parser\\test\\" + nombreArchivo + ".java"); //fout = new FileOutputStream("E:\\WorkspaceParser\\VBParser\\src\\cager\\parser\\test\\"+nombreArchivo+".java"); // get the content in bytes byte[] contentInBytes = null; contentInBytes = ("package cager.parser.test;\n\n").getBytes(); fout.write(contentInBytes); fout.flush(); contentInBytes = ("public class " + nombreArchivo + "{\n\n").getBytes(); fout.write(contentInBytes); fout.flush(); for (Element emt : elements) { // System.out.println("XPath has result: " + emt.getName()+" "+emt.getAttribute("type",xmi)); if (emt.getAttribute("type", xmi).getValue().compareTo("code:MethodUnit") == 0) { nombreMetodo = emt.getAttribute("name").getValue(); if (emt.getAttribute("export") != null) exportValue = emt.getAttribute("export").getValue(); atributos = new ArrayList<String>(); List<Element> hijos = emt.getChildren(); for (Element hijo : hijos) { if (hijo.getAttribute("type", xmi) != null) { if (hijo.getAttribute("type", xmi).getValue().compareTo("code:Signature") == 0) { List<Element> parametros = hijo.getChildren(); for (Element parametro : parametros) { if (parametro.getAttribute("kind") == null || parametro.getAttribute("kind").getValue().compareTo("return") != 0) { atributos.add(tipos.get(parametro.getAttribute("type").getValue()) + " " + parametro.getAttributeValue("name")); } else { tipoRetorno = tipos.get(parametro.getAttribute("type").getValue()); } } } } else if (hijo.getAttribute("snippet") != null) { codigoFuente = hijo.getAttribute("snippet").getValue(); } } //System.out.println("MethodUnit!! " + emt.getName()+" "+emt.getAttribute("type",xmi)+" "+emt.getAttribute("name").getValue()); //System.out.println(emt.getAttribute("name").getValue()); if (tipoRetorno.compareTo("Void") == 0) { tipoRetorno = "void"; } contentInBytes = ("\t" + exportValue + " " + tipoRetorno + " " + nombreMetodo + " (") .getBytes(); fout.write(contentInBytes); fout.flush(); int n = 0; for (String parametro : atributos) { if (atributos.size() > 0 && n < atributos.size() - 1) { contentInBytes = (" " + parametro + ",").getBytes(); } else { contentInBytes = (" " + parametro).getBytes(); } fout.write(contentInBytes); fout.flush(); n++; } contentInBytes = (" ) {\n").getBytes(); fout.write(contentInBytes); fout.flush(); contentInBytes = ("\n/* \n " + codigoFuente + " \n */\n").getBytes(); fout.write(contentInBytes); fout.flush(); contentInBytes = ("\t}\n\n").getBytes(); fout.write(contentInBytes); fout.flush(); System.out.print("\t" + exportValue + " " + tipoRetorno + " " + nombreMetodo + " ("); n = 0; for (String parametro : atributos) { if (atributos.size() > 0 && n < atributos.size() - 1) { System.out.print(" " + parametro + ", "); } else { System.out.print(" " + parametro); } n++; } System.out.println(" ) {"); System.out.println("/* \n " + codigoFuente + " \n */"); System.out.println("\t}\n"); } } contentInBytes = ("}\n").getBytes(); fout.write(contentInBytes); fout.flush(); fout.close(); XPathExpression<Attribute> xp = XPathFactory.instance().compile("//@*", Filters.attribute(xmi)); for (Attribute a : xp.evaluate(doc)) { a.setName(a.getName().toLowerCase()); } xpath = XPathFactory.instance().compile("//codeElement/@name='testvb.cls'", Filters.element()); Element emt = xpath.evaluateFirst(doc); if (emt != null) { System.out.println("XPath has result: " + emt.getName()); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JDOMException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:centroinfantil.PasoLista.java
License:Open Source License
/** * * @return/* w w w .j a va2 s. c om*/ */ static public ArrayList<ArrayList<String>> cargarXml() { //Se crea un SAXBuilder para poder parsear el archivo SAXBuilder builder = new SAXBuilder(); File xmlFile = new File("historial.xml"); ArrayList<ArrayList<String>> salida = new ArrayList<>(); try { ArrayList<String> nino = new ArrayList<>(); String cadena; //Se crea el documento a traves del archivo Document document = (Document) builder.build(xmlFile); //Se obtiene la raiz 'tables' Element rootNode = document.getRootElement(); //Se obtiene la lista de hijos de la raiz 'tables' List list = rootNode.getChildren("child"); System.out.println(list.size()); //Se recorre la lista de hijos de 'tables' for (int i = 0; i < list.size(); i++) { //Se obtiene el elemento 'tabla' Element tabla = (Element) list.get(i); //Se obtiene la lista de hijos del tag 'tabla' List lista_campos = tabla.getChildren(); //Se recorre la lista de campos for (int j = 0; j < lista_campos.size() - 1; j++) { //Se obtiene el elemento 'campo' Element campo = (Element) lista_campos.get(j); cadena = campo.getText(); nino.add(cadena); } Element campo = (Element) lista_campos.get(lista_campos.size() - 1); nino.add(campo.getChildTextTrim("fecha")); nino.add(campo.getChildTextTrim("sala")); nino.add(campo.getChildTextTrim("camara")); nino.add(campo.getChildTextTrim("posicionX")); nino.add(campo.getChildTextTrim("posicionY")); salida.add(nino); } } catch (IOException | JDOMException io) { System.out.println(io.getMessage()); } return salida; }
From source file:cfdi.clases.UtilidadesArchivoCfdi.java
License:Open Source License
/** * Proceso de parseo del XML al objeto estructura layout * El objeto layout es el que se pasa como parametro al reporte * * @param rutaArchivo ruta donde se va a colocar el archivo * @param nombreArchivo nombre del archivo a exportar * @param showLog guardar informacin del inicio y finilizacion del proceso de exportacin * @return EstructuraLayout/* w w w .j a va 2 s.co m*/ */ public EstructuraLayout parseLayout(String rutaArchivo, String nombreArchivo, boolean showLog) { EstructuraLayout layout = null; if (showLog) logger.log(Level.INFO, "Inicia parse {0}", nombreArchivo); try { File archivo; archivo = new File(rutaArchivo + nombreArchivo); SAXBuilder constructorSAX = new SAXBuilder(); try { layout = new EstructuraLayout(); layout.setRutaArchivo(rutaArchivo); layout.setNombreArchivo(nombreArchivo); Document documento = (Document) constructorSAX.build(archivo); layout.setVersion(documento.getRootElement().getAttribute("version") != null ? documento.getRootElement().getAttribute("version").getValue() : (documento.getRootElement().getAttribute("Version") != null ? documento.getRootElement().getAttribute("Version").getValue() : "")); layout.setSerie(documento.getRootElement().getAttribute("serie") != null ? documento.getRootElement().getAttribute("serie").getValue() : (documento.getRootElement().getAttribute("Serie") != null ? documento.getRootElement().getAttribute("Serie").getValue() : "")); layout.setFolio(documento.getRootElement().getAttribute("folio") != null ? documento.getRootElement().getAttribute("folio").getValue() : (documento.getRootElement().getAttribute("Folio") != null ? documento.getRootElement().getAttribute("Folio").getValue() : "")); layout.setFecha(documento.getRootElement().getAttribute("fecha") != null ? documento.getRootElement().getAttribute("fecha").getValue() : (documento.getRootElement().getAttribute("Fecha") != null ? documento.getRootElement().getAttribute("Fecha").getValue() : "")); layout.setSello(documento.getRootElement().getAttribute("sello") != null ? documento.getRootElement().getAttribute("sello").getValue() : (documento.getRootElement().getAttribute("Sello") != null ? documento.getRootElement().getAttribute("Sello").getValue() : "")); layout.setFormaPago(documento.getRootElement().getAttribute("formaDePago") != null ? documento.getRootElement().getAttribute("formaDePago").getValue() : (documento.getRootElement().getAttribute("FormaDePago") != null ? documento.getRootElement().getAttribute("FormaDePago").getValue() : "")); layout.setNoCertificado(documento.getRootElement().getAttribute("noCertificado") != null ? documento.getRootElement().getAttribute("noCertificado").getValue() : (documento.getRootElement().getAttribute("NoCertificado") != null ? documento.getRootElement().getAttribute("NoCertificado").getValue() : "")); layout.setCertificado(documento.getRootElement().getAttribute("certificado") != null ? documento.getRootElement().getAttribute("certificado").getValue() : (documento.getRootElement().getAttribute("Certificado") != null ? documento.getRootElement().getAttribute("Certificado").getValue() : "")); layout.setSubtotal(documento.getRootElement().getAttribute("subTotal") != null ? documento.getRootElement().getAttribute("subTotal").getValue() : (documento.getRootElement().getAttribute("SubTotal") != null ? documento.getRootElement().getAttribute("SubTotal").getValue() : "")); layout.setImporteLetras(NumberToLetterConvert .convertNumberToLetter(documento.getRootElement().getAttribute("total") != null ? documento.getRootElement().getAttribute("total").getValue() : (documento.getRootElement().getAttribute("Total") != null ? documento.getRootElement().getAttribute("Total").getValue() : ""))); layout.setTotal(documento.getRootElement().getAttribute("total") != null ? documento.getRootElement().getAttribute("total").getValue() : (documento.getRootElement().getAttribute("Total") != null ? documento.getRootElement().getAttribute("Total").getValue() : "")); layout.setDescuento(documento.getRootElement().getAttribute("descuento") != null ? documento.getRootElement().getAttribute("descuento").getValue() : (documento.getRootElement().getAttribute("Descuento") != null ? documento.getRootElement().getAttribute("Descuento").getValue() : "")); layout.setMotivoDescuento(documento.getRootElement().getAttribute("motivoDescuento") != null ? documento.getRootElement().getAttribute("motivoDescuento").getValue() : (documento.getRootElement().getAttribute("MotivoDescuento") != null ? documento.getRootElement().getAttribute("MotivoDescuento").getValue() : "")); layout.setTipoCambio(documento.getRootElement().getAttribute("TipoCambio") != null ? documento.getRootElement().getAttribute("TipoCambio").getValue() : (documento.getRootElement().getAttribute("tipoCambio") != null ? documento.getRootElement().getAttribute("tipoCambio").getValue() : "")); layout.setMoneda(documento.getRootElement().getAttribute("Moneda") != null ? documento.getRootElement().getAttribute("Moneda").getValue() : (documento.getRootElement().getAttribute("moneda") != null ? documento.getRootElement().getAttribute("moneda").getValue() : "")); layout.setMetodoPago(documento.getRootElement().getAttribute("metodoDePago") != null ? documento.getRootElement().getAttribute("metodoDePago").getValue() : (documento.getRootElement().getAttribute("MetodoDePago") != null ? documento.getRootElement().getAttribute("MetodoDePago").getValue() : "")); layout.setTipodeComprobante(documento.getRootElement().getAttribute("tipoDeComprobante") != null ? documento.getRootElement().getAttribute("tipoDeComprobante").getValue() : (documento.getRootElement().getAttribute("TipoDeComprobante") != null ? documento.getRootElement().getAttribute("TipoDeComprobante").getValue() : "")); layout.setLugarExpedicion(documento.getRootElement().getAttribute("LugarExpedicion") != null ? documento.getRootElement().getAttribute("LugarExpedicion").getValue() : (documento.getRootElement().getAttribute("lugarExpedicion") != null ? documento.getRootElement().getAttribute("lugarExpedicion").getValue() : "")); layout.setNumCtaPago(documento.getRootElement().getAttribute("NumCtaPago") != null ? documento.getRootElement().getAttribute("NumCtaPago").getValue() : (documento.getRootElement().getAttribute("numCtaPago") != null ? documento.getRootElement().getAttribute("numCtaPago").getValue() : "")); layout.setCondicionesDePago(documento.getRootElement().getAttribute("condicionesDePago") != null ? documento.getRootElement().getAttribute("condicionesDePago").getValue() : (documento.getRootElement().getAttribute("CondicionesDePago") != null ? documento.getRootElement().getAttribute("CondicionesDePago").getValue() : "")); Element emisor = documento.getRootElement().getChild("Emisor", Namespace.getNamespace("cfdi", "http://www.sat.gob.mx/cfd/3")); layout.setRFC(emisor.getAttribute("rfc") != null ? emisor.getAttribute("rfc").getValue() : (emisor.getAttribute("Rfc") != null ? emisor.getAttribute("Rfc").getValue() : "")); Element domicilioEmisor = emisor.getChild("DomicilioFiscal", Namespace.getNamespace("cfdi", "http://www.sat.gob.mx/cfd/3")); if (domicilioEmisor != null) { layout.setCp_df(domicilioEmisor.getAttribute("codigoPostal") != null ? domicilioEmisor.getAttribute("codigoPostal").getValue() : (domicilioEmisor.getAttribute("CodigoPostal") != null ? domicilioEmisor.getAttribute("CodigoPostal").getValue() : "")); layout.setPais_df(domicilioEmisor.getAttribute("pais") != null ? domicilioEmisor.getAttribute("pais").getValue() : (domicilioEmisor.getAttribute("Pais") != null ? domicilioEmisor.getAttribute("Pais").getValue() : "")); layout.setEstado_df(domicilioEmisor.getAttribute("estado") != null ? domicilioEmisor.getAttribute("estado").getValue() : (domicilioEmisor.getAttribute("Estado") != null ? domicilioEmisor.getAttribute("Estado").getValue() : "")); layout.setMunicipio_df(domicilioEmisor.getAttribute("municipio") != null ? domicilioEmisor.getAttribute("municipio").getValue() : (domicilioEmisor.getAttribute("Municipio") != null ? domicilioEmisor.getAttribute("Municipio").getValue() : "")); layout.setColonia_df(domicilioEmisor.getAttribute("colonia") != null ? domicilioEmisor.getAttribute("colonia").getValue() : (domicilioEmisor.getAttribute("Colonia") != null ? domicilioEmisor.getAttribute("Colonia").getValue() : "")); layout.setNoInterior_df(domicilioEmisor.getAttribute("noInterior") != null ? domicilioEmisor.getAttribute("noInterior").getValue() : (domicilioEmisor.getAttribute("NoInterior") != null ? domicilioEmisor.getAttribute("NoInterior").getValue() : "")); layout.setNoExterior_df(domicilioEmisor.getAttribute("noExterior") != null ? domicilioEmisor.getAttribute("noExterior").getValue() : (domicilioEmisor.getAttribute("NoExterior") != null ? domicilioEmisor.getAttribute("NoExterior").getValue() : "")); layout.setCalle_df(domicilioEmisor.getAttribute("calle") != null ? domicilioEmisor.getAttribute("calle").getValue() : (domicilioEmisor.getAttribute("Calle") != null ? domicilioEmisor.getAttribute("Calle").getValue() : "")); layout.setColonia_df(domicilioEmisor.getAttribute("localidad") != null ? domicilioEmisor.getAttribute("localidad").getValue() : (domicilioEmisor.getAttribute("Localidad") != null ? domicilioEmisor.getAttribute("Localidad").getValue() : "")); } Element expedidoEn = emisor.getChild("ExpedidoEn", Namespace.getNamespace("cfdi", "http://www.sat.gob.mx/cfd/3")); if (expedidoEn != null) { layout.setCp(expedidoEn.getAttribute("codigoPostal") != null ? expedidoEn.getAttribute("codigoPostal").getValue() : (expedidoEn.getAttribute("CodigoPostal") != null ? expedidoEn.getAttribute("CodigoPostal").getValue() : "")); layout.setPais( expedidoEn.getAttribute("pais") != null ? expedidoEn.getAttribute("pais").getValue() : (expedidoEn.getAttribute("Pais") != null ? expedidoEn.getAttribute("Pais").getValue() : "")); layout.setEstado( expedidoEn.getAttribute("estado") != null ? expedidoEn.getAttribute("estado").getValue() : (expedidoEn.getAttribute("Estado") != null ? expedidoEn.getAttribute("Estado").getValue() : "")); layout.setMunicipio(expedidoEn.getAttribute("municipio") != null ? expedidoEn.getAttribute("municipio").getValue() : (expedidoEn.getAttribute("Municipio") != null ? expedidoEn.getAttribute("Municipio").getValue() : "")); layout.setColonia(expedidoEn.getAttribute("colonia") != null ? expedidoEn.getAttribute("colonia").getValue() : (expedidoEn.getAttribute("Colonia") != null ? expedidoEn.getAttribute("Colonia").getValue() : "")); layout.setNoInterior(expedidoEn.getAttribute("noInterior") != null ? expedidoEn.getAttribute("noInterior").getValue() : (expedidoEn.getAttribute("NoInterior") != null ? expedidoEn.getAttribute("NoInterior").getValue() : "")); layout.setNoExterior(expedidoEn.getAttribute("noExterior") != null ? expedidoEn.getAttribute("noExterior").getValue() : (expedidoEn.getAttribute("NoExterior") != null ? expedidoEn.getAttribute("NoExterior").getValue() : "")); layout.setCalle( expedidoEn.getAttribute("calle") != null ? expedidoEn.getAttribute("calle").getValue() : (expedidoEn.getAttribute("Calle") != null ? expedidoEn.getAttribute("Calle").getValue() : "")); } Element regimenFiscal = emisor.getChild("RegimenFiscal", Namespace.getNamespace("cfdi", "http://www.sat.gob.mx/cfd/3")); if (regimenFiscal != null) { layout.setRegimenFiscal(regimenFiscal.getAttribute("Regimen") != null ? regimenFiscal.getAttribute("Regimen").getValue() : (regimenFiscal.getAttribute("regimen") != null ? regimenFiscal.getAttribute("regimen").getValue() : "")); } layout.setNombreEmisor(emisor.getAttribute("nombre") != null ? emisor.getAttribute("nombre").getValue() : (emisor.getAttribute("Nombre") != null ? emisor.getAttribute("Nombre").getValue() : "")); Element receptor = documento.getRootElement().getChild("Receptor", Namespace.getNamespace("cfdi", "http://www.sat.gob.mx/cfd/3")); layout.setNombreReceptor( receptor.getAttribute("nombre") != null ? receptor.getAttribute("nombre").getValue() : (receptor.getAttribute("Nombre") != null ? receptor.getAttribute("Nombre").getValue() : "")); layout.setRfcReceptor(receptor.getAttribute("rfc") != null ? receptor.getAttribute("rfc").getValue() : (receptor.getAttribute("Rfc") != null ? receptor.getAttribute("Rfc").getValue() : "")); Element domicilioReceptor = receptor.getChild("Domicilio", Namespace.getNamespace("cfdi", "http://www.sat.gob.mx/cfd/3")); if (domicilioReceptor != null) { layout.setCpReceptor(domicilioReceptor.getAttribute("codigoPostal") != null ? domicilioReceptor.getAttribute("codigoPostal").getValue() : (domicilioReceptor.getAttribute("CodigoPostal") != null ? domicilioReceptor.getAttribute("CodigoPostal").getValue() : "")); layout.setPaisReceptor(domicilioReceptor.getAttribute("pais") != null ? domicilioReceptor.getAttribute("pais").getValue() : (domicilioReceptor.getAttribute("Pais") != null ? domicilioReceptor.getAttribute("Pais").getValue() : "")); layout.setEstadoReceptor(domicilioReceptor.getAttribute("estado") != null ? domicilioReceptor.getAttribute("estado").getValue() : (domicilioReceptor.getAttribute("Estado") != null ? domicilioReceptor.getAttribute("Estado").getValue() : "")); layout.setMunicipioReceptor(domicilioReceptor.getAttribute("municipio") != null ? domicilioReceptor.getAttribute("municipio").getValue() : (domicilioReceptor.getAttribute("Municipio") != null ? domicilioReceptor.getAttribute("Municipio").getValue() : "")); layout.setColoniaReceptor(domicilioReceptor.getAttribute("colonia") != null ? domicilioReceptor.getAttribute("colonia").getValue() : (domicilioReceptor.getAttribute("Colonia") != null ? domicilioReceptor.getAttribute("Colonia").getValue() : "")); layout.setNoInteriorReceptor(domicilioReceptor.getAttribute("noInterior") != null ? domicilioReceptor.getAttribute("noInterior").getValue() : (domicilioReceptor.getAttribute("NoInterior") != null ? domicilioReceptor.getAttribute("NoInterior").getValue() : "")); layout.setNoExteriorReceptor(domicilioReceptor.getAttribute("noExterior") != null ? domicilioReceptor.getAttribute("noExterior").getValue() : (domicilioReceptor.getAttribute("NoExterior") != null ? domicilioReceptor.getAttribute("NoExterior").getValue() : "")); layout.setCalleReceptor(domicilioReceptor.getAttribute("calle") != null ? domicilioReceptor.getAttribute("calle").getValue() : (domicilioReceptor.getAttribute("Calle") != null ? domicilioReceptor.getAttribute("Calle").getValue() : "")); } Element impuestos = documento.getRootElement().getChild("Impuestos", Namespace.getNamespace("cfdi", "http://www.sat.gob.mx/cfd/3")); if (impuestos != null) { layout.setRetenidos(impuestos.getAttribute("totalImpuestosRetenidos") != null ? impuestos.getAttribute("totalImpuestosRetenidos").getValue() : (impuestos.getAttribute("TotalImpuestosRetenidos") != null ? impuestos.getAttribute("TotalImpuestosRetenidos").getValue() : "")); layout.setTrasladados(impuestos.getAttribute("totalImpuestosTrasladados") != null ? impuestos.getAttribute("totalImpuestosTrasladados").getValue() : (impuestos.getAttribute("TotalImpuestosTrasladados") != null ? impuestos.getAttribute("TotalImpuestosTrasladados").getValue() : "")); Element retenciones = impuestos.getChild("Retenciones", Namespace.getNamespace("cfdi", "http://www.sat.gob.mx/cfd/3")); if (retenciones != null) { Element retencion = retenciones.getChild("Retencion", Namespace.getNamespace("cfdi", "http://www.sat.gob.mx/cfd/3")); layout.setImpuestoRetenido(retencion.getAttribute("impuesto") != null ? retencion.getAttribute("impuesto").getValue() : (retencion.getAttribute("Impuesto") != null ? retencion.getAttribute("Impuesto").getValue() : "")); layout.setImporteRetenido(retencion.getAttribute("importe") != null ? retencion.getAttribute("importe").getValue() : (retencion.getAttribute("Importe") != null ? retencion.getAttribute("Importe").getValue() : "")); } Element trasladados = impuestos.getChild("Trasladados", Namespace.getNamespace("cfdi", "http://www.sat.gob.mx/cfd/3")); if (trasladados != null) { Element trasladado = trasladados.getChild("Trasladado", Namespace.getNamespace("cfdi", "http://www.sat.gob.mx/cfd/3")); layout.setImpuestoTrasladado(trasladado.getAttribute("impuesto") != null ? trasladado.getAttribute("impuesto").getValue() : (trasladado.getAttribute("Impuesto") != null ? trasladado.getAttribute("Impuesto").getValue() : "")); layout.setImporteTrasladado(trasladado.getAttribute("importe") != null ? trasladado.getAttribute("importe").getValue() : (trasladado.getAttribute("Importe") != null ? trasladado.getAttribute("Importe").getValue() : "")); layout.setTasaTrasladado( trasladado.getAttribute("tasa") != null ? trasladado.getAttribute("tasa").getValue() : (trasladado.getAttribute("Tasa") != null ? trasladado.getAttribute("Tasa").getValue() : "")); } } else { layout.setRetenidos(""); layout.setTrasladados(""); layout.setImpuestoRetenido(""); layout.setImporteRetenido(""); layout.setImpuestoTrasladado(""); layout.setImporteTrasladado(""); layout.setTasaTrasladado(""); } Element complemento = documento.getRootElement().getChild("Complemento", Namespace.getNamespace("cfdi", "http://www.sat.gob.mx/cfd/3")); Element nomina = complemento.getChild("Nomina", Namespace.getNamespace("nomina", "http://www.sat.gob.mx/nomina")); Element conceptos = documento.getRootElement().getChild("Conceptos", Namespace.getNamespace("cfdi", "http://www.sat.gob.mx/cfd/3")); if (nomina != null) { Element concepto = conceptos.getChild("Concepto", Namespace.getNamespace("cfdi", "http://www.sat.gob.mx/cfd/3")); if (concepto != null) { layout.setImporte(concepto.getAttribute("importe") != null ? concepto.getAttribute("importe").getValue() : (concepto.getAttribute("Importe") != null ? concepto.getAttribute("Importe").getValue() : "")); layout.setValorUnitario(concepto.getAttribute("valorUnitario") != null ? concepto.getAttribute("valorUnitario").getValue() : (concepto.getAttribute("ValorUnitario") != null ? concepto.getAttribute("ValorUnitario").getValue() : "")); layout.setDescripcion(concepto.getAttribute("descripcion") != null ? concepto.getAttribute("descripcion").getValue() : (concepto.getAttribute("Descripcion") != null ? concepto.getAttribute("Descripcion").getValue() : "")); layout.setUnidad( concepto.getAttribute("unidad") != null ? concepto.getAttribute("unidad").getValue() : (concepto.getAttribute("Unidad") != null ? concepto.getAttribute("Unidad").getValue() : "")); layout.setCantidad(concepto.getAttribute("cantidad") != null ? concepto.getAttribute("cantidad").getValue() : (concepto.getAttribute("Cantidad") != null ? concepto.getAttribute("Cantidad").getValue() : "")); } layout.setComprobanteTipo("NOMINA"); layout.setPuesto( nomina.getAttribute("Puesto") != null ? nomina.getAttribute("Puesto").getValue() : (nomina.getAttribute("puesto") != null ? nomina.getAttribute("puesto").getValue() : "")); layout.setFechaInicioRelLaboral(nomina.getAttribute("FechaInicioRelLaboral") != null ? nomina.getAttribute("FechaInicioRelLaboral").getValue() : (nomina.getAttribute("fechaInicioRelLaboral") != null ? nomina.getAttribute("fechaInicioRelLaboral").getValue() : "")); layout.setClabe(nomina.getAttribute("CLABE") != null ? nomina.getAttribute("CLABE").getValue() : (nomina.getAttribute("clabe") != null ? nomina.getAttribute("clabe").getValue() : "")); layout.setBanco(nomina.getAttribute("Banco") != null ? nomina.getAttribute("Banco").getValue() : (nomina.getAttribute("banco") != null ? nomina.getAttribute("banco").getValue() : "")); layout.setTipoContrato(nomina.getAttribute("TipoContrato") != null ? nomina.getAttribute("TipoContrato").getValue() : (nomina.getAttribute("tipoContrato") != null ? nomina.getAttribute("tipoContrato").getValue() : "")); layout.setRiesgoPuesto(nomina.getAttribute("RiesgoPuesto") != null ? nomina.getAttribute("RiesgoPuesto").getValue() : (nomina.getAttribute("riesgoPuesto") != null ? nomina.getAttribute("riesgoPuesto").getValue() : "")); layout.setSalarioDiarioIntegrado(nomina.getAttribute("SalarioDiarioIntegrado") != null ? nomina.getAttribute("SalarioDiarioIntegrado").getValue() : (nomina.getAttribute("salarioDiarioIntegrado") != null ? nomina.getAttribute("salarioDiarioIntegrado").getValue() : "")); layout.setSalarioBaseCotApor(nomina.getAttribute("SalarioBaseCotApor") != null ? nomina.getAttribute("SalarioBaseCotApor").getValue() : (nomina.getAttribute("salarioBaseCotApor") != null ? nomina.getAttribute("salarioBaseCotApor").getValue() : "")); layout.setTipoJornada(nomina.getAttribute("TipoJornada") != null ? nomina.getAttribute("TipoJornada").getValue() : (nomina.getAttribute("tipoJornada") != null ? nomina.getAttribute("tipoJornada").getValue() : "")); layout.setPeriodicidadPago(nomina.getAttribute("PeriodicidadPago") != null ? nomina.getAttribute("PeriodicidadPago").getValue() : (nomina.getAttribute("periodicidadPago") != null ? nomina.getAttribute("periodicidadPago").getValue() : "")); layout.setCurp(nomina.getAttribute("CURP") != null ? nomina.getAttribute("CURP").getValue() : (nomina.getAttribute("curp") != null ? nomina.getAttribute("curp").getValue() : "")); layout.setTipoRegimen(nomina.getAttribute("TipoRegimen") != null ? nomina.getAttribute("TipoRegimen").getValue() : (nomina.getAttribute("tipoRegimen") != null ? nomina.getAttribute("tipoRegimen").getValue() : "")); layout.setNumEmpleado(nomina.getAttribute("NumEmpleado") != null ? nomina.getAttribute("NumEmpleado").getValue() : (nomina.getAttribute("numEmpleado") != null ? nomina.getAttribute("numEmpleado").getValue() : "")); layout.setVersionN( nomina.getAttribute("Version") != null ? nomina.getAttribute("Version").getValue() : (nomina.getAttribute("version") != null ? nomina.getAttribute("version").getValue() : "")); layout.setRegistroPatronal(nomina.getAttribute("RegistroPatronal") != null ? nomina.getAttribute("RegistroPatronal").getValue() : (nomina.getAttribute("registroPatronal") != null ? nomina.getAttribute("registroPatronal").getValue() : "")); layout.setNss(nomina.getAttribute("NumSeguridadSocial") != null ? nomina.getAttribute("NumSeguridadSocial").getValue() : (nomina.getAttribute("numSeguridadSocial") != null ? nomina.getAttribute("numSeguridadSocial").getValue() : "")); layout.setNumDiasPagados(nomina.getAttribute("NumDiasPagados") != null ? nomina.getAttribute("NumDiasPagados").getValue() : (nomina.getAttribute("numDiasPagados") != null ? nomina.getAttribute("numDiasPagados").getValue() : "")); layout.setDepartamento(nomina.getAttribute("Departamento") != null ? nomina.getAttribute("Departamento").getValue() : (nomina.getAttribute("departamento") != null ? nomina.getAttribute("departamento").getValue() : "")); layout.setFechaFinalPago(nomina.getAttribute("FechaFinalPago") != null ? nomina.getAttribute("FechaFinalPago").getValue() : (nomina.getAttribute("fechaFinalPago") != null ? nomina.getAttribute("fechaFinalPago").getValue() : "")); layout.setFechaPago( nomina.getAttribute("FechaPago") != null ? nomina.getAttribute("FechaPago").getValue() : (nomina.getAttribute("fechaPago") != null ? nomina.getAttribute("fechaPago").getValue() : "")); layout.setFechaInicialPago(nomina.getAttribute("FechaInicialPago") != null ? nomina.getAttribute("FechaInicialPago").getValue() : (nomina.getAttribute("fechaInicialPago") != null ? nomina.getAttribute("fechaInicialPago").getValue() : "")); Element persepciones = nomina.getChild("Percepciones", Namespace.getNamespace("nomina", "http://www.sat.gob.mx/nomina")); if (persepciones != null) { layout.setTotalExentoP(persepciones.getAttribute("TotalExento") != null ? persepciones.getAttribute("TotalExento").getValue() : (persepciones.getAttribute("totalExento") != null ? persepciones.getAttribute("totalExento").getValue() : "")); layout.setTotalGravadoP(persepciones.getAttribute("TotalGravado") != null ? persepciones.getAttribute("TotalGravado").getValue() : (persepciones.getAttribute("totalGravado") != null ? persepciones.getAttribute("totalGravado").getValue() : "")); for (Element persepcion : persepciones.getChildren()) { NominaDetalle nominaDetalle = new NominaDetalle(); nominaDetalle.setTipo(persepcion.getAttribute("TipoPercepcion") != null ? persepcion.getAttribute("TipoPercepcion").getValue() : (persepcion.getAttribute("tipoPercepcion") != null ? persepcion.getAttribute("tipoPercepcion").getValue() : "")); nominaDetalle.setConcepto(persepcion.getAttribute("Concepto") != null ? persepcion.getAttribute("Concepto").getValue() : (persepcion.getAttribute("concepto") != null ? persepcion.getAttribute("concepto").getValue() : "")); nominaDetalle.setClave(persepcion.getAttribute("Clave") != null ? persepcion.getAttribute("Clave").getValue() : (persepcion.getAttribute("clave") != null ? persepcion.getAttribute("clave").getValue() : "")); nominaDetalle.setImporteGravado(persepcion.getAttribute("ImporteGravado") != null ? persepcion.getAttribute("ImporteGravado").getValue() : (persepcion.getAttribute("importeGravado") != null ? persepcion.getAttribute("importeGravado").getValue() : "")); nominaDetalle.setImporteExento(persepcion.getAttribute("ImporteExento") != null ? persepcion.getAttribute("ImporteExento").getValue() : (persepcion.getAttribute("importeExento") != null ? persepcion.getAttribute("importeExento").getValue() : "")); nominaDetalle.setTipoConcepto("1"); layout.addNominaDetalle(nominaDetalle); } } Element deducciones = nomina.getChild("Deducciones", Namespace.getNamespace("nomina", "http://www.sat.gob.mx/nomina")); if (deducciones != null) { layout.setTotalExentoD(deducciones.getAttribute("TotalExento") != null ? deducciones.getAttribute("TotalExento").getValue() : (deducciones.getAttribute("totalExento") != null ? deducciones.getAttribute("totalExento").getValue() : "")); layout.setTotalGravadoD(deducciones.getAttribute("TotalGravado") != null ? deducciones.getAttribute("TotalGravado").getValue() : (deducciones.getAttribute("totalGravado") != null ? deducciones.getAttribute("totalGravado").getValue() : "")); for (Element deduccion : deducciones.getChildren()) { NominaDetalle nominaDetalle = new NominaDetalle(); nominaDetalle.setTipo(deduccion.getAttribute("TipoDeduccion") != null ? deduccion.getAttribute("TipoDeduccion").getValue() : (deduccion.getAttribute("tipoDeduccion") != null ? deduccion.getAttribute("tipoDeduccion").getValue() : "")); nominaDetalle.setConcepto(deduccion.getAttribute("Concepto") != null ? deduccion.getAttribute("Concepto").getValue() : (deduccion.getAttribute("concepto") != null ? deduccion.getAttribute("concepto").getValue() : "")); nominaDetalle.setClave(deduccion.getAttribute("Clave") != null ? deduccion.getAttribute("Clave").getValue() : (deduccion.getAttribute("clave") != null ? deduccion.getAttribute("clave").getValue() : "")); nominaDetalle.setImporteGravado(deduccion.getAttribute("ImporteGravado") != null ? deduccion.getAttribute("ImporteGravado").getValue() : (deduccion.getAttribute("importeGravado") != null ? deduccion.getAttribute("importeGravado").getValue() : "")); nominaDetalle.setImporteExento(deduccion.getAttribute("ImporteExento") != null ? deduccion.getAttribute("ImporteExento").getValue() : (deduccion.getAttribute("importeExento") != null ? deduccion.getAttribute("importeExento").getValue() : "")); nominaDetalle.setTipoConcepto("2"); layout.addNominaDetalle(nominaDetalle); } } } else { layout.setComprobanteTipo("FACTURA"); for (Element concepto : conceptos.getChildren()) { IngresoDetalle ingresoDetalle = new IngresoDetalle(); ingresoDetalle.setImporte(concepto.getAttribute("importe") != null ? concepto.getAttribute("importe").getValue() : (concepto.getAttribute("importe") != null ? concepto.getAttribute("importe").getValue() : "")); ingresoDetalle.setValorUnitario(concepto.getAttribute("valorUnitario") != null ? concepto.getAttribute("valorUnitario").getValue() : (concepto.getAttribute("valorUnitario") != null ? concepto.getAttribute("valorUnitario").getValue() : "")); ingresoDetalle.setDescripcion(concepto.getAttribute("descripcion") != null ? concepto.getAttribute("descripcion").getValue() : (concepto.getAttribute("descripcion") != null ? concepto.getAttribute("descripcion").getValue() : "")); ingresoDetalle.setUnidad( concepto.getAttribute("unidad") != null ? concepto.getAttribute("unidad").getValue() : (concepto.getAttribute("unidad") != null ? concepto.getAttribute("unidad").getValue() : "")); ingresoDetalle.setCantidad(concepto.getAttribute("cantidad") != null ? concepto.getAttribute("cantidad").getValue() : (concepto.getAttribute("cantidad") != null ? concepto.getAttribute("cantidad").getValue() : "")); layout.addIngresoDetalle(ingresoDetalle); } } Element timbreFiscal = complemento.getChild("TimbreFiscalDigital", Namespace.getNamespace("tfd", "http://www.sat.gob.mx/TimbreFiscalDigital")); if (timbreFiscal != null) { layout.setUuid( timbreFiscal.getAttribute("UUID") != null ? timbreFiscal.getAttribute("UUID").getValue() : (timbreFiscal.getAttribute("Uuid") != null ? timbreFiscal.getAttribute("Uuid").getValue() : "")); layout.setFechaTimbrado(timbreFiscal.getAttribute("FechaTimbrado") != null ? timbreFiscal.getAttribute("FechaTimbrado").getValue() : (timbreFiscal.getAttribute("fechaTimbrado") != null ? timbreFiscal.getAttribute("fechaTimbrado").getValue() : "")); layout.setSelloCfd(timbreFiscal.getAttribute("selloCFD") != null ? timbreFiscal.getAttribute("selloCFD").getValue() : (timbreFiscal.getAttribute("SelloCFD") != null ? timbreFiscal.getAttribute("SelloCFD").getValue() : "")); layout.setNoCertificadoSat(timbreFiscal.getAttribute("noCertificadoSAT") != null ? timbreFiscal.getAttribute("noCertificadoSAT").getValue() : (timbreFiscal.getAttribute("NoCertificadoSAT") != null ? timbreFiscal.getAttribute("NoCertificadoSAT").getValue() : "")); layout.setSelloSat(timbreFiscal.getAttribute("selloSAT") != null ? timbreFiscal.getAttribute("selloSAT").getValue() : (timbreFiscal.getAttribute("SelloSAT") != null ? timbreFiscal.getAttribute("SelloSAT").getValue() : "")); } layout.setCadenaOriginal( "||" + layout.getVersion() + "|" + layout.getUuid() + "|" + layout.getFechaTimbrado() + "|" + layout.getSelloCfd() + "|" + layout.getNoCertificadoSat() + "||"); } catch (JDOMException e) { logger.log(Level.SEVERE, "{0}: {1}", new Object[] { nombreArchivo, e.getMessage() }); layout = null; } } catch (IOException e) { logger.log(Level.SEVERE, "{0}: {1}", new Object[] { nombreArchivo, e.getMessage() }); layout = null; } catch (Exception ex) { logger.log(Level.SEVERE, "{0}: {1}", new Object[] { nombreArchivo, ex.getMessage() }); layout = null; } if (showLog) logger.log(Level.INFO, "Fin parse "); return layout; }
From source file:ch.kostceco.tools.kostval.validation.modulesiard.impl.ValidationDstructureModuleImpl.java
License:Open Source License
@Override public boolean validate(File valDatei, File directoryOfLogfile) throws ValidationDstructureException { // Ausgabe SIARD-Modul Ersichtlich das KOST-Val arbeitet System.out.print("D "); System.out.print("\r"); int onWork = 41; boolean valid = true; try {//from ww w .j a v a 2 s. c o m /* Extract the metadata.xml from the temporare work folder and build a jdom document */ String pathToWorkDir = getConfigurationService().getPathToWorkDir(); pathToWorkDir = pathToWorkDir + File.separator + "SIARD"; File metadataXml = new File(new StringBuilder(pathToWorkDir).append(File.separator).append("header") .append(File.separator).append("metadata.xml").toString()); InputStream fin = new FileInputStream(metadataXml); SAXBuilder builder = new SAXBuilder(); Document document = builder.build(fin); fin.close(); /* read the document and for each schema and table entry verify existence in temporary * extracted structure */ Namespace ns = Namespace.getNamespace("http://www.bar.admin.ch/xmlns/siard/1.0/metadata.xsd"); // select schema elements and loop List<Element> schemas = document.getRootElement().getChild("schemas", ns).getChildren("schema", ns); for (Element schema : schemas) { valid = validateSchema(schema, ns, pathToWorkDir); if (onWork == 41) { onWork = 2; System.out.print("D- "); System.out.print("\r"); } else if (onWork == 11) { onWork = 12; System.out.print("D\\ "); System.out.print("\r"); } else if (onWork == 21) { onWork = 22; System.out.print("D| "); System.out.print("\r"); } else if (onWork == 31) { onWork = 32; System.out.print("D/ "); System.out.print("\r"); } else { onWork = onWork + 1; } } } catch (java.io.IOException ioe) { valid = false; getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_D_SIARD) + getTextResourceService().getText(ERROR_XML_UNKNOWN, ioe.getMessage() + " (IOException)")); } catch (JDOMException e) { valid = false; getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_D_SIARD) + getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage() + " (JDOMException)")); } return valid; }
From source file:ch.kostceco.tools.kostval.validation.modulesiard.impl.ValidationEcolumnModuleImpl.java
License:Open Source License
private boolean prepareXMLAccess(ValidationContext validationContext) throws JDOMException, IOException, Exception { boolean successfullyCommitted = false; Properties properties = validationContext.getValidationProperties(); File metadataXML = validationContext.getMetadataXML(); InputStream inputStream = new FileInputStream(metadataXML); SAXBuilder builder = new SAXBuilder(); Document document = builder.build(inputStream); // Assigning JDOM Document to the validation context validationContext.setMetadataXMLDocument(document); String xmlPrefix = properties.getProperty("module.e.metadata.xml.prefix"); String xsdPrefix = properties.getProperty("module.e.table.xsd.prefix"); // Setting the namespaces to access metadata.xml and the different table.xsd Element rootElement = document.getRootElement(); String namespaceURI = rootElement.getNamespaceURI(); Namespace xmlNamespace = Namespace.getNamespace(xmlPrefix, namespaceURI); Namespace xsdNamespace = Namespace.getNamespace(xsdPrefix, namespaceURI); // Assigning prefix to the validation context validationContext.setXmlPrefix(xmlPrefix); validationContext.setXsdPrefix(xsdPrefix); // Assigning namespace info to the validation context validationContext.setXmlNamespace(xmlNamespace); validationContext.setXsdNamespace(xsdNamespace); if (validationContext.getXmlNamespace() != null && validationContext.getXsdNamespace() != null && validationContext.getXmlPrefix() != null && validationContext.getXsdPrefix() != null && validationContext.getMetadataXMLDocument() != null && validationContext.getValidationProperties() != null) { this.setValidationContext(validationContext); successfullyCommitted = true;/* w w w. j a v a2s .c om*/ } else { successfullyCommitted = false; this.setValidationContext(null); throw new Exception(); } return successfullyCommitted; }