Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú$postTitle = $_POST["postTitle"];
$titleTokens = explode(" ", $postTitle);
$warningWords = ["cómo","como","quiero","ser","hacker"];
$warningWordsCounter = 0;
foreach($titleTolens as $token) {
foreach($warningWords as $word) {
if(strtolower($token) == $word)
$warningWordsCounter++;
}
}
echo $warningWordsCounter;
public void exportProducts(List<ProductVO> products) {
try(ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("D:\\products.obj"))) {
for(ProductVO product : products)
out.writeObject(product);
} catch(FileNotFoundException ex) {
ex.printStackTrace();
} catch(IOException ex2) {
ex2.printStackTrace();
}
}
/**
*
* @author Gus
*/
public class Board {
private String name;
private int towersNumber;
public Board() {}
public Board(String name, int towersNumber) {
this.name = name;
this.towersNumber = towersNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getTowersNumber() {
return towersNumber;
}
public void setTowersNumber(int towersNumber) {
this.towersNumber = towersNumber;
}
}
package net.elhacker.jaxbexample.model.entities;
/**
*
* @author Gus
*/
public class Tower {
private String name;
private int xAxis;
private int yAxis;
public Tower() {}
public Tower(String name, int xAxis, int yAxis) {
this.name = name;
this.xAxis = xAxis;
this.yAxis = yAxis;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getxAxis() {
return xAxis;
}
public void setxAxis(int xAxis) {
this.xAxis = xAxis;
}
public int getyAxis() {
return yAxis;
}
public void setyAxis(int yAxis) {
this.yAxis = yAxis;
}
}
package net.elhacker.jaxbexample.model.entities;
/**
*
* @author Gus
*/
public class Disc {
private int xAxis;
private int yAxis;
public Disc() {}
public Disc(int xAxis, int yAxis) {
this.xAxis = xAxis;
this.yAxis = yAxis;
}
public int getxAxis() {
return xAxis;
}
public void setxAxis(int xAxis) {
this.xAxis = xAxis;
}
public int getyAxis() {
return yAxis;
}
public void setyAxis(int yAxis) {
this.yAxis = yAxis;
}
}
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import net.elhacker.jaxbexample.model.entities.Board;
import net.elhacker.jaxbexample.model.entities.Disc;
import net.elhacker.jaxbexample.model.entities.Tower;
/**
*
* @author Gus
*/
@XmlRootElement(name="HanoiTower")
@XmlAccessorType(XmlAccessType.FIELD)
public class HanoiTower {
@XmlElement
public Tower tower;
@XmlElement
public Board board;
@XmlElement
public int playingTowers;
@XmlElement
public Disc disc;
public HanoiTower() {
}
public Tower getTower() {
return tower;
}
public void setTower(Tower tower) {
this.tower = tower;
}
public Board getBoard() {
return board;
}
public void setBoard(Board board) {
this.board = board;
}
public Disc getDisc() {
return disc;
}
public void setDisc(Disc disc) {
this.disc = disc;
}
public int getPlayingTowers() {
return playingTowers;
}
public void setPlayingTowers(int playingTowers) {
this.playingTowers = playingTowers;
}
}
import java.io.File;
import java.util.logging.Logger;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
/**
*
* @author Gus
*/
public class HanoiTowerMarshaller {
private static JAXBContext jaxbContext;
private static Logger logger;
public HanoiTowerMarshaller() {
try {
jaxbContext = JAXBContext.newInstance(HanoiTower.class);
logger = Logger.getLogger(HanoiTowerMarshaller.class.getName());
} catch(JAXBException ex) {
logger.warning(ex.getMessage());
}
}
public void marshal(HanoiTower hanoiTower) {
try {
File file = new File("D:\\hanoi-tower.xml");
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(hanoiTower, file);
jaxbMarshaller.marshal(hanoiTower, System.out);
} catch(JAXBException ex) {
logger.warning(ex.getMessage());
}
}
public HanoiTower unmarshall(String filePath) {
HanoiTower hanoiTower = null;
try {
File xml = new File(filePath);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
hanoiTower = (HanoiTower) jaxbUnmarshaller.unmarshal(xml);
} catch (JAXBException ex) {
logger.warning(ex.getMessage());
}
return hanoiTower;
}
}
package jaxbexample;
import net.elhacker.jaxbexample.model.entities.Board;
import net.elhacker.jaxbexample.model.entities.Disc;
import net.elhacker.jaxbexample.model.entities.Tower;
import net.elhacker.jaxbexample.model.xml.HanoiTower;
import net.elhacker.jaxbexample.model.xml.HanoiTowerMarshaller;
/**
*
* @author Gus
*/
public class JAXBExample {
public static void main(String[] args) {
HanoiTowerMarshaller marshaller = new HanoiTowerMarshaller();
Board board = new Board();
Tower tower = new Tower();
Disc disc = new Disc();
board.setName("Juego 1");
board.setTowersNumber(5);
tower.setName("Torre 1");
tower.setxAxis(25);
tower.setyAxis(34);
disc.setxAxis(19);
disc.setyAxis(23);
HanoiTower hanoiTower = new HanoiTower();
hanoiTower.setBoard(board);
hanoiTower.setTower(tower);
hanoiTower.setDisc(disc);
hanoiTower.setPlayingTowers(7);
marshaller.marshal(hanoiTower, "D:\\hanoi-tower.xml");
HanoiTower xmlToHanoiTower = marshaller.unmarshall("D:\\hanoi-tower.xml");
System.out.println("Datos del juego cargado:\n");
System.out.println("Nombre del juego:");
System.out.println(xmlToHanoiTower.getBoard().getName());
System.out.println("Número de torres en el juego:");
System.out.println(xmlToHanoiTower.getBoard().getTowersNumber());
System.out.println("Nombre de la torre del jugador:");
System.out.println(xmlToHanoiTower.getTower().getName());
System.out.println("Coordenada X de la torre:");
System.out.println(xmlToHanoiTower.getTower().getxAxis());
System.out.println("Coordenada Y de la torre:");
System.out.println(xmlToHanoiTower.getTower().getyAxis());
System.out.println("Número de torres jugando:");
System.out.println(xmlToHanoiTower.getPlayingTowers());
System.out.println("Coordenada X del disco:");
System.out.println(xmlToHanoiTower.getDisc().getxAxis());
System.out.println("Coordenada Y del disco:");
System.out.println(xmlToHanoiTower.getDisc().getyAxis());
}
}
<HanoiTower>
<tower>
<name>Torre 1</name>
<xAxis>25</xAxis>
<yAxis>34</yAxis>
</tower>
<board>
<name>Juego 1</name>
<towersNumber>5</towersNumber>
</board>
<playingTowers>7</playingTowers>
<disc>
<xAxis>19</xAxis>
<yAxis>23</yAxis>
</disc>
</HanoiTower>
Datos del juego cargado:
Nombre del juego:
Juego 1
Número de torres en el juego:
5
Nombre de la torre del jugador:
Torre 1
Coordenada X de la torre:
25
Coordenada Y de la torre:
34
Número de torres jugando:
7
Coordenada X del disco:
19
Coordenada Y del disco:
23