Search in sources :

Example 76 with Document

use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project jPOS by jpos.

the class Q2 method encrypt.

protected Document encrypt(Document doc) throws GeneralSecurityException, IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    OutputStreamWriter writer = new OutputStreamWriter(os);
    XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
    out.output(doc, writer);
    writer.close();
    byte[] crypt = dodes(os.toByteArray(), Cipher.ENCRYPT_MODE);
    Document secureDoc = new Document();
    Element root = new Element(PROTECTED_QBEAN);
    secureDoc.setRootElement(root);
    Element secureData = new Element("data");
    root.addContent(secureData);
    secureData.setText(ISOUtil.hexString(crypt));
    return secureDoc;
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 77 with Document

use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project jPOS by jpos.

the class Q2 method deployResource.

private void deployResource(String resource) throws IOException, SAXException, JDOMException, GeneralSecurityException, ISOException {
    SAXBuilder builder = new SAXBuilder();
    try (InputStream source = getClass().getClassLoader().getResourceAsStream(resource)) {
        Document doc = builder.build(source);
        deployElement(doc.getRootElement(), resource.substring(DEPLOY_PREFIX.length()), false, true);
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Document(org.jdom2.Document)

Example 78 with Document

use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project cxf by apache.

the class AbstractTypeTestClient2 method testDocument.

@Test
public void testDocument() throws Exception {
    if (!shouldRunTest("Document")) {
        return;
    }
    Document x = new Document();
    x.setValue("content-x");
    x.setID("Hello There");
    Document yOrig = new Document();
    yOrig.setID("Cheerio");
    yOrig.setValue("content-y");
    Holder<Document> y = new Holder<Document>(yOrig);
    Holder<Document> z = new Holder<Document>();
    Document ret;
    if (testDocLiteral) {
        ret = docClient.testDocument(x, y, z);
    } else if (testXMLBinding) {
        ret = xmlClient.testDocument(x, y, z);
    } else {
        ret = rpcClient.testDocument(x, y, z);
    }
    if (!perfTestOnly) {
        equals("testDocument(): Incorrect value for inout param", x, y.value);
        equals("testDocument(): Incorrect value for out param", yOrig, z.value);
        equals("testDocument(): Incorrect return value", x, ret);
    }
    x = new Document();
    yOrig = new Document();
    x.setValue("content-x");
    yOrig.setValue("content-y");
    x.setID(null);
    yOrig.setID(null);
    y = new Holder<Document>(yOrig);
    z = new Holder<Document>();
    if (testDocLiteral) {
        ret = docClient.testDocument(x, y, z);
    } else if (testXMLBinding) {
        ret = xmlClient.testDocument(x, y, z);
    } else {
        ret = rpcClient.testDocument(x, y, z);
    }
    if (!perfTestOnly) {
        equals("testDocument(): Incorrect value for inout param", x, y.value);
        equals("testDocument(): Incorrect value for out param", yOrig, z.value);
        equals("testDocument(): Incorrect return value", x, ret);
        assertNull(y.value.getID());
        assertNull(ret.getID());
    }
}
Also used : Holder(javax.xml.ws.Holder) Document(org.apache.type_test.types1.Document) Test(org.junit.Test)

Example 79 with Document

use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project opentheso by miledrousset.

the class importxml method ouvreFichier2.

/**
 * cette funtion permet de ouvrir un fichier pour comencée a faire une
 * injection de données.
 * Cette funtion c'est la generique
 * @param ds
 * @param archive
 * @throws ClassNotFoundException
 * @throws SQLException
 */
public void ouvreFichier2(HikariDataSource ds, File archive) throws ClassNotFoundException, SQLException {
    LanguageBean langueBean = new LanguageBean();
    SAXBuilder builder = new SAXBuilder();
    ArrayList<Table> toutTables = new ArrayList<>();
    ArrayList<LineOfData> lineOfDatas = new ArrayList<>();
    try {
        // on crée le document a partir du fichier que on a selectioné
        Document document = (Document) builder.build(archive);
        // Se obtiene la raiz 'tables'
        Element rootNode = document.getRootElement();
        // ici on a toutes les tables (les enfants de la racine)
        List list = rootNode.getChildren("table");
        // ici on fait le tour pour les enfants de 'tables'
        for (int i = 0; i < list.size(); i++) {
            // ici on a la première table
            Element tabla = (Element) list.get(i);
            // ici on a le nom de la table
            String nombreTabla = tabla.getAttributeValue("nom");
            // ici c'est la liste des lignes de la table
            List lista_campos = tabla.getChildren();
            // ici on découpe la liste des lignes
            for (int j = 0; j < lista_campos.size(); j++) {
                // ici on a une ligne de la table
                Element campo = (Element) lista_campos.get(j);
                for (Element colonne : campo.getChildren()) {
                    LineOfData lineOfData = new LineOfData();
                    lineOfData.setColomne(colonne.getName());
                    lineOfData.setValue(colonne.getText());
                    lineOfDatas.add(lineOfData);
                }
                insertLine2(ds, lineOfDatas, nombreTabla);
                lineOfDatas.clear();
            }
        // / mettre à jour la table dans la BDD
        }
    } catch (IOException | JDOMException io) {
        System.out.println(io.toString());
    }
// FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("impBDD.info1")));
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Table(mom.trd.opentheso.core.exports.privatesdatas.tables.Table) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) LineOfData(mom.trd.opentheso.core.exports.privatesdatas.LineOfData) ArrayList(java.util.ArrayList) List(java.util.List) LanguageBean(mom.trd.opentheso.SelectedBeans.LanguageBean)

Example 80 with Document

use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project opentheso by miledrousset.

the class testimportxml method ouvreFichier.

// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
// 
@Test
public void ouvreFichier() {
    HikariDataSource conn = openConnexionPool();
    SAXBuilder builder = new SAXBuilder();
    ArrayList<Table> toutTables = new ArrayList<>();
    ArrayList<LineOfData> lineOfDatas = new ArrayList<>();
    File xmlFile = new File("C:/Users/antonio.perez/Desktop/testbon.xml");
    try {
        // 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'
        // ici on a toutes les tables (les enfants de la racine)
        List list = rootNode.getChildren("table");
        // Se recorre la lista de hijos de 'tables'
        for (int i = 0; i < list.size(); i++) {
            // Se obtiene el elemento 'tabla'
            // ici on a la première table
            Element tabla = (Element) list.get(i);
            // Se obtiene el atributo 'nombre' que esta en el tag 'tabla'
            // ici on a le nom de la table
            String nombreTabla = tabla.getAttributeValue("nom");
            System.out.println("Nom de la table : " + nombreTabla);
            // Se obtiene la lista de hijos del tag 'tabla'
            // ici c'est la liste des lignes de la table
            List lista_campos = tabla.getChildren();
            // ici on découpe la liste des lignes
            for (int j = 0; j < lista_campos.size(); j++) {
                // Se obtiene el elemento 'campo'
                // ici on a une ligne de la table
                Element campo = (Element) lista_campos.get(j);
                // System.out.println("nouvelle ligne table "+ nombreTabla);
                for (Element colonne : campo.getChildren()) {
                    LineOfData lineOfData = new LineOfData();
                    // System.out.println("Nom de la colonne = " + colonne.getName());
                    // System.out.println("valeur de la colonne = " + colonne.getText());
                    lineOfData.setColomne(colonne.getName());
                    lineOfData.setValue(colonne.getText());
                    lineOfDatas.add(lineOfData);
                }
                insertLine(conn, lineOfDatas, nombreTabla);
                lineOfDatas.clear();
            }
        // / mettre à jour la table dans la BDD
        }
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) HikariDataSource(com.zaxxer.hikari.HikariDataSource) Table(mom.trd.opentheso.core.exports.privatesdatas.tables.Table) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) LineOfData(mom.trd.opentheso.core.exports.privatesdatas.LineOfData) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Aggregations

Document (org.jdom2.Document)391 Element (org.jdom2.Element)243 Test (org.junit.Test)104 SAXBuilder (org.jdom2.input.SAXBuilder)84 IOException (java.io.IOException)72 File (java.io.File)56 XMLOutputter (org.jdom2.output.XMLOutputter)56 JDOMException (org.jdom2.JDOMException)44 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)34 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)25 DocType (org.jdom2.DocType)24 ArrayList (java.util.ArrayList)22 MCRContent (org.mycore.common.content.MCRContent)22 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)22 MCRException (org.mycore.common.MCRException)21 Document (com.google.cloud.language.v1.Document)20 HashMap (java.util.HashMap)19 Attribute (org.jdom2.Attribute)19 MCRObject (org.mycore.datamodel.metadata.MCRObject)19 URL (java.net.URL)18