---
title: "Generator"
source: https://dev.pageseeder.com/reference/glossary/generator.html
description: "A generator is a server-side Java component in Berlioz that produces XML responses from content requests by implementing the ContentGenerator interface. Generators are used within services to process requests and can be named and targeted for XSLT matching."
last_updated: 2026-08-11T16:31:24+10:00
tokens: ~490
---

# Generator

A generator is a server-side component written in [Java](java.md) which produces an XML response from a content request. [Berlioz](berlioz.md) libraries provide a number of built-in generators for common use cases.

 It must follow the `ContentGenerator` Java interface.

```js

public interface ContentGenerator {

  void process(ContentRequest req, XMLWriter xml)
    throws BerliozException, IOException;

}
```

Generators can have other features, for example, cacheable.

## Usage

In order for a generator to be invoked, it must be part of a service. The same generator can be used in multiple services.

In the context of a service, a generator can be given a name and a target to make it easier for XSLT templates to match.

For example:

```xml
<service id="get-user" method="get">
  <url pattern="/user/{username}"/>
  <generator name="user" target="main" class="org.example.GetUser"/>
</service>
```

## Examples

Generators can be used to return any content.

> **Note:** The following examples are only used to demonstrate how to write simple generators; they aren’t meant to be used verbatim in a production environment where other aspects such as caching and error handling should be considered.

### Current user

A generator could return the user currently in the session. This kind of generator would be included in most services in the app.

```js

public void process(ContentRequest req, XMLWriter xml) throws IOException {
  HttpSession session = req.getSession();
  User user = (user)session.getAttribute("org.example.User");
  if (user != null) {
    user.toXML(xml);
  }
}
```

### PSML document

A generator could also be used to return an XML or [PSML](psml.md) document on the server.

```js

public void process(ContentRequest req, XMLWriter xml) throws IOException {
  String path = req.getBerliozPath();
  File file = new File(PSML_ROOT, path+".psml");
  if (file.exists()) {
    XMLCopy.copyTo(file, xml);
  }
}
```

