Search in sources :

Example 61 with XPathFactory

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;
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) XPathFactory(javax.xml.xpath.XPathFactory) DiagramNode(org.activiti.engine.repository.DiagramNode) ActivitiException(org.activiti.engine.ActivitiException) HashMap(java.util.HashMap) XPathExpressionException(javax.xml.xpath.XPathExpressionException)

Example 62 with XPathFactory

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();
}
Also used : XPath(javax.xml.xpath.XPath) XPathFactory(javax.xml.xpath.XPathFactory) NamespaceContext(javax.xml.namespace.NamespaceContext) Iterator(java.util.Iterator) Document(org.w3c.dom.Document)

Example 63 with XPathFactory

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();
}
Also used : XPathFactory(javax.xml.xpath.XPathFactory)

Example 64 with XPathFactory

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);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) ModelAndView(org.springframework.web.servlet.ModelAndView) IUserFragmentSubscription(org.apereo.portal.fragment.subscribe.IUserFragmentSubscription) Document(org.w3c.dom.Document) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) XPathFactory(javax.xml.xpath.XPathFactory) RestrictedPerson(org.apereo.portal.security.provider.RestrictedPerson) DistributedUserLayout(org.apereo.portal.layout.dlm.DistributedUserLayout) PortalException(org.apereo.portal.PortalException) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 65 with XPathFactory

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;
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) XPathFactory(javax.xml.xpath.XPathFactory)

Aggregations

XPathFactory (javax.xml.xpath.XPathFactory)75 XPath (javax.xml.xpath.XPath)59 XPathExpression (javax.xml.xpath.XPathExpression)40 Document (org.w3c.dom.Document)34 NodeList (org.w3c.dom.NodeList)34 XPathExpressionException (javax.xml.xpath.XPathExpressionException)26 DocumentBuilder (javax.xml.parsers.DocumentBuilder)24 Node (org.w3c.dom.Node)24 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)22 InputSource (org.xml.sax.InputSource)16 Test (org.junit.Test)15 IOException (java.io.IOException)13 PBXNativeTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXNativeTarget)11 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 Path (java.nio.file.Path)11 SAXException (org.xml.sax.SAXException)11 PBXFileReference (com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)10 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)9 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)7