How can I import libraries locally without using Nexus in Maven? - java

The Nexus referred to by my Maven project is located on another server, which has some restrictions. The problem is that I have to import some Java libraries into my project that the Nexus cannot download due to its restrictions. My goal is to import these libraries locally and thus avoid using the Nexus. If anyone knows any alternative, I am open to new proposals.
My only attempt has been to import these libraries using Maven which in turn uses the Nexus of those servers, but it is impossible because they have certain network restrictions.
Those libreries are:
import oracle.xml.parser.schema.*;
import oracle.xml.parser.v2.*;
But what i am trying?
I provide function that Validate XML files by using XSD schemas.
But when the function is called it throws an error becaus of the import of
the libreries are not allowed.
import oracle.xml.parser.schema.*;
import oracle.xml.parser.v2.*;
import java.net.*;
import java.io.*;
import org.w3c.dom.*;
import java.util.*;
import java.sql.SQLException;
/**
*
* Clase de utilidad para el tratamiento de XML.
* class SIXUtil
* author Ibermática
* date Diciembre 2008
*
*/
public class SIXUtil
{
public static String validarXmlSchema(oracle.sql.CLOB xml,
oracle.sql.CLOB xsd) throws Exception
{
XSDBuilder builder = new XSDBuilder();
XMLSchema schemadoc =
(XMLSchema)builder.build(xsd.getAsciiStream(),null);
DOMParser dp = new DOMParser();
dp.setXMLSchema(schemadoc);
dp.setValidationMode(XMLParser.SCHEMA_VALIDATION);
dp.setPreserveWhitespace (true);
StringWriter sw = new StringWriter();
dp.setErrorStream (new PrintWriter(sw));
try
{
dp.parse (xml.getAsciiStream());
}
catch (XMLParseException pe)
{
sw.write(pe.getMessage());
}
catch (Exception e)
{
sw.write("Error inesperado: " + e.getMessage());
}
return sw.toString();
}
}
/
I expect to import the libreries locally insted of using the Nexus.

You can use these jars by placing them in project’s lib folder and configure the as the system dependency
<dependency>
<groupId>com.ext</groupId>
<artifactId>dependency</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\war\WEB-INF\lib\extDependency.jar</systemPath>
</dependency>

Related

How to create a file from an action event for an IntelliJ plugin?

I'm creating a PhpStorm plugin with IntelliJ IDEA Community Edition and I would like to know how to create a file on disk from a PSIFile or VirtualFile.
Here my code: (The context is an action from NewGroup)
I've tried to use the PsiDirectory.copyFileFrom method to create the file but I have an exception com.intellij.util.IncorrectOperationException: Cannot copy non-physical file: PHP file
package fr.florent.idea.zendgenerator.action.NewGroup;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiFileFactory;
import com.intellij.util.ResourceUtil;
import com.jetbrains.php.lang.PhpFileType;
import fr.florent.idea.zendgenerator.action.AbstractDumbAwareAction;
import icons.PhpIcons;
import org.jetbrains.annotations.NotNull;
import java.net.URL;
public class CreateQueryAction extends AbstractDumbAwareAction {
public CreateQueryAction() {
super("Query", "Create query", PhpIcons.Php_icon);
}
#Override
public void actionPerformed(#NotNull AnActionEvent e) {
URL url = ResourceUtil.getResource(getClass(), "templates", "query.php"); // it contains an empty PHP class
VirtualFile virtualFile = VfsUtil.findFileByURL(url);
PsiFile file = PsiFileFactory.getInstance(e.getProject()).createFileFromText(
virtualFile.getPath(),
PhpFileType.INSTANCE,
LoadTextUtil.loadText(virtualFile)
);
PsiDirectory directory = LangDataKeys.IDE_VIEW.getData(e.getDataContext()).getOrChooseDirectory();
directory.copyFileFrom("query.php", file);
System.out.println("Create query");
}
}
I would like to have the file created in the project folder from the context of my action.
It will be great if someone can explain the process of creating a file in a IntelliJ plugin. I think the docs is really light.
In my case I would like to have the process to edit the query.php file, rename the class name, add method, properties, doc block and save it to the disk but I don't understand the PSI element.
You might want to ask this also on JB forum, there's a similar question: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360001787320-Create-VirtualFile-or-PsiFile-from-content
The answer is:
final PsiFileFactory factory = PsiFileFactory.getInstance(project);
final PsiFile file = factory.createFileFromText(language, text);

Azure functions using Java - How to created #BlobTrigger

i need to created Azure function BlobTrigger using Java to monitor my storage container for new and updated blobs.
tried with below code
import java.util.*;
import com.microsoft.azure.serverless.functions.annotation.*;
import com.microsoft.azure.serverless.functions.*;
import java.nio.file.*;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import com.microsoft.azure.storage.*;
import com.microsoft.azure.storage.blob.*;
#FunctionName("testblobtrigger")
public String testblobtrigger(#BlobTrigger(name = "test", path = "testcontainer/{name}") String content) {
try {
return String.format("Blob content : %s!", content);
} catch (Exception e) {
// Output the stack trace.
e.printStackTrace();
return "Access Error!";
}
}
when executed it is showing error
Storage binding (blob/queue/table) must have non-empty connection. Invalid storage binding found on method:
it is working when added connection string
public String kafkablobtrigger(#BlobTrigger(name = "test", path = "testjavablobstorage/{name}",connection=storageConnectionString) String content) {
why i need to add connection string when using blobtrigger?
in C# it is working without connection string:
public static void ProcessBlobContainer1([BlobTrigger("container1/{blobName}")] CloudBlockBlob blob, string blobName)
{
ProcessBlob("container1", blobName, blob);
}
i didn't see any Java sample for Azure functions for #BlobTrigger.
After all, connection is necessary for the trigger to identify where the container locates.
After test I find #Mikhail is right.
For C#, the default value(in local.settings.json or in application settings in portal) will be used if connection is ignored. But unfortunately there's no same settings for java.
You can add #StorageAccount("YourStorageConnection") below your #FuncionName as it's another valid way to choose. And value of YourStorageConnection in local.settings.json or in portal's application settings is up to you.
You can follow this tutorial, use mvn azure-functions:add to find four(Http/Blob/Queue/TimerTrigger) templates for java.

How to import RapidMiner JARs in Eclipse?

I want to create a RapidMiner classifier on Java that classifies a user based on his/her touch input. I have searched for days now, I have RapidMiner Studio and have downloaded the rapidMiner-studio from github - but I don't know which one should I include on my library/build path.
Do I just include all of them? Any help would be greatly appreciated.
I found the answer to my question, so far I found out that you can run a process ( a .rmp) file you created from RapidMiner in Eclipse, and the JAR files i added are located at C:\Program Files\RapidMiner\RapidMiner Studio\lib
Here's my code:
package rapid_process;
import com.rapidminer.Process;
import com.rapidminer.RapidMiner;
import com.rapidminer.operator.Operator;
import com.rapidminer.operator.OperatorException;
//import com.rapidminer.operator.io.ExcelExampleSource;
import com.rapidminer.tools.XMLException;
import java.io.File;
import java.io.IOException;
import java.lang.Object;
public class process {
public static void main(String[] args) throws IOException, XMLException, OperatorException {
/*// Path to process-definition
final String processPath = "C:/Users/Evie/.RapidMiner/repositories/Local Repository/processes/Compare ROCs.rmp";
// Init RapidMiner
RapidMiner.setExecutionMode(ExecutionMode.COMMAND_LINE);
RapidMiner.init();
// Load process
final com.rapidminer.Process process = new com.rapidminer.Process(new File(processPath));
process.run();*/
try {
RapidMiner.setExecutionMode(RapidMiner.ExecutionMode.COMMAND_LINE);
RapidMiner.init();
Process process = new Process(new File("C:/Users/YourUser/.RapidMiner/repositories/Local Repository/processes/Compare ROCs.rmp"));
process.run();
} catch (IOException | XMLException | OperatorException ex) {
ex.printStackTrace();
}
}
}

BIRT in spring boot app

I need to create a report capability(function) in an existing spring boot web application. The suggestion was to use BIRT, which I could integrate with the spring boot web app.
I found the article below and was able to run the reports in a spring boot starter project (using http://start.spring.io/). This article, fairly old, did help me to get to a working example. https://spring.io/blog/2012/01/30/spring-framework-birt. This article is basically exactly what I want, but in a spring boot web app.
The challenge I have is to run the report using the BIRT viewer, which comes with nice additional features. (Print, Expoet data, PDF, pagination etc.)
I cannot find any spring boot example using BIRT the way this article describes.
My questions are:
Is there an alternative or other way to do reports in a spring boot web application? (obviously not want to re-inventing the wheel by creating BIRT like capability from scratch or run the report engine separate from the web application if at all possible)
Does anyone today have BIRT working (with the viewer) in a spring boot web application and be willing to share or educate me on the best way to do this?
(I tried to get JSP page working with spring boot, but unable to so successfully...more a lack of experience than anything else)
Can someone help me please.
Kind Regards,
Henk
Dependencies, an instance of the IReportEngine, and directories are the most challenging part of setting up BIRT in a spring boot web application.
This example has a little bit of error handling and depends on environment variables for specifying paths to important directories.
One nice things about this setup is that it is a standalone ReST API for building and generating reports. As a side benefit it doesn't depend on JSP at all.
I run it in a Docker container.
Originally there was a plan to use some of the interfaces to try other reporting frameworks like Jasper reports or something else.
This isn't exactly what you are asking for though in my opinion it is better in certain contexts. You have a lot of flexibility with using, configuring, and deploying the BIRT report runner as an application like this. This does not use the pre-packaged BIRT Viewer provided by Actian.
I would make a data container for reports called birt-report-runner-data and then put all of the directories for logging and reports on that container which you can then mount onto your BIRT container.
Main Components
Main File (BirtReportRunnerApplication.java)
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class BirtReportRunnerApplication {
public static void main(String[] args) {
SpringApplication.run(BirtReportRunnerApplication.class, args);
}
}
Controller to receive report Requests (ReportController.java)
package com.example.core.web.controller;
import com.example.core.model.BIRTReport;
import com.example.core.service.ReportRunner;
import com.example.core.web.dto.ReportRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
#RestController("ReportController")
#RequestMapping("/reports")
public class ReportController {
private Logger logger = LoggerFactory.getLogger(ReportController.class);
#Autowired
#Qualifier("birt")
ReportRunner reportRunner;
#RequestMapping(value = "/birt", method = RequestMethod.POST)
public ResponseEntity<byte[]> getBIRTReport(#RequestBody ReportRequest reportRequest) {
byte[] reportBytes;
ResponseEntity<byte[]> responseEntity;
try {
logger.info("REPORT REQUEST NAME: " + reportRequest.getReportName());
reportBytes =
new BIRTReport(
reportRequest.getReportName(),
reportRequest.getReportParameters(),
reportRunner)
.runReport().getReportContent().toByteArray();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.parseMediaType("application/pdf"));
String fileName = reportRequest.getReportName() + ".pdf";
httpHeaders.setContentDispositionFormData(fileName, fileName);
httpHeaders.setCacheControl("must-revalidate, post-check=0, pre-check=0");
responseEntity = new ResponseEntity<byte[]>(reportBytes, httpHeaders, HttpStatus.OK);
} catch (Exception e) {
responseEntity = new ResponseEntity<byte[]>(HttpStatus.NOT_IMPLEMENTED);
return responseEntity;
}
return responseEntity;
}
}
Report Request DTO for specifying report to run (ReportRequest.java)
package com.example.core.web.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
public class ReportRequest {
private String reportName;
private String reportParameters;
public ReportRequest(#JsonProperty("reportName") String reportName,
#JsonProperty("reportParameters") String reportParameters) {
this.reportName = reportName;
this.reportParameters = reportParameters;
}
public String getReportName() {
return reportName;
}
public String getReportParameters() {
return reportParameters;
}
public void setReportParameters(String reportParameters) {
this.reportParameters = reportParameters;
}
}
Interface for report runner (ReportRunner.java)
package com.example.core.service;
import com.example.core.model.Report;
import java.io.ByteArrayOutputStream;
public interface ReportRunner {
ByteArrayOutputStream runReport(Report report);
}
Largest class that does most of the work (BIRTReportRunner.java)
package com.example.core.service;
import com.example.core.model.Report;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.*;
import org.eclipse.core.internal.registry.RegistryProviderFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
#Service
#Qualifier("birt")
public class BIRTReportRunner implements ReportRunner {
private static final String DEFAULT_LOGGING_DIRECTORY = "defaultBirtLoggingDirectory/";
private Logger logger = LoggerFactory.getLogger(BIRTReportRunner.class);
private static String reportOutputDirectory;
private IReportEngine birtReportEngine = null;
#Autowired
private Environment env;
/**
* Starts up and configures the BIRT Report Engine
*/
#PostConstruct
public void startUp() {
if(env.getProperty("birt_report_input_dir") == null)
throw new RuntimeException("Cannot start application since birt report input directory was not specified.");
try {
String birtLoggingDirectory = env.getProperty("birt_logging_directory") == null ? DEFAULT_LOGGING_DIRECTORY : env.getProperty("birt_logging_directory");
Level birtLoggingLevel = env.getProperty("birt_logging_level") == null ? Level.SEVERE : Level.parse(env.getProperty("birt_logging_level"));
EngineConfig engineConfig = new EngineConfig();
logger.info("BIRT LOG DIRECTORY SET TO : {}", birtLoggingDirectory);
logger.info("BIRT LOGGING LEVEL SET TO {}", birtLoggingLevel);
engineConfig.setLogConfig(birtLoggingDirectory, birtLoggingLevel);
// Required due to a bug in BIRT that occurs in calling Startup after the Platform has already been started up
RegistryProviderFactory.releaseDefault();
Platform.startup(engineConfig);
IReportEngineFactory reportEngineFactory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
birtReportEngine = reportEngineFactory.createReportEngine(engineConfig);
} catch (BirtException e) {
// TODO add logging aspect and find out how to log a platform startup problem from this catch block, if possible, using the aspect.
// Possibly rethrow the exception here and catch it in the aspect.
logger.error("Birt Startup Error: {}", e.getMessage());
}
reportOutputDirectory = env.getProperty("birt_temp_file_output_dir");
}
/**
* Shuts down the BIRT Report Engine
*/
#PreDestroy
public void shutdown() {
birtReportEngine.destroy();
RegistryProviderFactory.releaseDefault();
Platform.shutdown();
}
public File getReportFromFilesystem(String reportName) throws RuntimeException {
String reportDirectory = env.getProperty("birt_report_input_dir");
Path birtReport = Paths.get(reportDirectory + File.separator + reportName + ".rptdesign");
if(!Files.isReadable(birtReport))
throw new RuntimeException("Report " + reportName + " either did not exist or was not writable.");
return birtReport.toFile();
}
/**
* This method creates and executes the report task, the main responsibility
* of the entire Report Service.
* This method is key to enabling pagination for the BIRT report. The IRunTask run task
* is created and then used to generate an ".rptdocument" binary file.
* This binary file is then read by the separately created IRenderTask render
* task. The render task renders the binary document as a binary PDF output
* stream which is then returned from the method.
* <p>
*
* #param birtReport the report object created at the controller to hold the data of the report request.
* #return Returns a ByteArrayOutputStream of the PDF bytes generated by the
*/
#Override
public ByteArrayOutputStream runReport(Report birtReport) {
ByteArrayOutputStream byteArrayOutputStream;
File rptDesignFile;
// get the path to the report design file
try {
rptDesignFile = getReportFromFilesystem(birtReport.getName());
} catch (Exception e) {
logger.error("Error while loading rptdesign: {}.", e.getMessage());
throw new RuntimeException("Could not find report");
}
// process any additional parameters
Map<String, String> parsedParameters = parseParametersAsMap(birtReport.getParameters());
byteArrayOutputStream = new ByteArrayOutputStream();
try {
IReportRunnable reportDesign = birtReportEngine.openReportDesign(rptDesignFile.getPath());
IRunTask runTask = birtReportEngine.createRunTask(reportDesign);
if (parsedParameters.size() > 0) {
for (Map.Entry<String, String> entry : parsedParameters.entrySet()) {
runTask.setParameterValue(entry.getKey(), entry.getValue());
}
}
runTask.validateParameters();
String rptdocument = reportOutputDirectory + File.separator
+ "generated" + File.separator
+ birtReport.getName() + ".rptdocument";
runTask.run(rptdocument);
IReportDocument reportDocument = birtReportEngine.openReportDocument(rptdocument);
IRenderTask renderTask = birtReportEngine.createRenderTask(reportDocument);
PDFRenderOption pdfRenderOption = new PDFRenderOption();
pdfRenderOption.setOption(IPDFRenderOption.REPAGINATE_FOR_PDF, new Boolean(true));
pdfRenderOption.setOutputFormat("pdf");
pdfRenderOption.setOutputStream(byteArrayOutputStream);
renderTask.setRenderOption(pdfRenderOption);
renderTask.render();
renderTask.close();
} catch (EngineException e) {
logger.error("Error while running report task: {}.", e.getMessage());
// TODO add custom message to thrown exception
throw new RuntimeException();
}
return byteArrayOutputStream;
}
/**
* Takes a String of parameters started by '?', delimited by '&', and with
* keys and values split by '=' and returnes a Map of the keys and values
* in the String.
*
* #param reportParameters a String from a HTTP request URL
* #return a map of parameters with Key,Value entries as strings
*/
public Map<String, String> parseParametersAsMap(String reportParameters) {
Map<String, String> parsedParameters = new HashMap<String, String>();
String[] paramArray;
if (reportParameters.isEmpty()) {
throw new IllegalArgumentException("Report parameters cannot be empty");
} else if (!reportParameters.startsWith("?") && !reportParameters.contains("?")) {
throw new IllegalArgumentException("Report parameters must start with a question mark '?'!");
} else {
String noQuestionMark = reportParameters.substring(1, reportParameters.length());
paramArray = noQuestionMark.split("&");
for (String param : paramArray) {
String[] paramGroup = param.split("=");
if (paramGroup.length == 2) {
parsedParameters.put(paramGroup[0], paramGroup[1]);
} else {
parsedParameters.put(paramGroup[0], "");
}
}
}
return parsedParameters;
}
}
Report object class (Report.java)
package com.example.core.model;
import com.example.core.service.ReportRunner;
import java.io.ByteArrayOutputStream;
import java.util.List;
/**
* A Report object has a byte representation of the report output that can be
* used to write to any output stream. This class is designed around the concept
* of using ByteArrayOutputStreams to write PDFs to an output stream.
*
*
*/
public abstract class Report {
protected String name;
protected String parameters;
protected ByteArrayOutputStream reportContent;
protected ReportRunner reportRunner;
public Report(String name, String parameters, ReportRunner reportRunner) {
this.name = name;
this.parameters = parameters;
this.reportRunner = reportRunner;
}
/**
* This is the processing method for a Report. Once the report is ran it
* populates an internal field with a ByteArrayOutputStream of the
* report content generated during the run process.
* #return Returns itself with the report content output stream created.
*/
public abstract Report runReport();
public ByteArrayOutputStream getReportContent() {
return this.reportContent;
}
public String getName() {
return name;
}
public String getParameters() {
return parameters;
}
}
BIRTReport object class (BIRTReport.java)
package com.example.core.model;
import com.example.core.service.ReportRunner;
public class BIRTReport extends Report {
public BIRTReport(String name, String reportParameters, ReportRunner reportRunner) {
super(name, reportParameters, reportRunner);
}
#Override
public Report runReport() {
this.reportContent = reportRunner.runReport(this);
return this;
}
}
Build file (build.gradle)
buildscript {
ext {
springBootVersion = '1.3.2.RELEASE'
}
repositories {
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'com.example.simple-birt-runner'
version = '1.0.0'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
ext {
springBootVersion = '1.3.0.M5'
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}")
compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
// BIRT Runtime and ReportEngine dependencies
// These were pulled from the Actuate download site at http://download.eclipse.org/birt/downloads/ for version 4.5.0
compile fileTree(dir: 'lib', include: '*.jar')
/*compile("org.eclipse.birt.runtime:org.eclipse.birt.runtime:4.4.2") {
exclude group: "org.eclipse.birt.runtime", module: "org.apache.poi"
exclude group: "org.eclipse.birt.runtime", module: "org.eclipse.orbit.mongodb"
}*/
compile("org.springframework.boot:spring-boot-starter-tomcat")
// include any runtime JDBC driver dependencies here
testCompile("org.springframework.boot:spring-boot-starter-test")
}
Dependencies
Get all of the dependencies in the Birt Viewer lib directory and put them on your classpath. Here is a full list of external dependencies:
com.ibm.icu_54.1.1.v201501272100.jar
com.lowagie.text_2.1.7.v201004222200.jar
derby.jar
flute.jar
javax.wsdl_1.5.1.v201012040544.jar
javax.xml.stream_1.0.1.v201004272200.jar
javax.xml_1.3.4.v201005080400.jar
net.sourceforge.lpg.lpgjavaruntime_1.1.0.v201004271650.jar
org.apache.batik.bridge_1.6.0.v201011041432.jar
org.apache.batik.css_1.6.0.v201011041432.jar
org.apache.batik.dom.svg_1.6.0.v201011041432.jar
org.apache.batik.dom_1.6.1.v201505192100.jar
org.apache.batik.ext.awt_1.6.0.v201011041432.jar
org.apache.batik.parser_1.6.0.v201011041432.jar
org.apache.batik.pdf_1.6.0.v201105071520.jar
org.apache.batik.svggen_1.6.0.v201011041432.jar
org.apache.batik.transcoder_1.6.0.v201011041432.jar
org.apache.batik.util.gui_1.6.0.v201011041432.jar
org.apache.batik.util_1.6.0.v201011041432.jar
org.apache.batik.xml_1.6.0.v201011041432.jar
org.apache.commons.codec_1.6.0.v201305230611.jar
org.apache.commons.logging_1.1.1.v201101211721.jar
org.apache.lucene.core_3.5.0.v20120725-1805.jar
org.apache.poi_3.9.0.v201405241750.jar
org.apache.xerces_2.9.0.v201101211617.jar
org.apache.xml.resolver_1.2.0.v201005080400.jar
org.apache.xml.serializer_2.7.1.v201005080400.jar
org.eclipse.birt.runtime_4.5.0.jar
org.eclipse.core.contenttype_3.5.0.v20150421-2214.jar
org.eclipse.core.expressions_3.5.0.v20150421-2214.jar
org.eclipse.core.filesystem_1.5.0.v20150421-0713.jar
org.eclipse.core.jobs_3.7.0.v20150330-2103.jar
org.eclipse.core.resources_3.10.0.v20150423-0755.jar
org.eclipse.core.runtime.compatibility_3.2.300.v20150423-0821.jar
org.eclipse.core.runtime_3.11.0.v20150405-1723.jar
org.eclipse.datatools.connectivity.apache.derby.dbdefinition_1.0.2.v201107221459.jar
org.eclipse.datatools.connectivity.apache.derby_1.0.103.v201212070447.jar
org.eclipse.datatools.connectivity.console.profile_1.0.10.v201109250955.jar
org.eclipse.datatools.connectivity.db.generic_1.0.1.v201107221459.jar
org.eclipse.datatools.connectivity.dbdefinition.genericJDBC_1.0.2.v201310181001.jar
org.eclipse.datatools.connectivity.oda.consumer_3.2.6.v201403131814.jar
org.eclipse.datatools.connectivity.oda.design_3.3.6.v201403131814.jar
org.eclipse.datatools.connectivity.oda.flatfile_3.1.8.v201403010906.jar
org.eclipse.datatools.connectivity.oda.profile_3.2.9.v201403131814.jar
org.eclipse.datatools.connectivity.oda_3.4.3.v201405301249.jar
org.eclipse.datatools.connectivity.sqm.core_1.2.8.v201401230755.jar
org.eclipse.datatools.connectivity_1.2.11.v201401230755.jar
org.eclipse.datatools.enablement.hsqldb.dbdefinition_1.0.0.v201107221502.jar
org.eclipse.datatools.enablement.hsqldb_1.0.0.v201107221502.jar
org.eclipse.datatools.enablement.ibm.db2.iseries.dbdefinition_1.0.3.v201107221502.jar
org.eclipse.datatools.enablement.ibm.db2.iseries_1.0.2.v201107221502.jar
org.eclipse.datatools.enablement.ibm.db2.luw.dbdefinition_1.0.7.v201405302027.jar
org.eclipse.datatools.enablement.ibm.db2.luw_1.0.3.v201401170830.jar
org.eclipse.datatools.enablement.ibm.db2.zseries.dbdefinition_1.0.4.v201107221502.jar
org.eclipse.datatools.enablement.ibm.db2.zseries_1.0.2.v201107221502.jar
org.eclipse.datatools.enablement.ibm.db2_1.0.0.v201401170830.jar
org.eclipse.datatools.enablement.ibm.informix.dbdefinition_1.0.4.v201107221502.jar
org.eclipse.datatools.enablement.ibm.informix_1.0.1.v201107221502.jar
org.eclipse.datatools.enablement.ibm_1.0.0.v201401170830.jar
org.eclipse.datatools.enablement.msft.sqlserver.dbdefinition_1.0.1.v201201240505.jar
org.eclipse.datatools.enablement.msft.sqlserver_1.0.3.v201308161009.jar
org.eclipse.datatools.enablement.mysql.dbdefinition_1.0.4.v201109022331.jar
org.eclipse.datatools.enablement.mysql_1.0.4.v201212120617.jar
org.eclipse.datatools.enablement.oda.ws_1.2.6.v201403131825.jar
org.eclipse.datatools.enablement.oda.xml_1.2.5.v201403131825.jar
org.eclipse.datatools.enablement.oracle.dbdefinition_1.0.103.v201206010214.jar
org.eclipse.datatools.enablement.oracle_1.0.0.v201107221506.jar
org.eclipse.datatools.enablement.postgresql.dbdefinition_1.0.2.v201110070445.jar
org.eclipse.datatools.enablement.postgresql_1.1.1.v201205252207.jar
org.eclipse.datatools.enablement.sap.maxdb.dbdefinition_1.0.0.v201107221507.jar
org.eclipse.datatools.enablement.sap.maxdb_1.0.0.v201107221507.jar
org.eclipse.datatools.modelbase.dbdefinition_1.0.2.v201107221519.jar
org.eclipse.datatools.modelbase.derby_1.0.0.v201107221519.jar
org.eclipse.datatools.modelbase.sql.query_1.1.4.v201212120619.jar
org.eclipse.datatools.modelbase.sql_1.0.6.v201208230744.jar
org.eclipse.datatools.sqltools.data.core_1.2.3.v201212120623.jar
org.eclipse.datatools.sqltools.parsers.sql.lexer_1.0.1.v201107221520.jar
org.eclipse.datatools.sqltools.parsers.sql.query_1.2.1.v201201250511.jar
org.eclipse.datatools.sqltools.parsers.sql_1.0.2.v201107221520.jar
org.eclipse.datatools.sqltools.result_1.1.6.v201402080246.jar
org.eclipse.emf.common_2.11.0.v20150512-0501.jar
org.eclipse.emf.ecore.change_2.11.0.v20150512-0501.jar
org.eclipse.emf.ecore.xmi_2.11.0.v20150512-0501.jar
org.eclipse.emf.ecore_2.11.0.v20150512-0501.jar
org.eclipse.equinox.app_1.3.300.v20150423-1356.jar
org.eclipse.equinox.common_3.7.0.v20150402-1709.jar
org.eclipse.equinox.preferences_3.5.300.v20150408-1437.jar
org.eclipse.equinox.registry_3.6.0.v20150318-1503.jar
org.eclipse.help_3.6.0.v20130326-1254.jar
org.eclipse.osgi.services_3.5.0.v20150519-2006.jar
org.eclipse.osgi_3.10.100.v20150529-1857.jar
org.eclipse.update.configurator_3.3.300.v20140518-1928.jar
org.mozilla.javascript_1.7.5.v201504281450.jar
org.w3c.css.sac_1.3.1.v200903091627.jar
org.w3c.dom.events_3.0.0.draft20060413_v201105210656.jar
org.w3c.dom.smil_1.0.1.v200903091627.jar
org.w3c.dom.svg_1.1.0.v201011041433.jar
Application properties (application.yml)
birt:
report:
output:
dir: ${birt_temp_file_output_dir}
input:
dir: ${birt_report_input_dir}
logging:
level: ${birt_logging_level}
server:
port: 8080
context-path: /simple-birt-runner
birt:
logging:
level: SEVERE
logging:
level:
org:
springframework:
web: ERROR
Dockerfile for running (Dockerfile)
FROM java:openjdk-8u66-jre
MAINTAINER Kent O. Johnson <kentoj#gmail.com>
COPY com.example.simple-birt-runner-*.jar /opt/soft/simple-birt-runner.jar
RUN mkdir -p /reports/input \
&& mkdir /reports/output \
&& mkdir -p /reports/log/engine
WORKDIR /opt/soft
CMD java -jar -Xms128M -Xmx4G simple-birt-runner.jar
EXPOSE 8080
Docker compose file for running image (docker-compose.yml)
simple-birt-runner:
image: soft/simple-birt-runner-release
ports:
- "8090:8080"
environment:
- birt_temp_file_output_dir=/reports/output
- birt_report_input_dir=/reports/input
- birt_logging_directory=/reports/log/engine
- birt_logging_level=SEVERE
volumes_from:
- birt-report-runner-data
Regarding #Kent Johnson 's answer. I didn't manage to configure the project with gradle, but I managed to build it with maven.
Below is the pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>birt-runner</groupId>
<artifactId>com.example.simple-birt-runner</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.birt.runtime/org.eclipse.birt.runtime -->
<dependency>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.eclipse.birt.runtime</artifactId>
<version>4.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

XML Schema Validation in Android

I have created an XML and I want to validate with schema i.e,
XSD file but there are no direct classes provided by android for the
same if I am not wrong ......... and there is an external jar named
jaxp1.3 which doesn't allow me to compile the code is it because the
bytecode of desktop and android are different? Which has the classes
schema factory and validator which does the validation stuff ...... Is
there an other option available. Any help would be appreciated .....
desperately searching for the ans..........
It's a known issue posted by Google here
The solution is to use Apache Xerces ported to Android.
There is a project here
You have to do a svn chekout and export the proyect to a jar file to use as a library in your android proyect.
The code to instance SchemaFactory change a little.
I show you an example:
import mf.javax.xml.validation.Schema;
import mf.javax.xml.validation.SchemaFactory;
import mf.javax.xml.validation.Validator;
import mf.org.apache.xerces.jaxp.validation.XMLSchemaFactory;
SchemaFactory factory = new XMLSchemaFactory();
Schema esquema = factory.newSchema(".../file.xsd");
#iOSDev, I had to use Xerces-for-Android for my validation. The following is a summary of what I did to get it working with my program:
Create a validation utility.
Get both the xml and xsd into file on the android OS and use the validation utility against it.
Use Xerces-For-Android to do the validation.
Android does support some packages which we can use, I created my xml validation utility based on: http://docs.oracle.com/javase/1.5.0/docs/api/javax/xml/validation/package-summary.html
My initial sandbox testing was pretty smooth with java, then I tried to port it over to Dalvik and found that my code did not work. Some things just aren't supported the same with Dalvik, so I made some modifications.
I found a reference to xerces for android, so I modified my sandbox test of (the following doesn't work with android, the example after this does):
import java.io.File;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.w3c.dom.Document;
/**
* A Utility to help with xml communication validation.
*/
public class XmlUtil {
/**
* Validation method.
* Base code/example from: http://docs.oracle.com/javase/1.5.0/docs/api/javax/xml/validation/package-summary.html
*
* #param xmlFilePath The xml file we are trying to validate.
* #param xmlSchemaFilePath The schema file we are using for the validation. This method assumes the schema file is valid.
* #return True if valid, false if not valid or bad parse.
*/
public static boolean validate(String xmlFilePath, String xmlSchemaFilePath) {
// parse an XML document into a DOM tree
DocumentBuilder parser = null;
Document document;
// Try the validation, we assume that if there are any issues with the validation
// process that the input is invalid.
try {
// validate the DOM tree
parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
document = parser.parse(new File(xmlFilePath));
// create a SchemaFactory capable of understanding WXS schemas
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// load a WXS schema, represented by a Schema instance
Source schemaFile = new StreamSource(new File(xmlSchemaFilePath));
Schema schema = factory.newSchema(schemaFile);
// create a Validator instance, which can be used to validate an instance document
Validator validator = schema.newValidator();
validator.validate(new DOMSource(document));
} catch (Exception e) {
// Catches: SAXException, ParserConfigurationException, and IOException.
return false;
}
return true;
}
}
The above code had to be modified some to work with xerces for android (http://gc.codehum.com/p/xerces-for-android/). You need SVN to get the project, the following are some crib notes:
download xerces-for-android
download silk svn (for windows users) from http://www.sliksvn.com/en/download
install silk svn (I did complete install)
Once the install is complete, you should have svn in your system path.
Test by typing "svn" from the command line.
I went to my desktop then downloaded the xerces project by:
svn checkout http://xerces-for-android.googlecode.com/svn/trunk/ xerces-for-android-read-only
You should then have a new folder on your desktop called xerces-for-android-read-only
With the above jar (Eventually I'll make it into a jar, just copied it directly into my source for quick testing. If you wish to do the same, you can making the jar quickly with Ant (http://ant.apache.org/manual/using.html)), I was able to get the following to work for my xml validation:
import java.io.File;
import java.io.IOException;
import mf.javax.xml.transform.Source;
import mf.javax.xml.transform.stream.StreamSource;
import mf.javax.xml.validation.Schema;
import mf.javax.xml.validation.SchemaFactory;
import mf.javax.xml.validation.Validator;
import mf.org.apache.xerces.jaxp.validation.XMLSchemaFactory;
import org.xml.sax.SAXException;
/**
* A Utility to help with xml communication validation.
*/public class XmlUtil {
/**
* Validation method.
*
* #param xmlFilePath The xml file we are trying to validate.
* #param xmlSchemaFilePath The schema file we are using for the validation. This method assumes the schema file is valid.
* #return True if valid, false if not valid or bad parse or exception/error during parse.
*/
public static boolean validate(String xmlFilePath, String xmlSchemaFilePath) {
// Try the validation, we assume that if there are any issues with the validation
// process that the input is invalid.
try {
SchemaFactory factory = new XMLSchemaFactory();
Source schemaFile = new StreamSource(new File(xmlSchemaFilePath));
Source xmlSource = new StreamSource(new File(xmlFilePath));
Schema schema = factory.newSchema(schemaFile);
Validator validator = schema.newValidator();
validator.validate(xmlSource);
} catch (SAXException e) {
return false;
} catch (IOException e) {
return false;
} catch (Exception e) {
// Catches everything beyond: SAXException, and IOException.
e.printStackTrace();
return false;
} catch (Error e) {
// Needed this for debugging when I was having issues with my 1st set of code.
e.printStackTrace();
return false;
}
return true;
}
}
Some Side Notes:
For creating the files, I made a simple file utility to write string to files:
public static void createFileFromString(String fileText, String fileName) {
try {
File file = new File(fileName);
BufferedWriter output = new BufferedWriter(new FileWriter(file));
output.write(fileText);
output.close();
} catch ( IOException e ) {
e.printStackTrace();
}
}
I also needed to write to an area that I had access to, so I made use of:
String path = this.getActivity().getPackageManager().getPackageInfo(getPackageName(), 0).applicationInfo.dataDir;
A little hackish, it works. I'm sure there is a more succinct way of doing this, however I figured I'd share my success, as there weren't any good examples that I found.

Categories