close

Filter

loading table of contents...

Headless Server Developer Manual / Version 2204

Table Of Contents

5.2.2 Developing Custom RichTextAdapters

Please note, that the following example code is abbreviated for demonstration purposes.

To develop a custom RichTextAdapter, these three basic steps must be made:

  1. Implement your own RichTextAdapter
  2. Implement a RichTextAdapterFactory for your RichTextAdapter
  3. Implement a "To-Map" Converter for your RichTextAdapter

First step:

Implement a custom RichTextAdapter which is able to parse the intended XML grammar and provide it as an object structure which represents the XML tree. Optionally also support the transformation of the parsed grammar into any other "view", for example, transform the former markup into XML, which is bare of any XML tags but the surrounding root tag.

public class ExampleGrammarRichTextAdapter extends AbstractRichTextAdapter {
  public ExampleGrammarRichTextAdapter(Markup markup) {
    super(markup);
  }

  @Override
  public <T> T asTree(Class<? extends T> type) {
    return null;
  }

  @Override
  public Set<Content> getReferencedContent() {
    return null;
  }

  @Override
  public String asString() {
    return null;
  }
}

Second step:

Create a factory class for your adapter and provide it as a bean in CaasConfig.

public class ExampleRichTextAdapterFactory
implements RichTextAdapterFactory<ExampleGrammarRichTextAdapter> {
  @Override
  public String getGrammar() {
    return "my-xml-grammar-1.0";
  }

  @Override
  public ExampleGrammarRichTextAdapter to(Markup markup) {
    return new ExampleGrammarRichTextAdapter(markup);
  }
}
@Bean
public ExampleRichTextAdapterFactory exampleGrammarRichTextFactory() {
  return new ExampleRichTextAdapterFactory();
}

Third step:

Implement a "To-Map" converter, which is responsible to convert your transformed XML tree representation into a common, Map based tree structure, which is easy to digest for graphql-java. Also provide it as a bean in CaasConfig.

public class ExampleRichTextToMapConverter
implements RichTextToMapConverter<ExampleGrammarRichTextAdapter> {
  @Override
  public Map<String, Object> convert(ExampleGrammarRichTextAdapter source)
  {
    return null;
  }
}
@Bean
public ExampleRichTextToMapConverter exampleRichTextToMapConverter() {
  return new ExampleRichTextToMapConverter();
}

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.