示例#1
0
            /// <exception cref="System.IO.IOException"/>
            private FileChecksum GetFileChecksum(string f)
            {
                HttpURLConnection connection = this._enclosing.OpenConnection("/fileChecksum" + ServletUtil
                                                                              .EncodePath(f), "ugi=" + this._enclosing.GetEncodedUgiParameter());

                try
                {
                    XMLReader xr = XMLReaderFactory.CreateXMLReader();
                    xr.SetContentHandler(this);
                    xr.Parse(new InputSource(connection.GetInputStream()));
                }
                catch (SAXException e)
                {
                    Exception embedded = e.GetException();
                    if (embedded != null && embedded is IOException)
                    {
                        throw (IOException)embedded;
                    }
                    throw new IOException("invalid xml directory content", e);
                }
                finally
                {
                    connection.Disconnect();
                }
                return(this.filechecksum);
            }
 /// <summary>Loads edits file, uses visitor to process all elements</summary>
 /// <exception cref="System.IO.IOException"/>
 public override void LoadEdits()
 {
     try
     {
         XMLReader xr = XMLReaderFactory.CreateXMLReader();
         xr.SetContentHandler(this);
         xr.SetErrorHandler(this);
         xr.SetDTDHandler(null);
         xr.Parse(new InputSource(fileReader));
         visitor.Close(null);
     }
     catch (SAXParseException e)
     {
         System.Console.Out.WriteLine("XML parsing error: " + "\n" + "Line:    " + e.GetLineNumber
                                          () + "\n" + "URI:     " + e.GetSystemId() + "\n" + "Message: " + e.Message);
         visitor.Close(e);
         throw new IOException(e.ToString());
     }
     catch (SAXException e)
     {
         visitor.Close(e);
         throw new IOException(e.ToString());
     }
     catch (RuntimeException e)
     {
         visitor.Close(e);
         throw;
     }
     finally
     {
         fileReader.Close();
     }
 }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:TextStyles.Android.CustomHtmlParser"/> class.
        /// </summary>
        /// <param name="source">Source.</param>
        /// <param name="textStyles">Text styles.</param>
        /// <param name="defaultStyleID">Default style identifier.</param>
        public CustomHtmlParser(string source, Dictionary <string, TextStyleParameters> textStyles, string defaultStyleID = null)
        {
            _htmlSource   = source;
            _styles       = textStyles;
            _defaultStyle = String.IsNullOrEmpty(defaultStyleID) ? null : _styles [defaultStyleID];

            _spannableStringBuilder = new SpannableStringBuilder();
            _reader      = XMLReaderFactory.CreateXMLReader("org.ccil.cowan.tagsoup.Parser");
            _imageGetter = null;
            _tagHandler  = new CustomTagHandler(textStyles);
        }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:TextStyles.Android.CustomHtmlParser"/> class.
        /// </summary>
        /// <param name="source">Source.</param>
        /// <param name="textStyles">Text styles.</param>
        /// <param name="defaultStyleID">Default style identifier.</param>
        public CustomHtmlParser(TextStyle instance, string source, Dictionary <string, TextStyleParameters> textStyles, string defaultStyleID = null)
        {
            _instance   = instance;
            _htmlSource = source;
            _styles     = textStyles;

            if (!String.IsNullOrEmpty(defaultStyleID) && _styles.ContainsKey(defaultStyleID))
            {
                _defaultStyle = _styles [defaultStyleID];
            }

            _spannableStringBuilder = new SpannableStringBuilder();
            _reader      = XMLReaderFactory.CreateXMLReader("org.ccil.cowan.tagsoup.Parser");
            _imageGetter = null;
            _tagHandler  = new CustomTagHandler(_instance, _styles);
        }
 protected override IDanmakus Parse()
 {
     try
     {
         if (MDataSource != null)
         {
             AndroidFileSource source         = (AndroidFileSource)MDataSource;
             IXMLReader        xmlReader      = XMLReaderFactory.CreateXMLReader();
             XmlContentHandler contentHandler = new XmlContentHandler(this);
             xmlReader.ContentHandler = contentHandler;
             var inputSource = new InputSource(source.DataStream);
             xmlReader.Parse(inputSource);
             return(contentHandler.Result);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
     }
     return(new Danmakus());
 }
示例#6
0
        private static void extractFunctionData(FunctionDataCollector fdc, InputStream is1)
        {
            XMLReader xr;

            try
            {
                // First up, try the default one
                xr = XMLReaderFactory.CreateXMLReader();
            }
            catch (SAXException e)
            {
                // Try one for java 1.4
                System.SetProperty("org.xml.sax.driver", "org.apache.crimson.Parser.XMLReaderImpl");
                try
                {
                    xr = XMLReaderFactory.CreateXMLReader();
                }
                catch (SAXException e2)
                {
                    throw new RuntimeException(e2);
                }
            }
            xr.SetContentHandler(new EFFDocHandler(fdc));

            InputSource inSrc = new InputSource(is1);

            try
            {
                xr.Parse(inSrc);
                is1.Close();
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }
            catch (SAXException e)
            {
                throw new RuntimeException(e);
            }
        }
示例#7
0
 /// <exception cref="System.IO.IOException"/>
 private void FetchList(string path, bool recur)
 {
     try
     {
         XMLReader xr = XMLReaderFactory.CreateXMLReader();
         xr.SetContentHandler(this);
         HttpURLConnection connection = this._enclosing.OpenConnection("/listPaths" + ServletUtil
                                                                       .EncodePath(path), "ugi=" + this._enclosing.GetEncodedUgiParameter() + (recur ?
                                                                                                                                               "&recursive=yes" : string.Empty));
         InputStream resp = connection.GetInputStream();
         xr.Parse(new InputSource(resp));
     }
     catch (SAXException e)
     {
         Exception embedded = e.GetException();
         if (embedded != null && embedded is IOException)
         {
             throw (IOException)embedded;
         }
         throw new IOException("invalid xml directory content", e);
     }
 }
示例#8
0
            /// <summary>Connect to the name node and get content summary.</summary>
            /// <param name="path">The path</param>
            /// <returns>The content summary for the path.</returns>
            /// <exception cref="System.IO.IOException"/>
            private ContentSummary GetContentSummary(string path)
            {
                HttpURLConnection connection = this._enclosing.OpenConnection("/contentSummary" +
                                                                              ServletUtil.EncodePath(path), "ugi=" + this._enclosing.GetEncodedUgiParameter()
                                                                              );
                InputStream @in = null;

                try
                {
                    @in = connection.GetInputStream();
                    XMLReader xr = XMLReaderFactory.CreateXMLReader();
                    xr.SetContentHandler(this);
                    xr.Parse(new InputSource(@in));
                }
                catch (FileNotFoundException)
                {
                    //the server may not support getContentSummary
                    return(null);
                }
                catch (SAXException saxe)
                {
                    Exception embedded = saxe.GetException();
                    if (embedded != null && embedded is IOException)
                    {
                        throw (IOException)embedded;
                    }
                    throw new IOException("Invalid xml format", saxe);
                }
                finally
                {
                    if (@in != null)
                    {
                        @in.Close();
                    }
                    connection.Disconnect();
                }
                return(this.contentsummary);
            }
示例#9
0
文件: AmazonS3.cs 项目: shoff/ngit
            /// <exception cref="System.IO.IOException"></exception>
            internal void List()
            {
                IDictionary <string, string> args = new SortedDictionary <string, string>();

                if (this.prefix.Length > 0)
                {
                    args.Put("prefix", this.prefix);
                }
                if (!this.entries.IsEmpty())
                {
                    args.Put("marker", this.prefix + this.entries[this.entries.Count - 1]);
                }
                for (int curAttempt = 0; curAttempt < this._enclosing.maxAttempts; curAttempt++)
                {
                    HttpURLConnection c = this._enclosing.Open("GET", this.bucket, string.Empty, args
                                                               );
                    this._enclosing.Authorize(c);
                    switch (HttpSupport.Response(c))
                    {
                    case HttpURLConnection.HTTP_OK:
                    {
                        this.truncated = false;
                        this.data      = null;
                        XMLReader xr;
                        try
                        {
                            xr = XMLReaderFactory.CreateXMLReader();
                        }
                        catch (SAXException)
                        {
                            throw new IOException(JGitText.Get().noXMLParserAvailable);
                        }
                        xr.SetContentHandler(this);
                        InputStream @in = c.GetInputStream();
                        try
                        {
                            xr.Parse(new InputSource(@in));
                        }
                        catch (SAXException parsingError)
                        {
                            IOException p;
                            p = new IOException(MessageFormat.Format(JGitText.Get().errorListing, this.prefix
                                                                     ));
                            Sharpen.Extensions.InitCause(p, parsingError);
                            throw p;
                        }
                        finally
                        {
                            @in.Close();
                        }
                        return;
                    }

                    case HttpURLConnection.HTTP_INTERNAL_ERROR:
                    {
                        continue;
                        goto default;
                    }

                    default:
                    {
                        throw this._enclosing.Error("Listing", this.prefix, c);
                    }
                    }
                }
                throw this._enclosing.MaxAttempts("Listing", this.prefix);
            }