Reading XML in Java Applet - java

I know:
I have to sign the applet so it can read files
How to parse XML files
My Questions would be:
Should I keep the XML file in the .jar or separate?
Are there some best practices tutorials? if so please link me

If you ship your XML with the applet, then you won't need to sign it, as you're not really reading files, but just loading additional resources.
Only you can answer where the XML should be, because we don't know what it's used for, how often it changes and if its the same for every user of your applet.

Related

java inputStream read large html only one tag at a time

I have an android app that works with large html files (a whole book). Reading whole html files is not a good idea for many reasons (performance, memory usage, etc.)
I prefer to read the file one tag at a time if it's possible. My Html file looks like this
<main_tag>some text here</main_tag>
<main_tag><sub_tag>something</sub_tag><sub_tag>another thing</sub_tag><main_tag>
My Main tags are h1 ... h6 and p. And i want to read my file based on this tags. All the other tags are included in main tags and should be read with main tag.
any idea how can i achieve this? performance is a real issue here
all you need is to use android xml pull api, read the documentation about org.xmlpull.v1.XmlPullParser
Nirav

extracting text AND Images from PDF file

I have been bumping my head against the wall with this one, have researched and pretty much tried every library suggested to me. I am currently trying to write a program in java that will extract text AND images from a pdf file and allow me to write the extracted content to a word file. I have managed to extract the content using the ICEpdf library, however the problem is that I need to be able to write the content in the exact same order as it was read. So, to clarify, I need a library that will help me keep track of where exactly in the page the text and images are situated so I can put them in the same place in my word file.
A PDF to Word converter is a horribly complex proposition.
Your best bet will probably to use Open Office to do it for you and not even try to handle the intermediate steps.
http://www.openoffice.org/api/
Look at this: Advanced PDF parser for Java
OFF:
-Also to my knowledge there is a python parser that sorta converts the pdf to html (that way you can keep track of the ordering of the objects within the pdf). I know its not java, but you might be able to use the output.
http://www.unixuser.org/~euske/python/pdfminer/index.html

Two applications need to export and import a single file which needs to include data and images, best file type?

I'm making two Java applications one to collect data, another to use it. The one collecting will be importing a file from the other which will include data and images and will be decrypted.
I'm unsure what filetype to use. So far all of the data is in XML and works great but I need the images and was hoping not to have to rely on giving all the images in a folder with a path reference.
Ideas?
well, I think that the best way is to create your own format (.myformat or .data). This file will be in fact a Zip file that contains your XML file and images.
There is no perfect example writen in java as far as I know. However, here are some examples :
Not in java
The best example is, as #Bolo said, the odt format. Indeed, OpenOffice writes the doc in an xml file, and the images too. All that is wrapped in an odt file.
The .exe file is an other example. The C files and the resources are put in a single file. try to open it with 7-zip, you'll see.
The Skyrim plugins are .esp file that contain the dds, the scripts, the niffs (textures)...
In java
The minecraft texture packs are a zip file that contains a .mcmeta file (the infos) and the textures (.png)
Jar files are like exe.
If both programs are in java you could also go with serialization, which is basically saving an object as a file (suffix will be .ser I think) and then being able to retrieve it. You should google it, even if it won't help right now it is quite good to know about it.
I'd suggest using JSON. Gson is a decent library.
You can embed images as byte arrays.
Save the serialized string in a file with a preferred extension, read it from the second application, de-serialize, and reconstruct images.
You can convert binary image data to text with Base64 encoding and this way you can embed your images in XML. [1]: http://en.wikipedia.org/wiki/Base64

I can set a .doc file with permission to view only(no copy content, not editable). Can I do the same thing in a .java file?

Basically I want to deliver a java code which can only be viewed, neither edited or used any other way. Is it possible.
Note: This is not about delivering the .class file. The client wanna see the code in .java file.
Regards
It's not possible.
You can set file as read only. But the viewer can also change permission!.
If they can read it they can copy it. You could make it harder by sending the file as a set of PNG or JPEG screenshots, forcing them to retype (or use a good OCR program). If you are required to let them read the Java code, then they can make a copy.
There's nothing you can do about it.

making ePub with Java API

I'm relatively new to ePub format, but if I understand well, to make programmatically an ePub starting from XHTML or PDF content could mean:
choose HTML or XHTML content and validate them with an XHTML validator (or clean them with Tydy)
choose PDF file to insert in the ePub
create the XML manifest or XML packing files and TOC file
zip the whole files in a .epub file
validate the ePub (I saw something in Google code)
So my question is if there is some sort of high level Java API to do these steps. Sure I can use API for ZIP, XML in Java, but does it exist higher tools?
thanks a lot
------ EDIT -------
I've developed an open source project to do that!
http://scribaebookmake.sourceforge.net/
I haven't seen a java epub toolchain; however, I have been having good success with Sigil.
If the goal is to make an epub, I'd give Sigil a go. Before I used it I was rolling my epubs by hand (with the automation of an ant build.xml).
If the goal is to make a java based epub toolchain, then it shouldn't be terribly hard, depending on how much validation and pipelining you wish to do. Personally, I'd start with writing an epub viewer.
As far as the PDF parts go, I just embed XHTML. Haven't had a need for embedding PDF yet. As far as epub validation goes, if all the xml is valid and there's no dangling links prior to zipping, you're going to have a valid epub.
You should take a look at this project which seemed to be converting PDF to epub.
The following is a shameless plug for a project that I've been working on myself. It is basically EPUB tooling written in Java, for Eclipse. It comes with an API, UI and an Ant task that allows you to do pretty much everything. See http://help.eclipse.org/kepler/topic/org.eclipse.mylyn.docs.epub.help/help/introduction.html

Categories

Resources