Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Print / Reach / PrintConfig / PrtCap_Reader.cs / 1 / PrtCap_Reader.cs
/*++ Copyright (C) 2003 Microsoft Corporation All rights reserved. Module Name: PrtCap_Reader.cs Abstract: Definition and implementation of the private XmlPrintCapReader class. Author: [....] ([....]) 06/22/2003 --*/ using System; using System.Xml; using System.IO; using System.Diagnostics; using System.Globalization; using System.Printing; using MS.Internal.Printing.Configuration; #pragma warning disable 1634, 1691 // Allows suppression of certain PreSharp messages namespace MS.Internal.Printing.Configuration { ////// Reader class of XML PrintCapabilities /// internal class XmlPrintCapReader { #region Constructors ////// Instantiates a reader object for the given XML PrintCapabilities /// ///Constructor verifies the root element is valid ///thrown if XML PrintCapabilities is not well-formed public XmlPrintCapReader(Stream xmlStream) { // Internally the XML PrintCapabilities reader uses XmlTextReader _xmlReader = new XmlTextReader(xmlStream); // We need namespace support from the reader. _xmlReader.Namespaces = true; // Don't resolve external resources. _xmlReader.XmlResolver = null; // Verify root element isin our standard namespace if ((_xmlReader.MoveToContent() != XmlNodeType.Element) || (_xmlReader.LocalName != PrintSchemaTags.Framework.PrintCapRoot) || (_xmlReader.NamespaceURI != PrintSchemaNamespaces.Framework)) { throw NewPrintCapFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.InvalidRootElement"), _xmlReader.NamespaceURI, _xmlReader.LocalName)); } // Verify the XML PrintCapabilities version is supported // For XML attribute without a prefix (e.g. <... name="prn:PageMediaSize">), // even though the XML document has default namespace defined as our standard // Print Schema framework namespace, the XML atribute still has NULL namespaceURI. // It will only have the correct namespaceURI when a prefix is used. This doesn't // apply to XML element, whose namespaceURI works fine with default namespace. // GetAttribute doesn't move the reader cursor away from the current element string version = _xmlReader.GetAttribute(PrintSchemaTags.Framework.RootVersionAttr, PrintSchemaNamespaces.FrameworkAttrForXmlReader); if (version == null) { throw NewPrintCapFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.RootMissingAttribute"), PrintSchemaTags.Framework.RootVersionAttr)); } // Convert string to number to verify decimal versionNum; try { versionNum = XmlConvertHelper.ConvertStringToDecimal(version); } catch (FormatException e) { throw NewPrintCapFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.RootInvalidAttribute"), PrintSchemaTags.Framework.RootVersionAttr, version), e); } if (versionNum != PrintSchemaTags.Framework.SchemaVersion) { throw NewPrintCapFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.VersionNotSupported"), versionNum)); } // Reset internal states to be ready for client's reading of the PrintCapabilities XML ResetCurrentElementState(); } #endregion Constructors #region Public Methods /// /// Moves the reader cursor to the next Print Schema Framework element at the given depth. /// (The element could be Feature, ParameterDefinition, Option, ScoredProperty or Property) /// /// client-requested traversing depth /// flags to indicate client interested node types ///True if next Framework element is ready to read. /// False if no more Framework element at the given depth. ///XML is not well-formed. public bool MoveToNextSchemaElement(int depth, PrintSchemaNodeTypes typeFilterFlags) { bool foundElement = false; while (!foundElement && _xmlReader.Read()) { // Read() throws XmlException if error occurred while parsing the XML. // If we hit an end-element tag at higher depth, we know there are no more // Framework elements at the client-requested depth. if ((_xmlReader.NodeType == XmlNodeType.EndElement) && (_xmlReader.Depth < depth)) { break; } // Stop at the next XML start element at the client-requested depth // and in the standard Framework element namespace. if ((_xmlReader.NodeType != XmlNodeType.Element) || (_xmlReader.Depth != depth) || (_xmlReader.NamespaceURI != PrintSchemaNamespaces.Framework)) { continue; } // Find a candidate, so reset internal states to be ready for its parsing. ResetCurrentElementState(); foundElement = true; _currentElementDepth = depth; _currentElementIsEmpty = _xmlReader.IsEmptyElement; // Map element name to Schema node type int enumValue = PrintSchemaMapper.SchemaNameToEnumValueWithMap( PrintSchemaTags.Framework.NodeTypeMapTable, _xmlReader.LocalName); if (enumValue > 0) { _currentElementNodeType = (PrintSchemaNodeTypes)enumValue; } else { #if _DEBUG Trace.WriteLine("-Warning- skip unknown element '" + _xmlReader.LocalName + "' at line " + _xmlReader.LineNumber + ", position " + _xmlReader.LinePosition); #endif foundElement = false; } if (foundElement) { // Check whether or not the found element type is what client is interested in. // If not, we will skip this element. if ((CurrentElementNodeType & typeFilterFlags) == 0) { #if _DEBUG Trace.WriteLine("-Warning- skip not-wanted element '" + _xmlReader.LocalName + "' at line " + _xmlReader.LineNumber + ", position " + _xmlReader.LinePosition); #endif foundElement = false; } } if (foundElement) { // The element is what the client wants. if (CurrentElementNodeType != PrintSchemaNodeTypes.Value) { // Element other thanshould have the "name" XML attribute. // Reader will verify the "name" XML attribute has a QName value that // is in our standard Keyword namespace. string QName = _xmlReader.GetAttribute(PrintSchemaTags.Framework.NameAttr, PrintSchemaNamespaces.FrameworkAttrForXmlReader); // Only
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- StoreItemCollection.Loader.cs
- ConfigurationValues.cs
- Types.cs
- PackagePartCollection.cs
- StartFileNameEditor.cs
- ListSortDescriptionCollection.cs
- UserPreferenceChangingEventArgs.cs
- FillRuleValidation.cs
- List.cs
- XmlNavigatorFilter.cs
- HttpCookieCollection.cs
- CompilerHelpers.cs
- _FtpControlStream.cs
- InheritanceRules.cs
- Converter.cs
- Journaling.cs
- Automation.cs
- XmlSchemaAttributeGroup.cs
- IPeerNeighbor.cs
- XmlSchemaSimpleContentExtension.cs
- OleDbEnumerator.cs
- Viewport2DVisual3D.cs
- CompilerGeneratedAttribute.cs
- CollectionView.cs
- ReferencedCollectionType.cs
- _CacheStreams.cs
- AsyncPostBackErrorEventArgs.cs
- WebPartManager.cs
- InheritanceAttribute.cs
- DoubleLinkListEnumerator.cs
- FileCodeGroup.cs
- DocumentSchemaValidator.cs
- PermissionSet.cs
- DataStorage.cs
- CollectionsUtil.cs
- GridViewPageEventArgs.cs
- sqlser.cs
- NamedPermissionSet.cs
- CommandBinding.cs
- BinaryConverter.cs
- Typeface.cs
- X509Utils.cs
- ConcurrentStack.cs
- IOException.cs
- EnumConverter.cs
- TypedReference.cs
- RectangleGeometry.cs
- ConnectionDemuxer.cs
- XmlHierarchyData.cs
- UnmanagedBitmapWrapper.cs
- Rectangle.cs
- NameValuePair.cs
- OptionalRstParameters.cs
- PermissionSet.cs
- PackagingUtilities.cs
- FlagsAttribute.cs
- BorderGapMaskConverter.cs
- UpdatePanelControlTrigger.cs
- PerformanceCountersBase.cs
- OutOfProcStateClientManager.cs
- SecurityHelper.cs
- MemoryFailPoint.cs
- SchemaImporterExtension.cs
- SharedStatics.cs
- XamlLoadErrorInfo.cs
- DataMember.cs
- XmlSchemaException.cs
- WebPartPersonalization.cs
- PropertyInfoSet.cs
- AudioSignalProblemOccurredEventArgs.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs
- XmlTextReader.cs
- MergeExecutor.cs
- ErrorsHelper.cs
- ReflectionPermission.cs
- DataBoundLiteralControl.cs
- DataGridViewAutoSizeColumnModeEventArgs.cs
- ItemContainerGenerator.cs
- CallContext.cs
- SystemDiagnosticsSection.cs
- HttpDebugHandler.cs
- TreeViewImageKeyConverter.cs
- SyndicationElementExtensionCollection.cs
- _CommandStream.cs
- AQNBuilder.cs
- PipelineModuleStepContainer.cs
- NameSpaceExtractor.cs
- BindingMemberInfo.cs
- CodeFieldReferenceExpression.cs
- baseaxisquery.cs
- documentation.cs
- WebServiceClientProxyGenerator.cs
- HttpCacheVaryByContentEncodings.cs
- AffineTransform3D.cs
- RequestBringIntoViewEventArgs.cs
- SchemaCollectionPreprocessor.cs
- RuntimeConfigLKG.cs
- WinFormsSpinner.cs
- IdentifierCollection.cs
- EUCJPEncoding.cs