Exemplo n.º 1
0
        // ******************************************************************************
        /// <summary>
        /// Parses a PBL-Path string and creates a structured version of it
        /// </summary>
        /// <param name="pblPath">The PBL-Path as string</param>
        /// <returns>The PBL-Path as structure</returns>
        public static ParsedPblPath ParsePblPath(string pblPath)
        // Code History:
        // 2014-03-18, ~2014-03-20 mws
        {
            var parsedPath = new ParsedPblPath();

            if (string.IsNullOrEmpty(pblPath))
            {
                parsedPath.EndNodeType = PblNodeType.ParseError;
                return(parsedPath);
            }
            parsedPath.EndNodeType = PblNodeType.Undefined;

            string[] pathParts = { "" };        // dummy initializer
            if (pblPath.Contains("@"))
            {                                   // process the separator
                pathParts = pblPath.Split('@'); // pathParts[0] = group roles, others: the reference
                if (pathParts.Length < 2)       // there must be at least the group roles and a reference part
                {
                    parsedPath.EndNodeType = PblNodeType.ParseError;
                    return(parsedPath);
                }
                parsedPath.RefId = pathParts[1];
                if (pathParts.Length > 2)
                {
                    for (int idx = 2; idx <= pathParts.Length; idx++)
                    {
                        parsedPath.RefId += "@" + pathParts[idx];
                    }
                }
                // test the RefId for typical attribute names
                if (parsedPath.RefId.StartsWith("residref="))
                {
                    parsedPath.EndNodeType = PblNodeType.ItemRef;
                }
                if (parsedPath.RefId.StartsWith("href="))
                {
                    parsedPath.EndNodeType = PblNodeType.ItemRef;
                }
                if (parsedPath.RefId.StartsWith("qcode="))
                {
                    parsedPath.EndNodeType = PblNodeType.ContentRef;
                }
                if (parsedPath.RefId.StartsWith("uri="))
                {
                    parsedPath.EndNodeType = PblNodeType.ContentRef;
                }
            }
            else
            {
                parsedPath.EndNodeType = PblNodeType.Group;
            }
            // process the string representing the group roles
            string basePath;

            if (parsedPath.EndNodeType == PblNodeType.ItemRef || parsedPath.EndNodeType == PblNodeType.ContentRef)
            {
                basePath = pathParts[0];
            }
            else
            {
                basePath = pblPath;
            }
            pathParts = basePath.Split('/');
            foreach (string pathPart in pathParts)   // split up the group roles to an ordered sequence
            {
                if (!string.IsNullOrEmpty(pathPart)) // take out the empty parts; in any case the one at the start
                {
                    parsedPath.GroupRoles.Add(pathPart);
                }
            }
            return(parsedPath);
        } // ParsePblPath
Exemplo n.º 2
0
        // Code History:
        // 2014-03-18, ~2014-03-20 mws
        // ******************************************************************************
        /// <summary>
        /// Parses a PBL-Path string and creates a structured version of it
        /// </summary>
        /// <param name="pblPath">The PBL-Path as string</param>
        /// <returns>The PBL-Path as structure</returns>
        public static ParsedPblPath ParsePblPath(string pblPath)
        {
            var parsedPath = new ParsedPblPath();
            if (string.IsNullOrEmpty(pblPath))
            {
                parsedPath.EndNodeType = PblNodeType.ParseError;
                return parsedPath;
            }
            parsedPath.EndNodeType = PblNodeType.Undefined;

            string[] pathParts = { "" }; // dummy initializer
            if (pblPath.Contains("@"))
            {   // process the separator
                pathParts = pblPath.Split('@'); // pathParts[0] = group roles, others: the reference
                if (pathParts.Length < 2) // there must be at least the group roles and a reference part
                {
                    parsedPath.EndNodeType = PblNodeType.ParseError;
                    return parsedPath;
                }
                parsedPath.RefId = pathParts[1];
                if (pathParts.Length > 2)
                {
                    for (int idx = 2; idx <= pathParts.Length; idx++)
                    {
                        parsedPath.RefId += "@" + pathParts[idx];
                    }
                }
                // test the RefId for typical attribute names
                if (parsedPath.RefId.StartsWith("residref="))
                    parsedPath.EndNodeType = PblNodeType.ItemRef;
                if (parsedPath.RefId.StartsWith("href="))
                    parsedPath.EndNodeType = PblNodeType.ItemRef;
                if (parsedPath.RefId.StartsWith("qcode="))
                    parsedPath.EndNodeType = PblNodeType.ContentRef;
                if (parsedPath.RefId.StartsWith("uri="))
                    parsedPath.EndNodeType = PblNodeType.ContentRef;
            }
            else
                parsedPath.EndNodeType = PblNodeType.Group;
            // process the string representing the group roles
            string basePath;
            if (parsedPath.EndNodeType == PblNodeType.ItemRef || parsedPath.EndNodeType == PblNodeType.ContentRef)
                basePath = pathParts[0];
            else
                basePath = pblPath;
            pathParts = basePath.Split('/');
            foreach (string pathPart in pathParts) // split up the group roles to an ordered sequence
            {
                if (!string.IsNullOrEmpty(pathPart)) // take out the empty parts; in any case the one at the start
                    parsedPath.GroupRoles.Add(pathPart);
            }
            return parsedPath;
        }