Example usage for javax.xml.parsers ParserConfigurationException printStackTrace

List of usage examples for javax.xml.parsers ParserConfigurationException printStackTrace

Introduction

In this page you can find the example usage for javax.xml.parsers ParserConfigurationException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.portfolio.data.provider.MysqlAdminProvider.java

@Override
public Object getPortfolio(MimeType outMimeType, String portfolioUuid, int userId, int groupId, String label,
        String resource, String files) throws Exception {
    String rootNodeUuid = getPortfolioRootNode(portfolioUuid);
    String header = "";
    String footer = "";
    NodeRight nodeRight = credential.getPortfolioRight(userId, groupId, portfolioUuid, Credential.READ);
    if (!nodeRight.read)
        return "faux";

    if (outMimeType.getSubType().equals("xml")) {
        //         header = "<portfolio xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' schemaVersion='1.0'>";
        //         footer = "</portfolio>";

        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder;
        Document document = null;
        try {//w  ww . ja  v  a 2  s  . c  o m
            documentBuilder = documentBuilderFactory.newDocumentBuilder();
            document = documentBuilder.newDocument();
            document.setXmlStandalone(true);
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Element root = document.createElement("portfolio");
        root.setAttribute("id", portfolioUuid);
        root.setAttribute("code", "0");

        //// Noeuds supplmentaire pour WAD
        // Version
        Element verNode = document.createElement("version");
        Text version = document.createTextNode("3");
        verNode.appendChild(version);
        root.appendChild(verNode);
        // metadata-wad
        Element metawad = document.createElement("metadata-wad");
        metawad.setAttribute("prog", "main.jsp");
        metawad.setAttribute("owner", "N");
        root.appendChild(metawad);

        //          root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
        //          root.setAttribute("schemaVersion", "1.0");
        document.appendChild(root);

        getLinearXml(portfolioUuid, rootNodeUuid, root, true, null, userId, groupId);

        StringWriter stw = new StringWriter();
        Transformer serializer = TransformerFactory.newInstance().newTransformer();
        serializer.transform(new DOMSource(document), new StreamResult(stw));

        if (resource != null && files != null) {

            if (resource.equals("true") && files.equals("true")) {
                String adressedufichier = System.getProperty("user.dir") + "/tmp_getPortfolio_" + new Date()
                        + ".xml";
                String adresseduzip = System.getProperty("user.dir") + "/tmp_getPortfolio_" + new Date()
                        + ".zip";

                File file = null;
                PrintWriter ecrire;
                PrintWriter ecri;
                try {
                    file = new File(adressedufichier);
                    ecrire = new PrintWriter(new FileOutputStream(adressedufichier));
                    ecrire.println(stw.toString());
                    ecrire.flush();
                    ecrire.close();
                    System.out.print("fichier cree ");
                } catch (IOException ioe) {
                    System.out.print("Erreur : ");
                    ioe.printStackTrace();
                }

                try {
                    String fileName = portfolioUuid + ".zip";

                    ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(adresseduzip));
                    zip.setMethod(ZipOutputStream.DEFLATED);
                    zip.setLevel(Deflater.BEST_COMPRESSION);
                    File dataDirectories = new File(file.getName());
                    FileInputStream fis = new FileInputStream(dataDirectories);
                    byte[] bytes = new byte[fis.available()];
                    fis.read(bytes);

                    ZipEntry entry = new ZipEntry(file.getName());
                    entry.setTime(dataDirectories.lastModified());
                    zip.putNextEntry(entry);
                    zip.write(bytes);
                    zip.closeEntry();
                    fis.close();
                    //zipDirectory(dataDirectories, zip);
                    zip.close();

                    file.delete();

                    return adresseduzip;

                } catch (FileNotFoundException fileNotFound) {
                    fileNotFound.printStackTrace();

                } catch (IOException io) {

                    io.printStackTrace();
                }
            }
        }

        return stw.toString();

    } else if (outMimeType.getSubType().equals("json")) {
        header = "{\"portfolio\": { \"-xmlns:xsi\": \"http://www.w3.org/2001/XMLSchema-instance\",\"-schemaVersion\": \"1.0\",";
        footer = "}}";
    }

    return header + getNode(outMimeType, rootNodeUuid, true, userId, groupId, label).toString() + footer;
}

From source file:com.portfolio.data.provider.MysqlAdminProvider.java

private StringBuffer getNodeXmlOutput(String nodeUuid, boolean withChildren, String withChildrenOfXsiType,
        int userId, int groupId, String label, boolean checkSecurity) throws SQLException {
    StringBuffer result = new StringBuffer();
    // Verification securit
    if (checkSecurity) {
        NodeRight nodeRight = credential.getNodeRight(userId, groupId, nodeUuid, label);
        ////from   ww  w .  j a v  a  2 s  .  c  om
        if (!nodeRight.read)
            return result;
    }

    ResultSet resNode = getMysqlNode(nodeUuid, userId, groupId);
    ResultSet resResource;

    String indentation = " ";

    //try
    //{
    //         resNode.next();

    if (resNode.next()) {
        if (resNode.getString("shared_node_uuid") != null) {
            result.append(getNodeXmlOutput(resNode.getString("shared_node_uuid"), true, null, userId, groupId,
                    null, true));
        } else {
            result.append(indentation + "<" + resNode.getString("asm_type") + " "
                    + DomUtils.getXmlAttributeOutput("id", resNode.getString("node_uuid")) + " ");
            //if(resNodes.getString("node_parent_uuid").length()>0)
            //   result.append(getXmlAttributeOutput("parent-uuid",resNodes.getString("node_parent_uuid"))+" ");
            //      result.append(DomUtils.getXmlAttributeOutput("semantictag",resNode.getString("semtag"))+" ");
            //               String readRight= (nodeRight.read) ? "Y" : "N";
            //               String writeRight= (nodeRight.write) ? "Y" : "N";
            //               String submitRight= (nodeRight.submit) ? "Y" : "N";
            //               String deleteRight= (nodeRight.delete) ? "Y" : "N";

            //               result.append(DomUtils.getXmlAttributeOutput("read",readRight)+" ");
            //               result.append(DomUtils.getXmlAttributeOutput("write",writeRight)+" ");
            //               result.append(DomUtils.getXmlAttributeOutput("submit",submitRight)+" ");
            //               result.append(DomUtils.getXmlAttributeOutput("delete",deleteRight)+" ");
            //
            //
            //                     result.append(DomUtils.getXmlAttributeOutput("xsi_type",resNode.getString("xsi_type"))+" ");

            //      result.append(DomUtils.getXmlAttributeOutput("format",resNode.getString("format"))+" ");

            //      result.append(DomUtils.getXmlAttributeOutput("modified",resNode.getTimestamp("modif_date").toGMTString())+" ");

            result.append(">");

            if (!resNode.getString("asm_type").equals("asmResource")) {
                DocumentBuilderFactory newInstance = DocumentBuilderFactory.newInstance();
                DocumentBuilder builder;
                Document document = null;
                try {
                    builder = newInstance.newDocumentBuilder();
                    document = builder.newDocument();
                } catch (ParserConfigurationException e) {
                    e.printStackTrace();
                }

                //               if(!resNode.getString("metadata_wad").equals("") )
                if (resNode.getString("metadata_wad") != null
                        && !resNode.getString("metadata_wad").equals("")) {
                    Element meta = document.createElement("metadata-wad");
                    convertAttr(meta, resNode.getString("metadata_wad"));

                    TransformerFactory transFactory = TransformerFactory.newInstance();
                    Transformer transformer;
                    try {
                        transformer = transFactory.newTransformer();
                        StringWriter buffer = new StringWriter();
                        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
                        transformer.transform(new DOMSource(meta), new StreamResult(buffer));
                        result.append(buffer.toString());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else
                    result.append("<metadata-wad/>");

                //               if(!resNode.getString("metadata_epm").equals("") )
                if (resNode.getString("metadata_epm") != null && !resNode.getString("metadata_epm").equals(""))
                    result.append("<metadata-epm " + resNode.getString("metadata_epm") + "/>");
                else
                    result.append("<metadata-epm/>");

                //               if(!resNode.getString("metadata").equals("") )
                if (resNode.getString("metadata") != null && !resNode.getString("metadata").equals(""))
                    result.append("<metadata " + resNode.getString("metadata") + "/>");
                else
                    result.append("<metadata/>");

                //
                result.append(DomUtils.getXmlElementOutput("code", resNode.getString("code")));
                result.append(DomUtils.getXmlElementOutput("label", resNode.getString("label")));
                result.append(DomUtils.getXmlElementOutput("description", resNode.getString("descr")));
                try {
                    result.append(
                            DomUtils.getXmlElementOutput("semanticTag", resNode.getString("semantictag")));
                } catch (Exception ex) {
                    result.append(DomUtils.getXmlElementOutput("semanticTag", ""));
                }
            } else {
                /*// si asmResource
                   try
                   {
                      resResource = getMysqlResource(nodeUuid);
                      if(resResource.next())
                result.append(resResource.getString("content"));
                   }
                   catch(Exception ex)
                   {
                      ex.printStackTrace();
                   }*/

            }

            if (resNode.getString("res_res_node_uuid") != null)
                if (resNode.getString("res_res_node_uuid").length() > 0) {
                    result.append("<asmResource id='" + resNode.getString("res_res_node_uuid")
                            + "'  contextid='" + nodeUuid + "' xsi_type='nodeRes'>");
                    resResource = getMysqlResource(resNode.getString("res_res_node_uuid"));
                    if (resResource.next())
                        result.append(resResource.getString("content"));
                    result.append("</asmResource>");
                    resResource.close();
                }
            if (resNode.getString("res_context_node_uuid") != null)
                if (resNode.getString("res_context_node_uuid").length() > 0) {
                    result.append("<asmResource id='" + resNode.getString("res_context_node_uuid")
                            + "' contextid='" + nodeUuid + "' xsi_type='context'>");
                    resResource = getMysqlResource(resNode.getString("res_context_node_uuid"));
                    if (resResource.next())
                        result.append(resResource.getString("content"));
                    result.append("</asmResource>");
                    resResource.close();
                }
            if (resNode.getString("res_node_uuid") != null)
                if (resNode.getString("res_node_uuid").length() > 0) {
                    resResource = getMysqlResource(resNode.getString("res_node_uuid"));
                    if (resResource.next()) {
                        result.append("<asmResource id='" + resNode.getString("res_node_uuid") + "' contextid='"
                                + nodeUuid + "' xsi_type='" + resResource.getString("xsi_type") + "'>");

                        result.append(resResource.getString("content"));
                        result.append("</asmResource>");
                    }
                    resResource.close();
                }

            if (withChildren || withChildrenOfXsiType != null) {
                String[] arrayChild;
                try {
                    if (resNode.getString("node_children_uuid").length() > 0) {
                        arrayChild = resNode.getString("node_children_uuid").split(",");
                        for (int i = 0; i < (arrayChild.length); i++) {
                            ResultSet resChildNode = this.getMysqlNodeResultset(arrayChild[i]);

                            String tmpXsiType = "";
                            try {
                                resChildNode.next();
                                tmpXsiType = resChildNode.getString("xsi_type");
                            } catch (Exception ex) {

                            }
                            if (withChildrenOfXsiType == null || withChildrenOfXsiType.equals(tmpXsiType))
                                result.append(getNodeXmlOutput(arrayChild[i], true, null, userId, groupId, null,
                                        true));

                            resChildNode.close();
                        }
                    }
                } catch (Exception ex) {
                    // Pas de children
                }
            }

            result.append("</" + resNode.getString("asm_type") + ">");
        }
    }

    resNode.close();
    //}
    //catch(Exception ex)
    //{
    //   ex.printStackTrace();
    //
    //}
    return result;
}

From source file:com.portfolio.data.provider.MysqlAdminProvider.java

@Override
public Object getNodes(MimeType mimeType, String portfoliocode, String semtag, int userId, int groupId,
        String semtag_parent, String code_parent) throws SQLException {

    // TODO Auto-generated method stub

    PreparedStatement st = null;//ww  w.ja va 2  s  . c  om
    PreparedStatement st1 = null;
    String sql;
    String sql1;
    ResultSet res = null;
    ResultSet res3 = null;
    ResultSet res4 = null;
    String pid = null;

    try {
        pid = this.getPortfolioUuidByPortfolioCode(portfoliocode);
        if ("".equals(pid))
            return "";
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }

    String result = "";

    try {
        sql = "SELECT  bin2uuid(portfolio_id) AS portfolio_id,bin2uuid(root_node_uuid) as root_node_uuid, modif_user_id,modif_date, active, user_id "
                + "FROM portfolio " + "WHERE portfolio_id = uuid2bin(?) ";
        st = connection.prepareStatement(sql);
        st.setString(1, pid);
        res = st.executeQuery();

        if (semtag_parent != null && code_parent != null) {
            res3 = getMysqlNodeUuidBySemanticTag(pid, semtag_parent);

            if (res3.next()) {
                String node = res3.getString("res_res_node_uuid");
                ResultSet resResource = getMysqlResource(res3.getString("res_res_node_uuid"));

                if (resResource.next()) {
                    String a = resResource.getString("xsi_type");
                    if ((resResource.getString("xsi_type")).equals("nodeRes")) {
                        if (res3.getString("res_res_node_uuid") != null)
                            if (res3.getString("res_res_node_uuid").length() > 0) {
                                DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
                                        .newInstance();
                                DocumentBuilder documentBuilder = null;
                                Document document = null;

                                try {
                                    documentBuilder = documentBuilderFactory.newDocumentBuilder();
                                } catch (ParserConfigurationException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }

                                String text = "<node>" + resResource.getString("content") + "</node>";

                                try {
                                    document = documentBuilder
                                            .parse(new ByteArrayInputStream(text.getBytes("UTF-8")));
                                    //document = documentBuilder.parse(new InputSource(new StringReader(text)));
                                } catch (SAXException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }

                                String nom = document.getElementsByTagName("code").item(0).getTextContent();

                                if (document.getElementsByTagName("code").item(0).getTextContent() != null) {

                                    if (document.getElementsByTagName("code").item(0).getTextContent()
                                            .equals(code_parent)) {

                                        String children = res3.getString("node_children_uuid");
                                        String delim = ",";
                                        String[] listChildren = null;
                                        String listNode = null;
                                        listChildren = children.split(delim);
                                        result += "<nodes>";
                                        for (int i = 0; i < listChildren.length; i++) {

                                            sql = "SELECT  bin2uuid(node_uuid) AS node_uuid, metadata, asm_type "
                                                    + "FROM node "
                                                    + "WHERE node_uuid = uuid2bin(?) and metadata LIKE '%semantictag=%'?'%'";
                                            st = connection.prepareStatement(sql);
                                            st.setString(1, listChildren[i]);
                                            st.setString(2, semtag);
                                            res4 = st.executeQuery();

                                            if (res4.next()) {

                                                /*result += "<node ";
                                                                  result += DomUtils.getXmlAttributeOutput("id", res4.getString("node_uuid"));
                                                                  result += ">";
                                                                  result += "</node>";      */

                                                result += "<node ";
                                                result += DomUtils.getXmlAttributeOutput("id",
                                                        res4.getString("node_uuid"));
                                                result += ">";
                                                if (res4.getString("asm_type").equalsIgnoreCase("asmContext")) {
                                                    result += getRessource(res4.getString("node_uuid"), userId,
                                                            groupId, "Context");
                                                } else {

                                                    result += getRessource(res4.getString("node_uuid"), userId,
                                                            groupId, "nonContext");
                                                }
                                                result += "</node>";

                                            }

                                        }

                                        result += "</nodes>";
                                    }
                                }
                            }

                    }
                }
            }

            return result;

        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    if (res.next()) {

        ResultSet res1 = null;

        try {
            res1 = getMysqlNodeUuidBySemanticTag(pid, semtag);
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }

        result += "<nodes>";

        while (res1.next()) {
            result += "<node ";
            result += DomUtils.getXmlAttributeOutput("id", res1.getString("node_uuid"));
            result += ">";
            if (res1.getString("asm_type").equalsIgnoreCase("asmContext")) {
                result += getRessource(res1.getString("node_uuid"), userId, groupId, "Context");
            } else {

                result += getRessource(res1.getString("node_uuid"), userId, groupId, "nonContext");
            }

            result += "</node>";
        }

        result += "</nodes>";
    }

    return result;

}

From source file:com.portfolio.data.provider.MysqlAdminProvider.java

@Override
public String getRessource(String nodeUuid, int userId, int groupId, String type) throws SQLException {
    // TODO Auto-generated method stub

    //ResultSet res = getMysqlPortfolios(userId,portfolioActive);
    String result = "";

    String sql1 = "";
    PreparedStatement st1;//from  w ww.  ja v a  2s.c o  m
    ResultSet res1 = null;
    ResultSet resNode = null;
    ResultSet resResource = null;

    resNode = getMysqlNode(nodeUuid, userId, groupId);
    resResource = null;

    if (type.equals("Context")) {
        if (resNode.next()) {
            resResource = getMysqlResource(resNode.getString("res_node_uuid"));
            if (resResource.next()) {
                String a = resResource.getString("xsi_type");
                if ((resResource.getString("xsi_type")).equals("nodeRes")
                        || (resResource.getString("xsi_type")).equals("context")) {
                } else {
                    if (resNode.getString("res_node_uuid") != null)
                        if (resNode.getString("res_node_uuid").length() > 0) {
                            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
                                    .newInstance();
                            DocumentBuilder documentBuilder = null;
                            Document document = null;

                            try {
                                documentBuilder = documentBuilderFactory.newDocumentBuilder();
                            } catch (ParserConfigurationException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }

                            result += "<asmResource id='" + resNode.getString("res_node_uuid") + "' contextid='"
                                    + resNode.getString("node_uuid") + "' xsi_type='"
                                    + resResource.getString("xsi_type") + "'>";
                            //String text = "<node>"+resResource.getString("content")+"</node>";
                            result += resResource.getString("content");
                            result += "</asmResource>";

                            resResource.close();
                        }
                }
            }
            resResource = getMysqlResource(resNode.getString("res_res_node_uuid"));
            if (resResource.next()) {
                String a = resResource.getString("xsi_type");
                if ((resResource.getString("xsi_type")).equals("nodeRes")
                        || (resResource.getString("xsi_type")).equals("context")) {
                } else {
                    if (resNode.getString("res_res_node_uuid") != null)
                        if (resNode.getString("res_res_node_uuid").length() > 0) {
                            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
                                    .newInstance();
                            DocumentBuilder documentBuilder = null;
                            Document document = null;

                            try {
                                documentBuilder = documentBuilderFactory.newDocumentBuilder();
                            } catch (ParserConfigurationException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }

                            result += "<asmResource id='" + resNode.getString("res_res_node_uuid")
                                    + "' contextid='" + resNode.getString("node_uuid") + "' xsi_type='"
                                    + resResource.getString("xsi_type") + "'>";
                            //String text = "<node>"+resResource.getString("content")+"</node>";
                            result += resResource.getString("content");
                            result += "</asmResource>";

                            resResource.close();
                        }
                }
            }
            resResource = getMysqlResource(resNode.getString("res_context_node_uuid"));
            if (resResource.next()) {
                String a = resResource.getString("xsi_type");
                if ((resResource.getString("xsi_type")).equals("nodeRes")
                        || (resResource.getString("xsi_type")).equals("context")) {
                } else {
                    if (resNode.getString("res_context_node_uuid") != null)
                        if (resNode.getString("res_context_node_uuid").length() > 0) {

                            //result += "<asmResource id='"+resNode.getString("res_node_uuid")+"' contextid='"+resNode.getString("node_uuid")+"' xsi_type='"+resResource.getString("xsi_type")+"'>";
                            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
                                    .newInstance();
                            DocumentBuilder documentBuilder = null;
                            Document document = null;

                            try {
                                documentBuilder = documentBuilderFactory.newDocumentBuilder();
                            } catch (ParserConfigurationException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }

                            result += "<asmResource id='" + resNode.getString("res_context_node_uuid")
                                    + "' contextid='" + resNode.getString("node_uuid") + "' xsi_type='"
                                    + resResource.getString("xsi_type") + "'>";
                            //String text = "<node>"+resResource.getString("content")+"</node>";
                            result += resResource.getString("content");
                            result += "</asmResource>";

                            resResource.close();
                        }
                }
            }
        }
    } else {
        if (resNode.next()) {
            resResource = getMysqlResource(resNode.getString("res_node_uuid"));
            if (resResource.next()) {
                String a = resResource.getString("xsi_type");
                if ((resResource.getString("xsi_type")).equals("nodeRes")) {
                    if (resNode.getString("res_node_uuid") != null)
                        if (resNode.getString("res_node_uuid").length() > 0) {
                            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
                                    .newInstance();
                            DocumentBuilder documentBuilder = null;
                            Document document = null;

                            try {
                                documentBuilder = documentBuilderFactory.newDocumentBuilder();
                            } catch (ParserConfigurationException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }

                            result += "<asmResource id='" + resNode.getString("res_node_uuid") + "' contextid='"
                                    + resNode.getString("node_uuid") + "' xsi_type='"
                                    + resResource.getString("xsi_type") + "'>";
                            //String text = "<node>"+resResource.getString("content")+"</node>";
                            result += resResource.getString("content");
                            result += "</asmResource>";

                            resResource.close();
                        }
                }
            }
            resResource = getMysqlResource(resNode.getString("res_res_node_uuid"));
            if (resResource.next()) {
                String a = resResource.getString("xsi_type");
                if ((resResource.getString("xsi_type")).equals("nodeRes")) {
                    if (resNode.getString("res_res_node_uuid") != null)
                        if (resNode.getString("res_res_node_uuid").length() > 0) {
                            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
                                    .newInstance();
                            DocumentBuilder documentBuilder = null;
                            Document document = null;

                            try {
                                documentBuilder = documentBuilderFactory.newDocumentBuilder();
                            } catch (ParserConfigurationException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }

                            result += "<asmResource id='" + resNode.getString("res_res_node_uuid")
                                    + "' contextid='" + resNode.getString("node_uuid") + "' xsi_type='"
                                    + resResource.getString("xsi_type") + "'>";
                            //String text = "<node>"+resResource.getString("content")+"</node>";
                            result += resResource.getString("content");
                            result += "</asmResource>";

                            resResource.close();
                        }
                }
            }
            resResource = getMysqlResource(resNode.getString("res_context_node_uuid"));
            if (resResource.next()) {
                String a = resResource.getString("xsi_type");
                if ((resResource.getString("xsi_type")).equals("nodeRes")) {
                    if (resNode.getString("res_context_node_uuid") != null)
                        if (resNode.getString("res_context_node_uuid").length() > 0) {
                            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
                                    .newInstance();
                            DocumentBuilder documentBuilder = null;
                            Document document = null;

                            try {
                                documentBuilder = documentBuilderFactory.newDocumentBuilder();
                            } catch (ParserConfigurationException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }

                            result += "<asmResource id='" + resNode.getString("res_context_node_uuid")
                                    + "' contextid='" + resNode.getString("node_uuid") + "' xsi_type='"
                                    + resResource.getString("xsi_type") + "'>";
                            //String text = "<node>"+resResource.getString("content")+"</node>";
                            result += resResource.getString("content");
                            result += "</asmResource>";

                            resResource.close();
                        }
                }
            }
        }
    }

    resNode.close();

    return result;

}

From source file:com.portfolio.data.provider.MysqlDataProvider.java

@Override
public Object getPortfolio(MimeType outMimeType, String portfolioUuid, int userId, int groupId, String label,
        String resource, String files, int substid) throws Exception {
    String rootNodeUuid = getPortfolioRootNode(portfolioUuid);
    String header = "";
    String footer = "";
    NodeRight nodeRight = credential.getPortfolioRight(userId, groupId, portfolioUuid, Credential.READ);
    if (!nodeRight.read) {
        userId = credential.getPublicUid();
        //         NodeRight nodeRight = new NodeRight(false,false,false,false,false,false);
        /// Vrifie les droits avec le compte publique (dernire chance)
        nodeRight = credential.getPublicRight(userId, 123, rootNodeUuid, "dummy");
        if (!nodeRight.read)
            return "faux";
    }/*from w  ww .  j  a  v  a2  s  .  c  o m*/

    if (outMimeType.getSubType().equals("xml")) {
        //         header = "<portfolio xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' schemaVersion='1.0'>";
        //         footer = "</portfolio>";

        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder;
        Document document = null;
        try {
            documentBuilder = documentBuilderFactory.newDocumentBuilder();
            document = documentBuilder.newDocument();
            document.setXmlStandalone(true);
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        }

        Element root = document.createElement("portfolio");
        root.setAttribute("id", portfolioUuid);
        root.setAttribute("code", "0");

        //// Noeuds supplmentaire pour WAD
        // Version
        Element verNode = document.createElement("version");
        Text version = document.createTextNode("4");
        verNode.appendChild(version);
        root.appendChild(verNode);
        // metadata-wad
        //         Element metawad = document.createElement("metadata-wad");
        //         metawad.setAttribute("prog", "main.jsp");
        //         metawad.setAttribute("owner", "N");
        //         root.appendChild(metawad);
        int owner = credential.getOwner(userId, portfolioUuid);
        String isOwner = "N";
        if (owner == userId)
            isOwner = "Y";
        root.setAttribute("owner", isOwner);

        //          root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
        //          root.setAttribute("schemaVersion", "1.0");
        document.appendChild(root);

        getLinearXml(portfolioUuid, rootNodeUuid, root, true, null, userId, nodeRight.groupId,
                nodeRight.groupLabel);

        StringWriter stw = new StringWriter();
        Transformer serializer = TransformerFactory.newInstance().newTransformer();
        serializer.transform(new DOMSource(document), new StreamResult(stw));

        if (resource != null && files != null) {
            if (resource.equals("true") && files.equals("true")) {
                String adressedufichier = System.getProperty("user.dir") + "/tmp_getPortfolio_" + new Date()
                        + ".xml";
                String adresseduzip = System.getProperty("user.dir") + "/tmp_getPortfolio_" + new Date()
                        + ".zip";

                File file = null;
                PrintWriter ecrire;
                try {
                    file = new File(adressedufichier);
                    ecrire = new PrintWriter(new FileOutputStream(adressedufichier));
                    ecrire.println(stw.toString());
                    ecrire.flush();
                    ecrire.close();
                    System.out.print("fichier cree ");
                } catch (IOException ioe) {
                    System.out.print("Erreur : ");
                    ioe.printStackTrace();
                }

                try {
                    ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(adresseduzip));
                    zip.setMethod(ZipOutputStream.DEFLATED);
                    zip.setLevel(Deflater.BEST_COMPRESSION);
                    File dataDirectories = new File(file.getName());
                    FileInputStream fis = new FileInputStream(dataDirectories);
                    byte[] bytes = new byte[fis.available()];
                    fis.read(bytes);

                    ZipEntry entry = new ZipEntry(file.getName());
                    entry.setTime(dataDirectories.lastModified());
                    zip.putNextEntry(entry);
                    zip.write(bytes);
                    zip.closeEntry();
                    fis.close();
                    //zipDirectory(dataDirectories, zip);
                    zip.close();

                    file.delete();

                    return adresseduzip;
                } catch (FileNotFoundException fileNotFound) {
                    fileNotFound.printStackTrace();
                } catch (IOException io) {
                    io.printStackTrace();
                }
            }
        }

        return stw.toString();
    } else if (outMimeType.getSubType().equals("json")) {
        header = "{\"portfolio\": { \"-xmlns:xsi\": \"http://www.w3.org/2001/XMLSchema-instance\",\"-schemaVersion\": \"1.0\",";
        footer = "}}";
    }

    return header + getNode(outMimeType, rootNodeUuid, true, userId, groupId, label).toString() + footer;
}

From source file:com.portfolio.data.provider.MysqlDataProvider.java

@Override
public Object getNodes(MimeType mimeType, String portfoliocode, String semtag, int userId, int groupId,
        String semtag_parent, String code_parent) throws SQLException {
    PreparedStatement st = null;//from  w ww.  j  a va  2s.  c  om
    String sql;
    ResultSet res = null;
    ResultSet res3 = null;
    ResultSet res4 = null;
    String pid = null;

    try {
        pid = this.getPortfolioUuidByPortfolioCode(portfoliocode);
        if ("".equals(pid))
            return "";
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }

    String result = "";

    try {
        sql = "SELECT  bin2uuid(portfolio_id) AS portfolio_id,bin2uuid(root_node_uuid) as root_node_uuid, modif_user_id,modif_date, active, user_id "
                + "FROM portfolio " + "WHERE portfolio_id = uuid2bin(?) ";
        st = connection.prepareStatement(sql);
        st.setString(1, pid);
        res = st.executeQuery();

        // Not null, not empty
        if (semtag_parent != null && !"".equals(semtag_parent) && code_parent != null
                && !"".equals(code_parent)) {
            res3 = getMysqlNodeUuidBySemanticTag(pid, semtag_parent);

            while (res3.next()) {
                ResultSet resResource = getMysqlResource(res3.getString("res_res_node_uuid"));

                if (resResource.next()) {
                    String a = resResource.getString("xsi_type");
                    if ((resResource.getString("xsi_type")).equals("nodeRes")) {
                        if (res3.getString("res_res_node_uuid") != null)
                            if (res3.getString("res_res_node_uuid").length() > 0) {
                                DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
                                        .newInstance();
                                DocumentBuilder documentBuilder = null;
                                Document document = null;

                                try {
                                    documentBuilder = documentBuilderFactory.newDocumentBuilder();
                                } catch (ParserConfigurationException e) {
                                    e.printStackTrace();
                                }

                                String text = "<node>" + resResource.getString("content") + "</node>";

                                try {
                                    document = documentBuilder
                                            .parse(new ByteArrayInputStream(text.getBytes("UTF-8")));
                                    //document = documentBuilder.parse(new InputSource(new StringReader(text)));
                                } catch (SAXException e) {
                                    e.printStackTrace();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }

                                String nom = document.getElementsByTagName("code").item(0).getTextContent();

                                if (nom != null) {
                                    if (nom.equals(code_parent)) {
                                        String children = res3.getString("node_children_uuid");
                                        String delim = ",";
                                        String[] listChildren = null;
                                        listChildren = children.split(delim);
                                        result += "<nodes>";
                                        for (int i = 0; i < listChildren.length; i++) {
                                            sql = "SELECT bin2uuid(node_uuid) AS node_uuid, metadata, asm_type "
                                                    + "FROM node "
                                                    + "WHERE node_uuid = uuid2bin(?) and metadata LIKE ?";
                                            st = connection.prepareStatement(sql);
                                            st.setString(1, listChildren[i]);
                                            st.setString(2, "%semantictag=%" + semtag + "%");
                                            res4 = st.executeQuery();

                                            if (res4.next()) {
                                                /*result += "<node ";
                                                                  result += DomUtils.getXmlAttributeOutput("id", res4.getString("node_uuid"));
                                                                  result += ">";
                                                                  result += "</node>";      */

                                                result += "<node ";
                                                result += DomUtils.getXmlAttributeOutput("id",
                                                        res4.getString("node_uuid"));
                                                result += ">";
                                                if (res4.getString("asm_type").equalsIgnoreCase("asmContext")) {
                                                    result += getRessource(res4.getString("node_uuid"), userId,
                                                            groupId, "Context");
                                                } else {

                                                    result += getRessource(res4.getString("node_uuid"), userId,
                                                            groupId, "nonContext");
                                                }
                                                result += "</node>";

                                            }

                                        }

                                        result += "</nodes>";
                                    }
                                }
                            }

                    }
                }
            }

            return result;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    if (res.next()) {

        ResultSet res1 = null;

        try {
            res1 = getMysqlNodeUuidBySemanticTag(pid, semtag);
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }

        result += "<nodes>";

        while (res1.next()) {
            result += "<node ";
            result += DomUtils.getXmlAttributeOutput("id", res1.getString("node_uuid"));
            result += ">";
            if (res1.getString("asm_type").equalsIgnoreCase("asmContext")) {
                result += getRessource(res1.getString("node_uuid"), userId, groupId, "Context");
            } else {

                result += getRessource(res1.getString("node_uuid"), userId, groupId, "nonContext");
            }

            result += "</node>";
        }

        result += "</nodes>";
    }

    return result;
}

From source file:com.portfolio.data.provider.MysqlDataProvider.java

private StringBuffer getNodeXmlOutput(String nodeUuid, boolean withChildren, String withChildrenOfXsiType,
        int userId, int groupId, String label, boolean checkSecurity) throws SQLException {
    StringBuffer result = new StringBuffer();
    // Verification securit
    if (checkSecurity) {
        NodeRight nodeRight = credential.getNodeRight(userId, groupId, nodeUuid, label);
        ////from  ww  w.j  a  va 2 s .c  om
        if (!nodeRight.read)
            return result;
    }

    ResultSet resNode = getMysqlNode(nodeUuid, userId, groupId);
    ResultSet resResource;

    String indentation = " ";

    //try
    //{
    //         resNode.next();

    if (resNode.next()) {
        if (resNode.getString("shared_node_uuid") != null) {
            result.append(getNodeXmlOutput(resNode.getString("shared_node_uuid"), true, null, userId, groupId,
                    null, true));
        } else {
            result.append(indentation + "<" + resNode.getString("asm_type") + " "
                    + DomUtils.getXmlAttributeOutput("id", resNode.getString("node_uuid")) + " ");
            //if(resNodes.getString("node_parent_uuid").length()>0)
            //   result.append(getXmlAttributeOutput("parent-uuid",resNodes.getString("node_parent_uuid"))+" ");
            //      result.append(DomUtils.getXmlAttributeOutput("semantictag",resNode.getString("semtag"))+" ");
            //               String readRight= (nodeRight.read) ? "Y" : "N";
            //               String writeRight= (nodeRight.write) ? "Y" : "N";
            //               String submitRight= (nodeRight.submit) ? "Y" : "N";
            //               String deleteRight= (nodeRight.delete) ? "Y" : "N";

            //               result.append(DomUtils.getXmlAttributeOutput("read",readRight)+" ");
            //               result.append(DomUtils.getXmlAttributeOutput("write",writeRight)+" ");
            //               result.append(DomUtils.getXmlAttributeOutput("submit",submitRight)+" ");
            //               result.append(DomUtils.getXmlAttributeOutput("delete",deleteRight)+" ");
            //
            //
            //                     result.append(DomUtils.getXmlAttributeOutput("xsi_type",resNode.getString("xsi_type"))+" ");

            //      result.append(DomUtils.getXmlAttributeOutput("format",resNode.getString("format"))+" ");

            //      result.append(DomUtils.getXmlAttributeOutput("modified",resNode.getTimestamp("modif_date").toGMTString())+" ");

            result.append(">");

            if (!resNode.getString("asm_type").equals("asmResource")) {
                DocumentBuilderFactory newInstance = DocumentBuilderFactory.newInstance();
                DocumentBuilder builder;
                Document document = null;
                try {
                    builder = newInstance.newDocumentBuilder();
                    document = builder.newDocument();
                } catch (ParserConfigurationException e) {
                    e.printStackTrace();
                }

                //               if(!resNode.getString("metadata_wad").equals("") )
                if (resNode.getString("metadata_wad") != null
                        && !resNode.getString("metadata_wad").equals("")) {
                    Element meta = document.createElement("metadata-wad");
                    convertAttr(meta, resNode.getString("metadata_wad"));

                    TransformerFactory transFactory = TransformerFactory.newInstance();
                    Transformer transformer;
                    try {
                        transformer = transFactory.newTransformer();
                        StringWriter buffer = new StringWriter();
                        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
                        transformer.transform(new DOMSource(meta), new StreamResult(buffer));
                        result.append(buffer.toString());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else
                    result.append("<metadata-wad/>");

                //               if(!resNode.getString("metadata_epm").equals("") )
                if (resNode.getString("metadata_epm") != null && !resNode.getString("metadata_epm").equals(""))
                    result.append("<metadata-epm " + resNode.getString("metadata_epm") + "/>");
                else
                    result.append("<metadata-epm/>");

                //               if(!resNode.getString("metadata").equals("") )
                if (resNode.getString("metadata") != null && !resNode.getString("metadata").equals(""))
                    result.append("<metadata " + resNode.getString("metadata") + "/>");
                else
                    result.append("<metadata/>");

                //
                result.append(DomUtils.getXmlElementOutput("code", resNode.getString("code")));
                result.append(DomUtils.getXmlElementOutput("label", resNode.getString("label")));
                result.append(DomUtils.getXmlElementOutput("description", resNode.getString("descr")));
                try {
                    result.append(
                            DomUtils.getXmlElementOutput("semanticTag", resNode.getString("semantictag")));
                } catch (Exception ex) {
                    result.append(DomUtils.getXmlElementOutput("semanticTag", ""));
                }
            } else {
                /*// si asmResource
                   try
                   {
                      resResource = getMysqlResource(nodeUuid);
                      if(resResource.next())
                result.append(resResource.getString("content"));
                   }
                   catch(Exception ex)
                   {
                      ex.printStackTrace();
                   }*/

            }

            if (resNode.getString("res_res_node_uuid") != null)
                if (resNode.getString("res_res_node_uuid").length() > 0) {
                    result.append("<asmResource id='" + resNode.getString("res_res_node_uuid")
                            + "'  contextid='" + nodeUuid + "' xsi_type='nodeRes'>");
                    resResource = getMysqlResource(resNode.getString("res_res_node_uuid"));
                    if (resResource.next())
                        result.append(resResource.getString("content"));
                    result.append("</asmResource>");
                    resResource.close();
                }
            if (resNode.getString("res_context_node_uuid") != null)
                if (resNode.getString("res_context_node_uuid").length() > 0) {
                    result.append("<asmResource id='" + resNode.getString("res_context_node_uuid")
                            + "' contextid='" + nodeUuid + "' xsi_type='context'>");
                    resResource = getMysqlResource(resNode.getString("res_context_node_uuid"));
                    if (resResource.next())
                        result.append(resResource.getString("content"));
                    result.append("</asmResource>");
                    resResource.close();
                }
            if (resNode.getString("res_node_uuid") != null)
                if (resNode.getString("res_node_uuid").length() > 0) {
                    resResource = getMysqlResource(resNode.getString("res_node_uuid"));
                    if (resResource.next()) {
                        result.append("<asmResource id='" + resNode.getString("res_node_uuid") + "' contextid='"
                                + nodeUuid + "' xsi_type='" + resResource.getString("xsi_type") + "'>");

                        result.append(resResource.getString("content"));
                        result.append("</asmResource>");
                    }
                    resResource.close();
                }

            if (withChildren || withChildrenOfXsiType != null) {
                String[] arrayChild;
                try {
                    if (resNode.getString("node_children_uuid").length() > 0) {
                        arrayChild = resNode.getString("node_children_uuid").split(",");
                        for (int i = 0; i < (arrayChild.length); i++) {
                            ResultSet resChildNode = this.getMysqlNodeResultset(arrayChild[i]);

                            String tmpXsiType = "";
                            try {
                                resChildNode.next();
                                tmpXsiType = resChildNode.getString("xsi_type");
                            } catch (Exception ex) {

                            }
                            if (withChildrenOfXsiType == null || withChildrenOfXsiType.equals(tmpXsiType))
                                result.append(getNodeXmlOutput(arrayChild[i], true, null, userId, groupId, null,
                                        true));

                            resChildNode.close();
                        }
                    }
                } catch (Exception ex) {
                    // Pas de children
                }
            }

            result.append("</" + resNode.getString("asm_type") + ">");
        }

    }

    resNode.close();
    //}
    //catch(Exception ex)
    //{
    //   ex.printStackTrace();
    //
    //}
    return result;

}

From source file:at.vcity.androidim.services.IMService.java

private void parseFriendInfo(String xml) {
    try {//from w w  w.j a v  a 2  s .c o  m
        SAXParser sp = SAXParserFactory.newInstance().newSAXParser();
        sp.parse(new ByteArrayInputStream(xml.getBytes()), new XMLHandler(IMService.this));
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:at.vcity.androidim.services.IMService.java

private void parseMessageInfo(String xml) {
    try {/*w  w w. ja v  a2  s . c om*/
        SAXParser sp = SAXParserFactory.newInstance().newSAXParser();
        sp.parse(new ByteArrayInputStream(xml.getBytes()), new XMLHandler(IMService.this));
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.ac.vct.pharmacylog.services.IMService.java

public void parseFriendInfo(String xml) {
    try {//from  w ww.  ja va2s .c o  m
        SAXParser sp = SAXParserFactory.newInstance().newSAXParser();
        sp.parse(new ByteArrayInputStream(xml.getBytes()), new XMLHandler(IMService.this));
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}