本文整理匯總了Java中org.jaxen.JaxenException類的典型用法代碼示例。如果您正苦於以下問題:Java JaxenException類的具體用法?Java JaxenException怎麽用?Java JaxenException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JaxenException類屬於org.jaxen包,在下文中一共展示了JaxenException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: selectNodes
import org.jaxen.JaxenException; //導入依賴的package包/類
/**
* Jaxen has some magic with its IdentitySet, which means that we can get different results
* depending on whether we cache {@link ChildAssociationRef } instances or not.
* <p>
* So, duplicates are eliminated here before the results are returned.
*/
@SuppressWarnings("unchecked")
@Override
public List selectNodes(Object arg0) throws JaxenException
{
if (logger.isDebugEnabled())
{
logger.debug("Selecting using XPath: \n" +
" XPath: " + this + "\n" +
" starting at: " + arg0);
}
List<Object> resultsWithDuplicates = super.selectNodes(arg0);
Set<Object> set = new HashSet<Object>(resultsWithDuplicates);
// return new list without duplicates
List<Object> results = new ArrayList<>();
results.addAll(set);
// done
return results;
}
示例2: getUniqueValue
import org.jaxen.JaxenException; //導入依賴的package包/類
public String getUniqueValue(String xPath) {
SimpleNamespaceContext nsCtx = new SimpleNamespaceContext();
nsCtx.addNamespace("ns", serverNamespace);
try {
XPath xp = new AXIOMXPath(xPath);
xp.setNamespaceContext(nsCtx);
OMElement elem = builder.getDocumentElement();
if (elem != null) {
List nodeList = xp.selectNodes(elem);
Object obj;
if (!nodeList.isEmpty() && ((obj = nodeList.get(0)) != null)) {
return ((OMElement) obj).getText();
}
}
} catch (JaxenException e) {
throw new RuntimeException("XPath expression " + xPath + " failed", e);
}
return null;
}
示例3: getElements
import org.jaxen.JaxenException; //導入依賴的package包/類
public OMElement[] getElements(String xPath) {
SimpleNamespaceContext nsCtx = new SimpleNamespaceContext();
nsCtx.addNamespace("ns", serverNamespace);
try {
XPath xp = new AXIOMXPath(xPath);
xp.setNamespaceContext(nsCtx);
OMElement elem = builder.getDocumentElement();
if (elem != null) {
List nodeList = xp.selectNodes(elem);
return (OMElement[]) nodeList.toArray(new OMElement[nodeList.size()]);
}
} catch (JaxenException e) {
throw new RuntimeException("XPath expression " + xPath + " failed", e);
}
return new OMElement[0];
}
示例4: test
import org.jaxen.JaxenException; //導入依賴的package包/類
@Ignore
static void test(String xPathA, String xPathB, String xPathExpected) throws JaxenException, IOException {
Element a = new MCRNodeBuilder().buildElement("mods:mods" + xPathA, null, null);
Element b = new MCRNodeBuilder().buildElement("mods:mods" + xPathB, null, null);
Element e = new MCRNodeBuilder().buildElement("mods:mods" + xPathExpected, null, null);
MCRMergeTool.merge(a, b);
boolean asExpected = MCRXMLHelper.deepEqual(e, a);
if (!asExpected) {
System.out.println("actual result:");
logXML(a);
System.out.println("expected result:");
logXML(e);
}
assertTrue(asExpected);
}
示例5: testBuildingElements
import org.jaxen.JaxenException; //導入依賴的package包/類
@Test
public void testBuildingElements() throws JaxenException, JDOMException {
Element built = new MCRNodeBuilder().buildElement("element", null, null);
assertNotNull(built);
assertEquals("element", built.getName());
assertTrue(built.getText().isEmpty());
built = new MCRNodeBuilder().buildElement("element", "text", null);
assertNotNull(built);
assertEquals("element", built.getName());
assertEquals("text", built.getText());
Element root = new Element("root");
built = new MCRNodeBuilder().buildElement("element", null, root);
assertNotNull(built);
assertEquals("element", built.getName());
assertNotNull(built.getParentElement());
assertEquals("root", built.getParentElement().getName());
}
示例6: setSubmittedValues
import org.jaxen.JaxenException; //導入依賴的package包/類
private void setSubmittedValues(MCRBinding binding, String[] values) throws JDOMException, JaxenException {
List<Object> boundNodes = binding.getBoundNodes();
while (boundNodes.size() < values.length) {
binding.cloneBoundElement(boundNodes.size() - 1);
}
for (int i = 0; i < values.length; i++) {
String value = values[i] == null ? "" : values[i].trim();
value = MCRXMLFunctions.normalizeUnicode(value);
value = MCRXMLHelper.removeIllegalChars(value);
binding.setValue(i, value);
}
removeXPaths2CheckResubmission(binding);
binding.detach();
}
示例7: testRequiredRule
import org.jaxen.JaxenException; //導入依賴的package包/類
@Test
public void testRequiredRule() throws JDOMException, JaxenException {
MCREditorSession session = buildSession("document[title]");
addRule(session, "/document/title", "required", "true");
assertFalse(session.getValidator().isValid());
assertEquals("true", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
checkResult(session, "/document/title", MCRValidationResults.MARKER_ERROR);
session = buildSession("document[title='foo']");
addRule(session, "/document/title", "required", "true");
assertTrue(session.getValidator().isValid());
assertEquals("false", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
checkResult(session, "/document/title", MCRValidationResults.MARKER_SUCCESS);
session = buildSession("document[title][title[2]='foo']");
addRule(session, "/document/title", "required", "true");
assertTrue(session.getValidator().isValid());
assertEquals("false", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
checkResult(session, "/document/title", MCRValidationResults.MARKER_SUCCESS);
}
示例8: testMatchesRule
import org.jaxen.JaxenException; //導入依賴的package包/類
@Test
public void testMatchesRule() throws JaxenException, JDOMException {
MCREditorSession session = buildSession("document[isbn]");
addRule(session, "/document", "xpath", "//isbn", "matches", "^(97(8|9))?\\d{9}(\\d|X)$");
assertTrue(session.getValidator().isValid());
assertEquals("false", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
checkResult(session, "/document/isbn", MCRValidationResults.MARKER_DEFAULT);
session = buildSession("document[isbn='9780672317248']");
addRule(session, "/document", "xpath", "//isbn", "matches", "^(97(8|9))?\\d{9}(\\d|X)$");
assertTrue(session.getValidator().isValid());
assertEquals("false", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
checkResult(session, "/document/isbn", MCRValidationResults.MARKER_SUCCESS);
session = buildSession("document[isbn='0-672-31724-9']");
addRule(session, "/document", "xpath", "//isbn", "matches", "^(97(8|9))?\\d{9}(\\d|X)$");
assertFalse(session.getValidator().isValid());
assertEquals("true", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
checkResult(session, "/document/isbn", MCRValidationResults.MARKER_ERROR);
}
示例9: testSubmitTextfields
import org.jaxen.JaxenException; //導入依賴的package包/類
@Test
public void testSubmitTextfields() throws JaxenException, JDOMException, IOException {
String template = "document[title='Titel'][author[@firstName='John'][@lastName='Doe']]";
MCREditorSession session = new MCREditorSession();
session.setEditedXML(new Document(new MCRNodeBuilder().buildElement(template, null, null)));
Map<String, String[]> submittedValues = new HashMap<>();
submittedValues.put("/document/title", new String[] { "Title" });
submittedValues.put("/document/author/@firstName", new String[] { "Jim" });
submittedValues.put("/document/author/@lastName", new String[] { "" });
session.getSubmission().setSubmittedValues(submittedValues);
session.getSubmission().emptyNotResubmittedNodes();
template = "document[title='Title'][author[@firstName='Jim'][@lastName='']]";
Document expected = new Document(new MCRNodeBuilder().buildElement(template, null, null));
Document result = session.getEditedXML();
result = MCRChangeTracker.removeChangeTracking(result);
assertTrue(MCRXMLHelper.deepEqual(expected, result));
}
示例10: testSubmitCheckbox
import org.jaxen.JaxenException; //導入依賴的package包/類
@Test
public void testSubmitCheckbox() throws JaxenException, JDOMException, IOException {
String template = "document[@archive='false']";
MCREditorSession session = new MCREditorSession();
session.setEditedXML(new Document(new MCRNodeBuilder().buildElement(template, null, null)));
session.getSubmission().setXPaths2CheckResubmission("@archive");
session.getSubmission().emptyNotResubmittedNodes();
assertEquals("", session.getEditedXML().getRootElement().getAttributeValue("archive"));
session.getSubmission().setXPaths2CheckResubmission("@archive");
Map<String, String[]> submittedValues = new HashMap<>();
submittedValues.put("/document/@archive", new String[] { "true" });
session.getSubmission().setSubmittedValues(submittedValues);
session.getSubmission().emptyNotResubmittedNodes();
assertEquals("true", session.getEditedXML().getRootElement().getAttributeValue("archive"));
}
示例11: testRemoveEmptyNodes
import org.jaxen.JaxenException; //導入依賴的package包/類
@Test
public void testRemoveEmptyNodes() throws JDOMException, JaxenException {
String xPath1i = "root[child]";
String xPath1o = "root";
cleanAndCompareTo(xPath1i, xPath1o);
String xPath2i = "root[child='a']";
cleanAndCompareTo(xPath2i, xPath2i);
String xPath3i = "root[child[@foo='bar']]";
cleanAndCompareTo(xPath3i, xPath3i);
String xPath7i = "mods:mods[mods:name[@type='personal'][mods:namePart[@type='family']='Musterfrau'][mods:namePart]]";
String xPath7o = "mods:mods[mods:name[@type='personal'][mods:namePart[@type='family']='Musterfrau']]";
cleanAndCompareTo(xPath7i, xPath7o);
String xPath8i = "mods:mods[mods:name[@type='personal'][mods:namePart[@type='family']='Musterfrau'][mods:role/mods:roleTerm[@type]]]";
String xPath8o = "mods:mods[mods:name[@type='personal'][mods:namePart[@type='family']='Musterfrau']]";
cleanAndCompareTo(xPath8i, xPath8o);
}
示例12: testJavaCall
import org.jaxen.JaxenException; //導入依賴的package包/類
@Test
public void testJavaCall() throws JaxenException, JDOMException {
String res = evaluator.replaceXPathOrI18n(
"xed:call-java('org.mycore.frontend.xeditor.jaxen.MCRJaxenXPathFactoryTest','testNoArgs')");
assertEquals(testNoArgs(), res);
res = evaluator.replaceXPathOrI18n(
"xed:call-java('org.mycore.frontend.xeditor.jaxen.MCRJaxenXPathFactoryTest','testOneArg',name[2])");
assertEquals("n2", res);
res = evaluator.replaceXPathOrI18n(
"xed:call-java('org.mycore.frontend.xeditor.jaxen.MCRJaxenXPathFactoryTest','testTwoArgs',string(name[1]/@id),string(note[1]/@href))");
assertEquals("true", res);
res = evaluator.replaceXPathOrI18n(
"xed:call-java('org.mycore.frontend.xeditor.jaxen.MCRJaxenXPathFactoryTest','testTwoArgs',string(name[2]/@id),string(note[1]/@href))");
assertEquals("false", res);
}
示例13: testComplexBindings
import org.jaxen.JaxenException; //導入依賴的package包/類
@Test
public void testComplexBindings() throws JDOMException, JaxenException {
binding = new MCRBinding("document/title[contains(text(),'1')]", true, binding);
assertEquals("title1", binding.getValue());
binding = binding.getParent();
binding = new MCRBinding("//title[@type]", true, binding);
assertEquals("title1", binding.getValue());
binding = binding.getParent();
binding = new MCRBinding("//title[not(@type='main')]", true, binding);
assertEquals("title2", binding.getValue());
binding = binding.getParent();
binding = new MCRBinding("/document/title[../author/lastName='Doe'][2]", true, binding);
assertEquals("title2", binding.getValue());
binding = binding.getParent();
binding = new MCRBinding("//*", true, binding);
binding = new MCRBinding("*[name()='title'][2]", true, binding);
assertEquals("title2", binding.getValue());
binding = binding.getParent();
binding = binding.getParent();
}
示例14: testSwapParameter
import org.jaxen.JaxenException; //導入依賴的package包/類
@Test
public void testSwapParameter() throws JaxenException, JDOMException {
Element template = new MCRNodeBuilder().buildElement("parent[name='aa'][name='ab'][name='bc'][name='ac']", null,
null);
Document doc = new Document(template);
MCRBinding root = new MCRBinding(doc);
MCRRepeatBinding repeat = new MCRRepeatBinding("parent/name[contains(text(),'a')]", root, 0, 0, "build");
assertEquals(3, repeat.getBoundNodes().size());
repeat.bindRepeatPosition();
repeat.bindRepeatPosition();
assertEquals("/parent|1|build|name[contains(text(), \"a\")]",
MCRSwapTarget.getSwapParameter(repeat, MCRSwapTarget.MOVE_UP));
assertEquals("/parent|2|build|name[contains(text(), \"a\")]",
MCRSwapTarget.getSwapParameter(repeat, MCRSwapTarget.MOVE_DOWN));
}
示例15: testSwap
import org.jaxen.JaxenException; //導入依賴的package包/類
@Test
public void testSwap() throws JaxenException, JDOMException {
Element template = new MCRNodeBuilder().buildElement("parent[name='a'][note][foo][name='b'][note[2]]", null,
null);
Document doc = new Document(template);
MCRBinding root = new MCRBinding(doc);
MCRRepeatBinding repeat = new MCRRepeatBinding("parent/name", root, 2, 0, "build");
assertEquals(2, repeat.getBoundNodes().size());
assertEquals("a", doc.getRootElement().getChildren().get(0).getText());
assertEquals("b", doc.getRootElement().getChildren().get(3).getText());
assertEquals("a", ((Element) (repeat.getBoundNodes().get(0))).getText());
assertEquals("b", ((Element) (repeat.getBoundNodes().get(1))).getText());
repeat.bindRepeatPosition();
String swapParam = MCRSwapTarget.getSwapParameter(repeat, MCRSwapTarget.MOVE_DOWN);
new MCRSwapTarget().handle(swapParam, root);
assertEquals("b", doc.getRootElement().getChildren().get(0).getText());
assertEquals("a", doc.getRootElement().getChildren().get(3).getText());
}