RelaxNG choice and regular expression - relaxng

I have a RelaxNG based XML instance which should allow (choice) align="right", align="left" and align="{ anything here }". The right/left is easy:
attribute name="align">
<a:documentation>doc for attrib</a:documentation>
<choice>
<value>left</value>
<a:documentation>doc for left</a:documentation>
<value>right</value>
<a:documentation>doc for right</a:documentation>
</choice>
</attribute>
But how can I allow the user to enter { ... } as an alternative to the two values above?

You need to use the XML Schema string type and set a pattern on it. Here's an example:
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<start>
<element name="top">
<oneOrMore>
<element name="foo">
<attribute name="align">
<choice>
<value>left</value>
<value>right</value>
<data type="string">
<param name="pattern">\{.+\}</param>
</data>
</choice>
</attribute>
</element>
</oneOrMore>
</element>
</start>
</grammar>
And a test file:
<top>
<!-- valid cases -->
<foo align="{fasf}"></foo>
<foo align="left"></foo>
<foo align="right"></foo>
<!-- invalid cases -->
<foo align="fasf"></foo>
<foo align="{}"></foo>
<foo align="a{c}b"></foo>
</top>
Note the comments that delimit valid and invalid cases.
The regular expression I used allows things like align="{ab{c}d}". Curly braces are valid inside the curly braces that start and end the attribute value. I've not see any reason to disallow it.

Related

Bind Custom Properties to LoggingEvent Object in Log4Net

I am using log4net and I am trying to figure out the best way, or if there is anyway, to bind custom fields to the LoggingEvent object, that is used in the Append override method of the AppenderSkeleton.
For example, this could be a guid property to add to the other properties such as level, renderedMessage, etc.
However, I am planning on using the Log4net.Appenders.Fluentd with the log4net.Ext.Json, so the appender in the xml would look something like this:
<appender name="Fluentd" type="Log4net.Appenders.Fluentd.FluentdAppender, Log4net.Appenders.Fluentd">
<Host>127.0.0.1</Host>
<Port>24224</Port>
<Tag>YourTagHere</Tag>
<NoDelay>false</NoDelay>
<ReceiveBufferSize>8192</ReceiveBufferSize>
<SendBufferSize>8192</SendBufferSize>
<SendTimeout>1000</SendTimeout>
<ReceiveTimeout>1000</ReceiveTimeout>
<LingerEnabled>true</LingerEnabled>
<LingerTime>1000</LingerTime>
<EmitStackTraceWhenAvailable>true</EmitStackTraceWhenAvailable>
<IncludeAllProperties>false</IncludeAllProperties>
<!--json formatted log4net logging-->
<layout type="log4net.Layout.SerializedLayout, log4net.Ext.Json">
<decorator type="log4net.Layout.Decorators.StandardTypesDecorator, log4net.Ext.Json" />
<member value="date:date" />
<member value="level:level" />
<member value="message:messageObject" />
</layout>
</appender>
I was hoping there would be something like this in the end:
<!--json formatted log4net logging-->
<layout type="log4net.Layout.SerializedLayout, log4net.Ext.Json">
<decorator type="log4net.Layout.Decorators.StandardTypesDecorator, log4net.Ext.Json" />
<member value="date:date" />
<member value="level:level" />
<member value="message:messageObject" />
<member value="guid:guid" />
</layout>
Is this something I would have to some how carry out in the Log4net.Appenders.Fluentd source code?
You can use the ThreadContext to add a custom property to the LoggingEvent object that is passed into the Append override method of the AppenderSkeleton and the Format override method of the LayoutSkeleton.
Set it:
ThreadContext.Properties["my_custom_prop"] = "my custom property"
Then retrieve it:
var prop = evt.GetProperties()["my_custom_prop"].ToString();

Graph tool GraphML support for coloured vertices?

I am trying to use graph-tool to graph a network graph with coloured vertices. I am trying to graph the following graphML file from here shown below.
However, the colour are not showing with the following code:
g = Graph()
g= load_graph("filename.graphml", fmt="graphml")
graph_draw(g)
The graph renders but there are no colours on vertices, only for default red. I thought that graphML was fully supported?
Graph-tool docs states: "The only file formats which are capable of perfectly preserving the internal property maps are “gt” and “graphml”. Because of this, they should be preferred over the other formats whenever possible."
Is colour not an internal property?
Oringinally I was graphing in DOT. I have an array of colours the index of which depends on name of the node - the nodes are integers in increasing order. However, when I was using:
for v in g.vertices():
v_prop[v] = colourarray[vertex]
The colours did not correspond to the correct node. This is due to the fact the load_graph seems to have its own idea of which nodes are which index. Does any one have an idea of what I can do here?
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<key id="d0" for="node" attr.name="color" attr.type="string">
<default>yellow</default>
</key>
<key id="d1" for="edge" attr.name="weight" attr.type="double"/>
<graph id="G" edgedefault="undirected">
<node id="n0">
<data key="d0">green</data>
</node>
<node id="n1"/>
<node id="n2">
<data key="d0">blue</data>
</node>
<node id="n3">
<data key="d0">red</data>
</node>
<node id="n4"/>
<node id="n5">
<data key="d0">turquoise</data>
</node>
<edge id="e0" source="n0" target="n2">
<data key="d1">1.0</data>
</edge>
<edge id="e1" source="n0" target="n1">
<data key="d1">1.0</data>
</edge>
<edge id="e2" source="n1" target="n3">
<data key="d1">2.0</data>
</edge>
<edge id="e3" source="n3" target="n2"/>
<edge id="e4" source="n2" target="n4"/>
<edge id="e5" source="n3" target="n5"/>
<edge id="e6" source="n5" target="n4">
<data key="d1">1.1</data>
</edge>
</graph>
</graphml>
You are conflating the existence of a property map with it actually being used for drawing. If you want to use a property map, you have to do so explicitly:
graph_draw(g, vertex_fill_color=g.vp.color)
Please take a look at the documentation, which contains many examples of this kind.
The inherent vertex "names" that exist in dot and graphml files are loaded as internal property maps. In the case of dot, the property map is named "vertex_name":
g.vp.vertex_name
in the case of graphml, if the vertex label is not canonical (i.e. numbered from 0 to N-1), it is stored as "_graphml_vertex_id":
g.vp._graphml_vertex_id

How can I configure a live template that generates a builder method in IntelliJ IDEA?

I oftentimes need to create builder methods in my code. These methods are similar to getters, but they return this and they use with instead of get.
To be faster with that task I'd like to create a live-template in IDEA.
This how far I got:
(in ~/.IntelliJIdea14/config/templates/user.xml this looks like this:)
<template name="builderMethod" value="public $CLASS_NAME$ with$VAR_GET$(final $TYPE$ $PARAM_NAME$) {
this.$VAR$ = $PARAM_NAME$;
return this;
}" description="create a builder method" toReformat="true" toShortenFQNames="true">
<variable name="CLASS_NAME" expression="className()" defaultValue="" alwaysStopAt="true" />
<variable name="VAR" expression="complete()" defaultValue="" alwaysStopAt="true" />
<variable name="PARAM_NAME" expression="VAR" defaultValue="" alwaysStopAt="true" />
<variable name="TYPE" expression="typeOfVariable("this." + VAR)" defaultValue="" alwaysStopAt="true" />
<variable name="VAR_GET" expression="capitalize(VAR)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_EXPRESSION" value="false" />
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
This nearly works, except for typeOfVariable("this." + VAR) which does not. I just guessed how to call this method, because I could not find any documentation on the syntax used in the expressions except for this page which does not even mention a script language name or something that would make googling for easier.
How do I fix the call to typeOfVariable?
Bonus question: How can I get complete() for VAR to only show fields?
Similar question but not does not even have a start: Live Template for Fluent-API Builder in IntelliJ
Replace typeOfVariable("this." + VAR) with typeOfVariable(VAR).
Edit:
Another way to generate builder methods is to use an appropriate setter template (instead of live template).
https://www.jetbrains.com/help/idea/2016.1/generate-setter-dialog.html
There is already a built-in setter template named "Builder" which generates setters such as:
public Foo setBar(int bar) {
this.bar = bar;
return this;
}
You can create your own template (e.g by copying it) and change it so that the method prefix is with.
And to make the generated method parameter final go to settings:
Editor | Code Style | Java
Select the Code Generation tab
Tick Make generated parameters final
IntelliJ IDEA add final to auto-generated setters

Creating fixed FCE with fluidcontent

Width this code i can define content:
<flux:flexform.section name="columns">
<flux:flexform.object name="column" label="column">
<flux:flexform.field.input name="demo" label="Demo field" />
</flux:flexform.object>
</flux:flexform.section>
<flux:flexform.grid>
<flux:flexform.grid.row>
<f:for each="{columns}" as="sectionObject" iteration="iteration">
<flux:flexform.grid.column>
<flux:flexform.content name="column{iteration.cycle}" label="Column {iteration.cycle}" />
</flux:flexform.grid.column>
</f:for>
</flux:flexform.grid.row>
</flux:flexform.grid>
This is flexible. I can Add new "Content Areas" through the section. But this is not what I want. I Want to define a very fixed two-column and a three-column FCE. My editor should not have to decide how many columns to use.
I am missing something like:
<flux:flexform.field.contentArea name="col1" label="Column 1" />
<flux:flexform.field.contentArea name="col2" label="Column 2" />
<flux:flexform.grid>
<flux:flexform.grid.row>
<flux:flexform.grid.column>
<flux:flexform.content name="col1" />
</flux:flexform.grid.column>
<flux:flexform.grid.column>
<flux:flexform.content name="col2" />
</flux:flexform.grid.column>
</flux:flexform.grid>
</flux:flexform.grid.row>
Thank you for your hint to the right direction.
You are very close to the solution with the code you already have. In this example I will use the new ViewHelper names - but you can get the same result using the old names as in your example. Which is which, should be easy to spot (note: you had a typo in your code example which I edited, rgid used instead of grid - such a typo would cause Flux to error out):
<flux:grid>
<flux:grid.row>
<flux:grid.column>
<flux:content name="col1" label="Nice name for column 1" />
</flux:grid.column>
<flux:grid.column>
<flux:content name="col2" label="Column 2" />
</flux:grid.column>
</flux:grid>
</flux:grid.row>
And remove the flux:form.section with object inside it - you don't need this when you make a statically defined grid.
Then to render this grid:
<flux:content.render area="col1" /> and so on.

VXML: Field input, forward typing

Situation:
I have two VXML documents that are part of one flow. In the first document the user is prompted to enter a number (dtmf, max = 3 digits). The second document prompts the user to enter another number (dtmf, max = 10 digits).
Problem:
When the user is prompted to enter the first number and he enters 4 digits (e.g. 1234), the last number (4) is used as input for the second field.
Expected:
The last number must be ignored. I expect that a "nomatch" event is thrown because I define that the maxlength = 3.
Document 1:
<form>
<field name="input1" type="digits?minlength=1;maxlength=3">
<audio src="prompt1"/>
<filled>
<submit next="next.jsp" namelist="input1" />
</filled>
</field>
Document 2:
<form>
<field name="input2" type="digits?minlength=1;maxlength=10">
<audio src="prompt2"/>
<filled>
<submit next="next2.jsp" namelist="input2" />
</filled>
</field>
Question:
How can I solve this issue in VXML?
Try to set "termtimeout" property.
It means "The terminating timeout to use when recognizing DTMF input."
For example
<?xml version="1.0" encoding="UTF-8"?>
<vxml version="2.1">
<form>
<property name="termtimeout" value="0s" />
<field name="input1" type="digits?minlength=1;maxlength=3">
<filled>
<submit next="next.jsp" namelist="input1" />
</filled>
</field>
</form>
</vxml>