Exemple #1
0
        public ParsedUri Perform(ParsedUri input)
        {
            ParsedUri result = null;

            if (input != null && match != null)
            {
                String str     = input.ToString();
                Match  matcher = match.Match(str);
                if (matcher.Success)
                {
                    if (replace == null)
                    {
                        replace = "";
                    }
                    Debug.WriteLine(matcher.Groups[0].Value + " " + matcher.Groups[1].Value);
                    String rez = input.ToString().Replace(matcher.Groups[0].Value, replace);
                    for (int i = 1; i < matcher.Groups.Count; i++)
                    {
                        rez = rez.Replace("$" + i, matcher.Groups[i].Value);
                    }

                    result = new ParsedUri(rez);
                }
            }
            return(result);
        }
Exemple #2
0
        /// <summary>
        ///
        /// Encapsulate the oodss client requst in a simpler GetMetadata call.
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public async Task <Document> RequestMetadata(ParsedUri uri)
        {
            Document result = null;

            if (_metadataClient != null)
            {
                Debug.WriteLine("Performing asynchronous call");
                ResponseMessage metadataResponse =
                    _metadataClient.RequestAsync(new MetadataRequest(uri.ToString())).Result;
                Debug.WriteLine("Received asynchronous request ");

                if (metadataResponse != null && metadataResponse is MetadataResponse)
                {
                    result = (metadataResponse as MetadataResponse).Metadata;
                }
                else if (metadataResponse != null && metadataResponse is SemanticServiceError)
                {
                    (metadataResponse as SemanticServiceError).Perform();
                }
                else
                {
                    throw new Exception();
                }
            }
            else
            {
                var requestUri = new ParsedUri(_serviceBaseUri, "?url=" + uri.AbsoluteUri);
                result = await _metadataTypeScope.DeserializeUri(requestUri, Format.Xml) as Document;
            }

            return(result);
        }
Exemple #3
0
        public void Test()
        {
            char separator = '/';
            PrefixCollection <Object> pc = new PrefixCollection <Object>(separator);

            StringBuilder buffy = new StringBuilder(32);

            for (int i = 0; i < TEST_ADD.Length; i++)
            {
                //			println(TEST[i].directoryString());
                PrefixPhrase <Object> pp = pc.Add(TEST_ADD[i]);
                buffy.Clear();
                pp.ToStringBuilder(buffy, separator);
                Console.WriteLine(buffy);
            }
            Console.WriteLine("\n");

            for (int i = 0; i < TEST_MATCH.Length; i++)
            {
                ParsedUri purl = TEST_MATCH[i];

                Console.WriteLine(purl.ToString() + "\t" + pc.Match(purl));
            }
            Console.WriteLine("\n");

            foreach (String phrase in pc.Values())
            {
                Console.WriteLine(phrase);
            }
        }
        public PrefixPhrase <O> Add(ParsedUri purl)
        {
            String host = purl.Host;        //edit
            // domainPrefix is a child of this, the root (with no parent)
            PrefixPhrase <O> hostPrefix = GetPrefix(null, host);

            // children of hostPrefix
            String pathStringToParse = usePathFile ? purl.ToString() : purl.LocalPath;        //.pathDirectoryString;

            return((hostPrefix != null) ? hostPrefix.Add(pathStringToParse, separator) : LookupChild(host));
        }
        ///<summary>
        /// Extract location ParsedURL parameters into a HashMap.
        /// Let ParamOps operate on this Map.
        /// Derive a new ParsedURL using the base of the original location's ParsedURL and the transformed parameter map.
        /// If the new ParsedURL is different than the old one, make the old one an additional location for this,
        /// and add the transformed ParsedURL to the DocumentLocationMap.
        /// <p/>
        /// If the location changes, then reconnect to the new one.
        ///</summary>
        public override Object Perform(Object obj) // throws IOException
        {
            bool     usingThisDoc = true;          // if we are changing this document's location, or its child field's location
            Document document     = (Document)SemanticOperationHandler.SemanticOperationVariableMap.Get(SemanticOperationKeyWords.Metadata);

            if (ObjectStr != null)
            {
                Object o = SemanticOperationHandler.SemanticOperationVariableMap.Get(ObjectStr);
                if (o != null && o is Document)
                {
                    document     = (Document)o;
                    usingThisDoc = false;
                }
            }

            ParsedUri origLocation = document.Location.value;

            if (origLocation.IsFile)
            {
                Debug.WriteLine("Not doing <filter_location> because this is a file: " + origLocation);
                return(null);
            }

            SemanticsGlobalCollection <Document> globalCollection = SemanticOperationHandler.SemanticsScope.GlobalDocumentCollection;
            bool locationChanged = false;

            if (paramOps != null && paramOps.Count > 0)
            {
                Dictionary <String, String> parametersMap = new Dictionary <string, string>();

                foreach (String param in origLocation.Query.Split('&'))
                {
                    parametersMap.Add(param.Split('=')[0], param.Split('=')[1]);
                }

                if (parametersMap.Count == 0)
                {
                    parametersMap = new Dictionary <string, string>(paramOps.Count);
                }
                foreach (ParamOp paramOp in paramOps)
                {
                    paramOp.SemanticHandler = SemanticOperationHandler;
                    paramOp.TransformParams(parametersMap);
                }

                String str = origLocation.AbsolutePath + "?";
                foreach (KeyValuePair <string, string> pair in parametersMap)
                {
                    str += pair.Key + "=" + pair.Value + "&";
                }
                if (str[str.Length - 1] == '&')
                {
                    str = str.Substring(0, str.Length - 1);
                }

                ParsedUri transformedLocation = new ParsedUri(str);

                if (origLocation != transformedLocation)
                {
                    document.Location.Value = transformedLocation;

                    locationChanged = true;
                }
            }
            if (alternativeHosts != null)
            {
                String origHost = origLocation.Host;
                foreach (String alternativeHost in alternativeHosts)
                {
                    if (!origHost.Equals(alternativeHost))
                    {
                        ParsedUri newLocation = new ParsedUri(origLocation.AbsoluteUri.Replace(origLocation.Host, alternativeHost));
                        document.AddAdditionalLocation(new MetadataParsedURL(newLocation));
                        globalCollection.AddDocument(document, newLocation);
                    }
                }
            }
            if (regex != null)
            {
                ParsedUri location = document.Location.Value;
                ParsedUri regexURL = regex.Perform(location);

                document.ChangeLocation(regexURL);


                locationChanged = true;
            }
            if (stripPrefix != null)
            {
                String origlLocationString = origLocation.ToString();
                int    index = origlLocationString.IndexOf(stripPrefix);
                if (index > 6)
                {
                    String    newLocationString = origlLocationString.Substring(0, index);
                    ParsedUri newLocation       = new ParsedUri(newLocationString);
                    if (newLocation != null)
                    {
                        document.ChangeLocation(newLocation);
                    }
                }
            }
            if (locationChanged && usingThisDoc) // if we are just changing the location of a field, we don't have to reconnect.
            {
                if (documentParser != null)
                {
                    //documentParser.reConnect(); // changed the location, so we better connect again!
                }
                else
                {
                    //imageClosure.RequestMetadata();
                }
            }
            return(null);
        }
Exemple #6
0
        /// <summary>
        ///  Get MetaMetadata. First, try matching by url_base. If this fails, including if the attribute is
        ///  null, then try by url_prefix. If this fails, including if the attribute is null, then try by
        ///  url_pattern (regular expression).
        ///  <p/>
        /// If that lookup fails, then lookup by tag name, to acquire the default.
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="tagName"></param>
        /// <returns></returns>
        public MetaMetadata GetDocumentMM(ParsedUri uri, String tagName = DocumentParserTagNames.DocumentTag)
        {
            MetaMetadata result = null;

            if (uri != null)
            {
                if (!uri.IsFile)
                {
                    //String noAnchorNoQueryPageString = uri.GetLeftPart(UriPartial.Path);
                    String noAnchorNoQueryPageString = FundamentalPlatformSpecifics.Get().GetUriLeftPart(uri);

                    _documentRepositoryByUrlStripped.TryGetValue(noAnchorNoQueryPageString, out result);

                    if (result == null)
                    {
                        //Check to see if the url prefix is actually a url-path tree.
                        //TODO: For url-path-tree cases, we should just generate a regex to handle those cases.
                        PrefixPhrase <MetaMetadata> matchingPrefix = urlPrefixCollection.getMatchingPrefix(uri);
                        if (matchingPrefix != null)
                        {
                            result = matchingPrefix.MappedObject;
                        }
                    }

                    if (result == null)
                    {
                        String domain = uri.Domain;
                        if (domain != null)
                        {
                            List <RepositoryPatternEntry> entries = null;
                            _documentRepositoryByPattern.TryGetValue(domain, out entries);

                            if (entries != null)
                            {
                                foreach (RepositoryPatternEntry entry in entries)
                                {
                                    Match matcher = entry.Pattern.Match(uri.ToString());
                                    if (matcher.Success)
                                    {
                                        result = entry.MetaMetadata;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                // be careful of the order! suffix before domain

                if (result == null)
                {
                    String suffix = uri.Suffix;

                    if (suffix != null)
                    {
                        result = GetMMBySuffix(suffix);
                    }
                }
                if (result == null)
                {
                    String domain = uri.Domain;
                    _documentRepositoryByDomain.TryGetValue(domain, out result);

                    if (result != null)
                    {
                        Debug.WriteLine("Matched by domain = " + domain + "\t" + result);
                    }
                }
            }
            if (result == null)
            {
                result = GetMMByName(tagName);
            }

            return(result);
        }