Witam, piszę jeszcze raz tym razem z inny problemem, a raczej dalszym rozwinięciem aplikacji, chciałbym umieścić swoją aplikację która zawiera GUI na stronę WWW, tak aby powstała z niej aplikacja web'owa, nie będzie się ona łączyła z bazą danych, chodzi chyba o zwykły applet. Pytanie jest takie, ile zmian trzeba będzie przeprowadzić w tym kodzie aby umożliwić podpięcie go do strony WWW.
package fop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.commons.io.FileUtils;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
public class GUI extends JFrame implements ActionListener{
JLabel lXSL, lXML, lPDF;
JTextField tXSL,tXML,tPDF;
JButton bXSL, bXML, bKonwertuj, bMiejsceDocelowe;
String sXML, sXSL, sPDF;
public GUI()
{
//window
setSize(400,400);
setTitle("Konwerter XSL:FO");
setLayout(null);
//label
lXML = new JLabel("Plik XML:");
lXML.setBounds(60, 50, 150, 20);
add(lXML);
lXSL = new JLabel("Plik XSL:");
lXSL.setBounds(60, 70, 150, 20);
add(lXSL);
lPDF = new JLabel("Plik PDF:");
lPDF.setBounds(60, 90, 150, 20);
add(lPDF);
//text
tXML = new JTextField("");
tXML.setBounds(120, 50, 150, 20);
add(tXML);
tXSL = new JTextField("");
tXSL.setBounds(120, 70, 150, 20);
add(tXSL);
tPDF = new JTextField("");
tPDF.setBounds(120, 90, 150, 20);
add(tPDF);
//button
bXML = new JButton("Wczytaj XML");
bXML.setBounds(50, 150, 110, 20);
add(bXML);
bXML.addActionListener(this);
bXSL = new JButton("Wczytaj XSL");
bXSL.setBounds(190, 150, 110, 20);
add(bXSL);
bXSL.addActionListener(this);
bKonwertuj = new JButton("Konwertuj");
bKonwertuj.setBounds(100, 210, 170, 50);
add(bKonwertuj);
bKonwertuj.addActionListener(this);
bMiejsceDocelowe = new JButton("Miejsce docelowe PDF");
bMiejsceDocelowe.setBounds(100, 180, 170, 20);
add(bMiejsceDocelowe);
bMiejsceDocelowe.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
Object z = e.getSource();
if(z==bXML)
{
JFileChooser fc = new JFileChooser();
if (fc.showOpenDialog(null)==JFileChooser.APPROVE_OPTION)
{
File plik_xml = fc.getSelectedFile();
JOptionPane.showMessageDialog(null,"Wybrany plik to: "+ plik_xml.getAbsolutePath());
tXML.setText(plik_xml.getName());
sXML = plik_xml.getAbsolutePath();
}
}
else if(z==bXSL)
{
JFileChooser fc = new JFileChooser();
if (fc.showOpenDialog(null)==JFileChooser.APPROVE_OPTION)
{
File plik_xsl = fc.getSelectedFile();
JOptionPane.showMessageDialog(null,"Wybrany plik to: "+ plik_xsl.getAbsolutePath());
tXSL.setText(plik_xsl.getName());
sXSL = plik_xsl.getAbsolutePath();
}
}
else if(z==bMiejsceDocelowe)
{
JFileChooser fc = new JFileChooser();
if (fc.showSaveDialog(null)==JFileChooser.APPROVE_OPTION)
{
File plik_pdf = fc.getSelectedFile();
JOptionPane.showMessageDialog(null, "Miejsce docelowe: "+plik_pdf);
tPDF.setText(plik_pdf.getName());
sPDF = plik_pdf.getAbsolutePath();
}
}
else if (z==bKonwertuj)
{
try {
System.out.println("XML->PDF\n");
System.out.println("Przygotowanie...");
// Setup input and output files
File xmlfile = new File(sXML);
File xsltfile = new File(sXSL);
File pdffile = new File(sPDF);
System.out.println("Plik wejściowy XML: (" + xmlfile + ")");
System.out.println("Plik wejściowy XSL: (" + xsltfile+ ")");
System.out.println("Plik wyjściowy PDF: (" + pdffile + ")");
System.out.println();
System.out.println("Konwertowanie...");
// configure fopFactory as desired
FopFactory fopFactory = FopFactory.newInstance();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
// configure foUserAgent as desired
// Setup output
OutputStream out = new java.io.FileOutputStream(pdffile);
out = new java.io.BufferedOutputStream(out);
try {
// Construct fop with desired output format
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
System.out.println("Tworzenie PDF...");
// Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xsltfile));
// Set the value of a <param> in the stylesheet
transformer.setParameter("versionParam", "2.0");
// Setup input for XSLT transformation
Source src = new StreamSource(xmlfile);
// Resulting SAX events (the generated FO) must be piped through to FOP
Result res = new SAXResult(fop.getDefaultHandler());
// Start XSLT transformation and FOP processing
transformer.transform(src, res);
} finally {
out.close();
}
System.out.println("Sukces!");
} catch (Exception e1) {
e1.printStackTrace(System.err);
System.exit(-1);
}
}
}
public static void main(String[] args)
{
GUI aplikacja = new GUI();
aplikacja.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
aplikacja.setVisible(true);
}
}
Będę wdzięczny za wszelką radę jak to ugryźć.
Pozdrawiam