package jetbrains.mps.core.xml.textGen;

/*Generated by MPS */

import jetbrains.mps.text.rt.TextGenDescriptorBase;
import jetbrains.mps.text.rt.TextGenContext;
import jetbrains.mps.text.impl.TextGenSupport;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import org.jetbrains.mps.openapi.language.SProperty;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;

public class XmlExternalId_TextGen extends TextGenDescriptorBase {
  @Override
  public void generateText(final TextGenContext ctx) {
    final TextGenSupport tgs = new TextGenSupport(ctx);
    if (SPropertyOperations.getBoolean(ctx.getPrimaryInput(), PROPS.isPublic$E5Jp)) {
      tgs.append("PUBLIC");
      tgs.append(" ");
      if (isNotEmptyString(SPropertyOperations.getString(ctx.getPrimaryInput(), PROPS.publicId$E5hn)) && SPropertyOperations.getString(ctx.getPrimaryInput(), PROPS.publicId$E5hn).contains("'")) {
        tgs.append("\"");
        tgs.append(SPropertyOperations.getString(ctx.getPrimaryInput(), PROPS.publicId$E5hn));
        tgs.append("\"");
      } else {
        tgs.append("'");
        tgs.append(SPropertyOperations.getString(ctx.getPrimaryInput(), PROPS.publicId$E5hn));
        tgs.append("'");
      }
    } else {
      tgs.append("SYSTEM");
    }
    tgs.append(" ");
    if (isNotEmptyString(SPropertyOperations.getString(ctx.getPrimaryInput(), PROPS.systemId$E5wo)) && SPropertyOperations.getString(ctx.getPrimaryInput(), PROPS.systemId$E5wo).contains("'")) {
      tgs.append("\"");
      tgs.append(SPropertyOperations.getString(ctx.getPrimaryInput(), PROPS.systemId$E5wo));
      tgs.append("\"");
    } else {
      tgs.append("'");
      tgs.append(SPropertyOperations.getString(ctx.getPrimaryInput(), PROPS.systemId$E5wo));
      tgs.append("'");
    }

  }
  private static boolean isNotEmptyString(String str) {
    return str != null && str.length() > 0;
  }

  private static final class PROPS {
    /*package*/ static final SProperty isPublic$E5Jp = MetaAdapterFactory.getProperty(0x479c7a8c02f943b5L, 0x9139d910cb22f298L, 0x1d9c27c394f6033fL, 0x1d9c27c394f60345L, "isPublic");
    /*package*/ static final SProperty publicId$E5hn = MetaAdapterFactory.getProperty(0x479c7a8c02f943b5L, 0x9139d910cb22f298L, 0x1d9c27c394f6033fL, 0x1d9c27c394f60343L, "publicId");
    /*package*/ static final SProperty systemId$E5wo = MetaAdapterFactory.getProperty(0x479c7a8c02f943b5L, 0x9139d910cb22f298L, 0x1d9c27c394f6033fL, 0x1d9c27c394f60344L, "systemId");
  }
}
