Esempio n. 1
0
  /**
   * Add element starting with filter value to list.
   *
   * @param fo FileObject for adding
   * @param filter filtering with this value
   * @param elements List for adding (add to this)
   * @param pluginName plugin name if target is not plugin, set the null
   * @return true if add, otherwise false
   */
  protected boolean addElement(
      FileObject fo, String filter, List<String> elements, String pluginName) {
    String name = getFileName(fo);
    // set subdirectory path
    if (!subDirectoryPath.isEmpty()) {
      name = subDirectoryPath + SLASH + name; // NOI18N
    }

    // is root
    if (filter.startsWith(SLASH)) {
      name = SLASH + name;
      filter = filter.replaceFirst(SLASH, ""); // NOI18N
    }

    // filtering
    String fileName = getFileName(fo);
    if (fileName.startsWith(filter)) {
      if (!fo.isFolder() && extFilter != null && !extFilter.contains(fo.getExt())) {
        return false;
      }
      if (fo.isFolder() || !fo.getExt().isEmpty()) {
        if (fo.isFolder()) {
          name = name + SLASH;
        }
        if (pluginName != null && !pluginName.isEmpty()) {
          name = pluginName + DOT + name;
        }
        elements.add(name);
        return true;
      }
    }
    return false;
  }
  private FileObject getArchivedFile(FileObject fileObject) {
    // ZIP and JAR archives
    if (FileUtil.isArchiveFile(fileObject)) {
      try {
        fileObject = FileUtil.getArchiveRoot(fileObject).getChildren()[0];
      } catch (Exception e) {
        throw new RuntimeException(
            "The archive can't be opened, be sure it has no password and contains a single file, without folders");
      }
    } else { // GZ or BZIP2 archives
      boolean isGz = fileObject.getExt().equalsIgnoreCase("gz");
      boolean isBzip = fileObject.getExt().equalsIgnoreCase("bz2");
      if (isGz || isBzip) {
        try {
          String[] splittedFileName = fileObject.getName().split("\\.");
          if (splittedFileName.length < 2) {
            return fileObject;
          }

          String fileExt1 = splittedFileName[splittedFileName.length - 1];
          String fileExt2 = splittedFileName[splittedFileName.length - 2];

          File tempFile = null;
          if (fileExt1.equalsIgnoreCase("tar")) {
            String fname = fileObject.getName().replaceAll("\\.tar$", "");
            fname = fname.replace(fileExt2, "");
            tempFile = File.createTempFile(fname, "." + fileExt2);
            // Untar & unzip
            if (isGz) {
              tempFile = getGzFile(fileObject, tempFile, true);
            } else {
              tempFile = getBzipFile(fileObject, tempFile, true);
            }
          } else {
            String fname = fileObject.getName();
            fname = fname.replace(fileExt1, "");
            tempFile = File.createTempFile(fname, "." + fileExt1);
            // Unzip
            if (isGz) {
              tempFile = getGzFile(fileObject, tempFile, false);
            } else {
              tempFile = getBzipFile(fileObject, tempFile, false);
            }
          }
          tempFile.deleteOnExit();
          tempFile = FileUtil.normalizeFile(tempFile);
          fileObject = FileUtil.toFileObject(tempFile);
        } catch (IOException ex) {
          Exceptions.printStackTrace(ex);
        }
      }
    }
    return fileObject;
  }
  protected WizardDescriptor.Panel<WizardDescriptor>[] createPanels() {
    if (targetChooserDescriptorPanel == null) {
      TemplateWizard wiz = getWizard();
      DataObject dobj = wiz.getTemplate();
      FileObject fobj = dobj.getPrimaryFile();
      String mimeType = fobj.getMIMEType();
      MIMEExtensions extensions = MIMEExtensions.get(mimeType);
      if (extensions != null) {
        Project project = Templates.getProject(getWizard());
        Sources sources = ProjectUtils.getSources(project);
        SourceGroup[] groups = sources.getSourceGroups(Sources.TYPE_GENERIC);
        if (MIMENames.HEADER_MIME_TYPE.equals(extensions.getMIMEType())) {
          // this is the only place where we want to differ c headers from cpp headers (creation of
          // new one)
          if (dobj.getPrimaryFile().getAttribute(C_HEADER_MIME_TYPE) != null) {
            MIMEExtensions cHeaderExtensions = MIMEExtensions.get(C_HEADER_MIME_TYPE);
            if ((cHeaderExtensions == null)
                || !C_HEADER_MIME_TYPE.equals(cHeaderExtensions.getMIMEType())) {
              System.err.println("not found extensions for C Headers"); // NOI18N
            } else {
              extensions = cHeaderExtensions;
            }
          }
        }
        String defaultExt = null; // let the chooser panel decide default extension
        if (mimeType.equals(MIMENames.SHELL_MIME_TYPE)) {
          // for shell scripts set default extension explicitly
          defaultExt = fobj.getExt();
        } else if (mimeType.equals(MIMENames.HEADER_MIME_TYPE) && fobj.getExt().length() == 0) {
          // for standard header without extension
          defaultExt = fobj.getExt();
        }

        targetChooserDescriptorPanel =
            new NewTestSimplePanel(
                project,
                groups,
                null,
                extensions,
                defaultExt,
                (String) wiz.getProperty(CND_UNITTEST_DEFAULT_NAME));
      } else {
        targetChooserDescriptorPanel = getWizard().targetChooser();
      }
    }
    @SuppressWarnings("unchecked")
    Panel<WizardDescriptor>[] panels = new WizardDescriptor.Panel[] {targetChooserDescriptorPanel};
    return panels;
  }
 @Override
 public String findMIMEType(FileObject fo) {
   if (fo.getExt().equals("coffee") || fo.getNameExt().equals("Cakefile")) {
     return CoffeeScriptLanguage.MIME_TYPE;
   }
   return null;
 }
    @Override
    public String findMIMEType(FileObject fo) {
      if ("java".equals(fo.getExt())) {
        return JavacParser.MIME_TYPE;
      }

      return null;
    }
  //    private XMLFileSystem fs;
  public MatDefMetaData(MatDefDataObject file) {
    try {
      this.file = file;
      getFolder();
      FileObject primaryFile = file.getPrimaryFile();

      if (primaryFile != null) {
        extension = primaryFile.getExt() + "data";
      }

    } catch (IOException ex) {
      Exceptions.printStackTrace(ex);
    }
  }
  public void cssMinify() {
    MinifyProperty minifyProperty = MinifyProperty.getInstance();
    MinifyUtil util = new MinifyUtil();
    try {
      FileObject file = context.getPrimaryFile();

      String inputFilePath = file.getPath();
      String outputFilePath;

      if (minifyProperty.isNewCSSFile()
          && minifyProperty.getPreExtensionCSS() != null
          && !minifyProperty.getPreExtensionCSS().trim().isEmpty()) {
        outputFilePath =
            file.getParent().getPath()
                + File.separator
                + file.getName()
                + minifyProperty.getSeparatorCSS()
                + minifyProperty.getPreExtensionCSS()
                + "."
                + file.getExt();
      } else {
        outputFilePath = inputFilePath;
      }

      MinifyFileResult minifyFileResult =
          util.compressCss(inputFilePath, outputFilePath, minifyProperty);
      if (minifyProperty.isEnableOutputLogAlert()) {
        JOptionPane.showMessageDialog(
            null,
            "CSS Minified Completed Successfully\n"
                + "Input CSS Files Size : "
                + minifyFileResult.getInputFileSize()
                + "Bytes \n"
                + "After Minifying CSS Files Size : "
                + minifyFileResult.getOutputFileSize()
                + "Bytes \n"
                + "CSS Space Saved "
                + minifyFileResult.getSavedPercentage()
                + "%");
      }
    } catch (Exception ex) {
      Exceptions.printStackTrace(ex);
    }
  }
  private Set<PhpClass> parseFields(final FileObject fo) {
    FileObject tmp = fo;
    if (CakePhpUtils.isView(fo) || fo.getExt().equals(CakePhp.CTP)) {
      tmp = CakePhpUtils.getController(fo);
      if (tmp == null) {
        return Collections.singleton(getViewPhpClass());
      }
    }

    final FileObject target = tmp;
    final Set<PhpClass> phpClasses = new HashSet<PhpClass>();
    try {
      ParserManager.parse(
          Collections.singleton(Source.create(target)),
          new UserTask() {
            @Override
            public void run(ResultIterator resultIterator) throws Exception {
              ParserResult parseResult = (ParserResult) resultIterator.getParserResult();
              final CakePhpFieldsVisitor visitor;
              if (isView || isController) {
                visitor = new CakePhpControllerVisitor(fo, getPhpClass(fo));
              } else if (isComponent) {
                visitor = new CakePhpComponentVisitor(fo, getPhpClass(fo));
              } else if (isHelper) {
                visitor = new CakePhpHelperVisitor(fo, getPhpClass(fo));
              } else {
                visitor = null;
              }

              if (visitor != null) {
                visitor.scan(Utils.getRoot(parseResult));
                phpClasses.addAll(Collections.singleton(visitor.getPhpClass()));
              }
            }
          });
    } catch (ParseException ex) {
      LOGGER.log(Level.WARNING, null, ex);
    }

    return phpClasses;
  }
 private Properties parseRicohAdditionalResources(FileObject projectDir) {
   FileObject[] fos = projectDir.getChildren();
   for (int i = 0; i < fos.length; i++) {
     FileObject dalp = fos[i];
     if ("dalp".compareToIgnoreCase(dalp.getExt()) == 0) {
       Properties properties = new Properties();
       DalpParserHandlerImpl handler = new DalpParserHandlerImpl(projectDir, properties);
       try {
         DalpParser.parse(new InputSource(dalp.getInputStream()), handler);
       } catch (FileNotFoundException ex) {
         ErrorManager.getDefault().notify(ex);
       } catch (IOException ex) {
         ErrorManager.getDefault().notify(ex);
       } catch (SAXException ex) {
         ErrorManager.getDefault().notify(ex);
       } catch (ParserConfigurationException ex) {
         ErrorManager.getDefault().notify(ex);
       }
       return properties;
     }
   }
   return null;
 }
  public void initValues(
      final Project project, final FileObject template, final FileObject preselectedFolder) {
    this.project = project;
    this.helper = project.getLookup().lookup(AntProjectHelper.class);
    final Object obj = template.getAttribute(IS_MIDLET_TEMPLATE_ATTRIBUTE);
    isMIDlet = false;
    if (obj instanceof Boolean) isMIDlet = ((Boolean) obj).booleanValue();

    projectTextField.setText(ProjectUtils.getInformation(project).getDisplayName());

    final Sources sources = ProjectUtils.getSources(project);
    final SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    final SourceGroup preselectedGroup = getPreselectedGroup(groups, preselectedFolder);
    if (preselectedGroup != null) {
      final ModelItem groupItem = new ModelItem(preselectedGroup);
      final ModelItem[] nodes = groupItem.getChildren();
      packageComboBox.setModel(new DefaultComboBoxModel(nodes));
      final Object folderItem = getPreselectedPackage(groupItem, preselectedFolder);
      if (folderItem != null) packageComboBox.setSelectedItem(folderItem);
    } else {
      packageComboBox.setModel(new DefaultComboBoxModel());
    }

    // Determine the extension
    final String ext = template == null ? "" : template.getExt(); // NOI18N
    expectedExtension = ext.length() == 0 ? "" : "." + ext; // NOI18N

    lName.setVisible(isMIDlet);
    tName.setVisible(isMIDlet);
    lIcon.setVisible(isMIDlet);
    cIcon.setVisible(isMIDlet);
    lNote.setVisible(isMIDlet);
    org.openide.awt.Mnemonics.setLocalizedText(
        lClassName,
        NbBundle.getMessage(
            MIDPTargetChooserPanelGUI.class,
            isMIDlet ? "LBL_File_MIDletClassName" : "LBL_File_MIDPClassName")); // NOI18N

    // Show name of the project
    if (isMIDlet) {
      tName.getDocument().removeDocumentListener(this);
      tName.setText(template.getName());
      updateClassNameAndIcon();
      if (testIfFileNameExists(preselectedGroup) && updateClassName) {
        String name = tName.getText();
        int i = 1;
        for (; ; ) {
          tName.setText(name + "_" + i); // NOI18N
          updateClassNameAndIcon();
          if (!testIfFileNameExists(preselectedGroup) || !updateClassName) break;
          i++;
        }
      }
      tName.getDocument().addDocumentListener(this);
    } else {
      tClassName.setText(template.getName());
      if (testIfFileNameExists(preselectedGroup)) {
        String name = tClassName.getText();
        int i = 1;
        for (; ; ) {
          tClassName.setText(name + "_" + i); // NOI18N
          if (!testIfFileNameExists(preselectedGroup)) break;
          i++;
        }
      }
      tClassName.getDocument().addDocumentListener(this);
    }
    updateText();

    // Find all icons
    if (loadIcons) {
      loadIcons = false;
      final DefaultComboBoxModel icons = new DefaultComboBoxModel();
      cIcon.setModel(icons);
      cIcon.setSelectedItem(""); // NOI18N
      RequestProcessor.getDefault()
          .post(
              new Runnable() {
                public void run() {
                  final ArrayList<FileObject> roots = new ArrayList<FileObject>();
                  roots.add(
                      helper.resolveFileObject(
                          helper.getStandardPropertyEvaluator().getProperty("src.dir"))); // NOI18N
                  final String libs =
                      J2MEProjectUtils.evaluateProperty(
                          helper, DefaultPropertiesDescriptor.LIBS_CLASSPATH);
                  if (libs != null) {
                    final String elements[] = PropertyUtils.tokenizePath(helper.resolvePath(libs));
                    for (int i = 0; i < elements.length; i++)
                      try {
                        final FileObject root =
                            FileUtil.toFileObject(FileUtil.normalizeFile(new File(elements[i])));
                        if (root != null)
                          roots.add(
                              FileUtil.isArchiveFile(root) ? FileUtil.getArchiveRoot(root) : root);
                      } catch (Exception e) {
                      }
                  }
                  for (FileObject root : roots) {
                    if (root != null) {
                      final int rootLength = root.getPath().length();
                      final Enumeration en = root.getChildren(true);
                      while (en.hasMoreElements()) {
                        final FileObject fo = (FileObject) en.nextElement();
                        if (fo.isData()) {
                          final String ext = fo.getExt().toLowerCase();
                          if ("png".equals(ext)) { // NOI18N
                            String name = fo.getPath().substring(rootLength);
                            if (!name.startsWith("/")) name = "/" + name; // NOI18N
                            if (icons.getIndexOf(name) < 0) icons.addElement(name);
                          }
                        }
                      }
                    }
                  }
                }
              });
    }
  }