SXDA Entries

SXDA entries are used to link our custom program & structure to the LSMW tool. There are four entities. SXDA0 – Specify whether Batch/Direct IP. SXDA1-Specify the Custom Program. SXDA2-Specify the Custom Structure. SXDA3-Specify the fields/values for that custom structure.

Permanent link to this article: https://blog.openshell.in/2011/04/sxda-entries/

Include a file and store contents to variable

This very handy feature of PHP which allows you to include a file but store the contents of the included file to a variable. This is particularly useful for PHP scripts and software which output content to a page by using variables. Many CMSs are built like this.

The principal behind this solution is to use an output buffer. You start the output buffer, include the file(s), store the included content to a variable, then stop the output buffer. Code is shown below:

ob_start(); // start buffer
include (“file-to-include.php”);
$content = ob_get_contents(); // assign buffer contents to variable
ob_end_clean(); // end buffer and remove buffer contents
echo $content;

Permanent link to this article: https://blog.openshell.in/2011/04/include-a-file-and-store-contents-to-variable/

JLayer component

The JLayer class is a flexible and powerful decorator for Swing components, which enables you to implement various advanced painting effects as well as receive notifications of all AWTEvents generated within its borders. It enables you to draw on components and respond to component events without modifying the underlying component directly.

JLayer is a good solution if you only need to do custom painting over compound component or catch input events from its subcomponents.

Software Requirement: Java Platform SE 7 (jdk1.7)

Here is a sample example,

//WallpaperLayerUI.java

class WallpaperLayerUI extends LayerUI<JComponent> {
  @Override
  public void paint(Graphics g, JComponent c) {
    super.paint(g, c);

    Graphics2D g2 = (Graphics2D) g.create();

    int w = c.getWidth();
    int h = c.getHeight();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, .5f));
    g2.setPaint(new GradientPaint(0, 0, Color.yellow, 0, h, Color.red));
    g2.fillRect(0, 0, w, h);

    g2.dispose();
  }
}
//Wallpaper.java
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.LayerUI;
public class Wallpaper {
  public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        createUI();
      }
    });
  }
  public static void createUI() {
    JFrame f = new JFrame("Wallpaper");
    JPanel panel = createPanel();
    LayerUI<JComponent> layerUI = new WallpaperLayerUI();
    JLayer<JComponent> jlayer = new JLayer<JComponent>(panel, layerUI);
    f.add (jlayer);
    f.setSize(300, 200);
    f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    f.setLocationRelativeTo (null);
    f.setVisible (true);
  }
  private static JPanel createPanel() {
    JPanel p = new JPanel();
    ButtonGroup entreeGroup = new ButtonGroup();
    JRadioButton radioButton;
    p.add(radioButton = new JRadioButton("Beef", true));
    entreeGroup.add(radioButton);
    p.add(radioButton = new JRadioButton("Chicken"));
    entreeGroup.add(radioButton);
    p.add(radioButton = new JRadioButton("Vegetable"));
    entreeGroup.add(radioButton);
    p.add(new JCheckBox("Ketchup"));
    p.add(new JCheckBox("Mustard"));
    p.add(new JCheckBox("Pickles"));
    p.add(new JLabel("Special requests:"));
    p.add(new JTextField(20));
    JButton orderButton = new JButton("Place Order");
    p.add(orderButton);
    return p;
  }
}
The output  will be like below:

A panel with a jazzy decoration

Permanent link to this article: https://blog.openshell.in/2011/04/jlayer-component/

PNG transparency problem in Internet Explorer 5.5 & 6

hi friends

This plugin will fix the missing PNG-Transparency in Microsoft Internet Explorer 5.5 & 6.

1. download

2. Add jQuery and pngFix to the HEAD-Section of your HTML …

<head> 
... 
<script type="text/javascript" src="jquery-latest.pack.js"></script> 
<script type="text/javascript" src="jquery.pngFix.js"></script> 
... 
</head>

3. Activate pngFix on document.ready

<head> 
... 
<script type="text/javascript"> 
    $(document).ready(function(){ 
        $(document).pngFix(); 
    }); 
</script> 
... 
</head>

Permanent link to this article: https://blog.openshell.in/2011/03/pngfix-internet-explorer-5-5-6/

List Changer

This is a very simple background changer. It just takes the selected value from the list and makes that the background color.

Insert the following code inside the <body> tag:

<FORM><SELECT Size=5 name=clr onChange=”document.bgColor=this.options[this.selectedIndex].value”><OPTION VALUE=”blue”>blue<OPTION VALUE=”aquamarine”>aquamarine<OPTION VALUE=”chocolate”>chocolate<OPTION VALUE=”darkred”>dark red<OPTION VALUE=”gold”>gold<OPTION VALUE=”red”>red<OPTION VALUE=”yellow”>yellow<OPTION VALUE=”hotpink”>hotpink<OPTION VALUE=”lime”>lime<OPTION VALUE=”darkkhaki”>dark khaki<OPTION VALUE=”cadetblue “>cadet blue<OPTION VALUE=”darkgoldenrod”>dark goldenrod<OPTION VALUE=”darkslateblue”>dark slate<OPTION VALUE=”blue”>blue<OPTION VALUE=”deeppink”>deep pink<OPTION VALUE=”darksalmon”>dark salmon<OPTION VALUE=”salmon”>salmon<OPTION VALUE=”tan”>tan<OPTION VALUE=”wheat”>wheat<OPTION VALUE=”tomato”>tomato<OPTION VALUE=”springgreen”>springgreen<OPTION VALUE=”turquoise”>turquoise<OPTION VALUE=”white” SELECTED>White</SELECT></FORM>

Permanent link to this article: https://blog.openshell.in/2011/03/list-changer/

Net::HTTP Raw Post Ruby Code

Net::HTTP is still a popular option though it doesn’t have the easiest API to remember. In order to Post & Access posted request object from the ruby script example is shown below:

require “cgi”
require “uri”
require “net/http”

#To Post data without form using RESTful Method

url = URI.parse(“http://api.domain.com”)
begin
requestXml = “Johnjohn1234
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url.path)
request.body = requestXml
request[“Content-Type”] = “application/xml”
response = http.request(request)
response.code # => 200 Ok
response.body # => The body (HTML, XML, blob, whatever)
rescue
logger.debug “Error #{$!}”
end

#To Receive Posted raw data from RESTful Method
if request.post?
response = CGI::unescape(request.raw_post)
end

Permanent link to this article: https://blog.openshell.in/2011/03/nethttp-raw-post-ruby-code/

Comment multiple lines in ruby

A multi-line comment begins with the =begin token and ends with the =end token. These tokens should start at the beginning of the line and be the only thing on the line. Anything between these two tokens is ignored by the Ruby interpreter.

=begin
Between =begin and =end, any number
of lines may be written. All of these
lines are ignored by the Ruby interpreter.
=end

puts “Hello world!”

I’ve found that if I include a tab before =begin or =end, the comments don’t work. The =begin and =end each need to be written at the beginning of each line.

Permanent link to this article: https://blog.openshell.in/2011/03/comment-multiple-lines-in-ruby/

Try Catch Finally block in Ruby

This the ruby code which is equivalent of a try/catch/finally block in other languages.

#Try catch block Syntax

begin
somecode()
rescue
puts “Error #{$!}”
ensure
this_code_will_execute_always()
end

# Sample Code
f = File.open(“testfile.txt”)
begin
# .. process
rescue
# .. handle error
else
puts “– no errors!”
ensure
f.close unless f.nil?
end

Permanent link to this article: https://blog.openshell.in/2011/03/try-catch-finally-block-in-ruby/

REST methods form request in Ruby On Rails Client

In order to access RESTful web services from Ruby Client script using form request. The method net/http tries to connect over HTTP even of the uri is HTTPS. For HTTPS, You need to explicitly tell net/http that a secure connection should be used. REST client code as shown below:

# Basic REST.
# Most REST APIs will set semantic values in response.body and response.code.

require “net/http”

http = Net::HTTP.new(“api.domainname.com”)

request = Net::HTTP::Post.new(“/users”)
request.set_form_data({“users[login]” => “MyUser”})
response = http.request(request)
# Use nokogiri, hpricot, etc to parse response.body.

request = Net::HTTP::Get.new(“/users/1”)
response = http.request(request)
# As with POST, the data is in response.body.

request = Net::HTTP::Put.new(“/users/1”)
request.set_form_data({“users[login]” => “changed”})
response = http.request(request)

request = Net::HTTP::Delete.new(“/users/1”)
response = http.request(request)

Permanent link to this article: https://blog.openshell.in/2011/03/rest-methods-form-request-in-ruby-on-rails-client/

SAP Query

  • SAP Query is SAP’s tool to define and execute reports without ABAP knowledge.
  • SAP Queries are quick reports which can be used for validation of data after Data Loading.
  • SAP Queries can also be used to get some test data for our program.
  • Transaction : SQ01 – Query;  SQ02 – Infoset; SQ03 – User group.

Permanent link to this article: https://blog.openshell.in/2011/03/sap-query/