Example #1
0
        private void XmlConvert(dom.Node jNode, XmlNode nNode)
        {
            XmlDocument document = nNode.OwnerDocument;

            if (document == null)
            {
                document = (XmlDocument)nNode;
            }

            XmlNode n = null;

            switch (jNode.getNodeType())
            {
            case 1:
                n = document.CreateNode(XmlNodeType.Element, jNode.getNodeName(), jNode.getNamespaceURI());
                break;

            case 4:
                n = document.CreateNode(XmlNodeType.CDATA, jNode.getNodeName(), jNode.getNamespaceURI());
                break;

            default:
                return;
            }
            //set value
            n.InnerText = jNode.getNodeValue();
            nNode.AppendChild(n);

            //copy attributes
            org.w3c.dom.NamedNodeMap nm = jNode.getAttributes();
            for (int i = 0; i < nm.getLength(); i++)
            {
                XmlAttribute a = document.CreateAttribute(nm.item(i).getNodeName());
                a.Value = nm.item(i).getNodeValue();
                n.Attributes.Append(a);
            }

            //copy childs
            org.w3c.dom.NodeList nl = jNode.getChildNodes();
            for (int i = 0; i < nl.getLength(); i++)
            {
                XmlConvert(nl.item(i), n);
            }
        }
Example #2
0
	public Node importNode(Node importedNode, bool deep) { return default(Node); }
Example #3
0
	public bool isSameNode(Node other) { return default(bool); }
		/// <summary>
		/// Create a new input source with a DOM node, and with the
		/// system ID also passed in as the base URI.
		/// </summary>
		public DOMSource(Node @node, string @systemID)
		{
		}
Example #5
0
	public Node replaceChild(Node newChild, Node oldChild) { return default(Node); }
Example #6
0
	public Node appendChild(Node newChild) { return default(Node); }
 private void InjectBaseTag(Gadget gadget, Node headTag)
 {
     GadgetContext context = gadget.getContext();
     if ("true".Equals(containerConfig.Get(context.getContainer(), INSERT_BASE_ELEMENT_KEY))) 
     {
         Uri baseUrl = gadget.getSpec().getUrl();
         View view = gadget.getCurrentView();
         if (view != null && view.getHref() != null) 
         {
             baseUrl = view.getHref();
         }
         Element baseTag = headTag.getOwnerDocument().createElement("base");
         baseTag.setAttribute("href", baseUrl.ToString());
         headTag.insertBefore(baseTag, headTag.getFirstChild());
     }
 }
Example #8
0
	public void handle(short operation, string key, object data, Node src, Node dst) {}
 private static void save(Node node, Result result) {
     var factory = TransformerFactory.newInstance();
     var transformer = factory.newTransformer();
     transformer.setOutputProperty(OutputKeys.INDENT, "yes");
     transformer.transform(new DOMSource(node), result);
 }
Example #10
0
	public Node setNamedItemNS(Node arg) { return default(Node); }
 public static void save(Node node, Writer writer) {
     save(node, new StreamResult(writer));
 }
 public static void save(Node node, OutputStream output) {
     save(node, new StreamResult(output));
 }
Example #13
0
		/// <summary>
		/// Set the node that will represents a Source DOM tree.
		/// </summary>
		public void setNode(Node @node)
		{
		}
Example #14
0
	public Node adoptNode(Node source) { return default(Node); }
Example #15
0
 private static void InjectOnLoadHandlers(Node bodyTag) 
 {
     Element onloadScript = bodyTag.getOwnerDocument().createElement("script");
     bodyTag.appendChild(onloadScript);
     onloadScript.appendChild(bodyTag.getOwnerDocument().createTextNode(
         "gadgets.util.runOnLoadHandlers();"));
 }
Example #16
0
	public Node renameNode(Node n, string namespaceURI, string qualifiedName) { return default(Node); }
Example #17
0
        /// <summary>
        /// Injects javascript libraries needed to satisfy feature dependencies.
        /// </summary>
        /// <param name="gadget"></param>
        /// <param name="headTag"></param>
        private void InjectFeatureLibraries(Gadget gadget, Node headTag)
        {
            // TODO: If there isn't any js in the document, we can skip this. Unfortunately, that means
            // both script tags (easy to detect) and event handlers (much more complex).
            GadgetContext context = gadget.getContext();
            GadgetSpec spec = gadget.getSpec();
            String forcedLibs = context.getParameter("libs");
            HashKey<String> forced;
            if (string.IsNullOrEmpty(forcedLibs)) 
            {
                forced = new HashKey<string>();
            } 
            else 
            {
                forced = new HashKey<string>();
                foreach (var item in forcedLibs.Split(':'))
                {
                    forced.Add(item);
                }
            }


            // Forced libs are always done first.
            if (forced.Count != 0) 
            {
                String jsUrl = urlGenerator.getBundledJsUrl(forced, context);
                Element libsTag = headTag.getOwnerDocument().createElement("script");
                libsTag.setAttribute("src", jsUrl);
                headTag.appendChild(libsTag);

                // Forced transitive deps need to be added as well so that they don't get pulled in twice.
                // TODO: Figure out a clean way to avoid having to call getFeatures twice.
                foreach(GadgetFeature dep in featureRegistry.GetFeatures(forced)) 
                {
                    forced.Add(dep.getName());
                }
            }

            // Inline any libs that weren't forced. The ugly context switch between inline and external
            // Js is needed to allow both inline and external scripts declared in feature.xml.
            String container = context.getContainer();
            ICollection<GadgetFeature> features = GetFeatures(spec, forced);

            // Precalculate the maximum length in order to avoid excessive garbage generation.
            int size = 0;
            foreach(GadgetFeature feature in features) 
            {
                foreach(JsLibrary library in feature.getJsLibraries(RenderingContext.GADGET, container))
                {
                    if (library._Type == JsLibrary.Type.URL)
                    {
                        size += library.Content.Length;
                    }
                }
            }

            // Really inexact.
            StringBuilder inlineJs = new StringBuilder(size);

            foreach (GadgetFeature feature in features)
            {
                foreach (JsLibrary library in feature.getJsLibraries(RenderingContext.GADGET, container))
                {
                    if (library._Type == JsLibrary.Type.URL)
                    {
                        if (inlineJs.Length > 0)
                        {
                            Element inlineTag = headTag.getOwnerDocument().createElement("script");
                            headTag.appendChild(inlineTag);
                            inlineTag.appendChild(headTag.getOwnerDocument().createTextNode(inlineJs.ToString()));
                            inlineJs.Length = 0;
                        }
                        Element referenceTag = headTag.getOwnerDocument().createElement("script");
                        referenceTag.setAttribute("src", library.Content);
                        headTag.appendChild(referenceTag);
                    }
                    else
                    {
                        if (!forced.Contains(feature.getName()))
                        {
                            // already pulled this file in from the shared contents.
                            if (context.getDebug())
                            {
                                inlineJs.Append(library.DebugContent);
                            }
                            else
                            {
                                inlineJs.Append(library.Content);
                            }
                            inlineJs.Append(";\n");
                        }
                    }
                }
            }

            inlineJs.Append(GetLibraryConfig(gadget, features));

            if (inlineJs.Length > 0) 
            {
                Element inlineTag = headTag.getOwnerDocument().createElement("script");
                headTag.appendChild(inlineTag);
                inlineTag.appendChild(headTag.getOwnerDocument().createTextNode(inlineJs.ToString()));
            }
        }
Example #18
0
	public Node insertBefore(Node newChild, Node refChild) { return default(Node); }
Example #19
0
        /**
        * Injects message bundles into the gadget output.
        * @throws GadgetException If we are unable to retrieve the message bundle.
        */
        private void InjectMessageBundles(Gadget gadget, Node scriptTag) 
        {
            GadgetContext context = gadget.getContext();
            MessageBundle bundle = messageBundleFactory.getBundle(
                gadget.getSpec(), context.getLocale(), context.getIgnoreCache());

            String msgs = bundle.ToJSONString();

            Text text = scriptTag.getOwnerDocument().createTextNode("gadgets.Prefs.setMessages_(");
            text.appendData(msgs);
            text.appendData(");");
            scriptTag.appendChild(text);

        }
Example #20
0
	public Node removeChild(Node oldChild) { return default(Node); }
Example #21
0
        /**
        * Injects default values for user prefs into the gadget output.
        */
        private static void InjectDefaultPrefs(Gadget gadget, Node scriptTag)
        {
                List<UserPref> prefs = gadget.getSpec().getUserPrefs();
                Dictionary<String, String> defaultPrefs = new Dictionary<string, string>(prefs.Count);

                foreach(UserPref up in gadget.getSpec().getUserPrefs())
                {
                    defaultPrefs.Add(up.getName(), up.getDefaultValue());
                }
                Text text = scriptTag.getOwnerDocument().createTextNode("gadgets.Prefs.setDefaultPrefs_(");
                text.appendData(JsonConvert.ExportToString(defaultPrefs));
                text.appendData(");");
                scriptTag.appendChild(text);
        }
Example #22
0
	public short compareDocumentPosition(Node other) { return default(short); }
Example #23
0
        /**
        * Injects preloads into the gadget output.
        *
        * If preloading fails for any reason, we just output an empty object.
        */
        private static void InjectPreloads(Gadget gadget, Node scriptTag) 
        {
            IPreloads preloads = gadget.getPreloads();

            Dictionary<String, Object> preload = new Dictionary<string, object>();

            foreach(PreloadedData preloaded in preloads.getData()) 
            {
                foreach(var entry in preloaded.toJson()) 
                {
                    preload.Add(entry.Key, entry.Value);
                }
            }
            Text text = scriptTag.getOwnerDocument().createTextNode("gadgets.io.preloaded_=");
            text.appendData(JsonConvert.ExportToString(preload));
            text.appendData(";");
            scriptTag.appendChild(text);
        }
Example #24
0
	public bool isEqualNode(Node arg) { return default(bool); }
Example #25
0
		/// <summary>
		/// Create a new input source with a DOM node.
		/// </summary>
		public DOMSource(Node @n)
		{
		}