JSF external file based on locale - jsf

I have an JSF application where I want to send an email from. Now I don't want to put the email's content in my i18n file. I thought to save it in an external file, lets say email1_de.txt and email1_en.txt.
Can I somehow load this file depending on the user's locale?
Thanks

Why don't you just use a resource bundle.
1. Create a Message.properties file in one of your source code packages and then in that file, add your email content, in plain or HTML format as follows:
message.test3 = This is "<h2>message.test4</h2>"
message.param1 = This is "message.param1" - {0}
message.param2 = This is "message.param2" - {0} and {1}
You may even include parameters.
Declare your resource bundle in your faces-config.xml file
You can call the text in your resource bundle from you class or from your HTML files.
You may look at this example: http://www.mkyong.com/jsf2/jsf-2-0-and-resource-bundles-example/
If you are dealing with different locales, then you can look here: http://www.mkyong.com/jsf2/jsf-2-internationalization-example/
It is explained pretty well.

Related

Which JSF-tag to use to get the path of an Input Directory on the client side?

Is there an input directory for JSF, or library like Omnifaces or Primefaces? I don't need <h:inputFile> as the file actually no need to be uploaded, I would like to provide a field for user to input the path of a file for example:
C:\Folder One\myFile.txt
and ManagedBean will interpret the path, for example, read the content of the file. I don't want user to enter the file path manually in input text. And I don't have the client/server issue as the user will select the file on the machine which my JSF application is deployed.
If such component is not available, is there any workaround? like maybe I can provide a <h:inputFile> and get path from it?

Google tells do not change dynamic URLs, and offers this instead, how?

If you want to serve a static equivalent of your site, you might want to consider transforming the underlying content by serving a replacement which is truly static. One example would be to generate files for all the paths and make them accessible somewhere on your site.
What they mean exactly? And how to do it?
Your question: What do they mean exactly?
If you want to serve a static equivalent of your site - static refers to html pages that are not dynamically created.
you might want to consider transforming the underlying content by serving a replacement which is truly static. Have 'hard copies' of your pages with the different alternatives
One example would be to generate files for all the paths and make them accessible somewhere on your site. Go through your site and create static html pages (or pdf's) of each one and store them in the file structure that is represented by the URL.
Example of the last:
http://site.tld/product/pear which today is a dynamic (created on the fly by the code and database) but is not really in an actual folder on the server called product. They are suggesting to create a copy of the dynamically created page and store it in an actual folder on the server called product with the name pear.
Your question And how to do it?
Will that work - sort of if you wanted to by adding a .html to the physical file (copy of the dynamic one) and save it but I suspect you will run into all sorts of difficulties that you will need to overcome with the redirect code in places like .htaccess. Another option may be change the domain part of the URL to include static ie http://static.site.tld/ for the static copies and the original URL as is for the dynamic version.
The other big challenge then becomes maintaining the two copies because the concept they talk about is for the content (what is shown in the browser) to remain static over time. Kind of breaks the whole concept of how we build dynamic web sites today e.g. online shops etc.
For example if it's a shop, I would use PHP to also create the physical file when a product is added and not include parts that are going to change, rather include a link to the dynamic info something like:
<?php
$file = 'product/pear.html';
// mysql code here to extract the info and format ready for writing
$content = "<html><head><title>$title_from_db</title></head><body>$page_content_from_db</body></html>";
// Write the contents to the file
file_put_contents($file, $content);
?>

Alfresco node-browser.get.js webscript

At this location in this jar file alfresco-remote-api-5.0.d.jar\alfresco\templates\webscripts\org\alfresco\slingshot\node-browser\ there is a webscript. But this webscript consist to 2 files (node-browser.get.desc.xml and node-browser.get.json.ftl ) There isn't the node-browser.get.js file.
I want to know what is done in this fil. I want to select categories and include certains aspects (i have added to categories) in the selection.
Thank you.
Javascript file is not mandatory while creating webscript.
Below is the URL of source file which is getting called on your specified webscript.
https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/COMMUNITYTAGS/V5.0.d/root/projects/remote-api/source/java/org/alfresco/slingshot/web/scripts/NodeBrowserScript.java
Below is context file for java file.
https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/COMMUNITYTAGS/V5.0.d/root/projects/remote-api/config/alfresco/web-scripts-application-context.xml
check bean with webscript.org.alfresco.slingshot.node-browser.node-browser.get
Id.
you need to change in that if you want to customize it.
Usually a webscript is made of 3 parts:
a description file (in your case node-browser.get.desc.xml) which
uses a description language to define many aspects of the
webscript, like security, transaction management and so on
a Server-Side Javascript js file that consists of the business logic that is performed by
the script. In your case you don't have the node-browser.get.js file
because this happens to be a Java backed webscript, that is a
webscript whose business logic is written in Java and not in
Server-Side Javascript.
a Freemarker Template file, node-browser.get.json.ftl, which contains
the presentation logic (view) that has to show the results of the invocation.
In order to achieve what you're looking for about selecting categories and include certains aspects, you'd better learn more about how webscripts work and moreover how to configure/customize Alfresco's interface.
You'd better look at these tutorials in order to get more info.

Where can I find (Path in the bundle) the User create/edit screen source?

I am just trying to find the front end source code for user creation and edit pages. But I tried search by different label text and ID's but no use. Can anyone please tell me the path for user add and edit page source files.
As you can see, the URL is something like:
http://localhost:8080/group/control_panel/manage?p_p_id=125&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&refererPlid=15595&_125_redirect=%2Fgroup%2Fcontrol_panel%3FrefererPlid%3D15595&_125_struts_action=%2Fusers_admin%2Fedit_user
Searching in struts configurations you can see that struts_action=/users_admin/edit_user should refer to jsp file edit_user.jsp
That file is located in users_admin... so the path you are seeking should be html/portlet/users_admin inside portal-web project.
This is on GitHub.

When do browsers send application/octet-stream as Content-Type?

I'm developing a file upload with JSF. The application saves three dates about the file:
Filename
Bytes
Content-Type as submitted by the browser.
My problem is that some files are saved with content type = application/octet-stream even if they are *.doc files oder *.pdf.
When does the browser submits such a content type?
I would like to clean up the database so I need to know when the browser information are incorrect.
Ignore the value sent by the browser. This is indeed dependent on the client platform, browser and configuration used.
If you want full control over content types based on the file extension, then better determine it yourself using ServletContext#getMimeType().
String mimeType = servletContext.getMimeType(filename);
The default mime types are definied in the web.xml of the servletcontainer in question. In for example Tomcat, it's located in /conf/web.xml. You can extend/override it in the webapp's /WEB-INF/web.xml as follows:
<mime-mapping>
<extension>xlsx</extension>
<mime-type>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</mime-type>
</mime-mapping>
You can also determine the mime type based on the actual file content (because the file extension may not per se be accurate, it can be fooled by the client), but this is a lot of work. Consider using a 3rd party library to do all the work. I've found JMimeMagic useful for this. You can use it as follows:
String mimeType = Magic.getMagicMatch(file, false).getMimeType();
Note that it doesn't support all mimetypes as reliable. You can also consider a combination of both approaches. E.g. if the one returns null or application/octet-stream, use the other. Or if both returns a different but "valid" mimetype, prefer the one returned by JMimeMagic.
Oh, I almost forgot to add, in JSF you can obtain the ServletContext as follows:
ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
Or if you happen to use JSF 2.x already, use ExternalContext#getMimeType() instead.
It depends on the OS, the browser, and how the user has configured them. It's based on the way the browser determines the file type of local files (to display them). On most OS/browser combinations this is based on the file's extension, but on some it may be determined by other means. (eg: on Mac OS)
In ay case, you shouldn't really rely on the Content-type sent by the browser. The best approach would be to actually look at the contents of the file. You could probably also use the filename, but keep in mind that browsers aren't necessarily going to be good about telling you that either (though it's probably still a lot more reliable than the Content-type they send).

Resources