// Path: src/com/fieldexpert/fbapi4j/common/Attachment.java
// public class Attachment {
// 
// 	static {
// 		registerMimeDetector(ExtensionMimeDetector.class.getName());
// 		registerMimeDetector(MagicMimeMimeDetector.class.getName());
// 	}
// 
// 	public static String getType(File file) {
// 		Collection<?> types = getMimeTypes(file);
// 		return getMostSpecificMimeType(types).toString();
// 	}
// 
// 	public static String getType(InputStream is) {
// 		Collection<?> types = getMimeTypes(is);
// 		return getMostSpecificMimeType(types).toString();
// 	}
// 
// 	public static String getType(byte[] bytes) {
// 		Collection<?> types = getMimeTypes(bytes);
// 		return getMostSpecificMimeType(types).toString();
// 	}
// 
// 	private String filename;
// 	private String type;
// 	private InputStream content;
// 
// 	// not for you
// 	protected Attachment(String name) {
// 		this.filename = name;
// 	}
// 
// 	public Attachment(String filename, String type, byte[] content) {
// 		this(filename, type, new ByteArrayInputStream(content));
// 	}
// 
// 	public Attachment(String filename, String type, String content) {
// 		this(filename, type, content.getBytes(Charset.forName("UTF-8")));
// 	}
// 
// 	public Attachment(String filename, String type, InputStream content) {
// 		this.filename = filename;
// 		this.type = type;
// 		this.content = content;
// 	}
// 
// 	// can't chain this constructor call, because we need to try/catch
// 	public Attachment(File file) {
// 		Assert.notNull(file);
// 
// 		this.filename = file.getName();
// 		this.type = getType(file);
// 		try {
// 			this.content = new FileInputStream(file);
// 		} catch (Exception e) {
// 			throw new RuntimeException("Error reading file: '" + file.getName() + "'");
// 		}
// 	}
// 
// 	public InputStream getContent() {
// 		return content;
// 	}
// 
// 	public String getFilename() {
// 		return filename;
// 	}
// 
// 	public String getType() {
// 		return type;
// 	}
// }


import java.io.PrintWriter;
import java.io.StringWriter;
import com.fieldexpert.fbapi4j.common.Attachment;
package com.fieldexpert.fbapi4j;



public class DefaultCaseBuilder {

	private String project;
	private String area;

	public DefaultCaseBuilder(String project, String area) {
		this.project = project;
		this.area = area;
	}

	public Case build(Throwable t, boolean attachStackTrace) {
		StackTraceElement firstCause = getFirstCause(t).getStackTrace()[0];
		String className = firstCause.getClassName();
		String exceptionName = firstCause.getClass().getName();
		String fileName = firstCause.getFileName();
		int lineNumber = firstCause.getLineNumber();

		String title = exceptionName + " " + className + ":" + fileName + ":" + lineNumber;
		StringBuilder description = new StringBuilder();
		description.append(exceptionName + " \n");
		description.append(className + "\n");
		description.append(fileName + ":" + lineNumber + "\n");
		description.append("\n");

		StringWriter stackTraceWriter = new StringWriter();
		PrintWriter pw = new PrintWriter(stackTraceWriter);
		t.printStackTrace(pw);

		if (!attachStackTrace) {
			description.append(stackTraceWriter.toString());
		}

		Case fbCase = new Case(getProject(), getArea(), title, description.toString());

		if (attachStackTrace) {
// Path: src/com/fieldexpert/fbapi4j/common/Attachment.java
// public class Attachment {
// 
// 	static {
// 		registerMimeDetector(ExtensionMimeDetector.class.getName());
// 		registerMimeDetector(MagicMimeMimeDetector.class.getName());
// 	}
// 
// 	public static String getType(File file) {
// 		Collection<?> types = getMimeTypes(file);
// 		return getMostSpecificMimeType(types).toString();
// 	}
// 
// 	public static String getType(InputStream is) {
// 		Collection<?> types = getMimeTypes(is);
// 		return getMostSpecificMimeType(types).toString();
// 	}
// 
// 	public static String getType(byte[] bytes) {
// 		Collection<?> types = getMimeTypes(bytes);
// 		return getMostSpecificMimeType(types).toString();
// 	}
// 
// 	private String filename;
// 	private String type;
// 	private InputStream content;
// 
// 	// not for you
// 	protected Attachment(String name) {
// 		this.filename = name;
// 	}
// 
// 	public Attachment(String filename, String type, byte[] content) {
// 		this(filename, type, new ByteArrayInputStream(content));
// 	}
// 
// 	public Attachment(String filename, String type, String content) {
// 		this(filename, type, content.getBytes(Charset.forName("UTF-8")));
// 	}
// 
// 	public Attachment(String filename, String type, InputStream content) {
// 		this.filename = filename;
// 		this.type = type;
// 		this.content = content;
// 	}
// 
// 	// can't chain this constructor call, because we need to try/catch
// 	public Attachment(File file) {
// 		Assert.notNull(file);
// 
// 		this.filename = file.getName();
// 		this.type = getType(file);
// 		try {
// 			this.content = new FileInputStream(file);
// 		} catch (Exception e) {
// 			throw new RuntimeException("Error reading file: '" + file.getName() + "'");
// 		}
// 	}
// 
// 	public InputStream getContent() {
// 		return content;
// 	}
// 
// 	public String getFilename() {
// 		return filename;
// 	}
// 
// 	public String getType() {
// 		return type;
// 	}
// }


// Path: src/com/fieldexpert/fbapi4j/DefaultCaseBuilder.java
import java.io.PrintWriter;
import java.io.StringWriter;
import com.fieldexpert.fbapi4j.common.Attachment;

package com.fieldexpert.fbapi4j;



public class DefaultCaseBuilder {

	private String project;
	private String area;

	public DefaultCaseBuilder(String project, String area) {
		this.project = project;
		this.area = area;
	}

	public Case build(Throwable t, boolean attachStackTrace) {
		StackTraceElement firstCause = getFirstCause(t).getStackTrace()[0];
		String className = firstCause.getClassName();
		String exceptionName = firstCause.getClass().getName();
		String fileName = firstCause.getFileName();
		int lineNumber = firstCause.getLineNumber();

		String title = exceptionName + " " + className + ":" + fileName + ":" + lineNumber;
		StringBuilder description = new StringBuilder();
		description.append(exceptionName + " \n");
		description.append(className + "\n");
		description.append(fileName + ":" + lineNumber + "\n");
		description.append("\n");

		StringWriter stackTraceWriter = new StringWriter();
		PrintWriter pw = new PrintWriter(stackTraceWriter);
		t.printStackTrace(pw);

		if (!attachStackTrace) {
			description.append(stackTraceWriter.toString());
		}

		Case fbCase = new Case(getProject(), getArea(), title, description.toString());

		if (attachStackTrace) {
			Attachment attachment = new Attachment(exceptionName + ".txt", "text/plain", stackTraceWriter.toString());