Esempio n. 1
0
 protected void generateFiles(IProgressMonitor monitor) throws CoreException {
   super.generateFiles(monitor);
   // Copy the default splash screen if the branding option is selected
   if (copyBrandingDirectory()) {
     super.generateFiles(
         monitor, Activator.getDefault().getBundle().getEntry("branding/")); // $NON-NLS-1$
   }
 }
Esempio n. 2
0
 /*
  * Do a look-up and return the OSGi install area if it is set.
  */
 public static URL getOSGiInstallArea() {
   Location location =
       (Location)
           ServiceHelper.getService(
               Activator.getContext(), Location.class.getName(), Location.INSTALL_FILTER);
   if (location == null) return null;
   if (!location.isSet()) return null;
   return location.getURL();
 }
 /**
  * creates a new container instance.
  *
  * @param description the container type description.
  * @param parameters the parameter passed to the container constructor.
  * @return the factored container instance.
  * @see
  *     org.eclipse.ecf.core.provider.IContainerInstantiator#createInstance(org.eclipse.ecf.core.ContainerTypeDescription,
  *     java.lang.Object[])
  */
 public IContainer createInstance(
     final ContainerTypeDescription description, final Object[] parameters)
     throws ContainerCreateException {
   try {
     final RemoteOSGiService remoteOSGiService = Activator.getDefault().getRemoteOSGiService();
     String descriptionName = description.getName();
     boolean wss = descriptionName.equals(ROSGI_WEBSOCKETSS_CONFIG);
     boolean ws = (descriptionName.equals(ROSGI_WEBSOCKETS_CONFIG) || wss);
     Namespace ns =
         (wss
             ? R_OSGiWSSNamespace.getDefault()
             : ((ws) ? R_OSGiWSNamespace.getDefault() : R_OSGiNamespace.getDefault()));
     ID containerID = null;
     if (parameters == null) {
       String localHost = "localhost"; // $NON-NLS-1$
       if (useHostname) {
         try {
           localHost = InetAddress.getLocalHost().getCanonicalHostName();
         } catch (UnknownHostException e) {
           // Ignore
         }
       }
       final String nsScheme = ns.getScheme();
       final String wsProtocol = (wss ? WSS_PROTOCOL : (ws ? WS_PROTOCOL : null));
       int listeningPort =
           remoteOSGiService.getListeningPort((wsProtocol != null) ? wsProtocol : nsScheme);
       int idPort = -1;
       if (WSS_PROTOCOL.equals(wsProtocol) && listeningPort != WSS_DEFAULT_PORT)
         idPort = listeningPort;
       else if (WS_PROTOCOL.equals(wsProtocol) && listeningPort != WS_DEFAULT_PORT)
         idPort = listeningPort;
       String portStr = (idPort > 0 ? (":" + idPort) : ""); // $NON-NLS-1$ //$NON-NLS-2$
       containerID =
           createR_OSGiID(ns, new String(nsScheme + "://" + localHost + portStr)); // $NON-NLS-1$
     } else if (parameters.length > 0) {
       if (parameters[0] instanceof ID) containerID = (ID) parameters[0];
       else if (parameters[0] instanceof String)
         containerID = createR_OSGiID(ns, (String) parameters[0]);
       else if (parameters[0] instanceof Map) {
         Map params = (Map) parameters[0];
         String idStr = (String) params.get(ID_PROP);
         if (idStr == null)
           throw new NullPointerException("No ID prop found in parameters map"); // $NON-NLS-1$
         containerID = createR_OSGiID(ns, idStr);
       }
     }
     if (containerID == null)
       throw new ContainerCreateException(
           "Unsupported arguments " //$NON-NLS-1$
               + Arrays.asList(parameters));
     if (wss) return new R_OSGiWSSRemoteServiceContainer(remoteOSGiService, containerID);
     else if (ws) return new R_OSGiWSRemoteServiceContainer(remoteOSGiService, containerID);
     else return new R_OSGiRemoteServiceContainer(remoteOSGiService, containerID);
   } catch (Exception e) {
     throw new ContainerCreateException("Could not create R_OSGI ID", e); // $NON-NLS-1$
   }
 }
 public void setBundle(Bundle b) {
   try {
     MetaTypeInformation mtp = Activator.getMTP(b);
     jcmInfo.setProvider(mtp, b);
   } catch (Exception e) {
     e.printStackTrace();
     Activator.log.error("Failed to get MetaTypeInformation from bundle " + b.getBundleId(), e);
   }
 }
Esempio n. 5
0
 /*
  * Helper method to return the eclipse.home location. Return
  * null if it is unavailable.
  */
 public static File getEclipseHome() {
   Location eclipseHome =
       (Location)
           ServiceHelper.getService(
               Activator.getContext(), Location.class.getName(), Location.ECLIPSE_HOME_FILTER);
   if (eclipseHome == null || !eclipseHome.isSet()) return null;
   URL url = eclipseHome.getURL();
   if (url == null) return null;
   return URLUtil.toFile(url);
 }
Esempio n. 6
0
 private void notifyListeners() {
   for (DatabaseModelListener listener : listeners) {
     try {
       listener.connectedStatusChangedTo(connected());
     } catch (Exception exc) {
       IStatus status =
           new Status(
               IStatus.ERROR, Activator.PLUGIN_ID, "error during listener notification", exc);
       Activator.getDefault().getLog().log(status);
     }
   }
 }
Esempio n. 7
0
 public URL getTemplateLocation() {
   try {
     String[] candidates = getDirectoryCandidates();
     for (int i = 0; i < candidates.length; i++) {
       if (Activator.getDefault().getBundle().getEntry(candidates[i]) != null) {
         URL candidate = new URL(getInstallURL(), candidates[i]);
         return candidate;
       }
     }
   } catch (MalformedURLException e) { // do nothing
   }
   return null;
 }
Esempio n. 8
0
  /** Returns the name of the Eclipse application launcher. */
  private static String getLauncherName(String name, String os, File installFolder) {
    if (os == null) {
      EnvironmentInfo info =
          (EnvironmentInfo)
              ServiceHelper.getService(Activator.getContext(), EnvironmentInfo.class.getName());
      if (info == null) return null;
      os = info.getOS();
    }

    if (os.equals(org.eclipse.osgi.service.environment.Constants.OS_WIN32)) {
      IPath path = new Path(name);
      if ("exe".equals(path.getFileExtension())) // $NON-NLS-1$
      return name;
      return name + ".exe"; // $NON-NLS-1$
    }
    if (os.equals(Constants.MACOSX_BUNDLED)) {
      return "/Contents/MacOS/" + name; // $NON-NLS-1$
    }

    if (os.equals(org.eclipse.osgi.service.environment.Constants.OS_MACOSX)) {
      IPath path = new Path(name);
      if (path.segment(0).endsWith(".app")) // $NON-NLS-1$
      return name;

      String appName = null;
      if (installFolder != null) {
        File appFolder = new File(installFolder, name + ".app"); // $NON-NLS-1$
        if (appFolder.exists()) {
          try {
            appName = appFolder.getCanonicalFile().getName();
          } catch (IOException e) {
            appName = appFolder.getName();
          }
        }
      }

      StringBuffer buffer = new StringBuffer();
      if (appName != null) {
        buffer.append(appName);
      } else {
        buffer.append(name.substring(0, 1).toUpperCase());
        buffer.append(name.substring(1));
        buffer.append(".app"); // $NON-NLS-1$
      }
      buffer.append("/Contents/MacOS/"); // $NON-NLS-1$
      buffer.append(name);
      return buffer.toString();
    }
    return name;
  }
Esempio n. 9
0
  /**
   * Looks for the project in all workspaces of the user and removes it when found.
   *
   * @see WorkspaceResourceHandler#handleRemoveProject(HttpServletRequest, HttpServletResponse,
   *     WebWorkspace)
   * @param userName the user name
   * @param webProject the project to remove
   * @return ServerStatus <code>OK</code> if the project has been found and successfully removed,
   *     <code>ERROR</code> if an error occurred or the project couldn't be found
   */
  public static ServerStatus removeProject(String userName, WebProject webProject) {
    try {
      WebUser webUser = WebUser.fromUserId(userName);
      JSONArray workspacesJSON = webUser.getWorkspacesJSON();
      for (int i = 0; i < workspacesJSON.length(); i++) {
        JSONObject workspace = workspacesJSON.getJSONObject(i);
        String workspaceId = workspace.getString(ProtocolConstants.KEY_ID);
        WebWorkspace webWorkspace = WebWorkspace.fromId(workspaceId);
        JSONArray projectsJSON = webWorkspace.getProjectsJSON();
        for (int j = 0; j < projectsJSON.length(); j++) {
          JSONObject project = projectsJSON.getJSONObject(j);
          String projectId = project.getString(ProtocolConstants.KEY_ID);
          if (projectId.equals(webProject.getId())) {
            // If found, remove project from workspace
            try {
              WorkspaceResourceHandler.removeProject(userName, webWorkspace, webProject);
            } catch (CoreException e) {
              // we are unable to write in the platform location!
              String msg =
                  NLS.bind(
                      "Server content location could not be written: {0}",
                      Activator.getDefault().getRootLocationURI());
              return new ServerStatus(
                  IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
            }

            return new ServerStatus(IStatus.OK, HttpServletResponse.SC_OK, null, null);
          }
        }
      }
    } catch (JSONException e) {
      // ignore, no project will be harmed
    }
    // FIXME: not sure about this one
    return new ServerStatus(IStatus.OK, HttpServletResponse.SC_OK, null, null);
  }
Esempio n. 10
0
  private boolean handlePost(
      HttpServletRequest request, HttpServletResponse response, String pathString)
      throws IOException, JSONException, ServletException, URISyntaxException, CoreException,
          NoHeadException, NoMessageException, ConcurrentRefUpdateException,
          WrongRepositoryStateException {
    // make sure required fields are set
    JSONObject toAdd = OrionServlet.readJSONRequest(request);
    if (toAdd.optBoolean(GitConstants.KEY_PULL, false)) {
      GitUtils.createGitCredentialsProvider(toAdd);
      GitCredentialsProvider cp = GitUtils.createGitCredentialsProvider(toAdd);
      boolean force = toAdd.optBoolean(GitConstants.KEY_FORCE, false);
      return pull(request, response, cp, pathString, force);
    }

    Clone clone = new Clone();
    String url = toAdd.optString(GitConstants.KEY_URL, null);
    // method handles repository clone or just repository init
    // decision is based on existence of GitUrl argument
    boolean initOnly;
    if (url == null || url.isEmpty()) initOnly = true;
    else {
      initOnly = false;
      if (!validateCloneUrl(url, request, response)) return true;
      clone.setUrl(new URIish(url));
    }
    String cloneName = toAdd.optString(ProtocolConstants.KEY_NAME, null);
    if (cloneName == null) cloneName = request.getHeader(ProtocolConstants.HEADER_SLUG);
    // expected path /workspace/{workspaceId}
    String workspacePath = toAdd.optString(ProtocolConstants.KEY_LOCATION, null);
    // expected path /file/{workspaceId}/{projectName}[/{path}]
    String filePathString = toAdd.optString(ProtocolConstants.KEY_PATH, null);
    IPath filePath = filePathString == null ? null : new Path(filePathString);
    if (filePath != null && filePath.segmentCount() < 3) filePath = null;
    if (filePath == null && workspacePath == null) {
      String msg =
          NLS.bind(
              "Either {0} or {1} should be provided: {2}",
              new Object[] {ProtocolConstants.KEY_PATH, ProtocolConstants.KEY_LOCATION, toAdd});
      return statusHandler.handleRequest(
          request,
          response,
          new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
    }
    // only during init operation filePath or cloneName must be provided
    // during clone operation, name can be obtained from URL
    if (initOnly && filePath == null && cloneName == null) {
      String msg =
          NLS.bind(
              "Either {0} or {1} should be provided: {2}",
              new Object[] {ProtocolConstants.KEY_PATH, GitConstants.KEY_NAME, toAdd});
      return statusHandler.handleRequest(
          request,
          response,
          new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
    }
    if (!validateCloneName(cloneName, request, response)) return true;

    // prepare the WebClone object, create a new project if necessary
    WebProject webProject = null;
    boolean webProjectExists = false;
    if (filePath != null) {
      // path format is /file/{workspaceId}/{projectName}/[filePath]
      clone.setId(filePath.toString());
      webProject = GitUtils.projectFromPath(filePath);
      // workspace path format needs to be used if project does not exist
      if (webProject == null) {
        String msg = NLS.bind("Specified project does not exist: {0}", filePath.segment(2));
        return statusHandler.handleRequest(
            request,
            response,
            new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
      }
      webProjectExists = true;
      clone.setContentLocation(
          webProject.getProjectStore().getFileStore(filePath.removeFirstSegments(3)).toURI());
      if (cloneName == null)
        cloneName = filePath.segmentCount() > 2 ? filePath.lastSegment() : webProject.getName();
    } else if (workspacePath != null) {
      IPath path = new Path(workspacePath);
      // TODO: move this to CloneJob
      // if so, modify init part to create a new project if necessary
      WebWorkspace workspace = WebWorkspace.fromId(path.segment(1));
      String id = WebProject.nextProjectId();
      if (cloneName == null) cloneName = new URIish(url).getHumanishName();
      cloneName = getUniqueProjectName(workspace, cloneName);
      webProjectExists = false;
      webProject = WebProject.fromId(id);
      webProject.setName(cloneName);

      try {
        WorkspaceResourceHandler.computeProjectLocation(request, webProject, null, false);
      } catch (CoreException e) {
        // we are unable to write in the platform location!
        String msg =
            NLS.bind(
                "Server content location could not be written: {0}",
                Activator.getDefault().getRootLocationURI());
        return statusHandler.handleRequest(
            request,
            response,
            new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e));
      } catch (URISyntaxException e) {
        // should not happen, we do not allow linking at this point
      }

      try {
        // If all went well, add project to workspace
        WorkspaceResourceHandler.addProject(request.getRemoteUser(), workspace, webProject);
      } catch (CoreException e) {
        return statusHandler.handleRequest(
            request,
            response,
            new ServerStatus(
                IStatus.ERROR,
                HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "Error persisting project state",
                e));
      }

      URI baseLocation = getURI(request);
      baseLocation =
          new URI(
              baseLocation.getScheme(),
              baseLocation.getUserInfo(),
              baseLocation.getHost(),
              baseLocation.getPort(),
              workspacePath,
              baseLocation.getQuery(),
              baseLocation.getFragment());
      clone.setId(GitUtils.pathFromProject(workspace, webProject).toString());
      clone.setContentLocation(webProject.getProjectStore().toURI());
    }
    clone.setName(cloneName);
    clone.setBaseLocation(getURI(request));
    JSONObject cloneObject = clone.toJSON();
    String cloneLocation = cloneObject.getString(ProtocolConstants.KEY_LOCATION);

    if (initOnly) {
      // git init
      InitJob job =
          new InitJob(
              clone, TaskJobHandler.getUserId(request), request.getRemoteUser(), cloneLocation);
      return TaskJobHandler.handleTaskJob(request, response, job, statusHandler);
    }
    // git clone
    // prepare creds
    GitCredentialsProvider cp = GitUtils.createGitCredentialsProvider(toAdd);
    cp.setUri(new URIish(clone.getUrl()));

    // if all went well, clone
    CloneJob job =
        new CloneJob(
            clone,
            TaskJobHandler.getUserId(request),
            cp,
            request.getRemoteUser(),
            cloneLocation,
            webProjectExists
                ? null
                : webProject /* used for cleaning up, so null when not needed */);
    return TaskJobHandler.handleTaskJob(request, response, job, statusHandler);
  }
Esempio n. 11
0
 protected URL getInstallURL() {
   return Activator.getDefault().getInstallURL();
 }
Esempio n. 12
0
 protected ResourceBundle getPluginResourceBundle() {
   Bundle bundle = Platform.getBundle(Activator.getPluginId());
   return Platform.getResourceBundle(bundle);
 }
Esempio n. 13
0
  public void _jspService(HttpServletRequest request, HttpServletResponse response)
      throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
      response.setContentType("text/html; charset=utf-8");
      pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;
      _jspx_resourceInjector =
          (org.glassfish.jsp.api.ResourceInjector)
              application.getAttribute("com.sun.appserv.jsp.resource.injector");

      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write(
          "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n");
      out.write("<html xmlns=\"http://www.w3.org/1999/xhtml\" >\r\n");
      out.write("<head>\r\n");
      out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\r\n");
      out.write("<title>Neonat论坛</title>\r\n");
      out.write(
          "<link href=\"forum.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\">\r\n");
      out.write("</head>\r\n");
      out.write("<body>\r\n");
      out.write("<div id=\"page\">\r\n");
      out.write("  <div id=\"header\">\r\n");
      out.write("    <div class=\"clearfix\">\r\n");
      out.write("      <div style=\"padding:15px 0 10px 0;\">\r\n");
      out.write("          <div class=\"title_logo\"></div>\r\n");
      out.write("      </div>\r\n");
      out.write(
          "      <div class=\"toolbar\"><a href=\"new.jsp\"><img src=\"images/post.gif\" /></a><div style=\"float:right\">论坛发帖总数:\r\n");
      out.write("\t\t");

      BundleContext context = Activator.getContext();
      NeonatModelService ms =
          context.getService(context.getServiceReference(NeonatModelService.class));
      Board board = ms.getBoard();
      out.println(board.getTopicCount());

      out.write("\r\n");
      out.write("\t  </div></div>\r\n");
      out.write("\t  \r\n");
      out.write("\t <table id=\"forum_main\" cellspacing=\"1\">\r\n");
      out.write("        <thead>\r\n");
      out.write("          <tr>\r\n");
      out.write("            <td bgcolor=\"#477AA5\" style=\"width: 20px;\">ID</td>\r\n");
      out.write(
          "            <td colspan=\"2\" bgcolor=\"#477AA5\" style=\"border-left: 1px solid white;\">主题</td>\r\n");
      out.write("            <td bgcolor=\"#477AA5\" style=\"width: 50px;\">回复</td>\r\n");
      out.write("            <td bgcolor=\"#477AA5\" style=\"width: 100px;\">发帖时间</td>\r\n");
      out.write("            <td bgcolor=\"#477AA5\" style=\"width: 100px;\">作者</td>\r\n");
      out.write("          </tr>\r\n");
      out.write("        </thead>\r\n");
      out.write("        <tbody>\r\n");
      out.write("           ");

      for (Iterator<Entry<Integer, Topic>> i = board.getTopicsMap().entrySet().iterator();
          i.hasNext(); ) {
        Topic topic = i.next().getValue();

        out.write("\r\n");
        out.write("\t        <tr>\r\n");
        out.write("\t            <td class=\"topic_id\">");
        out.print(topic.getId());
        out.write("</td>\r\n");
        out.write("\t            <td class=\"topic_icon unread_topic\"></td>\r\n");
        out.write("\t            <td class=\"topic_title\"><a href=\"content.jsp?id=");
        out.print(topic.getId());
        out.write('"');
        out.write('>');
        out.print(topic.getTitle());
        out.write("</a></td>\r\n");
        out.write("\t            <td class=\"topic_replies\">");
        out.print(topic.getReplyTopics().size());
        out.write("</td>\r\n");
        out.write("\t            <td class=\"topic_time\">");
        out.print(topic.getDate().toLocaleString());
        out.write("</td>\r\n");
        out.write(
            "\t            <td class=\"topic_author\"><a href=\"#\" target=\"_blank\">IcyFenix</a></td>\r\n");
        out.write("\t        </tr>\r\n");
        out.write("\t        ");
      }

      out.write("\r\n");
      out.write("      </table>\r\n");
      out.write("      <br />\r\n");
      out.write(
          "      <div style=\"text-align:center\">©2011-2012 Neonat BBS All rights reserved.</div>\r\n");
      out.write("    </div>\r\n");
      out.write("  </div>\r\n");
      out.write("</div>\r\n");
      out.write("</body>\r\n");
      out.write("</html>");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)) {
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0) out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else throw new ServletException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }