Assert { public static void isXliffElement(org.w3c.dom.Node node) throws ConstraintViolationException { org.w3c.dom.Node parent = node.getParentNode(); if (!(node instanceof org.w3c.dom.Element)) { String msg; if (node instanceof org.w3c.dom.Text) { if (parent != null) { msg = MessageFormat .format( "Expected XLIFF element in element <{0}>, but found text ''{1}''", parent.getLocalName(), node .getTextContent()); } else { msg = MessageFormat.format( "Expected XLIFF element, but found text ''{0}''", node.getTextContent()); } } else { msg = MessageFormat.format( "Expected XLIFF element, but found a node of type {0}", node.getClass().getName()); } throw new ConstraintViolationException(msg); } org.w3c.dom.Element element = (Element) node; if (!Schemas.XLIFF_12_NAMESPACE.equals(element.getNamespaceURI())) { String msg; if (parent != null) { msg = MessageFormat .format( "Expected an XLIFF element in element <{0}>, but found a element of namespace ''{1}''", parent.getLocalName(), element .getNamespaceURI()); } else { msg = MessageFormat .format( "Expected an XLIFF element, but found a element of namespace ''{0}''", element.getNamespaceURI()); } throw new ConstraintViolationException(msg); } } private  Assert(); static void notNull(Object param, String paramName); static void validXMLChars(String s, String paramName); static void isNmtoken(String token, String paramName); static void xliffAttrAvailable(Element elem, String... attrNames); static void xliffAttrRestricted(Element elem,
			boolean nonXliffAllowed, boolean xmlSpaceAllowed,
			boolean xmlLangAllowed, String... xliffAttrNames); static void isXliffElement(org.w3c.dom.Node node); static void isXliffElement(org.w3c.dom.Node node, String name); static void isElement(Node node); static void isNonXliffElement(org.w3c.dom.Node node); static void isInstance(Object object, String name,
			Class<?>... classes); static void areInstances(Collection<?> objects, String name,
			Class<?>... classes);  }
@Test public void testIsXliffElementNode() { Document doc = Utils.createDocument(); Element parent = doc.createElementNS("xyz", "ijk"); Node attr = doc.createAttribute("abc"); Node text = doc.createTextNode("abc"); Node nonXliffElem = doc.createElementNS("xyz", "abc"); Node xliffElem = doc.createElementNS(XLIFF_NS, "abc"); try { Assert.isXliffElement(attr); fail("Expected ConstraintViolationException"); } catch (ConstraintViolationException e) { } try { Assert.isXliffElement(text); fail("Expected ConstraintViolationException"); } catch (ConstraintViolationException e) { } try { Assert.isXliffElement(nonXliffElem); fail("Expected ConstraintViolationException"); } catch (ConstraintViolationException e) { } try { Assert.isXliffElement(xliffElem); } catch (ConstraintViolationException e) { fail("Did not expect ConstraintViolationException"); } parent.appendChild(text); parent.appendChild(nonXliffElem); parent.appendChild(xliffElem); try { Assert.isXliffElement(text); fail("Expected ConstraintViolationException"); } catch (ConstraintViolationException e) { } try { Assert.isXliffElement(nonXliffElem); fail("Expected ConstraintViolationException"); } catch (ConstraintViolationException e) { } try { Assert.isXliffElement(xliffElem); } catch (ConstraintViolationException e) { fail("Did not expect ConstraintViolationException"); } }
@Test public void testIsXliffElementNodeString() { Document doc = Utils.createDocument(); Element parent = doc.createElementNS("xyz", "ijk"); Node attr = doc.createAttribute("abc"); Node text = doc.createTextNode("abc"); Node nonXliffElem = doc.createElementNS("xyz", "abc"); Node xliffElem = doc.createElementNS(XLIFF_NS, "abc"); try { Assert.isXliffElement(attr, "abc"); fail("Expected ConstraintViolationException"); } catch (ConstraintViolationException e) { } try { Assert.isXliffElement(text, "abc"); fail("Expected ConstraintViolationException"); } catch (ConstraintViolationException e) { } try { Assert.isXliffElement(nonXliffElem, "abc"); fail("Expected ConstraintViolationException"); } catch (ConstraintViolationException e) { } try { Assert.isXliffElement(xliffElem, "abc"); } catch (ConstraintViolationException e) { fail("Did not expect ConstraintViolationException"); } try { Assert.isXliffElement(xliffElem, "xyz"); fail("Expected ConstraintViolationException"); } catch (ConstraintViolationException e) { } parent.appendChild(text); parent.appendChild(nonXliffElem); parent.appendChild(xliffElem); try { Assert.isXliffElement(text, "abc"); fail("Expected ConstraintViolationException"); } catch (ConstraintViolationException e) { } try { Assert.isXliffElement(nonXliffElem, "abc"); fail("Expected ConstraintViolationException"); } catch (ConstraintViolationException e) { } try { Assert.isXliffElement(xliffElem, "abc"); } catch (ConstraintViolationException e) { fail("Did not expect ConstraintViolationException"); } try { Assert.isXliffElement(xliffElem, "xyz"); fail("Expected ConstraintViolationException"); } catch (ConstraintViolationException e) { } }