Example usage for javax.xml.xpath XPath compile

List of usage examples for javax.xml.xpath XPath compile

Introduction

In this page you can find the example usage for javax.xml.xpath XPath compile.

Prototype

public XPathExpression compile(String expression) throws XPathExpressionException;

Source Link

Document

Compile an XPath expression for later evaluation.

Usage

From source file:org.asimba.wa.integrationtest.saml2.model.Assertion.java

private void parseAttributes() {
    String xpathQuery = "/saml2p:Response/saml2:Assertion/saml2:AttributeStatement/saml2:Attribute";

    if (_responseDocument == null) {
        _logger.error("No document specified.");
        return;/*from ww  w.j  av  a2 s.  c  om*/
    }

    Map<String, String> attributeMap = new HashMap<>();

    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(new SimpleSAMLNamespaceContext(null));

    try {
        NodeList nodes = (NodeList) xpath.compile(xpathQuery).evaluate(_responseDocument,
                XPathConstants.NODESET);
        if (nodes != null) {
            for (int i = 0; i < nodes.getLength(); i++) {
                // get value of @Name attribute
                Node n = nodes.item(i);

                String name = n.getAttributes().getNamedItem("Name").getNodeValue();

                // get the first AttributeValue childnode
                NodeList valueNodes = n.getChildNodes();
                for (int ci = 0; ci < valueNodes.getLength(); ci++) {
                    Node cn = valueNodes.item(ci);
                    String nodename = cn.getLocalName();
                    if ("AttributeValue".equals(nodename)) {
                        String value = cn.getTextContent().trim();
                        attributeMap.put(name, value);
                    }
                }
            }
        }
    } catch (XPathExpressionException e) {
        _logger.error("Exception when getting attributes: {}", e.getMessage(), e);
        return;
    }

    _responseAttributes = attributeMap;
}

From source file:org.asimba.wa.integrationtest.saml2.model.Assertion.java

public Node getAssertionNode() {
    if (_responseDocument == null)
        return null;

    String xpathQuery = "/saml2p:Response/saml2:Assertion";

    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(new SimpleSAMLNamespaceContext(null));

    try {//from  w ww  . ja  v a  2  s  .  c o m
        return (Node) xpath.compile(xpathQuery).evaluate(_responseDocument, XPathConstants.NODE);
    } catch (XPathExpressionException e) {
        _logger.error("Exception when processing XPath Query: {}", e.getMessage(), e);
        return null;
    }

}

From source file:org.atricore.idbus.capabilities.sso.support.core.signature.JSR105SamlR2SignerImpl.java

protected NodeList evaluateXPath(Document doc, String expression) throws SamlR2SignatureException {
    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();
    xpath.setNamespaceContext(getNamespaceContext());

    NodeList nl;/*from w  w w  .j  a  v a 2  s .c o m*/
    try {
        XPathExpression expr = xpath.compile(expression);

        nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
    } catch (XPathExpressionException e) {
        throw new SamlR2SignatureException(e);
    }

    return nl;
}

From source file:org.bbaw.telota.ediarum.ReadRegister.java

/**
 * Der Konstruktor liest das Dokument der URL mit den benannten Knoten aus und konstruiert den Eintrag und die Id fr jeden Knoten.
 * @param indexURI Die URL zur Registerdatei
 * @param node Der X-Path-Ausdruck fr die Knoten der einzelnen Registereintrge
 * @param eintragExp Der Ausdruck um einen Registereintrag zu konstruieren. Er setzt sich aus Strings in "", Attributen beginnend mit @,
 *  Elementen mit / oder // und aus X-Path-Ausdrcken beginnend mit . zusammen. Die einzelnen Teile werden mit + verbunden.
 * @param idExp Der Ausdruck um die ID fr einen Registereintrag zu konstruieren. Er setzt sich wie eintragExp zusammen.
 * @throws AuthorOperationException/*from ww  w  .jav a  2s .  c om*/
 */
public ReadRegister(String indexURI, String node, String eintragExp, String idExp) {

    try {
        // Das neue Dokument wird vorbereitet.
        DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
        domFactory.setNamespaceAware(true);
        DocumentBuilder builder = domFactory.newDocumentBuilder();

        // Wenn es sich um eine URL mit Authentifizierung handelt, ..
        InputStream is;
        if (indexURI.indexOf('@') > -1) {
            // .. werden die Verbindungsdaten gelesen ..
            String authString = indexURI.substring(indexURI.indexOf("://") + 3, indexURI.indexOf('@'));
            String webPage = indexURI.substring(0, indexURI.indexOf("://") + 3)
                    + indexURI.substring(indexURI.indexOf('@') + 1);
            byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
            String authStringEnc = new String(authEncBytes);

            // .. und eine Verbindung mit Login geffnet.
            URL url = new URL(webPage);
            URLConnection urlConnection = url.openConnection();
            urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
            is = urlConnection.getInputStream();
        } else {
            // Im anderen Fall wird direkt eine Verbindung geffnet.
            URL url = new URL(indexURI);
            URLConnection urlConnection = url.openConnection();
            is = urlConnection.getInputStream();
        }

        // Dann wird die Datei gelesen.
        InputSource inputSource = new InputSource(is);
        Document indexDoc = builder.parse(inputSource);
        // Die xPath-Routinen werden vorbereitet.
        XPath xpath = XPathFactory.newInstance().newXPath();
        // Das XPath-Query wird definiert.
        XPathExpression expr = xpath.compile(node);

        // Die Resultate werden ausgelesen..
        Object result = expr.evaluate(indexDoc, XPathConstants.NODESET);
        NodeList registerNodes = (NodeList) result;

        // .. dann werden fr die Eintrge und IDs entsprechend lange Arrays angelegt.
        eintrag = new String[registerNodes.getLength()];
        id = new String[registerNodes.getLength()];

        // Die Ausdrcke fr die Eintrge ..
        String[] eintragExpression = (eintragExp).split("[+]");
        for (int i = 0; i < eintragExpression.length; i++) {
            eintragExpression[i] = eintragExpression[i].trim();
        }
        // .. und IDs werden in einzelne Glieder geteilt. 
        String[] idExpression = (idExp).split("[+]");
        for (int i = 0; i < idExpression.length; i++) {
            idExpression[i] = idExpression[i].trim();
        }

        // Fr jeden Knoten ..
        for (int i = 0; i < registerNodes.getLength(); i++) {
            Element currentElement = (Element) registerNodes.item(i);
            // .. wird der Eintrag konstruiert.
            eintrag[i] = "";
            // Dazu werden die Glieder des entsprechenden Ausdrucks interpretiert.
            for (int j = 0; j < eintragExpression.length; j++) {
                try {
                    // Jedes Glied kann entweder als Attribut, ..
                    if (eintragExpression[j].startsWith("@")) {
                        String attributeName = eintragExpression[j].substring(1);
                        eintrag[i] += currentElement.getAttribute(attributeName);
                    }
                    // .. als String, ..
                    if (eintragExpression[j].startsWith("\"") && eintragExpression[j].endsWith("\"")) {
                        String stringexpression = eintragExpression[j].substring(1,
                                eintragExpression[j].length() - 1);
                        eintrag[i] += stringexpression;
                    }
                    // .. als spter zu verarbeitetende Variable, ..
                    if (eintragExpression[j].startsWith("$")) {
                        String stringexpression = eintragExpression[j];
                        eintrag[i] += stringexpression;
                    }
                    // **
                    // .. als nachkommendes Element ..
                    if (eintragExpression[j].startsWith("//")) {
                        // .. (was direkt gelesen werden kann und schnell geht, ..
                        String elementName = eintragExpression[j].substring(2);
                        if (currentElement.getElementsByTagName(elementName).getLength() > 0) {
                            eintrag[i] += currentElement.getElementsByTagName(elementName).item(0)
                                    .getTextContent();
                        } else {
                            // .. oder welches ber eine X-Path-Abfrage gelesen werden kann und lange dauert), ..
                            XPathExpression queryExpr = xpath.compile("." + eintragExpression[j]);
                            NodeList elementNodes = (NodeList) queryExpr.evaluate(registerNodes.item(i),
                                    XPathConstants.NODESET);
                            if (elementNodes.getLength() > 0
                                    && elementNodes.item(0).getNodeType() == Node.ELEMENT_NODE) {
                                eintrag[i] += elementNodes.item(0).getTextContent();
                            }
                        }
                        // .. als direktes Kindelement (was schnell geht) ..
                    } else if (eintragExpression[j].startsWith("/")) {
                        String elementName = eintragExpression[j].substring(1);
                        if (currentElement.getElementsByTagName(elementName).getLength() > 0) {
                            eintrag[i] += currentElement.getElementsByTagName(elementName).item(0)
                                    .getTextContent();
                        }
                    }
                    // .. oder als X-Path-Ausdruck (was sehr lange dauert) verstanden werden.
                    if (eintragExpression[j].startsWith(".")) {
                        XPathExpression queryExpr = xpath.compile(eintragExpression[j]);
                        NodeList elementNodes = (NodeList) queryExpr.evaluate(registerNodes.item(i),
                                XPathConstants.NODESET);
                        if (elementNodes.item(0).getNodeType() == Node.ELEMENT_NODE) {
                            eintrag[i] += elementNodes.item(0).getTextContent();
                        }
                    }
                } catch (ArrayIndexOutOfBoundsException e) {
                }
            }

            // Genauso wird die ID konstruiert.
            id[i] = "";
            // Dazu werden die Glieder des entsprechenden Ausdrucks interpretiert.
            for (int j = 0; j < idExpression.length; j++) {
                try {
                    // Jedes Glied kann entweder als Attribut, ..
                    if (idExpression[j].startsWith("@")) {
                        String attributeName = idExpression[j].substring(1);
                        id[i] += currentElement.getAttribute(attributeName);
                    }
                    // .. als String, ..
                    if (idExpression[j].startsWith("\"") && idExpression[j].endsWith("\"")) {
                        String stringexpression = idExpression[j].substring(1, idExpression[j].length() - 1);
                        id[i] += stringexpression;
                    }
                    // .. als spter zu verarbeitetende Variable, ..
                    if (idExpression[j].startsWith("$")) {
                        String stringexpression = idExpression[j];
                        id[i] += stringexpression;
                    }
                    // .. als nachkommendes Element ..
                    if (idExpression[j].startsWith("//")) {
                        // .. (was direkt gelesen werden kann und schnell geht, ..
                        String elementName = idExpression[j].substring(2);
                        if (currentElement.getElementsByTagName(elementName).getLength() > 0) {
                            id[i] += currentElement.getElementsByTagName(elementName).item(0).getTextContent();
                        } else {
                            // .. oder welches ber eine X-Path-Abfrage gelesen werden kann und lange dauert), ..
                            XPathExpression queryExpr = xpath.compile("." + idExpression[j]);
                            NodeList elementNodes = (NodeList) queryExpr.evaluate(registerNodes.item(i),
                                    XPathConstants.NODESET);
                            if (elementNodes.getLength() > 0
                                    && elementNodes.item(0).getNodeType() == Node.ELEMENT_NODE) {
                                id[i] += elementNodes.item(0).getTextContent();
                            }
                        }
                        // .. als direktes Kindelement (was schnell geht) ..
                    } else if (idExpression[j].startsWith("/")) {
                        String elementName = idExpression[j].substring(1);
                        if (currentElement.getElementsByTagName(elementName).getLength() > 0) {
                            id[i] += currentElement.getElementsByTagName(elementName).item(0).getTextContent();
                        }
                    }
                    // .. oder als X-Path-Ausdruck (was sehr lange dauert) verstanden werden.
                    if (idExpression[j].startsWith(".")) {
                        XPathExpression queryExpr = xpath.compile(idExpression[j]);
                        NodeList elementNodes = (NodeList) queryExpr.evaluate(registerNodes.item(i),
                                XPathConstants.NODESET);
                        if (elementNodes.item(0).getNodeType() == Node.ELEMENT_NODE) {
                            id[i] += elementNodes.item(0).getTextContent();
                        }
                    }
                } catch (ArrayIndexOutOfBoundsException e) {
                }
            }
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (XPathExpressionException e) {
        e.printStackTrace();
    } catch (DOMException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    }
}

From source file:org.bireme.interop.toJson.Xml2Json.java

private Map<String, XPathExpression> getMap(final String xpathTable)
        throws IOException, XPathExpressionException {
    assert xpathTable != null;

    final XPath xPath = XPathFactory.newInstance().newXPath();
    final Map<String, XPathExpression> map = new HashMap<>();
    try (BufferedReader reader = new BufferedReader(new FileReader(xpathTable))) {
        while (true) {
            final String line = reader.readLine();
            if (line == null) {
                break;
            }/*  w w w .j a  v  a  2  s  .  c o m*/

            final String[] split = line.trim().split(" *= *", 2);
            if (split.length != 2) {
                throw new IOException("invalid line format: " + line);
            }
            map.put(split[0], (XPathExpression) xPath.compile(split[1]));
        }
    }

    return map;
}

From source file:org.codice.alliance.catalog.transformer.mgmp.MgmpTransformer.java

private void addMetacardDataQuality(MetacardImpl metacard) {

    try (InputStream inputStream = getSourceInputStream()) {
        DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
        domFactory.setNamespaceAware(false);
        try {/*from   w w w  .  j ava 2s.  c om*/
            domFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
            domFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        } catch (ParserConfigurationException e) {
            LOGGER.debug("Unable to set features on document builder.", e);
        }
        DocumentBuilder builder = domFactory.newDocumentBuilder();
        Document document = builder.parse(inputStream);

        XPath xPath = XPathFactory.newInstance().newXPath();

        List<String> dataQualityList = new ArrayList<>();
        for (String string : MgmpConstants.DATA_QUALITY_LIST) {

            XPathExpression dataExpression = xPath.compile(string);
            NodeList dataList = (NodeList) dataExpression.evaluate(document, XPathConstants.NODESET);

            for (int i = 0; i < dataList.getLength(); i++) {
                String dataQualityName = null;
                String resultValue = null;

                NodeList children = dataList.item(i).getChildNodes();
                for (int c = 0; c < children.getLength(); c++) {
                    Node node = children.item(c);
                    String name = node.getNodeName();

                    switch (name) {
                    case MgmpConstants.RESULT:
                        NodeList childNodes = node.getChildNodes();
                        for (int x = 0; x < childNodes.getLength(); x++) {
                            Node resultNode = childNodes.item(x);
                            if (StringUtils.isEmpty(resultValue)) {
                                resultValue = getDataQualityResultValue(resultNode);
                            }
                        }
                        break;
                    case MgmpConstants.NAME_OF_MEASURE:
                        if (StringUtils.isEmpty(dataQualityName)) {
                            dataQualityName = node.getTextContent().trim();
                        }
                        break;

                    default:
                        break;
                    }
                }

                if (StringUtils.isNotEmpty(dataQualityName) && StringUtils.isNotEmpty(resultValue)) {
                    dataQualityList.add(dataQualityName + " : " + resultValue);
                }
            }
        }

        if (CollectionUtils.isNotEmpty(dataQualityList)) {
            metacard.setAttribute(Isr.DATA_QUALITY, (Serializable) dataQualityList);
        }
    } catch (ParserConfigurationException | IOException | SAXException | XPathExpressionException e) {
        LOGGER.debug("Unable to parse Data Quality elements.  Metacard Data Quality will not be set.", e);
        return;
    }
}

From source file:org.codice.ddf.itests.common.csw.CswTestCommons.java

public static String getMetacardIdFromCswInsertResponse(Response response)
        throws IOException, XPathExpressionException {
    XPath xPath = XPathFactory.newInstance().newXPath();
    String idPath = "//*[local-name()='identifier']/text()";
    InputSource xml = new InputSource(IOUtils.toInputStream(response.getBody().asString(), UTF_8.name()));
    return xPath.compile(idPath).evaluate(xml);
}

From source file:org.codice.ddf.security.interceptor.AnonymousInterceptor.java

private String retrieveXmlValue(String xml, String xpathStmt) {
    String result = null;/*  ww  w .  ja  va  2 s . com*/
    Document document = createDocument(xml);
    XPathFactory xFactory = XPathFactory.newInstance();
    XPath xpath = xFactory.newXPath();

    try {
        XPathExpression expr = xpath.compile(xpathStmt);
        result = (String) expr.evaluate(document, XPathConstants.STRING);
    } catch (XPathExpressionException e) {
        LOGGER.warn("Error processing XPath statement on policy XML.");
    }
    return result;
}

From source file:org.codice.ddf.security.interceptor.AnonymousInterceptor.java

private boolean evaluateExpression(String xml, String xpathStmt) {
    Boolean result = false;//from  w  ww  .ja va2  s  .co  m
    Document document = createDocument(xml);

    XPathFactory xFactory = XPathFactory.newInstance();
    XPath xpath = xFactory.newXPath();

    try {
        XPathExpression expr = xpath.compile("boolean(" + xpathStmt + ")");
        result = (Boolean) expr.evaluate(document, XPathConstants.BOOLEAN);
    } catch (XPathExpressionException e) {
        LOGGER.warn("Error processing XPath statement on policy XML.", e);
    }
    return result;
}

From source file:org.company.processmaker.TreeFilesTopComponent.java

public TreeFilesTopComponent() {
    initComponents();/*  w  w  w.  j  a v  a  2  s  . c  om*/

    setName(Bundle.CTL_TreeFilesTopComponent());
    setToolTipText(Bundle.HINT_TreeFilesTopComponent());
    // new codes
    instance = this;

    MouseListener ml = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            int selRow = jTree1.getRowForLocation(e.getX(), e.getY());
            TreePath selPath = jTree1.getPathForLocation(e.getX(), e.getY());

            if (selRow != -1) {
                if (e.getClickCount() == 1) {
                    //mySingleClick(selRow, selPath);
                } else if (e.getClickCount() == 2) {

                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1
                            .getLastSelectedPathComponent();
                    if (node == null) {
                        return;
                    }
                    Object nodeInfo = node.getUserObject();
                    int node_level = node.getLevel();

                    if (node_level < 2) {
                        return;
                    }

                    // for each dyna form
                    if (node_level == 2) {

                        Global gl_obj = Global.getInstance();

                        //myDoubleClick(selRow, selPath);
                        conf = Config.getInstance();

                        DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
                        String parentName = (String) parent.getUserObject();

                        // handle triggers
                        if (parentName.equals("Triggers")) {

                            String filePath = "";
                            for (String[] s : res_trigger) {

                                if (s[0].equals(nodeInfo.toString())) {
                                    // get path of dyna in xml forms
                                    filePath = conf.tmp + "triggers/" + s[3] + "/" + s[2] + ".php";
                                    break;
                                }

                            }

                            File toAdd = new File(filePath);

                            try {
                                DataObject dObject = DataObject.find(FileUtil.toFileObject(toAdd));

                                dObject.getLookup().lookup(OpenCookie.class).open();
                                // dont listen for exist listen files
                                if (existFile(filePath)) {
                                    return;
                                }
                                dObject.addPropertyChangeListener(new PropertyChangeListener() {
                                    @Override
                                    public void propertyChange(PropertyChangeEvent evt) {
                                        if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) {
                                            //fire a dummy event
                                            if (!Boolean.TRUE.equals(evt.getNewValue())) {

                                                /*String msg = "Saved to" + evt.toString();
                                                NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE);
                                                DialogDisplayer.getDefault().notify(nd);*/
                                                TopComponent activeTC = TopComponent.getRegistry()
                                                        .getActivated();
                                                DataObject dataLookup = activeTC.getLookup()
                                                        .lookup(DataObject.class);
                                                String filePath = FileUtil.toFile(dataLookup.getPrimaryFile())
                                                        .getAbsolutePath();

                                                File userFile = new File(filePath);
                                                String fileName = userFile.getName();
                                                fileName = fileName.substring(0, fileName.lastIndexOf("."));

                                                try {
                                                    String content = new String(
                                                            Files.readAllBytes(Paths.get(filePath)));
                                                    // remote php tag and info "<?php //don't remove this tag! \n"
                                                    content = content.substring(6, content.length());

                                                    String query = "update triggers set TRI_WEBBOT = '"
                                                            + StringEscapeUtils.escapeSql(content)
                                                            + "' where TRI_UID = '" + fileName + "'";
                                                    GooglePanel.updateQuery(query);

                                                } catch (Exception e) {
                                                    //Exceptions.printStackTrace(e);
                                                    String msg = "Can not update trigger";
                                                    NotifyDescriptor nd = new NotifyDescriptor.Message(msg,
                                                            NotifyDescriptor.INFORMATION_MESSAGE);
                                                    DialogDisplayer.getDefault().notify(nd);
                                                }

                                            }

                                        }

                                    }
                                });

                            } catch (DataObjectNotFoundException ex) {
                                //Exceptions.printStackTrace(ex);
                                String msg = "Trigger not found";
                                NotifyDescriptor nd = new NotifyDescriptor.Message(msg,
                                        NotifyDescriptor.INFORMATION_MESSAGE);
                                DialogDisplayer.getDefault().notify(nd);
                            }

                            return;
                        }

                        List<String[]> res_dyna = gl_obj.getDyna();
                        String FileDir = "";
                        for (String[] s : res_dyna) {

                            if (s[1].equals(nodeInfo.toString())) {
                                // get path of dyna in xml forms
                                FileDir = s[3];
                                break;
                            }

                        }

                        //String msg = "selRow" + nodeInfo.toString() + "|" + conf.getXmlForms() + FileDir;
                        String filePath = conf.getXmlForms() + FileDir + ".xml";
                        if (conf.isRemote()) {
                            String[] res = FileDir.split("/");
                            filePath = conf.get("local_tmp_for_remote") + "/" + FileDir + "/" + res[1] + ".xml";
                        }

                        File toAdd = new File(filePath);

                        //Result will be null if the user clicked cancel or closed the dialog w/o OK
                        if (toAdd != null) {
                            try {
                                DataObject dObject = DataObject.find(FileUtil.toFileObject(toAdd));

                                dObject.getLookup().lookup(OpenCookie.class).open();
                                // dont listen for exist listen files
                                if (existFile(filePath)) {
                                    return;
                                }
                                dObject.addPropertyChangeListener(new PropertyChangeListener() {
                                    @Override
                                    public void propertyChange(PropertyChangeEvent evt) {
                                        if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) {
                                            //fire a dummy event
                                            if (!Boolean.TRUE.equals(evt.getNewValue())) {

                                                /*String msg = "Saved to" + evt.toString();
                                                NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE);
                                                DialogDisplayer.getDefault().notify(nd);*/
                                                TopComponent activeTC = TopComponent.getRegistry()
                                                        .getActivated();
                                                DataObject dataLookup = activeTC.getLookup()
                                                        .lookup(DataObject.class);
                                                String filePath = FileUtil.toFile(dataLookup.getPrimaryFile())
                                                        .getAbsolutePath();

                                                File userFile = new File(filePath);
                                                String fileName = userFile.getName();
                                                fileName = fileName.substring(0, fileName.lastIndexOf("."));

                                                Global gl_obj = Global.getInstance();

                                                List<String[]> res_dyna = gl_obj.getDyna();
                                                String FileDir = "";
                                                for (String[] s : res_dyna) {

                                                    if (filePath.contains(s[0])) {

                                                        FileDir = s[3];
                                                        break;

                                                    }

                                                }

                                                if (conf.isRemote()) {
                                                    boolean res_Upload = SSH.getInstance().uplaodFile(FileDir);
                                                    if (res_Upload) {
                                                        String msg = "file upload Successfully!";
                                                        NotifyDescriptor nd = new NotifyDescriptor.Message(msg,
                                                                NotifyDescriptor.INFORMATION_MESSAGE);
                                                        DialogDisplayer.getDefault().notify(nd);
                                                    } else {
                                                        String msg = "error in uploading file!";
                                                        NotifyDescriptor nd = new NotifyDescriptor.Message(msg,
                                                                NotifyDescriptor.INFORMATION_MESSAGE);
                                                        DialogDisplayer.getDefault().notify(nd);
                                                    }
                                                }

                                            }

                                        }

                                    }
                                });

                            } catch (DataObjectNotFoundException ex) {
                                //Exceptions.printStackTrace(ex);
                                String msg = "Can not find xml file";
                                NotifyDescriptor nd = new NotifyDescriptor.Message(msg,
                                        NotifyDescriptor.INFORMATION_MESSAGE);
                                DialogDisplayer.getDefault().notify(nd);
                            }
                        }
                    }

                    // for each js file
                    if (node_level == 3) {

                        TreeNode parentInfo = node.getParent();

                        Global gl_obj = Global.getInstance();

                        List<String[]> res_dyna = gl_obj.getDyna();
                        String FileDir = "";
                        for (String[] s : res_dyna) {

                            if (s[1].equals(parentInfo.toString())) {
                                // get path of dyna in xml forms
                                FileDir = s[3];
                                break;
                            }

                        }

                        //myDoubleClick(selRow, selPath);
                        conf = Config.getInstance();
                        String filePath = conf.tmp + "xmlForms/" + FileDir + "/" + nodeInfo.toString() + ".js";
                        if (conf.isRemote()) {
                            filePath = conf.get("local_tmp_for_remote") + FileDir + "/" + nodeInfo.toString()
                                    + ".js";
                        }

                        File toAdd = new File(filePath);

                        //Result will be null if the user clicked cancel or closed the dialog w/o OK
                        if (toAdd != null) {
                            try {
                                DataObject dObject = DataObject.find(FileUtil.toFileObject(toAdd));

                                dObject.getLookup().lookup(OpenCookie.class).open();
                                // dont listen for exist listen files
                                if (existFile(filePath)) {
                                    return;
                                }
                                dObject.addPropertyChangeListener(new PropertyChangeListener() {
                                    @Override
                                    public void propertyChange(PropertyChangeEvent evt) {
                                        if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) {
                                            //fire a dummy event
                                            if (!Boolean.TRUE.equals(evt.getNewValue())) {

                                                JTextComponent ed = EditorRegistry.lastFocusedComponent();
                                                String jsDoc = "";
                                                try {
                                                    jsDoc = ed.getText();
                                                } catch (Exception ex) {
                                                    //Exceptions.printStackTrace(ex);
                                                    String msg = "Can not get text from editor";
                                                    NotifyDescriptor nd = new NotifyDescriptor.Message(msg,
                                                            NotifyDescriptor.INFORMATION_MESSAGE);
                                                    DialogDisplayer.getDefault().notify(nd);
                                                }

                                                TopComponent activeTC = TopComponent.getRegistry()
                                                        .getActivated();
                                                DataObject dataLookup = activeTC.getLookup()
                                                        .lookup(DataObject.class);
                                                String filePath = FileUtil.toFile(dataLookup.getPrimaryFile())
                                                        .getAbsolutePath();

                                                File userFile = new File(filePath);
                                                String fileName = userFile.getName();
                                                fileName = fileName.substring(0, fileName.lastIndexOf("."));

                                                Global gl_obj = Global.getInstance();

                                                List<String[]> res_dyna = gl_obj.getDyna();
                                                String FileDir = "";
                                                for (String[] s : res_dyna) {

                                                    if (filePath.contains(s[0])) {

                                                        FileDir = s[3];
                                                        break;

                                                    }

                                                }

                                                String fullPath = conf.getXmlForms() + FileDir + ".xml";
                                                if (conf.isRemote()) {
                                                    String[] res = FileDir.split("/");
                                                    fullPath = conf.get("local_tmp_for_remote") + FileDir + "/"
                                                            + res[1] + ".xml";
                                                }
                                                try {
                                                    DocumentBuilderFactory factory = DocumentBuilderFactory
                                                            .newInstance();
                                                    DocumentBuilder builder = factory.newDocumentBuilder();
                                                    Document mainDoc = builder.parse(fullPath);

                                                    XPath xPath = XPathFactory.newInstance().newXPath();
                                                    Node startDateNode = (Node) xPath
                                                            .compile("//dynaForm/" + fileName)
                                                            .evaluate(mainDoc, XPathConstants.NODE);
                                                    Node cdata = mainDoc.createCDATASection(jsDoc);
                                                    startDateNode.setTextContent("");
                                                    startDateNode.appendChild(cdata);

                                                    /*String msg = evt.getPropertyName() + "-" + fileName;
                                                    NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE);
                                                    DialogDisplayer.getDefault().notify(nd);*/
                                                    // write the content into xml file
                                                    TransformerFactory transformerFactory = TransformerFactory
                                                            .newInstance();
                                                    Transformer transformer = transformerFactory
                                                            .newTransformer();
                                                    DOMSource source = new DOMSource(mainDoc);
                                                    StreamResult result = new StreamResult(new File(fullPath));
                                                    transformer.transform(source, result);

                                                    if (conf.isRemote()) {
                                                        boolean res_Upload = SSH.getInstance()
                                                                .uplaodFile(FileDir);
                                                        if (res_Upload) {
                                                            String msg = "file upload Successfully!";
                                                            NotifyDescriptor nd = new NotifyDescriptor.Message(
                                                                    msg, NotifyDescriptor.INFORMATION_MESSAGE);
                                                            DialogDisplayer.getDefault().notify(nd);
                                                        } else {
                                                            String msg = "error in uploading file!";
                                                            NotifyDescriptor nd = new NotifyDescriptor.Message(
                                                                    msg, NotifyDescriptor.INFORMATION_MESSAGE);
                                                            DialogDisplayer.getDefault().notify(nd);
                                                        }
                                                    }

                                                } catch (Exception ex) {
                                                    //Exceptions.printStackTrace(ex);
                                                    String msg = "Can not save to xml form";
                                                    NotifyDescriptor nd = new NotifyDescriptor.Message(msg,
                                                            NotifyDescriptor.INFORMATION_MESSAGE);
                                                    DialogDisplayer.getDefault().notify(nd);
                                                }

                                            }

                                        }

                                    }
                                });

                            } catch (DataObjectNotFoundException ex) {
                                //Exceptions.printStackTrace(ex);
                                String msg = "Can not save to xml form";
                                NotifyDescriptor nd = new NotifyDescriptor.Message(msg,
                                        NotifyDescriptor.INFORMATION_MESSAGE);
                                DialogDisplayer.getDefault().notify(nd);
                            }
                        }
                    }
                }
            }
        }
    };
    jTree1.addMouseListener(ml);
    jTree1.setModel(null);
}