So perhaps its possible to make some smart controller for content-type “Code”?
Here’s a stupid idea:
What if it was possible to make a custom content-type, with the section in the content type definition xml file being empty. Then make it possible somehow to upload XML/JSON files as this content-type.
Why do this: Well some of these XML/JSON files may have deeply nested structures which may take a very long time to write content-type definition for. I would rather spend my time on the view…
So I made a template to handle content-type “Code”, used my page controller, and made and added a Code part to it.
In this example Code part controller stream becomes undefined. Which it shouldn’t. Bug?
var assign = require(’/lib/assign’);
var contentLib = require(’/lib/xp/content’);
var portal = require(’/lib/xp/portal’);
var thymeleaf = require(’/lib/xp/thymeleaf’);
exports.get = function () {
var view = resolve(‘code.html’);
//var component = portal.getComponent();
var partConfig = portal.getComponent().config;
var content = portal.getContent();
//log.info(JSON.stringify(content, null, 4));
var attachments = contentLib.getAttachments(content._id);
//log.info(JSON.stringify(attachments, null, 4));
var firstAttachmentName = attachments[Object.keys(attachments)[0]]['name'];
log.info(firstAttachmentName);
var assign = require(’/lib/assign’);
var contentLib = require(’/lib/xp/content’);
var httpClientLib = require(’/lib/xp/http-client’);
var portal = require(’/lib/xp/portal’);
var thymeleaf = require(’/lib/xp/thymeleaf’);
At the moment, nothing is extracted from attachments, but this will be implemented in 6.6
For attachments in general, an extraction algorithm will extract whats possible from the file and indexed as one separate field, e.g attachment.content or somthing similar. Normal content are indexed with keys and values since it is structured data.
So; a content with an attachment would look like:
name = 'my-attachment'
displayName = 'My Attachment
data.something = 'fisk'
attachment.content = 'once upon a time something something'
So, the thing I think you would like would require the data to be parsed as a structured document first, meaning:
-> fixed format and special handling of the data given (e.g a special content type)
-> transforming to a structured document
-> normal, automatic indexing of document properties