How to access XML files through the URL - java

I am a beginner in Struts 2 and I am stuck in an issue, I would like to access an .xml file in the project doc, when the user goes to the link www.sitename.com/sitemap.xml. But right now I can only access it by going to the URL www.sitename.com/sitemap, i.e. without the extension. When I specify the action name as sitemap.xml it does not work. How could I make the user access the URL www.sitename.com/sitemap.xml. Sorry If the question does not make any sense.

The standard extension in Struts 2 for action name is .action. But it's configurable via using a setting struts.action.extension. It's available in the default.properties, which is used by the default action mapper.
You might use a comma separated list, e.g. struts.action.extension=action,xml,whatsoever
The blank extension used to map directories treated as action names. Static content is mapped via specifying a blank extension, e.g. struts.action.extension=, or struts.action.extension=a,b,c,,, or struts.action.extension=a,,b,c.

Related

How to specify, which resource file to be used while running?

I wants my application to be in both Hindi and English language, so I have created a ResourceBundle named as Resources. In this directory I have create label.properties,label_en_US.properties and label_hi_IN.properties and these file have putted some values like ab=xy_default, ab=xy_in_en and ab=xy_in_hindi respectively.
And Now I planned to use them as label text, so in property of that label i mantioned the default one, like this
Here code is key and In label_defualt is code=Code : , in label_en_US code=Code : and in label_hi_IN code=कोड :. How can I specify which of label.properties to be useout of label, label_en_US or label_hi_in. I have stored user preference in my database like which language to use. I want to know how I can force or tell it use that particular file out of label, label_en_US, label_hi_IN in main function or somewhere else. As now it's taking values from label.properties file only, if user want it to be in hindi then how internally we force to use that label_hi_IN.properties file.
If you've got your files sorted out OK, the right internationalization should occur naturally depending on your locale. If you want to test other supported locales in your software, set the appropriate system properties:
java -Duser.country=IN -Duser.language=hi …
or
java -Duser.country=US -Duser.language=en …
ResourceBundle uses a “fallback” strategy. If the user’s current locale is hi-IN:
ResourceBundle.getBundle will look in label_hi_IN.properties (if that resource exists)
If that file is not found, ResourceBundle.getBundle will look for label_hi.properties (if that resource exists)
If that file is not found, ResourceBundle.getBundle will look for label.properties (if that resource exists)
This means you should do the following:
If label.properties contains English entries, remove label_en_US.properties from your project
If label.properties contains Hindi entries, remove label_hi_IN.properties from your project
Rename label_hi_IN.properties, if it is still present, to label_hi.properties, so all Hindi locales will use that file
Rename label_en_US.properties, if it is still present, to label_en.properties, so all English locales will use that file
Finally I got it, We have to just set Default Locale.
Locale locale = new Locale("hi","IN");
Locale.setDefault(locale);

is "content://" in the Uri of Content Provider in Android replaceable ?

In our platform, we use a certain format from paths. In the Android App, it receives those paths to load some data or do something.
I want to do all the data handling using content provider, I want to give the path and get data. A simple transaction.
When I read into content providers, the documentation and all the tutorials out there always use "content://" at the beginning. However, I want to use our own start of the path which is usually "is-://". Can something like this work?
no, this is how the system categorize the uri as content provider.
its like relacing file:// with something else.
After referring to Developer.google site
A content URI is a URI that identifies data in a provider. Content URIs include the symbolic name of the entire provider (its authority) and a name that points to a table (a path). When you call a client method to access a table in a provider, the content URI for the table is one of the arguments.
From this I believe you can't set it on your own as it includes the symbol name.
Also why do you want to change it?

Create Dynamic URL in GWT

I am working on one application where I want to create dynamic URL appending my domain and the dynamic URL created can be shared with other users.
Like Example:
I have created one random string 'abcdef' and I want to create a dynamic url with this like 'http://domain.ext/abcdef/'. This URL now can be shared with other specific users, so those users can hit the same url to join on same page.
I want to create 'http://domain.ext/abcdef/' with 'abcdef' like dynamic string.
Please suggest, how I can do this with GWT ?
You can use: GWT.getHostPageBaseURL() to the the base of your URL, then append what you need to that string.
Take a look at the javadoc in: http://www.gwtproject.org/javadoc/latest/com/google/gwt/core/client/GWT.html

Struts2: UTF .properties

Is there a way to load a UTF-8 encoded .properties file in Struts2?
I know that its posible to load a UTF-8 file in a ResourceBundle via implementing your Control that loads a UTF8 inputstream but how to use it in Struts2? (I found howto do it in JSF here:
http://jdevelopment.nl/internationalization-jsf-utf8-encoded-properties-files/
but cannot figure how to do it in struts2)
PD: Also I know that I can use the native2ascii tool, but its... ugly...
EDIT:
I've seen that I can implement TextProviderSupport and set it default like says here and override all its constructors setting a custom createrd resourcebundle with UTF8 inputReader and letting some logs. I've save it and when starting tomcat it says:
Información: Choosing bean (myTextProvider) for
(com.opensymphony.xwork2.TextProvider)
with this in struts.config:
<bean class="com.utils.i18n.UTF8TextProvider" name="myTextProvider"
type="com.opensymphony.xwork2.TextProvider" scope="default"/>
<constant name="struts.xworkTextProvider" value="myTextProvider" />
<constant name="system" value="myTextProvider" />
So, its seems ok. But my class is never instanciated (I only run a sample action that implements action support and write a text with 'getText' and a jsp that have a <s:text name="">)
So problem remains...
Struts2 uses the concept of ResourceBundle to load properties files and achive the goals of internalization (i18n) as well as localization (l10n).
The resource bundle is used to keep the key and value pairs for respective languages such as English Resource Bundle can have value as English Text and France Resource Bundle can have value as France Text but the keys are same across.
Resource Bundle can be place in the following places
ActionClass.properties
Interface.properties
BaseClass.properties
ModelDriven’s Model
Package.properties
I18n message key
Global resource properties
The resource properties are being searched in the above order. At first it looks the resource properties with action class name.properties, if does not found then it looks for interface.properties else goes on till Global resource properties.
There are many tutorials which explain in detail about how to use Resource Bundles in Struts 2. Have a look at the following links:
http://www.journaldev.com/2304/struts2-resource-bundles-and-localization-example
http://javatechig.com/java/struts/struts2-localization-example
http://www.javabeat.net/struts-2-resource-bundle-example/
===============
Update
Regarding loading UTF-8 encoded properties file in Struts 2, you can refer http://javatechig.com/java/struts/struts2-localization-example and see how the Japanese text is being used after encoding it to UTF-8. Since, you mentioned about native2ascii, I am assuming that you know about how to convert a given text to UTF-8 encoding.

Custom URL scheme as adapter on existing URL schemes

Is there a clean and spec-conformant way to define a custom URL scheme that acts as an adapter on the resource returned by another URL?
I have already defined a custom URL protocol which returns a decrypted representation of a local file. So, for instance, in my code,
decrypted-file:///path/to/file
transparently decrypts the file you would get from file:///path/to/file. However, this only works for local files. No fun! I am hoping that the URL specification allows a clean way that I could generalize this by defining a new URL scheme as a kind of adapter on existing URLs.
For example, could I instead define a custom URL scheme decrypted: that could be used as an adapter that prefixes another absolute URL that retrieved a resource? Then I could just do
decrypted:file:///path/to/file
or decrypted:http://server/path/to/file or decrypted:ftp://server/path/to/file or whatever. This would make my decrypted: protocol composable with all existing URL schemes that do file retrieval.
Java does something similar with the jar: URL scheme but from my reading of RFC 3986 it seems like this Java technology violates the URL spec. The embedded URL is not properly byte-encoded, so any /, ?, or # delimiters in the embedded URL should officially be treated as segment delimiters in the embedding URL (even if that's not what JarURLConnection does). I want to stay within the specs.
Is there a nice and correct way to do this? Or is the only option to byte-encode the entire embedded URL (i.e., decrypted:file%3A%2F%2F%2Fpath%2Fto%2Ffile, which is not so nice)?
Is what I'm suggesting (URL adapters) done anywhere else? Or is there a deeper reason why this is misguided?
There's no built-in adaptor in Cocoa, but writing your own using NSURLProtocol is pretty straightforward for most uses. Given an arbitrary URL, encoding it like so seems simplest:
myscheme:<originalurl>
For example:
myscheme:http://example.com/path
At its simplest, NSURL only actually cares if the string you pass in is a valid URI, which the above is. Yes, there is then extra URL support layered on top, based around RFC 1808 etc. but that's not essential.
All that's required to be a valid URI is a colon to indicate the scheme, and no invalid characters (basically, ASCII without spaces).
You can then use the -resourceSpecifier method to retrieve the original URL and work with that.

Categories

Resources