All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.unidal.lookup.configuration.Configurators Maven / Gradle / Ivy

The newest version!
package org.unidal.lookup.configuration;

import java.util.List;

import org.unidal.lookup.container.model.entity.PlexusModel;
import org.unidal.lookup.container.model.transform.DefaultXmlBuilder;

public class Configurators {
   private Configurators() {
   }

   public static final Configurators forPlexus() {
      return new Configurators();
   }

   public String generateXmlConfiguration(Configurator configurator, List components) {
      PlexusModel model = new PlexusModel();

      for (Component component : components) {
         model.addComponent(component.getModel());
      }

      StringBuilder sb = new StringBuilder(4096);
      String xml = new DefaultXmlBuilder(false, sb).buildXml(model);
      String comment = String.format("",
            configurator.getClass().getName());

      xml = prependComment(xml, comment);

      return xml.replaceAll("   ", "\t").replaceAll("\r\n", "\n");
   }

   private String prependComment(String xml, String comment) {
      String instrument = "\r\n";

      if (xml.startsWith(instrument)) {
         return instrument + comment + "\n" + xml.substring(instrument.length());
      } else {
         return comment + xml;
      }
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy