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

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?

Related

How to get notes from Evernote API that have images?

I currently get notes from Evernote WebClipper API (Java) using the following code. This gets me the notes that have text in them. However, some notes might have images contained in them. I would like to get access to these images (resources). How would I do this?
NotesMetadataList nl = evernoteAccount.getRequestedNotes(words);
for (NoteMetadata note : nl.getNotes()) {
logger.debug("GUID: " + note.getGuid());
logger.debug("Title: " + note.getTitle());
logger.debug("Content: " + note.getContent());
}
Evernote notes can have attachments called resources which includes images. To download the resources you have 2 options:
parse the content of the note for the images for the "en-media" tag. The tag will have the attributes "type" and "hash". Type will contain the MIME type of the file that is attached to the note as a resource and the "hash" is the MD5 hash of the file. If the type of the file is one you would like to retrieve call getResourceByHash on the note store where the note resides passing the GUID of the note, hash of the file, and true/false to include not include the data, recognition, and alternative data respectively.
download the resource associated with the note via the metadata in the note. Each note has a "resources" attribute which is a list of all the resources attached to the note. Each item in the list represents a resource and will have a "mime" and "guid" attribute. You can also inspect the attributes.fileName attribute for the file name of the resource. If the "mime", filename or other attribute of the resource matches your criteria for downloading you can use the getResourceData method on the note store on which the note is contained to download the file by passing the GUID of the resource (not the GUID of the note).
Sources:
Evernote API Reference: https://dev.evernote.com/doc/reference/
Evernote Resources/Attachments: https://dev.evernote.com/doc/articles/resources.php
Evernote Markup Language (ENML): https://dev.evernote.com/doc/articles/enml.php

Using a compact URI in Jena

I'm using Jena to read an ontology and it's working really well so far. Unfortunately I haven't been able to figure out how to use compact uris that I've defined in the model. I've defined the prefixes using the model's setNSPrefix(String prefix, String uri) method. When I try to retrieve statements using the prefix, I get nothing. Also, when I do successfully retrieve a Statement, it contains the full uri instead of the compact one that I defined. It will even do it for the xsd uri http://www.w3.org/2001/XMLSchema#
For example, I'm using the uri http://www.example.com#, I've defined my prefix mapping as ex, and my Statement is http://www.example.com#father http://www.example.com#parentOf http://www.example.com#child where father is the subject, parentOf is the predicate, and child is the object. If I try to retrieve it using ex:father I get no results, and when I do get the Statement back the full uri is there for the subject, predicate, and object. I've seen it use the prefix instead of the uri when I do model.write(OutputStream), but that isn't particularly helpful for me. Am I able to use the prefix as a substitute for the uri like I've been trying to do, or is that not something Jena will provide for me?
When I try to retrieve statements using the prefix, I get nothing.
You can't do, e.g.,
model.getResource("ex:foo")`
You have to do
model.getResource("http://example.org/foo");
You can make that simpler, of course, by
String EX = "http://example.org/";
model.getResource(EX+"foo");
The prefixes are really just for making the serializations nicer to read and write.

How to access XML files through the URL

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.

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.

Selenium 2: Detect content type of link destinations

I am using the Selenium 2 Java API to interact with web pages. My question is: How can i detect the content type of link destinations?
Basically, this is the background: Before clicking a link, i want to be sure that the response is an HTML file. If not, i need to handle it in another way. So, let's say there is a download link for a PDF file. The application should directly read the contents of that URL instead of opening it in the browser.
The goal is to have an application which automatically knows wheather the current location is an HTML, PDF, XML or whatever to use appropriate parsers to extract useful information out of the documents.
Update
Added bounty: Will reward it to the best solution which allows me to get the content type of a given URL.
As Jochen suggests, the way to get the Content-type without also downloading the content is HTTP HEAD, and the selenium webdrivers does not seem to offer functionality like that. You'll have to find another library to help you with fetching the content type of an url.
A Java library that can do this is Apache HttpComponents, especially HttpClient.
(The following code is untested)
HttpClient httpclient = new DefaultHttpClient();
HttpHead httphead = new HttpHead("http://foo/bar");
HttpResponse response = httpclient.execute(httphead);
BasicHeader contenttypeheader = response.getFirstHeader("Content-Type");
System.out.println(contenttypeheader);
The project publishes JavaDoc for HttpClient, the documentation for the HttpClient interface contains a nice example.
You can figure out the content type will processing the data coming in.
Not sure why you need to figure this out first.
If so, use the HEAD method and look at the Content-Type header.
You can retrieve all the URLs from the DOM, and then parse the last few characters of each URL (using a java regex) to determine the link type.
You can parse characters proceeding the last dot. For example, in the url http://yoursite.com/whatever/test.pdf, extract the pdf, and enforce your test logic accordingly.
Am I oversimplifying your problem?

Categories

Resources