Пример #1
0
 private void addCreateLexerMethod(StringComposite sc) {
   sc.add("public " + iTextScannerClassName + " createLexer() {");
   if (OptionManager.INSTANCE.useScalesParser(getContext().getConcreteSyntax())) {
     sc.add("return new " + scannerlessScannerClassName + "();");
   } else {
     sc.add("return new " + antlrScannerClassName + "(new " + antlrLexerClassName + "());");
   }
   sc.add("}");
   sc.addLineBreak();
 }
Пример #2
0
  private void addCreateParserMethod(de.devboost.codecomposers.java.JavaComposite sc) {
    String parserClassName = antlrParserClassName;
    if (OptionManager.INSTANCE.useScalesParser(getContext().getConcreteSyntax())) {
      parserClassName = scannerlessParserClassName;
    }

    sc.add(
        "public "
            + iTextParserClassName
            + " createParser("
            + INPUT_STREAM(sc)
            + " inputStream, String encoding) {");
    sc.add("return new " + parserClassName + "().createInstance(inputStream, encoding);");
    sc.add("}");
    sc.addLineBreak();
  }
Пример #3
0
  @Override
  public void generateJavaContents(JavaComposite sc) {
    useScalesParser = OptionManager.INSTANCE.useScalesParser(getContext().getConcreteSyntax());

    sc.add("package " + getResourcePackageName() + ";");
    sc.addLineBreak();
    sc.addImportsPlaceholder();
    sc.addLineBreak();

    sc.add(
        "public class "
            + getResourceClassName()
            + " implements "
            + iMetaInformationClassName
            + " {");
    sc.addLineBreak();
    addMethods(sc);
    sc.add("}");
  }
Пример #4
0
  private void addCreatePrinterMethod(de.devboost.codecomposers.java.JavaComposite sc) {
    String usedPrinterClassName;
    boolean useClassicPrinter =
        OptionManager.INSTANCE.getBooleanOptionValue(
            getContext().getConcreteSyntax(), OptionTypes.USE_CLASSIC_PRINTER);

    sc.add(
        "public "
            + iTextPrinterClassName
            + " createPrinter("
            + OUTPUT_STREAM(sc)
            + " outputStream, "
            + iTextResourceClassName
            + " resource) {");
    if (useClassicPrinter) {
      usedPrinterClassName = printerClassName;
    } else {
      usedPrinterClassName = printer2ClassName;
    }
    sc.add("return new " + usedPrinterClassName + "(outputStream, resource);");
    sc.add("}");
    sc.addLineBreak();
  }
Пример #5
0
  private void addRegisterResourceFactoryMethod(JavaComposite sc) {
    final String secondaryConcreteSyntaxName =
        csUtil.getSecondarySyntaxName(getContext().getConcreteSyntax());

    sc.add("public void registerResourceFactory() {");
    if (secondaryConcreteSyntaxName == null) {
      sc.add("// if no resource factory registered, register delegator");

      sc.add(
          "if ("
              + RESOURCE_FACTORY(sc)
              + ".Registry.INSTANCE.getExtensionToFactoryMap().get(getSyntaxName()) == null) {");
      sc.add(
          RESOURCE_FACTORY(sc)
              + ".Registry.INSTANCE.getExtensionToFactoryMap().put(getSyntaxName(), new "
              + resourceFactoryDelegatorClassName
              + "());");
      sc.add("}");
    } else {
      // if this is a secondary syntax, the ResourceFactory is registered
      // using the 'additional_extension_parser' extension point.
      // Unfortunately, we do not know the name of the corresponding
      // registry because it can be implemented in arbitrary ways in the
      // base resource plug-in.
      sc.addComment(
          "This is a secondary syntax. "
              + "Registering the resource factory is done via the 'additional_extension_parser' extension point.");
    }

    // Register resource factory for additional file extensions if required.
    GenerationContext context = getContext();
    ConcreteSyntax syntax = context.getConcreteSyntax();
    Collection<String> additionalFileExtensions =
        OptionManager.INSTANCE.getStringOptionValueAsCollection(
            syntax, OptionTypes.ADDITIONAL_FILE_EXTENSIONS);

    if (additionalFileExtensions != null && !additionalFileExtensions.isEmpty()) {
      sc.addLineBreak();
      sc.add("Factory.Registry registry = " + RESOURCE_FACTORY(sc) + ".Registry.INSTANCE;");
      sc.add(
          MAP(sc)
              + "<String, Object> extensionToFactoryMap = registry.getExtensionToFactoryMap();");
      sc.addLineBreak();
      sc.add(
          resourceFactoryClassName + " resourceFactory = new " + resourceFactoryClassName + "();");
      sc.addLineBreak();
      sc.addComment("Register resource factory for additional extensions.");

      for (String additionalFileExtension : additionalFileExtensions) {
        additionalFileExtension = additionalFileExtension.trim();

        sc.add("if (extensionToFactoryMap.get(\"" + additionalFileExtension + "\") == null) {");
        sc.add("extensionToFactoryMap.put(\"" + additionalFileExtension + "\", resourceFactory);");
        sc.add("}");
        sc.addLineBreak();
      }
    }

    sc.add("}");
    sc.addLineBreak();
  }