mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-24 02:20:09 +08:00
Merge pull request #16660 from lujun9972/add-MjAxOTEyMTMgV2hhdCBHTk9NRSAyIGZhbnMgbG92ZSBhYm91dCB0aGUgTWF0ZSBMaW51eCBkZXNrdG9wLm1kCg==
自动选题: 20191213 What GNOME 2 fans love about the Mate Linux desktop
This commit is contained in:
commit
5c474fbaa2
@ -0,0 +1,88 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to generate code with Apache Velocity)
|
||||
[#]: via: (https://opensource.com/article/19/12/generate-code-apache-velocity)
|
||||
[#]: author: (Girish Managoli https://opensource.com/users/gammay)
|
||||
|
||||
How to generate code with Apache Velocity
|
||||
======
|
||||
Get started with Velocity, an open source, Java-based template engine
|
||||
and code generator that converts templates into source code.
|
||||
![Binary code on a computer screen][1]
|
||||
|
||||
Apache [Velocity][2] is an open source, Java-based template engine and code generator that converts templates into source code. Because it is implemented in Java, it is capable of interpreting varied templates and generating code for any language (web, service, SQL, scripts, etc.), although it seems to be oriented mostly toward web development.
|
||||
|
||||
## Velocity's structure
|
||||
|
||||
Velocity's structure is comprised of an engine and tools. Its core is the Velocity Engine, which uses the defined template, interprets the template language, and generates the code.
|
||||
|
||||
Templates are defined with Velocity Template Language ([VTL][3]), a simple language with effective directives. VTL statements are directives or variables, and variables can be standalone or class methods.
|
||||
|
||||
Examples of VTL expressions include:
|
||||
|
||||
|
||||
```
|
||||
`package ${packagename};`[/code] | Inserts a package statement in Java where the package name is defined as **packagename**
|
||||
---|---
|
||||
```
|
||||
`public ${classname} implements Serializable {`[/code] | Adds a class with name **classname**
|
||||
|
||||
```
|
||||
#foreach( $property in $properties )
|
||||
public ${property.fieldType} get${property.getField()}() {
|
||||
return this.${property.fieldName};
|
||||
}
|
||||
#end [/code] | Creates getter methods for all defined properties
|
||||
|
||||
Velocity tools are collections of basic user-friendly capabilities. There are [GenericTools][4], a "set of classes that provide basic infrastructure for using tools in standard Java SE Velocity projects, as well as a set of tools for use in generic Velocity templates." They include DateTool, MathTool, NumberTool, SortTool, and XmlTool. There are also [VelocityView][5] tools, which include "all of the GenericTools and adds infrastructure and specialized tools for using Velocity in the view layer of web applications (Java EE projects)." VelocityView tools include BrowserTool, CookieTool, and ImportTool
|
||||
|
||||
## Velocity advantages and disadvantages
|
||||
|
||||
Velocity is easy to use and has the capability to generate any language. On the downside, there is a learning curve to understand and apply its template language. Velocity is morphology- and ontology-free. It has no knowledge of the design capability of the module it generates. As a practical example, Velocity may use a template for a controller (e.g., Model-View-Controller or an architecture style) and generate the code, but it has no awareness of the concept of a controller. This is both an advantage and disadvantage, with a generator being simple and easy to use but with no awareness of the design's aptitude.
|
||||
|
||||
## Using Velocity
|
||||
|
||||
Velocity's Java library is available on the [Maven repository][6]. To use the .jar file, define Velocity's latest version in your Maven build config. (Velocity 1.7 is the latest version, as of this writing.) For example, enter the following in your Maven Project Object Model (POM):
|
||||
```
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity</artifactId>
|
||||
<version>1.7</version>
|
||||
</dependency>
|
||||
|
||||
```
|
||||
### Java Hello World example
|
||||
|
||||
To generate code, you need two things:
|
||||
|
||||
1. The **Velocity template** to be used for generation, e.g., java_example.vm: [code] public class ${className} {
|
||||
|
||||
public static void main([String][7][] args) {
|
||||
[System][8].out.println("${message}");
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
2. The **Velocity generator** that uses the template to generate code, e.g., VelocityStartGenerator.java: [code] public class VelocityStartGenerator {
|
||||
|
||||
static [String][7] inputTemplate = "java_example.vm";
|
||||
static [String][7] className = "VelocityExample";
|
||||
static [String][7] message = "Hello World!";
|
||||
static [String][7] outputFile = className + ".java";
|
||||
|
||||
public static void main([String][7][] args) throws [IOException][9] {
|
||||
|
||||
VelocityEngine velocityEngine = new VelocityEngine();
|
||||
velocityEngine.init();
|
||||
|
||||
VelocityContext context = new VelocityContext();
|
||||
context.put("className", className);
|
||||
|
@ -0,0 +1,58 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (What GNOME 2 fans love about the Mate Linux desktop)
|
||||
[#]: via: (https://opensource.com/article/19/12/mate-linux-desktop)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
What GNOME 2 fans love about the Mate Linux desktop
|
||||
======
|
||||
This article is part of a special series of 24 days of Linux desktops.
|
||||
If you remember GNOME 2 fondly, the Mate Linux desktop will fulfill your
|
||||
need for nostalgia.
|
||||
![Linux keys on the keyboard for a desktop computer][1]
|
||||
|
||||
Stop me if you've heard this one before: When GNOME 3 was first released, many GNOME users were not ready to give up GNOME 2. The [Mate][2] (named after the _yerba mate_ plant) project began as an effort to continue the GNOME 2 desktop, at first using GTK 2 (the toolkit GNOME 2 was based upon) and later incorporating GTK 3. The desktop became wildly popular, due in no small part to Linux Mint's prompt adoption of it, and since then, it has become commonly available on Fedora, Ubuntu, Slackware, Arch, and many other Linux distributions. Today, Mate continues to deliver a traditional desktop environment that looks and feels exactly like GNOME 2 did, using the GTK 3 toolkit.
|
||||
|
||||
You may find Mate included in the software repository of your Linux distribution, or you can download and [install][3] a distribution that ships Mate as its default desktop. Before you do, though, be aware that it is meant to provide a full desktop experience, so many Mate apps are installed along with the desktop. If you're running a different desktop, you may find yourself with redundant applications (two PDF readers, two media players, two file managers, and so on). If you just want to try the Mate desktop, you can install a Mate-based distribution in a virtual machine, such as [GNOME Boxes][4].
|
||||
|
||||
### Mate desktop tour
|
||||
|
||||
The Mate project doesn't just evoke GNOME 2; it _is_ GNOME 2. If you were a fan of the Linux desktop back in the mid-'00s, at the very least, you'll find Mate nostalgic. I was not a fan of GNOME 2 and tended to use KDE instead, but there's one place I can't imagine without GNOME 2: [OpenSolaris][5]. The OpenSolaris project didn't last long, coming to prominence when Ian Murdock joined Sun Microsystems just before it was subsumed by Oracle, but I was a low-level Solaris admin at the time and used OpenSolaris to teach myself more about that flavor of Unix. It was the only platform where I used GNOME 2 (because I didn't know how to change the desktop at first and then just got used to it), and today the [OpenIndiana project][6], a community continuation of OpenSolaris, uses GNOME 2 by way of the Mate desktop.
|
||||
|
||||
![Mate on OpenIndiana][7]
|
||||
|
||||
Mate's layout consists of three menus in the top-left corner: Applications, Places, and System. The Applications menu provides quick access to all application launchers installed on the system. The Places menu provides quick access to common locations, such as your home directory, a network folder, and so on. The System menu contains global options, such as shutdown and suspend. In the upper-right corner is a system tray, and there's a taskbar and a virtual desktop pager at the bottom of the screen.
|
||||
|
||||
It's a slightly peculiar configuration, as far as desktop design goes. It borrows equal parts from earlier Linux desktops, the Mac Finder, and Windows, but creates a unique configuration that's intuitive and somehow familiar. Mate intentionally resists deviation from this model, and that's exactly the way its users prefer it.
|
||||
|
||||
### Mate and open source
|
||||
|
||||
Mate is one of the most direct examples of how open source empowers developers to fight against a project's end of life. On paper, GNOME 2 was superseded by GNOME 3, yet it lives on because one developer forked the code and carried on. Momentum grew, more developers joined, and the desktop that users love is healthier than ever. Not all software gets a second chance at life, but the option is always there with open source, and it's always absent otherwise.
|
||||
|
||||
Using and supporting open source means supporting user and developer freedom. And the Mate desktop is a powerful example of what happens when it works.
|
||||
|
||||
Exploring different desktops is a good thing. I’ve recently converted to GNOME 3 ("hallowed be its...
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/12/mate-linux-desktop
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/linux_keyboard_desktop.png?itok=I2nGw78_ (Linux keys on the keyboard for a desktop computer)
|
||||
[2]: https://mate-desktop.org/
|
||||
[3]: https://mate-desktop.org/install/
|
||||
[4]: https://opensource.com/article/19/5/getting-started-gnome-boxes-virtualization
|
||||
[5]: https://en.wikipedia.org/wiki/OpenSolaris
|
||||
[6]: https://www.openindiana.org/documentation/faq/#what-is-openindiana
|
||||
[7]: https://opensource.com/sites/default/files/uploads/advent-mate-openindiana_675px.jpg (Mate on OpenIndiana)
|
Loading…
Reference in New Issue
Block a user