Exemplo n.º 1
0
        //UPGRADE_ISSUE: Class hierarchy differences between 'java.io.Reader' and 'System.IO.StreamReader' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1186'"
        public static Dictionary unmarshal(System.IO.StreamReader reader)
        {
            //LoggingTool //logger = new LoggingTool(typeof(Dictionary));
            DictionaryHandler     handler = new DictionaryHandler();
            XmlSAXDocumentManager parser  = null;

            try
            {
                parser = XmlSAXDocumentManager.NewInstance();
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                //logger.debug("Using " + parser);
            }
            catch (System.Exception e)
            {
                //logger.error("Could not instantiate any JAXP parser!");
                //logger.debug(e);
            }

            try
            {
                parser.setFeature("http://xml.org/sax/features/validation", false);
                //logger.debug("Deactivated validation");
            }
            //UPGRADE_TODO: Class 'org.xml.sax.SAXException' was converted to 'System.Xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
            catch (System.Xml.XmlException e)
            {
                //logger.warn("Cannot deactivate validation.");
                //logger.debug(e);
            }
            parser.setContentHandler(handler);
            Dictionary dict = null;

            try
            {
                parser.parse(new XmlSourceSupport(reader));
                dict = handler.Dictionary;
            }
            catch (System.IO.IOException e)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                //logger.error("IOException: " + e.ToString());
                //logger.debug(e);
            }
            //UPGRADE_TODO: Class 'org.xml.sax.SAXException' was converted to 'System.Xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
            catch (System.Xml.XmlException saxe)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                //logger.error("SAXException: " + saxe.GetType().FullName);
                //logger.debug(saxe);
            }
            return(dict);
        }
Exemplo n.º 2
0
        /// <summary> Triggers the XML parsing of the data file and returns the read Isotopes.
        /// It turns of XML validation before parsing.
        ///
        /// </summary>
        /// <returns> a Vector of Isotope's. Returns an empty vector is some reading error
        /// occured.
        /// </returns>
        public virtual List <PeriodicTableElement> readElements()
        {
            List <PeriodicTableElement> elements = new List <PeriodicTableElement>();

            try
            {
                parser.setFeature("http://xml.org/sax/features/validation", false);
                //logger.info("Deactivated validation");
            }
            //UPGRADE_TODO: Class 'org.xml.sax.SAXException' was converted to 'System.Xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
            catch (System.Xml.XmlException exception)
            {
                //logger.warn("Cannot deactivate validation: ", exception.Message);
                //logger.debug(exception);
            }
            ElementPTHandler handler = new ElementPTHandler();

            parser.setContentHandler(handler);
            try
            {
                parser.parse(new XmlSourceSupport(input));
                elements = new List <PeriodicTableElement>((PeriodicTableElement[])handler.Elements.ToArray(typeof(PeriodicTableElement)));
            }
            catch (System.IO.IOException exception)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                //logger.error("IOException: ", exception.Message);
                //logger.debug(exception);
            }
            //UPGRADE_TODO: Class 'org.xml.sax.SAXException' was converted to 'System.Xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
            catch (System.Xml.XmlException saxe)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                //logger.error("SAXException: ", saxe.GetType().FullName);
                //logger.error(saxe.Message);
                //logger.debug(saxe);
            }
            return(elements);
        }
Exemplo n.º 3
0
        /// <summary> Triggers the XML parsing of the data file and returns the read Isotopes.
        /// It turns of XML validation before parsing.
        ///
        /// </summary>
        /// <returns> a Vector of Isotope's. Returns an empty vector is some reading error
        /// occured.
        /// </returns>
        public virtual System.Collections.ArrayList readIsotopes()
        {
            System.Collections.ArrayList isotopes = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            try
            {
                parser.setFeature("http://xml.org/sax/features/validation", false);
                //logger.info("Deactivated validation");
            }
            //UPGRADE_TODO: Class 'org.xml.sax.SAXException' was converted to 'System.Xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
            catch (System.Xml.XmlException exception)
            {
                //logger.warn("Cannot deactivate validation: ", exception.Message);
                //logger.debug(exception);
            }
            IsotopeHandler handler = new IsotopeHandler(builder);

            parser.setContentHandler(handler);
            try
            {
                parser.parse(new XmlSourceSupport(input));
                isotopes = handler.Isotopes;
            }
            catch (System.IO.IOException exception)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                //logger.error("IOException: ", exception.Message);
                //logger.debug(exception);
            }
            //UPGRADE_TODO: Class 'org.xml.sax.SAXException' was converted to 'System.Xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
            catch (System.Xml.XmlException saxe)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                //logger.error("SAXException: ", saxe.GetType().FullName);
                //logger.error(saxe.Message);
                //logger.debug(saxe);
            }
            return(isotopes);
        }
Exemplo n.º 4
0
		/// <summary>
		/// Returns a clone instance of 'XmlSAXDocumentManager'.
		/// </summary>
		/// <returns>A clone 'XmlSAXDocumentManager' instance.</returns>
		public static XmlSAXDocumentManager CloneInstance(XmlSAXDocumentManager instance)
		{
			XmlSAXDocumentManager temp = new XmlSAXDocumentManager();
			temp.NamespaceAllowed = instance.NamespaceAllowed;
			temp.isValidating = instance.isValidating;
			XmlSaxContentHandler contentHandler = instance.getContentHandler();
			if (contentHandler != null)
				temp.setContentHandler(contentHandler);
			XmlSaxErrorHandler errorHandler = instance.getErrorHandler();
			if (errorHandler != null)
				temp.setErrorHandler(errorHandler);
			temp.setFeature("http://xml.org/sax/features/namespaces", instance.getFeature("http://xml.org/sax/features/namespaces"));
			temp.setFeature("http://xml.org/sax/features/namespace-prefixes", instance.getFeature("http://xml.org/sax/features/namespace-prefixes"));
			temp.setFeature("http://xml.org/sax/features/validation", instance.getFeature("http://xml.org/sax/features/validation"));
			temp.setProperty("http://xml.org/sax/properties/lexical-handler", instance.getProperty("http://xml.org/sax/properties/lexical-handler"));
			temp.parserFileName = instance.parserFileName;
			return temp;
		}
Exemplo n.º 5
0
        // private functions

        private IChemFile readChemFile(IChemFile file)
        {
            //logger.debug("Started parsing from input...");
            ChemFileCDO cdo = new ChemFileCDO(file);

            try
            {
                parser.setFeature("http://xml.org/sax/features/validation", false);
                //logger.info("Deactivated validation");
            }
            //UPGRADE_TODO: Class 'org.xml.sax.SAXException' was converted to 'System.Xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
            catch (System.Xml.XmlException e)
            {
                //logger.warn("Cannot deactivate validation.");
                return(cdo);
            }
            parser.setContentHandler(new CMLHandler((IChemicalDocumentObject)cdo));
            parser.setEntityResolver(new CMLResolver());
            //UPGRADE_TODO: Method 'org.xml.sax.XMLReader.setErrorHandler' was converted to 'XmlSAXDocumentManager.SetErrorHandler' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_orgxmlsaxXMLReadersetErrorHandler_orgxmlsaxErrorHandler'"
            parser.setErrorHandler(new CMLErrorHandler());
            try
            {
                if (input == null)
                {
                    //logger.debug("Parsing from URL: ", url);
                    parser.parse(url);
                }
                else
                {
                    //logger.debug("Parsing from Reader");
                    input.BaseStream.Seek(0, SeekOrigin.Begin);
                    parser.parse(new XmlSourceSupport(input));
                }
            }
            catch (System.IO.IOException e)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                System.String error = "Error while reading file: " + e.Message;
                //logger.error(error);
                //logger.debug(e);
                throw new CDKException(error, e);
            }
            //UPGRADE_TODO: Class 'org.xml.sax.SAXParseException' was converted to 'System.xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
            catch (System.Xml.XmlException saxe)
            {
                //UPGRADE_TODO: Class 'org.xml.sax.SAXParseException' was converted to 'System.xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
                System.Xml.XmlException spe   = (System.Xml.XmlException)saxe;
                System.String           error = "Found well-formedness error in line " + spe.LineNumber;
                //logger.error(error);
                //logger.debug(saxe);
                throw new CDKException(error, saxe);
            }
            //UPGRADE_TODO: Class 'org.xml.sax.SAXException' was converted to 'System.Xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
            //catch (System.Xml.XmlException saxe)
            //{
            //    System.String error = "Error while parsing XML: " + saxe.Message;
            //    //logger.error(error);
            //    //logger.debug(saxe);
            //    throw new CDKException(error, saxe);
            //}
            return(cdo);
        }