Package de.innovationgate.eclipse.wgadesigner.console

Source Code of de.innovationgate.eclipse.wgadesigner.console.TMLWarning

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.wgadesigner.console;

import java.io.IOException;
import java.text.ParseException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import de.innovationgate.utils.WGUtils;

public class TMLWarning {
 
  private String _resource;
  private String _medium;
  private String _db;
  private int _line;
  private String _message;
 
  public static TMLWarning parse(String content) throws ParseException {
        if (content != null) {
            if (content.contains("WARN TML warning - Resource:")) {    
                return parseWGA52Log(content);
            } else if (content.contains("WARN TML warning - Layout:")) {
                return parseWGA53Log(content);             
            }
        }
        throw new ParseException("Unable to parse TMLWarning", -1);
    }
   
    private static TMLWarning parseWGA52Log(String content) throws ParseException {
        try {
            TMLWarning warning = new TMLWarning();
            int start = content.indexOf("Resource:");
            int end = -1;
            if (start != -1) {
                start += "Resource:".length();
                end = content.indexOf("- Tag type:", start);
            }
            if (end != -1) {
                String resource = content.substring(start, end);
                // extract  medium and line
                Matcher matcher =Pattern.compile("\\(.*\\)").matcher(resource);
                while (matcher.find()) {
                    String group = matcher.group();
                    String[] parts = group.split("\\) \\(");
                    if (parts.length == 2) {
                        warning.setMedium(parts[0].substring(1));
                        String line = parts[1].substring(0, parts[1].length()-1);
                        line = line.substring(line.indexOf(" ")).trim();
                        try {
                            warning.setLine(Integer.parseInt(line));
                        } catch (NumberFormatException e) {
                            warning.setLine(-1);
                        }
                    }
                }
                resource = resource.trim();
                resource = resource.substring(0, resource.indexOf(" "));
                warning.setResource(resource);
            }
           
            start = content.indexOf("- Context");
            end = -1;
            if (start != -1) {
                start += "- Context".length();
                end = content.indexOf("- Message:", start);
            }
            if (end != -1) {
                String temp = content.substring(start, end);
                // extract  medium and line
                Matcher matcher =Pattern.compile("\\(.*\\)").matcher(temp);
                if (matcher.find()) {
                    String group = matcher.group();
                    warning.setDb(group.substring(1, group.length()-1));
                }
            }
           
            start = content.indexOf("- Message:");
            end = -1;
            if (start != -1) {
                start += "- Message:".length();
                end = content.length();
            }
            if (end != -1) {
                String temp = content.substring(start, end);
                try {
                    temp = WGUtils.toPlainText(temp.trim(), "\n", false);
                    if (temp.startsWith("TypeError executing tmlscript:")) {
                        temp = temp.substring("TypeError executing tmlscript:".length());
                    }
                    warning.setMessage(temp);
                } catch (IOException e) {
                }          
            }
           
            return warning;
        } catch (Exception e) {
            ParseException ex = new ParseException("Unable to parse TMLWarning: " + e.getMessage(), -1);
            ex.setStackTrace(e.getStackTrace());
            throw ex;
        }
    }

    private static TMLWarning parseWGA53Log(String content) throws ParseException {
        try {
            TMLWarning warning = new TMLWarning();
            int start = content.indexOf("Layout:");
            int end = -1;
            if (start != -1) {
                start += "Layout:".length();
                end = content.indexOf("- Tag type:", start);
            }
            if (end != -1) {
                String resource = content.substring(start, end);
                // extract  medium and line
                Matcher matcher =Pattern.compile("\\(.*\\)").matcher(resource);
                while (matcher.find()) {
                    String group = matcher.group();
                    String[] parts = group.split("\\) \\(");
                    if (parts.length == 2) {
                        warning.setMedium(parts[0].substring(1));
                        String line = parts[1].substring(0, parts[1].length()-1);
                        line = line.substring(line.indexOf(" ")).trim();
                        try {
                            warning.setLine(Integer.parseInt(line));
                        } catch (NumberFormatException e) {
                            warning.setLine(-1);
                        }
                    }
                }
                resource = resource.trim();
                resource = resource.substring(0, resource.indexOf(" "));
               
               
                warning.setDb(resource.split("/")[0]);
                warning.setResource(resource.split("/")[1]);               
            }          
           
            start = content.indexOf("- Message:");
            end = -1;
            if (start != -1) {
                start += "- Message:".length();
                end = content.length();
            }
            if (end != -1) {
                String temp = content.substring(start, end);
                try {
                    temp = WGUtils.toPlainText(temp.trim(), "\n", false);
                    if (temp.startsWith("TypeError executing tmlscript:")) {
                        temp = temp.substring("TypeError executing tmlscript:".length());
                    }
                    warning.setMessage(temp);
                } catch (IOException e) {
                }          
            }
           
            return warning;
        } catch (Exception e) {
            ParseException ex = new ParseException("Unable to parse TMLWarning: " + e.getMessage(), -1);
            ex.setStackTrace(e.getStackTrace());
            throw ex;
        }
    }

  public String getResource() {
    return _resource;
  }

  private void setResource(String resource) {
    _resource = resource;
  }

  public String toString() {
    return "Resource: '" + _resource + "' Line: '" + _line + "' medium: '" + _medium + "' Database: '" + _db + "'";
  }

  public String getMedium() {
    return _medium;
  }

  private void setMedium(String medium) {
    _medium = medium;
  }

  public int getLine() {
    return _line;
  }

  private void setLine(int line) {
    _line = line;
  }

  public String getDb() {
    return _db;
  }

  private void setDb(String db) {
    _db = db;
  }

  public String getMessage() {
    return _message;
  }

  private void setMessage(String message) {
    _message = message;
  }
}
TOP

Related Classes of de.innovationgate.eclipse.wgadesigner.console.TMLWarning

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.