How to use <?choose:?> inside image url function in BI Publisher template - bi-publisher

I'm totally new at BI Publisher and XML templates. I'm trying to update a template to add the logo for a new company/organization. The same templates will be used for 3 separate branches/organizations within JD Edwards.
I'm having trouble trying to conditionally set the url code in the alt text of the dummy image. I think it's because the interpreter can't understand having a <?choose:?> tag inside the url{} definition? How can I use a choose function to return the proper string to the url{} definition?

Two options:
Concatenation:
Just concatenate the source location of your image with an XML variable that holds the brand name.
url:{concat('/folder1/folder2/',BRANCH_NAME_XML_ELEMENT,'_LOGO.JPG')}
Assuming your BRANCH_NAME_XML_ELEMENT is WALMART it will then load the image: /folder1/folder2/WALMART_LOGO.JPG
IF Statements
Make three different dummy images. Each with their respective URL for the logo. Then put each image within an if/end if statement. Will make things look like hell in the RTF file, but it will functionally work when everything is rendered.

Related

How can I implement multiple material colours across multiple .JSON files

I have a MASTER.JSON file that is my main part, I then have multiple parts that DOCK into the MASTER part, each of these parts is called as a SUBCOMPONENT and is in it's own .JSON file, for example have a SUB_CUBBY.JSON, SUB_SHELF.JSON etc. The subcomponents have Material Colours set with in their JSON files, which works fine but we periodically need to add additional colours, which at the moment means opening each subcomponent file and updating the Material / Colour and resaving. Is there a way to have a Global File that contains the Material / Colours that can be CALLED from within each of the subcomponent files, so I would only need to update the 1 file and it would add the colours to all the files??
There are two ways:
Store the material parameter in another component, called for example material_carrier, supersede the parameter wherever you need it.
Load materials not via validValues, but validGroups or conditionalGroups. This will allow you to add or remove parameter by tagging the materials with the respective tags. See very end of this page https://docs.roomle.com/scripting/resources/200_140_getmaterialproperty.html
Note: I recommend NOT referring to "docked parts" as subcomponents.

Duplicate Variable Definition Inside Choose Block

I think the code below should work in a Word BI Publisher template, but it's not. When I use the BI Publisher Template Viewer app to test, it is showing Duplicate variable 'branch' definition. If only the matching <?when: ...?> block should be executed, how is the variable defined more than once?
I have experience in other programming languages, but XML/XSL/BIP, etc. is new to me. Can anyone shed some light on the below code?
Thanks!
<?variable:payco; xdoxslt:trim(Remit_to_Name_ID445)?>
<?choose:?>
<?when: $payco=”Company1”?>
<?variable#begin:branch;'CO1'?>
<?end when?>
<?when: $payco=’Company2’?>
<?variable#begin:branch;'CO2'?>
<?end when?>
<?when: $payco=’Company3’?>
<?variable#begin:branch;'CO3'?>
<?end when?>
<?end choose?>
I can think of a few options to solve your logo problem.
Update the data definition SQL to do a decode/concatenation or something to get your logo filename or variable in the SQL as its own field that's extracted into the XML. That way you can use this when determining the image path:
url:{concat('/logos/',branch,'-logo.jpg')}
Use if statements or choose/when in your RTF to select an entire image section. This would mean you need to update the RTF every time you add a branch/brand, but it's doable.

Is there a method to display dynamic information to the user BEFORE a build?

Within the Jenkins UI, on the project page, you can use the Description Setter plugin to set a description AFTER a build. Is there any way to dynamically set this before a build? I would want to pull information from a file in the workspace that shows information about files that will be changed when the user builds the project.
Edit: While I haven't found a way to dynamically set the project description, I did find that I can create an Active Choices Reactive Reference Parameter, give it a descriptive name that serves as a title, and then read the contents of a file containing HTML with a Groovy script like so..
// The contents of the file should be HTML
String contents = new File('/tmp/some_file.html').text
return contents
So I made this my last parameter, and it shows the information that I need to show, before the end user clicks the build button. Solves my problem.
I'm going to leave this question open though, in case someone has a better idea.
While I haven't found a way to dynamically set the project description, I did find that I can create an Active Choices Reactive Reference Parameter (this requires the Active Choices plugin),
Give it a descriptive name that serves as a title, and then read the contents of a file containing HTML with a Groovy script like so..
// The contents of the file should be HTML
String contents = new File('/tmp/some_file.html').text
return contents
You will need to select a Choice Type of: Formatted HTML.
So I made this my last parameter, and it shows the information that I need to show, before the end user clicks the build button. Solves my problem.

Pre-/postprocessing of DSL edited with TMF-based editor

Given:
Some kind of DSL parsed with Xtext parser and then edited by user in TMF-based editor.
When user open file for editing I want first get access to the parse tree of just opened file, modify loaded file content in a some way and then provide to user modified source for editing.
When user wish to save file I again want to preprocess text representation based on actual parse tree and save such altered version.
Is there any Xtext/EMF API to implement such pre-/post- processing?
The goal is to add some content not presented in the physical file, allow user to edit this content and remove it before saving to file. This extra content should be stored separately from DSL source file.
If I understand your question correctly, you want to display additional information in the text editor itself (and not add additional information only to the EMF model, not to the text, for which IDerivedStateComputer could be used).
If the user is not supposed to edit the additional text, the "Code Mining" feature might be useful: https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#code-mining and https://blogs.itemis.com/en/code-mining-support-in-xtext
To answer the question itself:
Is there any Xtext/EMF API to implement such pre-/post- processing?
No, I am pretty sure there is no such Xtext API for pre-/post-processing files based on their own parse tree (EMF is irrelevant as you want to change the physical content). You could try to mess around with the XtextDocumentProvider (i.e. create your own subclass and register it in the UI module), but this is very likely to break the UI because the line numbers and offsets won't match.
You might have more luck implementing a custom Eclipse action that is executed on the original file and creates a temporary modified copy based on the parsed original file and then opens an editor for the temporary file. Then you could implement a IXtextBuilderParticipant that writes the result back to the original file on save (you have to register it using the org.eclipse.xtext.builder.participant extension point).
Another idea would be not to use an Eclipse action but a tabbed editor using MultiPageEditorPart, with the original as one of three tabs (the composite file and the 'additional info' file being the other two).
The goal is to add some content not presented in the physical file, allow user to edit this content and remove it before saving to file. This extra content should be stored separately from DSL source file.
Couldn't you present this information in another view similar to the 'Properties' view of EMF ? e.g. the user opens file, the Xtext editor opens as well as the 'Properties' view, which presents a way to edit these "extra" information. Upon save of either view, the Xtext save is called and your extra properties are serialized in their own model.

Rendering HTML in rails without actually displaying it

My current project requires me to assemble a .zip file containing HTML and text-only templates for a user to download, for importing into an email marketing program.
I've inherited this project, and currently the code uses a "fake" model (that is a model that does not directly correlate to a database table), in which it stores the entire template in a string, using dynamic variables to populate certain areas. The "fake" model then has a method for creating a zip file.
It seems to me that there has to be a better way to do this. I was wondering if there was a way to move the template into a .erb/haml file, and then write a method that would populate the file in preparation for being zipped up? Basically, is there a way to render an HTML and text file, without actually having to display them?
Thanks for any help.
Just write the action and view to render the html and text as normal then use the render_to_string method to assign the content to strings
http://apidock.com/rails/ActionController/Base/render_to_string
Then you can run the Model method (hopefully a Class method) to create the zip file using the content you now have in instance variables
Please have a look at the cells plugin.

Resources