Returns a valid {@link Pathref} based on the specified arguments or
<code>null</null> if that's not possible.

@param layoutOwnerUsername
@param dlmNoderef
@param layout
@return a valid {@link Pathref} or <code>null</null>
435195
public Pathref getPathrefFromNoderef(
            String layoutOwnerUsername, String dlmNoderef, org.dom4j.Element layout) {

        Validate.notNull(layoutOwnerUsername, "Argument 'layoutOwnerUsername' cannot be null.");
        Validate.notNull(dlmNoderef, "Argument 'dlmNoderef' cannot be null.");

        if (log.isTraceEnabled()) {
            StringBuilder msg = new StringBuilder();
            msg.append("createPathref: [layoutOwnerUsername='")
                    .append(layoutOwnerUsername)
                    .append("', dlmNoderef='")
                    .append(dlmNoderef)
                    .append("']");
            log.trace(msg.toString());
        }

        Pathref rslt = null; // default;  signifies we can't match a node

        final Matcher dlmNodeMatcher = DLM_NODE_PATTERN.matcher(dlmNoderef);
        if (dlmNodeMatcher.matches()) {
            final int userId = Integer.valueOf(dlmNodeMatcher.group(1));
            final String nodeId = dlmNodeMatcher.group(2);

            final String userName = this.userIdentityStore.getPortalUserName(userId);
            final Tuple<String, DistributedUserLayout> userLayoutInfo =
                    getUserLayoutTuple(userName, userId);

            if (userLayoutInfo.second == null) {
                this.log.warn(
                        "no layout for fragment user '"
                                + userLayoutInfo.first
                                + "' Specified dlmNoderef "
                                + dlmNoderef
                                + " cannot be resolved.");
                return null;
            }

            final Document fragmentLayout = userLayoutInfo.second.getLayout();
            final Node targetElement =
                    this.xPathOperations.evaluate(
                            "//*[@ID = $nodeId]",
                            Collections.singletonMap("nodeId", nodeId),
                            fragmentLayout,
                            XPathConstants.NODE);

            // We can only proceed if there's a valid match in the document
            if (targetElement != null) {
                String xpath = this.xmlUtilities.getUniqueXPath(targetElement);
                // Pathref objects that refer to portlets are expected to include
                // the fname as the 3rd element; other pathref objects should leave
                // that element blank.
                String fname = null;
                Node fnameAttr = targetElement.getAttributes().getNamedItem("fname");
                if (fnameAttr != null) {
                    fname = fnameAttr.getTextContent();
                }

                rslt = new Pathref(userLayoutInfo.first, xpath, fname);
            }
        }

        final Matcher userNodeMatcher = USER_NODE_PATTERN.matcher(dlmNoderef);
        if (userNodeMatcher.find()) {
            // We need a pathref based on the new style of layout b/c on
            // import this users own layout will not be in the database
            // when the path is computed back to an Id...
            final String structId = userNodeMatcher.group(1);
            final org.dom4j.Node target = layout.selectSingleNode("//*[@ID = '" + structId + "']");
            if (target == null) {
                this.log.warn(
                        "no match found on layout for user '"
                                + layoutOwnerUsername
                                + "' for the specified dlmNoderef:  "
                                + dlmNoderef);
                return null;
            }

            String fname = null;
            if (target.getName().equals("channel")) {
                fname = target.valueOf("@fname");
            }

            rslt = new Pathref(layoutOwnerUsername, target.getUniquePath(), fname);
        }

        return rslt;
    }
925381
protected String idForPath(Path pluginPath) {
        for (PluginWrapper plugin : plugins.values()) {
            if (plugin.getPluginPath().equals(pluginPath)) {
                return plugin.getPluginId();
            }
        }

        return null;
    }
807882
@Override
  public PathImpl lookupImpl(String userPath, 
                         Map<String,Object> newAttributes,
                         boolean isAllowRoot)
  {
    String newPath;

    if (userPath == null)
      return _root.fsWalk(getPath(), newAttributes, "/");

    int length = userPath.length();
    int colon = userPath.indexOf(':');
    int slash = userPath.indexOf('/');
    int query = userPath.indexOf('?');

    // parent handles scheme:xxx
    if (colon != -1 && (colon < slash || slash == -1))
      return super.lookupImpl(userPath, newAttributes, isAllowRoot);
      
      // //hostname
    if (slash == 0 && length > 1 && userPath.charAt(1) == '/')
      return schemeWalk(userPath, newAttributes, userPath, 0);

      // /path
    else if (slash == 0) {
      String queryString = "";
      if (query >= 0) {
        queryString = userPath.substring(query);
        userPath = userPath.substring(0, query);
      }
      
      newPath = normalizePath("/", userPath, 0, '/');
      
      if (query >= 0)
        newPath += queryString;
    }
      // path
    else {
      String queryString = "";
      if (query >= 0) {
        queryString = userPath.substring(query);
        userPath = userPath.substring(0, query);
      }
      
      newPath = normalizePath(_pathname, userPath, 0, '/');
      
      if (query >= 0)
        newPath += queryString;
    }

    // XXX: does missing root here cause problems with restrictions?
    return _root.fsWalk(userPath, newAttributes, newPath);
  }
1052703
public IPortalUrlBuilder getPortalUrlBuilder(
            HttpServletRequest request, String fname, String layoutId, String type) {
        try {
            final UrlType urlType;
            if (StringUtils.isEmpty(type)) {
                urlType = UrlType.RENDER;
            } else {
                urlType = UrlType.valueOfIngoreCase(type);
            }

            if (StringUtils.isNotEmpty(fname)) {
                final IPortalUrlBuilder portalUrlBuilderByPortletFName =
                        this.portalUrlProvider.getPortalUrlBuilderByPortletFName(
                                request, fname, urlType);
                return portalUrlBuilderByPortletFName;
            }

            if (StringUtils.isNotEmpty(layoutId)) {
                final IPortalUrlBuilder portalUrlBuilderByLayoutNode =
                        this.portalUrlProvider.getPortalUrlBuilderByLayoutNode(
                                request, layoutId, urlType);
                return portalUrlBuilderByLayoutNode;
            }

            return this.portalUrlProvider.getDefaultUrl(request);
        } catch (Exception e) {
            this.logger.error(
                    "Failed to create IPortalUrlBuilder for fname='"
                            + fname
                            + "', layoutId='"
                            + layoutId
                            + "', type='"
                            + type
                            + "'. # will be returned instead.",
                    e);
            return new FailSafePortalUrlBuilder();
        }
    }
249878
public String getNodeNameX(int nodeHandle)
  {

    /** @todo: implement this org.apache.xml.dtm.DTMDefaultBase abstract method */
    error(XMLMessages.createXMLMessage(XMLErrorResources.ER_METHOD_NOT_SUPPORTED, null));//"Not yet supported!");

    return null;
  }
1275869
public void setXPathFunctionResolver(XPathFunctionResolver resolver) {
        if ( resolver == null ) {
            String fmsg = XSLMessages.createXPATHMessage( 
                    XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
                    new Object[] {"XPathFunctionResolver"} );
            throw new NullPointerException( fmsg );
        }
        this.functionResolver = resolver;
    }
461874
public @Nullable String getLinkRootPath(@NotNull Page page, @NotNull String linkTypeId) {
    if (StringUtils.equals(linkTypeId, InternalLinkType.ID)) {
      // inside an experience fragment it does not make sense to use a site root path
      if (Path.isExperienceFragmentPath(page.getPath())) {
        return DEFAULT_ROOT_PATH_CONTENT;
      }
      return AdaptTo.notNull(page.getContentResource(), SiteRoot.class).getRootPath(page);
    }
    else if (StringUtils.equals(linkTypeId, InternalCrossContextLinkType.ID)) {
      return DEFAULT_ROOT_PATH_CONTENT;
    }
    else if (StringUtils.equals(linkTypeId, MediaLinkType.ID)) {
      return DEFAULT_ROOT_PATH_MEDIA;
    }
    return null;
  }
308296
@Override
    public IPortletWindowId getPortletForFolderName(
            HttpServletRequest request, String targetedLayoutNodeId, String folderName) {
        final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);

        final String fname;
        final IPortletEntity portletEntity;

        final int seperatorIndex = folderName.indexOf(PORTLET_PATH_ELEMENT_SEPERATOR);
        if (seperatorIndex <= 0 || seperatorIndex + 1 == folderName.length()) {
            fname = folderName;
            portletEntity =
                    this.portletEntityRegistry.getOrCreatePortletEntityByFname(
                            request, userInstance, fname);
        } else {
            fname = folderName.substring(0, seperatorIndex);
            final String subscribeId = folderName.substring(seperatorIndex + 1);

            portletEntity =
                    this.portletEntityRegistry.getOrCreatePortletEntityByFname(
                            request, userInstance, fname, subscribeId);
        }
        if (portletEntity != null) {
            final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
            final IPortletWindow portletWindow =
                    this.portletWindowRegistry.getOrCreateDefaultPortletWindow(
                            request, portletEntityId);
            return portletWindow.getPortletWindowId();
        } else {
            this.logger.warn(
                    targetedLayoutNodeId
                            + " node for portlet of folder "
                            + folderName
                            + " can't be targeted by the request.");
            return null;
        }
    }
568699
@Override
    public String removeLayoutAttribute(String nodeId, String name) {
        Validate.notEmpty(nodeId, "nodeId cannot be null");
        Validate.notEmpty(name, "name cannot be null");

        final Map<String, String> nodeAttributes = this.layoutAttributes.get(nodeId);
        if (nodeAttributes == null) {
            return null;
        }

        return nodeAttributes.remove(name);
    }
241390
@Override
    public View resolveViewName(String viewName, Locale locale) {
        if (viewName == null) {
            throw new IllegalArgumentException("Method argument viewName must not be null.");
        }

        if (viewName.startsWith(REDIRECT_URL_PREFIX)) {
            String redirectUrl = viewName.substring(REDIRECT_URL_PREFIX.length());
            return new SlingRedirectView(redirectUrl, true, true);
        }

        if (viewName.startsWith(FORWARD_URL_PREFIX)) {
            String forwardUrl = viewName.substring(FORWARD_URL_PREFIX.length());
            return new InternalResourceView(forwardUrl);
        }

        return resolveScriptingView(viewName);
    }
1128081
private String[] getPathElements(CmsXmlContent content, I_CmsXmlContentValue value) {

        List<String> pathElements = new ArrayList<String>();
        String[] paths = value.getPath().split("/");
        String path = "";
        for (int i = 0; i < paths.length; i++) {
            path += paths[i];
            I_CmsXmlContentValue ancestor = content.getValue(path, value.getLocale());
            int valueIndex = ancestor.getXmlIndex();
            if (ancestor.isChoiceOption()) {
                Element parent = ancestor.getElement().getParent();
                valueIndex = parent.indexOf(ancestor.getElement());
            }
            String pathElement = getAttributeName(ancestor);
            pathElements.add(pathElement + "[" + valueIndex + "]");
            if (ancestor.isChoiceType()) {
                pathElements.add("ATTRIBUTE_CHOICE");
            }
            path += "/";
        }
        return pathElements.toArray(new String[pathElements.size()]);
    }
438062
public static PathMappingResult of(String path, @Nullable String query, Map<String, String> rawPathParams) {
        return of(path, query, rawPathParams, LOWEST_SCORE);
    }
77145
function getLayout(layout) {
    if (!layoutCache.hasOwnProperty(layout)) {
      var layoutContents = false,
          layoutPath = path.join(
        path.isAbsolute(options.layoutPath) ?
          options.layoutPath : path.join(process.cwd(), options.layoutPath),
        layout
      );
      try {
        layoutContents = fs.readFileSync(layoutPath, 'utf8');
      } catch (err) {
        throw new PluginError(logFlag, 'Could not read layout: \'' + layoutPath + '\'\n');
      }
      layoutCache[layout] = {
        contents: layoutContents,
        path: layoutPath
      };
    }
    return layoutCache[layout];
  }
591190
public void setLayout(String layout)
    {
        if (layout == null)
        {
            String message = Logging.getMessage("nullValue.StringIsNull");
            Logging.logger().severe(message);
            throw new IllegalArgumentException(message);
        }
        if (!this.layout.equals(layout))
        {
            this.layout = layout;
            clearControls();
        }
    }
1352600
private ResourcePathNode<D> navigateFrom(ResourcePathNode<D> resourcePath) {

    if (isParentDirectory()) {
      ResourcePathNode<D> result = resourcePath;
      ResourcePathNode<D> segment = this;
      do {
        assert (segment.isParentDirectory());
        if (result.isParentDirectory()) {
          return new ResourcePathNode<>(result, segment.name, segment.data);
        } else {
          result = result.navigateUp();
        }
        segment = segment.parent;
      } while (segment.parent != null);
      return result;
    } else if (this.parent == null) {
      return resourcePath;
    } else {
      return new ResourcePathNode<>(this.parent.navigateFrom(resourcePath), this.name, this.data);
    }
  }
858966
public static LocalDocument findLocalDocumentByParentAndUrlName(Folder parentFolder, String urlName) {
    ResourceDAO resourceDAO = new ResourceDAO();
    
    Resource resource = resourceDAO.findByUrlNameAndParentFolder(urlName, parentFolder);
    if (resource instanceof LocalDocument) {
      return (LocalDocument) resource;
    }
    
    return null;
  }
1113866
public MethodNode getDeclaredMethod(String name, Parameter[] parameters) {
        for (MethodNode method :  getDeclaredMethods(name)) {
            if (parametersEqual(method.getParameters(), parameters)) {
                return method;
            }
        }
        return null;
    }