?
Solved

URgent-CDF - Java

Posted on 2006-05-23
17
Medium Priority
?
348 Views
Last Modified: 2006-11-18
Hi,

I have a cdf file. How do i read from the java applet..

Any tutorials to get started..
0
Comment
Question by:Jasbir21
  • 6
  • 5
  • 3
  • +2
17 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16741928
Isn't a CDF file just xml?
0
 

Author Comment

by:Jasbir21
ID: 16742028
I dont know on that.

I have a common data format file and it ends with .cdf.

My applet needs to read that.Pls help
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16742053
Is it readable in a text editor?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 12

Expert Comment

by:Giant2
ID: 16742427
Here is a tutorial:
http://msdn.microsoft.com/workshop/delivery/cdf/tutorials/generic.asp

To create it you can use normal file writing or DOM writing:
See here:
http://javaalmanac.com/egs/java.io/WriteToFile.html
and so on

http://javaalmanac.com/egs/org.w3c.dom/pkg.html

Hope this could help you.
Bye, Giant.
0
 
LVL 1

Expert Comment

by:rongasa
ID: 16742444
CDF (http://www.w3.org/2004/CDF/) is like xml and should be treated that way. No java API has been created uptill now (however see this in case it makes any sence to you.. http://www.jcp.org/en/jsr/detail?id=290).
In my opinion you should open it like a normall file and parse it.

For us to be able to help you more, you need to tell us what you need to do with this file. The way you mention it CDF could be anything...i.e.  cdf could be connector descriptor file which is used to link the c++ windows API with java. So if this is what you are trying to do the answer is that for security reasons you cannot do this from an applet.

If it is really an XML file, parse the file and retrieve the information you wish to acquire -this is the easier way i know-. To do so however, you need to read a little the specification files of w3 org, in order for you to know how you will acqire from the file the information you wish to get.

I have never worked with xml files, but do know that there are java API's for XML processing. Check them, they will help a lot.
0
 
LVL 3

Assisted Solution

by:Kanti
Kanti earned 100 total points
ID: 16743005
If CDF is like XML you can try this out and later change it read it from an applet


import java.io.File;
import java.io.IOException;
import org.xml.sax.SAXException;

import org.xml.sax.XMLReader;
import org.apache.xerces.parsers.SAXParser;
import org.xml.sax.Locator;
import org.xml.sax.ContentHandler;
import org.xml.sax.Attributes;
public class TestXML
{
    public void performDemo(String uri)
    {
        System.out.println("parsing XML File :" + uri + "\n\n");
      // variable content is of class type  ContentHandler
        ContentHandler content = new MyContentHandler();
        try
        {
      //    variable parser is of type XMLReader
            XMLReader parser = (XMLReader)new SAXParser();
            parser.setContentHandler(content);
            parser.parse(uri);
        }
        catch(IOException ex)
        {
            System.out.println("Error reading URI:" + ex.getMessage());
        }
        catch(SAXException sx)
        {
            System.out.println("Error in parsing:" + sx.getMessage());
        }

    }

    public static void main(String[] args)
    {  
 /* if you want to pass any xml file as paramenter
  then uncomment the below block  and comment out this line
  String uri = "c:\\yourCDForXMLFIle.xml" ; */
  /*
         if(args.length != 1)
        {
            System.out.println("Usage : java TestXml [XML URI]");
            System.exit(0);
        }
       
        String uri = args[0]; */
   


        String uri = "c:\\yourCDForXMLFIle.xml" ;
        TestXML test = new TestXML();
        test.performDemo(uri);
    }

}

class MyContentHandler implements ContentHandler
{
    private Locator locator;

    public void setDocumentLocator(Locator locator)
    {
        System.out.println("    * setDocumentLocator() called");
        this.locator = locator;
    }

    public void startDocument() throws SAXException
    {
        System.out.println("Parsing Begins.....");
    }

    public void endDocument() throws SAXException
    {
        System.out.println(".........Parsing Ends");
    }

    public void processingInstruction(String target, String data) throws SAXException
    {
        System.out.println("PI: Target:" + target + "and Data: " + data);
    }

    public void startPrefixMapping(String prefix, String uri)
    {
   System.out.println("Mapping starts for prefix " + prefix + " mapped to URI " + uri);
    }

    public void endPrefixMapping(String prefix)
    {
        System.out.println("Mapping ends for prefix " + prefix);
    }

    public void startElement(String namespaceURI, String localName, String rawName, Attributes atts) throws SAXException
    {
        System.out.println("StartElement: " + localName);
        if(!namespaceURI.equals(""))
        {
   System.out.println("in namespace " + namespaceURI + "( " + rawName + " )");
        }
        else
        {
            System.out.println("has no associated namespace");
        }
        for(int i=0; i<atts.getLength();i++)
        {
     System.out.println("Attribute: " + atts.getLocalName(i) + "=" + atts.getValue(i));
        }
    }

    public void endElement(String namespaceURI, String localName, String rawName) throws SAXException
    {
        System.out.println("endElement: " + localName + "\n");
    }

    public void characters(char[] ch, int start, int end) throws SAXException
    {
        String s = new String(ch, start, end);
        System.out.println("characters: " + s);
    }

    public void ignorableWhitespace(char[] ch, int start, int end) throws SAXException
    {
        String s = new String(ch, start, end);
        System.out.println("ignorableWhitespace: [" + s +" ]");
       
    }

    public void skippedEntity(String name) throws SAXException
    {
        System.out.println("SkippedEntity " + name);
    }
}
0
 

Author Comment

by:Jasbir21
ID: 16758075
sorry just came back..

actually, what i mean is that , lets say the program has jtextfields and the user clicks save , it gets saved in the cdf format.

Something like, when you load that file, the jtextfields values that was  saved would be loaded.

 
0
 
LVL 12

Accepted Solution

by:
Giant2 earned 100 total points
ID: 16758251
You must create a persistent object.
See here:
http://www.javaworld.com/javaworld/jw-05-1997/jw-05-persistence.html
http://java.sun.com/docs/books/tutorial/essential/io/serialization.html

Here is JDO (read only for see a structure)
http://java.sun.com/developer/technicalArticles/J2SE/jdo/

Hope these link be usefull for you.
Bye, Giant.
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
ID: 16758450
>>actually, what i mean is that , lets say the program has jtextfields and the user clicks save , it gets saved in the cdf format.

You need to create a CDF document and then serialize the Document

http://javaalmanac.com/egs/org.w3c.dom/AddNode.html

http://javaalmanac.com/egs/javax.xml.transform/WriteDom.html
0
 
LVL 1

Assisted Solution

by:rongasa
rongasa earned 100 total points
ID: 16758503
There are many ways to do what you wish to do, atleast from what i have understood. You may use persistent data-database-. Just a notice to make it clear, you simply ignore the format!!! Why care if it is cgf, txt, or anything else... for you it is just a text that you need to store somewhere, under a key (i.e. database key="file name")) and retrieve it when needed with the use of this key.
0
 

Author Comment

by:Jasbir21
ID: 16768092
Thank you..I am trying out now..
0
 

Author Comment

by:Jasbir21
ID: 16768097
i am doing this from an applet... do i need sign the applet ?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16768102
:-)

>>do i need sign the applet ?

Yes
0
 
LVL 1

Expert Comment

by:rongasa
ID: 16768111
what do you mean "sign the applet", i do not understand the question? you mean if you need signature? No applets do not need signatures.
0
 

Author Comment

by:Jasbir21
ID: 16768217
i mean , jarsigner..applets has some security stuff..so, in order for it to do it, you need to jarsign it..for example access to database, etc.

Is there a way else than jarsigning?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16768227
Yes. This really should be a new question, but:

http://mindprod.com/jgloss/signedapplets.html
0
 

Author Comment

by:Jasbir21
ID: 16768239
Thanks ...:-)
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question