Example usage for org.w3c.dom Element getOwnerDocument

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

Introduction

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

Prototype

public Document getOwnerDocument();

Source Link

Document

The Document object associated with this node.

Usage

From source file:net.wastl.webmail.xml.XMLMessagePart.java

/**
 * Return a new part for a given part element
 *///  w ww. j  a va 2s. c  om
public XMLMessagePart(Element part) {
    this.part = part;
    this.root = part.getOwnerDocument();
}

From source file:org.adeptnet.auth.saml.SAMLClient.java

private String _createAuthnRequest(final String requestId) throws SAMLException {
    final AuthnRequest request = createAuthnRequest(requestId);

    try {//from   w  w  w . j a  va  2  s. co  m
        // samlobject to xml dom object
        final Element elem = Configuration.getMarshallerFactory().getMarshaller(request).marshall(request);

        // and to a string...
        final Document document = elem.getOwnerDocument();
        final DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation();
        final LSSerializer serializer = domImplLS.createLSSerializer();
        serializer.getDomConfig().setParameter("xml-declaration", false);
        return serializer.writeToString(elem);
    } catch (MarshallingException e) {
        throw new SAMLException(e);
    }
}

From source file:org.alfresco.web.forms.xforms.Schema2XForms.java

private void addAttributeSet(final Document xformsDocument, final Element modelSection,
        final Element defaultInstanceElement, final Element formSection, final XSModel schema,
        final XSComplexTypeDefinition controlType, final XSElementDeclaration owner, final String pathToRoot,
        final boolean checkIfExtension, final ResourceBundle resourceBundle) throws FormBuilderException {
    XSObjectList attrUses = controlType.getAttributeUses();

    if (attrUses == null) {
        return;/*w w  w .j  av  a2  s  .c  o m*/
    }
    for (int i = 0; i < attrUses.getLength(); i++) {
        final XSAttributeUse currentAttributeUse = (XSAttributeUse) attrUses.item(i);
        final XSAttributeDeclaration currentAttribute = currentAttributeUse.getAttrDeclaration();

        String attributeName = currentAttributeUse.getName();
        if (attributeName == null || attributeName.length() == 0) {
            attributeName = currentAttributeUse.getAttrDeclaration().getName();
        }

        //test if extended !
        if (checkIfExtension && SchemaUtil.doesAttributeComeFromExtension(currentAttributeUse, controlType)) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(
                        "[addAttributeSet] This attribute comes from an extension: recopy form controls. Model section =\n"
                                + XMLUtil.toString(modelSection));
            }

            //find the existing bind Id
            //(modelSection is the enclosing bind of the element)
            final NodeList binds = modelSection.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "bind");
            String bindId = null;
            for (int j = 0; j < binds.getLength() && bindId == null; j++) {
                Element bind = (Element) binds.item(j);
                String nodeset = bind.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset");
                if (nodeset != null) {
                    //remove "@" in nodeset
                    String name = nodeset.substring(1);
                    if (name.equals(attributeName)) {
                        bindId = bind.getAttributeNS(null, "id");
                    }
                }
            }

            //find the control
            Element control = null;
            if (bindId != null) {
                if (LOGGER.isDebugEnabled())
                    LOGGER.debug("[addAttributeSet] bindId found: " + bindId);

                JXPathContext context = JXPathContext.newContext(formSection.getOwnerDocument());
                final Pointer pointer = context
                        .getPointer("//*[@" + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']");
                if (pointer != null) {
                    control = (Element) pointer.getNode();
                } else if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("[addAttributeSet] unable to resolve pointer for: //*[@"
                            + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']");
                }
            }

            if (LOGGER.isDebugEnabled()) {
                if (control == null) {
                    LOGGER.debug("[addAttributeSet] control = <not found>");
                } else {
                    LOGGER.debug("[addAttributeSet] control = " + control.getTagName());
                }
            }

            //copy it
            if (control == null) {
                if (LOGGER.isDebugEnabled())
                    LOGGER.debug("Corresponding control not found");
            } else {
                Element newControl = (Element) control.cloneNode(true);
                //set new Ids to XForm elements
                this.resetXFormIds(newControl);

                formSection.appendChild(newControl);
            }
        } else {
            String attrNamespace = currentAttribute.getNamespace();
            String namespacePrefix = "";
            if (attrNamespace != null && attrNamespace.length() > 0) {
                String prefix = NamespaceResolver.getPrefix(xformsDocument.getDocumentElement(), attrNamespace);
                if (prefix != null && prefix.length() > 0) {
                    namespacePrefix = prefix + ":";
                }
            }

            final String newPathToRoot = (pathToRoot == null || pathToRoot.length() == 0
                    ? "@" + namespacePrefix + currentAttribute.getName()
                    : (pathToRoot.endsWith("/")
                            ? pathToRoot + "@" + namespacePrefix + currentAttribute.getName()
                            : pathToRoot + "/@" + namespacePrefix + currentAttribute.getName()));

            if (LOGGER.isDebugEnabled())
                LOGGER.debug("[addAttributeSet] adding attribute " + attributeName + " at " + newPathToRoot);

            try {
                String defaultValue = (currentAttributeUse.getConstraintType() == XSConstants.VC_NONE ? null
                        : currentAttributeUse.getConstraintValue());
                // make sure boolean attributes have a default value
                if (defaultValue == null && "boolean".equals(currentAttribute.getTypeDefinition().getName())) {
                    defaultValue = "false";
                }

                if (namespacePrefix.length() > 0) {
                    defaultInstanceElement.setAttributeNS(this.targetNamespace, attributeName, defaultValue);
                } else {
                    defaultInstanceElement.setAttribute(attributeName, defaultValue);
                }
            } catch (Exception e) {
                throw new FormBuilderException("error retrieving default value for attribute " + attributeName
                        + " at " + newPathToRoot, e);
            }
            this.addSimpleType(xformsDocument, modelSection, formSection, schema,
                    currentAttribute.getTypeDefinition(), currentAttributeUse, newPathToRoot, resourceBundle);
        }
    }
}

From source file:org.alfresco.web.forms.xforms.Schema2XForms.java

/**
 *///from  w  w  w  .  j a  v  a2  s  .co  m
private void addGroup(final Document xformsDocument, final Element modelSection,
        final Element defaultInstanceElement, final Element formSection, final XSModel schema,
        final XSModelGroup group, final XSComplexTypeDefinition controlType, final XSElementDeclaration owner,
        final String pathToRoot, final SchemaUtil.Occurrence occurs, final boolean checkIfExtension,
        final ResourceBundle resourceBundle) throws FormBuilderException {
    if (group == null) {
        return;
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("[addGroup] Start of addGroup, from owner = " + owner.getName() + " and controlType = "
                + controlType.getName());
        LOGGER.debug("[addGroup] group before =\n" + XMLUtil.toString(formSection));
    }

    final Element repeatSection = this.addRepeatIfNecessary(xformsDocument, modelSection, formSection,
            owner.getTypeDefinition(), pathToRoot, occurs);

    final XSObjectList particles = group.getParticles();
    for (int counter = 0; counter < particles.getLength(); counter++) {
        final XSParticle currentNode = (XSParticle) particles.item(counter);
        XSTerm term = currentNode.getTerm();
        final SchemaUtil.Occurrence childOccurs = new SchemaUtil.Occurrence(currentNode);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("[addGroup] next term = " + term.getName() + ", occurs = " + childOccurs);
        }

        if (term instanceof XSModelGroup) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("[addGroup] term is a group");
            }

            this.addGroup(xformsDocument, modelSection, defaultInstanceElement, repeatSection, schema,
                    ((XSModelGroup) term), controlType, owner, pathToRoot, childOccurs, checkIfExtension,
                    resourceBundle);
        } else if (term instanceof XSElementDeclaration) {
            XSElementDeclaration element = (XSElementDeclaration) term;

            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("[addGroup] term is an element declaration: " + term.getName());
            }

            //special case for types already added because used in an extension
            //do not add it when it comes from an extension !!!
            //-> make a copy from the existing form control
            if (checkIfExtension && SchemaUtil.doesElementComeFromExtension(element, controlType)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(
                            "[addGroup] This element comes from an extension: recopy form controls. Model Section =\n"
                                    + XMLUtil.toString(modelSection));
                }

                //find the existing bind Id
                //(modelSection is the enclosing bind of the element)
                NodeList binds = modelSection.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "bind");
                String bindId = null;
                for (int i = 0; i < binds.getLength() && bindId == null; i++) {
                    Element bind = (Element) binds.item(i);
                    String nodeset = bind.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset");

                    Pair<String, String> parsed = parseName(nodeset, xformsDocument);

                    if (nodeset != null
                            && EqualsHelper.nullSafeEquals(parsed.getSecond(), element.getNamespace())
                            && parsed.getFirst().equals(element.getName())) {
                        bindId = bind.getAttributeNS(null, "id");
                    }
                }

                if (LOGGER.isDebugEnabled())
                    LOGGER.debug("[addGroup] found bindId " + bindId + " for element " + element.getName());

                //find the control
                Element control = null;
                if (bindId != null) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("[addGroup] bindId found: " + bindId);
                    }

                    final JXPathContext context = JXPathContext.newContext(formSection.getOwnerDocument());
                    final Pointer pointer = context
                            .getPointer("//*[@" + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']");
                    if (pointer != null) {
                        control = (Element) pointer.getNode();
                    } else if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("[addGroup] unable to resolve pointer for: //*[@"
                                + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']");
                    }
                }

                if (LOGGER.isDebugEnabled()) {
                    if (control == null) {
                        LOGGER.debug("[addGroup] control = <not found>");
                    } else {
                        LOGGER.debug("[addGroup] control = " + control.getTagName());
                    }
                }

                //copy it
                if (control == null) {
                    if (LOGGER.isDebugEnabled())
                        LOGGER.debug("Corresponding control not found");

                    this.addElementToGroup(xformsDocument, modelSection, defaultInstanceElement, repeatSection,
                            schema, element, pathToRoot, childOccurs, resourceBundle);
                } else {
                    Element newControl = (Element) control.cloneNode(true);
                    //set new Ids to XForm elements
                    this.resetXFormIds(newControl);

                    repeatSection.appendChild(newControl);
                }
            } else {
                this.addElementToGroup(xformsDocument, modelSection, defaultInstanceElement, repeatSection,
                        schema, element, pathToRoot, childOccurs, resourceBundle);
            }
        } else {
            LOGGER.warn("Unhandled term " + term + " found in group from " + owner.getName()
                    + " for pathToRoot = " + pathToRoot);
        }
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("[addGroup] group after =\n" + XMLUtil.toString(formSection));
        LOGGER.debug("[addGroup] End of addGroup, from owner = " + owner.getName() + " and controlType = "
                + controlType.getName());
    }
}

From source file:org.alfresco.web.forms.xforms.Schema2XForms.java

/**
 * This method is invoked after an xforms:bind element is created for the specified SimpleType.
 * The implementation is responsible for setting setting any/all bind attributes
 * except for <b>id</b> and <b>ref</b> - these have been automatically set
 * by the caller (and should not be touched by implementation of startBindElement)
 * prior to invoking startBindElement.//from w w  w.j  a  v a2s. c o m
 * The caller automatically adds the returned element to the model section of
 * the form.
 *
 * @param bindElement The bindElement being processed.
 * @param schema XML Schema type of the element/attribute this bind is for.
 * @param controlType
 * @param owner
 * @param o
 * @return The bind Element to use in the XForm - bindElement or a replacement.
 */
public Element startBindElement(final Element bindElement, final XSModel schema,
        final XSTypeDefinition controlType, final XSObject owner, final SchemaUtil.Occurrence o) {
    // START WORKAROUND
    // Due to a Chiba bug, anyType is not a recognized type name.
    // so, if this is an anyType, then we'll just skip the type
    // setting.
    //
    // type.getName() may be 'null' for anonymous types, so compare against
    // static string (see bug #1172541 on sf.net)
    final List<String> constraints = new LinkedList<String>();
    if (controlType instanceof XSSimpleTypeDefinition
            && ((XSSimpleTypeDefinition) controlType).getBuiltInKind() != XSConstants.ANYSIMPLETYPE_DT) {
        String typeName = this.getXFormsTypeName(bindElement.getOwnerDocument(), schema, controlType);
        if (typeName != null && typeName.length() != 0) {
            bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":type",
                    typeName);
        }

        typeName = SchemaUtil.getBuiltInTypeName(controlType);
        if (typeName != null && typeName.length() != 0) {
            bindElement.setAttributeNS(NamespaceService.ALFRESCO_URI,
                    NamespaceService.ALFRESCO_PREFIX + ":builtInType", typeName);
        }
        final StringList lexicalPatterns = ((XSSimpleTypeDefinition) controlType).getLexicalPattern();

        // NOTE: from glen.johnson@alfresco.com
        // Workaround to fix issue WCM-952
        //
        // I added expression '&& !typeName.equals(SchemaSymbols.ATTVAL_INTEGER')
        // onto the end of loop condition expression below.
        //
        // This is to stop the pattern matching constraint (using deprecated chiba:match() function)
        // from being generated into binding elements that are linked to "xs:integer"
        // elements (in the xform instance)
        //
        // If this pattern match constraint is indeed added to the binding element linked to
        // a "xs:integer" element in the xform instance, then a value is always required
        // for that element - even if the corresponding schema has minOccurs="0" for
        // that element i.e. it causes a value to be required for "optional" xs:integer
        // elements.
        //
        // Note that the chiba:match() function is unsupported and will be removed from Chiba
        // in the future, so a solution enabling its complete removal will need to be found.
        // I do not see why it has been included here. The Schema inside the xform 
        // model should take care of most validation needs.
        // In the past, when I have completely removed this constraint (see CHK-2333), restrictions
        // using <xs:pattern> in the Schema fail to get enforced -
        // Causing the failure of org.alfresco.web.forms.xforms.Schema2XFormsTest.testConstraint()
        //
        for (int i = 0; lexicalPatterns != null && i < lexicalPatterns.getLength()
                && !SchemaSymbols.ATTVAL_INTEGER.equals(typeName); i++) {
            String pattern = lexicalPatterns.item(i);
            if (o.isOptional()) {
                pattern = "(" + pattern + ")?";
            }
            constraints.add("chiba:match(., '" + pattern + "',null)");
        }

        XSSimpleTypeDefinition simpleControlType = ((XSSimpleTypeDefinition) controlType);

        if (simpleControlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXLENGTH)) {
            constraints.add("string-length(.) <= "
                    + simpleControlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXLENGTH));
        }

        if (simpleControlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MINLENGTH)) {
            constraints.add("string-length(.) >= "
                    + simpleControlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MINLENGTH));
        }

    }

    final short constraintType = (owner != null && owner instanceof XSElementDeclaration
            ? ((XSElementDeclaration) owner).getConstraintType()
            : (owner != null && owner instanceof XSAttributeDeclaration
                    ? ((XSAttributeDeclaration) owner).getConstraintType()
                    : (owner != null && owner instanceof XSAttributeUse
                            ? ((XSAttributeUse) owner).getConstraintType()
                            : XSConstants.VC_NONE)));

    bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":readonly",
            (constraintType == XSConstants.VC_FIXED) + "()");

    if (controlType instanceof XSSimpleTypeDefinition) {
        bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":required",
                (o.minimum != 0) + "()");
    } else if (controlType instanceof XSComplexTypeDefinition) {
        // make all complex types not required since it helps with validation - otherwise
        // chiba seems to expect a nodevalue for the container element
        bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":required",
                "false()");

    }

    //no more minOccurs & maxOccurs element: add a constraint if maxOccurs>1:
    //count(.) <= maxOccurs && count(.) >= minOccurs
    final String nodeset = bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset");
    if (o.minimum > 1) {
        //if 0 or 1 -> no constraint (managed by "required")
        constraints.add("count(../" + nodeset + ") >= " + o.minimum);
    }
    bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":minOccurs",
            String.valueOf(o.minimum));
    if (o.maximum > 1) {
        //if 1 or unbounded -> no constraint
        constraints.add("count(../" + nodeset + ") <= " + o.maximum);
    }

    bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":maxOccurs",
            o.isUnbounded() ? "unbounded" : String.valueOf(o.maximum));

    if (constraints.size() != 0) {
        bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS,
                NamespaceConstants.XFORMS_PREFIX + ":constraint",
                StringUtils.join((String[]) constraints.toArray(new String[constraints.size()]), " and "));
    }
    return bindElement;
}

From source file:org.apache.axis.deployment.wsdd.WSDDDocument.java

/**
 * bind to a sub-element in a document.//  www.j ava2s .co  m
 * @param e (Element) XXX
 */
public WSDDDocument(Element e) throws WSDDException {
    doc = e.getOwnerDocument();
    if (ELEM_WSDD_UNDEPLOY.equals(e.getLocalName())) {
        undeployment = new WSDDUndeployment(e);
    } else {
        deployment = new WSDDDeployment(e);
    }
}

From source file:org.apache.axis.encoding.ser.BeanSerializer.java

/**
 * write a schema representation of the given Class field and append it to
 * the where Node, recurse on complex types
 * @param fieldName name of the field/* w  w  w . ja  v  a 2  s. c om*/
 * @param xmlType the schema type of the field
 * @param fieldType type of the field
 * @param isUnbounded causes maxOccurs="unbounded" if set
 * @param where location for the generated schema node
 * @param itemQName
 * @throws Exception
 */
protected void writeField(Types types, String fieldName, QName xmlType, Class fieldType, boolean isUnbounded,
        boolean isOmittable, Element where, boolean isAnonymous, QName itemQName) throws Exception {
    Element elem;
    String elementType = null;

    if (isAnonymous) {
        elem = types.createElementWithAnonymousType(fieldName, fieldType, isOmittable,
                where.getOwnerDocument());
    } else {
        if (!SchemaUtils.isSimpleSchemaType(xmlType) && Types.isArray(fieldType)) {
            xmlType = null;
        }

        if (itemQName != null && SchemaUtils.isSimpleSchemaType(xmlType) && Types.isArray(fieldType)) {
            xmlType = null;
        }

        QName typeQName = types.writeTypeAndSubTypeForPart(fieldType, xmlType);
        elementType = types.getQNameString(typeQName);

        if (elementType == null) {
            // If writeType returns null, then emit an anytype.
            QName anyQN = Constants.XSD_ANYTYPE;
            String prefix = types.getNamespaces().getCreatePrefix(anyQN.getNamespaceURI());
            elementType = prefix + ":" + anyQN.getLocalPart();
        }

        // isNillable default value depends on the field type
        boolean isNillable = Types.isNullable(fieldType);
        if (typeDesc != null) {
            FieldDesc field = typeDesc.getFieldByName(fieldName);
            if (field != null && field.isElement()) {
                isNillable = ((ElementDesc) field).isNillable();
            }
        }

        elem = types.createElement(fieldName, elementType, isNillable, isOmittable, where.getOwnerDocument());
    }

    if (isUnbounded) {
        elem.setAttribute("maxOccurs", "unbounded");
    }

    where.appendChild(elem);
}

From source file:org.apache.axis.encoding.ser.BeanSerializer.java

/**
 * write aa attribute element and append it to the 'where' Node
 * @param fieldName name of the field// w  w w . j  a  v  a 2s  . c  o  m
 * @param fieldType type of the field
 * @param where location for the generated schema node
 * @throws Exception
 */
protected void writeAttribute(Types types, String fieldName, Class fieldType, QName fieldXmlType, Element where)
        throws Exception {

    // Attribute must be a simple type.
    if (!types.isAcceptableAsAttribute(fieldType)) {
        throw new AxisFault(Messages.getMessage("AttrNotSimpleType00", fieldName, fieldType.getName()));
    }
    Element elem = types.createAttributeElement(fieldName, fieldType, fieldXmlType, false,
            where.getOwnerDocument());
    where.appendChild(elem);
}

From source file:org.apache.axis.handlers.MD5AttachHandler.java

public void invoke(MessageContext msgContext) throws AxisFault {
    log.debug("Enter: MD5AttachHandler::invoke");
    try {/*from  w w  w .j a v a  2s.co m*/
        // log.debug("IN MD5");        
        Message msg = msgContext.getRequestMessage();
        SOAPConstants soapConstants = msgContext.getSOAPConstants();
        org.apache.axis.message.SOAPEnvelope env = (org.apache.axis.message.SOAPEnvelope) msg.getSOAPEnvelope();
        org.apache.axis.message.SOAPBodyElement sbe = env.getFirstBody();//env.getBodyByName("ns1", "addedfile");
        org.w3c.dom.Element sbElement = sbe.getAsDOM();
        //get the first level accessor  ie parameter
        org.w3c.dom.Node n = sbElement.getFirstChild();

        for (; n != null && !(n instanceof org.w3c.dom.Element); n = n.getNextSibling())
            ;
        org.w3c.dom.Element paramElement = (org.w3c.dom.Element) n;
        //Get the href associated with the attachment.
        String href = paramElement.getAttribute(soapConstants.getAttrHref());
        org.apache.axis.Part ap = msg.getAttachmentsImpl().getAttachmentByReference(href);
        javax.activation.DataHandler dh = org.apache.axis.attachments.AttachmentUtils
                .getActivationDataHandler(ap);
        org.w3c.dom.Node timeNode = paramElement.getFirstChild();
        long startTime = -1;

        if (timeNode != null && timeNode instanceof org.w3c.dom.Text) {
            String startTimeStr = ((org.w3c.dom.Text) timeNode).getData();

            startTime = Long.parseLong(startTimeStr);
        }
        // log.debug("GOTIT");

        long receivedTime = System.currentTimeMillis();
        long elapsedTime = -1;

        // log.debug("startTime=" + startTime);
        // log.debug("receivedTime=" + receivedTime);            
        if (startTime > 0)
            elapsedTime = receivedTime - startTime;
        String elapsedTimeStr = elapsedTime + "";
        // log.debug("elapsedTimeStr=" + elapsedTimeStr);            

        java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
        java.io.InputStream attachmentStream = dh.getInputStream();
        int bread = 0;
        byte[] buf = new byte[64 * 1024];

        do {
            bread = attachmentStream.read(buf);
            if (bread > 0) {
                md.update(buf, 0, bread);
            }
        } while (bread > -1);
        attachmentStream.close();
        buf = null;
        //Add the mime type to the digest.
        String contentType = dh.getContentType();

        if (contentType != null && contentType.length() != 0) {
            md.update(contentType.getBytes("US-ASCII"));
        }

        sbe = env.getFirstBody();
        sbElement = sbe.getAsDOM();
        //get the first level accessor  ie parameter
        n = sbElement.getFirstChild();
        for (; n != null && !(n instanceof org.w3c.dom.Element); n = n.getNextSibling())
            ;
        paramElement = (org.w3c.dom.Element) n;
        // paramElement.setAttribute(soapConstants.getAttrHref(), respHref);
        String MD5String = org.apache.axis.encoding.Base64.encode(md.digest());
        String senddata = " elapsedTime=" + elapsedTimeStr + " MD5=" + MD5String;

        // log.debug("senddata=" + senddata);            
        paramElement.appendChild(paramElement.getOwnerDocument().createTextNode(senddata));

        sbe = new org.apache.axis.message.SOAPBodyElement(sbElement);
        env.clearBody();
        env.addBodyElement(sbe);
        msg = new Message(env);

        msgContext.setResponseMessage(msg);
    } catch (Exception e) {
        log.error(Messages.getMessage("exception00"), e);
        throw AxisFault.makeFault(e);
    }

    log.debug("Exit: MD5AttachHandler::invoke");
}

From source file:org.apache.axis2.description.WSDL11ToAxisServiceBuilder.java

private void addElementToAnExistingSchema(Element schemaElement, Element newElement, Map namespacePrefixMap,
        Map namespaceImportsMap, String targetNamespace) {

    Document ownerDocument = schemaElement.getOwnerDocument();

    String newElementName = newElement.getAttribute(XSD_NAME);

    // check whether this element already exists.
    NodeList nodeList = schemaElement.getChildNodes();
    Element nodeElement = null;/*from   ww w.  j  a v  a2 s  .c  o m*/
    for (int i = 1; i < nodeList.getLength(); i++) {
        if (nodeList.item(i) instanceof Element) {
            nodeElement = (Element) nodeList.item(i);
            if (nodeElement.getLocalName().equals(XML_SCHEMA_ELEMENT_LOCAL_NAME)) {
                if (nodeElement.getAttribute(XSD_NAME).equals(newElementName)) {
                    // if the element already exists we do not add this element
                    // and just return.
                    return;
                }
            }
        }

    }

    // loop through the namespace declarations first and add them
    String[] nameSpaceDeclarationArray = (String[]) namespacePrefixMap.keySet()
            .toArray(new String[namespacePrefixMap.size()]);
    for (int i = 0; i < nameSpaceDeclarationArray.length; i++) {
        String s = nameSpaceDeclarationArray[i];
        checkAndAddNamespaceDeclarations(s, namespacePrefixMap, schemaElement);
    }

    // add imports - check whether it is the targetnamespace before
    // adding
    Element[] namespaceImports = (Element[]) namespaceImportsMap.values()
            .toArray(new Element[namespaceImportsMap.size()]);
    for (int i = 0; i < namespaceImports.length; i++) {
        if (!targetNamespace.equals(namespaceImports[i].getAttribute(NAMESPACE_URI))) {
            schemaElement.appendChild(ownerDocument.importNode(namespaceImports[i], true));
        }
    }

    schemaElement.appendChild(ownerDocument.importNode(newElement, true));

}