elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


  Mostrar Mensajes
Páginas: 1 ... 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 [25] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 ... 139
241  Programación / Java / Re: modificar XML en: 8 Mayo 2020, 11:20 am
bueno gracias le echare cabeza  :laugh: :laugh:


Otra cosa, usa JSON mejor.
242  Programación / Java / Re: modificar XML en: 8 Mayo 2020, 11:09 am
Básicamente lo que busco es tener un opción de añadir nueva película, si lo pongo como me dices tendría que sobrescribir el xml que ya tengo creado?

Tal cual dog... asi mismo.

Para añadir otro Nodo digamos, debes reprogramarlo , ya tienes una idea al menos.
243  Programación / Java / Re: modificar XML en: 8 Mayo 2020, 10:59 am
No se si es mucha molestia... y para crear un nodo nuevo dentro de películas solo tendría que usar el builder y mandarle los datos por teclado ? y donde lo pondría al principio o al final.

Respuesta innesperada, pense que solo querías copiar y pegar LMAOOO

Para crear un nodo nuevo, instanciando el builder puedes hacer o añadiendo otro con el metodo añadir que te tocaría reprogramarlo, si que hay mucha informacion por ahi.

Recordemos que el Builder y su method chaining tienen cierto orden a la hora de crear Objetos entonces, sabiendo eso. puedes invocar a createNodeAndChild 3 veces, ejemplo:


Código
  1. new Presentar.Builder()
  2.            .conDocument(BuilderFile.CREATE)
  3.            .conRootElement(TIENDA)
  4.            .conId("1")
  5.            .createNodeAndChild(PELICULA, "titulo", "Rambo 1")
  6.            .conId("2")
  7.            .createNodeAndChild(PELICULA, "titulo", "Rambo 2")
  8.            .conId("3")
  9.            .createNodeAndChild(PELICULA, "titulo", "ryhuso la resurrecion")
  10.            .build();
  11.  

244  Programación / Bases de Datos / Re: Oracle REGEXP se queda trabado en: 8 Mayo 2020, 07:31 am
Disculpen mi ignoracia pero alguien sabe por que las funciones REGEXPT_INSTR y REGEXP_LIKE se quedan trabadas en Oracle 10?

Entiendo que son costosas pero que no respondan ya es mucho...

Mi problema radica en esta consulta (no termina)

Código
  1. SELECT
  2. NVL(REGEXP_INSTR('(HTTP 500) - soapenv:ServerOSB-382500: OSB Service Callout action received SOAP Fault responseOSB-382500OSB Service Callout action received SOAP Fault responsesoapenv:Server(CM1-000559) Stop collection treatment is not allowed on this account',
  3. '(\r|\n|.)*\(HTTP 500\) \- soapenv\:ServerOSB\-382500(.*)\(CM1\-000559\) Stop collection treatment is not allowed on this(\r|\n|.)*'), 0)
  4. FROM DUAL;

Saludos.

REGEXP_INSTR sin la T dog.

y dulces y sangrientas lunasssssss
245  Programación / Java / Re: Lectura y escritura de datos en: 8 Mayo 2020, 07:00 am
ressscaaataaaaalaaaaaaa

use Open jdk 11  :-( :-( :-( :-( :-( :-( :-(

Descripción hyper supra breve: recorreremos el fichero y por el condicional, concatenamos las lineas pares en impares, en sus
respectivos StringBuilder, para luego escribirlos en los ficheros de cada quien, se concatena xq de lo contrario se escribiria la ulllltima linea solamente en cada fichero.

* El método write crea los ficheros si no existen, para flojos como yo, y vagos como tu  :silbar:

* la explicación esta 100% mala, llevo dias sin dormir
mas millll ediciones  >:D

Código
  1.    private static final Path RUTA_PARES = Path.of("pares.txt");
  2.    private static final Path RUTA_IMPARES = Path.of("impares.txt");

Código
  1. public App() {
  2.        readLines("archivo.txt"); //fichero principal
  3.    }
  4.  
  5.    /**
  6.      * (e % 2) == 0 pares , !=0 impares
  7.      *
  8.      * @param rutaFichero
  9.      */
  10.    private void readLines(final String rutaFichero) {
  11.        try (final Stream<String> lines = Files.lines(Path.of(rutaFichero))) {
  12.  
  13.            final AtomicReference<Integer> atomicCounter = new AtomicReference<>(1);
  14.            final StringBuilder pares = new StringBuilder();
  15.            final StringBuilder impares = new StringBuilder();
  16.  
  17.            lines.forEach(linea -> {
  18.                final Integer count = atomicCounter.getAndUpdate(e -> ++e);
  19.                if ((count % 2) == 0) {//pares
  20.                    pares.append(linea);
  21.                    pares.append(System.lineSeparator());
  22.                } else { //IMPARES
  23.                    impares.append(linea);
  24.                    impares.append(System.lineSeparator());
  25.                }
  26.            });
  27.            writer(RUTA_PARES, pares.toString());
  28.            writer(RUTA_IMPARES, impares.toString());
  29.  
  30.        } catch (IOException e) {
  31.            e.printStackTrace();
  32.        }
  33.  
  34.  
  35.    }
  36.  
  37.    private void writer(final Path path, String line) {
  38.  
  39.        if(!path.toFile().exists()) {
  40.            try {
  41.                Files.createFile(path);
  42.            } catch (IOException e) {
  43.                e.printStackTrace();
  44.            }
  45.        }
  46.  
  47.        try (final BufferedWriter br = Files.newBufferedWriter(path)) {
  48.  
  49.            br.write(line);
  50.            br.write(System.lineSeparator());
  51.  
  52.        } catch (IOException ex) {
  53.  
  54.        }
  55.    }
246  Programación / Java / Re: modificar XML en: 8 Mayo 2020, 04:54 am
Hice un Builder, debes invocar a la primera opción si no esta creado el archivo, opcion 0

Para crear usar numero 0
Código
  1. /**
  2. * Instanciando Builder para crear Elemento Root e hijos
  3. */
  4.     new Presentar.Builder()
  5.            .conDocument(BuilderFile.CREATE)
  6.            .conRootElement(TIENDA)
  7.            .conId("1")
  8.            .createNodeAndChild(PELICULA, "titulo", "Rambo 1")
  9.            .conId("2")
  10.            .createNodeAndChild(PELICULA, "titulo", "Rambo 2")
  11.            .build();

Para modificar el fichero usa

viejoNombre = Rambo 2
nuevoNombre= Rambo 2 la resurrecion

Código
  1. new Presentar.Builder()
  2.                    .conDocument(BuilderFile.READ)
  3.                    .modificarChilNode(viejoNombre, nuevoNombre)
  4.                    .build();
  5.  


Código
  1. package org.example;
  2.  
  3. import org.w3c.dom.*;
  4. import org.xml.sax.SAXException;
  5.  
  6. import javax.xml.parsers.DocumentBuilderFactory;
  7. import javax.xml.parsers.ParserConfigurationException;
  8. import javax.xml.transform.TransformerException;
  9. import javax.xml.transform.TransformerFactory;
  10. import javax.xml.transform.dom.DOMSource;
  11. import javax.xml.transform.stream.StreamResult;
  12. import java.io.File;
  13. import java.io.IOException;
  14. import java.nio.file.Path;
  15. import java.nio.file.Paths;
  16. import java.util.concurrent.atomic.AtomicBoolean;
  17. import java.util.logging.Logger;
  18. import java.util.stream.IntStream;
  19.  
  20. interface Log {
  21.    default void info(String texto) {
  22.        Logger.getLogger(Presentar.class.getSimpleName()).info(texto);
  23.    }
  24.  
  25.    default void warn(String texto) {
  26.        Logger.getLogger(Presentar.class.getSimpleName()).info(texto);
  27.    }
  28. }
  29.  
  30. enum BuilderFile {
  31.    CREATE,READ;
  32. }
  33.  
  34. /**
  35.  * @author orlando
  36.  */
  37. public class Presentar implements Log {
  38.  
  39.    private static final String PELICULA = "pelicula";
  40.    private static final String TIENDA = "tienda";
  41.  
  42.    /**
  43.      * Ruta por defecto para crear el fichero
  44.      */
  45.    private static final Path PATH_DOC_XML_FILE = Paths.get("peliculas.xml");
  46.  
  47.    /**
  48.      * Invocar primero si no existe documento
  49.      */
  50.    public void crearDocumento() {
  51.  
  52.        /**
  53.          * Instanciando Builder para crear Elemento Root e hijos
  54.          */
  55.        new Presentar.Builder()
  56.                .conDocument(BuilderFile.CREATE)
  57.                .conRootElement(TIENDA)
  58.                .conId("1")
  59.                .createNodeAndChild(PELICULA, "titulo", "Rambo 1")
  60.                .conId("2")
  61.                .createNodeAndChild(PELICULA, "titulo", "Rambo 2")
  62.                .build();
  63.  
  64.        info("Archivo creado correctamente!");
  65.  
  66.    }
  67.  
  68.  
  69.    public void presentar() {
  70.        try {
  71.  
  72.            final NodeList listaPelis = DocumentBuilderFactory.newInstance()
  73.                    .newDocumentBuilder()
  74.                    .parse(new File("peliculas.xml"))
  75.                    .getElementsByTagName(PELICULA);
  76.  
  77.            for (int i = 0; i < listaPelis.getLength(); i++) {
  78.  
  79.                Node nodo = listaPelis.item(i);
  80.  
  81.                if (nodo.getNodeType() == Node.ELEMENT_NODE) {
  82.  
  83.                    Element e = (Element) nodo;
  84.  
  85.                    NodeList hijos = e.getChildNodes();
  86.  
  87.                    for (int j = 0; j < hijos.getLength(); j++) {
  88.  
  89.                        Node hijo = hijos.item(j);
  90.  
  91.                        if (hijo.getNodeType() == Node.ELEMENT_NODE) {
  92.  
  93.                            info(hijo.getNodeName() + ":  " + hijo.getTextContent());
  94.  
  95.                        }
  96.  
  97.                    }
  98.                    info("----------------------------------------------");
  99.                }
  100.  
  101.            }
  102.  
  103.        } catch (ParserConfigurationException | SAXException | IOException ex) {
  104.            warn(ex.getMessage());
  105.        }
  106.    }
  107.  
  108.    public void Añadir() {
  109.  
  110.    }
  111.  
  112.    public void modificar(String nodoModificar, String nuevoNombre) {
  113.        try {
  114.  
  115.            new Presentar.Builder()
  116.                    .conDocument(BuilderFile.READ)
  117.                    .modificarChilNode(nodoModificar, nuevoNombre)
  118.                    .build();
  119.  
  120.        } catch (Exception e) {
  121.            warn(e.getMessage());
  122.        }
  123.    }
  124.  
  125.    public void eliminar() {
  126.  
  127.  
  128.    }
  129.  
  130.    /**
  131.      * Builder para crear elementos
  132.      */
  133.    public static class Builder implements Log {
  134.  
  135.        private Element rootElement;
  136.        private Attr attr;
  137.        private Document document;
  138.  
  139.        //Primero
  140.        public Builder conDocument(BuilderFile builderFile) {
  141.            if(builderFile == BuilderFile.CREATE) {
  142.                try {
  143.                    this.document = DocumentBuilderFactory.newInstance()
  144.                            .newDocumentBuilder()
  145.                            .newDocument();
  146.                } catch (ParserConfigurationException e) {
  147.                    warn("{} error en createNewDocument()");
  148.                }
  149.            } else if(builderFile == BuilderFile.READ){
  150.                try {
  151.                    this.document = DocumentBuilderFactory.newInstance()
  152.                            .newDocumentBuilder()
  153.                            .parse(PATH_DOC_XML_FILE.toFile());
  154.                } catch (ParserConfigurationException e) {
  155.                    warn("{} error en createNewDocument()");
  156.                } catch (SAXException e) {
  157.                    e.printStackTrace();
  158.                } catch (IOException e) {
  159.                    e.printStackTrace();
  160.                }
  161.            }
  162.  
  163.            return this;
  164.        }
  165.  
  166.        //Segundo titulo
  167.        public Builder conRootElement(final String nombre) {
  168.            this.rootElement = document.createElement(nombre);
  169.            document.appendChild(rootElement);
  170.            return this;
  171.        }
  172.  
  173.        public Builder conId(final String id) {
  174.            this.attr = document.createAttribute("id");
  175.            attr.setValue(id);
  176.            return this;
  177.        }
  178.  
  179.        //Pelicula
  180.        public Builder createNodeAndChild(final String nodeName, final String title, final String childName) {
  181.            //Node title
  182.            final Element nodeTitle = document.createElement(nodeName);
  183.            rootElement.appendChild(nodeTitle);
  184.            nodeTitle.setAttributeNode(this.attr);
  185.  
  186.            //Child title
  187.            final Element childNameTitle = document.createElement(title);
  188.            childNameTitle.appendChild(document.createTextNode(childName));
  189.            nodeTitle.appendChild(childNameTitle);
  190.            return this;
  191.        }
  192.  
  193.        public Builder modificarChilNode(final String viejoNombre, final String nuevoNombre) {
  194.            //normalizar
  195.            document.getDocumentElement().normalize();
  196.            //Lista peliculas
  197.            final NodeList listaPeliculas = document.getElementsByTagName(PELICULA);
  198.  
  199.            final AtomicBoolean value = new AtomicBoolean(true);
  200.            IntStream.range(0, listaPeliculas.getLength())
  201.                    .boxed()
  202.                    .parallel()
  203.                    .forEachOrdered(pelicula -> {
  204.                        final Node node = listaPeliculas.item(pelicula);
  205.                        if (node.getNodeType() == Node.ELEMENT_NODE) {
  206.                            final Element element = (Element) node;
  207.                            if (element.hasChildNodes()) {
  208.                                final NodeList childNodes = node.getChildNodes();
  209.                                for (int j = 0; j < childNodes.getLength(); j++) {
  210.                                    final Node child = childNodes.item(j);
  211.                                    if (child.getTextContent().equals(viejoNombre)) {
  212.                                        child.setTextContent(nuevoNombre);
  213.                                        info("Nodo: ".concat(viejoNombre)
  214.                                                .concat(" cambiado por ")
  215.                                                .concat(nuevoNombre));
  216.                                        info("Edición terminada correctamente");
  217.                                        value.set(false);
  218.                                    }
  219.                                }
  220.                            }
  221.                        }
  222.                    });
  223.            if(value.get()) {
  224.                warn("No existe el titulo");
  225.            }
  226.            return this;
  227.        }
  228.  
  229.        public Builder build() {
  230.            try {
  231.                TransformerFactory.newInstance()
  232.                        .newTransformer()
  233.                        .transform(new DOMSource(document), new StreamResult(PATH_DOC_XML_FILE.toFile()));
  234.            } catch (TransformerException e) {
  235.                warn("error al escribir en fichero .xml");
  236.            }
  237.            return this;
  238.        }
  239.    }
  240.  
  241. }
  242. }

Codigo del switch

Código
  1. //Mejor Map<String,String> a
  2.            switch (opcion) {
  3.                case 0:
  4.                    final Presentar presentar = new Presentar();
  5.                    presentar.crearDocumento();
  6.                    break;
  7.                case 1:
  8.                    Presentar p = new Presentar();
  9.                    p.presentar();
  10.                    break;
  11.                case 2:
  12.                    break;
  13.                case 3:
  14.                    entrada.nextLine();
  15.                    System.out.println("Ingresa el nodo a modificar");
  16.                    String nombreNodo = entrada.nextLine();
  17.                    System.out.println("Ingresa nuevo nombre");
  18.                    String nuevoNombre = entrada.nextLine();
  19.  
  20.                    Presentar m = new Presentar();
  21.                    m.modificar(nombreNodo, nuevoNombre);
  22.                    break;
  23.                case 4:
  24.                    break;
  25.                case 5:
  26.                    System.exit(0);
  27.                    break;
  28.                default:
  29.                    System.out.println("Opcion no valida");
  30.                    break;
  31.            }
247  Programación / Java / Re: modificar XML en: 7 Mayo 2020, 15:35 pm
Q tal que es la que hay?

Pues bien, Pon lo que llevas al menos ni idea tengo un por donde vas,

Con un fichero Properties quizá quizá, valla la cuention por ahí.
248  Seguridad Informática / Abril negro / Re: Abril Negro 2020 - Shareware Ransomware en: 2 Mayo 2020, 17:27 pm
veo que los .class y .java se salvaron LMAO
249  Foros Generales / Foro Libre / Re: Más de 5.000 euros por escapar de España en patera en: 27 Abril 2020, 01:34 am
De Venezuela uno no puede escapar en una "pantera" porque aquí no hay de eso... nada mas tenemos "pumas y jaguares"... grrrrrrrrr...

 :rolleyes: :o :rolleyes:

lince y onza tambien loco.
250  Foros Generales / Sugerencias y dudas sobre el Foro / Re: Consulta de resolución óptima del Avatar del foro sin barras de desplazamiento en: 25 Abril 2020, 01:13 am
Estoy actualizando mi avatar con After Effects y tengo una duda:

¿Cuál es la mayor resolución posible sin que se muestren las barras de desplazamiento en los publicaciones del foro?

Como puede verse aquí calculé una resolución de 190x300 píxeles pero aún así, se muestran las barra de desplazamiento horizontal... Quiero si alguien del foro pueda decirme la resolución más alta sin barras de desplazamiento:



B#

que hay Sangre# , yo veo tu nick perfecto, no se si lo actualizaste?, o sea, lo veo sin barra horizontal. mi pantalla es 1920*1080
Páginas: 1 ... 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 [25] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 ... 139
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines