Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / August 2003

Tip: Looking for answers? Try searching our database.

jsp beautifier

Thread view: 
rabbits77 - 11 Jul 2003 20:46 GMT
Hi all,
anyone can help me finding a free tool for beautify and indent HTML (and
JSP) code?
I tried to use HTML-TIDY but it was not easy to use with JSP page.
I don't want to check code, I only would like to indent and swap properly to
uppercase/lowercase tags and attributes.

thanks
Roedy Green - 11 Jul 2003 23:51 GMT
>anyone can help me finding a free tool for beautify and indent HTML (and
>JSP) code?

Its not free, but I think Dreamweaver beautifies JSP.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
BigAl - 14 Jul 2003 13:50 GMT
JEdit (www.jedit.org) has a plugin called JavaStyle which works like a
charm. I don't know if it handles HTML or JSP - never have tried.

=Alan=

> Hi all,
> anyone can help me finding a free tool for beautify and indent HTML (and
[quoted text clipped - 4 lines]
>
> thanks
rabbits77 - 14 Jul 2003 20:03 GMT
> Hi all,
> anyone can help me finding a free tool for beautify and indent HTML (and
[quoted text clipped - 4 lines]
>
> thanks
Just in case this spurred any interest with anyone lese in the world
it appears that this is an intended feature for netbeans at some point
but is not targeted for any specific release at this point.
http://www.netbeans.org/issues/show_bug.cgi?id=12935
Wish I had time to bone up on their indentation engine and help
them>:(.......
Peter Kehl - 20 Jul 2003 09:25 GMT
I tried several JSP/Java editors. Possibly usable results:

html-helper-mode for Emacs -> supposed to have indentation Engine; I
didn't know to set it up. It is reported it requires psgml mode;
html-helper-mode source reads tempo.el mode is required as well.

http://jsppp.sourceforge.net -> free JSPPP; simpe JSP only, otherwise
failing

http://www.phpedit.com -> free PHPEdit + PHPCodeBeautifier module ->
beautifies both PHP and JSP code only; doesn't indent inner HTML... :(

Free Eclipse http://www.eclipse.org + Trita plugin
http://www.trita.com (14 days trial, $35) seems to indent inner HTML
quite nicely

I'm trying to make a free JSP indentation engine; if successful I will
report in a few days.

Peter Kehl
(email invalid; http://paneris.com/~peterk/ )
Jim - 14 Aug 2003 02:22 GMT
> Hi all,
> anyone can help me finding a free tool for beautify and indent HTML (and
[quoted text clipped - 4 lines]
>
> thanks

Here's a Perl script that does indentation and reports on the balances of
open/close
tags. It doesn't futz with case of tags and attributes.

It is offered without documentation or warrenty.  It does what I needed
done, hope it
works for you.

I agree with you about tidy.

jim

p.s.  It shouldn't to hard to put in code to force tags/attributes to a
particular case

########################################################################
#
# File: jspPretty.pl
#
# Author:  Jim
# Created: Mon Aug 11 15:50:18 2003
#
# Description:
#
# Copyright 2003 by the President and Fellows of Harvard College
#
########################################################################

$usage = "
   Usage: perl jspPretty.pl [ -h ]
       Filters Java Server Pages and prettys up the indentation;
           reports errors in balance of open/close tags.

       options:
           -h show this help

";

use Getopt::Std;

   #
   # Process command line options
   #
   $optionList = "h";
   &getopts( $optionList ) || die $usage;

   die $usage if ( $opt_h );

{ #main block

   $shift = "  ";

   $indent = "";

   $bLastWasTag = 0;
   $bInScript = 0;
   $bSeenHeadTag = 0;

   $openCCDATA = '//<!\[CDATA\[';
   $closeCCDATA = "//]]>";

   $infile = $ARGV[0];

   while( <> )
   {
       $bSeenHeadTag = 1 if ( m-^\s*<head.*>- );

       if ( !$bSeenHeadTag )
       {
           print;
           next;
       }
       print if ( m/^#/ );

       if ( $bInScript )
       {
           if ( m-^\s*</script- )
           {
               $bInScript = 0;
           }
           print;
           next;
       }
       elsif ( m-^\s*<script- )
       {
           print;
           $bInScript = 1;
           next;
       }

       # match html, head, body opening, closing tags
       m/^\s*<(\/?html|\/?body|\/?head)/ && do
       {
#print"1_$._    ";
           s/^\s*//;
#print "$. H balance:$balance\n";
           $indent = "";
           &printIt();
           1;
       }
       ||
       # matches comments that protect scripting code
       ( m-^\s*${openCCDATA}\s*$- || m-^.*${closeCCDATA}\s*$- ) && do
       {
           &printIt();
           next;
           1;

           #we want to skip internal tags for these.
       }
       ||
       # matches open tags (but not jsp tags or comment, i.e '<%', or
'<!' )
       m/^\s*<[^\/%!]/ && do
       {
#print"2_$._    ";
           $balance++;
           s/^\s*//;
           &decIndent() if ( !$bLastWasTag );
           &incIndent();
           $bLastWasTag = 1;
           &printIt();
           1;
        }

        ||
        # matches close tags
        m/^\s*<[\/]/ && do
        {
#print"3_$._    ";
            $balance--;
            s/^\s*//;
            &printIt();
            &decIndent() if ( !$bLastWasTag );
            &decIndent();
            $bLastWasTag = 1;
            1;
        }
        || do
        # these are regular text lines; we indent the first
        {
#print"4_$._    ";
            &incIndent() if ( $bLastWasTag );
            $bLastWasTag = 0;
            s/^\s*([^\s])/\1/;
            &printIt();
            1;
        }
        ;

    &doInternalTags();
    }

    if ( 1|| $balance != 0 )
    {
        print STDERR "ERROR: balance: $balance $infile\n";
    }

    exit( balance != 0 );
} #main block
sub decIndent()
{
    $indent =~ s/$shift//;
}

sub incIndent()
{
    $indent = $indent . $shift;
}

sub doInternalTags()
{
#print "$. T balance:$balance\n";
    my $theLine = $_;

    # eat opening tag; we already dealt with it
    $theLine =~ s/^\s*<//;

    #eat tags that close themselves, e.g.  <br />, <input type.... />
    $theLine =~ s-<[^>]*/>--g;

    while( $theLine =~ s/<[^\/%]//)
    {
        $balance++;
        &incIndent();
    }

    while( $theLine =~ s/<[^%]// )
    {
        $balance--;
        &decIndent();
    }

    # if we have any '/>' its the end of a tag that closes itself
    # whose opening '<' was at the beginning of the line.
    while( $theLine =~ s/\/>// )
    {
        $balance--;
        &decIndent();
    }
#print "$. B balance:$balance\n";
}

sub printIt()
{
    print "$indent" . $_;
}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.