PartGenerator takes as input elements with attributes like class="LexSense" fieldType="mlstring" restrictions="customOnly" and generates a sequence of clones of the first non-comment child of the generate element, one for each field indicated by the parameters.
Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="root"></param>
        /// <param name="cache"></param>
        /// <param name="keyAttrNames"></param>
        /// <param name="vc">for parts/layouts</param>
        /// <param name="rootClassId">class of the root object used to compute parts/layouts</param>
        /// <returns></returns>
        static private List <XmlNode> GetGeneratedChildren(XmlNode root, FdoCache cache, string[] keyAttrNames,
                                                           XmlVc vc, int rootClassId)
        {
            List <XmlNode> result = new List <XmlNode>();
            string         generateModeForColumns = XmlUtils.GetOptionalAttributeValue(root, "generate");
            bool           m_fGenerateChildPartsForParentLayouts = (generateModeForColumns == "childPartsForParentLayouts");

            // childPartsForParentLayouts
            foreach (XmlNode child in root.ChildNodes)
            {
                if (child is XmlComment)
                {
                    continue;
                }
                if (m_fGenerateChildPartsForParentLayouts)
                {
                    ChildPartGenerator cpg = new ChildPartGenerator(cache, child, vc, rootClassId);
                    cpg.GenerateChildPartsIfNeeded();
                }
                if (child.Name != "generate")
                {
                    result.Add(child);
                    continue;
                }

                PartGenerator generator;
                if (generateModeForColumns == "objectValuePartsForParentLayouts")
                {
                    generator = new ObjectValuePartGenerator(cache, child, vc, rootClassId);
                }
                else
                {
                    generator = new PartGenerator(cache, child, vc, rootClassId);
                }
                foreach (XmlNode genNode in generator.Generate())
                {
                    bool match = false;
                    if (keyAttrNames != null)
                    {
                        foreach (XmlNode matchNode in root.ChildNodes)
                        {
                            if (MatchNodes(matchNode, genNode, keyAttrNames))
                            {
                                match = true;
                                break;
                            }
                        }
                    }
                    if (!match)                     // not already present, or not checking; add it.
                    {
                        result.Add(genNode);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 2
0
		public void GenerateMlString()
		{
			XmlDocument docSrc = new XmlDocument();
			docSrc.LoadXml(
				"<generate class=\"LexEntry\" fieldType=\"mlstring\" restrictions=\"none\"> "
					+"<column label=\"$label\"> "
						+"<seq field=\"Senses\" sep=\"$delimiter:commaSpace\"> "
						+"<string field=\"$fieldName\" ws=\"$ws:analysis\"/> "
						+"</seq> "
					+"</column> "
				+"</generate>");
			XmlNode source = TestXmlViewsUtils.GetRootNode(docSrc, "generate");
			Assert.IsNotNull(source);

			PartGenerator generator = new PartGenerator(Cache, source);

			string[] fields = generator.FieldNames;
			Assert.AreEqual(7, fields.Length);
			Assert.IsTrue(StringArrayIncludes(fields, "CitationForm"));
			Assert.IsTrue(StringArrayIncludes(fields, "Bibliography"));
			Assert.IsTrue(StringArrayIncludes(fields, "Comment"));
			Assert.IsTrue(StringArrayIncludes(fields, "LiteralMeaning"));
			Assert.IsTrue(StringArrayIncludes(fields, "Restrictions"));
			Assert.IsTrue(StringArrayIncludes(fields, "SummaryDefinition"));
			Assert.IsTrue(StringArrayIncludes(fields, "MyRestrictions"));

			XmlNode[] results = generator.Generate();

			Assert.AreEqual(7, results.Length);

			XmlDocument docExpected = new XmlDocument();

			// LT-6956 : sense the test is calling Generate - add the "originalLabel" attribute.
			docExpected.LoadXml(
				"<column label=\"CitationForm\" originalLabel=\"CitationForm\" > "
					+"<seq field=\"Senses\" sep=\"$delimiter:commaSpace\"> "
					+"<string field=\"CitationForm\" ws=\"$ws:analysis\" class=\"LexEntry\"/> "
					+"</seq> "
				+"</column>");
			XmlNode expected = TestXmlViewsUtils.GetRootNode(docExpected, "column");

			Assert.IsTrue(SomeNodeMatches(results, expected), "CitationForm field is wrong");

			XmlDocument docExpected2 = new XmlDocument();
			docExpected2.LoadXml(
				"<column label=\"Bibliography\" originalLabel=\"Bibliography\"> "
				+"<seq field=\"Senses\" sep=\"$delimiter:commaSpace\"> "
				+"<string field=\"Bibliography\" ws=\"$ws:analysis\" class=\"LexEntry\"/> "
				+"</seq> "
				+"</column>");
			XmlNode expected2 = TestXmlViewsUtils.GetRootNode(docExpected2, "column");
			Assert.IsTrue(SomeNodeMatches(results, expected2), "Bibliography field is wrong");

			XmlDocument docExpected3 = new XmlDocument();
			docExpected3.LoadXml(
				"<column label=\"MyRestrictions\" originalLabel=\"MyRestrictions\"> "
				+"<seq field=\"Senses\" sep=\"$delimiter:commaSpace\"> "
				+"<string field=\"MyRestrictions\" ws=\"$ws:analysis\" class=\"LexEntry\"/> "
				+"</seq> "
				+"</column>");
			XmlNode expected3 = TestXmlViewsUtils.GetRootNode(docExpected3, "column");
			Assert.IsTrue(SomeNodeMatches(results, expected3), "generated MyRestrictions field is wrong");
		}
Exemplo n.º 3
0
		public void GenerateMlCustomString()
		{
			XmlDocument docSrc = new XmlDocument();
			docSrc.LoadXml(
				"<generate class=\"LexEntry\" fieldType=\"mlstring\" restrictions=\"customOnly\"> "
				+"<column label=\"$label\"> "
				+"<seq field=\"Senses\" sep=\"$delimiter:commaSpace\"> "
				+"<string field=\"$fieldName\" ws=\"$ws:analysis\" class=\"LexEntry\"/> "
				+"</seq> "
				+"</column> "
				+"</generate>");
			XmlNode source = TestXmlViewsUtils.GetRootNode(docSrc, "generate");
			Assert.IsNotNull(source);

			PartGenerator generator = new PartGenerator(Cache, source);

			string[] fields = generator.FieldNames;
			Assert.AreEqual(1, fields.Length);
			Assert.IsTrue(StringArrayIncludes(fields, "MyRestrictions"));

			XmlNode[] results = generator.Generate();

			// SampleCm.xml has three ML attrs on LexEntry
			Assert.AreEqual(1, results.Length);

			XmlDocument docExpected3 = new XmlDocument();
			docExpected3.LoadXml(
				"<column label=\"MyRestrictions\" originalLabel=\"MyRestrictions\" > "
				+"<seq field=\"Senses\" sep=\"$delimiter:commaSpace\"> "
				+"<string field=\"MyRestrictions\" ws=\"$ws:analysis\" class=\"LexEntry\"/> "
				+"</seq> "
				+"</column>");
			XmlNode expected3 = TestXmlViewsUtils.GetRootNode(docExpected3, "column");
			Assert.IsTrue(SomeNodeMatches(results, expected3));
		}
Exemplo n.º 4
0
		/// <summary>
		///
		/// </summary>
		/// <param name="root"></param>
		/// <param name="cache"></param>
		/// <param name="keyAttrNames"></param>
		/// <param name="vc">for parts/layouts</param>
		/// <param name="rootClassId">class of the root object used to compute parts/layouts</param>
		/// <returns></returns>
		static private List<XmlNode> GetGeneratedChildren(XmlNode root, FdoCache cache, string[] keyAttrNames,
			XmlVc vc, int rootClassId)
		{
			List<XmlNode> result = new List<XmlNode>();
			string generateModeForColumns = XmlUtils.GetOptionalAttributeValue(root, "generate");
			bool m_fGenerateChildPartsForParentLayouts = (generateModeForColumns == "childPartsForParentLayouts");

			// childPartsForParentLayouts
			foreach(XmlNode child in root.ChildNodes)
			{
				if (child is XmlComment)
					continue;
				if (m_fGenerateChildPartsForParentLayouts)
				{
					ChildPartGenerator cpg = new ChildPartGenerator(cache, child, vc, rootClassId);
					cpg.GenerateChildPartsIfNeeded();
				}
				if (child.Name != "generate")
				{
					result.Add(child);
					continue;
				}

				PartGenerator generator;
				if (generateModeForColumns == "objectValuePartsForParentLayouts")
					generator = new ObjectValuePartGenerator(cache, child, vc, rootClassId);
				else
					generator = new PartGenerator(cache, child, vc, rootClassId);
				foreach (XmlNode genNode in generator.Generate())
				{
					bool match = false;
					if (keyAttrNames != null)
					{
						foreach (XmlNode matchNode in root.ChildNodes)
						{
							if (MatchNodes(matchNode, genNode, keyAttrNames))
							{
								match = true;
								break;
							}
						}
					}
					if (!match) // not already present, or not checking; add it.
						result.Add(genNode);
				}
			}
			return result;
		}
Exemplo n.º 5
0
		public void GenerateMlString()
		{
			IFwMetaDataCache mdc = FwMetaDataCacheClass.Create();
			string m_sTestPath = Path.Combine(DirectoryFinder.FwSourceDirectory,
				@"DbAccess\Test\SampleCm.xml");
			mdc.InitXml(m_sTestPath, true);

			XmlDocument docSrc = new XmlDocument();
			docSrc.LoadXml(
				"<generate class=\"LexEntry\" fieldType=\"mlstring\" restrictions=\"none\"> "
					+"<column label=\"$label\"> "
						+"<seq field=\"Senses\" sep=\"$delimiter:commaSpace\"> "
						+"<string field=\"$fieldName\" ws=\"$ws:analysis\"/> "
						+"</seq> "
					+"</column> "
				+"</generate>");
			XmlNode source = TestXmlViewsUtils.GetRootNode(docSrc, "generate");
			Assert.IsNotNull(source);

			PartGenerator generator = new PartGenerator(mdc, source);

			string[] fields = generator.FieldNames;
			Assert.AreEqual(3, fields.Length);
			Assert.IsTrue(StringArrayIncludes(fields, "CitationForm"));
			Assert.IsTrue(StringArrayIncludes(fields, "Bibliography"));
			Assert.IsTrue(StringArrayIncludes(fields, "custom"));

			XmlNode[] results = generator.Generate();

			// SampleCm.xml has three ML attrs on LexEntry
			Assert.AreEqual(3, results.Length);

			XmlDocument docExpected = new XmlDocument();

			// LT-6956 : sense the test is calling Generate - add the "originalLabel" attribute.
			docExpected.LoadXml(
				"<column label=\"CitationForm\" originalLabel=\"CitationForm\" > "
					+"<seq field=\"Senses\" sep=\"$delimiter:commaSpace\"> "
					+"<string field=\"CitationForm\" ws=\"$ws:analysis\" class=\"LexEntry\"/> "
					+"</seq> "
				+"</column>");
			XmlNode expected = TestXmlViewsUtils.GetRootNode(docExpected, "column");

			Assert.IsTrue(SomeNodeMatches(results, expected), "CitationForm field is wrong");

			XmlDocument docExpected2 = new XmlDocument();
			docExpected2.LoadXml(
				"<column label=\"Bibliography\" originalLabel=\"Bibliography\"> "
				+"<seq field=\"Senses\" sep=\"$delimiter:commaSpace\"> "
				+"<string field=\"Bibliography\" ws=\"$ws:analysis\" class=\"LexEntry\"/> "
				+"</seq> "
				+"</column>");
			XmlNode expected2 = TestXmlViewsUtils.GetRootNode(docExpected2, "column");
			Assert.IsTrue(SomeNodeMatches(results, expected2), "Bibliography field is wrong");

			XmlDocument docExpected3 = new XmlDocument();
			docExpected3.LoadXml(
				"<column label=\"Restrictions\" originalLabel=\"Restrictions\"> "
				+"<seq field=\"Senses\" sep=\"$delimiter:commaSpace\"> "
				+"<string field=\"custom\" ws=\"$ws:analysis\" class=\"LexEntry\"/> "
				+"</seq> "
				+"</column>");
			XmlNode expected3 = TestXmlViewsUtils.GetRootNode(docExpected3, "column");
			Assert.IsTrue(SomeNodeMatches(results, expected3), "generated Restrictions field is wrong");
		}