Beispiel #1
0
  /**
   * Create the given ViewManager
   *
   * @param viewDescriptor Identifies the VM
   * @param properties Property string to pass
   * @return The new one
   */
  public ViewManager createViewManager(ViewDescriptor viewDescriptor, String properties) {
    synchronized (viewManagers) {
      try {
        ViewManager viewManager = null;
        if (viewDescriptor == null) {
          viewDescriptor = new ViewDescriptor();
        }
        if (viewDescriptor.getClassNames().size() > 0) {
          Class viewManagerClass = Misc.findClass((String) viewDescriptor.getClassNames().get(0));
          Constructor ctor =
              Misc.findConstructor(
                  viewManagerClass,
                  new Class[] {IntegratedDataViewer.class, ViewDescriptor.class, String.class});

          if (ctor == null) {
            throw new IllegalArgumentException(
                "cannot create ViewManager:" + viewManagerClass.getName());
          }

          viewManager =
              (ViewManager) ctor.newInstance(new Object[] {getIdv(), viewDescriptor, properties});
        } else {
          viewManager = new MapViewManager(getIdv(), viewDescriptor, properties);
        }

        addViewManager(viewManager);
        return viewManager;
      } catch (Throwable e) {
        logException("In getViewManager", e);
        return null;
      }
    }
  }
Beispiel #2
0
  public static View create(StaplerRequest req, StaplerResponse rsp, ViewGroup owner)
      throws FormException, IOException, ServletException {
    String requestContentType = req.getContentType();
    if (requestContentType == null) throw new Failure("No Content-Type header set");

    boolean isXmlSubmission =
        requestContentType.startsWith("application/xml")
            || requestContentType.startsWith("text/xml");

    String name = req.getParameter("name");
    checkGoodName(name);
    if (owner.getView(name) != null) throw new Failure(Messages.Hudson_ViewAlreadyExists(name));

    String mode = req.getParameter("mode");
    if (mode == null || mode.length() == 0) {
      if (isXmlSubmission) {
        View v = createViewFromXML(name, req.getInputStream());
        v.owner = owner;
        rsp.setStatus(HttpServletResponse.SC_OK);
        return v;
      } else throw new Failure(Messages.View_MissingMode());
    }

    View v;
    if (mode != null && mode.equals("copy")) {
      v = copy(req, owner, name);
    } else {
      ViewDescriptor descriptor = all().findByName(mode);
      if (descriptor == null) {
        throw new Failure("No view type ‘" + mode + "’ is known");
      }

      // create a view
      v = descriptor.newInstance(req, req.getSubmittedForm());
    }
    v.owner = owner;

    // redirect to the config screen
    rsp.sendRedirect2(req.getContextPath() + '/' + v.getUrl() + v.getPostConstructLandingPage());

    return v;
  }
Beispiel #3
0
  /**
   * Find the view manager identified by the given view descriptor
   *
   * @param viewDescriptor The id of the VM
   * @return The VM or null if none found
   */
  public ViewManager findViewManager(ViewDescriptor viewDescriptor) {
    ViewManager viewManager = null;
    if (viewDescriptor == null) {
      viewDescriptor = new ViewDescriptor(ViewDescriptor.LASTACTIVE);
    }

    if (viewDescriptor.nameEquals(ViewDescriptor.LASTACTIVE)) {
      viewManager = getLastActiveViewManager();
      if (viewManager != null) {
        if (viewManager.isClassOk(viewDescriptor)) {
          return viewManager;
        }
      }
      List local = new ArrayList(viewManagers);
      for (int i = 0; i < local.size(); i++) {
        ViewManager vm = (ViewManager) local.get(i);
        if (vm.isClassOk(viewDescriptor)) {
          return vm;
        }
      }
    }
    return findViewManagerInList(viewDescriptor);
  }
Beispiel #4
0
 public static List<ViewDescriptor> allInstantiable() {
   List<ViewDescriptor> r = new ArrayList<ViewDescriptor>();
   for (ViewDescriptor d : all()) if (d.isInstantiable()) r.add(d);
   return r;
 }