<%-- Copyright (C) 2004-2008 by Autodesk, Inc. This library is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA --%> <%@ Import Namespace="System" %> <%@ Import Namespace="System.Collections" %> <%@ Import Namespace="System.Collections.Specialized" %> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System.Text" %> <%@ Import Namespace="System.Web" %> <%@ Import Namespace="OSGeo.MapGuide" %> <% try { Response.Charset = "utf-8"; MgLocalizer.SetLocalizedFilesPath(Request.ServerVariables["APPL_PHYSICAL_PATH"] + "..\\localized\\"); // Initialize web tier with the site configuration file. InitializeWebTier(); //Fetch request parameters for this request GetRequestParameters(); //Open connection with the server bool createSession = true; MgUserInformation cred = new MgUserInformation(); if (null != sessionId && "" != sessionId) { cred.SetMgSessionId(sessionId); createSession = false; } else if (null != username) { cred.SetMgUsernamePassword(username, password); } else { RequestAuthentication(); return; } MgSiteConnection site = new MgSiteConnection(); cred.SetLocale(locale); site.Open(cred); if (createSession) { MgSite site1 = new MgSite(); site1.Open(cred); sessionId = site1.CreateSession(); if (forDwf == 0) { orgSessionId = sessionId; } } //Get an MgWebLayout object MgWebLayout webLayout = null; MgResourceService resourceSrvc = site.CreateService(MgServiceType.ResourceService) as MgResourceService; MgResourceIdentifier webLayoutId = new MgResourceIdentifier(webLayoutDefinition); webLayout = new MgWebLayout(resourceSrvc, webLayoutId); //calculate the size of the variable elements of the viewer // MgWebToolBar toolBar = webLayout.GetToolBar(); MgWebUiPane statusBar = webLayout.GetStatusBar(); MgWebTaskPane taskPane = webLayout.GetTaskPane(); MgWebInformationPane infoPane = webLayout.GetInformationPane(); MgWebTaskBar taskBar = taskPane.GetTaskBar(); String mapDef = webLayout.GetMapDefinition(); bool showTaskPane = taskPane.IsVisible(); bool showTaskBar = taskBar.IsVisible(); bool showStatusbar = statusBar.IsVisible(); bool showToolbar = toolBar.IsVisible(); int taskPaneWidth = taskPane.GetWidth(); int toolbarHeight = 30; int statusbarHeight = 26; int taskWidth = showTaskPane ? taskPaneWidth : 0; toolbarHeight = showToolbar ? toolbarHeight : 0; statusbarHeight = showStatusbar ? statusbarHeight : 0; String taskPaneUrl = taskPane.GetInitialTaskUrl(); String vpath = GetSurroundVirtualPath(Request); bool defHome = false; if (taskPaneUrl == null || taskPaneUrl.Length == 0) { taskPaneUrl = "gettingstarted.aspx"; defHome = true; } String mapDefinitionUrl = HttpUtility.UrlEncode(mapDef); String title = webLayout.GetTitle(); bool showLegend = infoPane.IsLegendBandVisible(); bool showProperties = infoPane.IsPropertiesBandVisible(); int infoWidth = 0; if (showLegend || showProperties) { if (infoPane.IsVisible()) { infoWidth = infoPane.GetWidth(); if (infoWidth < 5) { infoWidth = 5; //ensure visible } } else { showProperties = showLegend = false; } } //calculate the url of the inner pages // String srcToolbar = showToolbar ? ("src=\"" + vpath + "toolbar.aspx?LOCALE=" + locale + "\"") : ""; String srcStatusbar = showStatusbar ? ("src=\"" + vpath + "statusbar.aspx?LOCALE=" + locale + "\"") : ""; String srcTaskFrame = showTaskPane ? ("src=\"" + vpath + "taskframe.aspx?TASK=" + taskPaneUrl + "&WEBLAYOUT=" + HttpUtility.UrlEncode(webLayoutDefinition) + "&DWF=" + (forDwf != 0 ? "1" : "0") + "&SESSION=" + (sessionId != "" ? sessionId : "") + "&LOCALE=" + locale + "\"") : ""; String srcTaskBar = "src=\"" + vpath + "taskbar.aspx?LOCALE=" + locale + "\""; //view center // MgPoint ptCenter = webLayout.GetCenter(); String center = "null"; if (null != ptCenter) { MgCoordinate coord = ptCenter.GetCoordinate(); center = String.Format("new Point({0}, {1})", coord.GetX().ToString(NumberFormatInfo.InvariantInfo), coord.GetY().ToString(NumberFormatInfo.InvariantInfo)); } //Process commands and declare command objects // MgWebCommandCollection commands = webLayout.GetCommands(); String cmdObjects = ""; String cmdObject = ""; int navCmdIndex = 0; int scriptCmdIndex = 0; int measureCmdIndex = 0; int printCmdIndex = 0; int searchCmdIndex = 0; String userCode = ""; String userCodeCalls = "\nswitch(funcIndex)\n{\n"; int selAwareCmdCount = 0; String selAwareCmds = ""; cmds = new NameValueCollection(); int i = 0; for (i = 0; i < commands.GetCount(); i++) { MgWebCommand cmd = commands.GetItem(i); if (!cmd.IsUsed()) continue; int tgtViewer = cmd.GetTargetViewerType(); if ((tgtViewer == MgWebTargetViewerType.Dwf) != (forDwf == 1) && (tgtViewer != MgWebTargetViewerType.All)) continue; String name = cmd.GetName(); int action = cmd.GetAction(); if (action == MgWebActions.Search) { MgWebSearchCommand searchCmd = cmd as MgWebSearchCommand; // create the column objects String cols = "var resCols" + searchCmdIndex + " = new Array();\n"; if (searchCmd.GetResultColumnCount() > 0) { for (int j = 0; j < searchCmd.GetResultColumnCount(); j++) { String col = String.Format("resCols{0}[{1}] = new ResultColumn(\"{2}\", \"{3}\");\n", searchCmdIndex, j, StrEscape(searchCmd.GetColumnDisplayNameAt(j), true), StrEscape(searchCmd.GetColumnPropertyNameAt(j), true)); cols += col; } } cmdObjects += cols; // declare a new search command object cmdObject = String.Format("commands[{0}] = new SearchCommand(\"{1}\", \"{2}\", {3}, \"{4}\", \"{5}\", \"{6}\", \"{7}\", \"{8}\", \"{9}\", resCols{10}, \"{11}\", {12}, {13}, \"{14}\");\n", i, StrEscape(name, false), StrEscape(searchCmd.GetLabel(), false), searchCmd.GetAction(), searchCmd.GetIconUrl(), searchCmd.GetDisabledIconUrl(), StrEscape(searchCmd.GetTooltip(), false), StrEscape(searchCmd.GetDescription(), false), searchCmd.GetLayer(), StrEscape(searchCmd.GetPrompt(), false), searchCmdIndex, StrEscape(searchCmd.GetFilter(), false), searchCmd.GetMatchLimit(), searchCmd.GetTarget(), searchCmd.GetTargetName()); searchCmdIndex++; } else if (action == MgWebActions.InvokeUrl) { MgWebInvokeUrlCommand invokeUrlCmd = cmd as MgWebInvokeUrlCommand; // create the parameter objects String parameters = "var navParams" + navCmdIndex + " = new Array();\n"; String layers = "var layers" + navCmdIndex + " = new Array();\n"; if (invokeUrlCmd.GetParameterCount() > 0) { int j = 0; for (j = 0; j < invokeUrlCmd.GetParameterCount(); j++) { String param = String.Format("navParams{0}[{1}] = new NavParam(\"{2}\", \"{3}\");\n", navCmdIndex, j, invokeUrlCmd.GetParameterNameAt(j), invokeUrlCmd.GetParameterValueAt(j)); parameters = parameters + param; } for (j = 0; j < invokeUrlCmd.GetLayerCount(); j++) { String layer = String.Format("layers{0}[{1}] = \"{2}\";\n", navCmdIndex, j, invokeUrlCmd.GetLayerNameAt(j)); layers = layers + layer; } } cmdObjects = cmdObjects + parameters + layers; if (invokeUrlCmd.DisabledIfSelectionEmpty() || invokeUrlCmd.GetLayerCount() > 0) { selAwareCmds += String.Format("selectionAwareCmds[{0}] = {1};\n", selAwareCmdCount, i); selAwareCmdCount++; } // declare a new invokeurl command object cmdObject = String.Format("commands[{0}] = new InvokeUrlCommand(\"{1}\", {2}, \"{3}\", \"{4}\", \"{5}\", \"{6}\", \"{7}\", navParams{8}, {9}, layers{10}, {11}, \"{12}\");\n", i, StrEscape(name, false), invokeUrlCmd.GetAction(), invokeUrlCmd.GetIconUrl(), invokeUrlCmd.GetDisabledIconUrl(), StrEscape(invokeUrlCmd.GetTooltip(), false), StrEscape(invokeUrlCmd.GetDescription(), false), invokeUrlCmd.GetUrl(), navCmdIndex, invokeUrlCmd.DisabledIfSelectionEmpty() ? "true" : "false", navCmdIndex, invokeUrlCmd.GetTarget(), invokeUrlCmd.GetTargetName()); navCmdIndex++; } else if (action == MgWebActions.Buffer || action == MgWebActions.SelectWithin || action == MgWebActions.Measure || action == MgWebActions.ViewOptions || action == MgWebActions.GetPrintablePage) { MgWebUiTargetCommand targetCmd = cmd as MgWebUiTargetCommand; if (action == MgWebActions.Measure) { if (measureCmdIndex != 0) { throw new Exception(MgLocalizer.GetString("ALREADYINMEASURE", locale)); } measureCmdIndex = i; } // declare a new ui target command object cmdObject = String.Format("commands[{0}] = new UiTargetCommand(\"{1}\", {2}, \"{3}\", \"{4}\", \"{5}\", \"{6}\", {7}, \"{8}\");\n", i, StrEscape(name, false), targetCmd.GetAction(), targetCmd.GetIconUrl(), targetCmd.GetDisabledIconUrl(), StrEscape(targetCmd.GetTooltip(), false), StrEscape(targetCmd.GetDescription(), false), targetCmd.GetTarget(), targetCmd.GetTargetName()); } else if (action == MgWebActions.Help) { MgWebHelpCommand helpCmd = cmd as MgWebHelpCommand; // declare a new help command object cmdObject = String.Format("commands[{0}] = new HelpCommand(\"{1}\", {2}, \"{3}\", \"{4}\", \"{5}\", \"{6}\", \"{7}\", {8}, \"{9}\");\n", i, StrEscape(name, false), helpCmd.GetAction(), helpCmd.GetIconUrl(), helpCmd.GetDisabledIconUrl(), StrEscape(helpCmd.GetTooltip(), false), StrEscape(helpCmd.GetDescription(), false), helpCmd.GetUrl(), helpCmd.GetTarget(), helpCmd.GetTargetName()); } else if (action == MgWebActions.PrintMap) { MgWebPrintCommand printCmd = cmd as MgWebPrintCommand; // declare the print layouts String layouts = "var layouts" + printCmdIndex + " = new Array();\n"; int j; for (j = 0; j < printCmd.GetPrintLayoutCount(); j++) { String layout = ""; layout = String.Format("layouts{0}[{1}] = \"{2}\";\n", printCmdIndex, j, printCmd.GetPrintLayoutAt(j)); layouts = layouts + layout; } cmdObjects = cmdObjects + layouts; // declare a new print command object cmdObject = String.Format("commands[{0}] = new PrintCommand(\"{1}\", {2}, \"{3}\", \"{4}\", \"{5}\", \"{6}\", layouts{7});\n", i, StrEscape(name, false), printCmd.GetAction(), printCmd.GetIconUrl(), printCmd.GetDisabledIconUrl(), StrEscape(printCmd.GetTooltip(), false), StrEscape(printCmd.GetDescription(), false), printCmdIndex); printCmdIndex++; } else if (action == MgWebActions.InvokeScript) { MgWebInvokeScriptCommand invokeScriptCmd = cmd as MgWebInvokeScriptCommand; // declare a new basic command object cmdObject = String.Format("commands[{0}] = new InvokeScriptCommand(\"{1}\", {2}, \"{3}\", \"{4}\", \"{5}\", \"{6}\", {7});\n", i, StrEscape(name, false), invokeScriptCmd.GetAction(), invokeScriptCmd.GetIconUrl(), invokeScriptCmd.GetDisabledIconUrl(), StrEscape(invokeScriptCmd.GetTooltip(), false), StrEscape(invokeScriptCmd.GetDescription(), false), scriptCmdIndex); userCode = userCode + "\nfunction UserFunc" + scriptCmdIndex + "()\n{\n" + invokeScriptCmd.GetCode() + "\n}\n"; userCodeCalls = userCodeCalls + String.Format("case {0}: UserFunc{1}(); break;\n", scriptCmdIndex, scriptCmdIndex); scriptCmdIndex++; } else { // declare a new basic command object cmdObject = String.Format("commands[{0}] = new BasicCommand(\"{1}\", {2}, \"{3}\", \"{4}\", \"{5}\", \"{6}\");\n", i, name, cmd.GetAction(), cmd.GetIconUrl(), cmd.GetDisabledIconUrl(), StrEscape(cmd.GetTooltip(), false), StrEscape(cmd.GetDescription(), false)); } cmdObjects = cmdObjects + cmdObject; cmds[name] = i.ToString(NumberFormatInfo.InvariantInfo); } userCodeCalls = userCodeCalls + "\n}\n"; //Declare toolbar items // String toolbarDef = DeclareUiItems(toolBar.GetWidgets(), "toolbarItems"); //Declare task items String taskListDef = DeclareUiItems(taskBar.GetTaskList(), "taskItems"); //Declare context menu items MgWebContextMenu ctxMenu = webLayout.GetContextMenu(); String ctxMenuDef; if (ctxMenu.IsVisible()) ctxMenuDef = DeclareUiItems(ctxMenu, "ctxMenuItems"); else ctxMenuDef = ""; //task items texts String taskItemTexts = ""; MgWebWidgetCollection taskButtons = taskBar.GetTaskButtons(); for (i = 0; i < 4; i++) { MgWebTaskBarWidget btn = (MgWebTaskBarWidget)taskButtons.GetWidget(i); if (i > 0) taskItemTexts += ","; taskItemTexts += "\"" + StrEscape(btn.GetName(), true) + "\"," + "\"" + StrEscape(btn.GetTooltip(), true) + "\"," + "\"" + StrEscape(btn.GetDescription(), true) + "\"," + "\"" + StrEscape(btn.GetIconUrl(), true) + "\"," + "\"" + StrEscape(btn.GetDisabledIconUrl(), true) + "\""; } //transmit the session to the map pane if one was specified to this request String sessionParam = ""; if (orgSessionId != "") { sessionParam = "&SESSION=" + orgSessionId; } //load the frameset template and format it String frameset = ""; String viewerType = (1 == forDwf) ? "DWF" : "HTML"; if (showTaskBar) { frameset = LoadTemplate(Request, "../viewerfiles/framesettaskbar.templ"); String[] vals = { statusbarHeight.ToString(NumberFormatInfo.InvariantInfo), taskWidth.ToString(NumberFormatInfo.InvariantInfo), toolbarHeight.ToString(NumberFormatInfo.InvariantInfo), srcToolbar, vpath + "mapframe.aspx", mapDefinitionUrl, viewerType, showLegend? "1" : "0", showProperties? "1" : "0", infoWidth.ToString(NumberFormatInfo.InvariantInfo), locale, webLayout.GetHyperlinkTarget().ToString(NumberFormatInfo.InvariantInfo), webLayout.GetHyperlinkTargetFrame(), webLayout.IsZoomControlVisible()? "1": "0", sessionParam, vpath + "formframe.aspx", toolbarHeight.ToString(NumberFormatInfo.InvariantInfo), srcTaskBar, srcTaskFrame, srcStatusbar }; frameset = Substitute(frameset, vals); } else { frameset = LoadTemplate(Request, "../viewerfiles/framesetnotaskbar.templ"); String[] vals = { toolbarHeight.ToString(NumberFormatInfo.InvariantInfo), statusbarHeight.ToString(NumberFormatInfo.InvariantInfo), srcToolbar, taskWidth.ToString(NumberFormatInfo.InvariantInfo), vpath + "mapframe.aspx", mapDefinitionUrl, viewerType, showLegend? "1" : "0", showProperties? "1" : "0", infoWidth.ToString(NumberFormatInfo.InvariantInfo), locale, webLayout.GetHyperlinkTarget().ToString(NumberFormatInfo.InvariantInfo), webLayout.GetHyperlinkTargetFrame(), webLayout.IsZoomControlVisible()? "1": "0", sessionParam, srcTaskFrame, vpath + "formframe.aspx", srcStatusbar, }; frameset = Substitute(frameset, vals); } String homePageUrl = taskPaneUrl; if (String.Compare(homePageUrl.Substring(0, 7), "http://", true) != 0) homePageUrl = vpath + homePageUrl; //load the HTML template and format it // String template = MgLocalizer.Localize(LoadTemplate(Request, "../viewerfiles/mainframe.templ"), locale, GetClientOS(Request)); String[] args = { webLayout.GetTitle(), locale, showToolbar? "1" : "0", showStatusbar? "1" : "0", showTaskPane? "1" : "0", showTaskPane? "0" : (showTaskBar? "1" : "0"), homePageUrl, defHome? "1" : "0", webLayoutDefinition, mapDef, taskWidth.ToString(NumberFormatInfo.InvariantInfo), center, webLayout.GetScale().ToString(NumberFormatInfo.InvariantInfo), StrEscape(title, false), (forDwf == 1)? "1" : "0", cmdObjects, toolbarDef, taskListDef, ctxMenuDef, userCode, taskItemTexts, selAwareCmds, vpath + "printablepageui.aspx", vpath + "measureui.aspx", vpath + "searchprompt.aspx", vpath + "bufferui.aspx", vpath + "selectwithinui.aspx", userCodeCalls, vpath + "viewoptions.aspx", frameset }; String templ = Substitute(template, args); Response.Write(templ); } catch (MgUnauthorizedAccessException) { RequestAuthentication(); return; } catch (MgUserNotFoundException) { RequestAuthentication(); return; } catch (MgAuthenticationFailedException e) { RequestAuthentication(); return; } catch (MgException e) { Response.Write(e.GetMessage()); Response.Write("
"); Response.Write(e.GetDetails()); } catch (Exception ne) { Response.Write(ne.Message); } %>