Example usage for org.w3c.dom Element getLocalName

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

Introduction

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

Prototype

public String getLocalName();

Source Link

Document

Returns the local part of the qualified name of this node.

Usage

From source file:com.ubikod.capptain.android.sdk.reach.CapptainReachInteractiveContent.java

CapptainReachInteractiveContent(String jid, String rawXml, Element root) throws JSONException {
    super(jid, rawXml, root);
    mTitle = XmlUtil.getTagText(root, "title", root.getLocalName());
    mActionLabel = XmlUtil.getTagText(root, "label", "action");
    mExitLabel = XmlUtil.getTagText(root, "label", "exit");

    /* Behavior */
    mBehavior = Behavior.ANYTIME;//from  w  w  w .  j  a v  a  2  s .  co  m
    Element behavior = XmlUtil.getTag(root, "behavior", null);
    if (behavior != null)
        if (XmlUtil.getTag(behavior, "session", null) != null)
            mBehavior = Behavior.SESSION;
        else {
            mAllowedActivities = new HashSet<String>();
            NodeList activities = behavior.getElementsByTagNameNS(REACH_NAMESPACE, "activity");
            if (activities.getLength() > 0) {
                mBehavior = Behavior.ACTIVITY;
                for (int i = 0; i < activities.getLength(); i++)
                    mAllowedActivities.add(XmlUtil.getText(activities.item(i)));
            }
        }

    /* Notification */
    Element notification = XmlUtil.getTag(root, "notification", null);
    if (notification != null) {
        /* By default, system, unless "activity" is specified */
        mSystemNotification = !"activity".equals(notification.getAttribute("type"));

        /* The notification can be closed unless closeable is set to a non "true" value */
        mNotiticationCloseable = XmlUtil.getBooleanAttribute(notification, "closeable", true);

        /* The notification has a content icon unless icon attribute set to a non "true" value. */
        mNotificationIcon = XmlUtil.getBooleanAttribute(notification, "icon", true);

        /* Sound and vibration */
        mNotificationSound = XmlUtil.getBooleanAttribute(notification, "sound", false);
        mNotificationVibrate = XmlUtil.getBooleanAttribute(notification, "vibrate", false);

        /* Parse texts */
        mNotificationTitle = XmlUtil.getTagText(notification, "title", null);
        mNotificationMessage = XmlUtil.getTagText(notification, "message", null);

        /* Get image data, we decode the bitmap in a lazy way */
        mNotificationImageString = XmlUtil.getTagText(notification, "image", null);

        /* Options */
        String options = XmlUtil.getTagText(notification, "options", null);
        if (options != null) {
            JSONObject jOptions = new JSONObject(options);
            mNotificationBigText = jOptions.optString("bigText", null);
            mNotificationBigPicture = jOptions.optString("bigPicture", null);
        }
    }
}

From source file:de.betterform.agent.web.flux.FluxProcessor.java

/**
 * listen to processor with XMLEvents and add a xmlEvent object to the
 * EventQueue for every incoming DOM Event from the processor.
 *
 * @param event the handled DOMEvent//w w w.j a va 2s  .c om
 */
public void handleEvent(Event event) {
    super.handleEvent(event);
    try {
        if (event instanceof XMLEvent) {
            XMLEvent xmlEvent = (XMLEvent) event;
            String type = xmlEvent.getType();

            if (BetterFormEventNames.REPLACE_ALL.equals(type)
                    || BetterFormEventNames.REPLACE_ALL_XFORMS.equals(type)) {
                // get event context and store it in session
                Map submissionResponse = new HashMap();
                submissionResponse.put("header", xmlEvent.getContextInfo("header"));
                submissionResponse.put("body", xmlEvent.getContextInfo("body"));
                this.xformsProcessor.setContextParam(WebFactory.BETTERFORM_SUBMISSION_RESPONSE,
                        submissionResponse);

                // add event properties to log
                xmlEvent.addProperty("webcontext", (String) getContextParam("contextroot"));
                this.eventQueue.add(xmlEvent);

                this.exitEvent = xmlEvent;
                shutdown();
                return;
            } else if (BetterFormEventNames.LOAD_URI.equals(type)) {
                // get event properties
                String show = (String) xmlEvent.getContextInfo("show");
                if ("embed".equals(show)) {
                    Element targetElement = (Element) xmlEvent.getContextInfo("targetElement");
                    StringWriter result = new StringWriter();
                    generateUI(targetElement, result);
                    xmlEvent.addProperty("targetElement", result.toString());
                    /*
                                            if(LOGGER.isDebugEnabled()) {
                    DOMUtil.prettyPrintDOM(targetElement);
                    LOGGER.debug("xf:load show=\"embed\" Markup: \n" + result.toString() +"\n");
                                            }
                                            DOMUtil.prettyPrintDOM(targetElement);
                                            System.out.println("xf:load show=\"embed\" Markup: \n" + result.toString() +"\n");
                    */
                }

                // add event to log
                this.eventQueue.add(xmlEvent);
                if ("replace".equals(show)) {
                    this.exitEvent = xmlEvent;
                    shutdown();
                    //this.xformsSession.getManager().deleteXFormsSession(this.xformsSession.getKey());
                    WebUtil.removeSession(getKey());
                }

                return;
            } else if (BetterFormEventNames.STATE_CHANGED.equals(type)) {
                /*
                todo: This is a HACK cause BETTERFORM_STATE_CHANGED events are not sent consistently. For some reason
                todo: datatype changes are not always signalled e.g. when the datatype changes from a 'date' to
                todo: a 'string'. This should be fixed in betterForm Core - after that this branch should be removed again.
                 */

                // get event properties
                Element target = (Element) event.getTarget();
                String targetId = target.getAttributeNS(null, "id");
                String targetName = target.getLocalName();
                String dataType = (String) xmlEvent.getContextInfo("type");
                if (dataType == null) {
                    XFormsElement control = lookup(targetId);

                    //todo: this is copied from EventLog code - this is really a HACK!
                    if (EventQueue.HELPER_ELEMENTS.contains(targetName)) {
                        String parentId = ((Element) target.getParentNode()).getAttributeNS(null, "id");
                        xmlEvent.addProperty("parentId", parentId);
                    } else if (control instanceof BindingElement) {
                        if (LOGGER.isDebugEnabled()) {
                            DOMUtil.prettyPrintDOM(control.getElement());
                        }

                        Element bfData = DOMUtil.getChildElement(control.getElement(),
                                NamespaceConstants.BETTERFORM_PREFIX + ":data");
                        if (bfData != null) {
                            String internalType = bfData.getAttributeNS(NamespaceConstants.BETTERFORM_NS,
                                    "type");
                            xmlEvent.addProperty("type", internalType);
                        }
                    }
                }
                this.eventQueue.add(xmlEvent);
                return;
            } else if (XFormsEventNames.VERSION_EXCEPTION.equals(type)) {
                WebUtil.removeSession(getKey());
                xmlEvent.addProperty("errorinformation", xmlEvent.getContextInfo().get("error-information"));
            }
            this.eventQueue.add(xmlEvent);
        }
    } catch (Exception e) {
        handleEventException(e);
    }
}

From source file:be.agiv.security.client.IPSTSClient.java

private SecurityToken getSecurityToken(String username, String password, X509Certificate certificate,
        PrivateKey privateKey) {//from  w  ww  .ja v  a  2 s  .  com
    RequestSecurityTokenType requestSecurityToken = this.objectFactory.createRequestSecurityTokenType();
    List<Object> requestSecurityTokenContent = requestSecurityToken.getAny();
    requestSecurityTokenContent.add(this.objectFactory.createRequestType(WSConstants.ISSUE_REQUEST_TYPE));

    EntropyType entropy = this.objectFactory.createEntropyType();
    requestSecurityTokenContent.add(this.objectFactory.createEntropy(entropy));
    BinarySecretType binarySecret = this.objectFactory.createBinarySecretType();
    entropy.getAny().add(this.objectFactory.createBinarySecret(binarySecret));
    binarySecret.setType(WSConstants.SECRET_TYPE_NONCE);

    requestSecurityTokenContent.add(this.objectFactory.createKeyType(WSConstants.KEY_TYPE_SYMMETRIC));

    requestSecurityTokenContent.add(this.objectFactory.createKeySize(256L));

    if (null == this.wsTrustHandler.getSecondaryParameters()) {
        requestSecurityTokenContent
                .add(this.objectFactory.createKeyWrapAlgorithm(WSConstants.KEY_WRAP_ALGO_RSA_OAEP_MGF1P));

        requestSecurityTokenContent.add(this.objectFactory.createEncryptWith(WSConstants.ENC_ALGO_AES256_CBC));

        requestSecurityTokenContent.add(this.objectFactory.createSignWith(WSConstants.SIGN_ALGO_HMAC_SHA1));

        requestSecurityTokenContent
                .add(this.objectFactory.createCanonicalizationAlgorithm(WSConstants.C14N_ALGO_EXC));

        requestSecurityTokenContent
                .add(this.objectFactory.createEncryptionAlgorithm(WSConstants.ENC_ALGO_AES256_CBC));
    }

    AppliesTo appliesTo = this.policyObjectFactory.createAppliesTo();
    EndpointReferenceType endpointReference = this.addrObjectFactory.createEndpointReferenceType();
    AttributedURIType address = this.addrObjectFactory.createAttributedURIType();
    address.setValue(this.realm);
    endpointReference.setAddress(address);
    appliesTo.getAny().add(this.addrObjectFactory.createEndpointReference(endpointReference));
    requestSecurityTokenContent.add(appliesTo);

    requestSecurityTokenContent
            .add(this.objectFactory.createComputedKeyAlgorithm(WSConstants.COMP_KEY_ALGO_PSHA1));

    byte[] entropyData = new byte[256 / 8];
    // entropy = keysize / 8
    this.secureRandom.setSeed(System.currentTimeMillis());
    this.secureRandom.nextBytes(entropyData);
    binarySecret.setValue(entropyData);

    BindingProvider bindingProvider = (BindingProvider) this.port;
    if (null != username) {
        this.wsSecurityHandler.setCredentials(username, password);
    } else if (null != certificate) {
        this.wsSecurityHandler.setCredentials(privateKey, certificate);
    }
    this.wsAddressingHandler.setAddressing(WSConstants.WS_TRUST_ISSUE_ACTION, this.location);

    RequestSecurityTokenResponseCollectionType requestSecurityTokenResponseCollection = this.port
            .requestSecurityToken(requestSecurityToken);

    SecurityToken securityToken = new SecurityToken();

    List<RequestSecurityTokenResponseType> requestSecurityTokenResponseList = requestSecurityTokenResponseCollection
            .getRequestSecurityTokenResponse();
    RequestSecurityTokenResponseType requestSecurityTokenResponse = requestSecurityTokenResponseList.get(0);
    List<Object> requestSecurityTokenResponseContent = requestSecurityTokenResponse.getAny();
    for (Object contentObject : requestSecurityTokenResponseContent) {
        LOG.debug("content object: " + contentObject.getClass().getName());
        if (contentObject instanceof Element) {
            Element contentElement = (Element) contentObject;
            LOG.debug("element name: " + contentElement.getLocalName());
        }
        if (contentObject instanceof JAXBElement) {
            JAXBElement jaxbElement = (JAXBElement) contentObject;
            QName qname = jaxbElement.getName();
            LOG.debug("qname: " + qname);
            if (WSConstants.ENTROPY_QNAME.equals(qname)) {
                LOG.debug("trust:Entropy");
                EntropyType serverEntropy = (EntropyType) jaxbElement.getValue();
                List<Object> entropyContent = serverEntropy.getAny();
                for (Object entropyObject : entropyContent) {
                    if (entropyObject instanceof JAXBElement) {
                        JAXBElement entropyElement = (JAXBElement) entropyObject;
                        if (WSConstants.BINARY_SECRET_QNAME.equals(entropyElement.getName())) {
                            BinarySecretType serverBinarySecret = (BinarySecretType) entropyElement.getValue();
                            byte[] serverSecret = serverBinarySecret.getValue();
                            P_SHA1 p_SHA1 = new P_SHA1();
                            byte[] key;
                            try {
                                key = p_SHA1.createKey(entropyData, serverSecret, 0, 256 / 8);
                            } catch (ConversationException e) {
                                LOG.error(e);
                                return null;
                            }
                            LOG.debug("client secret size: " + entropyData.length);
                            LOG.debug("server secret size: " + serverSecret.length);
                            LOG.debug("key size: " + key.length);
                            securityToken.setKey(key);
                        }
                    }
                }
            } else if (WSConstants.LIFETIME_QNAME.equals(qname)) {
                LOG.debug("trust:Lifetime");
                LifetimeType lifetime = (LifetimeType) jaxbElement.getValue();
                String createdValue = lifetime.getCreated().getValue();
                DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTimeParser();
                DateTime created = dateTimeFormatter.parseDateTime(createdValue);
                securityToken.setCreated(created.toDate());
                String expiresString = lifetime.getExpires().getValue();
                DateTime expires = dateTimeFormatter.parseDateTime(expiresString);
                securityToken.setExpires(expires.toDate());
            } else if (WSConstants.REQUESTED_ATTACHED_REFERENCE_QNAME.equals(qname)) {
                RequestedReferenceType requestedReference = (RequestedReferenceType) jaxbElement.getValue();
                SecurityTokenReferenceType securityTokenReference = requestedReference
                        .getSecurityTokenReference();
                List<Object> securityTokenReferenceContent = securityTokenReference.getAny();
                for (Object securityTokenReferenceObject : securityTokenReferenceContent) {
                    LOG.debug("SecurityTokenReference object: "
                            + securityTokenReferenceObject.getClass().getName());
                    if (securityTokenReferenceObject instanceof JAXBElement) {
                        JAXBElement securityTokenReferenceElement = (JAXBElement) securityTokenReferenceObject;
                        LOG.debug("SecurityTokenReference element: " + securityTokenReferenceElement.getName());
                        if (securityTokenReferenceElement.getName().equals(WSConstants.KEY_IDENTIFIER_QNAME)) {
                            KeyIdentifierType keyIdentifier = (KeyIdentifierType) securityTokenReferenceElement
                                    .getValue();
                            String attachedReference = keyIdentifier.getValue();
                            securityToken.setAttachedReference(attachedReference);
                        }

                    }
                }
            } else if (WSConstants.REQUESTED_UNATTACHED_REFERENCE_QNAME.equals(qname)) {
                RequestedReferenceType requestedReference = (RequestedReferenceType) jaxbElement.getValue();
                SecurityTokenReferenceType securityTokenReference = requestedReference
                        .getSecurityTokenReference();
                List<Object> securityTokenReferenceContent = securityTokenReference.getAny();
                for (Object securityTokenReferenceObject : securityTokenReferenceContent) {
                    LOG.debug("SecurityTokenReference object: "
                            + securityTokenReferenceObject.getClass().getName());
                    if (securityTokenReferenceObject instanceof JAXBElement) {
                        JAXBElement securityTokenReferenceElement = (JAXBElement) securityTokenReferenceObject;
                        LOG.debug("SecurityTokenReference element: " + securityTokenReferenceElement.getName());
                        if (securityTokenReferenceElement.getName().equals(WSConstants.KEY_IDENTIFIER_QNAME)) {
                            KeyIdentifierType keyIdentifier = (KeyIdentifierType) securityTokenReferenceElement
                                    .getValue();
                            String unattachedReference = keyIdentifier.getValue();
                            securityToken.setUnattachedReference(unattachedReference);
                        }

                    }
                }
            }
        }
    }

    Element requestedSecurityToken = this.wsTrustHandler.getRequestedSecurityToken();
    securityToken.setToken(requestedSecurityToken);
    securityToken.setRealm(this.realm);
    securityToken.setStsLocation(this.location);

    return securityToken;
}

From source file:be.fedict.eid.dss.ws.DigitalSignatureServicePortImpl.java

@Override
public SignResponse sign(SignRequest signRequest) {

    LOG.debug("sign");

    // parse request
    String requestId = signRequest.getRequestID();
    LOG.debug("request Id: " + requestId);

    // verify profile
    String profile = signRequest.getProfile();
    LOG.debug("signRequest.profile: " + profile);
    if (!profile.equals(DSSConstants.ARTIFACT_NAMESPACE)) {
        return DSSUtil.createRequestorSignErrorResponse(requestId, DSSConstants.RESULT_MINOR_NOT_SUPPORTED,
                "Profile not supported.");
    }/*  ww w .java  2 s  .  com*/

    // parse OptionalInput's
    boolean returnStorageInfo = false;
    String documentId = null;

    AnyType optionalInputs = signRequest.getOptionalInputs();
    if (null == optionalInputs) {
        return DSSUtil.createRequestorSignErrorResponse(requestId, DSSConstants.RESULT_MINOR_NOT_SUPPORTED,
                "Expecting Artifact Binding OptionalInputs...");
    }
    for (Object optionalInputObject : optionalInputs.getAny()) {

        if (optionalInputObject instanceof Element) {

            Element element = (Element) optionalInputObject;

            if (DSSConstants.ARTIFACT_NAMESPACE.equals(element.getNamespaceURI())
                    && DSSConstants.RETURN_STORAGE_INFO.equals(element.getLocalName())) {

                returnStorageInfo = true;

            } else if (DSSConstants.ARTIFACT_NAMESPACE.equals(element.getNamespaceURI())
                    && DSSConstants.RETURN_STORED_DOCUMENT.equals(element.getLocalName())) {

                try {
                    ReturnStoredDocument returnStoredDocument = DSSUtil.getReturnStoredDocument(element);
                    documentId = returnStoredDocument.getIdentifier();
                } catch (JAXBException e) {

                    return DSSUtil.createRequestorSignErrorResponse(requestId,
                            DSSConstants.RESULT_MINOR_NOT_SUPPORTED,
                            "Failed to unmarshall \"ReturnStoredDocument\"" + " element.");
                }

            } else {

                return DSSUtil.createRequestorSignErrorResponse(requestId,
                        DSSConstants.RESULT_MINOR_NOT_SUPPORTED,
                        "Unexpected OptionalInput: \"" + element.getLocalName() + "\"");

            }
        }
    }

    if (!returnStorageInfo && null == documentId || returnStorageInfo && null != documentId) {

        return DSSUtil.createRequestorSignErrorResponse(requestId, DSSConstants.RESULT_MINOR_NOT_SUPPORTED,
                "Missing Artifact Binding OptionalInputs...");
    }

    if (returnStorageInfo) {

        return storageInfoResponse(signRequest);
    } else {

        return storedDocumentResponse(signRequest, documentId);
    }
}

From source file:be.fedict.eid.dss.ws.DigitalSignatureServicePortImpl.java

@Override
public ResponseBaseType verify(VerifyRequest verifyRequest) {

    LOG.debug("verify");

    /*//from w w  w .j  a v  a  2s  .c  om
     * Parse the request.
     */
    String requestId = verifyRequest.getRequestID();
    LOG.debug("request Id: " + requestId);
    List<DocumentDO> documents = getDocuments(verifyRequest.getInputDocuments());

    if (documents.isEmpty()) {
        return DSSUtil.createRequestorErrorResponse(requestId, null, "No valid document found to validate.");
    }
    if (documents.size() != 1) {
        return DSSUtil.createRequestorErrorResponse(requestId, null, "Can validate only one document.");
    }
    byte[] data = documents.get(0).getDocumentData();
    String mimeType = documents.get(0).getContentType();

    byte[] originalData = null;
    boolean returnVerificationReport = false;
    AnyType optionalInput = verifyRequest.getOptionalInputs();
    if (null != optionalInput) {
        List<Object> anyObjects = optionalInput.getAny();
        for (Object anyObject : anyObjects) {
            if (anyObject instanceof Element) {
                Element element = (Element) anyObject;
                if (DSSConstants.VR_NAMESPACE.equals(element.getNamespaceURI())
                        && "ReturnVerificationReport".equals(element.getLocalName())) {
                    /*
                     * We could check for supported ReturnVerificationReport
                     * input, but then again, who cares?
                     */
                    returnVerificationReport = true;
                }
                if (DSSConstants.ORIGINAL_DOCUMENT_NAMESPACE.equals(element.getNamespaceURI())
                        && DSSConstants.ORIGINAL_DOCUMENT_ELEMENT.equals(element.getLocalName())) {
                    try {
                        originalData = DSSUtil.getOriginalDocument(element);
                    } catch (JAXBException e) {
                        return DSSUtil.createRequestorErrorResponse(requestId,
                                DSSConstants.RESULT_MINOR_NOT_PARSEABLE_XML_DOCUMENT);
                    }
                }
            }
        }
    }

    /*
     * Invoke the underlying DSS verification service.
     */
    List<SignatureInfo> signatureInfos;
    try {
        signatureInfos = this.signatureVerificationService.verify(data, mimeType, originalData);
    } catch (DocumentFormatException e) {
        return DSSUtil.createRequestorErrorResponse(requestId,
                DSSConstants.RESULT_MINOR_NOT_PARSEABLE_XML_DOCUMENT);
    } catch (InvalidSignatureException e) {
        return DSSUtil.createRequestorErrorResponse(requestId);
    }

    /*
     * Construct the DSS response.
     */
    ObjectFactory dssObjectFactory = new ObjectFactory();

    ResponseBaseType responseBase = dssObjectFactory.createResponseBaseType();
    responseBase.setRequestID(requestId);
    Result result = dssObjectFactory.createResult();
    result.setResultMajor(DSSConstants.RESULT_MAJOR_SUCCESS);
    AnyType optionalOutput = dssObjectFactory.createAnyType();
    if (signatureInfos.size() > 1) {
        result.setResultMinor(DSSConstants.RESULT_MINOR_VALID_MULTI_SIGNATURES);
    } else if (1 == signatureInfos.size()) {
        result.setResultMinor(DSSConstants.RESULT_MINOR_VALID_SIGNATURE);
    } else {
        result.setResultMinor(DSSConstants.RESULT_MINOR_INVALID_SIGNATURE);
    }

    if (returnVerificationReport) {
        DSSUtil.addVerificationReport(optionalOutput, signatureInfos);
    }

    if (!optionalOutput.getAny().isEmpty()) {
        responseBase.setOptionalOutputs(optionalOutput);
    }

    responseBase.setResult(result);
    return responseBase;
}

From source file:org.solmix.runtime.support.spring.AbstractBeanDefinitionParser.java

protected void firstChildAsProperty(Element element, ParserContext ctx, BeanDefinitionBuilder bean,
        String propertyName) {/*from w  w w .ja  va2s  .com*/
    Element first = getFirstChild(element);
    if (first == null) {
        throw new IllegalStateException(propertyName + " property must have child elements!");
    }
    String id;
    BeanDefinition child;
    if (first.getNamespaceURI().equals(BeanDefinitionParserDelegate.BEANS_NAMESPACE_URI)) {
        String name = first.getLocalName();
        if ("ref".equals(name)) {
            id = first.getAttribute("bean");
            if (id == null) {
                throw new IllegalStateException("<ref> elements must have a \"bean\" attribute!");
            }
            bean.addPropertyReference(propertyName, id);
            return;
        } else if ("bean".equals(name)) {
            BeanDefinitionHolder bdh = ctx.getDelegate().parseBeanDefinitionElement(first);
            child = bdh.getBeanDefinition();
            bean.addPropertyValue(propertyName, child);
            return;
        } else {
            throw new UnsupportedOperationException("Elements with the name " + name + " are not currently "
                    + "supported as sub elements of " + element.getLocalName());
        }
    }
    child = ctx.getDelegate().parseCustomElement(first, bean.getBeanDefinition());
    bean.addPropertyValue(propertyName, child);
}

From source file:org.smf4j.spring.RegistryNodeTemplateDefinitionParser.java

protected String parseNode(ParserContext context, Element element, BeanDefinitionBuilder builder) {
    String name = element.getAttribute(NAME_ATTR);
    if (!StringUtils.hasLength(name)) {
        context.getReaderContext().error("'node' elements must have a 'name' attribute.", element);
    }//from  ww  w. j  a  va  2 s.co m

    // Process all child node tags
    ManagedList<RuntimeBeanReference> childProxyIds = new ManagedList<RuntimeBeanReference>();

    NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node childNode = childNodes.item(i);
        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        Element child = (Element) childNode;
        String childTagName = child.getLocalName();
        String childProxyId = null;

        // Parse the child node
        if (NODE_TAG.equals(childTagName)) {
            BeanDefinitionBuilder bdb = getBdb(RegistryNodeProxy.class);
            childProxyId = parseNode(context, child, bdb);
        } else if (NODE_TEMPLATE_TAG.equals(childTagName)) {
            childProxyId = createNodeTemplateRef(context, child);
        } else if (COUNTER_TAG.equals(childTagName)) {
            CounterConfig config = new CounterConfig(CounterType.ADD, child);
            childProxyId = createCounter(context, child, config);
        } else if (MIN_TAG.equals(childTagName)) {
            CounterConfig config = new CounterConfig(CounterType.MIN, child);
            childProxyId = createCounter(context, child, config);
        } else if (MAX_TAG.equals(childTagName)) {
            CounterConfig config = new CounterConfig(CounterType.MAX, child);
            childProxyId = createCounter(context, child, config);
        } else if (CUSTOM_TAG.equals(childTagName)) {
            childProxyId = parseCustom(context, child, builder.getRawBeanDefinition());
        } else if (NORMALIZE_TAG.equals(childTagName)) {
            childProxyId = createNormalize(context, child);
        } else if (RATIO_TAG.equals(childTagName)) {
            childProxyId = createRatio(context, child);
        } else if (RANGEGROUP_TAG.equals(childTagName)) {
            childProxyId = createRangeGroup(context, child);
        } else {
            context.getReaderContext().error("Unknown tag", child);
        }

        if (childProxyId != null) {
            childProxyIds.add(new RuntimeBeanReference(childProxyId));
        }
    }

    // Finish building the node proxy
    builder.addPropertyValue(NAME_ATTR, name);
    builder.addPropertyValue(CHILDREN_ATTR, childProxyIds);
    String nodeId = context.getReaderContext().registerWithGeneratedName(builder.getBeanDefinition());

    return nodeId;
}

From source file:org.drools.container.spring.namespace.KnowledgeSessionDefinitionParser.java

@SuppressWarnings("unchecked")
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {

    String id = element.getAttribute("id");
    emptyAttributeCheck(element.getLocalName(), "id", id);

    String kbase = element.getAttribute(KBASE_ATTRIBUTE);
    emptyAttributeCheck(element.getLocalName(), KBASE_ATTRIBUTE, kbase);

    String sessionType = element.getAttribute(TYPE_ATTRIBUTE);
    BeanDefinitionBuilder factory;/*  ww  w.j av  a2 s .  c om*/

    if ("stateful".equals(sessionType)) {
        factory = BeanDefinitionBuilder.rootBeanDefinition(StatefulKnowledgeSessionBeanFactory.class);
    } else if ("stateless".equals(sessionType)) {
        factory = BeanDefinitionBuilder.rootBeanDefinition(StatelessKnowledgeSessionBeanFactory.class);
    } else {
        throw new IllegalArgumentException(
                "Invalid value for " + TYPE_ATTRIBUTE + " attribute: " + sessionType);
    }

    factory.addPropertyReference("kbase", kbase);

    String node = element.getAttribute(GRID_NODE_ATTRIBUTE);
    if (node != null && node.length() > 0) {
        factory.addPropertyReference("node", node);
    }

    String name = element.getAttribute(NAME_ATTRIBUTE);
    if (StringUtils.hasText(name)) {
        factory.addPropertyValue("name", name);
    } else {
        factory.addPropertyValue("name", id);
    }

    // Additions for JIRA JBRULES-3076
    String listeners = element.getAttribute(LISTENERS_ATTRIBUTE);
    if (StringUtils.hasText(listeners)) {
        factory.addPropertyValue("eventListenersFromGroup", new RuntimeBeanReference(listeners));
    }
    EventListenersUtil.parseEventListeners(parserContext, factory, element);
    // End of Additions for JIRA JBRULES-3076

    Element ksessionConf = DomUtils.getChildElementByTagName(element, "configuration");
    if (ksessionConf != null) {
        Element persistenceElm = DomUtils.getChildElementByTagName(ksessionConf, "jpa-persistence");
        if (persistenceElm != null) {
            BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder
                    .genericBeanDefinition(JpaConfiguration.class);

            String loadId = persistenceElm.getAttribute("load");
            if (StringUtils.hasText(loadId)) {
                beanBuilder.addPropertyValue("id", Long.parseLong(loadId));
            }

            Element tnxMng = DomUtils.getChildElementByTagName(persistenceElm, TX_MANAGER_ATTRIBUTE);
            String ref = tnxMng.getAttribute("ref");

            beanBuilder.addPropertyReference("platformTransactionManager", ref);

            Element emf = DomUtils.getChildElementByTagName(persistenceElm, EMF_ATTRIBUTE);
            ref = emf.getAttribute("ref");
            beanBuilder.addPropertyReference("entityManagerFactory", ref);

            Element variablePersisters = DomUtils.getChildElementByTagName(persistenceElm,
                    "variable-persisters");
            if (variablePersisters != null && variablePersisters.hasChildNodes()) {
                List<Element> childPersisterElems = DomUtils.getChildElementsByTagName(variablePersisters,
                        "persister");
                ManagedMap persistors = new ManagedMap(childPersisterElems.size());
                for (Element persisterElem : childPersisterElems) {
                    String forClass = persisterElem.getAttribute(FORCLASS_ATTRIBUTE);
                    String implementation = persisterElem.getAttribute(IMPLEMENTATION_ATTRIBUTE);
                    if (!StringUtils.hasText(forClass)) {
                        throw new RuntimeException("persister element must have valid for-class attribute");
                    }
                    if (!StringUtils.hasText(implementation)) {
                        throw new RuntimeException(
                                "persister element must have valid implementation attribute");
                    }
                    persistors.put(forClass, implementation);
                }
                beanBuilder.addPropertyValue("variablePersisters", persistors);
            }

            factory.addPropertyValue("jpaConfiguration", beanBuilder.getBeanDefinition());
        }
        BeanDefinitionBuilder rbaseConfBuilder = BeanDefinitionBuilder
                .rootBeanDefinition(SessionConfiguration.class);
        Element e = DomUtils.getChildElementByTagName(ksessionConf, KEEP_REFERENCE);
        if (e != null && StringUtils.hasText(e.getAttribute("enabled"))) {
            rbaseConfBuilder.addPropertyValue("keepReference", Boolean.parseBoolean(e.getAttribute("enabled")));
        }

        e = DomUtils.getChildElementByTagName(ksessionConf, CLOCK_TYPE);
        if (e != null && StringUtils.hasText(e.getAttribute("type"))) {
            rbaseConfBuilder.addPropertyValue("clockType", ClockType.resolveClockType(e.getAttribute("type")));
        }
        factory.addPropertyValue("conf", rbaseConfBuilder.getBeanDefinition());

        e = DomUtils.getChildElementByTagName(ksessionConf, WORK_ITEMS);
        if (e != null) {
            List<Element> children = DomUtils.getChildElementsByTagName(e, WORK_ITEM);
            if (children != null && !children.isEmpty()) {
                ManagedMap workDefs = new ManagedMap();
                for (Element child : children) {
                    workDefs.put(child.getAttribute("name"),
                            new RuntimeBeanReference(child.getAttribute("ref")));
                }
                factory.addPropertyValue("workItems", workDefs);
            }
        }
    }

    Element batch = DomUtils.getChildElementByTagName(element, "batch");
    if (batch == null) {
        // just temporary legacy suppport
        batch = DomUtils.getChildElementByTagName(element, "script");
    }
    if (batch != null) {
        // we know there can only ever be one
        ManagedList children = new ManagedList();

        for (int i = 0, length = batch.getChildNodes().getLength(); i < length; i++) {
            Node n = batch.getChildNodes().item(i);
            if (n instanceof Element) {
                Element e = (Element) n;

                BeanDefinitionBuilder beanBuilder = null;
                if ("insert-object".equals(e.getLocalName())) {
                    String ref = e.getAttribute("ref");
                    Element nestedElm = getFirstElement(e.getChildNodes());
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(InsertObjectCommand.class);
                    if (StringUtils.hasText(ref)) {
                        beanBuilder.addConstructorArgReference(ref);
                    } else if (nestedElm != null) {
                        beanBuilder.addConstructorArgValue(
                                parserContext.getDelegate().parsePropertySubElement(nestedElm, null, null));
                    } else {
                        throw new IllegalArgumentException(
                                "insert-object must either specify a 'ref' attribute or have a nested bean");
                    }
                } else if ("set-global".equals(e.getLocalName())) {
                    String ref = e.getAttribute("ref");
                    Element nestedElm = getFirstElement(e.getChildNodes());
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(SetGlobalCommand.class);
                    beanBuilder.addConstructorArgValue(e.getAttribute("identifier"));
                    if (StringUtils.hasText(ref)) {
                        beanBuilder.addConstructorArgReference(ref);
                    } else if (nestedElm != null) {
                        beanBuilder.addConstructorArgValue(
                                parserContext.getDelegate().parsePropertySubElement(nestedElm, null, null));
                    } else {
                        throw new IllegalArgumentException(
                                "set-global must either specify a 'ref' attribute or have a nested bean");
                    }
                } else if ("fire-until-halt".equals(e.getLocalName())) {
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(FireUntilHaltCommand.class);
                } else if ("fire-all-rules".equals(e.getLocalName())) {
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(FireAllRulesCommand.class);
                    String max = e.getAttribute("max");
                    if (StringUtils.hasText(max)) {
                        beanBuilder.addPropertyValue("max", max);
                    }
                } else if ("start-process".equals(e.getLocalName())) {

                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(StartProcessCommand.class);
                    String processId = e.getAttribute("process-id");
                    if (!StringUtils.hasText(processId)) {
                        throw new IllegalArgumentException("start-process must specify a process-id");
                    }
                    beanBuilder.addConstructorArgValue(processId);

                    List<Element> params = DomUtils.getChildElementsByTagName(e, "parameter");
                    if (!params.isEmpty()) {
                        ManagedMap map = new ManagedMap();
                        for (Element param : params) {
                            String identifier = param.getAttribute("identifier");
                            if (!StringUtils.hasText(identifier)) {
                                throw new IllegalArgumentException(
                                        "start-process paramaters must specify an identifier");
                            }

                            String ref = param.getAttribute("ref");
                            Element nestedElm = getFirstElement(param.getChildNodes());
                            if (StringUtils.hasText(ref)) {
                                map.put(identifier, new RuntimeBeanReference(ref));
                            } else if (nestedElm != null) {
                                map.put(identifier, parserContext.getDelegate()
                                        .parsePropertySubElement(nestedElm, null, null));
                            } else {
                                throw new IllegalArgumentException(
                                        "start-process parameters must either specify a 'ref' attribute or have a nested bean");
                            }
                        }
                        beanBuilder.addPropertyValue("parameters", map);
                    }
                } else if ("signal-event".equals(e.getLocalName())) {
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(SignalEventCommand.class);
                    String processInstanceId = e.getAttribute("process-instance-id");
                    if (StringUtils.hasText(processInstanceId)) {
                        beanBuilder.addConstructorArgValue(processInstanceId);
                    }

                    beanBuilder.addConstructorArgValue(e.getAttribute("event-type"));

                    String ref = e.getAttribute("ref");
                    Element nestedElm = getFirstElement(e.getChildNodes());
                    if (StringUtils.hasText(ref)) {
                        beanBuilder.addConstructorArgReference(ref);
                    } else if (nestedElm != null) {
                        beanBuilder.addConstructorArgValue(
                                parserContext.getDelegate().parsePropertySubElement(nestedElm, null, null));
                    } else {
                        throw new IllegalArgumentException(
                                "signal-event must either specify a 'ref' attribute or have a nested bean");
                    }
                }
                if (beanBuilder == null) {
                    throw new IllegalStateException("Unknow element: " + e.getLocalName());
                }
                children.add(beanBuilder.getBeanDefinition());
            }
        }
        factory.addPropertyValue("batch", children);
    }

    // find any kagent's for the current kbase and assign (only if this 
    // is a stateless session)
    if (sessionType.equals("stateless")) {
        for (String beanName : parserContext.getRegistry().getBeanDefinitionNames()) {
            BeanDefinition def = parserContext.getRegistry().getBeanDefinition(beanName);
            if (KnowledgeAgentBeanFactory.class.getName().equals(def.getBeanClassName())) {
                PropertyValue pvalue = def.getPropertyValues().getPropertyValue("kbase");
                RuntimeBeanReference tbf = (RuntimeBeanReference) pvalue.getValue();
                if (kbase.equals(tbf.getBeanName())) {
                    factory.addPropertyValue("knowledgeAgent", new RuntimeBeanReference(beanName));
                }
            }
        }
    }

    return factory.getBeanDefinition();
}

From source file:eu.europa.esig.dss.tsl.service.TSLParser.java

private void fillPointerTerritoryAndMimeType(OtherTSLPointerType otherTSLPointerType, TSLPointer pointer) {
    List<Serializable> textualInformationOrOtherInformation = otherTSLPointerType.getAdditionalInformation()
            .getTextualInformationOrOtherInformation();
    if (CollectionUtils.isNotEmpty(textualInformationOrOtherInformation)) {
        Map<String, String> properties = new HashMap<String, String>();
        for (Serializable serializable : textualInformationOrOtherInformation) {
            if (serializable instanceof AnyType) {
                AnyType anyInfo = (AnyType) serializable;
                for (Object content : anyInfo.getContent()) {
                    if (content instanceof JAXBElement) {
                        @SuppressWarnings("rawtypes")
                        JAXBElement jaxbElement = (JAXBElement) content;
                        properties.put(jaxbElement.getName().toString(), jaxbElement.getValue().toString());
                    } else if (content instanceof Element) {
                        Element element = (Element) content;
                        properties.put("{" + element.getNamespaceURI() + "}" + element.getLocalName(),
                                element.getTextContent());
                    }//from w w  w . j av a  2 s  .  c o  m
                }
            }
        }
        pointer.setMimeType(properties.get("{http://uri.etsi.org/02231/v2/additionaltypes#}MimeType"));
        pointer.setTerritory(properties.get("{http://uri.etsi.org/02231/v2#}SchemeTerritory"));
    }
}

From source file:de.betterform.xml.xforms.action.LoadAction.java

private void destroyembeddedModels(Element targetElem) throws XFormsException {
    NodeList childNodes = targetElem.getChildNodes();

    for (int index = 0; index < childNodes.getLength(); index++) {
        Node node = childNodes.item(index);

        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element elementImpl = (Element) node;

            String name = elementImpl.getLocalName();
            String uri = elementImpl.getNamespaceURI();

            if (NamespaceConstants.XFORMS_NS.equals(uri) && name.equals(XFormsConstants.MODEL)) {
                Model model = (Model) elementImpl.getUserData("");
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("dispatch 'model-destruct' event to embedded model: " + model.getId());
                    ;// w  w w. j  av a  2 s . co  m
                }
                String modelId = model.getId();
                // do not dispatch model-destruct to avoid problems in lifecycle
                // TODO: review: this.container.dispatch(model.getTarget(), XFormsEventNames.MODEL_DESTRUCT, null);
                model.dispose();
                this.container.removeModel(model);
                model = null;
                if (Config.getInstance().getProperty("betterform.debug-allowed").equals("true")) {
                    Map contextInfo = new HashMap(1);
                    contextInfo.put("modelId", modelId);
                    this.container.dispatch(this.target, BetterFormEventNames.MODEL_REMOVED, contextInfo);
                }

            } else {
                destroyembeddedModels(elementImpl);
            }
        }
    }
}