Пример #1
0
 public ParsedTopic(TopicPropertyCollection properties, TopicRevisionCollection topicLinks, 
     ExternalReferencesMap externalReferences)
 {
     _properties.AddRange(properties);
     _topicLinks.AddRange(topicLinks);
     _externalReferences.AddRange(externalReferences); 
 }
Пример #2
0
        public void SetUp()
        {
            _lm = new LinkMaker(c_siteUrl);
            FederationConfiguration configuration = new FederationConfiguration();
            AuthorizationRule rule = new AuthorizationRule(new AuthorizationRuleWho(AuthorizationRuleWhoType.GenericAll, null),
                AuthorizationRulePolarity.Allow, AuthorizationRuleScope.Wiki, SecurableAction.ManageNamespace, 0);
            configuration.AuthorizationRules.Add(new WikiAuthorizationRule(rule));
            MockWikiApplication application = new MockWikiApplication(
                configuration,
                _lm,
                OutputFormat.HTML,
                new MockTimeProvider(TimeSpan.FromSeconds(1)));

            Federation = new Federation(application);
            Federation.WikiTalkVersion = 1;

            _namespaceManager = WikiTestUtilities.CreateMockStore(Federation, "FlexWiki");
            //_namespaceManager.Title  = "Friendly Title";

            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "_ContentBaseDefinition", "Title: Friendly Title", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "HomePage", "Home is where the heart is", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "BigPolicy", "This is ", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "BigDog", "This is ", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "BigAddress", "This is ", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "BigBox", "This is ", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "IncludeOne", "inc1", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "IncludeTwo", "!inc2", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "IncludeThree", "!!inc3", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "IncludeFour", "!inc4", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "IncludeNest", @"		{{IncludeNest1}}
            {{IncludeNest2}}", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "TopicWithColor", "Color: Yellow", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "IncludeNest1", "!hey there", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "IncludeNest2", "!black dog", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "IncludeNestURI", @"wiki://IncludeNest1 wiki://IncludeNest2 ", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "ResourceReference", @"URI: http://www.google.com/$$$", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "FlexWiki", "flex ", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "InlineTestTopic", @"aaa @@""foo""@@ zzz", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "OneMinuteWiki", "one ", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "TestIncludesBehaviors", "@@ProductName@@ somthing @@Now@@ then @@Now@@", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "_Underscore", "Underscore", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "TopicWithBehaviorProperties", @"
            Face: {""hello"".Length}
            one
            FaceWithArg: {arg | arg.Length }
            FaceSpanningLines:{ arg |

            arg.Length

            }

            ", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "TestTopicWithBehaviorProperties", @"
            len=@@topics.TopicWithBehaviorProperties.Face@@
            lenWith=@@topics.TopicWithBehaviorProperties.FaceWithArg(""superb"")@@
            lenSpanning=@@topics.TopicWithBehaviorProperties.FaceSpanningLines(""parsing is wonderful"")@@
            ", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "TestTopicWithBehaviorProperty",
            @"lenSpanning=@@topics.TopicWithBehaviorProperties.FaceSpanningLines(""parsing is wonderful"")@@", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "TopicWithInclude", "{{TopicOneNoRead}}", _user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "TopicOneNoRead",
            @"DenyRead: all
            PropertyOne: ValueOne
            PropertyTwo: Value Two
            PropertyOne: List, of, values", _user);

            _externals = new ExternalReferencesMap();
        }
Пример #3
0
 public static IWikiToPresentation WikiToPresentation(QualifiedTopicRevision topic, WikiOutput output,
     NamespaceManager namespaceManager, LinkMaker maker, ExternalReferencesMap external, int headingLevelBase)
 {
     ArrayList lines = new ArrayList();
     lines.Add(new StyledLine("", LineStyle.Unchanged));
     return new Formatter(topic, lines, output, namespaceManager, maker, external, headingLevelBase);
 }
Пример #4
0
 public static bool StripExternalWikiDef(ExternalReferencesMap table, string content)
 {
     Match m = externalWikiDef.Match(content);
     if (m.Success)
     {
         table[m.Groups[1].Value] = m.Groups[2].Value;
         return true;
     }
     return false;
 }
Пример #5
0
 /// <summary>
 /// Format a string of wiki content in a given OutputFormat with references all being relative to a given namespace
 /// </summary>
 /// <param name="topic">Topic context</param>
 /// <param name="input">The input wiki text</param>
 /// <param name="format">The desired output format</param>
 /// <param name="relativeToContentStore">References will be relative to this namespace</param>
 /// <param name="lm">Link maker (unless no relativeTo content base is provide)</param>
 /// <param name="accumulator">composite cache rule in which to accumulate cache rules</param>
 /// <returns></returns>
 public static string FormattedString(QualifiedTopicRevision topic, string input, OutputFormat format, NamespaceManager relativeToContentStore, LinkMaker lm)
 {
     // TODO -- some of the cases in which this call happens actually *are* nested, even though the false arg
     // below says that they aren't.  This causes scripts to be emitted multiple times -- should clean up.
     WikiOutput output = WikiOutput.ForFormat(format, null);
     ExternalReferencesMap ew;
     if (relativeToContentStore != null)
     {
         ew = relativeToContentStore.ExternalReferences;
     }
     else
     {
         ew = new ExternalReferencesMap();
     }
     Format(topic, input, output, relativeToContentStore, lm, ew, 0);
     return output.ToString();
 }
Пример #6
0
 /// <summary>
 /// Format a given input string to the given output
 /// </summary>pre
 /// <param name="source">Input wiki content as a list of StyledLines</param>
 /// <param name="output">Output object to which output is sent</param>
 /// <param name="namespaceManager">The ContentProviderChain that contains the wiki string text</param>
 /// <param name="maker">A link maker </param>
 /// <param name="external">External wiki map</param>
 /// <param name="headingLevelBase">Relative heading level</param>
 /// <param name="accumulator">composite cache rule in which to accumulate cache rules</param>
 /// 
 public static void Format(QualifiedTopicRevision topic, IList source, WikiOutput output,
     NamespaceManager namespaceManager, LinkMaker maker, ExternalReferencesMap external, int headingLevelBase)
 {
     Formatter f = new Formatter(topic, source, output, namespaceManager, maker, external, headingLevelBase);
     f.Format();
 }
Пример #7
0
 /// <summary>
 /// Create a new formatter for an input list of StyledLines
 /// </summary>
 /// <param name="source">Input wiki content as a list of StyledLines</param>
 /// <param name="output">Output object to which output is sent</param>
 /// <param name="namespaceManager">The ContentProviderChain that contains the wiki string text</param>
 /// <param name="maker">A link maker </param>
 /// <param name="external">External wiki map</param>
 /// <param name="headingLevelBase">Relative heading level</param>
 /// <param name="accumulator">composite cache rule in which to accumulate cache rules</param>
 /// 
 Formatter(QualifiedTopicRevision topic, IList source, WikiOutput output, NamespaceManager namespaceManager,
     LinkMaker maker, ExternalReferencesMap external, int headingLevelBase)
 {
     _topic = topic;
     _source = source;
     _output = output;
     _linkMaker = maker;
     NamespaceManager = namespaceManager;
     _externalWikiMap = external;
     _headingLevelBase = headingLevelBase;
 }
Пример #8
0
 /// <summary>
 /// Create a new formatter for a string of input content.
 /// </summary>
 /// <param name="source">Input wiki string</param>
 /// <param name="output">Output object to which output is sent</param>
 /// <param name="namespaceManager">The ContentProviderChain that contains the wiki string text</param>
 /// <param name="maker">A link maker </param>
 /// <param name="external">External wiki map</param>
 /// <param name="headingLevelBase">Relative heading level</param>
 /// <param name="accumulator">composite cache rule in which to accumulate cache rules</param>
 /// 
 Formatter(QualifiedTopicRevision topic, string source, WikiOutput output, NamespaceManager namespaceManager,
     LinkMaker maker, ExternalReferencesMap external, int headingLevelBase)
 {
     _topic = topic;
     _source = SplitStringIntoStyledLines(source, LineStyle.Unchanged);
     _linkMaker = maker;
     NamespaceManager = namespaceManager;
     _output = output;
     _externalWikiMap = external;
     _headingLevelBase = headingLevelBase;
 }
Пример #9
0
        public void Init()
        {
            _lm = new LinkMaker(_base);
            MockWikiApplication application = new MockWikiApplication(
                null,
                _lm,
                OutputFormat.HTML,
                new MockTimeProvider(TimeSpan.FromSeconds(1)));

            Federation = new Federation(application);
            Federation.WikiTalkVersion = 1;

            _namespaceManager = WikiTestUtilities.CreateMockStore(Federation, "FlexWiki");
            //_namespaceManager.Title  = "Friendly Title";

            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "HomePage", "Home is where the heart is", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "BigPolicy", "This is ", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "BigDog", "This is ", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "BigAddress", "This is ", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "BigBox", "This is ", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "IncludeOne", "inc1", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "IncludeTwo", "!inc2", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "IncludeThree", "!!inc3", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "IncludeFour", "!inc4", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "IncludeNest", @"		{{IncludeNest1}}
            {{IncludeNest2}}", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "TopicWithColor", "Color: Yellow", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "IncludeNest1", "!hey there", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "IncludeNest2", "!black dog", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "IncludeNestURI", @"wiki://IncludeNest1 wiki://IncludeNest2 ", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "ResourceReference", @"URI: http://www.google.com/$$$", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "FlexWiki", "flex ", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "InlineTestTopic", @"aaa @@""foo""@@ zzz", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "OneMinuteWiki", "one ", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "TestIncludesBehaviors", "@@ProductName@@ somthing @@Now@@ then @@Now@@", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "_Underscore", "Underscore", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "TopicWithBehaviorProperties", @"
            Face: {""hello"".Length}
            one
            FaceWithArg: {arg | arg.Length }
            FaceSpanningLines:{ arg |

            arg.Length

            }

            ", user);
            WikiTestUtilities.WriteTestTopicAndNewVersion(_namespaceManager, "TestTopicWithBehaviorProperties", @"
            len=@@topics.TopicWithBehaviorProperties.Face@@
            lenWith=@@topics.TopicWithBehaviorProperties.FaceWithArg(""superb"")@@
            lenSpanning=@@topics.TopicWithBehaviorProperties.FaceSpanningLines(""parsing is wonderful"")@@
            ", user);

            _externals = new ExternalReferencesMap();
        }
Пример #10
0
        private static ExternalReferencesMap ParseExternalReferences(string text)
        {
            // TODO: Move Formatter functionality to Parser

            ExternalReferencesMap references = new ExternalReferencesMap();

            foreach (string line in text.Split('\n'))
            {
                string l = line.Replace("\r", "");
                Formatter.StripExternalWikiDef(references, l);
            }

            return references;

        }
Пример #11
0
 public IWikiToPresentation WikiToPresentation(QualifiedTopicRevision topic, WikiOutput output,
     NamespaceManager namespaceManager, LinkMaker maker, ExternalReferencesMap external, int headingLevelBase, bool fragment)
 {
     //ArrayList lines = new ArrayList();
     //lines.Add(new StyledLine("", LineStyle.Unchanged));
     //return new Formatter(topic, lines, output, namespaceManager, maker, external, headingLevelBase);
     WomDocument doc = (WomDocument)output;
     doc.Mgr = namespaceManager;
     doc.Fed = _fed;
     doc.FragmentOnly = fragment;
     output.Begin();
     return this;
 }
Пример #12
0
		public IBELObject EvaluateToObject(TopicContext topicContext,  ExternalReferencesMap externalWikimap)
		{
			_CacheRules = new ArrayList();
			if (ParseTree == null)
			{
				ErrorString = "Expression can not be evaluated; parse failed.";
				State = InterpreterState.EvaluationFailure;
				return null;
			}
			ExecutionContext ctx = new ExecutionContext(topicContext);
			ctx.WikiTalkVersion = WikiTalkVersion;
			IBELObject answer = null;
			try 
			{
				ctx.ExternalWikiMap = externalWikimap;
				IScope theScope = null;

				ctx.Presenter = Presenter;

				TopicVersionInfo topic = topicContext != null ? topicContext.CurrentTopic : null;
				if (topic != null && topic.TopicRevision != null)
				{
					// Locate any topics via the NamespaceWith propertyName to see 
                    // if there's anybody else we should import (for all topics in the namespace)
					ArrayList nswith = topicContext.CurrentFederation.GetTopicInfo(ctx, 
                        topicContext.CurrentTopic.NamespaceManager.DefinitionTopicName.DottedName).GetListProperty("NamespaceWith");
					if (nswith != null)
					{
						nswith.Reverse();
						foreach (string top in nswith)
						{
							QualifiedTopicRevision abs = Federation.UnambiguousTopicNameFor(new TopicRevision(top), 
                                topic.NamespaceManager.Namespace);
							if (abs == null)
							{
								throw new Exception("No such topic: " + top + " (as specifed in NamespaceWith: property for " + 
                                    topicContext.CurrentTopic.NamespaceManager.DefinitionTopicName.DottedName + ")");
							}
							theScope = new TopicScope(theScope, new DynamicTopic(topic.Federation, abs));
						}
					}
					
					// Locate any topics via the with propertyName to see if there's anybody else we should import
					ArrayList with = topicContext.CurrentTopic.GetListProperty("With");
					if (with != null)
					{
						with.Reverse();
						foreach (string top in with)
						{
							QualifiedTopicRevision abs = Federation.UnambiguousTopicNameFor(new TopicRevision(top), 
                                topic.NamespaceManager.Namespace);
							if (abs == null)
							{
								throw new Exception("No such topic: " + top + " (as specifed in With: property for " + topicContext.CurrentTopic + ")");
							}
							theScope = new TopicScope(theScope, new DynamicTopic(topic.Federation, abs));
						}
					}
					// add the topic to the current scope (this guy goes at the front of the queue!)
					theScope = new TopicScope(theScope, new DynamicTopic(topic.Federation, topic.TopicRevision));

				}
				if (theScope != null)
					ctx.PushScope(theScope); // make sure we can use local references
				// parse tree -> live objects
				answer = ParseTree.Expose(ctx);
				if (theScope != null)
					ctx.PopScope();

				_CacheRules = ctx.CacheRules;
			}
			catch (Exception e)
			{
				_CacheRules = ctx.CacheRules;
				ErrorString = e.Message;
				State = InterpreterState.EvaluationFailure;
				return  null;
			}
			State = InterpreterState.EvaluationSuccess;
			return answer;
		}
Пример #13
0
		/// <summary>
		/// Evaluate and translate into a presentation
		/// </summary>
		/// <returns>true if success, false if failure</returns>
		public bool EvaluateToPresentation(TopicContext topicContext, ExternalReferencesMap externalWikimap)
		{
			IBELObject evaluated = EvaluateToObject(topicContext, externalWikimap);
			if (evaluated == null)
				return false;
			IOutputSequence seq = evaluated.ToOutputSequence();
			// output sequence -> pure presentation tree
			_Value = seq.ToPresentation(Presenter);
			return true;
		}