use of javax.xml.xpath.XPathFactory in project Activiti by Activiti.
the class ProcessDiagramLayoutFactory method fixFlowNodePositionsIfModelFromAdonis.
protected Map<String, DiagramNode> fixFlowNodePositionsIfModelFromAdonis(Document bpmnModel, Map<String, DiagramNode> elementBoundsFromBpmnDi) {
if (isExportedFromAdonis50(bpmnModel)) {
Map<String, DiagramNode> mapOfFixedBounds = new HashMap<String, DiagramNode>();
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xPath = xPathFactory.newXPath();
xPath.setNamespaceContext(new Bpmn20NamespaceContext());
for (Entry<String, DiagramNode> entry : elementBoundsFromBpmnDi.entrySet()) {
String elementId = entry.getKey();
DiagramNode elementBounds = entry.getValue();
String expression = "local-name(//bpmn:*[@id = '" + elementId + "'])";
try {
XPathExpression xPathExpression = xPath.compile(expression);
String elementLocalName = xPathExpression.evaluate(bpmnModel);
if (!"participant".equals(elementLocalName) && !"lane".equals(elementLocalName) && !"textAnnotation".equals(elementLocalName) && !"group".equals(elementLocalName)) {
elementBounds.setX(elementBounds.getX() - elementBounds.getWidth() / 2);
elementBounds.setY(elementBounds.getY() - elementBounds.getHeight() / 2);
}
} catch (XPathExpressionException e) {
throw new ActivitiException("Error while evaluating the following XPath expression on a BPMN XML document: '" + expression + "'.", e);
}
mapOfFixedBounds.put(elementId, elementBounds);
}
return mapOfFixedBounds;
} else {
return elementBoundsFromBpmnDi;
}
}
use of javax.xml.xpath.XPathFactory in project camel by apache.
the class MockEndpointFixture method assertMessageReceived.
protected void assertMessageReceived(Document aExpectedDoc, Document aActual) throws Exception, XPathExpressionException {
Document noTime = XmlFixture.stripTimestamp(aActual);
Document noUUID = XmlFixture.stripUUID(noTime);
XmlFixture.assertXMLIgnorePrefix("failed to match", aExpectedDoc, noUUID);
// assert that we have a timestamp and datetime
// can't rely on the datetime being the same due to timezone differences
// instead, we'll assert that the values exist.
XPathFactory xpf = XPathFactory.newInstance();
XPath xp = xpf.newXPath();
xp.setNamespaceContext(new NamespaceContext() {
public String getNamespaceURI(String aArg0) {
return "urn:org.apache.camel.component:jmx";
}
public String getPrefix(String aArg0) {
return "jmx";
}
public Iterator<Object> getPrefixes(String aArg0) {
return null;
}
});
assertEquals("1", xp.evaluate("count(//jmx:timestamp)", aActual));
assertEquals("1", xp.evaluate("count(//jmx:dateTime)", aActual));
resetMockEndpoint();
}
use of javax.xml.xpath.XPathFactory in project Asqatasun by Asqatasun.
the class HeritrixConfigurationModifier method initXpathCompiler.
private void initXpathCompiler() {
XPathFactory xPathfactory = XPathFactory.newInstance();
xpath = xPathfactory.newXPath();
}
use of javax.xml.xpath.XPathFactory in project uPortal by Jasig.
the class UpdatePreferencesServlet method subscribeToTab.
/**
* Subscribe a user to a pre-formatted tab (pulled DLM fragment).
*
* @param request
* @param response
* @return
* @throws IOException
*/
@RequestMapping(method = RequestMethod.POST, params = "action=subscribeToTab")
public ModelAndView subscribeToTab(HttpServletRequest request, HttpServletResponse response) throws IOException {
IUserInstance ui = userInstanceManager.getUserInstance(request);
IPerson per = getPerson(ui, response);
UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
IUserLayoutManager ulm = upm.getUserLayoutManager();
// Get the fragment owner's name from the request and construct
// an IPerson object representing that user
String fragmentOwnerName = request.getParameter("sourceID");
if (StringUtils.isBlank(fragmentOwnerName)) {
logger.warn("Attempted to subscribe to tab with null owner ID");
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return new ModelAndView("jsonView", Collections.singletonMap("error", "Attempted to subscribe to tab with null owner ID"));
}
RestrictedPerson fragmentOwner = PersonFactory.createRestrictedPerson();
fragmentOwner.setUserName(fragmentOwnerName);
// Mark the currently-authenticated user as subscribed to this fragment.
// If an inactivated fragment registration already exists, update it
// as an active subscription. Otherwise, create a new fragment
// subscription.
IUserFragmentSubscription userFragmentInfo = userFragmentInfoDao.getUserFragmentInfo(per, fragmentOwner);
if (userFragmentInfo == null) {
userFragmentInfo = userFragmentInfoDao.createUserFragmentInfo(per, fragmentOwner);
} else {
userFragmentInfo.setActive(true);
userFragmentInfoDao.updateUserFragmentInfo(userFragmentInfo);
}
try {
// reload user layout and stylesheet to incorporate new DLM fragment
ulm.loadUserLayout(true);
// get the target node this new tab should be moved after
String destinationId = request.getParameter("elementID");
// get the user layout for the currently-authenticated user
int uid = userIdentityStore.getPortalUID(fragmentOwner, false);
final DistributedUserLayout userLayout = userLayoutStore.getUserLayout(per, upm.getUserProfile());
Document layoutDocument = userLayout.getLayout();
// attempt to find the new subscribed tab in the layout so we can
// move it
StringBuilder expression = new StringBuilder("//folder[@type='root']/folder[starts-with(@ID,'").append(Constants.FRAGMENT_ID_USER_PREFIX).append(uid).append("')]");
XPathFactory fac = XPathFactory.newInstance();
XPath xpath = fac.newXPath();
NodeList nodes = (NodeList) xpath.evaluate(expression.toString(), layoutDocument, XPathConstants.NODESET);
String sourceId = nodes.item(0).getAttributes().getNamedItem("ID").getTextContent();
ulm.moveNode(sourceId, ulm.getParentId(destinationId), destinationId);
ulm.saveUserLayout();
return new ModelAndView("jsonView", Collections.singletonMap("tabId", sourceId));
} catch (XPathExpressionException e) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return new ModelAndView("jsonView", Collections.singletonMap("error", "Xpath error"));
} catch (PortalException e) {
return handlePersistError(request, response, e);
}
}
use of javax.xml.xpath.XPathFactory in project uPortal by Jasig.
the class PortletMarketplaceController method getPortletTabInfo.
private List<PortletTab> getPortletTabInfo(DistributedUserLayout layout, String fname) {
final String XPATH_TAB = "/layout/folder/folder[@hidden = 'false' and @type = 'regular']";
final String XPATH_COUNT_COLUMNS = "count(./folder[@hidden = \"false\"])";
final String XPATH_COUNT_NON_EDITABLE_COLUMNS = "count(./folder[@hidden = \"false\" and @*[local-name() = \"editAllowed\"] = \"false\"])";
final String XPATH_GET_TAB_PORTLET_FMT = ".//channel[@hidden = \"false\" and @fname = \"%s\"]";
Document doc = layout.getLayout();
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
try {
XPathExpression tabExpr = xpath.compile(XPATH_TAB);
NodeList list = (NodeList) tabExpr.evaluate(doc, XPathConstants.NODESET);
// Count columns and non-editable columns...
XPathExpression columnCountExpr = xpath.compile(XPATH_COUNT_COLUMNS);
XPathExpression nonEditableCountExpr = xpath.compile(XPATH_COUNT_NON_EDITABLE_COLUMNS);
// get the list of tabs...
String xpathStr = format(XPATH_GET_TAB_PORTLET_FMT, fname);
XPathExpression portletExpr = xpath.compile(xpathStr);
List<PortletTab> tabs = new ArrayList<>();
for (int i = 0; i < list.getLength(); i++) {
Node tab = list.item(i);
String tabName = ((Element) tab).getAttribute("name");
String tabId = ((Element) tab).getAttribute("ID");
// check if tab is editable...
Number columns = (Number) columnCountExpr.evaluate(tab, XPathConstants.NUMBER);
Number nonEditColumns = (Number) nonEditableCountExpr.evaluate(tab, XPathConstants.NUMBER);
// tab is not editable... skip it...
if (columns.intValue() > 0 && columns.intValue() == nonEditColumns.intValue()) {
continue;
}
// get all instances of this portlet on this tab...
List<String> layoutIds = new ArrayList<>();
NodeList fnameListPerTab = (NodeList) portletExpr.evaluate(tab, XPathConstants.NODESET);
for (int j = 0; j < fnameListPerTab.getLength(); j++) {
Node channel = fnameListPerTab.item(j);
String layoutId = ((Element) channel).getAttribute("ID");
layoutIds.add(layoutId);
}
PortletTab tabInfo = new PortletTab(tabName, tabId, layoutIds);
tabs.add(tabInfo);
}
return tabs;
} catch (XPathExpressionException e) {
logger.error("Error evaluating xpath", e);
}
return null;
}
Aggregations