Tabulação automática

9 respostas
falvesti

Fala pessoal tudo certo?

Estou com o seguinte problema:

Tenho um arquivo de texto que é carregado em uma String. Neste arquivo eu defini alguns trechos que irei substituir dinamicamente com o java.

Exemplo do arquivo:

while(rs.next()){
    [parteASerSubstituida]
}

Neste exemplo eu preciso substituir este trecho: [parteASerSubstituida]

Até ai tudo bem, usei o método replace da classe String.

O meu problema acontece quando o que preciso inserir no lugar de [parteASerSubstituida] é composto por várias linhas e as mesmas necessitam ser alinhadas.

Exemplo do código substituído com várias linhas:

while(rs.next()){
    linha1();
    linha2();
    linha3();
    linha4();
}

Do modo que estou fazendo esta ficando assim:

while(rs.next()){
    linha1();
linha2();
linha3();
linha4();
}

O único modo que eu encontrei foi “chumbar” o número de tabulações com o “\tab”, porém caso eu mude de posição não funciona mais.

Alguém tem alguma idéia ou uma dica de como resolver esse problema?

Obrigado!!!

9 Respostas

falvesti

Ninguem?

A

Não ficou claro o que as funções “linha()” fazem…

falvesti
package [packageName];

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class [domainClassName]DAO {

	private Connection connection;
	
	public [className](Connection connection) throws SQLException {
		this.connection = connection;
	}
	
	public void insert([domainClassName] [domainObjectName]) throws SQLException {
		PreparedStatement stmt = this.connection
				.prepareStatement("[insertSQLStatement]");

		[setInsertStatements]

		stmt.execute();
		stmt.close();
	}
	
	public void update([domainClassName] [domainObjectName]) throws SQLException {

		PreparedStatement stmt = this.connection
				.prepareStatement("[updateSQLStatement]");

		[setUpdateStatements]

		stmt.execute();
		stmt.close();
	}
	
	public void delete([domainClassName] [domainObjectName]) throws SQLException{
		
		PreparedStatement stmt = this.connection.prepareStatement("[deleteSQLStatement]");
		
		[setDeleteStatements]
		
		stmt.execute();
		stmt.close();
	}
	
	public List <[domainObjectName]> select() throws SQLException {
		PreparedStatement stmt = this.connection
				.prepareStatement("[selectSQLStatement]");

		ResultSet rs = stmt.executeQuery();
		List<[domainClassName]> [toListName] = new ArrayList<[domainClassName]>();
		while (rs.next()) {
			[domainClassName] [domainObjectName] = new [domainClassName]();
			[setObjectAtributesStatement]
			[toListName].add([domainObjectName]);
		}
		rs.close();
		stmt.close();
		return [toListName];
	}
		
}
falvesti
package br.org.skenp;

public class Cliente{
	
	private String cliNome;
	private Estado estId;
	private int cliId;
	
	public Cliente(){
	}	

	public String getCliNome() {
		return cliNome;
	}
	
	public Estado getEstId() {
		return estId;
	}
	
	public int getCliId() {
		return cliId;
	}	

	public void setCliNome(String cliNome){
		this.cliNome = cliNome;
	}
	
	public void setEstId(Estado estId){
		this.estId = estId;
	}
	
	public void setCliId(int cliId){
		this.cliId = cliId;
	}	
	 
	public String toString(){
		String toString = "cliNome:" + this.cliNome + 
		"cliId:" + this.cliId + "";
		return toString;
	}
}
falvesti
package br.org.skenp;

public class Estado{

	private int estId;
	private String estDescricao;
	private String estUf;
	
	public Estado(){
	}

	public int getEstId() {
		return estId;
	}

	public String getEstDescricao() {
		return estDescricao;
	}
	
	public String getEstUf() {
		return estUf;
	}

	public void setEstId(int estId){
		this.estId = estId;
	}

	public void setEstDescricao(String estDescricao){
		this.estDescricao = estDescricao;
	}
	
	public void setEstUf(String estUf){
		this.estUf = estUf;
	}

	public String toString(){
		String toString = "estId:" + this.estId + 
		"estDescricao:" + this.estDescricao + 
		"estUf:" + this.estUf + "";
		return toString;
	}
}
falvesti
package br.org.skenp;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ClienteDAO {

	private Connection connection;
	
	public Cliente(Connection connection) throws SQLException {
		this.connection = connection;
	}
	
	public void insert(Cliente cliente) throws SQLException {
		PreparedStatement stmt = this.connection
				.prepareStatement("insert into CLIENTE (CLI_NOME, CLI_ID) values(?, ?) ");

		stmt.setString(1, cliente.getCliNome());
		stmt.setInt(2, cliente.getCliId());

		stmt.execute();
		stmt.close();
	}
	
	public void update(Cliente cliente) throws SQLException {

		PreparedStatement stmt = this.connection
				.prepareStatement("update CLIENTE set CLI_NOME = ?, CLI_ID = ? where CLI_ID = ?");

		stmt.setString(1, cliente.getCliNome());
		stmt.setInt(2, cliente.getCliId());
		stmt.setInt(3, cliente.getCliId());

		stmt.execute();
		stmt.close();
	}
	
	public void delete(Cliente cliente) throws SQLException{
		
		PreparedStatement stmt = this.connection.prepareStatement("delete from CLIENTE where CLI_ID = ?");
		
		stmt.setInt(1, cliente.getCliId());
		
		stmt.execute();
		stmt.close();
	}
	
	public List <cliente> select() throws SQLException {
		PreparedStatement stmt = this.connection
				.prepareStatement("select * from CLIENTE");

		ResultSet rs = stmt.executeQuery();
		List<Cliente> clienteList = new ArrayList<Cliente>();
		while (rs.next()) {
			Cliente cliente = new Cliente();
			cliente.setCliNome(rs.getAcertar("CLI_NOME"));
			cliente.setCliId(rs.getAcertar("CLI_ID"));
			clienteList.add(cliente);
		}
		rs.close();
		stmt.close();
		return clienteList;
	}
		
}
falvesti
package br.org.skenp;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class EstadoDAO {

	private Connection connection;
	
	public Estado(Connection connection) throws SQLException {
		this.connection = connection;
	}
	
	public void insert(Estado estado) throws SQLException {
		PreparedStatement stmt = this.connection
				.prepareStatement("insert into ESTADO (EST_ID, EST_DESCRICAO, EST_UF) values(?, ?, ?) ");

		stmt.setInt(1, estado.getEstId());
		stmt.setString(2, estado.getEstDescricao());
		stmt.setString(3, estado.getEstUf());

		stmt.execute();
		stmt.close();
	}
	
	public void update(Estado estado) throws SQLException {

		PreparedStatement stmt = this.connection
				.prepareStatement("update ESTADO set EST_ID = ?, EST_DESCRICAO = ?, EST_UF = ? where EST_ID = ?");

		stmt.setInt(1, estado.getEstId());
		stmt.setString(2, estado.getEstDescricao());
		stmt.setString(3, estado.getEstUf());
		stmt.setInt(4, estado.getEstId());

		stmt.execute();
		stmt.close();
	}
	
	public void delete(Estado estado) throws SQLException{
		
		PreparedStatement stmt = this.connection.prepareStatement("delete from ESTADO where EST_ID = ?");
		
		stmt.setInt(1, estado.getEstId());
		
		stmt.execute();
		stmt.close();
	}
	
	public List <estado> select() throws SQLException {
		PreparedStatement stmt = this.connection
				.prepareStatement("select * from ESTADO");

		ResultSet rs = stmt.executeQuery();
		List<Estado> estadoList = new ArrayList<Estado>();
		while (rs.next()) {
			Estado estado = new Estado();
			estado.setEstId(rs.getInt("EST_ID"));
			estado.setEstDescricao(rs.getString("EST_DESCRICAO"));
			estado.setEstUf(rs.getString("EST_UF"));
			estadoList.add(estado);
		}
		rs.close();
		stmt.close();
		return estadoList;
	}
		
}
falvesti
<html>
<body>
<form name="myform" action="" >
CliNome <input type="text" name="cliNome" maxlength="[telefone removido]" value=""><br>
EstId <select name="estado.estId" ></select><br>
CliId <input type="text" name="cliId" maxlength="10" value="nextval('"CLIENTE_CLI_ID_seq"'::regclass)"><br>

</form>
</body>
</html>
falvesti
<html>
<body>
<form name="myform" action="" >
EstId <input type="text" name="estId" maxlength="10" value=""><br>
EstDescricao <input type="text" name="estDescricao" maxlength="[telefone removido]" value=""><br>
EstUf <input type="text" name="estUf" maxlength="2" value=""><br>

</form>
</body>
</html>
Criado 25 de outubro de 2007
Ultima resposta 13 de nov. de 2007
Respostas 9
Participantes 2