Example usage for javax.xml.namespace QName equals

List of usage examples for javax.xml.namespace QName equals

Introduction

In this page you can find the example usage for javax.xml.namespace QName equals.

Prototype

public final boolean equals(Object objectToTest) 

Source Link

Document

Test this QName for equality with another Object.

If the Object to be tested is not a QName or is null, then this method returns false.

Two QNames are considered equal if and only if both the Namespace URI and local part are equal.

Usage

From source file:org.apache.padaf.xmpbox.parser.XMPDocumentBuilder.java

/**
 * analyze one property in the stream, retrieve its type according to the
 * schema information and call its object representation building
 * //  w ww.j  av a  2  s  . co  m
 * @param schema
 *            The schema where find information
 * @param metadata
 *            Metadata to attach new elements
 * @throws XmpParsingException
 *             When element expected not found
 * @throws XMPUnexpectedTypeException
 *             When DOM Element type found unexpected
 * @throws XMLStreamException
 *             When error during reading the rest of xmp stream
 * @throws XmpUnknownPropertyTypeException
 *             Value Type property is incorrect or the basic value type
 *             can't be treat at the moment
 * @throws XmpPropertyFormatException
 *             Unexpected type found (IllegalArgumentException)
 */
protected void parseProperty(XMPSchema schema, XMPMetadata metadata)
        throws XmpParsingException, XmpPropertyFormatException, XmpUnexpectedTypeException, XMLStreamException,
        XmpUnknownPropertyTypeException {
    QName propertyName = reader.get().getName();
    nsMap.resetComplexBasicTypesDeclarationInPropertyLevel();
    int cptNs = reader.get().getNamespaceCount();
    for (int i = 0; i < cptNs; i++) {
        if (nsMap.isComplexBasicTypes(reader.get().getNamespaceURI(i))) {
            nsMap.setComplexBasicTypesDeclarationForLevelSchema(reader.get().getNamespaceURI(i),
                    reader.get().getNamespacePrefix(i));
        }
    }
    String type = getPropertyDeclarationInNamespaces(schema, propertyName);
    if (type.equals("Unmanaged")) {
        // do not parse the property, no validation, no reserialization
        boolean cont = true;
        while (cont) {
            int t = reader.get().next();
            if (t == XMLStreamReader.END_ELEMENT) {
                if (propertyName.equals(reader.get().getName())) {
                    cont = false;
                }
            }
        }
    } else if (type.equals("Text")) {
        parseXmpSimpleProperty(metadata, propertyName, XmpPropertyType.Text, schema.getContent());

    } else if (type.equals("Integer")) {
        parseXmpSimpleProperty(metadata, propertyName, XmpPropertyType.Integer, schema.getContent());

    } else if (type.equals("Boolean")) {
        parseXmpSimpleProperty(metadata, propertyName, XmpPropertyType.Boolean, schema.getContent());

    } else if (type.equals("Real")) {
        parseXmpSimpleProperty(metadata, propertyName, XmpPropertyType.Real, schema.getContent());
    } else if (type.equals("Date")) {
        parseXmpSimpleProperty(metadata, propertyName, XmpPropertyType.Date, schema.getContent());

    } else if (type.equals("URI")) {
        parseXmpSimpleProperty(metadata, propertyName, XmpPropertyType.Text, schema.getContent());

    } else if (type.equals("URL")) {
        parseXmpSimpleProperty(metadata, propertyName, XmpPropertyType.Text, schema.getContent());

    } else if (type.equals("bag Text")) {
        parseBagProperty(metadata, propertyName, XmpPropertyType.Text, schema.getContent());
    } else if (type.equals("bag ProperName")) {
        parseBagProperty(metadata, propertyName, XmpPropertyType.Text, schema.getContent());
    } else if (type.equals("bag Job")) {
        parseComplexBagProperty(metadata, propertyName, new JobParser(this), schema.getContent());
    } else if (type.equals("bag Xpath")) {
        parseBagProperty(metadata, propertyName, XmpPropertyType.Text, schema.getContent());
    } else if (type.equals("seq Text")) {
        parseSeqProperty(metadata, propertyName, XmpPropertyType.Text, schema.getContent());
    } else if (type.equals("seq Date")) {
        parseSeqProperty(metadata, propertyName, XmpPropertyType.Date, schema.getContent());
    } else if (type.equals("Lang Alt")) {
        parseAltProperty(metadata, propertyName, XmpPropertyType.Text, schema.getContent());
    } else if (type.equals("Field")) {
        parseFieldProperty(metadata, propertyName, schema);
    } else if (type.equals("Thumbnail")) {
        parseThumbnailProperty(metadata, propertyName, schema.getContent());
    } else if (type.equals("Alt Thumbnail")) {
        parseAltThumbnailProperty(metadata, propertyName, schema.getContent());
    } else {
        throw new XmpUnknownPropertyTypeException("Unknown type : " + type);
    }

}

From source file:org.apache.pluto.driver.services.container.EventProviderImpl.java

private boolean isEventSupported(List<? extends EventDefinitionReference> supportedEvents, QName eventName,
        String defaultNamespace) {
    if (supportedEvents != null) {
        for (EventDefinitionReference ref : supportedEvents) {
            QName refQName = ref.getQualifiedName(defaultNamespace);
            if (refQName != null && refQName.equals(eventName)) {
                return true;
            }/* w  ww  .ja  v  a2  s . com*/
        }
    }
    return false;
}

From source file:org.apache.pluto.driver.services.container.EventProviderImpl.java

private List<QName> getAllAliases(QName eventName, PortletApplicationDefinition portletAppDD) {
    if (portletAppDD.getEventDefinitions() != null) {

        for (EventDefinition def : portletAppDD.getEventDefinitions()) {
            QName defQName = def.getQualifiedName(portletAppDD.getDefaultNamespace());
            if (defQName != null && defQName.equals(eventName)) {
                return def.getAliases();
            }//from  www  .  j  av  a  2s .com
        }
    }
    return null;
}

From source file:org.apache.pluto.driver.services.container.EventProviderImpl.java

private boolean isDeclaredAsPublishingEvent(QName qname) {
    ServletContext servletContext = PortalRequestContext.getContext(request).getServletContext();
    String applicationId = PortletWindowConfig.parseContextPath(portletWindow.getId().getStringId());
    String applicationName = applicationId;
    if (applicationId.length() > 0) {
        applicationName = applicationId.substring(1);
    }//  w w  w .  ja  v  a2 s .c o m

    String portletName = PortletWindowConfig.parsePortletName(portletWindow.getId().getStringId());
    if (portletRegistry == null) {
        portletRegistry = ((PortletContainer) servletContext.getAttribute(AttributeKeys.PORTLET_CONTAINER))
                .getOptionalContainerServices().getPortletRegistryService();
    }
    List<? extends EventDefinitionReference> events = null;
    try {
        events = portletRegistry.getPortlet(applicationName, portletName).getSupportedPublishingEvents();
    } catch (PortletContainerException e1) {
        e1.printStackTrace();
    }
    if (events != null) {
        String defaultNamespace = portletWindow.getPortletEntity().getPortletDefinition().getApplication()
                .getDefaultNamespace();
        for (EventDefinitionReference ref : events) {
            QName name = ref.getQualifiedName(defaultNamespace);
            if (name == null) {
                continue;
            }
            if (qname.equals(name)) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.apache.pluto.driver.services.container.EventProviderImpl.java

private boolean isValueInstanceOfDefinedClass(QName qname, Serializable value) {
    PortletApplicationDefinition app = portletWindow.getPortletEntity().getPortletDefinition().getApplication();
    List<? extends EventDefinition> events = app.getEventDefinitions();
    if (events != null) {

        for (EventDefinition def : events) {
            if (def.getQName() != null) {
                if (def.getQName().equals(qname))
                    return value.getClass().getName().equals(def.getValueType());
            } else {
                QName tmp = new QName(app.getDefaultNamespace(), def.getName());
                if (tmp.equals(qname))
                    return value.getClass().getName().equals(def.getValueType());
            }//from  w  ww. j a  v  a  2  s  . co m
        }
    }
    // event not declared
    return true;
}

From source file:org.apache.pluto.driver.services.container.PortletWindowThread.java

private EventDefinition getEventDefintion(QName name) throws PortletContainerException {
    PortletApplicationDefinition appDD = portletWindow.getPortletEntity().getPortletDefinition()
            .getApplication();/*from   w  ww.  j  a  va2  s  . c om*/
    for (EventDefinition def : appDD.getEventDefinitions()) {
        if (def.getQName() != null) {
            if (def.getQName().equals(name))
                return def;
        } else {
            QName tmp = new QName(appDD.getDefaultNamespace(), def.getName());
            if (tmp.equals(name))
                return def;
        }
    }
    throw new IllegalStateException();
}

From source file:org.apache.rahas.impl.util.SAML2Utils.java

public static SAML2KeyInfo getSAML2KeyInfo(Assertion assertion, Crypto crypto, CallbackHandler cb)
        throws WSSecurityException {

    //First ask the cb whether it can provide the secret
    WSPasswordCallback pwcb = new WSPasswordCallback(assertion.getID(), WSPasswordCallback.CUSTOM_TOKEN);
    if (cb != null) {
        try {/*from  w  w  w  .j a  va2  s . com*/
            cb.handle(new Callback[] { pwcb });
        } catch (Exception e1) {
            throw new WSSecurityException(WSSecurityException.FAILURE, "noKey",
                    new Object[] { assertion.getID() }, e1);
        }
    }

    byte[] key = pwcb.getKey();

    if (key != null) {
        return new SAML2KeyInfo(assertion, key);
    } else {
        // if the cb fails to provide the secret.
        try {
            // extract the subject
            Subject samlSubject = assertion.getSubject();
            if (samlSubject == null) {
                throw new WSSecurityException(WSSecurityException.FAILURE, "invalidSAML2Token",
                        new Object[] { "for Signature (no Subject)" });
            }

            // extract the subject confirmation element from the subject
            SubjectConfirmation subjectConf = (SubjectConfirmation) samlSubject.getSubjectConfirmations()
                    .get(0);
            if (subjectConf == null) {
                throw new WSSecurityException(WSSecurityException.FAILURE, "invalidSAML2Token",
                        new Object[] { "for Signature (no Subject Confirmation)" });
            }

            // Get the subject confirmation data, KeyInfoConfirmationDataType extends SubjectConfirmationData.
            SubjectConfirmationData scData = subjectConf.getSubjectConfirmationData();

            if (scData == null) {
                throw new WSSecurityException(WSSecurityException.FAILURE, "invalidSAML2Token",
                        new Object[] { "for Signature (no Subject Confirmation Data)" });
            }

            // Get the SAML specific XML representation of the keyInfo object
            XMLObject KIElem = null;
            List<XMLObject> scDataElements = scData.getOrderedChildren();
            Iterator<XMLObject> iterator = scDataElements.iterator();
            while (iterator.hasNext()) {
                XMLObject xmlObj = iterator.next();
                if (xmlObj instanceof org.opensaml.xml.signature.KeyInfo) {
                    KIElem = xmlObj;
                    break;
                }
            }

            Element keyInfoElement;

            // Generate a DOM element from the XMLObject.
            if (KIElem != null) {

                // Set the "javax.xml.parsers.DocumentBuilderFactory" system property to make sure the endorsed JAXP
                // implementation is picked over the default jaxp impl shipped with the JDK.
                String jaxpProperty = System.getProperty("javax.xml.parsers.DocumentBuilderFactory");
                System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
                        "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");

                MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory();
                Marshaller marshaller = marshallerFactory.getMarshaller(KIElem);
                keyInfoElement = marshaller.marshall(KIElem);

                // Reset the sys. property to its previous value.
                if (jaxpProperty == null) {
                    System.getProperties().remove("javax.xml.parsers.DocumentBuilderFactory");
                } else {
                    System.setProperty("javax.xml.parsers.DocumentBuilderFactory", jaxpProperty);
                }

            } else {
                throw new WSSecurityException(WSSecurityException.FAILURE, "invalidSAML2Token",
                        new Object[] { "for Signature (no key info element)" });
            }

            AttributeStatement attrStmt = assertion.getAttributeStatements().size() != 0
                    ? (AttributeStatement) assertion.getAttributeStatements().get(0)
                    : null;
            AuthnStatement authnStmt = assertion.getAuthnStatements().size() != 0
                    ? (AuthnStatement) assertion.getAuthnStatements().get(0)
                    : null;

            // if an attr stmt is present, then it has a symmetric key.
            if (attrStmt != null) {
                NodeList children = keyInfoElement.getChildNodes();
                int len = children.getLength();

                for (int i = 0; i < len; i++) {
                    Node child = children.item(i);
                    if (child.getNodeType() != Node.ELEMENT_NODE) {
                        continue;
                    }
                    QName el = new QName(child.getNamespaceURI(), child.getLocalName());
                    if (el.equals(WSSecurityEngine.ENCRYPTED_KEY)) {

                        EncryptedKeyProcessor proc = new EncryptedKeyProcessor();
                        proc.handleEncryptedKey((Element) child, cb, crypto, null);

                        return new SAML2KeyInfo(assertion, proc.getDecryptedBytes());
                    } else if (el.equals(new QName(WSConstants.WST_NS, "BinarySecret"))) {
                        Text txt = (Text) child.getFirstChild();
                        return new SAML2KeyInfo(assertion, Base64.decode(txt.getData()));
                    } else if (el.equals(new QName(WSConstants.SIG_NS, "X509Data"))) {
                        X509Certificate[] certs = null;
                        try {
                            KeyInfo ki = new KeyInfo(keyInfoElement, null);

                            if (ki.containsX509Data()) {
                                X509Data data = ki.itemX509Data(0);
                                XMLX509Certificate certElem = null;
                                if (data != null && data.containsCertificate()) {
                                    certElem = data.itemCertificate(0);
                                }
                                if (certElem != null) {
                                    X509Certificate cert = certElem.getX509Certificate();
                                    certs = new X509Certificate[1];
                                    certs[0] = cert;
                                    return new SAML2KeyInfo(assertion, certs);
                                }
                            }

                        } catch (XMLSecurityException e3) {
                            throw new WSSecurityException(WSSecurityException.FAILURE, "invalidSAMLsecurity",
                                    new Object[] { "cannot get certificate (key holder)" }, e3);
                        }

                    }
                }

            }

            // If an authn stmt is present then it has a public key.
            if (authnStmt != null) {

                X509Certificate[] certs = null;
                try {
                    KeyInfo ki = new KeyInfo(keyInfoElement, null);

                    if (ki.containsX509Data()) {
                        X509Data data = ki.itemX509Data(0);
                        XMLX509Certificate certElem = null;
                        if (data != null && data.containsCertificate()) {
                            certElem = data.itemCertificate(0);
                        }
                        if (certElem != null) {
                            X509Certificate cert = certElem.getX509Certificate();
                            certs = new X509Certificate[1];
                            certs[0] = cert;
                            return new SAML2KeyInfo(assertion, certs);
                        }
                    }

                } catch (XMLSecurityException e3) {
                    throw new WSSecurityException(WSSecurityException.FAILURE, "invalidSAMLsecurity",
                            new Object[] { "cannot get certificate (key holder)" }, e3);
                }

            }

            throw new WSSecurityException(WSSecurityException.FAILURE, "invalidSAMLsecurity",
                    new Object[] { "cannot get certificate or key " });

        } catch (MarshallingException e) {
            throw new WSSecurityException(WSSecurityException.FAILURE, "Failed marshalling the SAML Assertion",
                    null, e);
        }
    }
}

From source file:org.apache.rampart.PolicyBasedResultsValidator.java

private boolean isRefIdPresent(ArrayList refList, QName qname) {

    for (int i = 0; i < refList.size(); i++) {
        WSDataRef dataRef = (WSDataRef) refList.get(i);

        // ArrayList can contain null elements
        if (dataRef == null) {
            continue;
        }//from w  ww .  j  a v  a  2  s.c om
        // QName of the decrypted element
        QName dataRefQName = dataRef.getName();

        if (dataRefQName != null && dataRefQName.equals(qname)) {
            return true;
        }

    }

    return false;

}

From source file:org.apache.synapse.commons.throttle.core.ThrottleFactory.java

/**
 * Factory method to create a throttle from a given throttle policy
 *
 * @param policy    Throttle policy/*from  w w  w . jav a 2  s. c  om*/
 * @param forceRoot Root assertion QName for select correct policy assertion
 * @return Throttle instance
 * @throws ThrottleException
 */
private static Throttle createThrottle(Policy policy, QName forceRoot) throws ThrottleException {

    if (policy == null) {
        if (log.isDebugEnabled()) {
            log.debug("Policy cannot be found");
        }
        //if policy is not available ,then return null for ThrottleConfiguration
        return null; // no policy is available in the module description
    }

    if (forceRoot == null) {
        if (log.isDebugEnabled()) {
            log.debug("Given root assertion QName is null");
        }
        return null;
    }

    for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
        Object object = iterator.next();
        if (object instanceof List) {
            List list = (List) object;
            for (Iterator it = list.iterator(); it.hasNext();) {
                Object assertObj = it.next();
                if (assertObj instanceof XmlPrimtiveAssertion) {
                    XmlPrimtiveAssertion primitiveAssertion = (XmlPrimtiveAssertion) assertObj;
                    QName qName = primitiveAssertion.getName();

                    if (qName == null) {
                        handleException(
                                "Invalid Throttle Policy - QName of the " + "assertion cannot be null.");
                    }
                    // top policy must contains ThrottleAssertion
                    Policy throttlePolicy = PolicyEngine.getPolicy(primitiveAssertion.getValue());
                    if (ThrottleConstants.THROTTLE_ASSERTION_QNAME.equals(qName)) {
                        return ThrottlePolicyProcessor.processPolicy(throttlePolicy);
                    } else if (forceRoot.equals(qName)) {
                        return buildThrottle(throttlePolicy);
                    } else {
                        if (log.isDebugEnabled()) {
                            log.debug("There is no throttle policy " + "for given QName : " + forceRoot);
                        }
                    }
                }
            }
        }
    }
    return null;

}

From source file:org.apache.synapse.task.TaskDescriptionFactory.java

public static TaskDescription createTaskDescription(OMElement el, OMNamespace tagetNamespace) {

    if (log.isDebugEnabled()) {
        log.debug("Creating SimpleQuartz Task");
    }/*from ww  w.j  av  a  2 s  . com*/
    QName task = createQName(TASK, tagetNamespace);
    if (task.equals(el.getQName())) {

        TaskDescription taskDescription = new TaskDescription();

        String name = el.getAttributeValue(new QName(NULL_NAMESPACE, "name"));
        if (name != null) {
            taskDescription.setName(name);
        } else {
            handleException("Name for a task is required, missing name in the task");
        }

        String group = el.getAttributeValue(new QName(NULL_NAMESPACE, "group"));
        if (group != null) {
            taskDescription.setTaskGroup(group);
        }

        // set the task class
        OMAttribute classAttr = el.getAttribute(new QName("class"));
        if (classAttr != null && classAttr.getAttributeValue() != null) {
            String classname = classAttr.getAttributeValue();
            try {
                Class.forName(classname).newInstance();
            } catch (Exception e) {
                handleException("Failed to load task class " + classname, e);
            }
            taskDescription.setTaskImplClassName(classname);
        } else {
            log.warn("TaskClass cannot be found."
                    + "Task implementation may need a task class if there is no default one");
        }

        OMElement descElem = el.getFirstChildWithName(createQName(DESCRIPTION, tagetNamespace));
        if (descElem != null) {
            taskDescription.setTaskDescription(descElem.getText());
        }

        // set pinned server list
        OMAttribute pinnedServers = el.getAttribute(new QName(NULL_NAMESPACE, "pinnedServers"));
        if (pinnedServers != null) {
            String pinnedServersValue = pinnedServers.getAttributeValue();
            if (pinnedServersValue == null) {
                // default to all servers
            } else {
                StringTokenizer st = new StringTokenizer(pinnedServersValue, " ,");
                List<String> pinnedServersList = new ArrayList<String>();
                while (st.hasMoreTokens()) {
                    String token = st.nextToken();
                    if (token.length() != 0) {
                        pinnedServersList.add(token);
                    }
                }
                taskDescription.setPinnedServers(pinnedServersList);
            }
        }

        // next sort out the property children

        Iterator it = el.getChildrenWithName(createQName(PROPERTY, tagetNamespace));
        while (it.hasNext()) {
            OMElement prop = (OMElement) it.next();
            if (PropertyHelper.isStaticProperty(prop)) {
                taskDescription.setXmlProperty(prop);
            } else {
                handleException("Tasks does not support dynamic properties");
            }
        }

        // setting the trigger to the task
        OMElement trigger = el.getFirstChildWithName(createQName(TRIGGER, tagetNamespace));
        if (trigger != null) {

            OMAttribute count = trigger.getAttribute(new QName("count"));
            if (count != null) {
                try {
                    taskDescription.setCount(Integer.parseInt(count.getAttributeValue()));
                } catch (Exception e) {
                    handleException("Failed to parse trigger count as an integer", e);
                }
            }

            OMAttribute once = trigger.getAttribute(new QName("once"));
            if (once != null && Boolean.TRUE.toString().equals(once.getAttributeValue())) {
                taskDescription.setCount(1);
                taskDescription.setInterval(1);
                taskDescription.setIntervalInMs(false);
            }

            OMAttribute repeatInterval = trigger.getAttribute(new QName("interval"));
            if (repeatInterval == null && taskDescription.getCount() > 1) {
                handleException("Trigger seems to be " + "a simple trigger, but no interval specified");
            } else if (repeatInterval != null && repeatInterval.getAttributeValue() != null) {
                try {
                    long repeatIntervalInSeconds = Long.parseLong(repeatInterval.getAttributeValue());
                    long repeatIntervalInMillis = repeatIntervalInSeconds * 1000;
                    taskDescription.setInterval(repeatIntervalInMillis);
                    taskDescription.setIntervalInMs(true);
                } catch (Exception e) {
                    handleException("Failed to parse trigger interval as a long value", e);
                }
            }

            OMAttribute expr = trigger.getAttribute(new QName("cron"));
            if (expr == null && taskDescription.getInterval() == 0) {
                taskDescription.setCount(1);
                taskDescription.setInterval(1);
                taskDescription.setIntervalInMs(false);
            } else if (expr != null && taskDescription.getInterval() > 0) {
                handleException(
                        "Trigger syntax error : " + "both cron and simple trigger attributes are present");
            } else if (expr != null && expr.getAttributeValue() != null) {
                taskDescription.setCronExpression(expr.getAttributeValue());
            }

        } else {
            taskDescription.setCount(1);
            taskDescription.setInterval(1);
            taskDescription.setIntervalInMs(false);
        }

        return taskDescription;
    } else {
        handleException("Syntax error in the task : wrong QName for the task");
        return null;
    }
}