Example usage for javax.xml.bind ValidationException getMessage

List of usage examples for javax.xml.bind ValidationException getMessage

Introduction

In this page you can find the example usage for javax.xml.bind ValidationException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.pepstock.jem.ant.AntFactory.java

@Override
public void init(Properties properties) throws JemException {
    super.init(properties);

    // missing enable multiple validator type like xslt, java, groovy
    String xsltvalidatorFile = getProperties().getProperty(AntKeys.ANT_XSLTPROJECTVALIDATOR);
    if (xsltvalidatorFile != null && !xsltvalidatorFile.isEmpty()) {
        if (validator == null) {
            validator = new TransformerValidator();
        }//from  w  w  w .ja v  a 2s . c  o  m
        // load a validator and initialize it with the xslt document (this is persisted in
        // memory and watched for changed)
        try {
            validator.load(xsltvalidatorFile);
        } catch (ValidationException e) {
            throw new JemException(e.getMessage(), e);
        }
    }
}

From source file:org.pepstock.jem.ant.AntFactory.java

/**
 * It validates XML syntax of ANT source code. <br>
 * Creates an ANT project object, extracting all information.<br>
 * For job name, uses the <code>name</code> attribute value for property
 * element inside of project element, to set job Name. If is missing, JEM
 * uses <code>name</code> attribute value for project.
 * /*from   w  w  w  . ja  v a  2s  .  co m*/
 * @param jcl JCL instance with source code
 * @param file file reference for JCL
 * @throws ValidationException if IO error or job name not set a exception
 *             occurs
 */
private void validate(Jcl jcl, File file) throws AntException {
    // creates an ANT empty project
    Project p = new Project();
    // initializes properties
    // we need to set ant.file prop
    p.initProperties();
    // sets base dir , current directory and set property for JCL
    // file name to use
    p.setBasedir(ANT_BASE_DIR);
    p.setUserProperty("ant.file", file.getAbsolutePath());

    // initializes it
    p.init();

    // creates the helper to parse JCL ANT file
    ProjectHelper helper = ProjectHelper.getProjectHelper();
    p.addReference("ant.projectHelper", helper);

    // parse it. If there is any syntax error, throw a BuildException, 
    // but it tries to get JobName!!
    try {
        helper.parse(p, file);
    } catch (BuildException ex) {
        String jobName = (p.getName() != null) ? p.getName() : p.getProperty(AntKeys.ANT_JOB_NAME);
        jcl.setJobName(jobName);
        throw ex;
    }
    // if I'm here, JCL is correct

    // checks if project has attribute name, if yes, uses it as JOB NAME
    // otherwise get the JEM property to define it
    String jobName = (p.getName() != null) ? p.getName() : p.getProperty(AntKeys.ANT_JOB_NAME);

    // Anyway job name can't be null. if yes, exception occurs
    if (jobName == null) {
        throw new AntException(AntMessage.JEMA031E);
    }

    // extracts the locking scope and checks if the value is correct
    // the value is not save in JCL because is not helpful to node but
    // at runtime so it will be read again from ANT listener
    String lockingScopeProperty = p.getProperty(AntKeys.ANT_LOCKING_SCOPE);
    if (lockingScopeProperty != null && !lockingScopeProperty.equalsIgnoreCase(AntKeys.ANT_JOB_SCOPE)
            && !lockingScopeProperty.equalsIgnoreCase(AntKeys.ANT_STEP_SCOPE)
            && !lockingScopeProperty.equalsIgnoreCase(AntKeys.ANT_TASK_SCOPE)) {
        throw new AntException(AntMessage.JEMA032E, AntKeys.ANT_LOCKING_SCOPE, lockingScopeProperty);
    }

    // Extracts from ANT enviroment property
    String environment = p.getProperty(AntKeys.ANT_ENVIRONMENT);
    // if null, uses current environment assigned to JEM NODE
    if (environment == null) {
        environment = Main.EXECUTION_ENVIRONMENT.getEnvironment();
    }

    // Extracts from ANT domain property
    String domain = p.getProperty(AntKeys.ANT_DOMAIN);
    // if null, uses domain default
    if (domain == null) {
        domain = Jcl.DEFAULT_DOMAIN;
    }

    // Extracts from ANT email addresses notification property
    String emailAddresses = p.getProperty(AntKeys.ANT_EMAILS_NOTIFICATION);
    if (null != emailAddresses) {
        jcl.setEmailNotificationAddresses(emailAddresses);
    }
    // Extracts from ANT affinity property
    String affinity = p.getProperty(AntKeys.ANT_AFFINITY);
    // if null, uses affinity default
    if (affinity == null) {
        affinity = Jcl.DEFAULT_AFFINITY;
    }

    // Extracts from ANT user property
    String user = p.getProperty(AntKeys.ANT_USER);
    if (null != user) {
        jcl.setUser(user);
    }

    // Extracts from ANT classpath property
    String classPath = p.getProperty(AntKeys.ANT_CLASSPATH);
    // if classpath is not set, changes if some variables are in
    if (classPath != null) {
        jcl.setClassPath(super.resolvePathNames(classPath, ConfigKeys.JEM_CLASSPATH_PATH_NAME));
    }

    // Extracts from ANT prior classpath property
    String priorClassPath = p.getProperty(AntKeys.ANT_PRIOR_CLASSPATH);
    // if classpath is not set, changes if some variables are in
    if (priorClassPath != null) {
        jcl.setPriorClassPath(super.resolvePathNames(priorClassPath, ConfigKeys.JEM_CLASSPATH_PATH_NAME));
    }

    // Extracts from ANT memory property. If missing, default is 256 
    int memory = Parser.parseInt(p.getProperty(AntKeys.ANT_MEMORY), Jcl.DEFAULT_MEMORY);
    // Extracts from ANT hold property. If missing, default is FALSE
    boolean hold = Parser.parseBoolean(p.getProperty(AntKeys.ANT_HOLD), false);
    // Extracts from ANT priority property. If missing, default is 10
    int priority = Parser.parseInt(p.getProperty(AntKeys.ANT_PRIORITY), Jcl.DEFAULT_PRIORITY);

    // saves all info inside of JCL object for further computing
    jcl.setJobName(jobName);
    jcl.setEnvironment(environment);
    jcl.setDomain(domain);
    jcl.setAffinity(affinity);
    jcl.setHold(hold);
    jcl.setPriority(priority);
    jcl.setMemory(memory);

    // apply custom validation rules loaded from an xlst grammar
    if (validator != null) {
        try {
            validator.validate(jcl);
        } catch (ValidationException e) {
            throw new AntException(AntMessage.JEMA047E, e, e.getMessage());
        }
    }
}

From source file:org.romaframework.aspect.view.html.HtmlServlet.java

/**
 * Given a request it must understand the action to be performed and bind the pojos, finally it call the display to write the
 * result html on the response//from  w w  w .  ja  v a 2  s . c om
 */
@Override
public void service(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    try {
        HttpSession httpSession = request.getSession(true);

        if (!isStarted(httpSession)) {
            httpSession = request.getSession(true);
            startUserSession(request, response);

            setStarted(httpSession);
        } else if (RestServiceHelper.existsServiceToInvoke(request)) {
            RestServiceHelper.invokeRestService(request, response);
            RestServiceHelper.clearSession(request);
        }

        removePreviousPushCommands(request);

        final RequestParser requestParser = Roma.component(RequestParser.class);

        try {
            requestParser.parseRequest(request);
        } catch (final ValidationException e) {
            ErrorMessageTextDetail toShow = new ErrorMessageTextDetail("application.error", "Application Error",
                    e);
            toShow.setMessage(e.getMessage());
            toShow.setDetail(ExceptionHelper.toString(e));
            Roma.flow().forward(toShow, "popup", null, Roma.session().getActiveSessionInfo());
        } catch (final BindingException e) {
            ErrorMessageTextDetail toShow = new ErrorMessageTextDetail("application.error", "Application Error",
                    e);
            toShow.setMessage(e.getMessage());
            toShow.setDetail(ExceptionHelper.toString(e));
            Roma.flow().forward(toShow, "popup", null, Roma.session().getActiveSessionInfo());
        } catch (final Throwable e) {
            ErrorMessageTextDetail toShow = new ErrorMessageTextDetail("application.error", "Application Error",
                    e);
            toShow.setMessage(e.getMessage());
            toShow.setDetail(ExceptionHelper.toString(e));
            Roma.flow().forward(toShow, "popup", null, Roma.session().getActiveSessionInfo());
            // throw new ServletException(e);
        }

        Boolean redirected = (Boolean) request.getAttribute(HtmlViewAspectHelper.REDIRECTED);
        if (redirected != null && redirected) {
            request.setAttribute(HtmlViewAspectHelper.REDIRECTED, Boolean.FALSE);
            return;
        }

        renderResponse(request, response);
    } finally {

        HtmlViewAspectHelper.removeCssBuffer();
        HtmlViewAspectHelper.removeJsBuffer();
    }
}