public virtual void SetFeature(string name, bool value) { if (_parent != null) { _parent.SetFeature(name, value); } else { throw new SAXNotRecognizedException("Feature: " + name); } }
public XhtmlParser(PeterO.Support.InputStream source, string address, string charset, string lang) { if(source==null)throw new ArgumentException(); if(address!=null && address.Length>0){ URL url=URL.parse(address); if(url==null || url.getScheme().Length==0) throw new ArgumentException(); } this.contentLang=HeaderParser.getLanguages(lang); this.address=address; try { this.reader=new PeterO.Support.SaxReader(); } catch (SaxException e) { if(e.InnerException is IOException) throw (IOException)(e.InnerException); throw new IOException("",e); } handler=new XhtmlContentHandler(this); try { reader.SetFeature("http://xml.org/sax/features/namespaces",true); reader.SetFeature("http://xml.org/sax/features/use-entity-resolver2",true); reader.SetFeature("http://xml.org/sax/features/namespace-prefixes",true); reader.LexicalHandler=(handler); } catch (SaxException e) { throw new NotSupportedException("",e); } reader.ContentHandler=(handler); reader.EntityResolver=(handler); charset=TextEncoding.resolveEncoding(charset); if(charset==null){ charset=sniffEncoding(source); if(charset==null) { charset="utf-8"; } } this.isource=new InputSource<Stream>(source); this.isource.Encoding=(charset); this.encoding=charset; }
/// <summary>See <see href="http://www.saxproject.org/apidoc/org/xml/sax/helpers/XMLFilterImpl.html#setFeature(java.lang.String, boolean)"> /// setFeature(java.lang.String, boolean)</see> on www.saxproject.org.</summary> /// <remarks>Difference to Java: Will throw <see cref="SaxException"/> /// if parent is <c>null</c>.</remarks> public void SetFeature(string name, bool value) { CheckParent(); parent.SetFeature(name, value); }
/// <summary> /// Handles the output of the results of trying to set the feature. Returns true if the /// feature can be set without exception. /// </summary> public bool TryFeature(string feature, IXmlReader parser) { int slashPos = feature.LastIndexOf('/'); string featureName = feature.Substring(slashPos + 1); try { if (!parser.GetFeature(feature)) parser.SetFeature(feature, true); writer.WriteLine(" <" + featureName + ">true</" + featureName + ">"); return true; } catch { writer.WriteLine(" <" + featureName + ">false</" + featureName + ">"); return false; } }
/// <summary> /// Handles setting the feature. /// </summary> public void SetFeature(string feature, IXmlReader parser, bool flag) { if (parser.GetFeature(feature) != flag) parser.SetFeature(feature, flag); }