List of usage examples for org.apache.commons.jxpath JXPathContext newContext
public static JXPathContext newContext(Object contextBean)
From source file:org.apache.maven.project.harness.PomTestWrapper.java
public PomTestWrapper(File pomFile, MavenProject mavenProject) { this.mavenProject = Validate.notNull(mavenProject, "mavenProject cannot be null"); this.pomFile = pomFile; context = JXPathContext.newContext(mavenProject.getModel()); }
From source file:org.apache.maven.project.harness.PomTestWrapper.java
public PomTestWrapper(MavenProject mavenProject) { this.mavenProject = Validate.notNull(mavenProject, "mavenProject cannot be null"); context = JXPathContext.newContext(mavenProject.getModel()); }
From source file:org.cauldron.einstein.ri.core.model.data.object.ObjectGraphDataQueryObject.java
public ObjectGraphDataQueryObject(Object object) { context = JXPathContext.newContext(object); }
From source file:org.chiba.tools.schemabuilder.AbstractSchemaFormBuilder.java
private void addAttributeSet(Document xForm, Element modelSection, Element formSection, XSComplexTypeDefinition controlType, XSElementDeclaration owner, String pathToRoot, boolean checkIfExtension) { XSObjectList attrUses = controlType.getAttributeUses(); if (attrUses != null) { int nbAttr = attrUses.getLength(); for (int i = 0; i < nbAttr; i++) { XSAttributeUse currentAttributeUse = (XSAttributeUse) attrUses.item(i); XSAttributeDeclaration currentAttribute = currentAttributeUse.getAttrDeclaration(); //test if extended ! if (checkIfExtension && this.doesAttributeComeFromExtension(currentAttributeUse, controlType)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(/* w ww .ja v a 2 s .c o m*/ "This attribute comes from an extension: recopy form controls. \n Model section: "); DOMUtil.prettyPrintDOM(modelSection); } String attributeName = currentAttributeUse.getName(); if (attributeName == null || attributeName.equals("")) attributeName = currentAttributeUse.getAttrDeclaration().getName(); //find the existing bind Id //(modelSection is the enclosing bind of the element) NodeList binds = modelSection.getElementsByTagNameNS(XFORMS_NS, "bind"); int j = 0; int nb = binds.getLength(); String bindId = null; while (j < nb && bindId == null) { Element bind = (Element) binds.item(j); String nodeset = bind.getAttributeNS(XFORMS_NS, "nodeset"); if (nodeset != null) { String name = nodeset.substring(1); //remove "@" in nodeset if (name.equals(attributeName)) bindId = bind.getAttributeNS(XFORMS_NS, "id"); } j++; } //find the control Element control = null; if (bindId != null) { if (LOGGER.isDebugEnabled()) LOGGER.debug("bindId found: " + bindId); JXPathContext context = JXPathContext.newContext(formSection.getOwnerDocument()); Pointer pointer = context .getPointer("//*[@" + this.getXFormsNSPrefix() + "bind='" + bindId + "']"); if (pointer != null) control = (Element) pointer.getNode(); } //copy it if (control == null) { LOGGER.warn("Corresponding control not found"); } else { Element newControl = (Element) control.cloneNode(true); //set new Ids to XForm elements this.resetXFormIds(newControl); formSection.appendChild(newControl); } } else { String newPathToRoot; if ((pathToRoot == null) || pathToRoot.equals("")) { newPathToRoot = "@" + currentAttribute.getName(); } else if (pathToRoot.endsWith("/")) { newPathToRoot = pathToRoot + "@" + currentAttribute.getName(); } else { newPathToRoot = pathToRoot + "/@" + currentAttribute.getName(); } XSSimpleTypeDefinition simpleType = currentAttribute.getTypeDefinition(); //TODO SRA: UrType ? /*if(simpleType==null){ simpleType=new UrType(); }*/ addSimpleType(xForm, modelSection, formSection, simpleType, currentAttributeUse, newPathToRoot); } } } }
From source file:org.chiba.tools.schemabuilder.AbstractSchemaFormBuilder.java
/** * checkIfExtension: if false, addElement is called wether it is an extension or not * if true, if it is an extension, element is recopied (and no additional bind) *//*from w w w. j av a 2 s . c o m*/ private void addGroup(Document xForm, Element modelSection, Element formSection, XSModelGroup group, XSComplexTypeDefinition controlType, XSElementDeclaration owner, String pathToRoot, int minOccurs, int maxOccurs, boolean checkIfExtension) { if (group != null) { Element repeatSection = addRepeatIfNecessary(xForm, modelSection, formSection, owner.getTypeDefinition(), minOccurs, maxOccurs, pathToRoot); Element repeatContentWrapper = repeatSection; if (repeatSection != formSection) { //selector -> no more needed? //this.addSelector(xForm, repeatSection); //group wrapper repeatContentWrapper = _wrapper.createGroupContentWrapper(repeatSection); } if (LOGGER.isDebugEnabled()) LOGGER.debug( "addGroup from owner=" + owner.getName() + " and controlType=" + controlType.getName()); XSObjectList particles = group.getParticles(); for (int counter = 0; counter < particles.getLength(); counter++) { XSParticle currentNode = (XSParticle) particles.item(counter); XSTerm term = currentNode.getTerm(); if (LOGGER.isDebugEnabled()) LOGGER.debug(" : next term = " + term.getName()); int childMaxOccurs = currentNode.getMaxOccurs(); if (currentNode.getMaxOccursUnbounded()) childMaxOccurs = -1; int childMinOccurs = currentNode.getMinOccurs(); if (term instanceof XSModelGroup) { if (LOGGER.isDebugEnabled()) LOGGER.debug(" term is a group"); addGroup(xForm, modelSection, repeatContentWrapper, ((XSModelGroup) term), controlType, owner, pathToRoot, childMinOccurs, childMaxOccurs, checkIfExtension); } else if (term instanceof XSElementDeclaration) { XSElementDeclaration element = (XSElementDeclaration) term; if (LOGGER.isDebugEnabled()) LOGGER.debug(" term is an element declaration: " + term.getName()); //special case for types already added because used in an extension //do not add it when it comes from an extension !!! //-> make a copy from the existing form control if (checkIfExtension && this.doesElementComeFromExtension(element, controlType)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug( "This element comes from an extension: recopy form controls.\n Model Section="); DOMUtil.prettyPrintDOM(modelSection); } //find the existing bind Id //(modelSection is the enclosing bind of the element) NodeList binds = modelSection.getElementsByTagNameNS(XFORMS_NS, "bind"); int i = 0; int nb = binds.getLength(); String bindId = null; while (i < nb && bindId == null) { Element bind = (Element) binds.item(i); String nodeset = bind.getAttributeNS(XFORMS_NS, "nodeset"); if (nodeset != null && nodeset.equals(element.getName())) bindId = bind.getAttributeNS(XFORMS_NS, "id"); i++; } //find the control Element control = null; if (bindId != null) { if (LOGGER.isDebugEnabled()) LOGGER.debug("bindId found: " + bindId); JXPathContext context = JXPathContext.newContext(formSection.getOwnerDocument()); Pointer pointer = context .getPointer("//*[@" + this.getXFormsNSPrefix() + "bind='" + bindId + "']"); if (pointer != null) control = (Element) pointer.getNode(); } //copy it if (control == null) { LOGGER.warn("Corresponding control not found"); } else { Element newControl = (Element) control.cloneNode(true); //set new Ids to XForm elements this.resetXFormIds(newControl); repeatContentWrapper.appendChild(newControl); } } else { //add it normally String elementName = getElementName(element, xForm); String path = pathToRoot + "/" + elementName; if (pathToRoot.equals("")) { //relative path = elementName; } addElement(xForm, modelSection, repeatContentWrapper, element, element.getTypeDefinition(), path); } } else { //XSWildcard -> ignore ? //LOGGER.warn("XSWildcard found in group from "+owner.getName()+" for pathToRoot="+pathToRoot); } } if (LOGGER.isDebugEnabled()) LOGGER.debug("--- end of addGroup from owner=" + owner.getName()); } }
From source file:org.chiba.xml.base.XMLBaseResolverTest.java
/** * __UNDOCUMENTED__/*from w ww. j av a 2 s . c o m*/ * * @throws Exception __UNDOCUMENTED__ */ public void testResolveXMLBase() throws Exception { Document doc = getXmlResource("XMLBaseResolverTest1.xml"); JXPathContext context = JXPathContext.newContext(doc); Pointer p = context.getPointer("descendant::*[@xlink:href][1]"); Node n = (Node) p.getNode(); String s = XMLBaseResolver.resolveXMLBase(n, "new.xml"); assertTrue(s.equals("http://example.org/today/new.xml")); p = context.getPointer("descendant::*[@xlink:href][2]"); n = (Node) p.getNode(); s = XMLBaseResolver.resolveXMLBase(n, "pick1.xml"); assertTrue(s.equals("http://example.org/hotpicks/pick1.xml")); p = context.getPointer("descendant::*[@xlink:href][3]"); n = (Node) p.getNode(); s = XMLBaseResolver.resolveXMLBase(n, "pick2.xml"); assertTrue(s.equals("http://example.org/hotpicks/pick2.xml")); p = context.getPointer("descendant::*[@xlink:href][4]"); n = (Node) p.getNode(); s = XMLBaseResolver.resolveXMLBase(n, "pick3.xml"); assertTrue(s.equals("http://example.org/hotpicks/pick3.xml")); }
From source file:org.chiba.xml.base.XMLBaseResolverTest.java
/** * __UNDOCUMENTED__//www .j a v a 2 s .co m * * @throws Exception __UNDOCUMENTED__ */ public void testResolveXMLBaseLess() throws Exception { Document doc = getXmlResource("XMLBaseResolverTest2.xml"); JXPathContext context = JXPathContext.newContext(doc); Pointer p = context.getPointer("descendant::*[@xlink:href][1]"); Node n = (Node) p.getNode(); String s = XMLBaseResolver.resolveXMLBase(n, "new.xml"); assertTrue(s.equals("new.xml")); p = context.getPointer("descendant::*[@xlink:href][2]"); n = (Node) p.getNode(); s = XMLBaseResolver.resolveXMLBase(n, "pick1.xml"); assertTrue(s.equals("pick1.xml")); p = context.getPointer("descendant::*[@xlink:href][3]"); n = (Node) p.getNode(); s = XMLBaseResolver.resolveXMLBase(n, "pick2.xml"); assertTrue(s.equals("pick2.xml")); p = context.getPointer("descendant::*[@xlink:href][4]"); n = (Node) p.getNode(); s = XMLBaseResolver.resolveXMLBase(n, "pick3.xml"); assertTrue(s.equals("pick3.xml")); }
From source file:org.chiba.xml.util.test.XMLBaseResolverTest.java
/** * __UNDOCUMENTED__// www . j av a 2s.c o m * * @throws Exception __UNDOCUMENTED__ */ public void testResolveXMLBase() throws Exception { Document doc = getXmlResource("xmlbase1.xml"); JXPathContext context = JXPathContext.newContext(doc); Pointer p = context.getPointer("descendant::*[@xlink:href][1]"); Node n = (Node) p.getNode(); String s = XMLBaseResolver.resolveXMLBase(n, "new.xml"); assertTrue(s.equals("http://example.org/today/new.xml")); p = context.getPointer("descendant::*[@xlink:href][2]"); n = (Node) p.getNode(); s = XMLBaseResolver.resolveXMLBase(n, "pick1.xml"); assertTrue(s.equals("http://example.org/hotpicks/pick1.xml")); p = context.getPointer("descendant::*[@xlink:href][3]"); n = (Node) p.getNode(); s = XMLBaseResolver.resolveXMLBase(n, "pick2.xml"); assertTrue(s.equals("http://example.org/hotpicks/pick2.xml")); p = context.getPointer("descendant::*[@xlink:href][4]"); n = (Node) p.getNode(); s = XMLBaseResolver.resolveXMLBase(n, "pick3.xml"); assertTrue(s.equals("http://example.org/hotpicks/pick3.xml")); }
From source file:org.chiba.xml.util.test.XMLBaseResolverTest.java
/** * __UNDOCUMENTED__//from w w w .j av a 2 s .c o m * * @throws Exception __UNDOCUMENTED__ */ public void testResolveXMLBaseLess() throws Exception { Document doc = getXmlResource("xmlbase2.xml"); JXPathContext context = JXPathContext.newContext(doc); Pointer p = context.getPointer("descendant::*[@xlink:href][1]"); Node n = (Node) p.getNode(); String s = XMLBaseResolver.resolveXMLBase(n, "new.xml"); assertTrue(s.equals("new.xml")); p = context.getPointer("descendant::*[@xlink:href][2]"); n = (Node) p.getNode(); s = XMLBaseResolver.resolveXMLBase(n, "pick1.xml"); assertTrue(s.equals("pick1.xml")); p = context.getPointer("descendant::*[@xlink:href][3]"); n = (Node) p.getNode(); s = XMLBaseResolver.resolveXMLBase(n, "pick2.xml"); assertTrue(s.equals("pick2.xml")); p = context.getPointer("descendant::*[@xlink:href][4]"); n = (Node) p.getNode(); s = XMLBaseResolver.resolveXMLBase(n, "pick3.xml"); assertTrue(s.equals("pick3.xml")); }
From source file:org.chiba.xml.xforms.action.MessageAction.java
/** * Performs the <code>message</code> action. * * @throws XFormsException if an error occurred during <code>message</code> * processing.//from w w w . ja v a 2 s . c o m */ public void perform() throws XFormsException { super.perform(); String bindAttribute = getXFormsAttribute(BIND_ATTRIBUTE); String refAttribute = getXFormsAttribute(REF_ATTRIBUTE); String srcAttribute = getXFormsAttribute(XFormsConstants.SRC_ATTRIBUTE); String message = ""; if (bindAttribute != null || refAttribute != null) { // get message from instance data message = this.model.getInstance(getInstanceId()).getNodeValue(getLocationPath()); } else if (srcAttribute != null) { // get message from link Object result; try { result = this.container.getConnectorFactory().createURIResolver(srcAttribute, this.element) .resolve(); } catch (Exception e) { throw new XFormsLinkError("uri resolution failed at " + this, e, this.model.getTarget(), srcAttribute); } try { message = JXPathContext.newContext(result).getValue("/").toString(); } catch (Exception e) { throw new XFormsLinkError("object model not supported at " + this, e, this.model.getTarget(), srcAttribute); } } else { // get message from text child message = this.textContent; } // dispatch internal chiba event HashMap map = new HashMap(); map.put("message", message); map.put("level", this.levelAttribute); this.container.dispatch(this.target, ChibaEventNames.RENDER_MESSAGE, map); }