Search in sources :

Example 46 with XPathExpression

use of javax.xml.xpath.XPathExpression in project oxCore by GluuFederation.

the class Response method getNameId.

public String getNameId() throws XPathExpressionException {
    XPath xPath = XPathFactory.newInstance().newXPath();
    xPath.setNamespaceContext(NAMESPACES);
    XPathExpression query = xPath.compile("/samlp:Response/saml:Assertion/saml:Subject/saml:NameID");
    return query.evaluate(xmlDoc);
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression)

Example 47 with XPathExpression

use of javax.xml.xpath.XPathExpression in project uPortal by Jasig.

the class UrlSyntaxProviderImpl method parseLegacyPortalUrl.

protected IPortalRequestInfo parseLegacyPortalUrl(HttpServletRequest request, Map<String, String[]> parameterMap) {
    final PortalRequestInfoImpl portalRequestInfo = new PortalRequestInfoImpl();
    final String[] fname = parameterMap.remove(LEGACY_PARAM_PORTLET_FNAME);
    if (fname != null && fname.length > 0) {
        final IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, fname[0]);
        if (portletWindow != null) {
            logger.debug("Legacy fname parameter {} resolved to {}", fname[0], portletWindow);
            final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
            portalRequestInfo.setTargetedPortletWindowId(portletWindowId);
            final PortletRequestInfoImpl portletRequestInfo = portalRequestInfo.getPortletRequestInfo(portletWindowId);
            //Check the portlet request type
            final String[] type = parameterMap.remove(LEGACY_PARAM_PORTLET_REQUEST_TYPE);
            if (type != null && type.length > 0 && "ACTION".equals(type[0])) {
                portalRequestInfo.setUrlType(UrlType.ACTION);
            }
            //Set the window state
            final String[] state = parameterMap.remove(LEGACY_PARAM_PORTLET_STATE);
            if (state != null && state.length > 0) {
                final WindowState windowState = PortletUtils.getWindowState(state[0]);
                //If this isn't an action request only allow PATH communicated WindowStates as none of the other options make sense
                if (portalRequestInfo.getUrlType() == UrlType.ACTION || PATH_WINDOW_STATES.contains(windowState)) {
                    portletRequestInfo.setWindowState(windowState);
                }
            }
            //If no window state was set assume MAXIMIZED
            if (portletRequestInfo.getWindowState() == null) {
                portletRequestInfo.setWindowState(WindowState.MAXIMIZED);
            }
            //Set the portlet mode
            final String[] mode = parameterMap.remove(LEGACY_PARAM_PORTLET_MODE);
            if (mode != null && mode.length > 0) {
                final PortletMode portletMode = PortletUtils.getPortletMode(mode[0]);
                portletRequestInfo.setPortletMode(portletMode);
            }
            //Set the parameters
            final Map<String, List<String>> portletParameters = portletRequestInfo.getPortletParameters();
            for (final Map.Entry<String, String[]> parameterEntry : parameterMap.entrySet()) {
                final String prefixedName = parameterEntry.getKey();
                //If the parameter starts with the portlet param prefix
                if (prefixedName.startsWith(LEGACY_PARAM_PORTLET_PARAM_PREFX)) {
                    final String name = prefixedName.substring(LEGACY_PARAM_PORTLET_PARAM_PREFX.length());
                    portletParameters.put(name, Arrays.asList(parameterEntry.getValue()));
                }
            }
            //Set the url state based on the window state
            final UrlState urlState = this.determineUrlState(portletWindow, portletRequestInfo.getWindowState());
            portalRequestInfo.setUrlState(urlState);
        } else {
            logger.debug("Could not find portlet for legacy fname fname parameter {}", fname[0]);
        }
    }
    //Check root=uP_root
    final String[] root = parameterMap.remove(LEGACY_PARAM_LAYOUT_ROOT);
    if (root != null && root.length > 0) {
        if (LEGACY_PARAM_LAYOUT_ROOT_VALUE.equals(root[0])) {
            //Check uP_sparam=activeTab
            final String[] structParam = parameterMap.remove(LEGACY_PARAM_LAYOUT_STRUCT_PARAM);
            if (structParam != null && structParam.length > 0) {
                if (LEGACY_PARAM_LAYOUT_TAB_ID.equals(structParam[0])) {
                    //Get the active tab id
                    final String[] activeTabId = parameterMap.remove(LEGACY_PARAM_LAYOUT_TAB_ID);
                    if (activeTabId != null && activeTabId.length > 0) {
                        //Get the user's layout and do xpath for tab at index=activeTabId[0]
                        final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
                        final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
                        final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
                        final IUserLayout userLayout = userLayoutManager.getUserLayout();
                        final String nodeId = this.xpathOperations.doWithExpression("/layout/folder/folder[@type='regular' and @hidden='false'][position() = $activeTabId]/@ID", Collections.singletonMap("activeTabId", activeTabId[0]), new Function<XPathExpression, String>() {

                            @Override
                            public String apply(XPathExpression xPathExpression) {
                                return userLayout.findNodeId(xPathExpression);
                            }
                        });
                        //Found nodeId for activeTabId
                        if (nodeId != null) {
                            logger.debug("Found layout node {} for legacy activeTabId parameter {}", nodeId, activeTabId[0]);
                            portalRequestInfo.setTargetedLayoutNodeId(nodeId);
                        } else {
                            logger.debug("No layoout node found for legacy activeTabId parameter {}", activeTabId[0]);
                        }
                    }
                }
            }
        }
    }
    return portalRequestInfo;
}
Also used : WindowState(javax.portlet.WindowState) XPathExpression(javax.xml.xpath.XPathExpression) IUserLayout(org.apereo.portal.layout.IUserLayout) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) PortletMode(javax.portlet.PortletMode) IUserInstance(org.apereo.portal.user.IUserInstance) LinkedList(java.util.LinkedList) List(java.util.List) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 48 with XPathExpression

use of javax.xml.xpath.XPathExpression in project uPortal by Jasig.

the class XPathPoolImpl method doWithExpression.

@Override
public <T> T doWithExpression(String expression, Map<String, ?> variables, Function<XPathExpression, T> callback) {
    try {
        final XPathExpression xPathExpression = (XPathExpression) this.pool.borrowObject(expression);
        try {
            this.variableResolver.setVariables(variables);
            return callback.apply(xPathExpression);
        } finally {
            this.variableResolver.clearVariables();
            this.pool.returnObject(expression, xPathExpression);
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new IllegalStateException("Exception of type " + e.getClass().getName() + " is not expected", e);
    }
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) XPathExpressionException(javax.xml.xpath.XPathExpressionException)

Example 49 with XPathExpression

use of javax.xml.xpath.XPathExpression in project uPortal by Jasig.

the class XmlUtilitiesImplTest method testGetUniqueXPath.

@Test
public void testGetUniqueXPath() throws Exception {
    final Document testDoc = loadTestDocument();
    final XPathFactory xPathFactory = XPathFactory.newInstance();
    final XPath xPath = xPathFactory.newXPath();
    final XPathExpression xPathExpression = xPath.compile("//*[@ID='11']");
    final Node node = (Node) xPathExpression.evaluate(testDoc, XPathConstants.NODE);
    final XmlUtilitiesImpl xmlUtilities = new XmlUtilitiesImpl();
    final String nodePath = xmlUtilities.getUniqueXPath(node);
    assertEquals("/layout/folder[2]/folder[3]", nodePath);
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) XPathFactory(javax.xml.xpath.XPathFactory) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 50 with XPathExpression

use of javax.xml.xpath.XPathExpression in project oxCore by GluuFederation.

the class XmlService method getNodeValue.

public String getNodeValue(Document xmlDocument, String xPathExpression, String attributeName) throws XPathExpressionException {
    XPath xPath = XPathFactory.newInstance().newXPath();
    XPathExpression formXPathExpression = xPath.compile(xPathExpression);
    if (StringHelper.isEmpty(attributeName)) {
        String nodeValue = (String) formXPathExpression.evaluate(xmlDocument, XPathConstants.STRING);
        return nodeValue;
    }
    Node node = ((Node) formXPathExpression.evaluate(xmlDocument, XPathConstants.NODE));
    if (node == null) {
        return null;
    }
    Node attributeNode = node.getAttributes().getNamedItem(attributeName);
    if (attributeNode == null) {
        return null;
    }
    return attributeNode.getNodeValue();
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) Node(org.w3c.dom.Node)

Aggregations

XPathExpression (javax.xml.xpath.XPathExpression)98 XPath (javax.xml.xpath.XPath)69 NodeList (org.w3c.dom.NodeList)56 Document (org.w3c.dom.Document)48 XPathExpressionException (javax.xml.xpath.XPathExpressionException)40 XPathFactory (javax.xml.xpath.XPathFactory)40 Node (org.w3c.dom.Node)38 DocumentBuilder (javax.xml.parsers.DocumentBuilder)24 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)19 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 Element (org.w3c.dom.Element)12 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 IOException (java.io.IOException)11 Path (java.nio.file.Path)11 PBXFileReference (com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)10 InputSource (org.xml.sax.InputSource)9