Example usage for org.w3c.dom Node getParentNode

List of usage examples for org.w3c.dom Node getParentNode

Introduction

In this page you can find the example usage for org.w3c.dom Node getParentNode.

Prototype

public Node getParentNode();

Source Link

Document

The parent of this node.

Usage

From source file:com.dinochiesa.edgecallouts.EditXmlNode.java

private void remove(NodeList nodes) {
    Node currentNode = nodes.item(0);
    // delete adjacent empty text node if it is empty/whitespace
    Node prevSibling = currentNode.getPreviousSibling();
    if (prevSibling != null && prevSibling.getNodeType() == Node.TEXT_NODE
            && prevSibling.getNodeValue().trim().isEmpty()) {
        currentNode.getParentNode().removeChild(prevSibling);
    }/*from w ww .ja  v a  2s . c o m*/
    currentNode.getParentNode().removeChild(currentNode);
}

From source file:it.greenvulcano.gvesb.virtual.gv_multipart.MultipartCallOperation.java

/**
 * /*from ww w .  j  a  v a  2s .c om*/
 * @param node
 *          The configuration node containing all informations. 
 * 
 * @see it.greenvulcano.gvesb.virtual.Operation#init(org.w3c.dom.Node)
 */
@Override
public void init(Node node) throws InitializationException {
    logger.debug("Init start");

    try {
        name = XMLConfig.get(node, "@name");
        String host = XMLConfig.get(node.getParentNode(), "@endpoint");
        String uri = XMLConfig.get(node, "@request-uri");
        url = host.concat(uri);
        connectionTimeout = XMLConfig.getInteger(node, "@conn-timeout", 3000);
        readTimeout = XMLConfig.getInteger(node, "@so-timeout", 6000);

        readMultipartCallConfiguration(node);
        readMultipartCallParts(node);

        logger.debug("Init stop");
    } catch (Exception exc) {
        throw new InitializationException("GV_INIT_SERVICE_ERROR",
                new String[][] { { "message", exc.getMessage() } }, exc);
    }

}

From source file:com.centeractive.ws.builder.soap.XmlUtils.java

private static int findNodeIndex(Node node) {
    String nm = node.getLocalName();
    String ns = node.getNamespaceURI();
    short nt = node.getNodeType();

    Node parentNode = node.getParentNode();
    if (parentNode.getNodeType() != Node.ELEMENT_NODE)
        return 1;

    Node child = parentNode.getFirstChild();

    int ix = 0;/*from w ww.  j ava  2  s . c  o  m*/
    while (child != null) {
        if (child == node)
            return ix + 1;

        if (child.getNodeType() == nt && nm.equals(child.getLocalName())
                && ((ns == null && child.getNamespaceURI() == null)
                        || (ns != null && ns.equals(child.getNamespaceURI()))))
            ix++;

        child = child.getNextSibling();
    }

    throw new SoapBuilderException("Child node not found in parent!?");
}

From source file:com.dinochiesa.edgecallouts.EditXmlNode.java

private void replace(NodeList nodes, Node newNode, short newNodeType) {
    Node currentNode = nodes.item(0);
    switch (newNodeType) {
    case Node.ATTRIBUTE_NODE:
        Element parent = ((Attr) currentNode).getOwnerElement();
        parent.removeAttributeNode((Attr) currentNode);
        parent.setAttributeNode((Attr) newNode);
        break;// ww w  .j  a va2 s. c o m
    case Node.ELEMENT_NODE:
        currentNode.getParentNode().replaceChild(newNode, currentNode);
        break;
    case Node.TEXT_NODE:
        currentNode.setNodeValue(newNode.getNodeValue());
        break;
    }
}

From source file:amulet.appbuilder.AppBuilder.java

@SuppressWarnings("unchecked")
private boolean callPipeLine(String filename) {
    QMReader qm = new QMReader(filename);
    try {/*from ww  w  .j  a v a  2  s . c  o m*/
        manifestReader = new ManifestReader(filename);
    } catch (Exception exp) {
        System.out.println("Exception when creating manifest reader for " + filename);
        exp.printStackTrace();
        return false;
    }

    // This will be written to a file for parsing by the Resource Profile UI
    finalJSONGraphStructure = new JSONObject();

    if (passToolchain) {

        Vector<QMClass> classes = qm.getClasses();
        authModule = new AuthorizationModule(manifestReader);

        for (int j = 0; j < classes.size(); j++) {
            QMClass qmclass = classes.get(j);
            Vector<State> states = qmclass.getStates();
            Vector<Node> action_nodes = qmclass.getActionNodes();
            Vector<Node> guard_nodes = qmclass.getGuardNodes();
            Vector<Node> operation_nodes = qmclass.getOperationNodes();

            // Get all the attributes (global variables) that are put in FRAM
            HashMap<String, String[]> attdetails = qmclass.getAttributesWithDetails();
            resourceProfiler.setGlobalContext(qmclass.getName());
            for (String key : attdetails.keySet()) {
                String[] attinfo = attdetails.get(key);
                resourceProfiler.addMemoryResource(qmclass.getName(), attinfo[0], key, attinfo[1],
                        ResourceType.GLOBAL_MEMORY);
            }
            resourceProfiler.clearProfilerContext();

            // This outputs a JSON format of the QMClass
            finalJSONGraphStructure.put("appname", qmclass.getName());
            finalJSONGraphStructure.put("app_human_readable_name", manifestReader.getAppName());
            finalJSONGraphStructure.put("app_human_readable_description", manifestReader.getAppDescription());

            /*
             * States.
             */
            // DEBUG::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
            //NodeList initNodes = qmclass.getInitialTransition();
            //for(int n = 0; n < initNodes.getLength(); n++) {
            //   String target = initNodes.item(n).getAttributes().getNamedItem("target").getNodeValue();
            //   System.out.println("##DEBUG## init->" + qmclass.getQmSateId2NameMapEntry("NONE", target));
            //}
            // DEBUG::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

            for (int i = 0; i < states.size(); i++) {
                State state = states.get(i);
                if (state != null) {
                    // Set state attributes.
                    String stateName = state.getName();

                    // DEBUG::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
                    //for(Transition t : state.getTransitions()) {
                    //   QMTransition qmt = (QMTransition) t;
                    //   System.out.println("##DEBUG## " + qmt.getSource().getName() + "->" + qmt.getTrigger() + "->" + qmt.getTarget().getName());
                    //}
                    // DEBUG::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

                    // [ENTER] State i. 
                    resourceProfiler.setStateContext(stateName);

                    // AFT analyzer/translator/profiler (entry)
                    if (state.getEntryCode() != null && state.getEntryCode().length() > 0) {
                        compatchecker = new CompatChecker(state.getEntryCode(), qmclass.getName());
                        if (!compatchecker.getSuccess())
                            return false;
                        if (!authModule.checkApiAuthorization(state.getEntryCode()))
                            return false;
                        runtimecheck = new RuntimeCheck(qmclass, state.getEntryCode(), togglePins,
                                qmclass.getArrayAttributes(), resourceProfiler);
                        state.setEntryCode(runtimecheck.getCheckedCode());
                        attributeMapper = new AttributeMapper(state.getEntryCode(), qmclass.getAttributes());
                        state.setEntryCode(attributeMapper.getMappedCode());
                    }

                    // AFT analyzer/translator/profiler (exit)
                    if (state.getExitCode() != null && state.getExitCode().length() > 0) {
                        compatchecker = new CompatChecker(state.getExitCode(), qmclass.getName());
                        if (!compatchecker.getSuccess())
                            return false;
                        if (!authModule.checkApiAuthorization(state.getExitCode()))
                            return false;
                        runtimecheck = new RuntimeCheck(qmclass, state.getExitCode(), togglePins,
                                qmclass.getArrayAttributes(), resourceProfiler);
                        state.setExitCode(runtimecheck.getCheckedCode());
                        attributeMapper = new AttributeMapper(state.getExitCode(), qmclass.getAttributes());
                        state.setExitCode(attributeMapper.getMappedCode());
                    }

                    // Add "basic blocks" record to state.
                    Resource record = new Resource(ComputationType.BASIC_BLOCKS.text(), qmclass.getName(),
                            ResourceType.COMPUTATION, 0.0);
                    resourceProfiler.add(record);

                    // [EXIT] State i. 
                    resourceProfiler.clearProfilerContext();
                }
            }

            /*
             * Action Nodes (i.e., Transitions).
             */
            JSONArray statesJsonArray = new JSONArray();
            String prevState = null, prevTrigger = null, prevTarget = null;
            for (int i = 0; i < action_nodes.size(); i++) {
                if (action_nodes.get(i) != null && action_nodes.get(i).getTextContent() != null) {
                    /*
                     * Set transition attributes.
                     */
                    String currentState = "", triggerName = "", targetNameID = "";

                    Node action_node = action_nodes.get(i);
                    Node parent1 = action_node.getParentNode();
                    Node parent2 = parent1.getParentNode();

                    // Set the "source" (i.e., the state which this action node is contained within---the "parent state").
                    currentState = QMClass.getCurrentQMStateFromActionNode(action_node);

                    // Set the "trigger".
                    if (parent1.getAttributes().getNamedItem("trig") != null) {
                        triggerName = parent1.getAttributes().getNamedItem("trig").getNodeValue();
                    } else if (parent2.getAttributes().getNamedItem("trig") != null) {
                        triggerName = parent2.getAttributes().getNamedItem("trig").getNodeValue();
                    } else {
                        triggerName = "init";
                    }

                    // Set the "target".
                    if (parent1.getAttributes().getNamedItem("target") != null) {
                        targetNameID = parent1.getAttributes().getNamedItem("target").getNodeValue();
                    } else if (parent2.getAttributes().getNamedItem("target") != null) {
                        targetNameID = parent2.getAttributes().getNamedItem("target").getNodeValue();
                    } else {
                        targetNameID = "init-target-unset?";
                    }

                    // Fetch the (human-readable) name of the state referenced by the ID specified in the action node.
                    String targetName = qmclass.getQmSateId2NameMapEntry(currentState, targetNameID);

                    /*
                     * Guard against recording duplicate records (it can happen!).
                     * 
                     * NOTE: This is a little sloppy, since it assumes that the duplicate records happen in 
                     * sequence; this seems to always be true with the QM files we've worked with, but this 
                     * issue may need to be re-addressed later...
                     */
                    if (!currentState.equals(prevState) || !triggerName.equals(prevTrigger)
                            || !targetName.equals(prevTarget)) {
                        //System.out.println(" + TRIGGER:: currentState=" + currentState + "->triggerName="+triggerName + "->targetName="+targetName + " (targetNameID="+targetNameID+")");

                        // Maintain a JSON representation of the FSM (i.e., states and transitions).
                        JSONObject actionJsonObj = new JSONObject();
                        actionJsonObj.put("source", currentState);
                        actionJsonObj.put("trigger", triggerName);
                        actionJsonObj.put("target", targetName);
                        statesJsonArray.add(actionJsonObj);

                        // [ENTER] Action Node i. 
                        resourceProfiler.setActionContext(currentState, triggerName, targetName);

                        // AFT analyzer/translator/profiler
                        compatchecker = new CompatChecker(action_nodes.get(i).getTextContent(),
                                qmclass.getName());
                        if (!compatchecker.getSuccess())
                            return false;
                        if (!authModule.checkApiAuthorization(action_nodes.get(i).getTextContent()))
                            return false;
                        runtimecheck = new RuntimeCheck(qmclass, action_nodes.get(i).getTextContent(),
                                togglePins, qmclass.getArrayAttributes(), resourceProfiler);
                        action_nodes.get(i).setTextContent(runtimecheck.getCheckedCode());
                        attributeMapper = new AttributeMapper(action_nodes.get(i).getTextContent(),
                                qmclass.getAttributes());
                        action_nodes.get(i).setTextContent(attributeMapper.getMappedCode());

                        // Add "basic blocks" record to action.
                        Resource record = new Resource(ComputationType.BASIC_BLOCKS.text(), qmclass.getName(),
                                ResourceType.COMPUTATION, 0.0);
                        resourceProfiler.add(record);

                        // [EXIT] Action Node i. 
                        resourceProfiler.clearProfilerContext();
                    }

                    // Keep track of the previous trigger information...
                    prevState = currentState;
                    prevTrigger = triggerName;
                    prevTarget = targetName;
                }
            }
            finalJSONGraphStructure.put("states", statesJsonArray);

            /*
             * Guard Nodes.
             */
            for (int i = 0; i < guard_nodes.size(); i++) {
                if (guard_nodes.get(i) != null && guard_nodes.get(i).getTextContent() != null
                        && guard_nodes.get(i).getTextContent().length() > 0) {
                    // [ENTER] Guard Node i. 
                    resourceProfiler.setGuardContext();

                    // AFT analyzer/translator/profiler
                    compatchecker = new CompatChecker(guard_nodes.get(i).getTextContent(), qmclass.getName());
                    if (!compatchecker.getSuccess())
                        return false;
                    if (!authModule.checkApiAuthorization(guard_nodes.get(i).getTextContent()))
                        return false;
                    runtimecheck = new RuntimeCheck(qmclass, guard_nodes.get(i).getTextContent(), togglePins,
                            qmclass.getArrayAttributes(), resourceProfiler);
                    guard_nodes.get(i).setTextContent(runtimecheck.getCheckedCode());
                    attributeMapper = new AttributeMapper(guard_nodes.get(i).getTextContent(),
                            qmclass.getAttributes());
                    guard_nodes.get(i).setTextContent(attributeMapper.getMappedCode());

                    // Add "basic blocks" record to guard.
                    Resource record = new Resource(ComputationType.BASIC_BLOCKS.text(), qmclass.getName(),
                            ResourceType.COMPUTATION, 0.0);
                    resourceProfiler.add(record);

                    // [EXIT] Guard Node i. 
                    resourceProfiler.clearProfilerContext();
                }
            }

            /*
             * Operation Nodes.
             */
            for (int i = 0; i < operation_nodes.size(); i++) {
                if (operation_nodes.get(i) != null && operation_nodes.get(i).getTextContent() != null
                        && operation_nodes.get(i).getTextContent().length() > 0) {
                    // Set operations attributes.
                    String name = operation_nodes.get(i).getParentNode().getAttributes().getNamedItem("name")
                            .getNodeValue();
                    String type = operation_nodes.get(i).getParentNode().getAttributes().getNamedItem("type")
                            .getNodeValue();
                    String visibility = operation_nodes.get(i).getParentNode().getAttributes()
                            .getNamedItem("visibility").getNodeValue();
                    String properties = operation_nodes.get(i).getParentNode().getAttributes()
                            .getNamedItem("properties").getNodeValue();

                    // [ENTER] Operation Node i. 
                    resourceProfiler.setOperationContext(name, type, visibility, properties);

                    // AFT analyzer/translator/profiler
                    compatchecker = new CompatChecker(operation_nodes.get(i).getTextContent(),
                            qmclass.getName());
                    if (!compatchecker.getSuccess())
                        return false;
                    if (!authModule.checkApiAuthorization(operation_nodes.get(i).getTextContent()))
                        return false;
                    runtimecheck = new RuntimeCheck(qmclass, operation_nodes.get(i).getTextContent(),
                            togglePins, qmclass.getArrayAttributes(), resourceProfiler);
                    operation_nodes.get(i).setTextContent(runtimecheck.getCheckedCode());
                    attributeMapper = new AttributeMapper(operation_nodes.get(i).getTextContent(),
                            qmclass.getAttributes());
                    operation_nodes.get(i).setTextContent(attributeMapper.getMappedCode());

                    // Add "basic blocks" record to operation.
                    Resource record = new Resource(ComputationType.BASIC_BLOCKS.text(), qmclass.getName(),
                            ResourceType.COMPUTATION, 0.0);
                    resourceProfiler.add(record);

                    // [EXIT] Operation Node i. 
                    resourceProfiler.clearProfilerContext();

                    // For now, add a place-holder entry to the operation map -- it will be updated later
                    // when a request is made to the Resource Profiler to calculate the cost of some application.
                    resourceProfiler.getCurrentQMAppObj().addOperationRecord(name, 0.0, 0.0);
                }
            }

            // Verify checks against function white-list pass...
            funcWhiteList = new FunctionWhitelist(qmclass.getName(), states, action_nodes, guard_nodes,
                    qmclass.getOperations());
            if (!funcWhiteList.getSuccess())
                return false;
        }

    } else {
        System.out.println("AFT WARNING: skipping AFT processing -- code has not been properly validated!");
    }

    qm.saveAs(filename + ".temp");
    return true;
}

From source file:de.betterform.xml.xforms.XFormsElement.java

public XFormsElement getEnclosingXFormsContainer() {
    Node currentNode = this.getElement();
    XFormsElement enclosingContainer = null;
    while (true) {
        Node parentNode = currentNode.getParentNode();

        if (parentNode == null) {
            break;
        }//from  w w  w.  jav a  2s .  c  om

        if (!(parentNode instanceof Element)) {
            break;
        }

        Element elementImpl = (Element) parentNode;
        Object containerObject = elementImpl.getUserData("");
        if (containerObject instanceof Group || containerObject instanceof Switch
                || containerObject instanceof Repeat) {
            enclosingContainer = (XFormsElement) containerObject;
            break;
        }
        currentNode = parentNode;
    }
    return enclosingContainer;

}

From source file:com.occamlab.te.parsers.ImageParser.java

private static void processBufferedImage(BufferedImage buffimage, String formatName, NodeList nodes)
        throws Exception {
    HashMap<Object, Object> bandMap = new HashMap<Object, Object>();

    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            if (node.getLocalName().equals("subimage")) {
                Element e = (Element) node;
                int x = Integer.parseInt(e.getAttribute("x"));
                int y = Integer.parseInt(e.getAttribute("y"));
                int w = Integer.parseInt(e.getAttribute("width"));
                int h = Integer.parseInt(e.getAttribute("height"));
                processBufferedImage(buffimage.getSubimage(x, y, w, h), formatName, e.getChildNodes());
            } else if (node.getLocalName().equals("checksum")) {
                CRC32 checksum = new CRC32();
                Raster raster = buffimage.getRaster();
                DataBufferByte buffer;
                if (node.getParentNode().getLocalName().equals("subimage")) {
                    WritableRaster outRaster = raster.createCompatibleWritableRaster();
                    buffimage.copyData(outRaster);
                    buffer = (DataBufferByte) outRaster.getDataBuffer();
                } else {
                    buffer = (DataBufferByte) raster.getDataBuffer();
                }//from  w w w  . j av  a  2s.  co  m
                int numbanks = buffer.getNumBanks();
                for (int j = 0; j < numbanks; j++) {
                    checksum.update(buffer.getData(j));
                }
                Document doc = node.getOwnerDocument();
                node.appendChild(doc.createTextNode(Long.toString(checksum.getValue())));
            } else if (node.getLocalName().equals("count")) {
                String band = ((Element) node).getAttribute("bands");
                String sample = ((Element) node).getAttribute("sample");
                if (sample.equals("all")) {
                    bandMap.put(band, null);
                } else {
                    HashMap<Object, Object> sampleMap = (HashMap<Object, Object>) bandMap.get(band);
                    if (sampleMap == null) {
                        if (!bandMap.containsKey(band)) {
                            sampleMap = new HashMap<Object, Object>();
                            bandMap.put(band, sampleMap);
                        }
                    }
                    sampleMap.put(Integer.decode(sample), new Integer(0));
                }
            } else if (node.getLocalName().equals("transparentNodata")) { // 2011-08-24
                                                                          // PwD
                String transparentNodata = checkTransparentNodata(buffimage, node);
                node.setTextContent(transparentNodata);
            }
        }
    }

    Iterator bandIt = bandMap.keySet().iterator();
    while (bandIt.hasNext()) {
        String band_str = (String) bandIt.next();
        int band_indexes[];
        if (buffimage.getType() == BufferedImage.TYPE_BYTE_BINARY
                || buffimage.getType() == BufferedImage.TYPE_BYTE_GRAY) {
            band_indexes = new int[1];
            band_indexes[0] = 0;
        } else {
            band_indexes = new int[band_str.length()];
            for (int i = 0; i < band_str.length(); i++) {
                if (band_str.charAt(i) == 'A')
                    band_indexes[i] = 3;
                if (band_str.charAt(i) == 'B')
                    band_indexes[i] = 2;
                if (band_str.charAt(i) == 'G')
                    band_indexes[i] = 1;
                if (band_str.charAt(i) == 'R')
                    band_indexes[i] = 0;
            }
        }

        Raster raster = buffimage.getRaster();
        java.util.HashMap sampleMap = (java.util.HashMap) bandMap.get(band_str);
        boolean addall = (sampleMap == null);
        if (sampleMap == null) {
            sampleMap = new java.util.HashMap();
            bandMap.put(band_str, sampleMap);
        }

        int minx = raster.getMinX();
        int maxx = minx + raster.getWidth();
        int miny = raster.getMinY();
        int maxy = miny + raster.getHeight();
        int bands[][] = new int[band_indexes.length][raster.getWidth()];

        for (int y = miny; y < maxy; y++) {
            for (int i = 0; i < band_indexes.length; i++) {
                raster.getSamples(minx, y, maxx, 1, band_indexes[i], bands[i]);
            }
            for (int x = minx; x < maxx; x++) {
                int sample = 0;
                for (int i = 0; i < band_indexes.length; i++) {
                    sample |= bands[i][x] << ((band_indexes.length - i - 1) * 8);
                }

                Integer sampleObj = new Integer(sample);

                boolean add = addall;
                if (!addall) {
                    add = sampleMap.containsKey(sampleObj);
                }
                if (add) {
                    Integer count = (Integer) sampleMap.get(sampleObj);
                    if (count == null) {
                        count = new Integer(0);
                    }
                    count = new Integer(count.intValue() + 1);
                    sampleMap.put(sampleObj, count);
                }
            }
        }
    }

    Node node = nodes.item(0);
    while (node != null) {
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            if (node.getLocalName().equals("count")) {
                String band = ((Element) node).getAttribute("bands");
                String sample = ((Element) node).getAttribute("sample");
                HashMap sampleMap = (HashMap) bandMap.get(band);
                Document doc = node.getOwnerDocument();
                if (sample.equals("all")) {
                    Node parent = node.getParentNode();
                    Node prevSibling = node.getPreviousSibling();
                    Iterator sampleIt = sampleMap.keySet().iterator();
                    Element countnode = null;
                    int digits;
                    String prefix;
                    switch (buffimage.getType()) {
                    case BufferedImage.TYPE_BYTE_BINARY:
                        digits = 1;
                        prefix = "";
                        break;
                    case BufferedImage.TYPE_BYTE_GRAY:
                        digits = 2;
                        prefix = "0x";
                        break;
                    default:
                        prefix = "0x";
                        digits = band.length() * 2;
                    }
                    while (sampleIt.hasNext()) {
                        countnode = doc.createElementNS(node.getNamespaceURI(), "count");
                        Integer sampleInt = (Integer) sampleIt.next();
                        Integer count = (Integer) sampleMap.get(sampleInt);
                        if (band.length() > 0) {
                            countnode.setAttribute("bands", band);
                        }
                        countnode.setAttribute("sample", prefix + HexString(sampleInt.intValue(), digits));
                        Node textnode = doc.createTextNode(count.toString());
                        countnode.appendChild(textnode);
                        parent.insertBefore(countnode, node);
                        if (sampleIt.hasNext()) {
                            if (prevSibling != null && prevSibling.getNodeType() == Node.TEXT_NODE) {
                                parent.insertBefore(prevSibling.cloneNode(false), node);
                            }
                        }
                    }
                    parent.removeChild(node);
                    node = countnode;
                } else {
                    Integer count = (Integer) sampleMap.get(Integer.decode(sample));
                    if (count == null)
                        count = new Integer(0);
                    Node textnode = doc.createTextNode(count.toString());
                    node.appendChild(textnode);
                }
            }
        }
        node = node.getNextSibling();
    }
}

From source file:com.icesoft.faces.context.DOMResponseWriter.java

private void displayParent(Node n) {
    System.out.println("Node: " + n);
    Node parent = n.getParentNode();
    if (parent != null) {
        displayParent(parent);//from w ww  . j a v a2 s. c o m
    } else {
        System.out.println("-- done");
    }

}

From source file:de.betterform.xml.xforms.XFormsElement.java

/**
 * Returns the enclosing binding element of the specified xforms element.
 *
 * @param xFormsElement the xforms element.
 * @param returnBind if true returns the bind that corresponds to the UI control instead of the UI control itself
 * @return the enclosing binding element of the specified xforms element or
 * <code>null</code> if there is no enclosing binding element.
 *//*w  ww .  j  ava 2s  . c  o m*/

public Binding getEnclosingBinding(XFormsElement xFormsElement, boolean returnBind) {
    Binding enclosingBinding = null;
    Container container = xFormsElement.getContainerObject();
    Node currentNode = xFormsElement.getElement();
    String modelId = xFormsElement.getModel().getId();

    while (true) {
        Node parentNode = currentNode.getParentNode();

        if (parentNode == null) {
            break;
        }

        if (!(parentNode instanceof Element)) {
            break;
        }

        Element elementImpl = (Element) parentNode;
        Object o = elementImpl.getUserData("");

        if (BindingResolver.hasModelBinding(elementImpl)) {
            Binding binding = (Binding) o;

            if (binding.getModelId().equals(modelId)) {
                String bindId = binding.getBindingId();
                if (returnBind) {
                    enclosingBinding = (Binding) container.lookup(bindId);
                } else {
                    enclosingBinding = binding;
                }
                break;
            }
        }

        Binding enclosingUIBinding = getEnclosingUIBinding(elementImpl, o, modelId);
        if (enclosingUIBinding != null) {
            enclosingBinding = enclosingUIBinding;
            break;
        }
        currentNode = parentNode;
    }

    return enclosingBinding;
}

From source file:com.stratelia.webactiv.util.XMLConfigurationStore.java

public void put(String key, String values[]) {
    Node paramNode = getXMLParamNode(key);
    if (paramNode != null) {
        Node paramNodeParent = paramNode.getParentNode();
        if (paramNodeParent != null) {
            paramNodeParent.removeChild(paramNode);
        }//from   w w  w.  j  a  va  2s  . c  om
    }
    Element param = xmlConfigDOMDoc.createElement("param");
    Node name = xmlConfigDOMDoc.createElement("param-name");
    Node description = xmlConfigDOMDoc.createElement("param-description");
    Node nameValue = xmlConfigDOMDoc.createTextNode(key);
    for (String value : values) {
        Node vValue = xmlConfigDOMDoc.createTextNode(value);
        Node v = xmlConfigDOMDoc.createElement("param-value");
        param.appendChild(v);
        v.appendChild(vValue);
    }
    rootNode.appendChild(param);
    param.appendChild(name);
    name.appendChild(nameValue);
    param.appendChild(description);
    xmlConfigDOMDoc.getDocumentElement().normalize();
}