Package com.liferay.faces.util.io

Examples of com.liferay.faces.util.io.TextResource


    }

    URL resourceURL = relativeClass.getResource(resourcePath);

    if (resourceURL != null) {
      TextResource textResource = TextResourceUtil.read(resourceURL);
      String templateText = textResource.getText();

      return getTemplate(templateText, contentType);
    }
    else {
      throw new IOException("Unable to read file " + resourcePath);
View Full Code Here


  private static final String XML = "xml";

  public static CodeExample read(URL sourceFileURL, String sourceFileName, boolean productionMode)
    throws IOException {

    TextResource textResource = TextResourceUtil.read(sourceFileURL);
    String sourceCodeText = textResource.getText();

    if (sourceCodeText != null) {

      String fileExtension;

      if (sourceFileName.endsWith(JAVA_EXTENSION)) {
        fileExtension = JAVA;

        Matcher matcher = JAVA_MULTILINE_COMMENTS_PATTERN.matcher(sourceCodeText);
        sourceCodeText = matcher.replaceAll(StringPool.BLANK);
      }
      else {
        fileExtension = XML;
        sourceCodeText = TEMPLATE_ATTRIBUTE_PATTERN.matcher(sourceCodeText).replaceAll(StringPool.BLANK);
        sourceCodeText = SHOWCASE_NAMESPACE_PATTERN.matcher(sourceCodeText).replaceAll(StringPool.BLANK);

        StringReader stringReader = new StringReader(sourceCodeText);
        StringBuffer buf = new StringBuffer();
        BufferedReader bufferedReader = new BufferedReader(stringReader);
        int trimTab = 0;
        String line;
        boolean ignoreNextLine = false;

        while ((line = bufferedReader.readLine()) != null) {
          String trimmedLine = line.trim();

          if (ignoreNextLine) {
            ignoreNextLine = !trimmedLine.endsWith(StringPool.GREATER_THAN);
          }
          else {

            if (trimmedLine.startsWith("<showcase") || trimmedLine.startsWith("<ui:define")) {
              trimTab++;
              ignoreNextLine = !trimmedLine.endsWith(StringPool.GREATER_THAN);
            }
            else if (trimmedLine.startsWith("</showcase") || trimmedLine.startsWith("</ui:define")) {
              trimTab--;
            }
            else {

              for (int i = 0; i < trimTab; i++) {

                if (line.startsWith(StringPool.TAB)) {
                  line = line.substring(1);
                }
              }

              int pos = line.indexOf(OUTPUTMODEL_MODELVALUE);

              if (pos > 0) {
                line = line.substring(0, pos) + ":modelValue" +
                  line.substring(pos + OUTPUTMODEL_MODELVALUE.length());
              }

              pos = line.indexOf(RENDER_EXAMPLE_FORM);

              if (pos > 0) {
                line = line.substring(0, pos) + "render=\"" +
                  line.substring(pos + RENDER_EXAMPLE_FORM.length());
              }

              pos = line.indexOf(RENDER_FORM_EXAMPLE);

              if (pos > 0) {
                line = line.substring(0, pos) + "render=\":exampleForm" +
                  line.substring(pos + RENDER_FORM_EXAMPLE.length());
              }

              if (productionMode) {
                pos = line.indexOf(RENDERED);

                if (pos > 0) {
                  line = line.substring(0, pos) + line.substring(pos + RENDERED.length());
                }
              }

              // Strip empty lines
              Pattern BLANK_LINE_PATTERN = Pattern.compile("\\t+$");
              Matcher matcher = BLANK_LINE_PATTERN.matcher(line);
              if (!matcher.matches()) {
                buf.append(line);
                buf.append(StringPool.NEW_LINE);
              }
            }
          }
        }

        sourceCodeText = buf.toString();
      }

      sourceCodeText = sourceCodeText.trim();

      return new CodeExample(sourceFileName, fileExtension, sourceFileURL, textResource.getLastModified(),
          sourceCodeText);
    }
    else {
      throw new IOException("Unable to locate " + sourceFileURL);
    }
View Full Code Here

TOP

Related Classes of com.liferay.faces.util.io.TextResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.