1 11 package org.eclipse.update.internal.ui.servlets; 12 13 import java.io.*; 14 import java.net.*; 15 import java.util.*; 16 17 import javax.servlet.*; 18 import javax.servlet.http.*; 19 20 import org.eclipse.jface.wizard.*; 21 import org.eclipse.swt.custom.*; 22 import org.eclipse.swt.widgets.*; 23 import org.eclipse.update.core.*; 24 import org.eclipse.update.internal.search.*; 25 import org.eclipse.update.internal.ui.*; 26 import org.eclipse.update.internal.ui.parts.*; 27 import org.eclipse.update.internal.ui.wizards.*; 28 import org.eclipse.update.operations.*; 29 import org.eclipse.update.search.*; 30 31 38 public class InstallServlet extends HttpServlet { 39 private ServletConfig servletConfig; 40 public static final String SERVLET_NAME = "/InstallServlet"; 42 public void init(ServletConfig config) throws ServletException { 43 this.servletConfig = config; 44 } 45 46 public void destroy() { 47 } 48 49 public ServletConfig getServletConfig() { 50 return servletConfig; 51 } 52 53 public String getServletInfo() { 54 return "Eclipse Install servlet"; } 56 57 public void service( 58 HttpServletRequest servletRequest, 59 HttpServletResponse servletResponse) 60 throws ServletException, IOException { 61 PrintWriter writer = 62 ServletsUtil.createResponsePrologue(servletResponse); 63 execute(writer, servletRequest); 64 ServletsUtil.createResponseEpilogue( 65 servletRequest, 66 servletResponse, 67 writer); 68 } 69 70 74 private void execute( 75 PrintWriter writer, 76 HttpServletRequest servletRequest) { 77 String serverURL = servletRequest.getParameter("server"); String license = servletRequest.getParameter("license"); boolean needLicensePage = true; 80 if (license != null && license.equalsIgnoreCase("false")) needLicensePage = false; 82 83 String [] versionedIds = servletRequest.getParameterValues("feature"); 85 if (serverURL == null) { 86 createPageError(writer, UpdateUI.getString("InstallServlet.unknownServerURL")); return; 88 } 89 if (versionedIds == null) { 90 createPageError(writer, UpdateUI.getString("InstallServlet.noFeatures")); return; 92 } 93 if (OperationsManager.isInProgress()) { 94 ServletsUtil.createError(writer, UpdateUI.getString("InstallServlet.inProgress"), null); return; 96 } 97 try { 102 URL url = new URL(serverURL); 103 VersionedIdentifier[] vids = 104 computeVersionedIdentifiers(versionedIds); 105 boolean success = 106 executeInstall(writer, url, vids, needLicensePage); 107 if (success) 108 ServletsUtil.createInfo(writer); 109 } catch (MalformedURLException e) { 110 createPageError(writer, UpdateUI.getFormattedMessage("InstallServlet.incorrectURLFormat", serverURL.toString())); 112 } 113 } 114 115 private void createPageError(PrintWriter writer, String problem) { 116 ServletsUtil.createError(writer, problem, UpdateUI.getString("InstallServlet.contactWebmaster")); } 118 119 private VersionedIdentifier[] computeVersionedIdentifiers(String [] array) { 120 ArrayList result = new ArrayList(); 121 for (int i = 0; i < array.length; i++) { 122 String id_version = array[i]; 123 int sep = id_version.lastIndexOf('_'); 124 if (sep == -1) 125 continue; 126 String id = id_version.substring(0, sep); 127 String version = id_version.substring(sep + 1); 128 VersionedIdentifier vid = new VersionedIdentifier(id, version); 129 result.add(vid); 130 } 131 return (VersionedIdentifier[]) result.toArray( 132 new VersionedIdentifier[result.size()]); 133 } 134 135 private boolean executeInstall( 136 final PrintWriter writer, 137 final URL siteURL, 138 final VersionedIdentifier[] vids, 139 final boolean needLicensePage) { 140 141 Display display = SWTUtil.getStandardDisplay(); 142 final boolean[] result = new boolean[] { false }; 143 144 display.syncExec(new Runnable () { 145 public void run() { 146 final Shell shell = UpdateUI.getActiveWorkbenchShell(); 147 BusyIndicator.showWhile(shell.getDisplay(), new Runnable () { 148 public void run() { 149 result[0] = 150 doExecuteInstall( 151 writer, 152 shell, 153 siteURL, 154 vids, 155 needLicensePage); 156 } 157 }); 158 } 159 }); 160 return result[0]; 161 } 162 163 private boolean doExecuteInstall( 164 PrintWriter writer, 165 final Shell shell, 166 URL siteURL, 167 VersionedIdentifier[] vids, 168 final boolean needLicensePage) { 169 170 shell.forceActive(); 171 172 UpdateSearchScope searchScope = new UpdateSearchScope(); 173 searchScope.addSearchSite( 174 siteURL.toString(), 175 siteURL, 176 new String [0]); 177 178 final UpdateSearchRequest searchRequest = 179 new UpdateSearchRequest( 180 new SiteSearchCategory(), 181 searchScope); 182 183 searchRequest.addFilter(new VersionedIdentifiersFilter(vids)); 184 searchRequest.addFilter(new EnvironmentFilter()); 185 searchRequest.addFilter(new BackLevelFilter()); 186 187 shell.getDisplay().asyncExec(new Runnable () { 188 public void run() { 189 openWizard(shell, searchRequest); 190 } 191 }); 192 return true; 193 } 194 195 196 private void openWizard(Shell shell, UpdateSearchRequest searchRequest) { 197 InstallWizard wizard = new InstallWizard(searchRequest); 198 WizardDialog dialog = new ResizableWizardDialog(shell, wizard); 199 dialog.create(); 200 dialog.getShell().setSize(600, 500); 203 dialog.open(); 204 if (wizard.isSuccessfulInstall()) 205 UpdateUI.requestRestart(); 206 } 207 } 208 | Popular Tags |