Java boolean expression evaluation

import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
public class Main {

    public static boolean evalBoolExpression(String script) {
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("js");
        Object result = null;
        try {
            result = engine.eval(script);
        } catch (ScriptException e) {e.printStackTrace();}
        return ((Boolean)result).booleanValue();
    }  

    public static void main(String[] args) {
        System.out.println(evalBoolExpression("\"coco\"==\"co\"+\"co\""));
        System.out.println(evalBoolExpression("142==100+50-(16/2)"));
        System.out.println(evalBoolExpression("var1=\"text\";var1==\"texte\""));
    }
}

Old gray


Rust and decay

Comments Off more...

Lego sniper rifle and AK-47




Comments Off more...

How to create a DOM using a Node

public Document newDocument(Node node){
        Document document = null;
        try {
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            document = docBuilder.newDocument();
            Node nn = document.importNode(node, true);
            document.appendChild(nn);
        }catch (Throwable t) {
            t.printStackTrace ();
        }
        return document;
    }
Comments Off more...

How to Convert HTML to XHTML

The open source JTidy project does an excellent job of converting HTML files to the newer XHTML standard. You can find jTitdy here

import org.w3c.tidy.Tidy;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.w3c.dom.Document;
...
  public static void htmlToXhtml(String htmlFile, String xhtmlFile){
    try{
      FileInputStream in=new FileInputStream(htmlFile);
      FileOutputStream out=new FileOutputStream(xhtmlFile);
      Tidy T=new Tidy();
      Document D=T.parseDOM(in,out);
    } catch (java.io.FileNotFoundException e) {
      e.printStackTrace();
    }
  }
Comments Off more...

8-bit Starcraft

Comments Off more...

Sarmalele Reci – Violeta


Interrupting a parade


I’ll sue ya

Comments Off more...

  • Categories


  • All photos are protected by copyright and cannot be used or reproduced without the written consent of the owner.
    Toate fotografiile sunt proprietatea titularului de copyright şi nu pot fi reproduse fără acordul scris al acestuia.
    Jarrah theme by Templates Next | Powered by WordPress