[
https://issues.jboss.org/browse/JBDS-3371?page=com.atlassian.jira.plugin....
]
Alexey Kazakov updated JBDS-3371:
---------------------------------
Description:
Im getting "The method openFileDialog(null, null) is undefined for the type
FileOpenService" error wen trying to run the code bellow.:
{code}
package com.hrtrust.ps.scanner;
// add javaws.jar to the classpath during compilation
import javax.jnlp.FileOpenService;
import javax.jnlp.FileSaveService;
import javax.jnlp.FileContents;
import javax.jnlp.ServiceManager;
import javax.jnlp.UnavailableServiceException;
import java.io.*;
import javax.jnlp.ExtendedService;
public class FileHandler {
static private FileOpenService fos = null;
static private FileSaveService fss = null;
static private FileContents fc = null;
static private ExtendedService exs = null;
// retrieves a reference to the JNLP services
private static synchronized void initialize() {
if (fss != null) {
return;
}
try {
fos = (FileOpenService)
ServiceManager.lookup("javax.jnlp.FileOpenService");
fss = (FileSaveService)
ServiceManager.lookup("javax.jnlp.FileSaveService");
exs = (ExtendedService)
ServiceManager.lookup("javax.jnlp.ExtendedService");
} catch (UnavailableServiceException e) {
fos = null;
fss = null;
exs = null;
}
}
public static FileContents getDLL(File dllFile) {
initialize();
try {
fc = exs.openFile(dllFile);
} catch (IOException ioe) {
ioe.printStackTrace(System.out);
return null;
}
return fc;
}
// displays open file dialog and reads selected file using FileOpenService
public static String open() {
initialize();
try {
fc = fos.openFileDialog(null, null);
return readFromFile(fc);
} catch (IOException ioe) {
ioe.printStackTrace(System.out);
return null;
}
}
// displays saveFileDialog and saves file using FileSaveService
public static void save(String txt) {
initialize();
try {
// Show save dialog if no name is already given
if (fc == null) {
fc = fss.saveFileDialog(null, null,
new ByteArrayInputStream(txt.getBytes()), null);
// file saved, done
return;
}
// use this only when filename is known
if (fc != null) {
writeToFile(txt, fc);
}
} catch (IOException ioe) {
ioe.printStackTrace(System.out);
}
}
// displays saveAsFileDialog and saves file using FileSaveService
public static void saveAs(String txt) {
initialize();
try {
if (fc == null) {
// If not already saved. Save-as is like save
save(txt);
} else {
fc = fss.saveAsFileDialog(null, null, fc);
save(txt);
}
} catch (IOException ioe) {
ioe.printStackTrace(System.out);
}
}
private static void writeToFile(String txt, FileContents fc) throws IOException {
int sizeNeeded = txt.length() * 2;
if (sizeNeeded > fc.getMaxLength()) {
fc.setMaxLength(sizeNeeded);
}
BufferedWriter os = new BufferedWriter(new
OutputStreamWriter(fc.getOutputStream(true)));
os.write(txt);
os.close();
}
private static String readFromFile(FileContents fc) throws IOException {
if (fc == null) {
return null;
}
BufferedReader br = new BufferedReader(new
InputStreamReader(fc.getInputStream()));
StringBuffer sb = new StringBuffer((int) fc.getLength());
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append("\n");
line = br.readLine();
}
br.close();
return sb.toString();
}
}
{code}
NB. fc = fos.openFileDialog(null, null); is the line that gives an error.
(FileOpenService)....FileSaveService and FileContents works just fine.
was:
Im getting "The method openFileDialog(null, null) is undefined for the type
FileOpenService" error wen trying to run the code bellow.:
package com.hrtrust.ps.scanner;
// add javaws.jar to the classpath during compilation
import javax.jnlp.FileOpenService;
import javax.jnlp.FileSaveService;
import javax.jnlp.FileContents;
import javax.jnlp.ServiceManager;
import javax.jnlp.UnavailableServiceException;
import java.io.*;
import javax.jnlp.ExtendedService;
public class FileHandler {
static private FileOpenService fos = null;
static private FileSaveService fss = null;
static private FileContents fc = null;
static private ExtendedService exs = null;
// retrieves a reference to the JNLP services
private static synchronized void initialize() {
if (fss != null) {
return;
}
try {
fos = (FileOpenService)
ServiceManager.lookup("javax.jnlp.FileOpenService");
fss = (FileSaveService)
ServiceManager.lookup("javax.jnlp.FileSaveService");
exs = (ExtendedService)
ServiceManager.lookup("javax.jnlp.ExtendedService");
} catch (UnavailableServiceException e) {
fos = null;
fss = null;
exs = null;
}
}
public static FileContents getDLL(File dllFile) {
initialize();
try {
fc = exs.openFile(dllFile);
} catch (IOException ioe) {
ioe.printStackTrace(System.out);
return null;
}
return fc;
}
// displays open file dialog and reads selected file using FileOpenService
public static String open() {
initialize();
try {
fc = fos.openFileDialog(null, null);
return readFromFile(fc);
} catch (IOException ioe) {
ioe.printStackTrace(System.out);
return null;
}
}
// displays saveFileDialog and saves file using FileSaveService
public static void save(String txt) {
initialize();
try {
// Show save dialog if no name is already given
if (fc == null) {
fc = fss.saveFileDialog(null, null,
new ByteArrayInputStream(txt.getBytes()), null);
// file saved, done
return;
}
// use this only when filename is known
if (fc != null) {
writeToFile(txt, fc);
}
} catch (IOException ioe) {
ioe.printStackTrace(System.out);
}
}
// displays saveAsFileDialog and saves file using FileSaveService
public static void saveAs(String txt) {
initialize();
try {
if (fc == null) {
// If not already saved. Save-as is like save
save(txt);
} else {
fc = fss.saveAsFileDialog(null, null, fc);
save(txt);
}
} catch (IOException ioe) {
ioe.printStackTrace(System.out);
}
}
private static void writeToFile(String txt, FileContents fc) throws IOException {
int sizeNeeded = txt.length() * 2;
if (sizeNeeded > fc.getMaxLength()) {
fc.setMaxLength(sizeNeeded);
}
BufferedWriter os = new BufferedWriter(new
OutputStreamWriter(fc.getOutputStream(true)));
os.write(txt);
os.close();
}
private static String readFromFile(FileContents fc) throws IOException {
if (fc == null) {
return null;
}
BufferedReader br = new BufferedReader(new
InputStreamReader(fc.getInputStream()));
StringBuffer sb = new StringBuffer((int) fc.getLength());
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append("\n");
line = br.readLine();
}
br.close();
return sb.toString();
}
}
NB. fc = fos.openFileDialog(null, null); is the line that gives an error.
(FileOpenService)....FileSaveService and FileContents works just fine.
The method openFileDialog(null, null) is undefined for the type
FileOpenService
-------------------------------------------------------------------------------
Key: JBDS-3371
URL:
https://issues.jboss.org/browse/JBDS-3371
Project: Developer Studio (JBoss Developer Studio)
Issue Type: Bug
Environment: JBoss Developer Studio Version: 8.0.2.GA
Reporter: Ludumo Sankobe
Im getting "The method openFileDialog(null, null) is undefined for the type
FileOpenService" error wen trying to run the code bellow.:
{code}
package com.hrtrust.ps.scanner;
// add javaws.jar to the classpath during compilation
import javax.jnlp.FileOpenService;
import javax.jnlp.FileSaveService;
import javax.jnlp.FileContents;
import javax.jnlp.ServiceManager;
import javax.jnlp.UnavailableServiceException;
import java.io.*;
import javax.jnlp.ExtendedService;
public class FileHandler {
static private FileOpenService fos = null;
static private FileSaveService fss = null;
static private FileContents fc = null;
static private ExtendedService exs = null;
// retrieves a reference to the JNLP services
private static synchronized void initialize() {
if (fss != null) {
return;
}
try {
fos = (FileOpenService)
ServiceManager.lookup("javax.jnlp.FileOpenService");
fss = (FileSaveService)
ServiceManager.lookup("javax.jnlp.FileSaveService");
exs = (ExtendedService)
ServiceManager.lookup("javax.jnlp.ExtendedService");
} catch (UnavailableServiceException e) {
fos = null;
fss = null;
exs = null;
}
}
public static FileContents getDLL(File dllFile) {
initialize();
try {
fc = exs.openFile(dllFile);
} catch (IOException ioe) {
ioe.printStackTrace(System.out);
return null;
}
return fc;
}
// displays open file dialog and reads selected file using FileOpenService
public static String open() {
initialize();
try {
fc = fos.openFileDialog(null, null);
return readFromFile(fc);
} catch (IOException ioe) {
ioe.printStackTrace(System.out);
return null;
}
}
// displays saveFileDialog and saves file using FileSaveService
public static void save(String txt) {
initialize();
try {
// Show save dialog if no name is already given
if (fc == null) {
fc = fss.saveFileDialog(null, null,
new ByteArrayInputStream(txt.getBytes()), null);
// file saved, done
return;
}
// use this only when filename is known
if (fc != null) {
writeToFile(txt, fc);
}
} catch (IOException ioe) {
ioe.printStackTrace(System.out);
}
}
// displays saveAsFileDialog and saves file using FileSaveService
public static void saveAs(String txt) {
initialize();
try {
if (fc == null) {
// If not already saved. Save-as is like save
save(txt);
} else {
fc = fss.saveAsFileDialog(null, null, fc);
save(txt);
}
} catch (IOException ioe) {
ioe.printStackTrace(System.out);
}
}
private static void writeToFile(String txt, FileContents fc) throws IOException {
int sizeNeeded = txt.length() * 2;
if (sizeNeeded > fc.getMaxLength()) {
fc.setMaxLength(sizeNeeded);
}
BufferedWriter os = new BufferedWriter(new
OutputStreamWriter(fc.getOutputStream(true)));
os.write(txt);
os.close();
}
private static String readFromFile(FileContents fc) throws IOException {
if (fc == null) {
return null;
}
BufferedReader br = new BufferedReader(new
InputStreamReader(fc.getInputStream()));
StringBuffer sb = new StringBuffer((int) fc.getLength());
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append("\n");
line = br.readLine();
}
br.close();
return sb.toString();
}
}
{code}
NB. fc = fos.openFileDialog(null, null); is the line that gives an error.
(FileOpenService)....FileSaveService and FileContents works just fine.
--
This message was sent by Atlassian JIRA
(v6.3.11#6341)