Exemple #1
0
  @Override
  @SuppressWarnings("unchecked")
  public TopComponent getTopComponent() {
    // Loading the multiview windows:
    FileObject multiviewsFolder = FileUtil.getConfigFile("skitmultiviews");
    FileObject[] kids = multiviewsFolder.getChildren();
    MultiViewDescription[] descriptionArray = new MultiViewDescription[kids.length];
    ArrayList<MultiViewDescription> listOfDescs = new ArrayList<MultiViewDescription>();

    for (FileObject kid : FileUtil.getOrder(Arrays.asList(kids), true)) {
      MultiViewDescription attribute = (MultiViewDescription) kid.getAttribute("multiview");

      if (attribute instanceof ContextAwareInstance) {
        Lookup lu = Lookups.fixed(this);
        attribute =
            ((ContextAwareInstance<MultiViewDescription>) attribute).createContextAwareInstance(lu);
      }

      listOfDescs.add(attribute);
    }

    for (int i = 0; i < listOfDescs.size(); i++) {
      descriptionArray[i] = listOfDescs.get(i);
    }

    CloneableTopComponent ctc =
        MultiViewFactory.createCloneableMultiView(descriptionArray, descriptionArray[0]);

    return ctc;
  }
  /**
   * See issue #57773 for details. Toolbar should be updated with possible changes after module
   * install/uninstall
   */
  private void installModulesInstallationListener() {
    moduleRegListener =
        new FileChangeAdapter() {
          public @Override void fileChanged(FileEvent fe) {
            // some module installed/uninstalled. Refresh toolbar content
            Runnable r =
                new Runnable() {
                  public void run() {
                    if (isToolbarVisible()) {
                      checkPresentersRemoved();
                      checkPresentersAdded();
                    }
                  }
                };
            Utilities.runInEventDispatchThread(r);
          }
        };

    FileObject moduleRegistry = FileUtil.getConfigFile("Modules"); // NOI18N

    if (moduleRegistry != null) {
      moduleRegistry.addFileChangeListener(
          FileUtil.weakFileChangeListener(moduleRegListener, moduleRegistry));
    }
  }
  public void savePreset(String name, Layout layout) {
    Preset preset = addPreset(new Preset(name, layout));

    try {
      // Create file if dont exist
      FileObject folder = FileUtil.getConfigFile("layoutpresets");
      if (folder == null) {
        folder = FileUtil.getConfigRoot().createFolder("layoutpresets");
      }
      FileObject presetFile = folder.getFileObject(name, "xml");
      if (presetFile == null) {
        presetFile = folder.createData(name, "xml");
      }

      // Create doc
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder documentBuilder = factory.newDocumentBuilder();
      final Document document = documentBuilder.newDocument();
      document.setXmlVersion("1.0");
      document.setXmlStandalone(true);

      // Write doc
      preset.writeXML(document);

      // Write XML file
      Source source = new DOMSource(document);
      Result result = new StreamResult(FileUtil.toFile(presetFile));
      Transformer transformer = TransformerFactory.newInstance().newTransformer();
      transformer.setOutputProperty(OutputKeys.INDENT, "yes");
      transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
      transformer.transform(source, result);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 private static DataObject findTemplate(String name) {
   FileObject tFo = FileUtil.getConfigFile(name);
   if (tFo == null) {
     return null;
   }
   try {
     return DataObject.find(tFo);
   } catch (DataObjectNotFoundException e) {
     return null;
   }
 }
 @Override
 protected FileSystem createFS(String... resources) throws IOException {
   for (String s : resources) {
     FileObject fo = FileUtil.getConfigFile(s.replaceAll("/.*", ""));
     if (fo != null) {
       fo.delete();
     }
   }
   FileSystem sfs = FileUtil.getConfigRoot().getFileSystem();
   for (String s : resources) {
     assertNotNull("creating: " + s, FileUtil.createData(sfs.getRoot(), s));
   }
   return sfs;
 }
 private void loadPresets() {
   FileObject folder = FileUtil.getConfigFile("layoutpresets");
   if (folder != null) {
     for (FileObject child : folder.getChildren()) {
       if (child.isValid() && child.hasExt("xml")) {
         try {
           InputStream stream = child.getInputStream();
           DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
           DocumentBuilder builder = factory.newDocumentBuilder();
           Document document = builder.parse(stream);
           Preset preset = new Preset(document);
           addPreset(preset);
         } catch (Exception ex) {
           ex.printStackTrace();
         }
       }
     }
   }
 }
Exemple #7
0
  /**
   * Creates the default CASA file object in the JBI project.
   *
   * @param project a JBI project
   * @return the newly created CASA file object
   */
  public static FileObject createDefaultCasaFileObject(JbiProject project) {
    ProjectInformation projInfo = project.getLookup().lookup(ProjectInformation.class);
    assert projInfo != null;
    String projName = projInfo.getName();
    FileObject confFO = project.getProjectDirectory().getFileObject(CASA_DIR_NAME);
    FileObject casaFO = null;
    try {
      FileObject casaTemplateFO =
          FileUtil.getConfigFile(
              "org-netbeans-modules-compapp-projects-jbi/project.casa" // NOI18N
              );
      casaFO = FileUtil.copyFile(casaTemplateFO, confFO, projName);
      //            registerCasaFileListener(project);
    } catch (IOException ex) {
      ex.printStackTrace();
    }

    return casaFO;
  }
Exemple #8
0
  public static Action findAction(String key) {
    FileObject fo = FileUtil.getConfigFile(key);

    if (fo != null && fo.isValid()) {
      try {
        DataObject dob = DataObject.find(fo);
        InstanceCookie ic = dob.getCookie(InstanceCookie.class);

        if (ic != null) {
          Object instance = ic.instanceCreate();
          if (instance instanceof Action) {
            Action a = (Action) instance;
            return a;
          }
        }
      } catch (Exception e) {
        ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
        return null;
      }
    }
    return null;
  }
  private void loadFromDefaultFileSystem() {
    FileObject f = FileUtil.getConfigFile("SaaSServices"); // NOI18N

    if (f != null && f.isFolder()) {
      Enumeration<? extends FileObject> en = f.getFolders(false);
      while (en.hasMoreElements()) {
        FileObject groupFolder = en.nextElement();
        for (FileObject fo : groupFolder.getChildren()) {
          if (fo.isFolder()) {
            continue;
          }
          if (PROFILE_PROPERTIES_FILE.equals(fo.getNameExt())) {
            continue;
          }
          loadSaasServiceFile(fo, false);
        }
        SaasGroup g = rootGroup.getChildGroup(groupFolder.getName());
        if (g != null) {
          g.setIcon16Path((String) groupFolder.getAttribute("icon16"));
          g.setIcon32Path((String) groupFolder.getAttribute("icon32"));
        }
      }
    }
  }
  public boolean generateTarget(ProgressHandle ph, String target) {
    if (mapping.getServiceMapping(target) != null) {
      String msg = NbBundle.getMessage(ClientJavonTemplate.class, "MSG_Client"); // NOI18N
      ph.progress(msg);
      OutputLogger.getInstance().log(msg);
      mapping.setProperty("target", "client");

      JavonMapping.Service service = mapping.getServiceMapping(target);
      FileObject outputDir =
          FileUtil.toFileObject(
              FileUtil.normalizeFile(new File(mapping.getClientMapping().getOutputDirectory())));
      outputDir =
          outputDir.getFileObject(mapping.getClientMapping().getPackageName().replace('.', '/'));

      FileObject outputFile =
          outputDir.getFileObject(mapping.getClientMapping().getClassName(), "java");
      if (outputFile == null) {
        OutputLogger.getInstance()
            .log(
                MessageFormat.format(
                    NbBundle.getMessage(ClientJavonTemplate.class, "MSG_ClientJavonCreation"),
                    mapping.getClientMapping().getClassName())); // NOI18N
        try {
          outputFile = outputDir.createData(mapping.getClientMapping().getClassName(), "java");
        } catch (IOException e) {
          OutputLogger.getInstance()
              .log(
                  LogLevel.ERROR,
                  MessageFormat.format(
                      NbBundle.getMessage(ClientJavonTemplate.class, "MSG_FailClientJavonCreation"),
                      mapping.getClientMapping().getClassName())); // NOI18N
        }
      }
      OutputFileFormatter off = null;
      try {
        off = new OutputFileFormatter(outputFile);
      } catch (DataObjectNotFoundException e) {
        generationFailed(e, outputFile);
        return false;
      } catch (IOException e) {
        generationFailed(e, outputFile);
        return false;
      }

      ScriptEngineManager mgr = new ScriptEngineManager();
      ScriptEngine eng = mgr.getEngineByName("freemarker");
      Bindings bind = eng.getContext().getBindings(ScriptContext.ENGINE_SCOPE);

      FileObject template = FileUtil.getConfigFile("Templates/Client/Client.java");

      OutputLogger.getInstance()
          .log(NbBundle.getMessage(ClientJavonTemplate.class, "MSG_ConfigureBindings")); // NOI18N
      Set<ClassData> returnTypes = service.getReturnTypes();
      Set<ClassData> parameterTypes = service.getParameterTypes();
      bind.put("mapping", mapping);
      bind.put("registry", mapping.getRegistry());
      bind.put("returnTypes", returnTypes);
      bind.put("parameterTypes", parameterTypes);
      bind.put("service", service);
      bind.put("utils", new Utils(mapping.getRegistry()));

      // Compute imports for JavaBeans
      Set<String> imports = new HashSet<String>();
      for (ClassData cd : parameterTypes) {
        while (cd.isArray()) {
          cd = cd.getComponentType();
        }
        if (cd.isPrimitive()) continue;
        if (cd.getPackage().equals("java.lang")) continue;
        if (cd.getFullyQualifiedName().equals("java.util.List")) continue;
        imports.add(cd.getFullyQualifiedName());
      }
      for (ClassData cd : returnTypes) {
        while (cd.isArray()) {
          cd = cd.getComponentType();
        }
        if (cd.isPrimitive()) continue;
        if (cd.getPackage().equals("java.lang")) continue;
        if (cd.getFullyQualifiedName().equals("java.util.List")) continue;
        imports.add(cd.getFullyQualifiedName());
      }
      bind.put("imports", imports);

      OutputLogger.getInstance()
          .log(
              MessageFormat.format(
                  NbBundle.getMessage(ClientBeanGeneratorTemplate.class, "MSG_GenerateJavonClient"),
                  FileUtil.toFile(outputFile))); // NOI18N
      Writer w = null;
      Reader is = null;
      try {
        try {
          w = new StringWriter();
          is = new InputStreamReader(template.getInputStream());

          eng.getContext().setWriter(w);
          eng.getContext()
              .setAttribute(FileObject.class.getName(), template, ScriptContext.ENGINE_SCOPE);
          eng.getContext()
              .setAttribute(
                  ScriptEngine.FILENAME, template.getNameExt(), ScriptContext.ENGINE_SCOPE);

          eng.eval(is);
        } catch (FileNotFoundException e) {
          OutputLogger.getInstance().log(e);
          ErrorManager.getDefault().notify(e);
          return false;
        } catch (ScriptException e) {
          OutputLogger.getInstance().log(e);
          ErrorManager.getDefault().notify(e);
          return false;
        } finally {
          if (w != null) {
            off.write(w.toString());
            // System.err.println( "" + w.toString());
            w.close();
          }
          if (is != null) is.close();
          off.close();
        }
      } catch (IOException e) {
        generationFailed(e, FileUtil.toFile(outputFile));
        return false;
      }

      OutputLogger.getInstance()
          .log(
              MessageFormat.format(
                  NbBundle.getMessage(ClientJavonTemplate.class, "MSG_ClientGenerated"),
                  FileUtil.toFile(outputFile)));
    }
    return true;
  }
  /** Creates a new instance of TomcatProperties */
  public TomcatProperties(TomcatManager tm) throws IllegalArgumentException {
    this.tm = tm;
    this.ip = tm.getInstanceProperties();
    String catalinaHome = null;
    String catalinaBase = null;
    String uri = ip.getProperty(PROP_URL); // NOI18N
    final String home = "home="; // NOI18N
    final String base = ":base="; // NOI18N
    final String uriString = "http://"; // NOI18N
    int uriOffset = uri.indexOf(uriString);
    int homeOffset = uri.indexOf(home) + home.length();
    int baseOffset = uri.indexOf(base, homeOffset);
    if (homeOffset >= home.length()) {
      int homeEnd = baseOffset > 0 ? baseOffset : (uriOffset > 0 ? uriOffset - 1 : uri.length());
      int baseEnd = uriOffset > 0 ? uriOffset - 1 : uri.length();
      catalinaHome = uri.substring(homeOffset, homeEnd);
      if (baseOffset > 0) {
        catalinaBase = uri.substring(baseOffset + base.length(), baseEnd);
      }
      // Bundled Tomcat home and base dirs can be specified as attributes
      // specified in BUNDLED_TOMCAT_SETTING file. Tomcat manager URL can
      // then look like "tomcat:home=$bundled_home:base=$bundled_base" and
      // therefore remains valid even if Tomcat version changes. (issue# 40659)
      if (catalinaHome.length() > 0 && catalinaHome.charAt(0) == '$') {
        FileObject fo = FileUtil.getConfigFile(BUNDLED_TOMCAT_SETTING);
        if (fo != null) {
          catalinaHome = fo.getAttribute(catalinaHome.substring(1)).toString();
          if (catalinaBase != null && catalinaBase.length() > 0 && catalinaBase.charAt(0) == '$') {
            catalinaBase = fo.getAttribute(catalinaBase.substring(1)).toString();
          }
        }
      }
    }
    if (catalinaHome == null) {
      throw new IllegalArgumentException("CATALINA_HOME must not be null."); // NOI18N
    }
    homeDir = new File(catalinaHome);
    if (!homeDir.isAbsolute()) {
      InstalledFileLocator ifl = InstalledFileLocator.getDefault();
      homeDir = ifl.locate(catalinaHome, null, false);
    }
    if (!homeDir.exists()) {
      throw new IllegalArgumentException("CATALINA_HOME directory does not exist."); // NOI18N
    }
    if (catalinaBase != null) {
      baseDir = new File(catalinaBase);
      if (!baseDir.isAbsolute()) {
        InstalledFileLocator ifl = InstalledFileLocator.getDefault();
        baseDir = ifl.locate(catalinaBase, null, false);
        if (baseDir == null) {
          baseDir = new File(System.getProperty("netbeans.user"), catalinaBase); // NOI18N
        }
      }
    }

    //        //parse the old format for backward compatibility
    //        if (uriOffset > 0) {
    //            String theUri = uri.substring (uriOffset + uriString.length ());
    //            int portIndex = theUri.indexOf (':');
    //            String host = theUri.substring (0, portIndex - 1);
    //            setHost (host);
    //            //System.out.println("host:"+host);
    //            int portEnd = theUri.indexOf ('/');
    //            portEnd = portEnd > 0 ? portEnd : theUri.length ();
    //            String port = theUri.substring (portIndex, portEnd - 1);
    //            //System.out.println("port:"+port);
    //            try {
    //                setServerPort (Integer.valueOf (port));
    //            } catch (NumberFormatException nef) {
    //                org.openide.ErrorManager.getDefault ().log (nef.getLocalizedMessage ());
    //            }
    //        }
    ip.addPropertyChangeListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (PROP_SERVER_PORT.equals(name)
                || PROP_USERNAME.equals(name)
                || PROP_PASSWORD.equals(name)) {
              // update Ant deployment properties file if it exists
              try {
                storeAntDeploymentProperties(getAntDeploymentPropertiesFile(), false);
              } catch (IOException ioe) {
                Logger.getLogger(TomcatProperties.class.getName()).log(Level.INFO, null, ioe);
              }
            }
          }
        });
  }