public override StateManager.SerializedView saveSerializedView(FacesContext facesContext) { Object treeStruct = getTreeStructureToSave(facesContext); Object compStates = getComponentStateToSave(facesContext); SerializedView serializedView = new SerializedView(this, treeStruct, compStates); return(serializedView); }
//BINDING_DEFINITION_BEGIN //BINDING_DEFINITION_END private void Awake() { //BINDING_CODE_BEGIN //BINDING_CODE_END SerializedView component = GetComponent <SerializedView>(); component.AddClick("ButtonMain", () => WindowManager.Instance.Open("UIMain")); component.AddClick("ButtonPop", () => WindowManager.Instance.Open("UIPop")); component.AddClick("ButtonWidget", () => WindowManager.Instance.Open("UIWidget")); }
protected override void restoreComponentState(FacesContext facesContext, javax.faces.component.UIViewRoot uiViewRoot, String renderKitId) { Trace.WriteLine("Entering restoreComponentState"); Object serializedComponentStates; if (isSavingStateInClient(facesContext)) { serializedComponentStates = GetStateFromClient(facesContext, uiViewRoot.getViewId(), renderKitId); } else { HttpSession session = (HttpSession)facesContext.getExternalContext().getSession(false); if (session == null) { serializedComponentStates = null; } else { string key = ((IExtendedViewHandler)facesContext.getApplication().getViewHandler()).EncodeNamespace(facesContext, VIEWSTATE); SerializedView serializedView = session.getAttribute(key) as SerializedView; if (serializedView == null) { serializedComponentStates = null; } else { serializedComponentStates = serializedView.getState(); } } } ((UIComponent)uiViewRoot.getChildren().get(0)).processRestoreState(facesContext, serializedComponentStates); Trace.WriteLine("Exiting restoreComponentState"); }
private void Parse(string file, string section = "", string html = "", Dictionary <string, SerializedView> cache = null, bool loadPartials = true) { SerializedView cached = new SerializedView() { Elements = new List <ViewElement>() }; Filename = file; Data = new ViewData(); Section = section; if (file != "") { #if (!DEBUG) if (cache == null && ViewCache.cache != null) { cache = ViewCache.cache; } #endif if (cache != null) { if (cache.ContainsKey(file + '/' + section) == true) { cached = cache[file + '/' + section]; //Data = cached.Data; Elements = cached.Elements; Fields = cached.Fields; } } } //was able to retrieve cached object if (cached.Elements.Count != 0) { return; } //was NOT able to retrieve cached object Elements = new List <ViewElement>(); //try loading file from disk if (file != "") { if (File.Exists(MapPath(file))) { HTML = File.ReadAllText(MapPath(file)); } } else { HTML = html; } if (HTML.Trim() == "") { return; } //next, find the group of code matching the view section name if (section != "") { //find starting tag (optionally with arguments) //for example: {{button (name:submit, style:outline)}} int[] e = new int[3]; e[0] = HTML.IndexOf("{{" + section); if (e[0] >= 0) { e[1] = HTML.IndexOf("}", e[0]); if (e[1] - e[0] <= 256) { e[1] = HTML.IndexOf("{{/" + section + "}}", e[1]); } else { e[0] = -1; } } if (e[0] >= 0 & e[1] > (e[0] + section.Length + 4)) { e[2] = e[0] + 4 + section.Length; HTML = HTML.Substring(e[2], e[1] - e[2]); } } //get view from html code var dirty = true; var arr = HTML.Split("{{"); var i = 0; var s = 0; var c = 0; var u = 0; var u2 = 0; ViewElement viewElem; while (dirty == true) { dirty = false; arr = HTML.Split("{{"); i = 0; s = 0; c = 0; u = 0; u2 = 0; viewElem = new ViewElement(); //types of view elements // {{title}} = variable // {{address}} {{/address}} = block // {{button "/ui/button-medium"}} = HTML include // {{button "/ui/button" title:"save", onclick="do.this()"}} = HTML include with properties // {{page-list path:"blog", length:"5"}} = HTML variable with properties //first, load all HTML includes for (var x = 0; x < arr.Length; x++) { if (x == 0 && HTML.IndexOf(arr[x]) == 0) { arr[x] = "{!}" + arr[x]; } else if (arr[x].Trim() != "") { i = arr[x].IndexOf("}}"); s = arr[x].IndexOf(':'); u = arr[x].IndexOf('"'); if (i > 0 && u > 0 && u < i - 2 && (s == -1 || s > u) && loadPartials == true) { //read partial include & load HTML from another file viewElem.Name = arr[x].Substring(0, u - 1).Trim().ToLower(); u2 = arr[x].IndexOf('"', u + 2); var partial_path = arr[x].Substring(u + 1, u2 - u - 1); if (partial_path.Length > 0) { if (partial_path[0] == '/') { partial_path = partial_path.Substring(1); } //replace pointer paths with relative paths var pointer = ViewPartialPointers.Paths.Where(a => partial_path.IndexOf(a.Key) == 0).Select(p => new { p.Key, p.Value }).FirstOrDefault(); if (pointer != null) { partial_path = partial_path.Replace(pointer.Key, pointer.Value); } partial_path = '/' + partial_path; //load the view HTML var newScaff = new View(partial_path, "", cache); //check for HTML include variables if (i - u2 > 0) { var vars = arr[x].Substring(u2 + 1, i - (u2 + 1)).Trim(); if (vars.IndexOf(":") > 0) { //HTML include variables exist try { var kv = JsonSerializer.Deserialize <Dictionary <string, string> >("{" + vars + "}"); foreach (var kvp in kv) { newScaff[kvp.Key] = kvp.Value; } } catch (Exception) { } } } //rename child view variables, adding a prefix var ht = newScaff.Render(newScaff.Data, false); var y = 0; var prefix = viewElem.Name + "-"; while (y >= 0) { y = ht.IndexOf("{{", y); if (y < 0) { break; } if (ht.Substring(y + 2, 1) == "/") { ht = ht.Substring(0, y + 3) + prefix + ht.Substring(y + 3); } else { ht = ht.Substring(0, y + 2) + prefix + ht.Substring(y + 2); } y += 2; } Partials.Add(new ViewPartial() { Name = viewElem.Name, Path = partial_path, Prefix = prefix }); Partials.AddRange(newScaff.Partials.Select(a => { var partial = a; partial.Prefix = prefix + partial.Prefix; return(partial); }) ); arr[x] = "{!}" + ht + arr[x].Substring(i + 2); } else { //partial not found arr[x] = "{!}" + arr[x].Substring(i + 2); } HTML = JoinHTML(arr); dirty = true; //HTML is dirty, restart loop break; } } } if (dirty == false) { //next, process variables & blocks for (var x = 0; x < arr.Length; x++) { if (x == 0 && HTML.IndexOf(arr[0].Substring(3)) == 0)//skip "{!}" using substring { //first element is HTML only Elements.Add(new ViewElement() { Htm = arr[x].Substring(3), Name = "" }); } else if (arr[x].Trim() != "") { i = arr[x].IndexOf("}}"); s = arr[x].IndexOf(' '); c = arr[x].IndexOf(':'); u = arr[x].IndexOf('"'); viewElem = new ViewElement(); if (i > 0) { viewElem.Htm = arr[x].Substring(i + 2); //get variable name if (s < i && s > 0) { //found space viewElem.Name = arr[x].Substring(0, s).Trim().ToLower(); } else { //found tag end viewElem.Name = arr[x].Substring(0, i).Trim().ToLower(); } //since each variable could have the same name but different parameters, //save the full name & parameters as the name //viewElem.Name = arr[x].Substring(0, i); if (!viewElem.Name.Contains('/')) { if (Fields.ContainsKey(viewElem.Name)) { //add element index to existing field var field = Fields[viewElem.Name]; Fields[viewElem.Name] = field.Append(Elements.Count).ToArray(); } else { //add field with element index Fields.Add(viewElem.Name, new int[] { Elements.Count }); } //check if view element is a block for (var y = x + 1; y < arr.Length; y++) { if (arr[y].IndexOf("/" + viewElem.Name + "}}") == 0) { viewElem.isBlock = true; viewElem.blockEnd = y; break; } } } if (s < i && s > 0) { //get optional variables stored within tag var vars = arr[x].Substring(s + 1, i - s - 1); //clean vars var vi = 0; var ve = 0; var inq = false;//inside quotes var vItems = new List <string>(); while (vi < vars.Length) { var a = vars.Substring(vi, 1); if (a == "\"") { inq = !inq ? true : false; } if ((inq == false && (a == ":" || a == ",")) || vi == vars.Length - 1) { if (vi == vars.Length - 1) { vi = vars.Length; } var r = vars.Substring(ve, vi - ve).Trim(); if (r.Substring(0, 1) != "\"") { r = "\"" + r + "\""; } vItems.Add(r); ve = vi + 1; } vi++; } inq = false; vars = ""; foreach (var item in vItems) { vars += item + (!inq ? ":" : ","); inq = !inq ? true : false; } if (vars[^ 1] == ',')
public override StateManager.SerializedView saveSerializedView (FacesContext facesContext) { Object treeStruct = getTreeStructureToSave (facesContext); Object compStates = getComponentStateToSave (facesContext); SerializedView serializedView = new SerializedView (this, treeStruct, compStates); return serializedView; }
private void Awake() { mTarget = target as SerializedView; }