Interleave In RNC - schema

I have source with three p with different attribute values, I tried to make arbitrary order of elements along with one mandatory element p class='paragraph1'. That is any number of paragraph1, paragraph2 and pharagraph3 in any order but there must be at least one paragraph1.
Below I tried the interleave option in RNC, but I failed with an error "the element "p" can occur in more than one operand of "interleave"" This is because the same element declared more than one time. But is this possible in RelaxNG using any other method?
Source
<body>
<h1 class="title">title</h1>
<h2 class="subtitle">subtitle</h2>
<p class="paragraph2">Para text 2</p>
<p class="paragraph1">para text 1</p>
<p class="paragraph3">Para text 2</p>
</body>
RNC
start = element body { h1?, h2?, (p.paragraph1+ & p.paragraph2? &
p.paragraph3?) }
h1 = element h1 { text & attribute class { string } }
h2 = element h2 { text & attribute class { string } }
p.paragraph1 = element p { text & attribute class { string "paragraph1" } }
p.paragraph2 = element p { text & attribute class { string "paragraph2" } }
p.paragraph3 = element p { text & attribute class { string "paragraph3" } }

Related

Do I need a property to bind server code to input events in Blazor?

Here's what I imagine I need:
<input type="text" #bind="this.ConceptSearch" #bind:event="oninput" />
#code {
private string _ConceptSearch = "";
private string ConceptSearch {
get {
return this._ConceptSearch;
}
set {
this._ConceptSearch = value;
this.PopulateSuggestions();
}
}
}
Is there a way to cut out the middle man (the property) and just directly call some code?
Using #onchange instead of #bind to solve it

Editor method of HtmlHelper class doesn't work with collections

In my view I have a model with a property Details of type List. The collection has 3 elements. Now I need to edit this list in a view.
If I use Html.EditorFor method passing the expression everything works correctly, But if I use Html.Editor method, the binding fails. By "fails" I mean that MVC uses the string editor for all fields (even if they are numbers) passing null as a model.
// this works correctly
#for (var i = 0; i < Model.Details.Count; i++)
{
<li>
#Html.EditorFor(m => m.Details[i].Name)
#Html.EditorFor(m => m.Details[i].Age)
</li>
}
// this doesn't work
#for (var i = 0; i < Model.Details.Count; i++)
{
<li>
#Html.Editor("Details[" + i +"].Name")
#Html.Editor("Details[" + i +"].Age")
</li>
}
I'm using ASP.NET Core 3.0 and didn't test this code against previous versions. For several reasons, I cannot use the EditorFor method so I'm stuck with this problem.
Any ideas?
Editor() HTML Helper method is for simple type view and EditorFor() HTML Helper method is for strongly type view to generate HTML elements based on the data type of the model object’s property.
The definition of Html.Editor:
// Summary:
// Returns HTML markup for the expression, using an editor template. The template
// is found using the expression's Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.
//
// Parameters:
// htmlHelper:
// The Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper instance this method extends.
//
// expression:
// Expression name, relative to the current model. May identify a single property
// or an System.Object that contains the properties to edit.
//
// Returns:
// A new Microsoft.AspNetCore.Html.IHtmlContent containing the <input> element(s).
//
// Remarks:
// For example the default System.Object editor template includes <label> and <input>
// elements for each property in the expression's value.
// Example expressions include string.Empty which identifies the current model and
// "prop" which identifies the current model's "prop" property.
// Custom templates are found under a EditorTemplates folder. The folder name is
// case-sensitive on case-sensitive file systems.
public static IHtmlContent Editor(this IHtmlHelper htmlHelper, string expression);
You could identify a single property for the expression of Editor Tag Helper like below :
#model MVC3_0.Models.Detail
<table>
<tr>
<td>Id</td>
<td>#Html.Editor("Id")</td>
</tr>
<tr>
<td>Name</td>
<td>#Html.Editor("Name")</td>
</tr>
<tr>
<td>Age</td>
<td>#Html.Editor("Age")</td>
</tr>
</table>
public IActionResult Index()
{
var model = new Detail { Id = 1, Name = "jack", Age = 12 };
return View(model);
}
Result:
There is a workaround that you could use TextBox or input instead
#for (var i = 0; i < Model.Details.Count; i++)
{
<li>
#Html.TextBox("Details[" + i + "].Name", Model.Details[i].Name, new { htmlAttributes = new { #class = "text-field" } })
#Html.TextBox("Details[" + i + "].Age", Model.Details[i].Age, new { htmlAttributes = new { #class = "text-field" } })
</li>
}
// input tag helper
#for (var i = 0; i < Model.Details.Count; i++)
{
<li>
<input asp-for="#Model.Details[i].Name" />
<input asp-for="#Model.Details[i].Age" />
</li>
}

what is "Dojo Name Text Box" onremove event?

I have a Dojo Name Text Box "xe:djextNameTextBox" on my form. By clicking [x] it removes a name from the list. How do I check what exact name was removed or clicked without parsing all values in getComponent("myNameBox").getValue()?
In my opinion the only way to handle this issue is to parse all values to get the information which name exactly was removed. I had to deal with the same problem in a previous project.
XPage
Set viewScope var "viewFiltersAsString":
<xp:this.beforeRenderResponse><![CDATA[#{javascript:log('beforerenderresponse (start rendering)');
requestScope.start = new Date().getTime();
viewScope.put('viewFiltersAsString', viewController.getViewFiltersAsString());
viewController.actionSetPage();}]]></xp:this.beforeRenderResponse>
Extension Library Dojo Name List Text Box control:
<xe:djextListTextBox id="djFilters" multipleSeparator=","
value="#{viewScope.viewFiltersAsString}" displayLabel="true"
title="Hier klicken um Filter zu löschen">
<xe:this.dataProvider>
<xe:simpleValuePicker caseInsensitive="false"
labelSeparator="~" valueListSeparator=","
valueList="#{viewController.viewFiltersLabelsAsString}">
</xe:simpleValuePicker>
</xe:this.dataProvider>
<xp:eventHandler event="onChange" submit="true" refreshMode="partial"
refreshId="${javascript:compositeData.refreshId}" execMode="partial"
action="#{javascript:viewController.setViewFiltersAsString(#Trim(viewScope.get('viewFiltersAsString')).toString())}">
</xp:eventHandler>
</xe:djextListTextBox>
Managed Bean "viewController"
/**
* Converts all filters to a useable format for dojo List Textbox
* #return string of filters
*/
public String getViewFiltersAsString() {
String filtersAsString = "";
for (ViewFilter filter : viewFilters) {
if (filtersAsString == "") filtersAsString = filter.getKey();
else filtersAsString += "," + filter.getKey();
}
return filtersAsString;
}
public void setViewFiltersAsString(String viewFiltersAsString) {
if (viewFiltersAsString != null && !viewFiltersAsString.equals("")) {
List<String> currentfilters = Converter.toList(",", viewFiltersAsString);
for (ViewFilter filter : viewFilters) {
boolean remove = true;
for (String currentFilter : currentfilters) {
if (filter.getKey().equals(currentFilter)) {
remove = false;
break;
}
}
if (remove) {
// user can click only one filter at one time
setActionViewFilter(viewFilters.removeFilter(filter));
break;
}
}
} else {
setActionViewFilter(viewFilters.removeFilter(viewFilters.get(0)));
}
}
Hint: viewFilters is a java.util.List of ViewFilter objects and a ViewFilter is a simple java class holding information about a filter (in your case a name)

How to remove a line with a particular content in docx4j

I want to delete a particular line in the docx if it has a particular word, say "killer".
How i can write a program using docx4j?
If i replace it with empty data, the line will be still there. I want to remove the whole line.
I tried something like this,
private void replacePlaceholders(WordprocessingMLPackage targetDocument,
String nameOfTheInvitedGuest) throws JAXBException {
List<Object> texts = targetDocument.getMainDocumentPart()
.getJAXBNodesViaXPath(XPATH_TO_SELECT_TEXT_NODES, true);
System.out.println(texts.size());
Iterator<Object> itr = texts.iterator();
while (itr.hasNext()) {
Object obj = itr.next();
Text text = (Text) ((JAXBElement) obj).getValue();
// System.out.println(text.getValue());
if (text.getValue().contains("Hulk Hogan")) {
itr.remove();
}
else {
String textValue = replacePlaceholderOfInvitedGuestWithGivenName(
nameOfTheInvitedGuest, text.getValue());
for (Object key : templateProperties.keySet()) {
textValue = textValue.replaceAll("\\$\\{" + key + "\\}",
(String) templateProperties.get(key));
}
text.setValue(textValue);
}
}
System.out.println(texts.size());
}
But its still showing in the docx file.
A Text element in a docx file has parent elements. The text will reside within a Run which in turn will sit within a block element like a paragraph (P node) or a table cell. If you're looking to remove a particular block element based on its textual content, once you've located the relevant text elements, you need to move up the parent elements, and remove them too -- for example, if the ultimate parent is a paragraph node, remove that.
If say, a paragraph displays as 3 lines in Word and you are trying to remove the 2nd line in that paragraph, then you have a different and more challenging problem.
maybe this will help futur people :
if(((org.docx4j.wml.Text) o2).getValue().contains("WhatYouWant")) {
// if your text contains "WhatYouWant" then...
Object o4 =((org.docx4j.wml.Text)o2).getParent();
//gets R
Object o5 = ((org.docx4j.wml.R) o4).getParent();
// gets P
Object o6 = ((org.docx4j.wml.P) o5).getParent();
// gets SdtElement
((List<List<Object>>) o6).remove(o5);
// now you remove your P (paragraph)
}
I had a content control (SdtElement) but I needed to put it in List < List < Object > > don't really know why but.... You might have something else so check in your document.xml before copy/pasting this.
This is for others who have a hard time, like I did to understand docx4j
You could use Apache POI to remove Text from docx file as shown below.
public static void removeTextFromDocx(FileInputStream inpudocxfile, String stringToBeReplaced,
String stringToBeReplacedWith, FileOutputStream outputdocxfile) {
XWPFDocument document = null;
try {
//loading docx file
document = new XWPFDocument(inpudocxfile);
for (XWPFParagraph paragraph : document.getParagraphs()) {
List<XWPFRun> runs = paragraph.getRuns();
for (XWPFRun run : runs) {
//reading an entire paragraph. So size of list is 1 and index of first element is 0
String text = run.getText(0);
if (text != null) {
if (text.contains(stringToBeReplaced)) {
text = text.replace(stringToBeReplaced, stringToBeReplacedWith);
text = text.trim();
run.setText(text, 0);
}
}
}
}
for (XWPFTable table : document.getTables()) {
for (XWPFTableRow row : table.getRows()) {
for (XWPFTableCell cell : row.getTableCells()) {
for (XWPFParagraph paragraph : cell.getParagraphs()) {
for (XWPFRun run : paragraph.getRuns()) {
String text = run.getText(0);
if (text != null) {
if (text.contains(stringToBeReplaced)) {
text = text.replace(stringToBeReplaced, stringToBeReplacedWith);
text = text.trim();
run.setText(text, 0);
}
}
}
}
}
}
}
document.write(outputdocxfile);
} catch (IOException e) {
LOGGER.error("Could not create outputdocxFile --> IOEXception" + e);
}
}

Less CSS: & reverse parent with multiple classes?

This is the first time I'm finding the & parent selector extremely useful so that I don't need to redefine parents simply to modify a child element.
Of course this is actually easy with LESS, but I have to ask!
<div id="skrollr-body" class="nonav">
<div class="skrollable">
</div>
</div>
#skroller-body {
.skrollable {
margin-top:40px;
.nonav & {
// this parent selector lets me modify
// .skrollable without duplicating it
margin-top:0px;
}
}
}
The output of .nonav & is
.nonav #skroller-body .skrollable
I'm wondering if I can get #skroller-body.nonav .skrollable instead somehow without extra HTML markup (a wrapper div.nonav)?
Currently I'll just duplicate the parent
#skrollr-body {
margin-top:40px;
left:0;
width:100%;
.skrollable {
margin-top:40px;
position:fixed;
z-index:100;
.skrollable {
position:absolute;
.skrollable {
position:static;
}
}
}
&.nonav {
.skrollable {
margin-top:0px;
}
}
}
Or to save redundant output;
#skroller-body.nonav .scrollable { margin-top:0px; }
But the whole point here is CSS code that's easy to maintain and read.
The docs tell us:
The & operator represents the parent selectors of a nested rule and
is most commonly used when applying a modifying class or pseudo-class
to an existing selector
So:
#skroller-body {
&.nonav {
.skrollable {
// stuff
}
}
}
}