Monday, May 30, 2011

referenced from:


className String|null
The optional name of the Class to declare.
The className will be used as a global name for a created constructor.
If you don't specify it, the class is assumed to be anonymous (new since V1.4).
If you specify it, the name will be stored in the property "declaredClass" in the created prototype.
superclass null|Object|Object[]
This parameter is either
  • null (no base class),
  • an object (a base class) or
  • an array of objects (multiple inheritance).
props Object
An object whose properties are copied (mixed in) to the created prototype after all other inheritance has been solved.
You can add an instance-initialization function by making it a property named "constructor".

Global:

Example: http://stackoverflow.com/questions/2444801/queryreadstore-loads-json-into-datagrid-but-jsonreststore-does-not-from-the-sam


dojo.declare("dojox.data.CustomStore", dojox.data.JsonRestStore, {
    _processResults: function(results, deferred){
        var items = SOME_MAPPING_FUNCTION_HERE(results);
        var count = COUNT_RESULTS_HERE;
        return {totalCount:deferred.fullLength || (deferred.request.count == count ? (deferred.request.start || 0) + count * 2 : count), items: items};
    }
}


To show how the inheritance chain works, we will create a new class derived from my.Thinger:
1
2
3
4
5
6
7
8
9
dojo.declare("my.OtherThinger", [my.Thinger], {
  divisor: 5,
  constructor: function(args){
    console.log('OtherThinger constructor called');
    this.total = this.count / this.divisor;
  }
});
var thing = new my.OtherThinger({ count:50 });
console.log(thing.total); // 10 

Local:


Now we have a 'base class', called my.Thinger.
If we don't want a globally accessible class we can easily make it local (since 1.4):
1
2
3
4
5
6
7
8
9
var localThinger = dojo.declare(null, {
  count: 100,
  constructor: function(args){
    dojo.mixin(this, args);
  }
});
var thing1 = new localThinger();
var thing2 = new localThinger({ count:200 });
console.log(thing1.count, thing2.count);

Saturday, May 28, 2011

SMD service

http://groups.google.com/group/json-schema/web/service-mapping-description-proposal?pli=1

A Service Mapping Description (SMD) is a JSON representation describing web services.


Examples

{
    "transport": "POST",
    "envelope": "URL",
    "target": "/service/",
    "additionalParameters": true,
    "parameters": [
 {
     "name":"outputType",
            "default": "json"
        },
        {
     "name":"ignoreErrors",
            "optional": true
        }
    ],
    "services": {
        "foo": {
            "transport": "GET",
            "target": "executeFoo.php",
            "parameters": [
                {"name":"paramOne", "type": "string"},
                {"name":"paramTwo", "type": "integer", "default": 5},
                {"name":"paramThree", "type": "integer", "optional": true}
            ]
        },
        "add": {
            "transport": "POST",
            "envelope": "JSON-RPC-2.0",
            "additionalParameters": {"type": "integer", "default": 0},
            "parameters": [
                {"type": "integer", "default": 0},
                {"type": "integer", "default": 0}
            ]
        }
    }
}
In the above example, two methods are defined: foo and add. foo is declared to take named parameters, with a service endpoint of /service/executeFoo.php (derived as a relative URL) with url-encoded parameters. The following is an example of a valid service call for the foo method:
GET /service/executeFoo.php?paramOne=value&paramTwo\\0753&outputType=json
The add service is defined to use the service endpoint of /service/ (inherited from the root level), and takes positional parameters using JSON-RPC version 2.0. The following is an example of a valid service call for the add method:
POST /service/

{"id":1,"method":"add","params":[4,7,9]}
Note that all service definition properties are optional. Therefore, a service could be defined:
"simple": {}
and this would indicate that any parameters may be passed in, and return value can be returned.


Type Defined Sub-Services


Examples of Sub-Services

{
   "services":{
       "person": {
            "transport": "REST",
            "envelope": "PATH",
            "target": "person",
            "parameters": [{
                "name":"id",
                "type": "string"
            }],
            "returns": {
                "type": {
                    "id":{"type":"string" },
                    "firstName":{"type":"string"},
                    "lastName":{"type":"string"},
                    "age":{"type":"number","maximum":125,"minimum":0},
                    "address":{"type":"string"}}
                },
                "services":{
         "sendMessage": {
                    "type": "method",
                 "transport": "RAW_POST",
                 "envelope": "JSON-RPC-2.0",
                 "parameters": [
                       {"type": "string", "optional": true},
                       {"type":"object"}],
                 "returns": {"type": "boolean"}
                  }
               }
            }
        }
    }
}

JSONP

JSONP or "JSON with padding" is a complement to the base JSON data format, a pattern of usage that allows a page to request data from a server in a different domain. 

Under the same origin policy, a web page served from server1.example.com cannot normally connect to or communicate with a server other than server1.example.com. An exception is the HTML <script> element. Taking advantage of the open policy for <script> elements, some pages use them to retrieve Javascript code that operates on dynamically-generated JSON-formatted data from other origins. This usage pattern is known as JSONP.

In the JSONP usage pattern, the URL returns the dynamically-generated JSON, with a function call wrapped around it. This is the "padding" (or sometimes, "prefix") of JSONP.

Use the 'src' element of the <script> tag:

<script type="text/javascript"
         src="http://server2.example.com/RetrieveUser?UserId=1823&jsonp=parseResponse">
 </script>

what received is 
  parseResponse({"Name": "Cheeso", "Id" : 1823, "Rank": 7})
 
 

Security concerns

Including script tags from remote sites allows the remote sites to inject any content into a website. If the remote sites have vulnerabilities that allow JavaScript injection, the original site can also be affected.
 

Cross-site request forgery


Naïve deployments of JSONP are subject to cross-site request forgery attacks (CSRF or XSRF).[1] Because the HTML <script> tag does not respect the same origin policy in web browser implementations, a malicious page can request and obtain JSON data belonging to another site. This will allow the JSON-encoded data to be evaluated in the context of the malicious page, possibly divulging passwords or other sensitive data if the user is currently logged into the other site.

i.e. Then you browse the malicious page while you've logged on to facebook, the malicious page may issue a request to facebook, potentially getting your facebook password

Friday, May 20, 2011

Find Files

Find just directory

find . -type d -name xxxx

Find top 10 largest files

du -ks xxxxdirxxxx | sort -n -r | head -n 10

find . -type f -printf ‘%s %p\n’ |sort -nr|head -10

du -xak .|sort -n|tail -10

Sunday, May 15, 2011

ProcessBuilder cmd with wildcard


The wildcard '*' needs to be interpreted by a shell. One approach is to invoke the shell using the varargs approach

ProcessBuilder procBldr = new ProcessBuilder("sh","-c","cp -f /tmp/src/*.zip /tmp/removeme");

javascript weird illegal character error

To find where exactly went wrong.

put the separate js file back into the HTML or JSP

tightvnc on ubuntu extreme basic

1. install
sudo apt-get install tightvncserver

2. start
tightvncserver

3. stop the server
vncserver -kill :viewnumber

TODO:
1.
after log on from client:

it is a new workspace, instead of taking over the screen

2.
start the server from boot

http://www.abdevelopment.ca/blog/start-vnc-server-ubuntu-boot

Saturday, May 14, 2011

Declare function in JSP


http://www.jguru.com/faq/view.jsp?EID=1010

Do note that you do not have direct access to any of the JSP implicit objects like request, response, session and so forth from within JSP methods. However, you should be able to pass any of the implicit JSP variables as parameters to the methods you declare. For example:

-----including 'out'--------------------------


<%! 
      public String whereFrom(HttpServletRequest req) {
      HttpSession ses = req.getSession();
      ... 
      return req.getRemoteHost();
     }
%>
<%
     out.print("Hi there, I see that you are coming in from  ");
%>
<%= whereFrom(request) %>



Re: calling methods of an included page

Oystein Ovrebo, Apr 4, 2002  [replies:1]
Maybe you could try this? Works for me:
file1.jsp:
<%@page contentType="text/html"%>

<%!

    public void test(JspWriter writer) throws IOException{
        writer.println("Hello!");
    }

%>

file2.jsp
<%@include file="file1.jsp"%>
<html>
<body>

<%test(out);%>

</body>
</html>

Hope this helps. Oystein

Is this item helpful?  yes  no     Previous votes   Yes: 1  No: 0



Reply to this answer/comment  Help  
Re[2]: calling methods of an included page
Mohan Jadhav, Apr 19, 2002
Yes...this works... But, if you use the JSP action tag for include, it doesn't work. For example, in the code given by Oystein, if I replace <%@include file="file1.jsp"%> with <jsp:include page="file1.jsp" />, it doesn't work.
The reason for this is the page mentioned in the action tag is considered at run time, where as in the first case it is just like inlining of the code.
Hope this clarifies the point...
Mohan.

Is this item helpful?  yes  no     Previous votes   Yes: 0  No: 0



Reply to this answer/comment  Help