Texen
  1. Texen
  2. TEXEN-2

Provide class to be called from command-line to translate any file with special suffix.

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      WindowsXP

      Description

      This is a simple but important feature to have. To standadize the use of Velocity, provide a class that can be called from the command-line that will do the translation from *.vm ---> final-file. The class will look for any file that has one of the special suffixes (specified by as parameters) and will translate it.

      The name convention for the translation would like this that:
      someFileName.velocity ---> someFileName
      someFileName.vm ---> someFileName

      Example:
      myFile.html.velocity ---> myFile.html

      The user would specify the list of suffixes as parameter in Java (like String[] suffixes =

      { ".velocity", ".vm" }

      .

      1. Transformer.java
        14 kB
        Christoph Reck

        Activity

        Hide
        Nathan Bubna added a comment -

        Oops. Forgot to actually change the component.

        Show
        Nathan Bubna added a comment - Oops. Forgot to actually change the component.
        Hide
        Nathan Bubna added a comment -

        I think this (and VELOCITY-442, of course) are a better fit for Texen than the VelocityEngine.

        I'm also still hoping that we can pull Texen (and Anakia) out of Engine and put them in their own projects. I have some needs soon approaching for which an improved Texen (with things like this) would be quite handy. I'd love to be able to deprecate it in Engine and release an independent Texen before (or otherwise apart from) Velocity 1.6.

        After Velocity 1.5 is out, expect me to push for creating a Texen project and dragging ideas like this one into it.

        If you really feel strongly that this belongs in Engine, i'll change it back, until we've discussed it. I'm just betting you don't feel that strongly and moving it before asking.

        Show
        Nathan Bubna added a comment - I think this (and VELOCITY-442 , of course) are a better fit for Texen than the VelocityEngine. I'm also still hoping that we can pull Texen (and Anakia) out of Engine and put them in their own projects. I have some needs soon approaching for which an improved Texen (with things like this) would be quite handy. I'd love to be able to deprecate it in Engine and release an independent Texen before (or otherwise apart from) Velocity 1.6. After Velocity 1.5 is out, expect me to push for creating a Texen project and dragging ideas like this one into it. If you really feel strongly that this belongs in Engine, i'll change it back, until we've discussed it. I'm just betting you don't feel that strongly and moving it before asking.
        Hide
        Henning Schmiedehausen added a comment -

        Well, it is engine'ish, so move it there and let's review it after the 1.5 release.

        Show
        Henning Schmiedehausen added a comment - Well, it is engine'ish, so move it there and let's review it after the 1.5 release.
        Hide
        Henning Schmiedehausen added a comment -

        this is not a build problem (build means "Velocity build"), so I set the component to "unknown".

        Show
        Henning Schmiedehausen added a comment - this is not a build problem (build means "Velocity build"), so I set the component to "unknown".
        Hide
        Colbert Philippe added a comment -

        Good suggestion! I have question though. Why does Transformer have to be specific to XML? Why can't it be for general use?

        Text file preprocessing is nothing new. It's as old as Assembly Language. Under unix there was a number of source file macro preprocessors. One of them was called M4. M4 was for general use, felixbile and expressive. The usefulness of macro preprocessors got lost in the programming tradition. It's time to revive it given that Velocity already exists.

        I am suggesting to do the same thing with Velocity. There should be no assumption as to the nature of the source file.

        I like the fact that your Transformer.java handles a variety of text encoding. I have never messed around with that.

        Show
        Colbert Philippe added a comment - Good suggestion! I have question though. Why does Transformer have to be specific to XML? Why can't it be for general use? Text file preprocessing is nothing new. It's as old as Assembly Language. Under unix there was a number of source file macro preprocessors. One of them was called M4. M4 was for general use, felixbile and expressive. The usefulness of macro preprocessors got lost in the programming tradition. It's time to revive it given that Velocity already exists. I am suggesting to do the same thing with Velocity. There should be no assumption as to the nature of the source file. I like the fact that your Transformer.java handles a variety of text encoding. I have never messed around with that.
        Hide
        Christoph Reck added a comment -

        find attached a tool using anakia for transformations. It may also take CSV or just run a plain VTL file against the context.

        It may use a CSV tool, Anakia, DOM reader and/or a XmlConfiguration reader.
        The setup of these tools should be replaced by the VelocityToolbox manager (Nathan there was a thread on this...). Use examples:
        #set( $now = $date.clone() )
        #set( $LF = $Context.formDecode("%0A") )
        #set( $Integer = 1 )
        #set( $Long = $Integer.longValue() )
        #set( $cdLimit = $Long.valueOf("640000000") )

        I also used a ClassTool to setup e.g. a FileWriter:

          1. ------------------------------------------------------------------------
          2. Macro to write a text to a file.
          3. ------------------------------------------------------------------------
            #macro( fileWrite $filename $text )
            #set( $out = $Class.newInstance("java.io.FileOutputStream", $filename) )
            #set( $data = $text.getBytes() )
            #call( $out.write($data) )
            #call( $out.close() )
            #end

        It would also be sensible to add a command line parameter to define the VelociMacro file
        to load at startup (maybe via ToolboxManager?).

        Cheers,
        Christoph

        Show
        Christoph Reck added a comment - find attached a tool using anakia for transformations. It may also take CSV or just run a plain VTL file against the context. It may use a CSV tool, Anakia, DOM reader and/or a XmlConfiguration reader. The setup of these tools should be replaced by the VelocityToolbox manager (Nathan there was a thread on this...). Use examples: #set( $now = $date.clone() ) #set( $LF = $Context.formDecode("%0A") ) #set( $Integer = 1 ) #set( $Long = $Integer.longValue() ) #set( $cdLimit = $Long.valueOf("640000000") ) I also used a ClassTool to setup e.g. a FileWriter: ------------------------------------------------------------------------ Macro to write a text to a file. ------------------------------------------------------------------------ #macro( fileWrite $filename $text ) #set( $out = $Class.newInstance("java.io.FileOutputStream", $filename) ) #set( $data = $text.getBytes() ) #call( $out.write($data) ) #call( $out.close() ) #end It would also be sensible to add a command line parameter to define the VelociMacro file to load at startup (maybe via ToolboxManager?). Cheers, Christoph
        Hide
        Nathan Bubna added a comment -

        yeah, this would be a very handy little tool. I would have some use for it too. And it should actually be pretty easy to write too. My only thought is whether it wouldn't be better as part of VelocityTools.

        Anyway, if you or someone else doesn't beat me to writing it, i might take a stab at it one of these days.

        Show
        Nathan Bubna added a comment - yeah, this would be a very handy little tool. I would have some use for it too. And it should actually be pretty easy to write too. My only thought is whether it wouldn't be better as part of VelocityTools. Anyway, if you or someone else doesn't beat me to writing it, i might take a stab at it one of these days.

          People

          • Assignee:
            Unassigned
            Reporter:
            Colbert Philippe
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development