Category: Technical


Page asset provides Category for categorization purpose. In this article i will explain “how to create new Category for page assets”.

  • Login to system with admin rights
  • Go to Advance environment
  • Goto Admin > Asset Types > Page > Categories

Here we will find all association with page asset (see Figure 1)

Category

Figure 1 – Page Category

To create a new association, click on “Add New Category button”

Category

And fill the form (see Figure – 2)

CategoryForm

Figure 2 – Page Category creation form

Description: Information about this page category. Make it small and informative.
Category Code: This code will be used get the value. This is a 4 char value. Please do not put blank space.

  • Click “Add New Category” Button

Other Related Posts:
Fatwire – How to create new association with page asset

Counter Description / Thresholds
Memory -
Available Bytes
Description: Available Bytes is the amount of physical memory, in bytes, immediately available for allocation to a process or for system use. It is equal to the sum of memory assigned to the standby (cached), free and zero page lists.
Thresholds: If the average value of the counter is less then 300MB, otherwise the server experiences a performance hit due to memory pressure.
Memory -
Page Faults/sec
Description: This counter gives a general idea of how many times information being requested is not where the application (and VMM) expects it to be. The information must either be retrieved from another location in memory or from the pagefile. Recall that while a sustained value may indicate trouble here, you should be more concerned with hard page faults that represent actual reads or writes to the disk. Remember that the disk access is much slower than RAM.
Thresholds: 0 is the optimum measurement. Any measurement higher than zero delays response time and probably indicates not enough RAM
Memory -
Pages/sec
Description: Pages/sec is the rate at which pages are read from or written to disk to resolve hard page faults. This counter is a primary indicator of the kinds of faults that cause system-wide delays.
Thresholds: It should typically be 0–20. (Unhealthy if greater than 80; probably indicates not enough RAM.)
LogicalDisk -
Avg. Disk Bytes/Transfer
Description: Measures the size of input/output (I/O) operations.
To analyze transfer data further, use Avg. Disk Bytes/Read and Avg. Disk Bytes/Write.
Thresholds:
- The disk is efficient if it transfers large amounts of data relatively quickly.
- Watch this counter when measuring maximum throughput.
LogicalDisk -
% Free Space
Description: Reports the percentage of unallocated disk space to the total usable space on the logical volume.
PhysicalDisk -
Avg. Disk sec / Transfer
Description: How fast is data being moved (in seconds)? This counter measures the average time of each data transfer, regardless of the number of bytes read or written. It shows the total time of the read or write, from the moment it leaves the Disk Performance Statistics Driver to the moment it is complete.
Thresholds:
> 0.3 seconds may indicate disk controller needs too many retrys. Include Faster drives.
PhysicalDisk -
Avg. Disk Bytes/Transfer
Thresholds:
< 20K may indicate an app. is accessing too little at a time.
PhysicalDisk -
Current Disk Queue Length
Description:
Are disk requests waiting?
Thresholds: If more than 2 request are waiting over time, the disk may be a bottleneck.   More hard drives.
PhysicalDisk -
% Disk Time
Description: How often is the disk busy?
This value is displayed as a percentage and is capped at 100%.
Thresholds: If it’s busy almost all of the time (>90%), and there is a large queue, the disk might be a bottleneck.   More hard drives.
Network Interface -
Output Queue Length
Description: Output Queue Length is the length of the output packet queue (in packets). Since the requests are queued by Network Driver Interface Specification (NDIS) in this implementation, this value is always 0.
Thresholds: If this is longer than 2, there are delays and the bottleneck should be found and eliminated, if possible
Network Interface -
Packets Received/sec
Packets Received/sec is the rate at which packets are received on the network interface.
Network Interface -
Packets Sent/sec
Packets Sent/sec is the rate at which packets are sent on the network interface.
Network Interface -
Packets/sec
Packets/sec is the rate at which packets are sent and received on the network interface.
Processor -
% Processor Time
Description: % Processor Time is the percentage of elapsed time that the processor spends to execute a non-Idle thread. It is calculated by measuring the percentage of time that the processor spends executing the idle thread and then subtracting that value from 100%.
Thresholds:
- Less than 60% consumed = Healthy
- 51% – 80% consumed = Monitor or Caution
- 81% – 100% consumed = Critical or Out of Spec Scale CPUs
System -
Context Switches/sec
Description: Context Switches/sec is the combined rate at which all processors on the computer are switched from one thread to another. Compare this value with the value of Web Service\Total Method Requests/sec.
Thresholds:
- Context switches per request (Context Switches/sec divided by Total Method Requests/sec) should be low.
- high context switches/sec – more than 5000 context switches per second
- Very high context switches/sec – more than 15,000 context switches per second

Reference: Windows 2000 Resource Kit Performance Counters Start Page

Fatwire initially provides some basic building assets, which we can use while setting up a site. Page, Query, Template, CSElement … is few of them.

Note: Fatwire treat every thing as asset (eg. Template)

Page asset is used to create site plan. We can define child parent relation ship within our site plan using page assets. It totally depends on our design how many level of hierarchy we will use. Its not possible to customize Fatwire provided assets (Page in our case), means we can’t introduce new attributes with these assets. But Fatwire provide a provision to create association. Using association, we can associate any asset type with our page asset.

I have divided this article in two parts:
1. How to create association with page asset
2. How to access associated assets

1. How to create association with page asset?

  • Login to system with admin rights
  • Go to Advance environment
  • Goto Admin > Asset Types > Page > Asset Associations
    Here we will find all association with page asset (see Figure 1)

    Figure 1 - Page associattions

    Figure 1 - Page associations

  • To create a new association, click on “Add New” and fill the form (see Figure 2)
    Figure 2 - Create new Association with Page asset

    Figure 2 - Create new Association with Page asset

    Name: Name of new association, please make it informative, we will be using this name to get the associated assets.
    Description: Description we want to provide. Can be same as name
    Child Asset: If we want to associate only specific asset type, then select that asset type from drop down. If any asset can be associated then leave it “Any”
    Page SubTypes: If we are using page subtypes and want this association with only some specific sub types, then select the sub type otherwise leave it “Any”
    Mirror Dependency Type: It’s a trade off and totally depends on business requirement. Select this value to Exact version if any change to the associated asset will require approval for publish of Page otherwise keep it Exists. I will suggest keeping it Exists.
    Multivalued Association: single valued / multivalued

  • Click “Add New Association” Button
  • We can find this new association on page creation form (eg. See Figure 3)

    Figure 3 - Page Creation Form with Associations

    Figure 3 - Page Creation Form with Associations

    NOTE: We can create number of associations with page assets

2. How to access associated assets?

We can use <asset:children … /> tag to get the associated assets. The syntax is as follows:

<asset:children type=”Page” assetid=’<%=ics.GetVar(“pageId”) %>’ list=”myList” code=”associationName” order=”nrank” />

Description:

type: asset type, “Page” in our case
assetid: Page asset id
list: named list which will refer to the fetched assets. We will use this list to get the asset ids
code: Give the name of association (which we have created)
order: “nrank” to return an ordered list. Applicable in case of multivalued association only.

We can use “myList” to get the associated assets. This list has two attributes (otype, oid)

otype: type of associated asset
oid: id of associated asset

Iterate through the list:

// Check for empty list. Its a common practice to avoid any error. Please see Common errors and their Prevention
<ics:if condition=’<%=null != ics.GetList(“myList”)&& ics.GetList(“myList”).hasData() %>’>
<ics:then>

<ics:listloop listname=”myList”>

<ics:listget listname=”myList” fieldname=”otype” output=”c” />
<ics:listget listname=”myList” fieldname=”oid” output=”cid” />

</ics:listloop>

</ics:then>
</ics:if>

Next Read :
Fatwire | How to create new Category with Page asset

  1. ics:listloop tag failure
  2. Invalid type specified: Page
  3. Need a ‘ID’ field & Need a ‘Type’ field
  4. ics:setvar missing or empty argument value
  5. Error: no object named <ObjectName>
  6. Error -101 in tag ics:selectto with table Template_Composition

1. Error: ics:listloop tag failure

Root Cause: This error occur if asset type [c] and/or asset Id [cid] passed to tag <assetset:setasset/> or <asset:load/> is NULL.

<ics:listloop listname=”myList”>

</ics:listloop>

Solution: Always apply null check before iterating a list.

<ics:if condition=’<%=null != ics.GetList(“myList”) && ics.GetList( “myList” ).hasData() %>’>
<ics:then>

<ics:listloop listname=myList”>

</ics:listloop>

</ics:then>
</ics:if>

2. Error: Invalid type specified: Page

Root Cause: This error occurred, If type passed to <assetset:setasset /> tag is a basic asset eg. Page. As Page asset is basic type asset. And this tag is meant to load Flex Asset.
This code will give “Invalid type specified: Page” error:

<ics:setvar name=”c” value=”Page“/>
<ics:setvar name=”cid” value=”123456789″/>
<assetset:setasset name=”asset” type=’<%=ics.GetVar(“c”)%>’ id=’<%=ics.GetVar(“cid”)%>’ />

Solution: Check asset type and use <asset:load> tag for basic assets.

<ics:setvar name=”c” value=”Page“/>
<ics:setvar name=”cid” value=”123456789″/>

<ics:if condition=’<%=“Page”.equals(ics.GetVar(“c”)) %>’>
<ics:then>

<asset:load name=”AsscAsset” type=’<%=ics.GetVar(“c”)%>’ objectid=’<%=ics.GetVar(“cid”)%>’/>

</ics:then>
<ics:else>

<assetset:setasset name=”AsscAsset” type=’<%=ics.GetVar(“c”)%>’ id=’<%=ics.GetVar(“cid”)%>’ />

</ics:else>
</ics:if>

3. Error: Need a ‘ID’ field & Need a ‘Type’ field

Root Cause: This error occur if we try to iterate through an uninitialized list.
Solution: We should put NULL check on c and/or cid in such a situation where there is possibility for NULL value.

<ics:if condition=’<%=ics.GetVar(“c”) != null && ics.GetVar(“cid”) != null %>’>
<ics:then>

<assetset:setasset name=”myAsset” type=’<%=ics.GetVar(“c”)%>’ id=’<%=ics.GetVar(“cid”)%>’/>

</ics:then>
</ics:if>

4. Error: ics:setvar missing or empty argument value

Root Cause: This error occur if we try to set null as value in <ics:setvar /> tag.
Solution: Set some Default value for variable at the top of the page or Write code in a manner so that no chance to NullPointer, NumberFormat … exception.

5. Error: no object named <ObjectName>

Root Cause: This error occurred when asset loaded is NULL and we are trying to get data from the object.

<asset:load name=”TestObject” type=’<%=ics.GetVar(“c”) %>’ objectid=’<%=ics.GetVar(“cid”) %>’ />
<asset:get name=”TestObject” field=”id” output=”asset:cid”/>

Solution: Put NULL check on object before getting data out of it.

<asset:load name=”TestObject” type=’<%=ics.GetVar(“c”)%>’ objectid=’<%=ics.GetVar(“cid”) %>’ />
<ics:if condition=’<%=ics.GetObj(“TestObject”) != null %>’>
<ics:then>

<asset:get name=”TestObject” field=”id” output=”asset:cid”/>

</ics:then>
</ics:if>

6. Error: Error -101 in tag ics:selectto with table Template_Composition

Root Cause: If there is no record found for SQL for tag <ics:selectto/>, then it returns (-101) Error code.
Solution: I will suggest to use SQL query (using <ics:sql /> tag) instead of <ics:selectto/>. Also Its always good to use SQL query (with join in 3-4 tables) instead of <asset:load> tags … Its a trade off and you are the best person to decide which one to use.

In any kind of implementation, i (actually everyone) perform some empty string operation:

if(null != myString && !"".equals(myString))
    ...
}

.equals() method compare each character of strings to check the equality. In the example above we are:

  • Creating a String object (“”) with 0 length
  • using .equals() method to check if both strings are equal or not

Note: String class store values as char array

But when i had a look into the implementation of .equals() method, the idea comes in my mind why not use length() method in this scenario to save the .equals() overhead. length() method just return the length of string which String class store in count variable at the time we create String object. So its definition looks like:

public int length() {
    return count;
}

As simple as it can be. So i have simply replaced my code with length() metohd

if(null != myString && !0 == myString.length()) {
    ...
}

Is it safe to replace .equals() with .length() in my code?

It depends on your requirement actually, equals() method check for equality of two objects (string in our case), while .length() just return the number of characters in String object.

HashMap – How it works?

On very high level, Hash Map is used to store data in form of key value pair.

Hash Map is a Hash table based implementation of the Map interface. This implementation provides all of the optional map operations, and permits null values and the null key. (The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.) This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.” … from Java API

After reading this definition, some question comes in my mind:

  1. How hash map store data internally?
  2. What happen when I try to store some new information in map?
  3. How hash map find my data?

And when I tried to explore it, I find it more and more interesting.

HashMap has a static class named Entry which implements Map.Entry interface. The Entry class looks like:

static class Entry implements Map.Entry {

final Object key;
Object value;
final int hash;
Entry next;
Entry(int i, Object obj, Object obj1, Entry entry) {
value = obj1;
next = entry;
key = obj;
hash = i;

}
// Other methods

}

Every time we insert a <key,value> into hashmap using .put() method, a new Entry object is created (not true is some cases. if key already exists, then it just replace the value).  Map internally used two data structures to manage/store data:

  1. Array
  2. Link List

This image shows how hashmap manage data. Here

  • Each index of array is a bucket
  • To identify the bucket for any <key,value>, Hash map use key.hashCode() and perform some operation:
    Bucket (index) =HashMap.indexFor (HashMap.hash(key.hashCode()), entryArray.length)
    It means, two keys with different hashCode can fall under same bucket.
  • If a bucket is empty (table[i] is null) then the Entry object is simply inserted at ith position
    table[i] = new Entry(hash, key, value, null)
  • If a bucket has some values, then the following algo is used:
    Entry entry = table[i]

    Table[i] = new Entry(hash,key,value,entry)

    It means, the latest entry resides on the top of the bucket.

  • If a key already exists in a map, then it just replace the value and return the old value
    If(entry.key == key || key.equals(entry.key)
    Then

    Object oldValue = entry.value;
    Entry.value = newValue;
    Return oldValue;

    End if

  • In case of new key,  map add the key, value (a new Entry object with key value) and return null
  • Entry.hash is not the hashCode of key, but HashMap use its own hash algo to create hash based on key.hashCode(). So it’s like:
    entry.hash = HashMap.hash(key.hashCode());
  • HashMap allow single null as key, in case of null key, it create a dummy object and use it as key.
    static final Object NULL_KEY = new Object();
  • hashMap.get(Obj) and hashMap.containsKey(obj), both method iterate through the map. Avoid to use extra call of containsKey().

    If(null != map.containsKey(obj)) {

    myObj = map.get(obj);
    //Perform other operations

    }

    This can be easily replaced by:

    myMap  = map.get(obj);
    if(null != myMap) {

    // Perform other operations

    }

Caching is always a broad topic in any design. Every CMS/Framework provides its own ways to implement cache. I am using Fatwire 7 CMS. Fatwire provide 2 level of caching:

  1. Content Server Cache (CSCache)
  2. Satellite Server Cache (SSCache)

Note: I will use CS and SS for Content Server and Satellite Server.

Let’s have a look how fatwire serve a request:

  • Every time a user (End user) hit a page (A), the request goes to SS
    SS check if the requested page/pagelete is available in its cache. If the requested page/pagelate is available in SS cache, then it servers the requested page back to end user (E,F) otherwise SS request CS to provide it the requested page/pagelete (C)
    CS check if the requested page/pagelete is available in its cache. If the requested page/pagelate is available in CS cache, then it servers the requested page back to SS (D) otherwise CS follow the following steps:

    • CS process the code (Templates/CSElements) to generate the requested page/pagelete.
    • Cache* the page/pagelete on CS
    • Return the output to SS (D)
  • Now, SS cache* the processed page/pagelete and return the complete page back to requested user (E,F)

* Its not necessary that we cache every page/pagelete. If a page is cached but it’s internally calling number of uncached Elements (CSElements/Templates) then the cached page save the call for that element instead of html output. So every time a user request for a page, these uncached elements will got evaluated on CS.

Server-side XML gives us even more power then Client-side XML processing. For example, since the processing is done on the server, only the results are sent to the client, so we don’t have to worry about making our code cross-browser compatible. It is true that processing XML on the server-side transfers some of the load to the server, but since web servers are usually extremely powerful creatures with the ability to cache data, that is probably nothing to be worried about.

Pros of Server-side XML Processing:

  • No need to write code cross-browser compatible.
  • Server-side approach also greatly reduces the amount of data that flows across the network connection.
  • By using server-side parsing, we can display different results for different browsers, by detecting the browser-type on the server side and using the correct style sheet for the transformation.
  • Systems can provide better performance and maintainability for data-driven web sites by generating and caching frequently accessed pages ahead of time on the server.
  • We can filter-out sensitive data on server side sending the data on client side.
  • Maintaining code becomes easier, since we don’t have to modify it when new browser types or versions become available.
  • By doing transformations on the server side we can simplify what is sent to the client, avoiding the problem of designing functionality that works for all possible browser combinations (even mobile devices).
  • XML-support in browsers is still limited.

Cons of Server-side XML Processing:

  • Parsing XML on server-side transfer some load on server.

Ajax using JQuery

Using JQuery, we can simply make Ajax call. JQuery provides us simple methods to make Ajax call using GET or POST. We can use any of these HTTP methods to make Ajax request using JQuery.

1. $.get() : Load a remote page using an HTTP GET request.

Syntax: $.get(String url, Map params, Function callback) returns XMLHttpRequest

Example 1: simple ajax call using $.get()

$.get(“test.php”);

Example 2: ajax call with parameter in query string

$.get(“test.php”, { name: “mohit”, age: “24″ } );

Example 3: ajax call handles response

$.get(“test.php”, function(data){
alert(“Ajax call complete”);
});

Example 4: ajax call with parameter in query string and handles response

$.get(“test.php”,
{ name: “mohit”, age: “24″ },
function(data){
alert(“Ajax call complete”);
}
);

2. $.post() : Load a remote page using an HTTP POST request.

Syntax: $.post(String url, Map params, Function callback) returns XMLHttpRequest

Example 1: simple ajax call using $.post()

$.post(“test.php”);

Example 2: ajax call with parameter

$.post(“test.php”, { name: “mohit”, age: “24″ } );

Example 3: ajax call handles response

$.post(“test.php”, function(data){
alert(“Ajax call complete”);
});

Example 4: ajax call with parameter and handles response

$.post(“test.php”,
{ name: “mohit”, age: “24″ },
function(data){
alert(“Ajax call complete”);
}
);

Isn’t it simple to use JQuery for AJAX…

This is a small script, which change the alt attribute of all img (images) tags on the page:

$(document).ready(function() {

$(“img”).each(function(i) {

this.alt = ‘your new alt text’;

} );

})

Another complex script, which change the alt attribute of all img (images) tags on the page, to the title of the page, if the alt attribute is not set already.

$(document).ready(function() {

var title = $(“title”).html();

$(“img”).each(function(i) {

if(this.alt==”)

this.alt = title;

} );

})

JQuery makes the things as simpler as you cant imagine.

Follow

Get every new post delivered to your Inbox.