Search for content encoding - alfresco

In Alfresco it is possible to search for a document with a content mimetype like this:
#cm\:content.mimetype:text/plain
The search documenatition describes this as
Content has some additional information about the mimetype and size which can also be used in queries. These are of the form #cm:content.mimetype.
Question
Is it possible to search for a content encoding, too? This has no effect:
#cm\:content.encoding:UTF-8

I am using the Alfresco 4.2.d and in the Repository search I get results for eg. UTF-16BE encoding when searching like this:
#cm\:content.encoding:UTF-16BE
Url: http://localhost:8080/share/page/search?t=%40cm%5C%3Acontent.encoding%3AUTF-16BE&s=&a=true&r=true
or when using the server side JavaScript search (webscript):
var query = "#cm\\:content.mimetype:text/plain AND #cm\\:content.encoding:UTF-16BE";
var nodes = search.luceneSearch(query, null, true, 1000);

Related

What is the optimal way to encode a tag to use in algolia?

I have an article page that lists the tags related to that article. When the user clicks on the tag it brings them to the Algolia search results page. This is a Wordpress website. Some of my tags happen to contain ampersands in them like "Spades & Shovels", for example.
What I've noticed is that when I urlencode this term it does not display the search term properly in the search box when I send it via a query string.
I've tried this and thought this was the secret sauce, but it doesn't always work.
$tag_name = json_encode(urlencode(html_entity_decode($tag->name)));
What would be the best way to encode a tag name so that when I pass it via a query string to the search results page it handles it properly?
I've done more testing and I am noticing some odd things on my search results page. If I come to the search page with the searchbox field empty, but pass a post_id (I'm dynamically loading the tags associated with a post in the filter section), I can see "Spades & Shovels" listed there and it has a count of "65" next to it.
If I type "Spades & Shovels" into the searchbox, I see that number quickly drop down to 10 in the sidebar.
When I pass the tag in the query string no matter how I encode it, it doesn't seem to work. I mean I see the words Spades & Shovel in the search box, but I don't get any results. Its very strange, but probably something simple I'm hoping to fix. I need to be able to pass & in a query string to my search results page, but I have not found the proper formula for sending an ampersand in the url for this to work.
It does seem like the value I am passing through in the query string is not an exact match to the actual tag name.
I have tried all of these possibilities and different combinations:
$clean_tag = json_encode(urlencode(html_entity_decode($tag->name)));
$clean_tag = htmlspecialchars_decode($clean_tag);
$clean_tag = html_entity_decode($clean_tag);
$clean_tag = urlencode($clean_tag);
$clean_tag = htmlentities($clean_tag);
$clean_tag = html_entity_decode($clean_tag);
$clean_tag = json_encode($clean_tag);
None of these seem to do the trick. Any thoughts?

How to store an image to riak and get it from riak?

In my project now, I need to store some images to Riak, then get them from Riak and display them in HTML page.
Here is an API I encapsulated:
//inputstream is a stream of an image
byte[] imageContent = IOUtils.toByteArray(inputStream);
String descriptiveId = null;
String storedImageId = UUID.randomUUID().toString();
BlobContent blobContent = new BlobContent(imageContent,descriptiveId);
riakBlobDAO.create(storedImageId,blobContent);
.....
//get the byte[] from riak by the uuid
BlobContent returnedBlobContent = riakBlobDAO.get(storedImageId);
byte[] returnedImageContent = returnedBlobContent.getData();
if i invoke this method,it will return sth,but for this <img src="xxxx">,i can't
get the src from the returned sth, so any other solutions?
I know the image stored in riak is binary bytes, but I am confused that how can I get it from riak and display it in HTML page.
I know that <img src="xxxx" />,but if an image stored in Riak,can i generate the image url ?
If I understand your problem correctly, you are storing image's data as a BLOB in Riak and retrieving the same. With this stored BLOB, if you try retrieving it and do something like this in your HTML:
<img src="*<...retrieved BLOB data...>*" /img>
then it's not bound to work. The ideal way is to save this BLOB as a file (maybe a temporary file in /tmp) with proper extension and then use the same path into your HTML.
As an additional point, if your image's BLOB is in a format which is supported by newer browsers under HTML5, then you could also pass the data directly using following format:
<img src="data:image/png;base64, ....." />
More info on it here: Embedding Base64 Images
Although, beware that the above way is subject to varying behaviors on different browsers.

PDF creation tool that can handle Client-side view changes

I am trying to find a tool that can be used to create PDFs from websites. These websites all have Bootstrap based client side view settings, such as tabs, toggles, and paging. As such, there is no post-back to the server. I need to be able to create a pdf that is in the same state as the user sees it.
In my research, I have only been able to find tools that can create PDFs if given a URL, or if given a HTML string. Examples of these tools include ActivePDF's Webgrabber, and EVO PDF. However, they are not able to generate the PDF's with the client-specific settings, but instead only see the default selections of a given page. It is not possible for me to do a post-back to the server, so I am looking for a tool that can create PDFs on the fly, with the dynamic settings intact. I am working in ASP.NET, and so I would like a tool that is .NET friendly as well. Lastly, I would prefer the tool to not be open-sourced.
It sounds like a proper solution here would be to take data from your client side, post it via AJAX (not an ASP.NET postback!) and then process it on the server side to generate the PDF. Since you haven't given much detail, I'm going to assume we don't need to send over all the HTML, but rather values that were entered via a form.
<script>
function postDataToServer(){
var itemId = $("#ItemIdTB").val();
var quantityOrdered = $("#QuantityTB").val();
$.ajax({
url : "GeneratePdfFromForm?itemId="+itemId+"&quantityOrdered="+quantityOrdered
})
.done(function(){alert("Success!");})
.fail(function(){alert("Failure!");});
}
</script>
My answer is using jQuery, which is a JavaScript library that simplifies AJAX and DOM manipulation. However, this technique is doable with other JavaScript libraries (or even without a library).
On the server side, let's have an ASP.NET Web API function that can handle that AJAX Post.
[Route("GeneratePdfFromForm")]
public static void GeneratePdfFromForm(string itemId, int quantityOrdered)
{
Debug.WriteLine("Received itemId {0} and quantity {1}", itemId, quantityOrdered);
byte[] pdf = GeneratePDF(itemId, quantityOdered); //you'll need a function called GeneratePDF that can generate your PDF based on the parameters, probably using a library like iTextSharp.
//now do you want with the PDF byte array
}
So that's how you'd generate the PDF. You could return it from the GeneratePdfFromForm() function back to the client. But since that's potentially a long running task, you should probably implement it in the background using something like Hangfire, then when the PDF is ready you'd present it to the client for download (perhaps using SignalR or jQuery AJAX polling to alert the client of when the PDF is ready).
I was passing data from the client side to the server side via query string. You could instead create a class to represent the parameters for your PDF generation, then pass that form the client side to the server side via jQuery AJAX's data parameter.
If you really want to post the entire HTML from the client side to the server, you could so something like this:
var html=$("html").html();
$.ajax({
url: <your url here>,
data: html,
contentType: "text/html"
});
However, I'm willing to bet the actual HTML isn't what you care about for generating the PDF, but rather the selected values from some client side form. The actual HTML would include everything on the client side, including navigation menus, scripts etc. You could post a subset of the HTML using a different selector (ex: $("#OrderDiv").html()), which is a technique some people use to generate PDF's. But I think it's much cleaner to decouple your HTML intended for the browser from the way the PDF is generated, so that changes to your site don't mess up the PDF. You can then use the PDF creating library's capabilities to build the PDF rather than using HTML.

Decode and RequestQueryString

My URL is
www.domainname.com/default.aspx?l=en&t=32600483-1618-4f09-9a86-c12de4dafc7b
I would love to read the QueryString value of t. So i can parse it as GUID.
Unfortunatelly that & thing, seems to mess things up.
How can i parse the value of the t Query string?
My URL is
I hope you realize that this is not a valid URL. This is a HTML encoded string. Do not confuse with an URL. URLs should be properly URL encoded, not HTML encoded. And since you start with something invalid your only chance is to use some ugly string parsing/regex to extract the necessary information. Since this looks like an HTML encoded string you could HTML decode it first:
var myUrl = "http://www.domainname.com/default.aspx?l=en&t=32600483-1618-4f09-9a86-c12de4dafc7b";
myUrl = HttpUtility.HtmlDecode(myUrl);
var values = HttpUtility.ParseQueryString(myUrl);
var t = values["t"];
But I repeat once again: don't do this: tackle the problem at its root. And the root of your problem is the origin of this URL. So if you have control over the generation of this URL then fix it so that you can have a valid URL that you could easily work with with the built-in methods. If you don't have control over the generation of the URL then notify the author of the code that he has a bug in it and ask him to fix it because he has provided you a non-properly encoded URL and you are obliged to use some ugly string parsing mechanisms to extract the information from it.

ASP.NET Request - Can I get a posted file from a dynamic control created on client?

I have a web control with some custom javascript. The javascript creates new file upload controls on the client dynamically using code similar to:
var newFileUpload = document.createElement('input');
newFileUpload.type = 'file';
container.appendChild(newFileUpload); // where container is a div
This exists in an ASP.NET form with encType set to multipart/form-data. I will have 1 - n controls on the page (well, limited to a reasonable number, of course).
I now would like to capture the uploaded files in my ASP.NET application. Because of the approach taken above I know that I cannot capture them as I would from a FileUpload control (which unfortunately I cannot use). Is there another way to capture the uploaded files?
I have looked through a number of areas, including:
Request.Files
Request.Form
Request.Form.Keys
Request.InputStream
But I have not been able to find the content. I believe the client is submitting this data correctly but have been unable to determine what the server does with the raw request information (if this is even exposed).
Does anyone have any suggestions on areas I might further explore?
Thanks
You should add a unique name to your upload element to get it from Request.Form collection.
var newFileUpload = document.createElement('input');
newFileUpload.type = 'file';
//newFileUpload.id = 'file01';
newFileUpload.name = 'file01';
container.appendChild(newFileUpload);
EDIT : I tried id and name attibutes, the with name, you can get the content by
Request.Form["file01"]
Also if you should add the attribute below to your form element. This allows you to get the file content by Request.Files["file01"] :
enctype="multipart/form-data"

Resources