OpenCMS - howto explose a flat structure instead of a folder/tree structure - java

I would like to have a tree/ folder structure for my content but would like all pages to be served as a flat URL. E.g.
the page located at /cat1/subcat2/tulips.html would be served at:
http://example.com/tulips.html
and the page located at /cat5/roses.html would be served at:
http://example.com/roses.html
I would need all links to be automatically calculated and ensure that there are no conflicts.
Is this possible with opencms?
Thanks,
Assaf

A rough outline how I'd to approach this:
You would first get the list of all the resources via <cms:contentload> (http://www.bng-galiza.org/opencms/opencms/alkacon-documentation/documentation_taglib/docu_tag_contentload.html), taglib or the respective java API in java code as you need some coding anyway, and then create new resources of type 'external link' in your OpenCms root folder, pointing to your targets; probably using something like
getCms().createResource(newFileName, templateFile.getTypeId());
or similar method (as external link isn't structured content) for it.
You could wrap this logic up into a java class and schedule it as a scheduled job, I guess it's sufficient, as long as you don't need it right away and some delay is acceptable. Otherwise you'd need to hook it into the publishing flow.

Related

Make modified JS and CSS file be fetched by browsers

I want to make the js and css files which are modified are to be downloaded at the client end when a page is accessed. I have these approaches
Manually add the modified timestamp the URL in each page.
I was thinking of writing a scriptlet code in all the jsp pages which will read all the js and css files modified timestamp and append it to the url in the page.
Add the modified timestamp while building the war file using ANT.
I have following questions.
Can any one let me know which would be a better solution of the above approaches? I am open to any other solutions also.
I went through this answer on SO and using it I can get the modified date but how to change the jsp file?
Is there anything similar to this in java?
In this situation better or best solution is took shape according to your exact requirements. I might derive simple questions like; Will your static resources in same server or included in your app in same server etc.. May be some other better ways..
I don't have ant experience so I can't talk about it now , but you can go with java way already.I want to share just idea/s. A filter(looks the .css or .js requests , gets resources and look resource lastmodified date or checksum return as version on response) or custom jsp tag will provide your requirements. Write a custom jsp tag <resource:static path="app.js"/> like that example. So it may look specific file's last modified date, assumed under the same document root, and it can produce <script type="text/javascript" src="app.js?version=8637"> like this result, so this result will bust the cache.

How use the getFolders() method of the DLFolderLocalServiceUtil class?

I am absolutly new in LifeRay development and I have some doubts related to the use of the DLFolderLocalServiceUtil class.
In my code I have something like this:
List<DLFolder> listFolder = DLFolderLocalServiceUtil.getDLFolders(-1, -1);
private Map<String, DLFolder> treePath = new TreeMap<String, DLFolder>();
What exaclty do the previous code? I think that is is something related to the LifeRay document library. I think that the previous code retrieve the root of the document library of my portal.
But, if my reasoning is correct, what exactly is the document library in LifeRay? Is it something used to stored documents on the portal? If so what exactly is a document in LifeRay? any type of file or specific type of content?
Looking on the official LifeRAy documentation, here: https://docs.liferay.com/portal/6.2/javadocs-all/com/liferay/portlet/documentlibrary/service/DLFolderLocalServiceUtil.html
it seems to me that, in the previous code snippet, it is used this version of the getDLFolders() method:
getDLFolders(int start, int end)
and say that:
Returns a range of all the document library folders
But what exactly mean a range of all document library folder? And what means if, as in the previous snippet, is used the start and end values setted to -1 ?
Yes, this service is related to the Documents and Media portlet which can be found within Content of a site's Admin area. The source code package structure designates this portlet as the document_library portlet (dated but applicable wiki page). The portlet serves as the management facility for all document based content for any type of document.
The portlet uses both the database and file system in providing document management functionality. If you navigate to the same directory level as your ${LIFERAY_HOME} and have a look, you'll see a data folder. Within this folder you'll notice a document_library folder. The directory structure going forward corresponds to companyId / folder (internally managed association) for a specific file / individual versions of a specific file.
One of the available actions for the portlet is to add a folder. Any folders added this way are managed through the database. These folders are the ones returned by the service method, for the entirety of the portal, along with some folders Liferay uses. The folders specific to each file will not show up when using this service.
Liferay uses -1 to designate "all". Sometimes you see the usage as getDLFolders(QueryUtil.ALL_POS, QueryUtil.ALL_POS) where ALL_POS is short for "all possible" and it simply wraps a constant value.

How to hide personal info from a publicly shared GitHub?

I share my Java project on GitHub (because I believe in open-source code and no hidden tricks). Anyways, I have a unique UserAgent I got from a website for API usages... I want to know how I can hide that from GitHub without making my project private...
What can I do?
I tried searching Google, but no one seems to have the same problem. I can't use a separate file and then add it to .gitignore because it won't work when I deploy the project. Please help!
I want to know how I can hide that from GitHub without making my project private
You cannot push that information to the repo then.
What you can do is declaring a content filter driver which, on checkout, will check if it has access to a private source of information (elsewhere than your public repo, potentially elsewhere than GitHub), and generate the right file (which remains private, and is declared in the .gitignore).
That content filter driver is declared in a .gitattributes, and is taking a template file (which is versioned but contains, by its nature, no value), and will generate the complete file with:
default values (if the source of the private data isn't found)
sensitive values (if the script has access to the private source of information)
As suggested in comments: put this information in a config file.
Here is an example: this javascript project provides a config.js.template file, but the application expects a config.js file (which is gitignored). If this file doesn't exist, the template is copied.
That way, it will run with sensible default values even if the user doesn't take the time to write his own config first.
Moreover, since you're saying yo plan to "switch" to a config file, I guess those personal config values are currently in your code. So don't forget to also clean your old commits before pushing to github!
Just encrypt confidential info using GPG and also sign your tags.

How do I create an HTML table of files for download?

I'm in charge of updating an existing java app for an embedded device (a copier).
One of the things I want to do is create a servlet which allows the download of all the files in our sandboxed directory on the device (which will include the application log files, local caches, etc). At the moment these files are all in a single directory with no subdirectories.
Basically what I'd like to do is as follows:
Log.log
Log.log.1
Log.log.2
SomeLocalCache.txt
AnotherLocalCache.txt
where each line is a clickable link allowing download of the file.
However, my HTML experience is basically nil, and my familiarity with the Java API is still fairly rudimentary, so I'm looking for some advice on the proper way to go about it.
I've read through all the samples provided, and here's what I'm thinking.
I can create a servlet at a specified URL on the device which will call into my code. Let's call this /MyApp.
I add another link below that, let's call it /MyApp/Download.
When this address it reached in a browser, it displays the list of files.
This list will have to be created on the fly. I can create an HTML template file and put it in the res folder (this seems to be the recommended method for the device in question), but the whole list of files/links will need to be substituted in at run time. Here's an example I found using <ol>+<li> tags for the list and <a> tags for the links. I can generate that on the fly pretty easily. Is that a reasonable way to go?
e.g.
<ol>
<li>
Log.log
</li>
<!--more <li> elements-->
</ol>
Clicking on an individual file will link to /MyApp/Download/File.ext which will then trigger the file download via my servlet (I've found this code which looks promising for the actual download).
The device will require users to log before they are allowed to access the /MyApp link or any sub-links, and I can additionally require that the logged in user be an admin before allowing file download, which together seems like sufficient security in this case (heavy security is not required for these files).
So am I missing anything big or is this a reasonable plan of engagement?
EDIT
Judging by this link when to use UL or OL in html? Many people are going to hammer the answer and comment below because they say it is important to put semantic information into the HTML.
My point is simply this -- the only difference is browsers will display one with bullet points (as OP seems to want) and one with numbers (as the OP does not want.) I suggest he change the HTML to the way he wants it to render, or leave it as is, and make some CSS changes.
Yes there is a semantic difference between the two... they will both still render in order as defined here http://www.w3.org/TR/html401/struct/lists.html Is the HTML the place to put semantic information? I think not, code that generated the HTML is the correct place. Your cohesion may vary.
I won't change my original comment for the sake of history.
END EDIT
Seems fine to me -- however <ol> is not really used any more, I'd go with <ul>. Don't worry, it is still ordered as you would expect.
The reason for this is the only difference between the two was browsers would automatically number (render with a number before) ordered lists. However, with CSS all the rendering control can be in the CSS (including numbering) and everyone is happy.
Hardly anyone uses the auto number anymore. In fact via CSS, lists can and are used for all sorts of crazy things, including CSS menuing systems.
Here's a summary you need to do:
You can use File#listFiles() to get a File[].
You can use JSTL c:forEach to iterate over an array.
You can use HTML <ol>, <ul> or <dl> elements to display a list.
You can use HTML <a> element to display a link.
You can use a Servlet to write an InputStream of a local file to OutputStream of the response. Remember to pass at least Content-Type, Content-Length and Content-Disposition along.
You can make use of request pathinfo to pass file identifier safely. E.g. map servlet on /files/* and let link point to http://example.com/files/path/to/file.ext and in the servlet you can get /path/to/file.ext by request.getPathInfo().
A basic and solid servlet example can be found here: FileServlet. If you want to add resume and compressing capabilities, then you may find the improved FileServlet more useful.
That said, most appservers also just supports directory listing by default. Tomcat for example supports it by default. You can just define another <Context> in Tomcat's server.xml with a docBase of C:/path/to/all/files and a context path of /files (so that it's accessible by http://example.com/files.
<Context docBase="/path/to/all/files" path="/files" />
That's basically all. No homegrown code/html/servlet needed.

How to preview a file on the server in JBoss

I need some ideas on how I can best solve this problem.
I have a JBoss Seam application running on JBoss 4.3.3
What a small portion of this application does is generate an html and a pdf document based on an Open Office template.
The files that are generated I put inside /tmp/ on the filesystem.
I have tried with System.getProperties("tmp.dir") and some other options, and they always return $JBOSS_HOME/bin
I would like to choose the path $JBOSS_HOME/$DEPLOY/myEAR.ear/myWAR.war/WhateverLocationHere/
However, I don't know how I can programatically choose path without giving an absolute path, or setting $JBOSS_HOME and $DEPLOY.
Anybody know how I can do this?
The second question;
I want to easily preview these generated files. Either through JavaScript, or whatever is the easiest way. However, JavaScript cannot access the filesystem on the server, so I cannot open the file through JavaScript.
Any easy solutions out there?
Not sure how you are generating your PDFs, but if possible, skip the disk IO all together, stash the PDF content in a byte[] and flush it out to the user in a servlet setting the mime type to application/pdf* that responds to a URL which is specified by a link in your client or dynamically set in a <div> by javascript. You're probably taking the memory hit anyways, and in addition to skipping the IO, you don't have to worry about deleting the tmp files when you're done with the preview.
*****I think this is right. Need to look it up.
Not sure I have a complete grasp of what you are trying to achieve, but I'll give it a try anyway:
My assumption is that your final goal is to make some files (PDF, HTML) available to end users via a web application.
In that case, why not have Apache serve those file to the end users, so you only need your JBOSS application to know the path of a directory that is mapped to an Apache virtual host.
So basically, create a file and save it as /var/www/html/myappfiles/tempfile.pdf (the folder your application knows), and then provide http://mydomain.com/myappfiles (an Apache virtual host) to your users. The rest will be done by the web server.
You will have to set an environment variable or system property to let your application know where your folder resides (/var/www/html/myappfiles/ in this example).
Hopefully I was not way off :)
I agree with Peter (yo Pete!). Put the directory outside of your WAR and setup an environment variable pointing to this. Have a read of this post by Jacob Orshalick about how to configure environment variables in Seam :
As for previewing PDFs, have a look at how Google Docs handles previewing PDFs - it displays them as an image. To do this with Java check out the Sun PDF Renderer.
I'm not sure if this works in JBoss, given that you want a path inside a WAR archive, but you could try using ServletContext.getRealPath(String).
However, I personally would not want generated files to be inside my deployed application; instead I would configure an external data directory somewhere like $JBOSS_HOME/server/default/data/myapp
First, most platforms use java.io.tmpdir to set a temporary directory. Some servlet containers redefine this property to be something underneath their tree. Why do you care where the file gets written?
Second, I agree with Nicholas: After generating the PDF on the server side, you can generate a URL that, when clicked, sends the file to the browser. If you use MIME type application/pdf, the browser should do the right thing with it.

Categories