finished, tested and fixed initial impl

This commit is contained in:
Brian Long 2022-03-28 20:05:46 +01:00
parent 0541cf502b
commit 3d353cf6d5
20 changed files with 223 additions and 181 deletions

View File

@ -41,7 +41,7 @@
<dependency> <dependency>
<groupId>com.inteligr8.alfresco</groupId> <groupId>com.inteligr8.alfresco</groupId>
<artifactId>aps-public-rest-api</artifactId> <artifactId>aps-public-rest-api</artifactId>
<version>1.2.0</version> <version>1.2.1</version>
<classifier>aps1</classifier> <classifier>aps1</classifier>
</dependency> </dependency>
<dependency> <dependency>
@ -216,8 +216,7 @@
<properties> <properties>
<aps-model.baseUrl>${aps-model.baseUrl}</aps-model.baseUrl> <aps-model.baseUrl>${aps-model.baseUrl}</aps-model.baseUrl>
<aps-model.authType>${aps-model.authType}</aps-model.authType> <aps-model.authType>${aps-model.authType}</aps-model.authType>
<aps-model.basicAuth.username>${aps-model.basicAuth.username}</aps-model.basicAuth.username> <aps-model.basicAuth.mavenServerId>${aps-model.basicAuth.mavenServerId}</aps-model.basicAuth.mavenServerId>
<aps-model.basicAuth.password>${aps-model.basicAuth.password}</aps-model.basicAuth.password>
<aps-model.appName>${aps-model.appName}</aps-model.appName> <aps-model.appName>${aps-model.appName}</aps-model.appName>
</properties> </properties>
<pomIncludes> <pomIncludes>

View File

@ -12,10 +12,6 @@
<name>Deploy App Plugin Tests</name> <name>Deploy App Plugin Tests</name>
<properties>
<aps.app>FORMS Core</aps.app>
</properties>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
@ -24,14 +20,46 @@
<version>@pom.version@</version> <version>@pom.version@</version>
<executions> <executions>
<execution> <execution>
<id>download-app</id> <id>download-unpack-app</id>
<phase>validate</phase> <phase>generate-sources</phase>
<goals> <goals>
<goal>download-app</goal> <goal>download-app</goal>
<goal>unpack-app</goal>
</goals>
<configuration>
<reformat>true</reformat>
<normalize>true</normalize>
</configuration>
</execution>
<execution>
<id>translate-app</id>
<phase>compile</phase>
<goals>
<goal>translate-app</goal>
</goals>
<configuration>
<finalDirectory>${project.build.directory}/aps-dev</finalDirectory>
</configuration>
</execution>
<execution>
<id>pack-app</id>
<phase>package</phase>
<goals>
<goal>pack-app</goal>
</goals>
<configuration>
<unzipDirectory>${project.build.directory}/aps-dev</unzipDirectory>
<zipDirectory>${project.build.directory}/aps-test</zipDirectory>
</configuration>
</execution>
<execution>
<id>deploy-app</id>
<phase>package</phase>
<goals>
<goal>deploy-app</goal> <goal>deploy-app</goal>
</goals> </goals>
<configuration> <configuration>
<apsAppName>${aps.app}</apsAppName> <zipDirectory>${project.build.directory}/aps-test</zipDirectory>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>

View File

@ -21,14 +21,14 @@
<executions> <executions>
<execution> <execution>
<id>download-app</id> <id>download-app</id>
<phase>validate</phase> <phase>generate-sources</phase>
<goals> <goals>
<goal>download-app</goal> <goal>download-app</goal>
</goals> </goals>
</execution> </execution>
<execution> <execution>
<id>download-app-other</id> <id>download-app-other</id>
<phase>validate</phase> <phase>generate-sources</phase>
<goals> <goals>
<goal>download-app</goal> <goal>download-app</goal>
</goals> </goals>

View File

@ -12,10 +12,6 @@
<name>Pack App Plugin Tests</name> <name>Pack App Plugin Tests</name>
<properties>
<aps.app>FORMS Core</aps.app>
</properties>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
@ -25,7 +21,7 @@
<executions> <executions>
<execution> <execution>
<id>download-unpack-app</id> <id>download-unpack-app</id>
<phase>validate</phase> <phase>generate-sources</phase>
<goals> <goals>
<goal>download-app</goal> <goal>download-app</goal>
<goal>unpack-app</goal> <goal>unpack-app</goal>
@ -36,11 +32,12 @@
</execution> </execution>
<execution> <execution>
<id>pack-app</id> <id>pack-app</id>
<phase>validate</phase> <phase>package</phase>
<goals> <goals>
<goal>pack-app</goal> <goal>pack-app</goal>
</goals> </goals>
<configuration> <configuration>
<zipDirectory>${basedir}</zipDirectory>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
@ -56,7 +53,7 @@
<rules> <rules>
<requireFilesExist> <requireFilesExist>
<files> <files>
<file>${basedir}/src/main/app/${aps.app}.zip</file> <file>${basedir}/${aps-model.appName}.zip</file>
</files> </files>
</requireFilesExist> </requireFilesExist>
</rules> </rules>

View File

@ -21,7 +21,7 @@
<executions> <executions>
<execution> <execution>
<id>download-unpack-app</id> <id>download-unpack-app</id>
<phase>validate</phase> <phase>generate-sources</phase>
<goals> <goals>
<goal>download-app</goal> <goal>download-app</goal>
<goal>unpack-app</goal> <goal>unpack-app</goal>
@ -33,7 +33,7 @@
</execution> </execution>
<execution> <execution>
<id>translate-app</id> <id>translate-app</id>
<phase>validate</phase> <phase>compile</phase>
<goals> <goals>
<goal>translate-app</goal> <goal>translate-app</goal>
</goals> </goals>

View File

@ -21,7 +21,7 @@
<executions> <executions>
<execution> <execution>
<id>download-unpack-app</id> <id>download-unpack-app</id>
<phase>validate</phase> <phase>generate-sources</phase>
<goals> <goals>
<goal>download-app</goal> <goal>download-app</goal>
<goal>unpack-app</goal> <goal>unpack-app</goal>
@ -29,7 +29,7 @@
</execution> </execution>
<execution> <execution>
<id>unpack-app</id> <id>unpack-app</id>
<phase>validate</phase> <phase>process-sources</phase>
<goals> <goals>
<goal>unpack-app</goal> <goal>unpack-app</goal>
</goals> </goals>

View File

@ -1,6 +1,8 @@
package com.inteligr8.maven.aps.modeling.goal; package com.inteligr8.maven.aps.modeling.goal;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.settings.Server;
import com.inteligr8.alfresco.activiti.ApsClientConfiguration; import com.inteligr8.alfresco.activiti.ApsClientConfiguration;
import com.inteligr8.alfresco.activiti.ApsClientJerseyImpl; import com.inteligr8.alfresco.activiti.ApsClientJerseyImpl;
@ -8,32 +10,26 @@ import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
public abstract class ApsAddressibleGoal extends DisablableGoal { public abstract class ApsAddressibleGoal extends DisablableGoal {
@Parameter( defaultValue = "${session}", readonly = true )
protected MavenSession session;
@Parameter( property = "aps-model.baseUrl", required = true, defaultValue = "http://localhost:8080/activiti-app" ) @Parameter( property = "aps-model.baseUrl", required = true, defaultValue = "http://localhost:8080/activiti-app" )
protected String activitiAppBaseUrl; protected String activitiAppBaseUrl;
@Parameter( property = "aps-model.authType", required = true, defaultValue = "BASIC" ) @Parameter( property = "aps-model.authType", required = true, defaultValue = "BASIC" )
protected String activitiAppAuthType; protected String activitiAppAuthType;
@Parameter( property = "aps-model.basicAuth.username", required = false, defaultValue = "admin@app.activiti.com" ) @Parameter( property = "aps-model.basicAuth.mavenServerId", required = true, defaultValue = "aps" )
protected String activitiAppAuthBasicUsername; protected String activitiAppAuthBasicServerId;
@Parameter( property = "aps-model.basicAuth.password", required = false, defaultValue = "admin" )
protected String activitiAppAuthBasicPassword;
@Parameter( property = "aps-model.oauth.code", required = false ) @Parameter( property = "aps-model.oauth.code", required = false )
protected String oauthCode; protected String oauthCode;
@Parameter( property = "aps-model.oauth.clientId", required = false ) @Parameter( property = "aps-model.oauth.client.mavenServerId", required = false )
protected String oauthClientId; protected String oauthClientServerId;
@Parameter( property = "aps-model.oauth.clientSecret", required = false ) @Parameter( property = "aps-model.oauth.mavenServerId", required = false )
protected String oauthClientSecret; protected String oauthServerId;
@Parameter( property = "aps-model.oauth.username", required = false )
protected String oauthUsername;
@Parameter( property = "aps-model.oauth.password", required = false )
protected String oauthPassword;
@Parameter( property = "aps-model.oauth.tokenUrl", required = false ) @Parameter( property = "aps-model.oauth.tokenUrl", required = false )
protected String oauthTokenUrl; protected String oauthTokenUrl;
@ -47,21 +43,41 @@ public abstract class ApsAddressibleGoal extends DisablableGoal {
switch (this.activitiAppAuthType.toUpperCase()) { switch (this.activitiAppAuthType.toUpperCase()) {
case "BASIC": case "BASIC":
this.getLog().info("Configuring APS with BASIC authentication"); this.getLog().info("Configuring APS with BASIC authentication");
this.getLog().debug("Username: " + this.activitiAppAuthBasicUsername);
config.setBasicAuthUsername(this.activitiAppAuthBasicUsername); Server creds = this.session.getSettings().getServer(this.activitiAppAuthBasicServerId);
config.setBasicAuthPassword(this.activitiAppAuthBasicPassword); if (this.activitiAppAuthBasicServerId != null && creds == null)
this.getLog().warn("The Maven configuration has no server '" + this.activitiAppAuthBasicServerId + "'; continuing with default credentials");
if (creds != null) {
this.getLog().debug("Username: " + creds.getUsername());
config.setBasicAuthUsername(creds.getUsername());
config.setBasicAuthPassword(creds.getPassword());
}
break; break;
case "OAUTH": case "OAUTH":
this.getLog().info("Configuring APS with OAuth authentication"); this.getLog().info("Configuring APS with OAuth authentication");
Server clientCreds = this.session.getSettings().getServer(this.oauthClientServerId);
Server oauthCreds = this.session.getSettings().getServer(this.oauthServerId);
if ((this.oauthClientServerId != null || this.oauthServerId != null) && clientCreds == null && oauthCreds == null)
this.getLog().warn("The Maven configuration has no server '" + this.oauthClientServerId + "' or '" + this.oauthServerId + "'; continuing without credentials");
this.getLog().debug("OAuth Code: " + this.oauthCode); this.getLog().debug("OAuth Code: " + this.oauthCode);
this.getLog().debug("OAuth Client ID: " + this.oauthClientId);
this.getLog().debug("OAuth Username: " + this.oauthUsername);
config.setOAuthAuthCode(this.oauthCode); config.setOAuthAuthCode(this.oauthCode);
if (clientCreds != null) {
this.getLog().debug("OAuth Client ID: " + clientCreds.getUsername());
config.setOAuthClientId(clientCreds.getUsername());
config.setOAuthClientSecret(clientCreds.getPassword());
}
if (oauthCreds != null) {
this.getLog().debug("OAuth Username: " + oauthCreds.getUsername());
config.setOAuthUsername(oauthCreds.getUsername());
config.setOAuthPassword(oauthCreds.getPassword());
}
config.setOAuthTokenUrl(this.oauthTokenUrl); config.setOAuthTokenUrl(this.oauthTokenUrl);
config.setOAuthClientId(this.oauthClientId);
config.setOAuthClientSecret(this.oauthClientSecret);
config.setOAuthUsername(this.oauthUsername);
config.setOAuthPassword(this.oauthPassword);
break; break;
default: default:
throw new IllegalArgumentException("The 'activitiAppAuthType' configuration must be either 'Basic' or 'OAuth'"); throw new IllegalArgumentException("The 'activitiAppAuthType' configuration must be either 'Basic' or 'OAuth'");

View File

@ -5,12 +5,15 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import javax.ws.rs.core.MediaType;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataMultiPart;
import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart;
import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl; import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
import com.inteligr8.alfresco.activiti.model.AppDefinitionUpdateResultRepresentation; import com.inteligr8.alfresco.activiti.model.AppDefinitionUpdateResultRepresentation;
@ -19,13 +22,14 @@ import com.inteligr8.alfresco.activiti.model.AppDefinitionUpdateResultRepresenta
@Component( role = org.apache.maven.plugin.Mojo.class ) @Component( role = org.apache.maven.plugin.Mojo.class )
public class DeployAppGoal extends ApsAppAccessibleGoal { public class DeployAppGoal extends ApsAppAccessibleGoal {
@Parameter( property = "sourceDirectory", required = true, defaultValue = "${project.build.directory}/aps/app" ) @Parameter( property = "aps-model.upload.directory", required = true, defaultValue = "${project.build.directory}/aps" )
protected File sourceDirectory; protected File zipDirectory;
@Parameter( property = "publish", required = true, defaultValue = "false" ) @Parameter( property = "publish", required = true, defaultValue = "false" )
protected boolean publish = false; protected boolean publish = false;
protected final int bufferSize = 128 * 1024; protected final int bufferSize = 128 * 1024;
private final MediaType zipMediaType = MediaType.valueOf("application/zip");
@Override @Override
public void executeEnabled() throws MojoExecutionException, MojoFailureException { public void executeEnabled() throws MojoExecutionException, MojoFailureException {
@ -36,21 +40,21 @@ public class DeployAppGoal extends ApsAppAccessibleGoal {
try { try {
this.uploadApp(appId, sourceFile); this.uploadApp(appId, sourceFile);
} catch (IOException ie) { } catch (IOException ie) {
throw new MojoExecutionException("The downloaded APS App could not be unpacked", ie); throw new MojoExecutionException("The APS App could not be uploaded", ie);
} }
} }
protected File validateSourceDirectory() { protected File validateSourceDirectory() {
if (!this.sourceDirectory.exists()) { if (!this.zipDirectory.exists()) {
throw new IllegalStateException("The 'sourceDirectory' does not exist: " + this.sourceDirectory); throw new IllegalStateException("The 'zipDirectory' does not exist: " + this.zipDirectory);
} else if (!this.sourceDirectory.isDirectory()) { } else if (!this.zipDirectory.isDirectory()) {
throw new IllegalStateException("The 'sourceDirectory' is not a directory: " + this.sourceDirectory); throw new IllegalStateException("The 'zipDirectory' is not a directory: " + this.zipDirectory);
} }
File sourceFile = new File(this.sourceDirectory, this.apsAppName + ".zip"); File sourceFile = new File(this.zipDirectory, this.apsAppName + ".zip");
if (!sourceFile.exists()) { if (!sourceFile.exists()) {
throw new IllegalStateException("The App file does not exists in the 'sourceDirectory': " + sourceFile); throw new IllegalStateException("The App file does not exists in the 'zipDirectory': " + sourceFile);
} else if (!sourceFile.isFile()) { } else if (!sourceFile.isFile()) {
throw new IllegalStateException("The App file is not a file: " + sourceFile); throw new IllegalStateException("The App file is not a file: " + sourceFile);
} }
@ -61,33 +65,31 @@ public class DeployAppGoal extends ApsAppAccessibleGoal {
private void uploadApp(Long appId, File appZip) throws IOException, MojoExecutionException { private void uploadApp(Long appId, File appZip) throws IOException, MojoExecutionException {
ApsPublicRestApiJerseyImpl api = this.getApsApi(); ApsPublicRestApiJerseyImpl api = this.getApsApi();
FormDataContentDisposition cdisposition = FormDataContentDisposition.name("file")
.size(appZip.length())
.fileName(appZip.getName())
.build();
FileInputStream fistream = new FileInputStream(appZip); FileInputStream fistream = new FileInputStream(appZip);
BufferedInputStream bistream = new BufferedInputStream(fistream, this.bufferSize); BufferedInputStream bistream = new BufferedInputStream(fistream, this.bufferSize);
try { try {
FormDataMultiPart multipart = new FormDataMultiPart();
multipart.bodyPart(new StreamDataBodyPart("file", bistream, appZip.getName(), this.zipMediaType));
if (appId == null) { if (appId == null) {
if (this.publish) { if (this.publish) {
this.getLog().info("Uploading & publishing new APS App: " + this.apsAppName); this.getLog().info("Uploading & publishing new APS App: " + this.apsAppName);
AppDefinitionUpdateResultRepresentation appDefUpdate = api.getAppDefinitionsJerseyApi().publishApp(bistream, cdisposition); AppDefinitionUpdateResultRepresentation appDefUpdate = api.getAppDefinitionsJerseyApi().publishApp(multipart);
if (Boolean.TRUE.equals(appDefUpdate.getError())) if (Boolean.TRUE.equals(appDefUpdate.getError()))
throw new MojoExecutionException(appDefUpdate.getErrorDescription()); throw new MojoExecutionException(appDefUpdate.getErrorDescription());
} else { } else {
this.getLog().info("Uploading new APS App: " + this.apsAppName); this.getLog().info("Uploading new APS App: " + this.apsAppName);
api.getAppDefinitionsJerseyApi().import_(bistream, cdisposition); api.getAppDefinitionsJerseyApi().importApp(multipart, true);
} }
} else { } else {
if (this.publish) { if (this.publish) {
this.getLog().info("Uploading, versioning, & publishing APS App: " + this.apsAppName); this.getLog().info("Uploading, versioning, & publishing APS App: " + this.apsAppName + " (" + appId + ")");
AppDefinitionUpdateResultRepresentation appDefUpdate = api.getAppDefinitionsJerseyApi().publishApp(appId, bistream, cdisposition); AppDefinitionUpdateResultRepresentation appDefUpdate = api.getAppDefinitionsJerseyApi().publishApp(appId, multipart);
if (Boolean.TRUE.equals(appDefUpdate.getError())) if (Boolean.TRUE.equals(appDefUpdate.getError()))
throw new MojoExecutionException(appDefUpdate.getErrorDescription()); throw new MojoExecutionException(appDefUpdate.getErrorDescription());
} else { } else {
this.getLog().info("Uploading & versioning APS App: " + this.apsAppName); this.getLog().info("Uploading & versioning APS App: " + this.apsAppName + " (" + appId + ")");
api.getAppDefinitionsJerseyApi().import_(appId, bistream, cdisposition); api.getAppDefinitionsJerseyApi().importApp(appId, multipart, true);
} }
} }
} finally { } finally {

View File

@ -22,11 +22,11 @@ import org.codehaus.plexus.component.annotations.Component;
@Component( role = org.apache.maven.plugin.Mojo.class ) @Component( role = org.apache.maven.plugin.Mojo.class )
public class PackAppGoal extends ApsAppGoal { public class PackAppGoal extends ApsAppGoal {
@Parameter( property = "sourceDirectory", required = true, defaultValue = "${project.build.directory}/aps/app" ) @Parameter( property = "aps-model.app.directory", required = true, defaultValue = "${project.build.directory}/aps/app" )
protected File sourceDirectory; protected File unzipDirectory;
@Parameter( property = "targetDirectory", required = true, defaultValue = "${project.build.directory}/aps/app" ) @Parameter( property = "aps-model.upload.directory", required = true, defaultValue = "${project.build.directory}/aps" )
protected File targetDirectory; protected File zipDirectory;
protected final int bufferSize = 128 * 1024; protected final int bufferSize = 128 * 1024;
@ -45,17 +45,17 @@ public class PackAppGoal extends ApsAppGoal {
} }
protected void validateSourceDirectory() { protected void validateSourceDirectory() {
if (!this.sourceDirectory.exists()) { if (!this.unzipDirectory.exists()) {
throw new IllegalStateException("The 'sourceDirectory' does not exist: " + this.sourceDirectory); throw new IllegalStateException("The 'unzipDirectory' does not exist: " + this.unzipDirectory);
} else if (!this.sourceDirectory.isDirectory()) { } else if (!this.unzipDirectory.isDirectory()) {
throw new IllegalStateException("The 'sourceDirectory' is not a directory: " + this.sourceDirectory); throw new IllegalStateException("The 'unzipDirectory' is not a directory: " + this.unzipDirectory);
} }
} }
protected File validateAppDirectory() { protected File validateAppDirectory() {
File appDirectory = new File(this.sourceDirectory, this.apsAppName); File appDirectory = new File(this.unzipDirectory, this.apsAppName);
if (!appDirectory.exists()) { if (!appDirectory.exists()) {
throw new IllegalStateException("The 'apsAppName' does not exist in the source directory: " + this.sourceDirectory); throw new IllegalStateException("The 'apsAppName' does not exist in the source directory: " + this.unzipDirectory);
} else if (!appDirectory.isDirectory()) { } else if (!appDirectory.isDirectory()) {
throw new IllegalStateException("The 'apsAppName' refers to a file and not a directory: " + appDirectory); throw new IllegalStateException("The 'apsAppName' refers to a file and not a directory: " + appDirectory);
} }
@ -64,19 +64,19 @@ public class PackAppGoal extends ApsAppGoal {
} }
protected File validateTargetDirectory() { protected File validateTargetDirectory() {
if (!this.targetDirectory.exists()) { if (!this.zipDirectory.exists()) {
this.getLog().debug("The 'targetDirectory' does not exist; creating: " + this.targetDirectory); this.getLog().debug("The 'zipDirectory' does not exist; creating: " + this.zipDirectory);
this.targetDirectory.mkdirs(); this.zipDirectory.mkdirs();
} else if (!this.targetDirectory.isDirectory()) { } else if (!this.zipDirectory.isDirectory()) {
throw new IllegalStateException("The 'targetDirectory' is not a directory: " + this.targetDirectory); throw new IllegalStateException("The 'zipDirectory' is not a directory: " + this.zipDirectory);
} }
File targetFile = new File(this.targetDirectory, this.apsAppName + ".zip"); File targetFile = new File(this.zipDirectory, this.apsAppName + ".zip");
if (targetFile.isDirectory()) { if (targetFile.isDirectory()) {
throw new IllegalStateException("The App file is not a file: " + targetFile); throw new IllegalStateException("The App file is not a file: " + targetFile);
} else if (targetFile.exists()) { } else if (targetFile.exists()) {
this.getLog().debug("The App file in the 'targetDirectory' exists; deleting: " + targetFile); this.getLog().debug("The App file in the 'zipDirectory' exists; deleting: " + targetFile);
targetFile.delete(); targetFile.delete();
} }
@ -92,6 +92,7 @@ public class PackAppGoal extends ApsAppGoal {
ZipOutputStream zostream = new ZipOutputStream(bostream); ZipOutputStream zostream = new ZipOutputStream(bostream);
try { try {
this.zipDirectory(appDirectory, null, zostream); this.zipDirectory(appDirectory, null, zostream);
zostream.flush();
} finally { } finally {
zostream.close(); zostream.close();
} }
@ -118,7 +119,8 @@ public class PackAppGoal extends ApsAppGoal {
this.getLog().debug("Packing APS file: " + path); this.getLog().debug("Packing APS file: " + path);
ZipEntry zentry = new ZipEntry(path.toString()); // Activit App processing requires forward slashes (WOW)
ZipEntry zentry = new ZipEntry(path.toString().replace('\\', '/'));
zostream.putNextEntry(zentry); zostream.putNextEntry(zentry);
try { try {
FileInputStream fistream = new FileInputStream(file); FileInputStream fistream = new FileInputStream(file);

View File

@ -4,12 +4,10 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
import com.inteligr8.maven.aps.modeling.crawler.ApsAppCrawler; import com.inteligr8.maven.aps.modeling.crawler.ApsAppCrawler;
@ -19,12 +17,6 @@ import com.inteligr8.maven.aps.modeling.translator.ApsAppTranslator;
@Component( role = org.apache.maven.plugin.Mojo.class ) @Component( role = org.apache.maven.plugin.Mojo.class )
public class TranslateAppGoal extends ApsAppAccessibleGoal { public class TranslateAppGoal extends ApsAppAccessibleGoal {
@Parameter( defaultValue = "${project}", readonly = true )
protected MavenProject project;
@Parameter( defaultValue = "${session}", readonly = true )
protected MavenSession session;
@Parameter( property = "aps-model.app.directory", required = true, defaultValue = "${project.build.directory}/aps/app" ) @Parameter( property = "aps-model.app.directory", required = true, defaultValue = "${project.build.directory}/aps/app" )
protected File unzipDirectory; protected File unzipDirectory;

View File

@ -188,7 +188,7 @@ public class UnpackAppGoal extends ApsAppGoal {
case "json": case "json":
this.getLog().debug("Reformatting file: " + file); this.getLog().debug("Reformatting file: " + file);
Map<String, Object> json = ModelUtil.getInstance().readJsonAsMap(file); Map<String, Object> json = ModelUtil.getInstance().readJsonAsMap(file);
ModelUtil.getInstance().writeJson(json, file); ModelUtil.getInstance().writeJson(json, file, false);
break; break;
case "xml": case "xml":
case "bpmn": case "bpmn":

View File

@ -36,17 +36,18 @@ public class ApsAppJsonNormalizer implements ApsFileNormalizer {
ObjectNode jsonModel = (ObjectNode)_jsonModel; ObjectNode jsonModel = (ObjectNode)_jsonModel;
int fields = jsonModel.size(); int fields = jsonModel.size();
jsonModel.remove(Arrays.asList("createdBy", "createdByFullName", "lastUpdatedBy", "lastUpdatedByFullName", "lastUpdated")); jsonModel.remove(Arrays.asList("lastUpdated"));
// jsonModel.remove(Arrays.asList("createdBy", "createdByFullName", "lastUpdatedBy", "lastUpdatedByFullName", "lastUpdated"));
if (jsonModel.size() < fields) if (jsonModel.size() < fields)
changed = true; changed = true;
} }
// sort the models for better 'diff' support // sort the models for better 'diff' support
if (this.enableSorting) if (this.enableSorting)
ApsModelArrayNodeSorter.getInstance().sort(jsonModels, "name"); changed = ApsModelArrayNodeSorter.getInstance().sort(jsonModels, "name") || changed;
if (changed) if (changed)
ModelUtil.getInstance().writeJson(descriptor, file); ModelUtil.getInstance().writeJson(descriptor, file, this.enableSorting);
} }
} }

View File

@ -37,7 +37,7 @@ public class ApsProcessJsonNormalizer implements ApsFileNormalizer {
changed = ApsModelArrayNodeSorter.getInstance().sort(jsonChildShapes, "resourceId") || changed; changed = ApsModelArrayNodeSorter.getInstance().sort(jsonChildShapes, "resourceId") || changed;
if (changed) if (changed)
ModelUtil.getInstance().writeJson(jsonDescriptor, file); ModelUtil.getInstance().writeJson(jsonDescriptor, file, this.enableSorting);
} }
private ArrayNode getChildShapes(ObjectNode jsonDescriptor) { private ArrayNode getChildShapes(ObjectNode jsonDescriptor) {

View File

@ -2,7 +2,6 @@ package com.inteligr8.maven.aps.modeling.translator;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.Map; import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -67,11 +66,15 @@ public class ApsAppJsonTranslator implements ApsFileTranslator {
} }
} }
int fields = jsonModel.size(); if (jsonModel.has("version")) {
jsonModel.remove(Arrays.asList("version")); jsonModel.put("version", 0);
if (jsonModel.size() < fields)
changed = true; changed = true;
} }
// int fields = jsonModel.size();
// jsonModel.remove(Arrays.asList("version"));
// if (jsonModel.size() < fields)
// changed = true;
}
for (JsonNode _jsonIdentityInfo : descriptor.get("definition").get("publishIdentityInfo")) { for (JsonNode _jsonIdentityInfo : descriptor.get("definition").get("publishIdentityInfo")) {
ObjectNode jsonGroup = (ObjectNode)_jsonIdentityInfo.get("group"); ObjectNode jsonGroup = (ObjectNode)_jsonIdentityInfo.get("group");
@ -92,9 +95,13 @@ public class ApsAppJsonTranslator implements ApsFileTranslator {
} }
if (jsonGroup.has("parentGroupId")) { if (jsonGroup.has("parentGroupId")) {
jsonGroup.remove("parentGroupName"); jsonGroup.put("parentGroupId", 0);
changed = true; changed = true;
} }
// if (jsonGroup.has("parentGroupId")) {
// jsonGroup.remove("parentGroupId");
// changed = true;
// }
} else { } else {
this.logger.warn("The organization '{}' does not exist in APS", fileOrgName); this.logger.warn("The organization '{}' does not exist in APS", fileOrgName);
// FIXME create the organization // FIXME create the organization
@ -102,7 +109,7 @@ public class ApsAppJsonTranslator implements ApsFileTranslator {
} }
if (changed) if (changed)
ModelUtil.getInstance().writeJson(descriptor, file); ModelUtil.getInstance().writeJson(descriptor, file, false);
} }
} }

View File

@ -46,7 +46,7 @@ public class ApsFormJsonTranslator implements ApsFileTranslator {
} }
if (changed) if (changed)
ModelUtil.getInstance().writeJson(jsonDescriptor, file); ModelUtil.getInstance().writeJson(jsonDescriptor, file, false);
} }
} }

View File

@ -25,7 +25,6 @@ import org.xml.sax.SAXException;
import com.inteligr8.alfresco.activiti.model.Group; import com.inteligr8.alfresco.activiti.model.Group;
import com.inteligr8.maven.aps.modeling.util.Index; import com.inteligr8.maven.aps.modeling.util.Index;
import com.inteligr8.maven.aps.modeling.util.ModelUtil; import com.inteligr8.maven.aps.modeling.util.ModelUtil;
import com.inteligr8.maven.aps.modeling.xml.CDATAFlexSection;
public class ApsProcessBpmnTranslator implements ApsFileTranslator { public class ApsProcessBpmnTranslator implements ApsFileTranslator {
@ -106,6 +105,7 @@ public class ApsProcessBpmnTranslator implements ApsFileTranslator {
if (apsProcessId != null) if (apsProcessId != null)
changed = this.setAttributeIfSet(definitionsElement, NAMESPACE_ACTIVITI_MODELER, "modelId", apsProcessId) || changed; changed = this.setAttributeIfSet(definitionsElement, NAMESPACE_ACTIVITI_MODELER, "modelId", apsProcessId) || changed;
changed = this.removeAttributeIfSet(definitionsElement, NAMESPACE_ACTIVITI_MODELER, "modelVersion") || changed; changed = this.removeAttributeIfSet(definitionsElement, NAMESPACE_ACTIVITI_MODELER, "modelVersion") || changed;
//changed = this.setAttributeIfSet(definitionsElement, NAMESPACE_ACTIVITI_MODELER, "modelVersion", "0") || changed;
return changed; return changed;
} }
@ -200,17 +200,17 @@ public class ApsProcessBpmnTranslator implements ApsFileTranslator {
this.logger.trace("The form '{}' key does not change; leaving unchanged", formRefName); this.logger.trace("The form '{}' key does not change; leaving unchanged", formRefName);
} }
CDATAFlexSection formRefIdData = (CDATAFlexSection)ModelUtil.getInstance().xpath( CharacterData formRefIdData = (CharacterData)ModelUtil.getInstance().xpath(
taskElement, taskElement,
"tns:extensionElements/modeler:form-reference-id", "tns:extensionElements/modeler:form-reference-id",
ModelUtil.CDATA_FLEX); ModelUtil.CDATA_FLEX);
if (formRefIdData == null) if (formRefIdData == null)
throw new IllegalStateException("A form was detected in the task, but no form reference ID was found: " + taskElement.getAttribute("id")); throw new IllegalStateException("A form was detected in the task, but no form reference ID was found: " + taskElement.getAttribute("id"));
long formRefId = Long.parseLong(formRefIdData.getValue()); long formRefId = Long.parseLong(formRefIdData.getData());
if (apsFormId != formRefId) { if (apsFormId != formRefId) {
this.logger.debug("The form '{}' reference exists in APS with ID {}; changing model", formRefName, apsFormId); this.logger.debug("The form '{}' reference exists in APS with ID {}; changing model", formRefName, apsFormId);
formRefIdData.setValue(apsFormId.toString()); formRefIdData.setData(apsFormId.toString());
changed = true; changed = true;
} else { } else {
this.logger.trace("The form '{}' reference ID does not change; leaving unchanged", formRefName); this.logger.trace("The form '{}' reference ID does not change; leaving unchanged", formRefName);
@ -244,14 +244,14 @@ public class ApsProcessBpmnTranslator implements ApsFileTranslator {
this.logger.trace("Found ID {} for the subprocess '{}' in the APS Process BPMN model", apsProcessId, subprocessName); this.logger.trace("Found ID {} for the subprocess '{}' in the APS Process BPMN model", apsProcessId, subprocessName);
CDATAFlexSection subprocessIdData = (CDATAFlexSection)ModelUtil.getInstance().xpath( CharacterData subprocessIdData = (CharacterData)ModelUtil.getInstance().xpath(
subprocessElement, subprocessElement,
"tns:extensionElements/modeler:subprocess-id", "tns:extensionElements/modeler:subprocess-id",
ModelUtil.CDATA_FLEX); ModelUtil.CDATA_FLEX);
long subprocessId = Long.parseLong(subprocessIdData.getValue()); long subprocessId = Long.parseLong(subprocessIdData.getData());
if (apsProcessId != subprocessId) { if (apsProcessId != subprocessId) {
this.logger.debug("The process '{}' exists in APS with ID {}; changing model", subprocessName, apsProcessId); this.logger.debug("The process '{}' exists in APS with ID {}; changing model", subprocessName, apsProcessId);
subprocessIdData.setValue(apsProcessId.toString()); subprocessIdData.setData(apsProcessId.toString());
changed = true; changed = true;
} else { } else {
this.logger.trace("The process '{}' ID does not change; leaving unchanged", subprocessName); this.logger.trace("The process '{}' ID does not change; leaving unchanged", subprocessName);
@ -289,24 +289,38 @@ public class ApsProcessBpmnTranslator implements ApsFileTranslator {
boolean changed = false; boolean changed = false;
String conditionExpression = conditionExpressionCdata.getData(); String conditionExpression = conditionExpressionCdata.getData();
Pattern formOutcomeInExpressionPattern = Pattern.compile("[^A-Za-z0-9]form([0-9]+)outcome[^A-Za-z0-9]"); StringBuilder newce = new StringBuilder();
int pos = 0;
Pattern formOutcomeInExpressionPattern = Pattern.compile("form([0-9]+)outcome");
Matcher matcher = formOutcomeInExpressionPattern.matcher(conditionExpression); Matcher matcher = formOutcomeInExpressionPattern.matcher(conditionExpression);
while (matcher.find()) { while (matcher.find()) {
newce.append(conditionExpression.substring(pos, matcher.start(1)));
long formId = Long.parseLong(matcher.group(1)); long formId = Long.parseLong(matcher.group(1));
String formName = this.fileFormIndex.getValue(formId); String formName = this.fileFormIndex.getValue(formId);
if (formName == null) { if (formName == null) {
this.logger.warn("The form ID '{}' does not exist in the form model files; ignoring", formId); this.logger.warn("The form ID '{}' does not exist in the form model files; ignoring", formId);
newce.append(formId);
} else { } else {
Long apsFormId = this.apsFormIndex.getFirstKey(formName); Long apsFormId = this.apsFormIndex.getFirstKey(formName);
if (apsFormId == null) { if (apsFormId == null) {
this.logger.warn("The form '{}' does not exist in APS; leaving unchanged", formName); this.logger.warn("The form '{}' does not exist in APS; leaving unchanged", formName);
newce.append(formId);
} else { } else {
conditionExpressionCdata.setData(apsFormId.toString()); newce.append(apsFormId);
changed = true; changed = true;
} }
} }
pos = matcher.end(1);
} }
newce.append(conditionExpression.substring(pos));
if (changed)
conditionExpressionCdata.setData(newce.toString());
return changed; return changed;
} }

View File

@ -45,7 +45,7 @@ public class ApsProcessJsonTranslator implements ApsFileTranslator {
changed = this.translateSubprocesses(jsonDescriptor) || changed; changed = this.translateSubprocesses(jsonDescriptor) || changed;
if (changed) if (changed)
ModelUtil.getInstance().writeJson(jsonDescriptor, file); ModelUtil.getInstance().writeJson(jsonDescriptor, file, false);
} }
private boolean translateResourceId(ObjectNode jsonDescriptor, Long apsProcessId) { private boolean translateResourceId(ObjectNode jsonDescriptor, Long apsProcessId) {
@ -130,8 +130,8 @@ public class ApsProcessJsonTranslator implements ApsFileTranslator {
for (JsonNode jsonChildShape : this.getChildShapes(jsonDescriptor)) { for (JsonNode jsonChildShape : this.getChildShapes(jsonDescriptor)) {
try { try {
JsonNode jsonConditionalSequenceFlow = (JsonNode)jsonChildShape.get("properties").get("conditionalsequenceflow"); JsonNode jsonConditionalSequenceFlow = (JsonNode)jsonChildShape.get("properties").get("conditionsequenceflow");
changed = this.translateConditionalSequenceFlow(jsonConditionalSequenceFlow) || changed; changed = this.translateConditionSequenceFlow(jsonConditionalSequenceFlow) || changed;
JsonNode jsonFormRef = (JsonNode)jsonChildShape.get("properties").get("formreference"); JsonNode jsonFormRef = (JsonNode)jsonChildShape.get("properties").get("formreference");
changed = this.translateReference(jsonFormRef, this.apsFormIndex) || changed; changed = this.translateReference(jsonFormRef, this.apsFormIndex) || changed;
@ -143,7 +143,7 @@ public class ApsProcessJsonTranslator implements ApsFileTranslator {
return changed; return changed;
} }
private boolean translateConditionalSequenceFlow(JsonNode jsonConditionalSequenceFlow) { private boolean translateConditionSequenceFlow(JsonNode jsonConditionalSequenceFlow) {
if (jsonConditionalSequenceFlow == null || !jsonConditionalSequenceFlow.isObject()) if (jsonConditionalSequenceFlow == null || !jsonConditionalSequenceFlow.isObject())
return false; return false;

View File

@ -27,7 +27,7 @@ import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory; import javax.xml.xpath.XPathFactory;
import org.w3c.dom.CDATASection; import org.w3c.dom.CharacterData;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
@ -38,12 +38,10 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializationFeature;
import com.inteligr8.maven.aps.modeling.xml.CDATAFlexSection;
import com.inteligr8.maven.aps.modeling.xml.DomNamespaceContext; import com.inteligr8.maven.aps.modeling.xml.DomNamespaceContext;
public class ModelUtil { public class ModelUtil {
public final static QName CDATA = QName.valueOf("inteligr8:xml:cdata");
public final static QName CDATA_FLEX = QName.valueOf("inteligr8:xml:cdata_or_element"); public final static QName CDATA_FLEX = QName.valueOf("inteligr8:xml:cdata_or_element");
private final static ModelUtil INSTANCE = new ModelUtil(); private final static ModelUtil INSTANCE = new ModelUtil();
@ -54,6 +52,7 @@ public class ModelUtil {
private final ObjectMapper om = new ObjectMapper(); private final ObjectMapper om = new ObjectMapper();
private final ObjectMapper omsorted = new ObjectMapper();
private final DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance(); private final DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
private final DocumentBuilder docBuilder; private final DocumentBuilder docBuilder;
private final XPathFactory xpathfactory = XPathFactory.newInstance(); private final XPathFactory xpathfactory = XPathFactory.newInstance();
@ -81,26 +80,28 @@ public class ModelUtil {
// makes Git handling a whole lot better // makes Git handling a whole lot better
this.om.enable(SerializationFeature.INDENT_OUTPUT); this.om.enable(SerializationFeature.INDENT_OUTPUT);
this.omsorted.enable(SerializationFeature.INDENT_OUTPUT);
// makes Git handling better between environment nuances // makes Git handling better between environment nuances
this.om.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY); this.omsorted.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
this.om.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS); this.omsorted.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
} }
public void json(File inplaceFile) throws IOException { public void json(File inplaceFile, boolean enableSorting) throws IOException {
JsonNode json = this.readJson(inplaceFile); JsonNode json = this.readJson(inplaceFile);
this.writeJson(json, inplaceFile); this.writeJson(json, inplaceFile, enableSorting);
} }
public void json(File sourceFile, File targetFile) throws IOException { public void json(File sourceFile, File targetFile, boolean enableSorting) throws IOException {
FileInputStream fistream = new FileInputStream(sourceFile); FileInputStream fistream = new FileInputStream(sourceFile);
BufferedInputStream bistream = new BufferedInputStream(fistream, this.bufferSize); BufferedInputStream bistream = new BufferedInputStream(fistream, this.bufferSize);
try { try {
FileOutputStream fostream = new FileOutputStream(targetFile); FileOutputStream fostream = new FileOutputStream(targetFile);
BufferedOutputStream bostream = new BufferedOutputStream(fostream, this.bufferSize); BufferedOutputStream bostream = new BufferedOutputStream(fostream, this.bufferSize);
try { try {
this.json(bistream, bostream); this.json(bistream, bostream, enableSorting);
} finally { } finally {
bostream.close(); bostream.close();
} }
@ -109,10 +110,10 @@ public class ModelUtil {
} }
} }
public void json(InputStream istream, OutputStream ostream) throws IOException { public void json(InputStream istream, OutputStream ostream, boolean enableSorting) throws IOException {
// FIXME stream it for lower memory/IO usage // FIXME stream it for lower memory/IO usage
JsonNode json = this.readJson(istream); JsonNode json = this.readJson(istream);
this.writeJson(json, ostream); this.writeJson(json, ostream, enableSorting);
} }
public JsonNode readJson(File file) throws IOException { public JsonNode readJson(File file) throws IOException {
@ -167,33 +168,41 @@ public class ModelUtil {
return this.om.readValue(istream, Map.class); return this.om.readValue(istream, Map.class);
} }
public void writeJson(JsonNode json, File file) throws IOException { public void writeJson(JsonNode json, File file, boolean enableSorting) throws IOException {
FileOutputStream fostream = new FileOutputStream(file); FileOutputStream fostream = new FileOutputStream(file);
BufferedOutputStream bostream = new BufferedOutputStream(fostream, this.bufferSize); BufferedOutputStream bostream = new BufferedOutputStream(fostream, this.bufferSize);
try { try {
this.writeJson(json, bostream); this.writeJson(json, bostream, enableSorting);
} finally { } finally {
bostream.close(); bostream.close();
} }
} }
public void writeJson(Map<String, Object> map, File file) throws IOException { public void writeJson(Map<String, Object> map, File file, boolean enableSorting) throws IOException {
FileOutputStream fostream = new FileOutputStream(file); FileOutputStream fostream = new FileOutputStream(file);
BufferedOutputStream bostream = new BufferedOutputStream(fostream, this.bufferSize); BufferedOutputStream bostream = new BufferedOutputStream(fostream, this.bufferSize);
try { try {
this.writeJson(map, bostream); this.writeJson(map, bostream, enableSorting);
} finally { } finally {
bostream.close(); bostream.close();
} }
} }
public void writeJson(JsonNode json, OutputStream ostream) throws IOException { public void writeJson(JsonNode json, OutputStream ostream, boolean enableSorting) throws IOException {
if (enableSorting) {
this.omsorted.writeValue(ostream, json);
} else {
this.om.writeValue(ostream, json); this.om.writeValue(ostream, json);
} }
}
public void writeJson(Map<String, Object> map, OutputStream ostream) throws IOException { public void writeJson(Map<String, Object> map, OutputStream ostream, boolean enableSorting) throws IOException {
if (enableSorting) {
this.omsorted.writeValue(ostream, map);
} else {
this.om.writeValue(ostream, map); this.om.writeValue(ostream, map);
} }
}
@ -277,22 +286,23 @@ public class ModelUtil {
XPath xpath = this.xpathfactory.newXPath(); XPath xpath = this.xpathfactory.newXPath();
xpath.setNamespaceContext(new DomNamespaceContext(node)); xpath.setNamespaceContext(new DomNamespaceContext(node));
boolean isFlex = returnType.equals(ModelUtil.CDATA_FLEX); if (returnType.equals(ModelUtil.CDATA_FLEX)) {
if (returnType.equals(ModelUtil.CDATA) || isFlex) {
NodeList nodes = (NodeList)xpath.evaluate(xpathExpr, node, XPathConstants.NODESET); NodeList nodes = (NodeList)xpath.evaluate(xpathExpr, node, XPathConstants.NODESET);
Node anode = this.getFirstCDataSectionOrLastElement(nodes); Node anode = this.getFirstCDataSectionOrLastElement(nodes);
if (anode instanceof CDATASection) { if (anode instanceof CharacterData) {
// nothing special // nothing special
} else if (anode instanceof Element) { } else if (anode instanceof Element) {
Node anode2 = this.getFirstCDataSectionOrLastElement(anode.getChildNodes()); Node anode2 = this.getFirstCDataSectionOrLastElement(anode.getChildNodes());
if (anode2 != null) if (anode2 == null)
return anode = anode2; return null;
if (!(anode2 instanceof CharacterData))
throw new IllegalStateException();
anode = anode2;
} else { } else {
return null; return null;
} }
return isFlex ? new CDATAFlexSection(anode) : anode; return anode;
} else { } else {
return xpath.evaluate(xpathExpr, node, returnType); return xpath.evaluate(xpathExpr, node, returnType);
} }
@ -303,8 +313,8 @@ public class ModelUtil {
for (int n = 0; n < nodes.getLength(); n++) { for (int n = 0; n < nodes.getLength(); n++) {
Node anode = nodes.item(n); Node anode = nodes.item(n);
if (anode.getNodeType() == Node.CDATA_SECTION_NODE) { if (anode instanceof CharacterData) {
return (CDATASection)anode; return (CharacterData)anode;
} else if (anode.getNodeType() == Node.ELEMENT_NODE) { } else if (anode.getNodeType() == Node.ELEMENT_NODE) {
element = (Element)anode; element = (Element)anode;
} }

View File

@ -1,31 +0,0 @@
package com.inteligr8.maven.aps.modeling.xml;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Node;
public class CDATAFlexSection {
private final Node node;
public CDATAFlexSection(Node node) {
this.node = node;
}
public String getValue() {
if (this.node instanceof CDATASection) {
return ((CDATASection)this.node).getData();
} else {
String value = this.node.getTextContent();
return value == null ? null : this.node.getTextContent().trim();
}
}
public void setValue(String value) {
if (this.node instanceof CDATASection) {
((CDATASection)this.node).setData(value);
} else {
this.node.setTextContent(value);
}
}
}

View File

@ -6,4 +6,9 @@
<xsl:apply-templates select="@*|node()"/> <xsl:apply-templates select="@*|node()"/>
</xsl:copy> </xsl:copy>
</xsl:template> </xsl:template>
<xsl:template match="text()">
<xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
<xsl:value-of select="." disable-output-escaping="yes" />
<xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
</xsl:template>
</xsl:stylesheet> </xsl:stylesheet>