Java Code Examples for org.netbeans.api.queries.FileEncodingQuery#getDefaultEncoding()

The following examples show how to use org.netbeans.api.queries.FileEncodingQuery#getDefaultEncoding() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JpaControllerUtil.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Get the encoding of the supplied project as a Charset object
 * @param project The project
 * @param file A file in the project
 * @return The project encoding, or a suitable default if the project encoding cannot be determined. Never null
 */
public static Charset getProjectEncoding(Project project, FileObject file) {
    Charset encoding = project.getLookup().lookup(FileEncodingQueryImplementation.class).getEncoding(file);
    if (encoding == null) {
        encoding = FileEncodingQuery.getDefaultEncoding();
        if (encoding == null) {
            return Charset.forName("UTF-8");
        }
        else {
            return encoding;
        }
    }
    else {
        return encoding;
    }
}
 
Example 2
Source File: JpaControllerUtil.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Get the encoding of the supplied project as a String (by performing a lookup and invoking Charset.name).
 * @param project The project
 * @param file A file in the project
 * @return The project encoding, or a suitable default if the project encoding cannot be determined. Never null
 */
public static String getProjectEncodingAsString(Project project, FileObject file) {
    Charset encoding = project.getLookup().lookup(FileEncodingQueryImplementation.class).getEncoding(file);
    if (encoding == null) {
        encoding = FileEncodingQuery.getDefaultEncoding();
        if (encoding == null) {
            return "UTF-8";
        }
        else {
            return encoding.name();
        }
    }
    else {
        return encoding.name();
    }
}
 
Example 3
Source File: ConfigureProjectPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Charset getEncoding() {
    Charset enc = (Charset) descriptor.getProperty(ENCODING);
    if (enc == null) {
        // #136917
        enc = FileEncodingQuery.getDefaultEncoding();
    }
    return enc;
}
 
Example 4
Source File: EjbJarProjectGenerator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static AntProjectHelper createProjectImpl(final EjbJarProjectCreateData createData,
        final FileObject projectDir) throws IOException {

    String name = createData.getName();
    String serverInstanceID = createData.getServerInstanceID();

    FileObject srcRoot = projectDir.createFolder(DEFAULT_SRC_FOLDER); // NOI18N
    srcRoot.createFolder(DEFAULT_JAVA_FOLDER); //NOI18N
    if (!createData.skipTests()) {
        projectDir.createFolder(DEFAULT_TEST_FOLDER);
    }
    FileObject confRoot = srcRoot.createFolder(DEFAULT_DOC_BASE_FOLDER); // NOI18N
    
    //create a default manifest
    FileUtil.copyFile(FileUtil.getConfigFile("org-netbeans-modules-j2ee-ejbjarproject/MANIFEST.MF"), confRoot, "MANIFEST"); //NOI18N
    
    final AntProjectHelper h = setupProject(projectDir, name,
            "src", "test", null, null, null, createData.getJavaEEProfile(), serverInstanceID,
            createData.getLibrariesDefinition(), createData.skipTests());
    
    EditableProperties ep = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
    ep.put(EjbJarProjectProperties.SOURCE_ROOT, DEFAULT_SRC_FOLDER); //NOI18N
    ep.setProperty(EjbJarProjectProperties.META_INF, "${"+EjbJarProjectProperties.SOURCE_ROOT+"}/"+DEFAULT_DOC_BASE_FOLDER); //NOI18N
    ep.setProperty(EjbJarProjectProperties.SRC_DIR, "${"+EjbJarProjectProperties.SOURCE_ROOT+"}/"+DEFAULT_JAVA_FOLDER); //NOI18N
    ep.setProperty(EjbJarProjectProperties.META_INF_EXCLUDES, "sun-cmp-mappings.xml"); // NOI18N
    Charset enc = FileEncodingQuery.getDefaultEncoding();
    ep.setProperty(EjbJarProjectProperties.SOURCE_ENCODING, enc.name());
    h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
    
    EjbJarProject p = (EjbJarProject) ProjectManager.getDefault().findProject(h.getProjectDirectory());
    ProjectManager.getDefault().saveProject(p);
    
    final ReferenceHelper refHelper = p.getReferenceHelper();
    try {
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            public Void run() throws Exception {
                copyRequiredLibraries(h, refHelper, createData);
                return null;
            }
        });
    } catch (MutexException ex) {
        Exceptions.printStackTrace(ex.getException());
    }
    
    // create ejb-jar.xml
    Profile profile = createData.getJavaEEProfile();
    if (!Profile.JAVA_EE_5.equals(profile) && !Profile.JAVA_EE_6_FULL.equals(profile) && !Profile.JAVA_EE_6_WEB.equals(profile) &&
            !Profile.JAVA_EE_7_FULL.equals(profile) && !Profile.JAVA_EE_7_WEB.equals(profile)) {
        String resource = "org-netbeans-modules-j2ee-ejbjarproject/ejb-jar-2.1.xml";
        FileObject ddFile = FileUtil.copyFile(FileUtil.getConfigFile(resource), confRoot, "ejb-jar"); //NOI18N
        EjbJar ejbJar = DDProvider.getDefault().getDDRoot(ddFile);
        ejbJar.setDisplayName(name);
        ejbJar.write(ddFile);
    }
    if (createData.isCDIEnabled()) {
        DDHelper.createBeansXml(profile, confRoot);
    }
    
    return h;
}