Set mimetype on swp

54 views
Skip to first unread message

Ilya Ushakov

unread,
May 26, 2017, 6:59:51 AM5/26/17
to TopBraid Suite Users
I need to create report based on swp technology which would be save as file and not just opens in new browser's tab . To achieve this in, for example, sparqlmotion, you can use sml:mimeType property of sml:ReturnText and put there something like "text/csv". But, alas, sparqlmotion is not suitable technology for our requirements. 
Is it possible to put mimetype in swp? 

Holger Knublauch

unread,
May 26, 2017, 6:11:39 PM5/26/17
to topbrai...@googlegroups.com
The mime type can be set via the ui:responseType property at the SWP service. There are several pre-defined instances of ui:ResponseType, but you can define your own. Example:

ui:HTML
  rdf:type ui:ResponseType ;
  ui:mimeType "text/html" ;
  rdfs:comment "The HTML response type." ;
  rdfs:label "HTML" .

Holger




On 26/05/2017 20:59, Ilya Ushakov wrote:
I need to create report based on swp technology which would be save as file and not just opens in new browser's tab . To achieve this in, for example, sparqlmotion, you can use sml:mimeType property of sml:ReturnText and put there something like "text/csv". But, alas, sparqlmotion is not suitable technology for our requirements. 
Is it possible to put mimetype in swp? 
--
You received this message because you are subscribed to the Google Group "TopBraid Suite Users", the topics of which include the TopBraid Suite family of products and its base technologies such as SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to topbrai...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ilya Ushakov

unread,
May 29, 2017, 7:35:51 AM5/29/17
to TopBraid Suite Users
Hi Holger, 
Thank you for your reply.
I tried to add ui:responseType with my own instance (which has ui:mimeType = application/octet-stream) in skos:Concept where i defined logic in ui:instanceView property of skos:Concept. 
In ui:instanceView i call my own subclass of ui:Element. ui:responseType there as well. But, alas, no any impact. 
If i add application/octet-stream to _format parameter of request, the result is automatically downloaded but the content is wrapped by <div> element.
Here is example of link
http://192.168.99.100:8888/evn/tbl/swp?_resource=http%3A%2F%2Fwww.ontologies.thomson.com%2FKNS137PR%23Concept_9f132aca-2b2c-11b2-80cb-d7e28d5ba670&_matchIds=ExportToIntented&_withImports=true&_snippet=true&_format=text&_base=urn%3Ax-evn-master%3Amini_kns&metadataList=


 example of result see in an attachment.
What is the nature of this <div>? 
What must I do that this <div> didn't appear?


swp (3)

Holger Knublauch

unread,
May 29, 2017, 8:38:45 AM5/29/17
to topbrai...@googlegroups.com
I guess going through ui:instanceView will by default assume HTML in the servlet, and then also wrap it into a <div>. But from my test the attached solution seems to work. Call it using

    http://localhost:8083/tbl/swp?_viewClass=octet:TestServices&who=World

(Produces a direct file download, no <div>)

To simulate the situation of the instanceView, just use another argument (instead of who above) which will have the value of _resource, and get to the business logic from there.

HTH
Holger
octet.ui.ttlx

Ilya Ushakov

unread,
May 29, 2017, 10:06:22 AM5/29/17
to TopBraid Suite Users
Hi Holger,
Seems everything works. Thank you.
One additional question:
Is it possible to put default extension of downloaded file (for example .txt) un swp?

Holger Knublauch

unread,
May 29, 2017, 7:44:27 PM5/29/17
to topbrai...@googlegroups.com
We have no clean way of setting the download file name or extension right now (apart from an undocumented hack), but I have just extended ui:setResponseHeader for 5.4 so that you could do

<ui:setResponseHeader ui:headerName="Content-Disposition" ui:headerValue="inline; filename=..." />

Anyway, I hope your users can live with this little gap for the time being.

Cheers,
Holger

Ilya Ushakov

unread,
May 30, 2017, 9:18:13 AM5/30/17
to TopBraid Suite Users
Hi Holger, 
Thank you for your answer. When the new version of evn is expected?
About mimeType. 
You did recommended me use ui:Service. 
When I try to get value of _resource param as ui:param(&quot;_resource&quot;), it does not work at all. Always new tab is opening.
RequestLink for this case looks like this:
http://192.168.99.100:8888/evn/tbl/swp?_resource=http%3A%2F%2Fwww.ontologies.thomson.com%2FKNS137PR%23Concept_25c38181-29ff-11b2-8070-d32bf9e39c50&_viewClass=trevn:IntentedExport&_withImports=true&_snippet=true&projectGraph=urn%3Ax-evn-master%3Amini_kns&metadataList=

When I pass value of  resource uri as resource in link. 
in my ui:service i created spl:argument named resource and pass this in my ui:element implementing business logic as 
<trevn:displayIntentedReport arg:concept="{= IRI(?resource) }" arg:projectGraph="{= IRI(?projectGraph) }"/>

I am not able to get all childs of this recource, query:
SELECT ?child
WHERE {
BIND(smf:trace("INFO: resource {?1}", ?resource) AS ?dummy)
?child (skos:broader)* ?resource.
}

returns nothing despite BIND(smf:trace("INFO: resource {?1}", ?resource) AS ?dummy)  writes to log
<http://www.ontologies.thomson.com/AIN1PR#Concept_073769e8-2b29-11b2-809b-b6c43c3606a4>

So, How can I get access to data from ui:elements.

P. S. 
If i use old version where I used to ui:instanceView of skos:concept and determined current concept as ?this, everythin works fine

Richard Cyganiak

unread,
May 30, 2017, 10:52:27 AM5/30/17
to topbrai...@googlegroups.com
Hi Ilya,

I think Holger’s point was that you need to use a different parameter name than &_resource=… in the URL if you use ui:Service and &_viewClass=…

That’s because &_resource… is only used when your SWP snippets are attached directly to instances (ui:resourceView) or classes (ui:instanceView). But you’re not doing that. You’re defining a ui:Service, with the SWP snippet attached to the service as ui:prototype. So you can’t use _resource.

In his example, Holger called the parameter &who=… but you should pick whatever makes sense in your case, like &concept=…

In your SWP snippet, you have various options to get the value of that parameter.

First, you can use ui:param("concept") to read the value. This is simple.

Second, you can declare an argument called “concept” (like you already did, just don’t call it “resource”). Now the value passed in the URL as &concept=… will be available as ?concept in the SWP snippet. I find this version a bit cleaner.

Hope that helps,
Richard

Ilya Ushakov

unread,
May 30, 2017, 11:46:27 AM5/30/17
to TopBraid Suite Users
Hi Richard,
Thank you for your answer.
I am able to get value of resource param (I renamed resource to concept). 
The problem is when i use 
 ui:Service and &_viewClass=…, I am not able to get all child of this concept in my ui:elements. As I mentioned before, the query
SELECT ?child
WHERE {
BIND(smf:trace("INFO: concept {?1}", ?concept) AS ?dummy)
?child (skos:broader)* ?resource.
}

despite i see in logs properly value of concept.

If I use 
 &_resource… and ui:instanceView on skos:Concept or skos:ConceptScheme  and pass this param to my ui:element, everything displays correct. But i am not able to put mimeType = application/octet-stream in latest case.
This behavior is very strange.
What is the reason of this behavior?

Ilya Ushakov

unread,
May 30, 2017, 11:52:54 AM5/30/17
to TopBraid Suite Users
In addition:
I use this query as datasource e. g.
<ui:forEach ui:resultSet='{# query }'>
...do something
</ui:forEach>

Richard Cyganiak

unread,
May 30, 2017, 12:05:23 PM5/30/17
to topbrai...@googlegroups.com
In the query you pasted below, it still says ?resource instead of ?concept. That could be the problem.

Besides that, if &_base= is correct, and the smf:trace logs the expected value, then I can’t really think of any reason why it wouldn’t work.

Richard

Ilya Ushakov

unread,
May 31, 2017, 8:42:47 AM5/31/17
to TopBraid Suite Users

Hi Everyone,
Thank you for reply
You pointed me out on the problem. I had incorrect &_base param. Thanks a lot again.
earkier you mentioned about  undocumented hack, "We have no clean way of setting the download file name or extension right now (apart from an undocumented hack), but I have just extended ui:setResponseHeader for 5.4 so that you could do". Which hack in 5.3 version did you mean?


<ui:setResponseHeader ui:headerName="Content-Disposition" ui:headerValue="inline; filename=..." />"

Richard Cyganiak

unread,
May 31, 2017, 9:05:42 AM5/31/17
to topbrai...@googlegroups.com
On 31 May 2017, at 13:42, Ilya Ushakov <juve.us...@gmail.com> wrote:

earkier you mentioned about  undocumented hack, "We have no clean way of setting the download file name or extension right now (apart from an undocumented hack), but I have just extended ui:setResponseHeader for 5.4 so that you could do". Which hack in 5.3 version did you mean?

It was Holger who said that, not me. We’ll have to wait for him to answer that.

Glad I could help with the other problem.

Richard

Holger Knublauch

unread,
May 31, 2017, 7:22:43 PM5/31/17
to topbrai...@googlegroups.com


On 31/05/2017 22:42, Ilya Ushakov wrote:

Hi Everyone,
Thank you for reply
You pointed me out on the problem. I had incorrect &_base param. Thanks a lot again.
earkier you mentioned about  undocumented hack, "We have no clean way of setting the download file name or extension right now (apart from an undocumented hack), but I have just extended ui:setResponseHeader for 5.4 so that you could do". Which hack in 5.3 version did you mean?

I will send you info off-list as I don't want a temp hack to be propagated further.

Holger
Message has been deleted

Holger Knublauch

unread,
Jun 1, 2017, 6:38:02 PM6/1/17
to topbrai...@googlegroups.com
On 1/06/2017 22:14, Ilya Ushakov wrote:
Hi Holger, 
Thanks a lot.
By the way, I got an unexpected obstacle when i tried to set mimetype in my sparqlmotion. 
Because because only sml:ReurnText has sml:mimeType. I need to use smf:convertRDFToTextfirst. After that I use sml:ReturnText  where i set text/csv or application/octet-stream. 
The problem is that i must have all possible serialization (Turtle, RDFXML and JSON), but using smf:convertRDFToText + sml:ReturnText combination is only acceptable to RDFXML format.
How can i set mimeType for Turtle and json formats in sparqlmotion?

I don't understand the problem. sml:ReturnText's sml:mimeType can be any string that you compute dynamically, e.g. using a SPARQL expression. It is not limited to RDF/XML. Could you clarify?

Holger
Reply all
Reply to author
Forward
0 new messages