Beispiel #1
1
 /** renders the template and wraps it to a full httpresponse */
 public void renderTemplate(IRequest req) {
   if (tpl == null) {
     if (this.ts == null) ts = Server.srv.templatemanager.getTemplateSet("default");
     tpl = ts.getTemplate(tName);
     if (tpl == null) tpl = ts.getTemplate("not_found");
   }
   if (tpl.isRedirect()) {
     this.setRedirectTo(tpl.getDestination(), req.getCookieDomain());
     return;
   }
   if (!nocache
       && !nostore
       && !tpl.hasToBeRendered(
           req.getProperty("if-none-match"),
           HttpDateParser.parseDate(req.getProperty("if-modified-since")))) {
     StringBuffer sb = new StringBuffer(isHTTP11 ? "HTTP/1.1" : "HTTP/1.0");
     sb.append(IResponseHeaders.NOT_MODIFIED);
     sb.trimToSize();
     prepareForSending(CharBuffer.wrap(sb.toString()));
     return;
   }
   String cntnt = tpl.render(req);
   if (cntnt == null || cntnt.length() < 1) {
     Server.log(
         this,
         "renderTemplate: rendered template has no content",
         Server.MSG_STATE,
         Server.LVL_MAJOR);
     resCode = NOCONTENT_CODE;
     StringBuffer sb = new StringBuffer();
     sb.append("<html><body><b>The requested page could not be displayed!<br><br>Reason:</b> ");
     if (tpl == null) {
       sb.append("No template given");
     } else {
       sb.append("Template '");
       sb.append(tpl.getName());
       sb.append("' has not been found on this server.");
     }
     sb.append("</body></html>");
     wrap(sb.toString(), req.getCookieDomain());
     return;
   }
   nocache = tpl.notCacheable();
   //      if (nocache)
   //          Server.log (this, "not cacheable", Server.MSG_STATE, Server.LVL_VERY_VERBOSE);
   wrap(cntnt, tpl.getEtag(), req.getCookieDomain());
 }
 private void update() {
   Vector<String> data = new Vector<String>();
   Iterator<Template> i = templateMap.values().iterator();
   while (i.hasNext()) {
     Template template = i.next();
     data.add(template.getName());
   }
   templateList.setListData(data);
   repaint();
 }
  @Test
  public void testListTemplates() throws Exception {
    Set<Template> response = client.getTemplateClient().listTemplates();
    assert null != response;
    long templateCount = response.size();
    assertTrue(templateCount >= 0);
    for (Template template : response) {
      Template newDetails =
          Iterables.getOnlyElement(
              client
                  .getTemplateClient()
                  .listTemplates(zoneId(template.getZoneId()).id(template.getId())));
      Logger.CONSOLE.info("Checking template: " + template);

      assertEquals(template, newDetails);
      assertEquals(
          template,
          client.getTemplateClient().getTemplateInZone(template.getId(), template.getZoneId()));
      assert template.getId() > 0 : template;
      assert template.getName() != null : template;
      assert template.getDisplayText() != null : template;
      assert template.getCreated() != null : template;
      assert template.getFormat() != null && template.getFormat() != Template.Format.UNRECOGNIZED
          : template;
      assert template.getOSType() != null : template;
      assert template.getOSTypeId() > 0 : template;
      assert template.getAccount() != null : template;
      assert template.getZone() != null : template;
      assert template.getZoneId() > 0 : template;
      assert (template.getStatus() == null || template.getStatus().equals("Download Complete"))
          : template;
      assert template.getType() != null && template.getType() != Template.Type.UNRECOGNIZED
          : template;
      assert template.getHypervisor() != null : template;
      assert template.getDomain() != null : template;
      assert template.getDomainId() > 0 : template;
      assert template.getSize() > 0 : template;
    }
  }
  public ManageTemplatesDialog(MainFrame mainFrame) {
    super(mainFrame, "Manage Templates", true);

    JPanel rootPanel = new JPanel(new BorderLayout());
    rootPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    GridBagLayout layout = new GridBagLayout();
    JPanel mainPanel = new JPanel(layout);
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0d;
    c.weighty = 0.0d;

    JPanel textPanel =
        SwingTools.createTextPanel(
            "Manage Templates...",
            "Please select templates to delete them. Only "
                + "user defined templates can be removed.");
    c.gridwidth = GridBagConstraints.REMAINDER;
    layout.setConstraints(textPanel, c);
    mainPanel.add(textPanel);

    Component sep = Box.createVerticalStrut(10);
    c.gridwidth = GridBagConstraints.REMAINDER;
    layout.setConstraints(sep, c);
    mainPanel.add(sep);

    // add components to main panel
    File[] templateFiles =
        ParameterService.getUserRapidMinerDir()
            .listFiles(
                new FileFilter() {

                  public boolean accept(File file) {
                    return file.getName().endsWith(".template");
                  }
                });
    for (int i = 0; i < templateFiles.length; i++) {
      try {
        Template template = new Template(templateFiles[i]);
        templateMap.put(template.getName(), template);
      } catch (InstantiationException e) {
        SwingTools.showSimpleErrorMessage(
            "Cannot load template file '" + templateFiles[i] + "'", e);
      }
    }

    JScrollPane listPane = new ExtendedJScrollPane(templateList);
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weighty = 1.0d;
    layout.setConstraints(listPane, c);
    mainPanel.add(listPane);
    c.weighty = 0.0d;

    // buttons
    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    JButton deleteButton = new JButton("Delete");
    deleteButton.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            delete();
          }
        });
    buttonPanel.add(deleteButton);
    JButton okButton = new JButton("Ok");
    okButton.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            ok();
          }
        });
    buttonPanel.add(okButton);

    rootPanel.add(mainPanel, BorderLayout.CENTER);
    rootPanel.add(buttonPanel, BorderLayout.SOUTH);
    getContentPane().add(rootPanel);

    update();
    pack();
    setSize(250, 400);
    setLocationRelativeTo(mainFrame);
  }