Beispiel #1
0
 public static List<String> rewrite(java.io.Reader content, Uri source,
                                    ILinkRewriter rewriter, java.io.Writer writer, bool extractImports)
 {
     List<String> imports = new List<string>();
     CharProducer producer = CharProducer.Factory.create(content,
                                                         new InputSource(new java.net.URI(source.ToString())));
     CssLexer lexer = new CssLexer(producer);
     try
     {
         bool inImport = false;
         while (lexer.hasNext())
         {
             Token token = lexer.next();
             if (extractImports)
             {
                 if (token.type == CssTokenType.SYMBOL && token.text.ToLower().Equals("@import"))
                 {
                     inImport = true;
                     continue;
                 }
                 if (inImport)
                 {
                     if (token.type == CssTokenType.URI)
                     {
                         Match matcher = urlMatcher.Match(token.text);
                         if (matcher.Success)
                         {
                             imports.Add(matcher.Groups[2].Value.Trim());
                         }
                     }
                     else if (token.type != CssTokenType.SPACE && token.type != CssTokenType.PUNCTUATION)
                     {
                         inImport = false;
                     }
                 }
                 if (!inImport)
                 {
                     writer.write(token.text);
                 }
             }
             else
             {
                 if (token.type == CssTokenType.URI)
                 {
                     writer.write(rewriteLink(token, source, rewriter));
                     continue;
                 }
                 writer.write(token.text);
             }
         }
         writer.flush();
     }
     catch (ParseException pe)
     {
         pe.printStackTrace();
     }
     catch (Exception ioe)
     {
         throw ioe;
     }
     return imports;
 }
Beispiel #2
0
        public static void rewrite(java.io.Reader content, Uri source,
                                   Dictionary<String, IHtmlTagTransformer> transformers, java.io.Writer writer)
        {
            CharProducer producer = CharProducer.Factory.create(content, new InputSource(new java.net.URI(source.ToString())));
            HtmlLexer lexer = new HtmlLexer(producer);
            try
            {
                Token lastToken = null;
                Token currentTag = null;
                IHtmlTagTransformer currentTransformer = null;
                bool tagChanged;
                while (lexer.hasNext())
                {
                    tagChanged = false;
                    Token token = lexer.next() as Token;
                    if (token.type == HtmlTokenType.IGNORABLE)
                    {
                        continue;
                    }
                    if (token.type == HtmlTokenType.TAGBEGIN)
                    {
                        currentTag = token;
                        tagChanged = true;
                    }
                    if (tagChanged)
                    {
                        if (currentTransformer == null)
                        {
                            transformers.TryGetValue(currentTag.toString().Substring(1).ToLower(), out currentTransformer);
                        }
                        else
                        {
                            if (!currentTransformer.acceptNextTag(currentTag))
                            {
                                writer.write(currentTransformer.close());
                                transformers.TryGetValue(currentTag.toString().Substring(1).ToLower(), out currentTransformer);
                            }
                        }
                    }
                    if (currentTransformer == null)
                    {
                        writer.write(producePreTokenSeparator(token, lastToken));
                        writer.write(token.toString());
                        writer.write(producePostTokenSeparator(token, lastToken));
                    }
                    else
                    {
                        currentTransformer.accept(token, lastToken);
                    }
                    if (token.type == HtmlTokenType.TAGEND)
                    {
                        currentTag = null;
                    }
                    lastToken = token;
                }
                if (currentTransformer != null)
                {
                    writer.write(currentTransformer.close());
                }
                writer.flush();
            }
            catch (Exception pe)
            {
                throw pe;
            }

        }
 /// <summary>
 /// Writes a stream of bytes representing an audio file of the file type
 /// indicated to the output stream provided.
 /// </summary>
 /// <remarks>
 /// Writes a stream of bytes representing an audio file of the file type
 /// indicated to the output stream provided.
 /// </remarks>
 /// <param name="stream">
 /// - the audio input stream containing audio data to be written
 /// to the output stream.
 /// </param>
 /// <param name="out">- stream to which the file data should be written.</param>
 /// <returns>the number of bytes written to the output stream.</returns>
 /// <exception>
 /// IOException
 /// - if an I/O exception occurs.
 /// </exception>
 /// <exception cref="System.IO.IOException"></exception>
 private int write(javax.sound.sampled.AudioInputStream stream, java.io.OutputStream
     @out)
 {
     byte[] data = new byte[2048];
     int read = 0;
     int temp;
     while ((temp = stream.read(data, 0, 2048)) > 0)
     {
         @out.write(data, 0, temp);
         read += temp;
     }
     @out.flush();
     @out.close();
     return read;
 }