private XPathSemWebNavigator(Entity root, Store model, NamespaceManager namespaces, string exapandThisPredicate) {
			this.model = model;
			
			if (!(namespaces is SemWeb.IO.AutoPrefixNamespaceManager))
				namespaces = new SemWeb.IO.AutoPrefixNamespaceManager(namespaces);
			this.nsmgr = namespaces;
			nswrap = new NSWrap(nsmgr);
			
			Position start = new Position();
			start.FirstChild = true;
			start.LastChild = true;
			start.Predicate = root; // a trick to make sure the URI info for the root reflects the root
			start.Object = root;
			if (exapandThisPredicate != null)
				Expand(start, exapandThisPredicate);
			current = start;
		}
Esempio n. 2
0
        static MetadataStore()
        {
            Namespaces = new NamespaceManager ();

            Namespaces.AddNamespace (PhotoshopNS, "photoshop");
            Namespaces.AddNamespace (Iptc4xmpCoreNS, "Iptc4xmpCore");
            Namespaces.AddNamespace (DcNS, "dc");
            Namespaces.AddNamespace (XmpNS, "xmp");
            Namespaces.AddNamespace (XmpidqNS, "xmpidq");
            Namespaces.AddNamespace (XmpRightsNS, "xmpRights");
            Namespaces.AddNamespace (XmpBJNS, "xmpBJ");
            Namespaces.AddNamespace (XmpMMNS, "xmpMM");
            Namespaces.AddNamespace (ExifNS, "exif");
            Namespaces.AddNamespace (TiffNS, "tiff");
            Namespaces.AddNamespace (RdfNS, "rdf");
            Namespaces.AddNamespace (RdfsNS, "rdfs");
            Namespaces.AddNamespace (IViewNS, "mediapro");
        }
Esempio n. 3
0
		public void AddFrom(NamespaceManager nsmgr) {
			foreach (string uri in nsmgr.GetNamespaces())
				AddNamespace(uri, nsmgr.GetPrefix(uri));
		}
Esempio n. 4
0
		public NamespaceManager(NamespaceManager parent) {
			this.parent = parent;
		}
Esempio n. 5
0
		public AutoPrefixNamespaceManager(NamespaceManager parent) : base(parent) {
		}
Esempio n. 6
0
            /// <summary>
            /// Initializes a new <see cref="AbbreviatedNamespaceManagerWrapper"/> instance.
            /// </summary>
            /// <param name="originalNamespaceManager">The original namespace manager.</param>
            /// <param name="abbreviations">The abbreviations.</param>
            public AbbreviatedNamespaceManagerWrapper(NamespaceManager originalNamespaceManager, Hashtable abbreviations)
            {
                m_OriginalNamespaceManager = originalNamespaceManager;
                m_Abbreviations = abbreviations;

                // calculate minimum and maximum abbreviated URI length
                m_MaxKeyLength = 0;
                m_MinKeyLength = int.MaxValue;
                foreach (var key in abbreviations.Keys)
                {
                    m_MinKeyLength = Math.Min(((string) key).Length, m_MinKeyLength);
                    m_MaxKeyLength = Math.Max(((string)key).Length, m_MaxKeyLength);
                }
            }
Esempio n. 7
0
 public NamespaceManager GetQueryPrefixes()
 {
     NamespaceManager ns = new NamespaceManager();
     java.util.Map prefixes = ((QueryData)query).getPrefixExpansions();
     for (java.util.Iterator i = prefixes.keySet().iterator(); i.hasNext(); ) {
         string prefix = (string)i.next();
         string uri = prefixes.get(prefix).ToString(); // surrounded in < >
         uri = uri.Substring(1, uri.Length-2); // not sure how to get this directly
         ns.AddNamespace(uri, prefix);
     }
     return ns;
 }
Esempio n. 8
0
    public static void Main(string[] args)
    {
        Opts opts = new Opts();
        opts.ProcessArgs(args);
        if (opts.RemainingArguments.Length != 2 && opts.RemainingArguments.Length != 3) {
            opts.DoHelp();
            return;
        }

        string datasource, rootentity, stylesheetfile;
        if (opts.RemainingArguments.Length == 2) {
            datasource = opts.RemainingArguments[0];
            rootentity = null;
            stylesheetfile = opts.RemainingArguments[1];
        } else {
            datasource = opts.RemainingArguments[0];
            rootentity = opts.RemainingArguments[1];
            stylesheetfile = opts.RemainingArguments[2];
        }

        XsltArgumentList xsltargs = new XsltArgumentList();

        if (opts.param != null)
        foreach (string p in opts.param) {
            int eq = p.IndexOf('=');
            if (eq == -1) {
                Console.Error.WriteLine("Param arguments must be name=value.");
                return;
            }
            string n = p.Substring(0, eq);
            string v = p.Substring(eq+1);
            xsltargs.AddParam(n, "", v);
        }

        XmlDocument sty = new XmlDocument();
        sty.PreserveWhitespace = true;
        sty.Load(stylesheetfile);

        XslTransform t = new XslTransform();
        t.Load(sty, null, null);

        NamespaceManager nsmgr = new NamespaceManager();

        // Scan xmlsn: attributes in the stylesheet node.
        // For all namespaces of the form assembly://assemblyname/TypeName, load in
        // the methods of that type as extension functions in that namespace.
        // And add xmlns declarations to nsmgr.
        foreach (XmlAttribute a in sty.DocumentElement.Attributes) {
            if (!a.Name.StartsWith("xmlns:")) continue;

            nsmgr.AddNamespace(a.Value, a.Name.Substring(6));

            System.Uri uri = new System.Uri(a.Value);
            if (uri.Scheme != "assembly") continue;
            System.Reflection.Assembly assembly = System.Reflection.Assembly.Load(uri.Host);
            System.Type ty = assembly.GetType(uri.AbsolutePath.Substring(1));
            if (ty == null) {
                Console.Error.WriteLine("Type not found: " + uri);
                return;
            }
            object obj = ty.GetConstructor(new Type[0]).Invoke(new Type[0]);
            xsltargs.AddExtensionObject(a.Value, obj);
        }

        StatementSource source = Store.CreateForInput(datasource);
        Store model;
        if (source is Store) model = (Store)source;
        else model = new MemoryStore(source);

        XPathNavigator nav;
        if (rootentity != null)
            nav = new XPathSemWebNavigator(rootentity, model, nsmgr);
        else
            nav = new XPathSemWebNavigator(model, nsmgr);

        t.Transform(nav, xsltargs, Console.Out, null);
    }
		public XPathSemWebNavigator(Entity root, Store model, NamespaceManager namespaces) : this(root, model, namespaces, null) { }
		public XPathSemWebNavigator(Store model, NamespaceManager namespaces) : this(ExpandEntitiesOfType, model, namespaces, null) { }
			public NSWrap(NamespaceManager nsmgr) : base(new NameTable()) { this.nsmgr = nsmgr; }
		public override bool MoveTo (XPathNavigator other) {
			XPathSemWebNavigator clone = other as XPathSemWebNavigator;
			if (clone == null) return false;
			this.model = clone.model;
			this.nsmgr = clone.nsmgr;
			this.nswrap = clone.nswrap;
			this.stack = (ArrayList)clone.stack.Clone();
			this.current = clone.current;
			return true;
		}
Esempio n. 13
0
		public static Literal Parse(string literal, NamespaceManager namespaces) {
			if (literal.Length < 2 || literal[0] != '\"') throw new FormatException("Literal value must start with a quote.");
			int quote = literal.LastIndexOf('"');
			if (quote <= 0) throw new FormatException("Literal value must have an end quote (" + literal + ")");
			string value = literal.Substring(1, quote-1);
			literal = literal.Substring(quote+1);
			
			value = value.Replace("\\\"", "\"");
			value = value.Replace("\\\\", "\\");
			
			string lang = null;
			string datatype = null;
			
			if (literal.Length >= 2 && literal[0] == '@') {
				int type = literal.IndexOf("^^");
				if (type == -1) lang = literal.Substring(1);
				else {
					lang = literal.Substring(1, type);
					literal = literal.Substring(type);
				}
			}
			
			if (literal.StartsWith("^^")) {
				if (literal.StartsWith("^^<") && literal.EndsWith(">")) {
					datatype = literal.Substring(3, literal.Length-4);
				} else {
					if (namespaces == null)
						throw new ArgumentException("No NamespaceManager was given to resolve the QName in the literal string.");
					datatype = namespaces.Resolve(literal.Substring(2));
				}
			}
			
			return new Literal(value, lang, datatype);
		}
 public NamespaceManager(NamespaceManager parent)
 {
     this.parent = parent;
 }