Skip to content

Commit 3692a6f

Browse files
committed
WA-6194: Add sample for computed values
1 parent 59c54c0 commit 3692a6f

File tree

10 files changed

+467
-0
lines changed

10 files changed

+467
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Web Author Table Computed Values
2+
================================
3+
4+
Plugin that allows you to add automatically-computed values in a table cell.
5+
6+
Demo
7+
----
8+
9+
You can see a demo of this plugin in action in the [sample document](./samples/elections.dita):
10+
11+
![Demo](./samples/elections.gif)
12+
13+
[Try it yourself](https://www.oxygenxml.com/oxygen-xml-web-author/app/oxygen.html?url=gitgh%3A%2F%2Fhttps%253A%252F%252Fgithub.com%252Foxygenxml%252Fweb-author-sample-plugins%2Fmaster%2Fweb-author-table-cell-formulas%2Fsamples%2Felections.dita)
14+
15+
16+
Usage
17+
-----
18+
19+
Once you installed the plugin, to add such a computed value, add the following processing-instruction in the XML source:
20+
21+
<?computed-value formula="[some-xpath-expression]"?>
22+
23+
The XPath formula is resolved relative to the processing-instruction. The example below, computes the sum of all cells
24+
in the column where the processing-instruction is located (it assumes that the cell that contains the PI does not have
25+
other content than the PI):
26+
27+
let
28+
$cell := ./ancestor-or-self::stentry,
29+
$table := ./ancestor-or-self::simpletable,
30+
$column := count(./ancestor-or-self::stentry/preceding-sibling::*) + 1
31+
return sum($table/strow/stentry[$column][text() != ''])
32+
33+
To make it easy to add such a processing-instruction, you can
34+
[configure a toolbar button](https://www.oxygenxml.com/doc/versions/25.0.0/ug-waCustom/topics/wa_inserting_xml_elements.html#wa_inserting_xml_elements__section_bzb_vsy_dlb)
35+
to insert it.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!-- This is an assembly file used for all the sample plugins. -->
2+
3+
<assembly
4+
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
7+
<id>plugin</id>
8+
<formats>
9+
<format>jar</format>
10+
</formats>
11+
12+
<fileSets>
13+
<fileSet>
14+
<directory>web</directory>
15+
<outputDirectory>web</outputDirectory>
16+
<includes>
17+
<include>**/*</include>
18+
</includes>
19+
</fileSet>
20+
21+
<fileSet>
22+
<directory>target/lib</directory>
23+
<outputDirectory>lib</outputDirectory>
24+
<includes>
25+
<include>**/*</include>
26+
</includes>
27+
</fileSet>
28+
</fileSets>
29+
30+
<files>
31+
<file>
32+
<source>target/build/${project.build.finalName}.jar</source>
33+
<outputDirectory>lib</outputDirectory>
34+
</file>
35+
<file>
36+
<source>plugin.xml</source>
37+
<filtered>true</filtered>
38+
</file>
39+
</files>
40+
41+
</assembly>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@namespace oxy url('http://www.oxygenxml.com/extensions/author');
2+
3+
oxy|processing-instruction[computed-value] {
4+
visibility: -oxy-collapse-text;
5+
color: black !important;
6+
-oxy-editable: false;
7+
}
8+
oxy|processing-instruction[computed-value]:before {
9+
content: oxy_xpath(attr(formula));
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This folder was added here to be easier to download the plugin, although it is not best practice to commit JAR files in the Git repo.
2+
3+
If the Java code is modified, the JAR needs to be updated.
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE plugin SYSTEM "../plugin.dtd">
2+
3+
<plugin class="ro.sync.exml.plugin.Plugin"
4+
id="table-cell-computed-values"
5+
name="Table Cell Computed Values"
6+
description="Plugin that allows the user to use auto-computed values in a table cell."
7+
version="1.0"
8+
vendor="Syncro Soft">
9+
10+
<runtime>
11+
<librariesFolder name="lib"/>
12+
<library name="target/classes"/>
13+
<librariesFolder name="target/lib"/>
14+
</runtime>
15+
<extension type="WorkspaceAccess"
16+
class="com.oxygenxml.webapp.plugins.table.cell.formula.FormulaRefresherInstaller"/>
17+
<extension type="AuthorStylesheet" href="formulas.css"/>
18+
</plugin>
19+
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.oxygenxml.webapp.plugins.table.cell.formula</groupId>
8+
<artifactId>web-author-table-computed-values</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<oxygen.sdk.version>24.1.0.0</oxygen.sdk.version>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
<maven.compiler.target>1.8</maven.compiler.target>
15+
<maven.compiler.source>1.8</maven.compiler.source>
16+
</properties>
17+
18+
<repositories>
19+
<repository>
20+
<id>oxygenxml</id>
21+
<name>Oxygenxml Maven Repository</name>
22+
<url>https://oxygenxml.com/maven/</url>
23+
<releases>
24+
<enabled>true</enabled>
25+
</releases>
26+
<snapshots>
27+
<enabled>false</enabled>
28+
</snapshots>
29+
</repository>
30+
</repositories>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>com.oxygenxml</groupId>
35+
<artifactId>oxygen-sdk</artifactId>
36+
<version>${oxygen.sdk.version}</version>
37+
<scope>provided</scope>
38+
</dependency>
39+
</dependencies>
40+
41+
<build>
42+
<finalName>${project.artifactId}</finalName>
43+
<plugins>
44+
<plugin>
45+
<groupId>org.codehaus.mojo</groupId>
46+
<artifactId>build-helper-maven-plugin</artifactId>
47+
<version>1.10</version>
48+
<executions>
49+
<execution>
50+
<id>set-nosnapshot-version-property</id>
51+
<goals>
52+
<goal>regex-property</goal>
53+
</goals>
54+
<configuration>
55+
<name>project.nosnapshot.version</name>
56+
<value>${project.version}</value>
57+
<regex>-SNAPSHOT</regex>
58+
<replacement></replacement>
59+
<failIfNoMatch>false</failIfNoMatch>
60+
</configuration>
61+
</execution>
62+
</executions>
63+
</plugin>
64+
<plugin>
65+
<artifactId>maven-dependency-plugin</artifactId>
66+
<version>2.8</version>
67+
<executions>
68+
<execution>
69+
<phase>generate-resources</phase>
70+
<goals>
71+
<goal>copy-dependencies</goal>
72+
</goals>
73+
<configuration>
74+
<outputDirectory>${project.build.directory}/lib</outputDirectory>
75+
<includeScope>runtime</includeScope>
76+
</configuration>
77+
</execution>
78+
</executions>
79+
</plugin>
80+
<plugin>
81+
<groupId>org.apache.maven.plugins</groupId>
82+
<artifactId>maven-jar-plugin</artifactId>
83+
<version>2.2</version>
84+
<configuration>
85+
<!-- We only want the final JAR package in the target folder so that it's easier for users to identify it.-->
86+
<outputDirectory>${project.build.directory}/build</outputDirectory>
87+
</configuration>
88+
</plugin>
89+
90+
<plugin>
91+
<groupId>org.apache.maven.plugins</groupId>
92+
<artifactId>maven-assembly-plugin</artifactId>
93+
<version>2.6</version>
94+
<executions>
95+
<execution>
96+
<id>make-assembly</id>
97+
<phase>package</phase>
98+
<goals>
99+
<goal>single</goal>
100+
</goals>
101+
<configuration>
102+
<archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
103+
<descriptors>
104+
<descriptor>assembly.xml</descriptor>
105+
</descriptors>
106+
</configuration>
107+
</execution>
108+
</executions>
109+
</plugin>
110+
</plugins>
111+
112+
<pluginManagement>
113+
<plugins>
114+
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
115+
<plugin>
116+
<groupId>org.eclipse.m2e</groupId>
117+
<artifactId>lifecycle-mapping</artifactId>
118+
<version>1.0.0</version>
119+
<configuration>
120+
<lifecycleMappingMetadata>
121+
<pluginExecutions>
122+
<pluginExecution>
123+
<pluginExecutionFilter>
124+
<groupId>org.codehaus.mojo</groupId>
125+
<artifactId>
126+
build-helper-maven-plugin
127+
</artifactId>
128+
<versionRange>[1.10,)</versionRange>
129+
<goals>
130+
<goal>regex-property</goal>
131+
</goals>
132+
</pluginExecutionFilter>
133+
<action>
134+
<ignore></ignore>
135+
</action>
136+
</pluginExecution>
137+
</pluginExecutions>
138+
</lifecycleMappingMetadata>
139+
</configuration>
140+
</plugin>
141+
</plugins>
142+
</pluginManagement>
143+
</build>
144+
</project>
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
3+
<topic id="lilac">
4+
<title>Mexican election tables</title>
5+
<body>
6+
<section id="section_aq2_1j2_jwb">
7+
<title>Election, 1 July 2018</title>
8+
<p>
9+
<simpletable relcolwidth="1* 1*" id="simpletable_pbf_mf2_jwb">
10+
<sthead>
11+
<stentry>Party</stentry>
12+
<stentry>Seats</stentry>
13+
</sthead>
14+
<strow>
15+
<stentry>MORENA</stentry>
16+
<stentry>55</stentry>
17+
</strow>
18+
<strow>
19+
<stentry>PAN</stentry>
20+
<stentry>23</stentry>
21+
</strow>
22+
<strow>
23+
<stentry>PRI</stentry>
24+
<stentry>14</stentry>
25+
</strow>
26+
<strow>
27+
<stentry>PRD</stentry>
28+
<stentry>8</stentry>
29+
</strow>
30+
<strow>
31+
<stentry>PES</stentry>
32+
<stentry>8</stentry>
33+
</strow>
34+
<strow>
35+
<stentry>MC</stentry>
36+
<stentry>7</stentry>
37+
</strow>
38+
<strow>
39+
<stentry>PVEM</stentry>
40+
<stentry>6</stentry>
41+
</strow>
42+
<strow>
43+
<stentry>PT</stentry>
44+
<stentry>6</stentry>
45+
</strow>
46+
<strow>
47+
<stentry>PANAL</stentry>
48+
<stentry>1</stentry>
49+
</strow>
50+
<strow>
51+
<stentry><b>Total</b></stentry>
52+
<stentry><?computed-value formula="
53+
let $cell := ./ancestor-or-self::stentry,
54+
$table := ./ancestor-or-self::simpletable,
55+
$column := count(./ancestor-or-self::stentry/preceding-sibling::*) + 1
56+
return sum($table/strow/stentry[$column][text() != ''])"?></stentry>
57+
</strow>
58+
</simpletable>
59+
</p>
60+
<p>Source: <xref href="https://en.wikipedia.org/wiki/2018_Mexican_general_election" format="html"
61+
scope="external">https://en.wikipedia.org/wiki/2018_Mexican_general_election</xref></p>
62+
</section>
63+
<section id="section_mjj_y32_jwb">
64+
<title>Election, 6 June 2021</title>
65+
<p>
66+
<simpletable relcolwidth="1* 1*" id="simpletable_khy_q32_jwb">
67+
<sthead>
68+
<stentry>Party</stentry>
69+
<stentry>Seats</stentry>
70+
</sthead>
71+
<strow>
72+
<stentry>MORENA</stentry>
73+
<stentry>198</stentry>
74+
</strow>
75+
<strow>
76+
<stentry>PAN</stentry>
77+
<stentry>114</stentry>
78+
</strow>
79+
<strow>
80+
<stentry>PRI</stentry>
81+
<stentry>70</stentry>
82+
</strow>
83+
<strow>
84+
<stentry>PVEM</stentry>
85+
<stentry>43</stentry>
86+
</strow>
87+
<strow>
88+
<stentry>PT</stentry>
89+
<stentry>37</stentry>
90+
</strow>
91+
<strow>
92+
<stentry>MC</stentry>
93+
<stentry>23</stentry>
94+
</strow>
95+
<strow>
96+
<stentry>PRD</stentry>
97+
<stentry>15</stentry>
98+
</strow>
99+
<strow>
100+
<stentry><b>Total</b></stentry>
101+
<stentry><?computed-value formula="
102+
let $cell := ./ancestor-or-self::stentry,
103+
$table := ./ancestor-or-self::simpletable,
104+
$column := count(./ancestor-or-self::stentry/preceding-sibling::*) + 1
105+
return sum($table/strow/stentry[$column][text() != ''])"?></stentry>
106+
</strow>
107+
</simpletable>
108+
</p>
109+
<p>Source: <xref href="https://en.wikipedia.org/wiki/2021_Mexican_legislative_election"
110+
format="html" scope="external"
111+
>https://en.wikipedia.org/wiki/2021_Mexican_legislative_election</xref></p>
112+
</section>
113+
</body>
114+
</topic>

0 commit comments

Comments
 (0)