1 Ağustos 2013 Perşembe

Developerlardan Özlü Sözler

Object-Oriented ustasıyım, Design Pattern hastasıyım.

 Eşin, benzerin yok bu alemde. Singleton musun güzelim? (sevgiliye hoş bir söz...)

 Aşkımızı Microsoft'a anlattım, .Net 4.0 diye release oldu.

 Java'da pointer olsaydı, yalnız seni gösterirdi.

 Mesele nesneye yönelmek değil yeğen! Mesele nesneyi yöneltebilmekte!

 Hayatta herşey bir pattern olsa, senin adın Singleton olurdu. 

Testerla dargın, çilekeş developer!

 Gözlerine her bakışımda, kalbimden bir exception fırlatılır.

5 Nisan 2012 Perşembe

A Printer class for GWT


import com.google.gwt.user.client.ui.UIObject;
import com.google.gwt.user.client.Element;

public class Printer {
    public static native void it() /*-{
        $wnd.print();
    }-*/;
    public static native void it(String html) /*-{
        var frame = $doc.getElementById('__printingFrame');
        if (!frame) {
            $wnd.alert("Error: Can't find printing frame.");
            return;
        }
        frame = frame.contentWindow;
        var doc = frame.document;
        doc.open();
        doc.write(html);
        doc.close();
        frame.focus();
        frame.print();
    }-*/;
    public static void it(UIObject obj) {
        it("", obj.getElement().toString());
    }
    public static void it(Element element) {
        it("", element.toString());
    }
    public static void it(String style, String it) {
        it("<it><header>"+style+"</header><body>"+it+"</body></it>");
    }
    public static void it(String style, UIObject obj) {
        it(style, obj.getElement().toString());
    }
    public static void it(String style, Element element) {
        it(style, element.toString());
    }
}

Open a new window in GWT


public static void openNewWindow(String name, String url) {
   com.google.gwt.user.client.Window.open(url, name.replace(" ", "_"),
          "menubar=no," +
          "location=false," +
          "resizable=yes," +
          "scrollbars=yes," +
          "status=no," +
          "dependent=true");
}

28 Ocak 2012 Cumartesi

Hashing with MD5 in JAVA

This guy has explained it very well.

JSF 1.2 Email Validation

In JSF 2.0 we have
@Pattern(regexp=".+@.+\\.[a-z]+",message="Username must be in e-mail format");
We define it just above the mailadress variable in Managedbean and life is so good. But inJSF1.2 we have to write our own mailValidator class. Here is how we can do it:

  1. First of all, create a validator class :/**
     * @author Burhan ARAS
     *
     */
    public class EmailValidator implements Validator {

        /* (non-Javadoc)
         * @see javax.faces.validator.Validator#validate(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
         */
        @Override
        public void validate(FacesContext facesContext, UIComponent uIComponent, Object object)
        throws ValidatorException {
            // TODO Auto-generated method stub
             String enteredEmail = (String)object;
                //Set the email pattern string
                Pattern p = Pattern.compile(".+@.+\\\\.[a-z]+");
               
                //Match the given string with the pattern
                Matcher m = p.matcher(enteredEmail);
               
                //Check whether match is found
                boolean matchFound = m.matches();
               
                if (!matchFound) {
                    FacesMessage message = new FacesMessage();
                    message.setDetail("Email geçersiz.");
                    message.setSummary("Kullanıcı adi e-mail formatında değil.");
                    message.setSeverity(FacesMessage.SEVERITY_ERROR);
                    throw new ValidatorException(message);
                }
        }

    }
  2. Secondly we should define this validator in faces-config.xml file. <validator>
      <validator-id>emailvalidator</validator-id>
      <validator-class>com.blog.util.EmailValidator</validator-class>
     </validator>
  3. And finally, we are gonna declare it in our preview file like html, jsf or whatever.

5 Ocak 2012 Perşembe

EXCEL formatting

=CONCATENATE(REPT("0", 9 - LEN(A2)),A2," ",B2,REPT(" ",20 - LEN(B2))," ",C2,REPT("0",8 - LEN(C2))," ",REPT("0",2 - LEN(D2)),D2," ",REPT("0",9 - LEN(E2)),E2)

2 Eylül 2011 Cuma

JAVA Robot Class

Nowadays, it's spectacularly popular to control something remotely. However Java Robot class isn't a new and cutting edge technology but you can do fantastic thing if you know how to use it.

Today, we are gonna build a very small app that will launch Notepad and types the text that we want.

Step 1 : let's open a new notepad file :

Runtime.getRuntime().exec("notepad.exe");

Step 2 : now type the keys:

Robot r=new Robot();
r.keyPress(KeyEvent.VK_T);


Actually that is just it but we can do some funny things. For instance lets add a waiting time so it will seem as if we are in Hollywood movies :)

Thread.sleep(500);

You can download pure and poor codes from right here :)


We will add a few extra features in near future, stay tuned and have fun..