public void writeStartElement()

in core/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java [166:294]


    public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException {
        currentDepth++;
        namespaceContext.down();
        if (matchesDropped(false)) {
            return;
        }
        Set<String> s;
        if (writtenUris.isEmpty()) {
            s = new HashSet<>();
        } else {
            s = new HashSet<>(writtenUris.get(0));
        }
        writtenUris.add(0, s);

        final QName theName = new QName(uri, local, prefix);
        final ElementProperty appendProp = appendMap.remove(theName);
        final boolean replaceContent = appendProp != null && theName.equals(appendProp.getName());

        final boolean dropped = dropElements.contains(theName);
        QName expected = elementsMap.get(theName);
        if (expected == null) {
            expected = theName;
        } else {
            if (prefix.isEmpty() && !expected.getNamespaceURI().isEmpty()
                && theName.getNamespaceURI().isEmpty()) {
                // if the element is promoted to a qualified element, use the prefix bound
                // to that namespace. If the namespace is unbound, generate a new prefix and
                // write its declaration later.
                prefix = namespaceContext.getPrefix(expected.getNamespaceURI());
                if (prefix == null) {
                    prefix = namespaceContext.findUniquePrefix(expected.getNamespaceURI());
                }
            } else if (!prefix.isEmpty() && expected.getNamespaceURI().isEmpty()) {
                // if the element is demoted to a unqualified element, use an empty prefix.
                prefix = "";
            }
            expected = new QName(expected.getNamespaceURI(), expected.getLocalPart(), prefix);
        }
        List<ParsingEvent> pe = null;
        if (appendProp != null && !replaceContent) {
            if (!appendProp.isChild()) {
                // ap-pre-*
                QName appendQName = appendProp.getName();
                String theprefix = namespaceContext.getPrefix(appendQName.getNamespaceURI());
                boolean nsadded = false;
                if (theprefix == null) {
                    nsadded = true;
                    theprefix = namespaceContext.getPrefix(appendQName.getNamespaceURI());
                    if (theprefix == null
                        && (appendQName.getNamespaceURI().equals(expected.getNamespaceURI())
                            && expected.getPrefix().length() > 0)) {
                        theprefix = expected.getPrefix();
                    } else if (theprefix == null) {
                        theprefix = namespaceContext.findUniquePrefix(appendQName.getNamespaceURI());
                    }
                    if (theprefix == null) {
                        theprefix = "";
                    }
                }
                write(new QName(appendQName.getNamespaceURI(), appendQName.getLocalPart(), theprefix), false);
                if (nsadded && theprefix.length() > 0) {
                    writeNamespace(theprefix, appendQName.getNamespaceURI());
                }
                if (appendProp.getText() == null) {
                    // ap-pre-wrap
                    currentDepth++;
                    pe = new ArrayList<>();
                    pe.add(TransformUtils.createEndElementEvent(expected));
                    pe.add(TransformUtils.createEndElementEvent(appendProp.getName()));
                    pushedAheadEvents.add(0, null);
                    elementsStack.add(0, appendQName);
                } else {
                    // ap-pre-incl
                    super.writeCharacters(appendProp.getText());
                    super.writeEndElement();
                }
            }
        } else if (null != appendProp && replaceContent) {
            //
            replaceText = appendProp.getText();
        } else if (dropped) {
            // unwrap the current element (shallow drop)
            elementsStack.add(0, theName);
            return;
        } else if (TransformUtils.isEmptyQName(expected)) {
            // skip the current element (deep drop));
            dropDepth = currentDepth;
            return;
        }
        write(expected, false);
        if (!expected.getNamespaceURI().isEmpty() && theName.getNamespaceURI().isEmpty()) {
            // the element is promoted to a qualified element, thus write its declaration
            writeNamespace(expected.getPrefix(), expected.getNamespaceURI());
        }
        pushedAheadEvents.add(0, pe);
        elementsStack.add(0, expected);
        replaceNamespace = expected.getNamespaceURI().equals(theName.getNamespaceURI())
            ? null : theName.getNamespaceURI();

        if (appendProp != null && !replaceContent && appendProp.isChild()) {
            // ap-post-*
            QName appendQName = appendProp.getName();
            String theprefix = namespaceContext.getPrefix(appendQName.getNamespaceURI());

            if (appendProp.getText() == null) {
                // ap-post-wrap
                write(new QName(appendQName.getNamespaceURI(), appendQName.getLocalPart(),
                                theprefix == null ? "" : theprefix), false);
                if (namespaceContext.getPrefix(appendQName.getNamespaceURI()) == null) {
                    this.writeNamespace(theprefix, uri);
                }
                currentDepth++;
                pe = new ArrayList<>();
                pe.add(TransformUtils.createEndElementEvent(appendProp.getName()));
                pe.add(TransformUtils.createEndElementEvent(expected));
                pushedAheadEvents.add(0, pe);
                elementsStack.add(0, appendQName);
            } else {
                // ap-post-incl
                pushedAheadEvents.remove(0);
                pe = new ArrayList<>();
                pe.add(TransformUtils.createStartElementEvent(appendProp.getName()));
                pe.add(TransformUtils.createCharactersEvent(appendProp.getText()));
                pe.add(TransformUtils.createEndElementEvent(appendProp.getName()));
                pe.add(TransformUtils.createEndElementEvent(expected));
                pushedAheadEvents.add(0, pe);
            }
        }
    }