Jme + xml

8 respostas
H

Olá, eu gostaria de saber se é possivel eu tratar uma xml em jme?
já fiz o download dela, mas até agora eu naum consegui pegar o conteudo?
alguem poderia me ajudar?
grato

8 Respostas

carlos.macleod

HJ:
Olá, eu gostaria de saber se é possivel eu tratar uma xml em jme?
grato

CLDC ou CDC ?

H

carlos.macleod:
HJ:
Olá, eu gostaria de saber se é possivel eu tratar uma xml em jme?
grato

CLDC ou CDC ?

CLDC

carlos.macleod

HJ:

CLDC

Pelo que me consta a CLDC não tem nenhuma implementação que te permita fazer isso de forma fácil. Vc vai ter de interpretar o XML “na unha”. Outra coisa, espero que receba o XML atraves de uma conexão, pois não conheço nenhuma forma de abrir arquivo em CLDC.

Se não for programar para celulares antigos, e sim para HandHelds e SmartPhones, aconselho utilizar CDC. Vai te evitar muita dor de cabeça e frustração.

Abraços,

Carlos MacLeod

http://java.sun.com/products/sjwtoolkit/download-2_3.html

H

carlos.macleod:
HJ:

CLDC

Pelo que me consta a CLDC não tem nenhuma implementação que te permita fazer isso de forma fácil. Vc vai ter de interpretar o XML “na unha”. Outra coisa, espero que receba o XML atraves de uma conexão, pois não conheço nenhuma forma de abrir arquivo em CLDC.

Se não for programar para celulares antigos, e sim para HandHelds e SmartPhones, aconselho utilizar CDC. Vai te evitar muita dor de cabeça e frustração.

Abraços,

mas eu posso programar para smartphone usando cdc?
se puder quais as alterações que preciso fazer?

Carlos MacLeod

http://java.sun.com/products/sjwtoolkit/download-2_3.html

carlos.macleod

Os smartphones ( tirando o iphone que ainda não tem JVM ) implementam CDC enão CLDC. Pra começar, jogar a maior parte do código de GUI fora, e aproveitar apenas tua regra de negócio ( espero que tenha separado os dois, hehehhehe )…

Com CDC vc programa quase que como se estivese fazendo uma aplicação Swing, e não com aqueles controles malucos do CLDC. No CLDC vc é limitado a persistencia em RecordStore ( eca !!! ), no CDC vc poderá utilizar algum outro framework. No meu caso utilizo o DB4O.

Qualquer coisa posta aí.

Abraços,

Carlos MacLeod

H

carlos.macleod:
HJ:

mas eu posso programar para smartphone usando cdc?
se puder quais as alterações que preciso fazer?

Os smartphones ( tirando o iphone que ainda não tem JVM ) implementam CDC enão CLDC. Pra começar, jogar a maior parte do código de GUI fora, e aproveitar apenas tua regra de negócio ( espero que tenha separado os dois, hehehhehe )…

Com CDC vc programa quase que como se estivese fazendo uma aplicação Swing, e não com aqueles controles malucos do CLDC. No CLDC vc é limitado a persistencia em RecordStore ( eca !!! ), no CDC vc poderá utilizar algum outro framework. No meu caso utilizo o DB4O.

Qualquer coisa posta aí.

Abraços,

Carlos MacLeod

Carlos, esse é o meu download, o resto do meu codigo é coisa simples, do tipo criar botão, login, essas coisas,
o q eu tenho que descartar seria isso ?

private void processRequest() throws IOException
	{

		String url2 = "http://h2jweb.com/xml/"+this.user.getString()+this.password.getString()+this.categoria+this.subcategoria+".xml";	
		HttpConnection http = null;
		InputStream iStrm = null;

		try
		{
			http = (HttpConnection) Connector.open(url2);
			http.setRequestMethod(HttpConnection.GET);
			http.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0");

			if (http.getResponseCode() == HttpConnection.HTTP_OK)
			{

				String str;
				iStrm = http.openInputStream();
				int length = (int) http.getLength();
				if (length != -1)
				{
					byte serverData[] = new byte[length];
					iStrm.read(serverData);
					str = new String(serverData);
				}
				else
				{
					ByteArrayOutputStream bStrm = new ByteArrayOutputStream();       

					int ch;
					while ((ch = iStrm.read()) != -1)
						bStrm.write(ch);

					str = new String(bStrm.toByteArray());
					bStrm.close();                
				}
				char palavra[] = new char[str.length()];
				int i=0, veritag=0, j=0;
				String tm = "";

				for(i=0; i<str.length();i++)
				{
					if(str.charAt(i) == '<')
					{
						veritag=1;	
						j=0;
					}



					if(veritag==1)
					{
						if((str.charAt(i) != '>')&&(str.charAt(i) != '<')&&(str.charAt(i) != '/')){
							palavra[j] = str.charAt(i);
							tm = tm + palavra[j];
							j++;
						}
					}

					if((str.charAt(i) == '>')||(str.charAt(i) == '/'))
					{
						veritag=0;

						System.out.println(tm);
						tm="";

					}
				}
			}
		}catch(Exception e){
			e.printStackTrace();

		}finally{
			if (iStrm != null)
				iStrm.close();
			if (http != null)
				http.close();
		}
	}

Abraços Júlio

carlos.macleod

Sim, o seu código para baixar o XML pode manter. Os códigos de criação de GUI ( componente visuais ) não serão aproveitados.


Abraços,

Carlos MacLeod

H

carlos.macleod:
HJ:

Carlos, esse é o meu download, o resto do meu codigo é coisa simples, do tipo criar botão, login, essas coisas,
o q eu tenho que descartar seria isso ?

Sim, o seu código para baixar o XML pode manter. Os códigos de criação de GUI ( componente visuais ) não serão aproveitados.


Abraços,

Carlos MacLeod

o que eu tenho de interface seria isso

public class h2j extends MIDlet implements CommandListener {
//	declarar variaveis
	private Display tela;
	private Command sair, ok, avancar, download, voltar;
	private Form fMain;
	private TextField user, password;
	int categoria = 0;
	private int subcategoria;
	private String errorMsg = null, str, titulo = "H2J - Consultas"; 
	private Alert alError;
	private List listaExclusiva;
	public h2j()
	{
		this.fMain = new Form(titulo);
		this.sair = new Command("Sair", Command.EXIT, 0);
		this.sair = new Command("Sair", Command.OK , 1);
		this.ok = new Command("OK", Command.SCREEN, 2);
		this.user = new TextField("Usuario ", "", 20, TextField.NUMERIC);
		this.password = new TextField("Senha    ", "", 20, TextField.ANY | TextField.PASSWORD);


//		relacionar Commands com Form

		this.fMain.append(this.user);
		this.fMain.append(this.password);
		this.fMain.addCommand(sair);
		this.fMain.addCommand(ok);
		this.fMain.setCommandListener(this);
	}

	protected void destroyApp(boolean i)
	{
	}

	protected void pauseApp() 
	{
	}

	protected void startApp() throws MIDletStateChangeException 
	{

//		obter tela do dispositivo
		this.tela = Display.getDisplay(this);
//		setar Displayable corrente para a tela
		this.tela.setCurrent(this.fMain);
	}

	public void commandAction(Command c, Displayable d)
	{
		if (c == this.sair)
		{
//			sair da aplicação
			this.destroyApp(true);
			this.notifyDestroyed();
		}

		if (c == this.avancar)
		{
			this.categoria = this.listaExclusiva.getSelectedIndex()+1;

			switch(this.categoria){
			case 1:
				String[] itensListaExclusiva = {"Panelas", "Outras Utilidades Domésticas", "Uten.p/  Praia em Esporte e Lazer", "Equip. / Veterinários", "Uten. para Churrasco", "Uten. para Corte / Costura", "Uten. Diversos para a Mamãe", "Uten. Alimentação do Bebê", "Uten.  Ferramentas para Jardim", "Uten. para Bar", "Utensílios de Limpez", "Utensílios para Banheiro"};

				this.listaExclusiva = new List("Selecione uma SubCategoria", Choice.EXCLUSIVE , itensListaExclusiva, null);

				this.download = new Command("Download", Command.SCREEN, 1);
				this.voltar = new Command("Voltar", Command.SCREEN, 2);

				this.tela.setCurrent(listaExclusiva);

				this.listaExclusiva.getString(listaExclusiva.getSelectedIndex());
				this.listaExclusiva.addCommand(this.download);
				this.listaExclusiva.addCommand(this.sair);
				this.listaExclusiva.addCommand(this.voltar);
				this.listaExclusiva.setCommandListener(this);
				break;

			case 2:
				String[] itensListaExclusiva1 = {"Calota / Pneu / Roda para Automóveis", "Equipamentos / Ferramentas Automotivas", "Farol / Lanterna para Automóveis", "Óleo / Aditivo para Automóveis", "Outros Acessórios / Peças para Automóveis", "Produtos de Limpeza para Automóveis", "Produtos de Segurança para Automóveis", "Som Automotivo", "Tuning para Automóveis"};

				this.listaExclusiva = new List("Selecione uma SubCategoria", Choice.EXCLUSIVE , itensListaExclusiva1, null);

				this.download = new Command("Download", Command.SCREEN, 1);
				this.voltar = new Command("Voltar", Command.SCREEN, 2);

				this.tela.setCurrent(listaExclusiva);

				this.listaExclusiva.getString(listaExclusiva.getSelectedIndex());
				this.listaExclusiva.addCommand(this.download);
				this.listaExclusiva.addCommand(this.sair);
				this.listaExclusiva.addCommand(this.voltar);
				this.listaExclusiva.setCommandListener(this);
				break;

			case 3:
				String[] itensListaExclusiva2 = {"Bebida", "Biscoito", "Bomboniere", "Diet e Light", "Feira", "Vinho e Espumante", "Padaria", "Leite e Iogurte", "Mercearia", "Mercearia Doce"};

				this.listaExclusiva = new List("Selecione uma SubCategoria", Choice.EXCLUSIVE , itensListaExclusiva2, null);

				this.download = new Command("Download", Command.SCREEN, 1);
				this.voltar = new Command("Voltar", Command.SCREEN, 2);

				this.tela.setCurrent(listaExclusiva);

				this.listaExclusiva.getString(listaExclusiva.getSelectedIndex());
				this.listaExclusiva.addCommand(this.download);
				this.listaExclusiva.addCommand(this.sair);
				this.listaExclusiva.addCommand(this.voltar);
				this.listaExclusiva.setCommandListener(this);
				break;

			case 4:
				String[] itensListaExclusiva3 = {"Alvejante & Cia", "Desodorizador Casa", "Álcool & Removedor", "Amaciante & Cia", "Cera & Cia", "Desinfetante", "Desodorizador WC", "Detergente", "Inseticida e Raticida", "Limpeza da Cozinha", "Limpeza da Roupa", "Limpeza de Calçado", "Limpeza Pesada", "Lixeira e Saco", "Multi - Uso & Cia", "Lustra Móveis & Cia"};

				this.listaExclusiva = new List("Selecione uma SubCategoria", Choice.EXCLUSIVE , itensListaExclusiva3, null);

				this.download = new Command("Download", Command.SCREEN, 1);
				this.voltar = new Command("Voltar", Command.SCREEN, 2);

				this.tela.setCurrent(listaExclusiva);

				this.listaExclusiva.getString(listaExclusiva.getSelectedIndex());
				this.listaExclusiva.addCommand(this.download);
				this.listaExclusiva.addCommand(this.sair);
				this.listaExclusiva.addCommand(this.voltar);
				this.listaExclusiva.setCommandListener(this);
				break;

			case 5:
				String[] itensListaExclusiva4 = {"Home Theater", "Televisores", "DVD Players", "Som Automotivo", "Áudio", "Cabos", "Antenas"};

				this.listaExclusiva = new List("Selecione uma SubCategoria", Choice.EXCLUSIVE , itensListaExclusiva4, null);

				this.download = new Command("Download", Command.SCREEN, 1);
				this.voltar = new Command("Voltar", Command.SCREEN, 2);

				this.tela.setCurrent(listaExclusiva);

				this.listaExclusiva.getString(listaExclusiva.getSelectedIndex());
				this.listaExclusiva.addCommand(this.download);
				this.listaExclusiva.addCommand(this.sair);
				this.listaExclusiva.addCommand(this.voltar);
				this.listaExclusiva.setCommandListener(this);
				break;

			case 6:
				String[] itensListaExclusiva5 = {"Computadores", "Notebooks", "Impressão e Imagem", "Banda Larga e Rede sem Fio", "Palm Tops", "Armazenamento", "Acessórios e Periféricos", "Componentes e Peças", "Softwares"};

				this.listaExclusiva = new List("Selecione uma SubCategoria", Choice.EXCLUSIVE , itensListaExclusiva5, null);

				this.download = new Command("Download", Command.SCREEN, 1);
				this.voltar = new Command("Voltar", Command.SCREEN, 2);

				this.tela.setCurrent(listaExclusiva);

				this.listaExclusiva.getString(listaExclusiva.getSelectedIndex());
				this.listaExclusiva.addCommand(this.download);
				this.listaExclusiva.addCommand(this.sair);
				this.listaExclusiva.addCommand(this.voltar);
				this.listaExclusiva.setCommandListener(this);
				break;

			case 7:
				String[] itensListaExclusiva6 = {"Ar-Condicionado", "Refrigeradores", "Máquina de Gelo", "Microondas", "Lavadoras de Roupas", "Fogões de Piso", "Fogões de Embutir", "Coifas", "Depuradores", "Freezeres", "Lavalouças", "Secadoras"};

				this.listaExclusiva = new List("Selecione uma SubCategoria", Choice.EXCLUSIVE , itensListaExclusiva6, null);

				this.download = new Command("Download", Command.SCREEN, 1);
				this.voltar = new Command("Voltar", Command.SCREEN, 2);

				this.tela.setCurrent(listaExclusiva);

				this.listaExclusiva.getString(listaExclusiva.getSelectedIndex());
				this.listaExclusiva.addCommand(this.download);
				this.listaExclusiva.addCommand(this.sair);
				this.listaExclusiva.addCommand(this.voltar);
				this.listaExclusiva.setCommandListener(this);
				break;

			case 8:
				String[] itensListaExclusiva7 = {"Balanças", "Barbeadores", "Chapinhas (Pranchas)", "Depiladores", "Escovas de Cabelo", "Máquinas de Cortar Cabelo", "Massageadores", "Modeladores", "Manicuro/Pedicuro", "Perfumes", "Secadores", "Tratamento para Cabelos", "Cuidados com o corpo", "Absorventes", "Alimentos Naturais", "Bengalas/Muletas", "Bolsas Térmicas", "Cadeiras de Roda", "Dilatador Nasal", "Estetoscópios", "Fisioterapia", "Higiene Bucal", "Inaladores", "Medidores de Glicose"};

				this.listaExclusiva = new List("Selecione uma SubCategoria", Choice.EXCLUSIVE , itensListaExclusiva7, null);

				this.download = new Command("Download", Command.SCREEN, 1);
				this.voltar = new Command("Voltar", Command.SCREEN, 2);

				this.tela.setCurrent(listaExclusiva);

				this.listaExclusiva.getString(listaExclusiva.getSelectedIndex());
				this.listaExclusiva.addCommand(this.download);
				this.listaExclusiva.addCommand(this.sair);
				this.listaExclusiva.addCommand(this.voltar);
				this.listaExclusiva.setCommandListener(this);
				break;

			}   

		}

		if (c == this.voltar)
		{
			this.categoria();
		}

		if (c == this.download)
		{
			switch(this.categoria){
			case 1:
				this.subcategoria = this.listaExclusiva.getSelectedIndex()+1;
				this.downloadXML();
				break;

			case 2:
				this.subcategoria = this.listaExclusiva.getSelectedIndex()+13;
				this.downloadXML();
				break;

			case 3:
				this.subcategoria = this.listaExclusiva.getSelectedIndex()+22;
				this.downloadXML();
				break;

			case 4:
				this.subcategoria = this.listaExclusiva.getSelectedIndex()+32;
				this.downloadXML();
				break;

			case 5:
				this.subcategoria = this.listaExclusiva.getSelectedIndex()+48;
				this.downloadXML();
				break;

			case 6:
				this.subcategoria = this.listaExclusiva.getSelectedIndex()+56;
				this.downloadXML();
				break;

			case 7:
				this.subcategoria = this.listaExclusiva.getSelectedIndex()+64;
				this.downloadXML();
				break;

			case 8:
				this.subcategoria = this.listaExclusiva.getSelectedIndex()+76;
				this.downloadXML();
				break;

			} 
		}


		if(c == this.ok)
		{
			//chama a conexão HTTP
			try 
			{ 
				lookupBalance_withGET(); 

			} 
			catch (Exception e) 
			{ 
				System.out.println("Msg: " + e.toString()); 
			}

		}


	}

tipo são textfield e command, como teria que alterar?

Abraços Julio Coelho

Criado 17 de julho de 2008
Ultima resposta 18 de jul. de 2008
Respostas 8
Participantes 2