CommonsParser { public static ArrayList<CodeFragment> parseCodeFragments( List<? extends Node> elementsAndText) throws ConstraintViolationException { ArrayList<CodeFragment> ret = new ArrayList<CodeFragment>(); NodeIterator iter = new NodeIterator(elementsAndText, false); while (iter.hasNext()) { if (iter.nextIsElement()) { Element element = iter .getXliffElement(Sub.NAME); ret.add(new SubImpl(element)); } else { ret.add(new TextImpl(iter.getText())); } } return ret; } private  CommonsParser(); static ArrayList<TextFragment> parseTextFragments(
			List<? extends Node> elementsAndText); static ArrayList<CodeFragment> parseCodeFragments(
			List<? extends Node> elementsAndText);  }
@Test public void testParseCodeFragments() { Document doc = Utils.createDocument(); ArrayList<Node> list = new ArrayList<Node>(); list.add(doc.createTextNode("text1")); Element sub = doc.createElementNS(XLIFF_12_NAMESPACE, "sub"); sub.setTextContent("text2"); list.add(sub); try { ArrayList<CodeFragment> fragments = CommonsParser.parseCodeFragments(list); assertEquals(new Integer(2), new Integer(fragments.size())); assertTrue(fragments.get(0) instanceof Text); assertTrue(fragments.get(1) instanceof Sub); } catch (ConstraintViolationException e) { fail("Did not expect ConstraintViolationException"); } list.clear(); Element invalid = doc.createElementNS(XLIFF_12_NAMESPACE, "invalid"); list.add(invalid); try { CommonsParser.parseCodeFragments(list); fail("Expected ConstraintViolationException"); } catch (ConstraintViolationException e) { } Element invalidParent = doc.createElementNS(XLIFF_12_NAMESPACE, "parent"); invalidParent.appendChild(invalid); try { CommonsParser.parseCodeFragments(list); fail("Expected ConstraintViolationException"); } catch (ConstraintViolationException e) { } }