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:com.evolveum.midpoint.util.QNameUtil.java

public static boolean match(QName a, QName b, boolean caseInsensitive) {
    if (a == null && b == null) {
        return true;
    }/*from  w  w w .  j a  v  a  2  s . com*/
    if (a == null || b == null) {
        return false;
    }
    if (!caseInsensitive) {
        // traditional comparison
        if (StringUtils.isBlank(a.getNamespaceURI()) || StringUtils.isBlank(b.getNamespaceURI())) {
            return a.getLocalPart().equals(b.getLocalPart());
        } else {
            return a.equals(b);
        }
    } else {
        // relaxed (case-insensitive) one
        if (!a.getLocalPart().equalsIgnoreCase(b.getLocalPart())) {
            return false;
        }
        if (StringUtils.isBlank(a.getNamespaceURI()) || StringUtils.isBlank(b.getNamespaceURI())) {
            return true;
        } else {
            return a.getNamespaceURI().equals(b.getNamespaceURI());
        }
    }

}

From source file:com.evolveum.midpoint.test.util.TestUtil.java

public static void assertElement(List<Object> elements, QName elementQName, String value) {
    for (Object element : elements) {
        QName thisElementQName = JAXBUtil.getElementQName(element);
        if (elementQName.equals(thisElementQName)) {
            if (element instanceof Element) {
                String thisElementContent = ((Element) element).getTextContent();
                if (value.equals(thisElementContent)) {
                    return;
                } else {
                    AssertJUnit.fail("Wrong value for element with name " + elementQName + "; expected " + value
                            + "; was " + thisElementContent);
                }/*from  w w  w .  j a  v a 2 s  . c  o m*/
            } else {
                throw new IllegalArgumentException(
                        "Unexpected type of element " + elementQName + ": " + element.getClass());
            }
        }
    }
    AssertJUnit.fail("No element with name " + elementQName);
}

From source file:com.xqdev.jam.MLJAM.java

private static void sendXQueryResponse(HttpServletResponse res, Object o) throws IOException {
    // Make sure to leave the status code alone.  It defaults to 200, but sometimes
    // callers of this method will have set it to a custom code.
    res.setContentType("x-marklogic/xquery; charset=UTF-8");
    //res.setContentType("text/plain");
    Writer writer = res.getWriter(); // care to handle errors later?

    if (o == null) {
        writer.write("()");
    }//from  w w w .j av a  2s  .  c  om

    else if (o instanceof byte[]) {
        writer.write("binary {'");
        writer.write(hexEncode((byte[]) o));
        writer.write("'}");
    }

    else if (o instanceof Object[]) {
        Object[] arr = (Object[]) o;
        writer.write("(");
        for (int i = 0; i < arr.length; i++) {
            sendXQueryResponse(res, arr[i]);
            if (i + 1 < arr.length)
                writer.write(", ");
        }
        writer.write(")");
    }

    else if (o instanceof String) {
        writer.write("'");
        writer.write(escapeSingleQuotes(o.toString()));
        writer.write("'");
    } else if (o instanceof Integer) {
        writer.write("xs:int(");
        writer.write(o.toString());
        writer.write(")");
    } else if (o instanceof Long) {
        writer.write("xs:integer(");
        writer.write(o.toString());
        writer.write(")");
    } else if (o instanceof Float) {
        Float flt = (Float) o;
        writer.write("xs:float(");
        if (flt.equals(Float.POSITIVE_INFINITY)) {
            writer.write("'INF'");
        } else if (flt.equals(Float.NEGATIVE_INFINITY)) {
            writer.write("'-INF'");
        } else if (flt.equals(Float.NaN)) {
            writer.write("fn:number(())"); // poor man's way to write NaN
        } else {
            writer.write(o.toString());
        }
        writer.write(")");
    } else if (o instanceof Double) {
        Double dbl = (Double) o;
        writer.write("xs:double(");
        if (dbl.equals(Double.POSITIVE_INFINITY)) {
            writer.write("'INF'");
        } else if (dbl.equals(Double.NEGATIVE_INFINITY)) {
            writer.write("'-INF'");
        } else if (dbl.equals(Double.NaN)) {
            writer.write("fn:number(())"); // poor man's way to write NaN
        } else {
            writer.write(o.toString());
        }
        writer.write(")");
    } else if (o instanceof Boolean) {
        writer.write("xs:boolean('");
        writer.write(o.toString());
        writer.write("')");
    } else if (o instanceof BigDecimal) {
        writer.write("xs:decimal(");
        writer.write(o.toString());
        writer.write(")");
    } else if (o instanceof Date) {
        // We want something like: 2006-04-30T01:28:30.499-07:00
        // We format to get:       2006-04-30T01:28:30.499-0700
        // Then we add in the colon
        writer.write("xs:dateTime('");
        String d = dateFormat.format((Date) o);
        writer.write(d.substring(0, d.length() - 2));
        writer.write(":");
        writer.write(d.substring(d.length() - 2));
        writer.write("')");
    } else if (o instanceof XMLGregorianCalendar) {
        XMLGregorianCalendar greg = (XMLGregorianCalendar) o;
        QName type = greg.getXMLSchemaType();
        if (type.equals(DatatypeConstants.DATETIME)) {
            writer.write("xs:dateTime('");
        } else if (type.equals(DatatypeConstants.DATE)) {
            writer.write("xs:date('");
        } else if (type.equals(DatatypeConstants.TIME)) {
            writer.write("xs:time('");
        } else if (type.equals(DatatypeConstants.GYEARMONTH)) {
            writer.write("xs:gYearMonth('");
        } else if (type.equals(DatatypeConstants.GMONTHDAY)) {
            writer.write("xs:gMonthDay('");
        } else if (type.equals(DatatypeConstants.GYEAR)) {
            writer.write("xs:gYear('");
        } else if (type.equals(DatatypeConstants.GMONTH)) {
            writer.write("xs:gMonth('");
        } else if (type.equals(DatatypeConstants.GDAY)) {
            writer.write("xs:gDay('");
        }
        writer.write(greg.toXMLFormat());
        writer.write("')");
    } else if (o instanceof Duration) {
        Duration dur = (Duration) o;
        /*
        // The following fails on Xerces
        QName type = dur.getXMLSchemaType();
        if (type.equals(DatatypeConstants.DURATION)) {
          writer.write("xs:duration('");
        }
        else if (type.equals(DatatypeConstants.DURATION_DAYTIME)) {
          writer.write("xdt:dayTimeDuration('");
        }
        else if (type.equals(DatatypeConstants.DURATION_YEARMONTH)) {
          writer.write("xdt:yearMonthDuration('");
        }
        */
        // If no years or months, must be DURATION_DAYTIME
        if (dur.getYears() == 0 && dur.getMonths() == 0) {
            writer.write("xdt:dayTimeDuration('");
        }
        // If has years or months but nothing else, must be DURATION_YEARMONTH
        else if (dur.getDays() == 0 && dur.getHours() == 0 && dur.getMinutes() == 0 && dur.getSeconds() == 0) {
            writer.write("xdt:yearMonthDuration('");
        } else {
            writer.write("xs:duration('");
        }
        writer.write(dur.toString());
        writer.write("')");
    }

    else if (o instanceof org.jdom.Element) {
        org.jdom.Element elt = (org.jdom.Element) o;
        writer.write("xdmp:unquote('");
        // Because "&lt;" in XQuery is the same as "<" I need to double escape any ampersands
        writer.write(new org.jdom.output.XMLOutputter().outputString(elt).replaceAll("&", "&amp;")
                .replaceAll("'", "''"));
        writer.write("')/*"); // make sure to return the root elt
    } else if (o instanceof org.jdom.Document) {
        org.jdom.Document doc = (org.jdom.Document) o;
        writer.write("xdmp:unquote('");
        writer.write(new org.jdom.output.XMLOutputter().outputString(doc).replaceAll("&", "&amp;")
                .replaceAll("'", "''"));
        writer.write("')");
    } else if (o instanceof org.jdom.Text) {
        org.jdom.Text text = (org.jdom.Text) o;
        writer.write("text {'");
        writer.write(escapeSingleQuotes(text.getText()));
        writer.write("'}");
    } else if (o instanceof org.jdom.Attribute) {
        // <fake xmlns:pref="http://uri.com" pref:attrname="attrvalue"/>/@*:attrname
        // <fake xmlns="http://uri.com" attrname="attrvalue"/>/@*:attrname
        org.jdom.Attribute attr = (org.jdom.Attribute) o;
        writer.write("<fake xmlns");
        if ("".equals(attr.getNamespacePrefix())) {
            writer.write("=\"");
        } else {
            writer.write(":" + attr.getNamespacePrefix() + "=\"");
        }
        writer.write(attr.getNamespaceURI());
        writer.write("\" ");
        writer.write(attr.getQualifiedName());
        writer.write("=\"");
        writer.write(escapeSingleQuotes(attr.getValue()));
        writer.write("\"/>/@*:");
        writer.write(attr.getName());
    } else if (o instanceof org.jdom.Comment) {
        org.jdom.Comment com = (org.jdom.Comment) o;
        writer.write("comment {'");
        writer.write(escapeSingleQuotes(com.getText()));
        writer.write("'}");
    } else if (o instanceof org.jdom.ProcessingInstruction) {
        org.jdom.ProcessingInstruction pi = (org.jdom.ProcessingInstruction) o;
        writer.write("processing-instruction ");
        writer.write(pi.getTarget());
        writer.write(" {'");
        writer.write(escapeSingleQuotes(pi.getData()));
        writer.write("'}");
    }

    else if (o instanceof QName) {
        QName q = (QName) o;
        writer.write("fn:expanded-QName('");
        writer.write(escapeSingleQuotes(q.getNamespaceURI()));
        writer.write("','");
        writer.write(q.getLocalPart());
        writer.write("')");
    }

    else {
        writer.write("error('XQuery tried to retrieve unsupported type: " + o.getClass().getName() + "')");
    }

    writer.flush();
}

From source file:org.mule.modules.constantcontact.ConstantContactClient.java

public Feed populate(String response) {
    Document<? extends Element> doc = parser.parse(new StringReader(response));
    QName qName = doc.getRoot().getQName();
    if (qName.equals(Constants.ENTRY)) {
        FOMFeed feed = new FOMFeed();
        feed.addEntry((Entry) doc.getRoot());
        return feed;
    } else if (qName.equals(Constants.FEED)) {
        Feed feed = (Feed) doc.getRoot();
        if (feed.getLink("next") != null) {
            // TODO get more responses and merge them
            //             <link href="/ws/customers/joesflowers/contacts?next=23654&amp;updatedsince=2009-12-01T20%3A18%3A25.503Z&amp;
            //  listtype=active&amp;ous=2009-12-01T01%3A00%3A00.000Z" rel="next" />
            //  <link href="/ws/customers/joesflowers/contacts?updatedsince=2009-12-01T01%3A00%3A00.000Z&amp;listtype=active"
        }// www  .j  av a2 s .c o m
        return feed;
    } else {
        throw new UnsupportedOperationException("Cannot parse response of type: " + qName);
    }
}

From source file:com.evolveum.midpoint.prism.LiteralEqualsStrategy.java

@Override
protected boolean equalsInternal(ObjectLocator leftLocator, ObjectLocator rightLocator, Object lhs,
        Object rhs) {//from  ww w  . ja v a  2 s . com
    //      System.out.println("DomAwareEqualsStrategy: "+PrettyPrinter.prettyPrint(lhs)+"<=>"+PrettyPrinter.prettyPrint(rhs));
    if (lhs instanceof String && rhs instanceof String) {
        // this is questionable (but seems ok)
        return DOMUtil.compareTextNodeValues((String) lhs, (String) rhs);
    } else if (lhs instanceof Element && rhs instanceof Element) {
        // this is perhaps obsolete
        final Element left = (Element) lhs;
        final Element right = (Element) rhs;
        boolean result = DOMUtil.compareElement(left, right, true);
        //         System.out.println("cmp: "+PrettyPrinter.prettyPrint(left)+"<=>"+PrettyPrinter.prettyPrint(right)+": "+result);
        return result;
    } else if (lhs instanceof QName && rhs instanceof QName) {
        QName l = (QName) lhs;
        QName r = (QName) rhs;
        if (!l.equals(r)) {
            return false;
        }
        return StringUtils.equals(l.getPrefix(), r.getPrefix());
    } else if (lhs instanceof ItemPathType && rhs instanceof ItemPathType) {
        // ItemPathType's equals is already working literally
        return ((ItemPathType) lhs).equals((ItemPathType) rhs);
    } else {
        return super.equalsInternal(leftLocator, rightLocator, lhs, rhs);
    }
}

From source file:com.centeractive.ws.builder.soap.WsdlUtils.java

public static String[] getExentsibilityAttributes(AttributeExtensible item, QName qname) {
    if (item == null)
        return new String[0];

    StringList result = new StringList();

    Map map = item.getExtensionAttributes();

    for (Iterator<?> i = map.keySet().iterator(); i.hasNext();) {
        QName name = (QName) i.next();
        if (name.equals(qname)) {
            result.add(map.get(name).toString());
        }//  www.ja va 2 s . co  m
    }

    return result.toStringArray();
}

From source file:com.centeractive.ws.server.matcher.SoapOperationMatcher.java

/**
 * Last matching mechanism ->/*ww w. java 2s  . c  om*/
 * When a non ws-compliant document-literal service specifies wsdl:part using the type instead of the element tag
 * Resources:
 * http://stackoverflow.com/questions/1172118/what-is-the-difference-between-type-and-element-in-wsdl
 * http://www.xfront.com/ElementVersusType.html
 * http://www.xfront.com/GlobalVersusLocal.html !!!
 *
 * @param rootNodes root nodes of the request
 * @return operation matched
 */
private BindingOperation getOperationByInputTypes(final Set<Node> rootNodes) {
    AggregatingVisitor<BindingOperation> visitor = new AggregatingVisitor<BindingOperation>() {
        @Override
        public void visit(BindingOperation operation) {
            Collection<Part> expectedParts = operation.getOperation().getInput().getMessage().getParts()
                    .values();
            Set<QName> expectedTypes = new HashSet<QName>();
            for (Part part : expectedParts) {
                expectedTypes.add(part.getElementName());
            }
            Set<QName> receivedTypes = XmlUtils.getNodeTypes(rootNodes);
            if (expectedTypes.equals(receivedTypes)) {
                addResult(operation);
            } else if (expectedParts.isEmpty() && receivedTypes.size() == 1) {
                // check the case when pseudo input name was sent when no input was expected and got one element
                QName receivedType = receivedTypes.toArray(new QName[receivedTypes.size()])[0];
                String namespaceUri = operation.getOperation().getInput().getMessage().getQName()
                        .getNamespaceURI();
                String name = operation.getOperation().getName();
                QName pseudoInputName = new QName(namespaceUri, name);
                if (pseudoInputName.equals(receivedType)) {
                    addResult(operation);
                }
            }
        }
    };
    visitOperation(visitor);
    return visitor.getUniqueResult();
}

From source file:org.reficio.ws.server.matcher.SoapOperationMatcher.java

/**
 * Last matching mechanism ->/*  w w w.  java  2 s. c  o m*/
 * When a non ws-compliant document-literal service specifies wsdl:part using the type instead of the element tag
 * Resources:
 * http://stackoverflow.com/questions/1172118/what-is-the-difference-between-type-and-element-in-wsdl
 * http://www.xfront.com/ElementVersusType.html
 * http://www.xfront.com/GlobalVersusLocal.html !!!
 *
 * @param rootNodes root nodes of the request
 * @return operation matched
 */
@SuppressWarnings("unchecked")
private BindingOperation getOperationByInputTypes(final Set<Node> rootNodes) {
    AggregatingVisitor<BindingOperation> visitor = new AggregatingVisitor<BindingOperation>() {
        @Override
        public void visit(BindingOperation operation) {
            Collection<Part> expectedParts = operation.getOperation().getInput().getMessage().getParts()
                    .values();
            Set<QName> expectedTypes = new HashSet<QName>();
            for (Part part : expectedParts) {
                expectedTypes.add(part.getElementName());
            }
            Set<QName> receivedTypes = XmlUtils.getNodeTypes(rootNodes);
            if (expectedTypes.equals(receivedTypes)) {
                addResult(operation);
            } else if (expectedParts.isEmpty() && receivedTypes.size() == 1) {
                // check the case when pseudo input name was sent when no input was expected and got one element
                QName receivedType = receivedTypes.toArray(new QName[receivedTypes.size()])[0];
                String namespaceUri = operation.getOperation().getInput().getMessage().getQName()
                        .getNamespaceURI();
                String name = operation.getOperation().getName();
                QName pseudoInputName = new QName(namespaceUri, name);
                if (pseudoInputName.equals(receivedType)) {
                    addResult(operation);
                }
            }
        }
    };
    visitOperation(visitor);
    return visitor.getUniqueResult();
}

From source file:com.evolveum.midpoint.test.IntegrationTestTools.java

public static void assertNoAssociation(PrismObject<ShadowType> shadow, QName associationName,
        String entitlementOid) {/*w  ww  .  j  ava 2s. c om*/
    ShadowType accountType = shadow.asObjectable();
    List<ShadowAssociationType> associations = accountType.getAssociation();
    if (associations == null) {
        return;
    }
    for (ShadowAssociationType association : associations) {
        if (associationName.equals(association.getName())
                && entitlementOid.equals(association.getShadowRef().getOid())) {
            AssertJUnit.fail("Unexpected association for entitlement " + entitlementOid + " in " + shadow);
        }
    }
}

From source file:fr.dutra.confluence2wordpress.core.sync.DefaultAttachmentsSynchronizer.java

private Set<Attachment> parseForAttachments(ContentEntityObject page) throws SynchronizationException {
    Set<Attachment> attachments = new HashSet<Attachment>();
    try {//from ww w  .  j  a v  a2 s . co m
        XMLEventReader r = StaxUtils.getReader(page);
        String fileName = null;
        String pageTitle = null;
        String spaceKey = null;
        try {
            while (r.hasNext()) {
                XMLEvent e = r.nextEvent();
                if (e.isStartElement()) {
                    StartElement startElement = e.asStartElement();
                    QName name = startElement.getName();
                    if (name.equals(ATTACHMENT_QNAME)) {
                        Attribute att = startElement.getAttributeByName(FILENAME_QNAME);
                        if (att != null) {
                            fileName = att.getValue();
                        }
                    } else if (name.equals(PAGE_QNAME)) {
                        Attribute title = startElement.getAttributeByName(TITLE_QNAME);
                        if (title != null) {
                            pageTitle = title.getValue();
                        }
                        Attribute space = startElement.getAttributeByName(SPACE_QNAME);
                        if (space != null) {
                            spaceKey = space.getValue();
                        }
                    }
                } else if (e.isEndElement()) {
                    EndElement endElement = e.asEndElement();
                    if (endElement.getName().equals(ATTACHMENT_QNAME)) {
                        ContentEntityObject attachmentPage;
                        if (pageTitle == null) {
                            attachmentPage = page;
                        } else {
                            attachmentPage = pageManager.getPage(spaceKey, pageTitle);
                        }
                        Attachment attachment = attachmentManager.getAttachment(attachmentPage, fileName);
                        attachments.add(attachment);
                        fileName = null;
                        pageTitle = null;
                        spaceKey = null;
                    }
                }
            }
        } finally {
            r.close();
        }
    } catch (XMLStreamException e) {
        throw new SynchronizationException("Cannot read page: " + page.getTitle(), e);
    }
    return attachments;
}