How to programmatically write content into json file - java

How to programmatically write json data into json file, located in Documents and Media of Liferay?
I have a portlet, in which I am receiving json data. I want to write the received json data into a json file located in Documents and media of Liferay portal.
I am able to write data into physical file path inside a portlet. But not able to find the physical file path of folder in Documents and media. I know it is in data/document_library. But not able to find the folder id.
Also file is encrypted with version number.
So I think it won't be of any use even if I get the folder id properly.
Can you guys suggest any feasible solutions on the same. I am new to Liferay.

Looking for the physical path of the file is plain wrong. Instead, use Liferay's API to store files in the Document Library. Watch out for API interfaces starting with DL, e.g. DLFileEntryService. There are plenty of examples for interacting with that API.
Storing files in data/document_library is one option (the default configuration) but the data can be anywhere else on disk, in a database or in other system. Plus, the metadata is always in the database. And it only gets there when you use the proper APIs.

Related

Azure Functions and temporary File Storage

I'm a beginner and have never dealt with cloud-based solutions yet before, so apologies for the dumb question.
I have an Azure Blob Storage containing PDF files from which I want to extract data using PDFBox. Because PDFbox can't load blobs directly, I currently download these files locally first. However, eventually my project will need to become fully Cloud-based, preferably as an Azure Function.
The main hurdle therefore is figuring out how my Azure Function should access the files. When using the console inside my Azure Function I noticed it comes with a file storage. Can the Function download blobs and store them here before processing it? Does this file storage work the same as a local environment or are there differences to keep in mind?
I'm only looking to store files temporarily here, for only a few minutes at a time.
The main hurdle therefore is figuring out how my Azure Function should
access the files. When using the console inside my Azure Function I
noticed it comes with a file storage.
Yes, all of the information of your deployed azure function is stored in the file storage you set.(It is defined when you create the function app.)
Can the Function download blobs and store them here before processing
it? Does this file storage work the same as a local environment or are
there differences to keep in mind?
Yes, you can. And the root directory is D:/home/site/wwwroot. So if you don't specify, the file you create will be in this directory.
Remember to delete the files, because the storage space is limited. It is based on the plan you selected.
I'm only looking to store files temporarily here, for only a few
minutes at a time.
By the way, if you get a file from blob storage, at this time you have completely got its data. You can process the obtained data directly in the code without temporarily storing it in the current folder. (Of course, if you have special needs, please ignore this one.)
You can use a blob trigger or input binding to load a blob into memory of your function for processing by PDFBox.
With regards to the local file system, you can read about more about it here. From the description of your problem I think a blob trigger or input binding should be sufficient for you.

Need to get absolute path of a webpage using Java

I am writing a program that downloads some HTML. I need to retain the original filenames and folder structure as are on the server, so I need a way to handle links like "www.google.com". If you type it in, it will obviously download some PHP, but I need to know exactly what that file is called. I am writing in Kotlin, but if you can provide an answer in Java that'll work.
I need to retain the original filenames and folder structure as are on the server
This not possible, you cannot know the structure of the data on the server. There may not even exist a file and folder structure on the server, the returned data could be all dynamically generated an not be based on a filesystem.

Dynamically generating files and providing those files for download in Google App engine

I am creating a web app in google app engine using java which dynamically generate an HTML file. The requirement is such that if the Html file size increases from a certain limit (say 3 mb), then it should be split into two files and zipped together and that zip file should be sent back as the response.
I would like help on how and where to create those temporary HTML files and then zip it, in google app engine as i guess GAE doesnt allow to write on the filesystem.
Please help!!!
You can use the blobstore like a filesystem. Experimentally, they've even added access via the File api!
https://developers.google.com/appengine/docs/java/blobstore/overview#Writing_Files_to_the_Blobstore
You could also use the Google Cloud Storage. The advantage of this one is that once the file is produced, you can easily write scripts to manipulate the files through gsutil.

Google App Engine (Java) Text in Datastore/Dynamic Text File

I am using GAE with Java to dynamically create a "text file" based on information provided in a form. With the form parameters, I successfully generated a String that should serve as the text in the txt file. However I am not sure exactly how to get that String in an easy to read format. Ultimately, I would like to have an iOS app be able to read the text. These are the two routes that I was thinking of using, but I've encountered problems with both.
Store the text in the database then showing that in another page. Unfortunately I exceed the 500 char limit for a String with GAE. I then tried using the Text class, but as it's not queryable, I'm not sure how to access it from a jsp page.
Dynamically generate a text file with the String of file contents. This option seems more of the "right way" by actually creating a new file. To be quite honest, I just don't know how to do that. I have looked extensively online, but have not found an answer. I've looked into Blob API, but what that allow me to create a brand new file that can be accessed at another URL location? Most of the documentation deals with images or other file types.
All responses are very much appreciated.
Thanks.
For 1, just remember the key of the entity, and fetch an entity with that key afterwards. For 2, you can serve text files as well. Now we're offering Google Cloud Storage integration, so it might be a better option.

How can I convert one slide of a PowerPoint file to flash in jsf app (using javaSE/javaEE)?

I need to show the first slide of a PowerPoint presentation in my jsf app. It must look something like that:
user upload the .ppt file to jsf app
the app take the first slide and converts it to Flash
user sees the converted slide in the separate (not as part of the another page)
I suppose that I couldn't use any external converters because the user of the system will not have them when he uses our system.
Also I'm thinkinig about Flash, not HTML, because the presentation can be dynamic.
Any ideas? Can I do this task or it's impossible and I need to think in another way (maybe restriction for end users - to save presentation as png, but I think that my boss won't like this decision).
Maybe I need to look at .xslt format, maybe it would help?
suppose that I couldn't use any external converters because the user of the system will not have them when he uses our system.
You can truly use external tools since your Java/JSF code runs at the webserver, not at the webclient (webbrowser). All the webbrowser get is just the Java/JSF-generated HTML/CSS/JS code. Open a page in webbrowser, rightclick and View Source and see it yourself. You just install the external tool at the webserver and execute it there.
To upload a file in JSF, you'll need to grab a 3rd party component library since the standard implementation doesn't have an upload component, for example Tomahawk's t:inputFileUpload or the one of whatever component library you're currently already using.
To convert PPT to Flash, execute the appropriate action using external tool in the managed bean action method and store the Flash file somewhere in the local disk file system of the webserver. You can store it in the public webcontent so that it's directly accessible by URL, but those files will be lost whenever you redeploy the webapp. If this shouldn't happen, then store it outside the public webcontent.
I don't have hands on experience with PPT-Flash converters, so I can't recommend a specific one, but Google learns me that there's pretty a lot of choice. There seems to be a Java solution of iSpring.
To display the Flash file, use the HTML <object> element which points to the URL of the Flash file. If the Flash file is stored outside the public webcontent, then you'll need to create a Servlet which gets an InputStream of the file from the local disk file system and writes it to the OutputStream of the response along a correct set of HTTP headers and then let the URL of the <object> element point to that instead.

Categories