Example usage for org.w3c.dom Element getFirstChild

List of usage examples for org.w3c.dom Element getFirstChild

Introduction

In this page you can find the example usage for org.w3c.dom Element getFirstChild.

Prototype

public Node getFirstChild();

Source Link

Document

The first child of this node.

Usage

From source file:net.bpelunit.framework.SpecificationLoader.java

private CompleteHumanTask createCompleteHumanTaskActivity(PartnerTrack pTrack, String testDirectory,
        XMLCompleteHumanTaskActivity xmlActivity) throws SpecificationException {
    CompleteHumanTask activity = new CompleteHumanTask(pTrack);
    activity.setTaskName(xmlActivity.getTaskName());
    NamespaceContext context = getNamespaceMap(xmlActivity.newCursor());

    Element rawDataRoot = null;
    String templateText = null;/*www  .  ja va  2s  . c o  m*/
    try {
        if (xmlActivity.isSetData()) {
            rawDataRoot = getLiteralDataForSend(xmlActivity.getData(), testDirectory);
        }
        if (xmlActivity.isSetTemplate()) {
            templateText = getTemplateText(testDirectory, xmlActivity.getTemplate());
        }
    } catch (Exception ex) {
        throw new SpecificationException(
                "There was a problem while interpreting the 'src' attribute in activity " + activity, ex);
    }
    final Element literalSendDataChild = rawDataRoot != null ? (Element) rawDataRoot.getFirstChild() : null;

    CompleteHumanTaskSpecification spec = new CompleteHumanTaskSpecification(activity, context,
            literalSendDataChild, templateText, pTrack);

    // get conditions
    List<XMLCondition> xmlConditionList = xmlActivity.getConditionList();
    List<ReceiveCondition> cList = new ArrayList<ReceiveCondition>();
    if (xmlConditionList != null) {
        for (XMLCondition xmlCondition : xmlConditionList) {
            cList.add(new ReceiveCondition(spec, xmlCondition.getExpression(), xmlCondition.getTemplate(),
                    xmlCondition.getValue()));
        }
    }
    addConditionsFromConditionGroups(xmlActivity.getConditionGroupList(), spec, cList);
    spec.setConditions(cList);

    // get data extraction requests
    final List<XMLDataExtraction> xmlDataExtractionList = xmlActivity.getDataExtractionList();
    final List<DataExtraction> deList = readDataExtractionElements(spec, xmlDataExtractionList);
    spec.setDataExtractions(deList);

    activity.initialize(spec);
    return activity;
}

From source file:co.cask.cdap.common.conf.Configuration.java

private void loadResource(Properties properties, Object name, boolean quiet) {
    try {/*from  ww w.  j av a2  s  .co  m*/
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        //ignore all comments inside the xml file
        docBuilderFactory.setIgnoringComments(true);

        //allow includes in the xml file
        docBuilderFactory.setNamespaceAware(true);
        try {
            docBuilderFactory.setXIncludeAware(true);
        } catch (UnsupportedOperationException e) {
            LOG.error("Failed to set setXIncludeAware(true) for parser " + docBuilderFactory + ":" + e, e);
        }
        DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
        Document doc = null;
        Element root = null;

        if (name instanceof URL) { // an URL resource
            URL url = (URL) name;
            if (url != null) {
                if (!quiet) {
                    LOG.info("parsing " + url);
                }
                doc = builder.parse(url.toString());
            }
        } else if (name instanceof String) { // a CLASSPATH resource
            URL url = getResource((String) name);
            if (url != null) {
                if (!quiet) {
                    LOG.info("parsing " + url);
                }
                doc = builder.parse(url.toString());
            }
        } else if (name instanceof InputStream) {
            try {
                doc = builder.parse((InputStream) name);
            } finally {
                ((InputStream) name).close();
            }
        } else if (name instanceof Element) {
            root = (Element) name;
        }

        if (doc == null && root == null) {
            if (quiet) {
                return;
            }
            throw new RuntimeException(name + " not found");
        }

        if (root == null) {
            root = doc.getDocumentElement();
        }
        if (!"configuration".equals(root.getTagName())) {
            LOG.fatal("bad conf file: top-level element not <configuration>");
        }
        NodeList props = root.getChildNodes();
        for (int i = 0; i < props.getLength(); i++) {
            Node propNode = props.item(i);
            if (!(propNode instanceof Element)) {
                continue;
            }
            Element prop = (Element) propNode;
            if ("configuration".equals(prop.getTagName())) {
                loadResource(properties, prop, quiet);
                continue;
            }
            if (!"property".equals(prop.getTagName())) {
                LOG.warn("bad conf file: element not <property>");
            }
            NodeList fields = prop.getChildNodes();
            String attr = null;
            String value = null;
            boolean finalParameter = false;
            for (int j = 0; j < fields.getLength(); j++) {
                Node fieldNode = fields.item(j);
                if (!(fieldNode instanceof Element)) {
                    continue;
                }
                Element field = (Element) fieldNode;
                if ("name".equals(field.getTagName()) && field.hasChildNodes()) {
                    attr = ((Text) field.getFirstChild()).getData().trim();
                }
                if ("value".equals(field.getTagName()) && field.hasChildNodes()) {
                    value = ((Text) field.getFirstChild()).getData();
                }
                if ("final".equals(field.getTagName()) && field.hasChildNodes()) {
                    finalParameter = "true".equals(((Text) field.getFirstChild()).getData());
                }
            }

            // Ignore this parameter if it has already been marked as 'final'
            if (attr != null) {
                if (deprecatedKeyMap.containsKey(attr)) {
                    DeprecatedKeyInfo keyInfo = deprecatedKeyMap.get(attr);
                    keyInfo.accessed = false;
                    for (String key : keyInfo.newKeys) {
                        // update new keys with deprecated key's value
                        loadProperty(properties, name, key, value, finalParameter);
                    }
                } else {
                    loadProperty(properties, name, attr, value, finalParameter);
                }
            }
        }

    } catch (IOException e) {
        LOG.fatal("error parsing conf file: " + e);
        throw new RuntimeException(e);
    } catch (DOMException e) {
        LOG.fatal("error parsing conf file: " + e);
        throw new RuntimeException(e);
    } catch (SAXException e) {
        LOG.fatal("error parsing conf file: " + e);
        throw new RuntimeException(e);
    } catch (ParserConfigurationException e) {
        LOG.fatal("error parsing conf file: " + e);
        throw new RuntimeException(e);
    }
}

From source file:com.glaf.core.config.Configuration.java

private Resource loadResource(Properties properties, Resource wrapper, boolean quiet) {
    String name = UNKNOWN_RESOURCE;
    try {/*from  www. ja v  a2  s .c o  m*/
        Object resource = wrapper.getResource();
        name = wrapper.getName();

        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        // ignore all comments inside the xml file
        docBuilderFactory.setIgnoringComments(true);

        // allow includes in the xml file
        docBuilderFactory.setNamespaceAware(true);
        try {
            docBuilderFactory.setXIncludeAware(true);
        } catch (UnsupportedOperationException e) {
            LOG.error("Failed to set setXIncludeAware(true) for parser " + docBuilderFactory + ":" + e, e);
        }
        DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
        Document doc = null;
        Element root = null;
        boolean returnCachedProperties = false;

        if (resource instanceof URL) { // an URL resource
            doc = parse(builder, (URL) resource);
        } else if (resource instanceof String) { // a CLASSPATH resource
            URL url = getResource((String) resource);
            doc = parse(builder, url);
        } else if (resource instanceof InputStream) {
            doc = parse(builder, (InputStream) resource, null);
            returnCachedProperties = true;
        } else if (resource instanceof Properties) {
            overlay(properties, (Properties) resource);
        } else if (resource instanceof Element) {
            root = (Element) resource;
        }

        if (root == null) {
            if (doc == null) {
                if (quiet) {
                    return null;
                }
                throw new RuntimeException(resource + " not found");
            }
            root = doc.getDocumentElement();
        }
        Properties toAddTo = properties;
        if (returnCachedProperties) {
            toAddTo = new Properties();
        }
        if (!"configuration".equals(root.getTagName()))
            LOG.fatal("bad conf file: top-level element not <configuration>");
        NodeList props = root.getChildNodes();

        for (int i = 0; i < props.getLength(); i++) {
            Node propNode = props.item(i);
            if (!(propNode instanceof Element))
                continue;
            Element prop = (Element) propNode;
            if ("configuration".equals(prop.getTagName())) {
                loadResource(toAddTo, new Resource(prop, name), quiet);
                continue;
            }
            if (!"property".equals(prop.getTagName()))
                LOG.warn("bad conf file: element not <property>");
            NodeList fields = prop.getChildNodes();
            String attr = null;
            String value = null;
            boolean finalParameter = false;
            LinkedList<String> source = new LinkedList<String>();
            for (int j = 0; j < fields.getLength(); j++) {
                Node fieldNode = fields.item(j);
                if (!(fieldNode instanceof Element))
                    continue;
                Element field = (Element) fieldNode;
                if ("name".equals(field.getTagName()) && field.hasChildNodes())
                    attr = StringInterner.weakIntern(((Text) field.getFirstChild()).getData().trim());
                if ("value".equals(field.getTagName()) && field.hasChildNodes())
                    value = StringInterner.weakIntern(((Text) field.getFirstChild()).getData());
                if ("final".equals(field.getTagName()) && field.hasChildNodes())
                    finalParameter = "true".equals(((Text) field.getFirstChild()).getData());
                if ("source".equals(field.getTagName()) && field.hasChildNodes())
                    source.add(StringInterner.weakIntern(((Text) field.getFirstChild()).getData()));
            }
            source.add(name);

            // Ignore this parameter if it has already been marked as
            // 'final'
            if (attr != null) {
                loadProperty(toAddTo, name, attr, value, finalParameter,
                        source.toArray(new String[source.size()]));
            }
        }

        if (returnCachedProperties) {
            overlay(properties, toAddTo);
            return new Resource(toAddTo, name);
        }
        return null;
    } catch (IOException e) {
        LOG.fatal("error parsing conf " + name, e);
        throw new RuntimeException(e);
    } catch (DOMException e) {
        LOG.fatal("error parsing conf " + name, e);
        throw new RuntimeException(e);
    } catch (SAXException e) {
        LOG.fatal("error parsing conf " + name, e);
        throw new RuntimeException(e);
    } catch (ParserConfigurationException e) {
        LOG.fatal("error parsing conf " + name, e);
        throw new RuntimeException(e);
    }
}

From source file:de.betterform.xml.xforms.model.submission.Submission.java

/**
 * Implements <code>xforms-submit</code> default action.
 *///from   w w w .  j  a va2s .  c o m
protected void submit() throws XFormsException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug(this + " submit");
    }

    try {
        updateXPathContext();
    } catch (Exception xe) {
        LOGGER.warn("Exception occured while updating nodeset bound by submission "
                + DOMUtil.getCanonicalPath(this.element) + " " + xe.getMessage());
        LOGGER.warn(
                "Exception occured while updating nodeset bound by submission - exception will be ignored. Submission cancelled");
        return;
    }

    // get instance object and location path to submit
    Instance instanceObject = this.model.getInstance(getInstanceId());
    /*
            if(instanceObject == null) {
    instanceObject = targetModel.getInstance(getInstanceId());
            }
    */
    String pathExpression = getLocationPath();
    if (!XPathUtil.existsNode(instanceObject.getInstanceNodeset(), 1, locationPath, getPrefixMapping(),
            this.xpathFunctionContext)) {
        throw new XFormsSubmitError("nodeset is empty at: " + DOMUtil.getCanonicalPath(this.getElement()),
                this.getTarget(), XFormsSubmitError.constructInfoObject(this.element, this.container,
                        locationPath, XFormsConstants.NO_DATA, getResourceURI()));
    }

    //todo: when serialization is 'none' validation and relevance selection should be skipped if not explicitly set as attributes
    // validate instance items
    submitValidate(instanceObject, pathExpression, getPrefixMapping(), this.xpathFunctionContext);

    // select relevant items
    //todo: this should happen before submitValidate above according to spec - see the xforms-submit event
    Node instanceNode = submitSelectRelevant(instanceObject, pathExpression);

    Map response;
    try {
        // todo: should be supported by serializers
        /*
                    if (this.includenamespaceprefixes != null) {
        getLogger().warn(this + " submit: the 'includenamespaceprefixes' attribute is not supported yet");
                    }
        */

        processSubmissionOptions();

        // todo: refactor submission options to become a typed object, e.g. SubmissionOptions
        // todo: refactor submission response to become a typed object, e.g. SubmissionResponse
        // todo: refactor serializers to be set excplicitly

        // Look for resource submission option and possibly replace action
        // Implementation of the resource attribute version 1.1 feature
        // http://www.w3.org/TR/2007/CR-xforms11-20071129/#submit
        // chapter 11.1
        if (this.resource != null && this.resource.isAvailable()) {
            // obtain relative URI
            //                String relativeURI = null;
            //                relativeURI = instanceObject.getNodeValue(this.resource);
            //
            //                if (relativeURI != null) {
            //                    // resolve uri and assign to action
            //                    this.action = this.container.getConnectorFactory().getAbsoluteURI(relativeURI, this.element).toString();
            //                }
            this.action = getResourceURI();
        }

        //do xforms-submit-serialize handling
        final Element submissionBodyEl = this.element.getOwnerDocument().createElement("submission-body");
        final Map<String, Object> info = new HashMap<String, Object>();
        info.put(XFormsConstants.SUBMISSION_BODY,
                this.container.getDocumentWrapper(this.element).wrap(submissionBodyEl));

        this.container.dispatch(this.id, XFormsEventNames.SUBMIT_SERIALIZE, info);
        submissionBodyEl.normalize();

        // serialize and transmit instance items
        SubmissionHandler sh = this.container.getConnectorFactory().createSubmissionHandler(this.action,
                this.element);
        if (submissionBodyEl.getFirstChild() == null) {
            response = sh.submit(this, instanceNode);
        } else {
            response = sh.submit(this, submissionBodyEl.getFirstChild());
        }
    } catch (XFormsInternalSubmitException e) {
        Map<String, Object> info = XFormsSubmitError.constructInfoObject(this.element, this.container,
                locationPath, e.getErrorType(), getResourceURI(), e.getStatusCode(), null, e.getStatusText(),
                e.getResponseBodyAsString());
        throw new XFormsSubmitError(
                "instance submission failed at: " + DOMUtil.getCanonicalPath(this.getElement()), e,
                this.getTarget(), info);
    } catch (Exception e) {
        String errorType;
        if (e instanceof XFormsInternalSubmitException) {
            errorType = ((XFormsInternalSubmitException) e).getErrorType();
        } else {
            errorType = XFormsConstants.RESOURCE_ERROR;
        }
        Map<String, Object> info = XFormsSubmitError.constructInfoObject(this.element, this.container,
                locationPath, errorType, getResourceURI());

        //todo: hacky - event context info construction must be reviewed - using exception cause as response-reason-phrase for now
        if (e.getCause() != null && e.getCause().getMessage() != null) {
            info.put(RESPONSE_REASON_PHRASE, e.getCause().getMessage());
            if (e.getCause() instanceof XFormsInternalSubmitException) {
                info.put(RESPONSE_STATUS_CODE,
                        new Integer(((XFormsInternalSubmitException) e.getCause()).getStatusCode())
                                .doubleValue());
            }
        }
        throw new XFormsSubmitError(
                "instance submission failed at: " + DOMUtil.getCanonicalPath(this.getElement()), e,
                this.getTarget(), info);
        //throw new XFormsSubmitError("instance submission failed", e, this.getTarget(), this.action);
    }

    //todo: for async submits processing should stop here!!!
    // handle replace mode
    if (this.replace.equals("all")) {
        submitReplaceAll(response);
        return;
    }
    if (this.replace.equals("instance")) {
        submitReplaceInstance(response);
        return;
    }
    if (this.replace.equals("text")) {
        submitReplaceText(response);
        return;
    }
    if (this.replace.equals("none")) {
        submitReplaceNone(response);
        return;
    }
    if (this.replace.equals("embedHTML")) {
        submitReplaceEmbedHTML(response);
        return;
    }
    if (this.replace.equals("embedXFormsUI")) {
        submitReplaceEmbedXForms(response);
        return;
    }

    if (this.replace.equals("new")) {
        submitReplaceNew(response);
        return;
    }

    throw new XFormsSubmitError("unknown replace mode " + this.replace, this.getTarget(),
            XFormsSubmitError.constructInfoObject(this.element, this.container, locationPath,
                    XFormsConstants.VALIDATION_ERROR, getResourceURI()));
}

From source file:com.amalto.workbench.utils.XSDGenerateHTML.java

/**
 * Handle a markup element by caching information in a map.
 * //w  w w  .jav  a  2  s . c  o  m
 * @param markupMap the map to contain the markup.
 * @param markupElement the element specifying the markup.
 */
public void handleMarkup(Map markupMap, Element markupElement) {
    String keyList = markupElement.getAttribute("key"); //$NON-NLS-1$
    for (StringTokenizer stringTokenizer = new StringTokenizer(keyList); stringTokenizer.hasMoreTokens();) {
        String key = stringTokenizer.nextToken();
        String markup = markupElement.getAttribute("markup"); //$NON-NLS-1$
        if (markup.length() > 0) {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            try {
                TransformerFactory transformerFactory = TransformerFactory.newInstance();
                Transformer transformer = transformerFactory.newTransformer();

                transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
                transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
                transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$

                for (Node grandChild = markupElement
                        .getFirstChild(); grandChild != null; grandChild = grandChild.getNextSibling()) {
                    if (grandChild.getNodeType() == Node.ELEMENT_NODE) {
                        transformer.transform(new DOMSource(grandChild), new StreamResult(out));
                    }
                }
                String serialization = out.toString();
                serialization = serialization.substring(serialization.indexOf("<div>")); //$NON-NLS-1$
                markupMap.put(key, markup + "@" + serialization); //$NON-NLS-1$
            } catch (Exception exception) {
                exception.printStackTrace(System.err);
            }
        }
    }
}

From source file:com.netspective.sparx.util.xml.XmlSource.java

public void inheritElement(Element srcElement, Element destElem, Set excludeElems, String inheritedFromNode) {
    NamedNodeMap inhAttrs = srcElement.getAttributes();
    for (int i = 0; i < inhAttrs.getLength(); i++) {
        Node attrNode = inhAttrs.item(i);
        final String nodeName = attrNode.getNodeName();
        if (!excludeElems.contains(nodeName) && destElem.getAttribute(nodeName).equals(""))
            destElem.setAttribute(nodeName, attrNode.getNodeValue());
    }//from ww w. j ava  2s .  co m

    DocumentFragment inheritFragment = xmlDoc.createDocumentFragment();
    NodeList inhChildren = srcElement.getChildNodes();
    for (int i = inhChildren.getLength() - 1; i >= 0; i--) {
        Node childNode = inhChildren.item(i);

        // only add if there isn't an attribute overriding this element
        final String nodeName = childNode.getNodeName();
        if (destElem.getAttribute(nodeName).length() == 0 && (!excludeElems.contains(nodeName))) {
            Node cloned = childNode.cloneNode(true);
            if (inheritedFromNode != null && cloned.getNodeType() == Node.ELEMENT_NODE)
                ((Element) cloned).setAttribute("_inherited-from", inheritedFromNode);
            inheritFragment.insertBefore(cloned, inheritFragment.getFirstChild());
        }
    }

    destElem.insertBefore(inheritFragment, destElem.getFirstChild());
}

From source file:edu.uams.clara.webapp.xml.processor.impl.DefaultXmlProcessorImpl.java

private synchronized String duplicate(final Document originalDom, final Element originalRootElement,
        final Element patchElement) throws Exception {

    boolean isdone = false;
    Element parentElement = null;

    DuplicateChildElementObject childElementObject = isChildElement(originalRootElement, patchElement);
    if (!childElementObject.isNeedDuplicate()) {
        isdone = true;//from   ww  w . j  a  v  a 2 s .  c o  m
        parentElement = childElementObject.getElement();
    } else if (childElementObject.getElement() != null) {
        parentElement = childElementObject.getElement();
    } else {
        parentElement = originalRootElement;
    }

    String son_name = patchElement.getNodeName();

    Element subITEM = null;
    if (!isdone) {
        subITEM = originalDom.createElement(son_name);

        if (patchElement.hasChildNodes()) {
            if (patchElement.getFirstChild().getNodeType() == Node.TEXT_NODE) {
                subITEM.setTextContent(patchElement.getTextContent());

            }
        }

        if (patchElement.hasAttributes()) {
            NamedNodeMap attributes = patchElement.getAttributes();
            for (int i = 0; i < attributes.getLength(); i++) {
                String attribute_name = attributes.item(i).getNodeName();
                String attribute_value = attributes.item(i).getNodeValue();
                subITEM.setAttribute(attribute_name, attribute_value);
            }
        }
        parentElement.appendChild(subITEM);
    } else {
        subITEM = parentElement;
    }

    NodeList sub_messageItems = patchElement.getChildNodes();
    int sub_item_number = sub_messageItems.getLength();
    logger.debug("patchEl: " + DomUtils.elementToString(patchElement) + "length: " + sub_item_number);
    if (sub_item_number == 0) {
        isdone = true;
    } else {
        for (int j = 0; j < sub_item_number; j++) {
            if (sub_messageItems.item(j).getNodeType() == Node.ELEMENT_NODE) {
                Element sub_messageItem = (Element) sub_messageItems.item(j);
                logger.debug("node name: " + DomUtils.elementToString(subITEM) + " node type: "
                        + subITEM.getNodeType());
                duplicate(originalDom, subITEM, sub_messageItem);
            }

        }
    }

    return (parentElement != null) ? DomUtils.elementToString(parentElement) : "";
}

From source file:MyZone.Settings.java

private String getTextValue(Element ele, String tagName) {
    String textVal = null;/*from   w  w  w.java  2  s. c o  m*/
    NodeList nl = ele.getElementsByTagName(tagName);
    if (nl != null && nl.getLength() > 0) {
        Element el = (Element) nl.item(0);
        textVal = el.getFirstChild().getNodeValue();
    }

    return textVal;
}

From source file:autohit.creator.compiler.SimCompiler.java

/**
 *  handle a Buffer.//  ww  w .j a v  a 2 s .c  o  m
 *  MICROCODE
 *  1- if (clear exists)   i.clear(name), ALREADY = true
 *   2- if (eval exists)   i.eval(eval), i.merge(name) 
 *  3-    else if (value exists) i.left(value), i.merge(name)
 *  4-    else if (buffer exists)i.reduce(buffer), i.merge(name)
 *  5-    else CLEAR = true         
 *  6- if (cdata exists)           i.load(cdata), i.merge(name)
 *  7-      else if (CLEAR true, ALREADY false)      i.clear(name)
 */
private void handleBuffer(Element en) {

    String name = en.getAttribute(ATTR_NAME);
    String cdata;
    boolean clearFlag = false;
    boolean clearAlready = false;

    //runtimeDebug("handleBuffer.  name=" + name);

    // 1- if (clear exists)   i.clear(name)
    if (en.hasAttribute(ATTR_CLEAR)) {
        this.emitClear(name);
        clearAlready = true;
    }

    // 2- if (eval exists)   i.eval(eval), i.merge(name) 
    if (en.hasAttribute(ATTR_EVALUATOR)) {
        this.emitEval(en.getAttribute(ATTR_EVALUATOR));
        this.emitMerge(en.getAttribute(ATTR_NAME));

        // 3-    else if (value exists) i.load(value), i.merge(name)    
    } else if (en.hasAttribute(ATTR_VALUE)) {
        this.emitLoad(en.getAttribute(ATTR_VALUE));
        this.emitMerge(en.getAttribute(ATTR_NAME));

        // 4- else if (buffer exists)i.reduce(buffer), i.merge(name) 
    } else if (en.hasAttribute(ATTR_BUFFER)) {
        this.emitReduce(en.getAttribute(ATTR_BUFFER));
        this.emitMerge(en.getAttribute(ATTR_NAME));

        // 5-    else          i.clear(name), done
    } else {
        clearFlag = true;
    }

    // 6- if (cdata exists)    i.load(cdata), i.merge(name)
    try {
        cdata = getText(en.getFirstChild());
    } catch (Exception e) {
        cdata = null;
    }

    if (cdata != null) {
        this.emitLoad(cdata);
        this.emitMerge(en.getAttribute(ATTR_NAME));

        // 7- else if (CLEAR true, ALREADY false)      i.clear(name)
    } else if ((clearFlag == true) && (clearAlready == false)) {
        this.emitClear(name);
    }
}

From source file:com.twinsoft.convertigo.engine.util.WsReference.java

private static void extractSoapVariables(XmlSchema xmlSchema, List<RequestableHttpVariable> variables,
        Node node, String longName, boolean isMulti, QName variableType) throws EngineException {
    if (node == null)
        return;/*from  w w w  . ja va2  s  . c om*/
    int type = node.getNodeType();

    if (type == Node.ELEMENT_NODE) {
        Element element = (Element) node;
        if (element != null) {
            String elementName = element.getLocalName();
            if (longName != null)
                elementName = longName + "_" + elementName;

            if (!element.getAttribute("soapenc:arrayType").equals("") && !element.hasChildNodes()) {
                String avalue = element.getAttribute("soapenc:arrayType");
                element.setAttribute("soapenc:arrayType", avalue.replaceAll("\\[\\]", "[1]"));

                Element child = element.getOwnerDocument().createElement("item");
                String atype = avalue.replaceAll("\\[\\]", "");
                child.setAttribute("xsi:type", atype);
                if (atype.startsWith("xsd:")) {
                    String variableName = elementName + "_item";
                    child.appendChild(
                            element.getOwnerDocument().createTextNode("$(" + variableName.toUpperCase() + ")"));
                    RequestableHttpVariable httpVariable = createHttpVariable(true, variableName,
                            new QName(Constants.URI_2001_SCHEMA_XSD, atype.split(":")[1]));
                    variables.add(httpVariable);
                }
                element.appendChild(child);
            }

            // extract from attributes
            NamedNodeMap map = element.getAttributes();
            for (int i = 0; i < map.getLength(); i++) {
                Node child = map.item(i);
                if (child.getNodeName().equals("soapenc:arrayType"))
                    continue;
                if (child.getNodeName().equals("xsi:type"))
                    continue;
                if (child.getNodeName().equals("soapenv:encodingStyle"))
                    continue;

                String variableName = getVariableName(variables, elementName + "_" + child.getLocalName());

                child.setNodeValue("$(" + variableName.toUpperCase() + ")");

                RequestableHttpVariable httpVariable = createHttpVariable(false, variableName,
                        Constants.XSD_STRING);
                variables.add(httpVariable);
            }

            // extract from children nodes
            boolean multi = false;
            QName qname = Constants.XSD_STRING;
            NodeList children = element.getChildNodes();
            if (children.getLength() > 0) {
                Node child = element.getFirstChild();
                while (child != null) {
                    if (child.getNodeType() == Node.COMMENT_NODE) {
                        String value = child.getNodeValue();
                        if (value.startsWith("type:")) {
                            String schemaType = child.getNodeValue().substring("type:".length()).trim();
                            qname = getVariableSchemaType(xmlSchema, schemaType);
                        }
                        if (value.indexOf("repetitions:") != -1) {
                            multi = true;
                        }
                    } else if (child.getNodeType() == Node.TEXT_NODE) {
                        String value = child.getNodeValue().trim();
                        if (value.equals("?") || !value.equals("")) {
                            String variableName = getVariableName(variables, elementName);

                            child.setNodeValue("$(" + variableName.toUpperCase() + ")");

                            RequestableHttpVariable httpVariable = createHttpVariable(isMulti, variableName,
                                    variableType);
                            variables.add(httpVariable);
                        }
                    } else if (child.getNodeType() == Node.ELEMENT_NODE) {
                        extractSoapVariables(xmlSchema, variables, child, elementName, multi, qname);
                        multi = false;
                        qname = Constants.XSD_STRING;
                    }

                    child = child.getNextSibling();
                }
            }

        }
    }
}