Exemplo n.º 1
0
        /// <summary>
        /// Gets the response and modify the headers.
        /// </summary>
        /// <returns>The response.</returns>
        /// <param name="request">Request.</param>
        public override WebResponse getResponse(WebRequest request)
        {
            WebResponse response = base.getResponse(request);

            //
            // Only if Url matches
            //
            if (request.getUrl().toExternalForm().Contains("com"))
            {
                string content = response.getContentAsString("UTF-8");
                java.util.ArrayList newheaders = new java.util.ArrayList();
                java.util.List      headers    = response.getResponseHeaders();
                java.util.Iterator  it         = headers.iterator();
                //
                // Remove the 'Access-Control-Allow-Origin' header
                //
                while (it.hasNext())
                {
                    com.gargoylesoftware.htmlunit.util.NameValuePair o = (com.gargoylesoftware.htmlunit.util.NameValuePair)it.next();
                    if (o.getName().Equals("Access-Control-Allow-Origin"))
                    {
                        string value = response.getResponseHeaderValue("Access-Control-Allow-Origin");
                        Console.WriteLine("Found header 'Access-Control-Allow-Origin' = \"{0}\" and stripping it from new headers for response", value);
                        continue; //headers.remove(o);
                    }
                    newheaders.add(o);
                }
                byte[]          utf  = System.Text.Encoding.UTF8.GetBytes(content);
                WebResponseData data = new WebResponseData(utf,
                                                           response.getStatusCode(), response.getStatusMessage(), newheaders);
                response = new WebResponse(data, request, response.getLoadTime());
                return(response);
            }
            return(response);
        }
Exemplo n.º 2
0
        /*
         * Compares the specified object to this vector and returns if they are
         * equal. The object must be a List which contains the same objects in the
         * same order.
         *
         * @param object
         *            the object to compare with this object
         * @return {@code true} if the specified object is equal to this vector,
         *         {@code false} otherwise.
         * @see #hashCode
         */

        public override bool Equals(Object obj)
        {
            lock (this) {
                if (this == obj)
                {
                    return(true);
                }
                if (obj is java.util.List <Object> )
                {
                    java.util.List <Object> list = (java.util.List <Object>)obj;
                    if (list.size() != elementCount)
                    {
                        return(false);
                    }

                    int index            = 0;
                    Iterator <Object> it = list.iterator();
                    while (it.hasNext())
                    {
                        Object e1 = elementData[index++], e2 = it.next();
                        if (!(e1 == null ? e2 == null : e1.equals(e2)))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                return(false);
            }
        }
Exemplo n.º 3
0
 internal java.util.Iterator <String> getAliases()
 {
     if (aliases == null)
     {
         aliases = new java.util.ArrayList <String>(0);
     }
     return(aliases.iterator());
 }
Exemplo n.º 4
0
        private static IEnumerable <T> Enumerate <T>(java.util.List list)
        {
            var iterator = list.iterator();

            while (iterator.hasNext())
            {
                yield return((T)(iterator.next()));
            }
        }
Exemplo n.º 5
0
        public virtual void  paint(System.Drawing.Graphics g)
        {
            Graphics2D gr = (Graphics2D)g;

            gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            gr.setFont(font);
            Iterator itshapes = shapes.iterator();
            Iterator itarrows = lines.iterator();

            while (itshapes.hasNext())
            {
                Shape s = (Shape)itshapes.next();
                drawPrimitive(s, gr);
            }
            while (itarrows.hasNext())
            {
                ConnectorLine l = (ConnectorLine)itarrows.next();
                drawPrimitive(l, gr);
            }
        }
        /**
         * Subtracts all elements in the second list from the first list,
         * placing the results in a new list.
         * <p>
         * This differs from {@link List#removeAll(Collection)} in that
         * cardinality is respected; if <Code>list1</Code> contains two
         * occurrences of <Code>null</Code> and <Code>list2</Code> only
         * contains one occurrence, then the returned list will still contain
         * one occurrence.
         *
         * @param list1  the list to subtract from
         * @param list2  the list to subtract
         * @return  a new list containing the results
         * @throws NullPointerException if either list is null
         */
        public static java.util.List <Object> subtract(java.util.List <Object> list1, java.util.List <Object> list2)
        {
            java.util.ArrayList <Object> result   = new java.util.ArrayList <Object>(list1);
            java.util.Iterator <Object>  iterator = list2.iterator();

            while (iterator.hasNext())
            {
                result.remove(iterator.next());
            }

            return(result);
        }
 /**
  * Constructs a FixedOrderComparator which uses the order of the given list
  * to compare the objects.
  * <p>
  * The list is copied, so later changes will not affect the comparator.
  *
  * @param items  the items that the comparator can compare in order
  * @throws IllegalArgumentException if the list is null
  */
 public FixedOrderComparator(java.util.List <Object> items)
     : base()
 {
     if (items == null)
     {
         throw new java.lang.IllegalArgumentException("The list of items must not be null");
     }
     for (java.util.Iterator <Object> it = items.iterator(); it.hasNext();)
     {
         add(it.next());
     }
 }
Exemplo n.º 8
0
        public static IEnumerable <T> toIEnumerable <T>(this java.util.List list)
        {
            if (list != null)
            {
                java.util.Iterator itr = list.iterator();

                while (itr.hasNext())
                {
                    yield return((T)itr.next());
                }
            }
        }
Exemplo n.º 9
0
 private System.Object currentValue(java.util.List <IAC_Range> ranges)
 {
     java.util.Iterator <IAC_Range> it = ranges.iterator();
     while (it.hasNext())
     {
         IAC_Range range = it.next();
         if (offset >= range.start && offset < range.end)
         {
             return(inRange(range) ? range.value : null);
         }
     }
     return(null);
 }
Exemplo n.º 10
0
        /**
         * Gets iterator for user listeners.
         *
         * @return iterator for user listeners.
         */
        public java.util.Iterator <T> getUserIterator()
        {
            lock (this)
            {
                if (userList == null)
                {
                    java.util.List <T> emptyList = java.util.Collections <T> .emptyList();

                    return(emptyList.iterator());
                }
                return(new ReadOnlyIterator <T>(userList.iterator()));
            }
        }
Exemplo n.º 11
0
        /**
         * Adds a whole bunch of suggestions, and does not worry about frequency.
         *
         * @param token The token to associate the suggestions with
         * @param suggestions The suggestions
         */
        public void add(Token token, List /*<String>*/ suggestions)
        {
            LinkedHashMap /*<String, Integer>*/ map = (LinkedHashMap)this.suggestions.get(token);

            if (map == null)
            {
                map = new LinkedHashMap/*<String, Integer>*/ ();
                this.suggestions.put(token, map);
            }
            for (var iter = suggestions.iterator(); iter.hasNext();)
            {
                string suggestion = (string)iter.next();
                map.put(suggestion, NO_FREQUENCY_INFO);
            }
        }
        //-----------------------------------------------------------------------

        /**
         * Returns a new list containing all elements that are contained in
         * both given lists.
         *
         * @param list1  the first list
         * @param list2  the second list
         * @return  the intersection of those two lists
         * @throws NullPointerException if either list is null
         */
        public static java.util.List <Object> intersection(java.util.List <Object> list1, java.util.List <Object> list2)
        {
            java.util.ArrayList <Object> result   = new java.util.ArrayList <Object>();
            java.util.Iterator <Object>  iterator = list2.iterator();

            while (iterator.hasNext())
            {
                Object o = iterator.next();

                if (list1.contains(o))
                {
                    result.add(o);
                }
            }

            return(result);
        }
Exemplo n.º 13
0
 private bool inRange(java.util.List <IAC_Range> ranges)
 {
     java.util.Iterator <IAC_Range> it = ranges.iterator();
     while (it.hasNext())
     {
         IAC_Range range = it.next();
         if (range.start >= begin && range.start < end)
         {
             return(!(range.value is java.lang.annotation.Annotation) ||
                    (range.end > begin && range.end <= end));
         }
         else if (range.end > begin && range.end <= end)
         {
             return(!(range.value is java.lang.annotation.Annotation) ||
                    (range.start >= begin && range.start < end));
         }
     }
     return(false);
 }
Exemplo n.º 14
0
        public void inform(ResourceLoader loader)
        {
            string wordFiles = (string)args.get(PROTECTED_TOKENS);

            if (wordFiles != null)
            {
                try
                {
                    File protectedWordFiles = new File(wordFiles);
                    if (protectedWordFiles.exists())
                    {
                        List /*<String>*/ wlist = loader.getLines(wordFiles);
                        //This cast is safe in Lucene
                        protectedWords = new CharArraySet(wlist, false);//No need to go through StopFilter as before, since it just uses a List internally
                    }
                    else
                    {
                        List /*<String>*/ files = StrUtils.splitFileNames(wordFiles);
                        for (var iter = files.iterator(); iter.hasNext();)
                        {
                            string            file  = (string)iter.next();
                            List /*<String>*/ wlist = loader.getLines(file.Trim());
                            if (protectedWords == null)
                            {
                                protectedWords = new CharArraySet(wlist, false);
                            }
                            else
                            {
                                protectedWords.addAll(wlist);
                            }
                        }
                    }
                }
                catch (IOException e)
                {
                    throw new System.ApplicationException("Unexpected exception", e);
                }
            }
        }
Exemplo n.º 15
0
        private static string GetCollationQuery(String origQuery,
                                                java.util.List /*<SpellCheckCorrection>*/ corrections)
        {
            var collation = new java.lang.StringBuilder(origQuery);
            int offset    = 0;

            for (var iter = corrections.iterator(); iter.hasNext();)
            {
                SpellCheckCorrection correction = (SpellCheckCorrection)iter.next();
                Token tok = correction.getOriginal();
                // we are replacing the query in order, but injected terms might cause
                // illegal offsets due to previous replacements.
                if (tok.getPositionIncrement() == 0)
                {
                    continue;
                }
                collation.replace(tok.startOffset() + offset, tok.endOffset() + offset,
                                  correction.getCorrection());
                offset += correction.getCorrection().Length
                          - (tok.endOffset() - tok.startOffset());
            }
            return(collation.toString());
        }
Exemplo n.º 16
0
        /** {@inheritDoc} */
        public override void finish() //throws IOException
        {
            if (finished)
            {
                throw new java.io.IOException("This archive has already been finished");
            }

            if (entry != null)
            {
                throw new java.io.IOException("This archives contains unclosed entries.");
            }

            cdOffset = written;
            for (java.util.Iterator <ZipArchiveEntry> i = entries.iterator(); i.hasNext();)
            {
                writeCentralFileHeader((ZipArchiveEntry)i.next());
            }
            cdLength = written - cdOffset;
            writeCentralDirectoryEnd();
            offsets.clear();
            entries.clear();
            finished = true;
        }
Exemplo n.º 17
0
        public void inform(ResourceLoader loader)
        {
            string commonWordFiles = (string)args.get("words");

            ignoreCase = getBoolean("ignoreCase", false);

            if (commonWordFiles != null)
            {
                try {
                    List /*<String>*/ files = StrUtils.splitFileNames(commonWordFiles);
                    if (commonWords == null && files.size() > 0)
                    {
                        // default stopwords list has 35 or so words, but maybe don't make it
                        // that big to start
                        commonWords = new CharArraySet(files.size() * 10, ignoreCase);
                    }
                    for (var iter = files.iterator(); iter.hasNext();)
                    {
                        string            file  = (string)iter.next();
                        List /*<String>*/ wlist = loader.getLines(file.Trim());
                        // TODO: once StopFilter.makeStopSet(List) method is available, switch
                        // to using that so we can avoid a toArray() call
                        commonWords.addAll(CommonGramsFilter.makeCommonSet((string[])wlist
                                                                           .toArray(new string[0]), ignoreCase));
                    }
                } catch (IOException e) {
                    throw new System.ApplicationException("Unexpected exception", e);
                }
            }
            else
            {
#pragma warning disable 612
                commonWords = CommonGramsFilter.makeCommonSet(
                    StopAnalyzer.ENGLISH_STOP_WORDS, ignoreCase);
#pragma warning restore 612
            }
        }
Exemplo n.º 18
0
        //-----------------------------------------------------------------------

        /**
         * Perform comparisons on the Objects as per
         * Comparator.compare(o1,o2).
         *
         * @param o1  the first object to compare
         * @param o2  the second object to compare
         * @return -1, 0, or 1
         * @exception UnsupportedOperationException
         *                   if the ComparatorChain does not contain at least one
         *                   Comparator
         */
        public int compare(Object o1, Object o2)
        {//throws UnsupportedOperationException {
            if (isLockedJ == false)
            {
                checkChainIntegrity();
                isLockedJ = true;
            }

            // iterate over all comparators in the chain
            java.util.Iterator <Object> comparators = comparatorChain.iterator();
            for (int comparatorIndex = 0; comparators.hasNext(); ++comparatorIndex)
            {
                java.util.Comparator <Object> comparator = (java.util.Comparator <Object>)comparators.next();
                int retval = comparator.compare(o1, o2);
                if (retval != 0)
                {
                    // invert the order if it is a reverse sort
                    if (orderingBits.get(comparatorIndex) == true)
                    {
                        if (java.lang.Integer.MIN_VALUE == retval)
                        {
                            retval = java.lang.Integer.MAX_VALUE;
                        }
                        else
                        {
                            retval *= -1;
                        }
                    }

                    return(retval);
                }
            }

            // if comparators are exhausted, return 0
            return(0);
        }
Exemplo n.º 19
0
        private int runStart(java.util.List <IAC_Range> ranges)
        {
            int result = begin;

            java.util.Iterator <IAC_Range> it = ranges.iterator();
            while (it.hasNext())
            {
                IAC_Range range = it.next();
                if (range.start >= end)
                {
                    break;
                }
                if (offset >= range.start && offset < range.end)
                {
                    return(inRange(range) ? range.start : result);
                }
                else if (offset < range.start)
                {
                    break;
                }
                result = range.end;
            }
            return(result);
        }
 internal ListOrderedIterator(ListOrderedMap parent, java.util.List <Object> insertOrder)
     : base(insertOrder.iterator())
 {
     this.parent = parent;
 }
Exemplo n.º 21
0
 public static readonly ResultDataContent public static ResultDataContent[] fromNames(java.util.List <JavaToDotNetGenericWildcard> names)
 {
     if (names == null || names.isEmpty())
     {
         return(null);
     }
     ResultDataContent[] result = new ResultDataContent[names.size()]; java.util.Iterator <JavaToDotNetGenericWildcard> name = names.iterator(); for (int i = 0; i < result.length; i++)
     {
         Object contentName = name.next(); if (contentName instanceof String)
         {
             try { result[i] = valueOf((( String )contentName).toLowerCase()); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Invalid result data content specifier: " + contentName); }
         }
Exemplo n.º 22
0
        public static Phrase GetTokens(this Tree tree, Tree root = null, Rhetorica.Sentence sentence = null, string ignore = "", string punctuation = null, AnalyzerOptions options = AnalyzerOptions.None)
        {
            var tokens = new Phrase(sentence: sentence);

            java.util.List leaves = tree.getLeaves();

            for (java.util.Iterator i = leaves.iterator(); i.hasNext();)
            {
                Tree   leaf  = (Tree)i.next();
                string token = leaf.value().Trim();

                Tree preterminal = leaf.parent(tree);
                if (preterminal == null)
                {
                    continue;
                }
                string tag = preterminal.value().Trim();

                bool ignoreMeansInclude = options.HasFlag(AnalyzerOptions.IgnoreMeansInclude);
                if (ignore != string.Empty)
                {
                    bool isMatch = Regex.IsMatch(token, ignore);
                    if (ignoreMeansInclude)
                    {
                        if (!isMatch)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (isMatch)
                        {
                            continue;
                        }
                    }
                }

                bool omitPunctuation = options.HasFlag(AnalyzerOptions.OmitPunctuationTokens);
                if (omitPunctuation)
                {
                    // Leave out certain types of punctuation:
                    bool isPunctuation = Regex.IsMatch(tag, punctuation ?? Analyzer.PunctuationPatterns) ||
                                         Regex.IsMatch(token, punctuation ?? Analyzer.PunctuationPatterns);
                    if (isPunctuation)
                    {
                        tokens.IsPunctuationOmitted = true;
                        continue;
                    }

                    // But also remove any straggler punctuation missed within a token...? Maybe not. Use RegExp 'FloatingPunctuationPatterns' if so.
                }

                root = root ?? tree;
                int depth = root.depth() - root.depth(preterminal);

                var characterEdges = new CharacterEdges(root.leftCharEdge(leaf), root.rightCharEdge(leaf));
                tokens.Add(new Token(token, tag, depth, characterEdges));
            }

            return(tokens);
        }