示例#1
0
  protected int getFieldValueIndex(
      String[] fieldsDisplayValues, String fieldName, String instanceId) {

    if (Validator.isNull(instanceId)) {
      return -1;
    }

    int offset = 0;

    String prefix = fieldName.concat(INSTANCE_SEPARATOR);

    for (String fieldsDisplayValue : fieldsDisplayValues) {
      if (fieldsDisplayValue.startsWith(prefix)) {
        String fieldIstanceId =
            StringUtil.extractLast(fieldsDisplayValue, DDMImpl.INSTANCE_SEPARATOR);

        if (fieldIstanceId.equals(instanceId)) {
          return offset;
        }

        offset++;
      }
    }

    return -1;
  }
  protected String getLastDDMFormFieldParameterName(String ddmFormFieldParameterName) {

    String lastDDMFormFieldParameterName =
        StringUtil.extractLast(
            ddmFormFieldParameterName, DDMFormRendererConstants.DDM_FORM_FIELDS_SEPARATOR);

    if (lastDDMFormFieldParameterName == null) {
      return ddmFormFieldParameterName;
    }

    return lastDDMFormFieldParameterName;
  }
示例#3
0
  protected String getFieldIntanceId(String[] fieldsDisplayValues, String fieldName, int index) {

    String prefix = fieldName.concat(INSTANCE_SEPARATOR);

    for (String fieldsDisplayValue : fieldsDisplayValues) {
      if (fieldsDisplayValue.startsWith(prefix)) {
        index--;

        if (index < 0) {
          return StringUtil.extractLast(fieldsDisplayValue, DDMImpl.INSTANCE_SEPARATOR);
        }
      }
    }

    return null;
  }
示例#4
0
  public Tuple service(String method, String path, Map<String, String> headers, byte[] data) {

    WebDAVStorage webDAVStorage = new DLWebDAVStorageImpl();

    webDAVStorage.setToken("document_library");

    WebDAVUtil.addStorage(webDAVStorage);

    WebDAVServlet webDAVServlet = new WebDAVServlet();

    String requestURI = _CONTEXT_PATH + _SERVLET_PATH + _PATH_INFO_PREFACE + path;

    MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(method, requestURI);

    mockHttpServletRequest.setContextPath(_CONTEXT_PATH);
    mockHttpServletRequest.setServletPath(_SERVLET_PATH);
    mockHttpServletRequest.setPathInfo(_PATH_INFO_PREFACE + path);

    try {
      mockHttpServletRequest.setRemoteUser(String.valueOf(TestPropsValues.getUserId()));
    } catch (Exception e) {
      Assert.fail("User ID cannot be initialized");
    }

    if (headers == null) {
      headers = new HashMap<String, String>();
    }

    headers.put(HttpHeaders.USER_AGENT, getUserAgent());

    try {
      throw new Exception();
    } catch (Exception e) {
      StackTraceElement[] stackTraceElements = e.getStackTrace();

      for (StackTraceElement stackTraceElement : stackTraceElements) {
        String methodName = stackTraceElement.getMethodName();

        if (methodName.equals("setUp")
            || methodName.equals("tearDown")
            || methodName.startsWith("test")) {

          String testName =
              StringUtil.extractLast(stackTraceElement.getClassName(), CharPool.PERIOD);

          testName =
              StringUtil.replace(testName, new String[] {"WebDAV", "Test"}, new String[] {"", ""});

          headers.put(
              "X-Litmus",
              testName
                  + ": ("
                  + stackTraceElement.getMethodName()
                  + ":"
                  + stackTraceElement.getLineNumber()
                  + ")");

          break;
        }
      }
    }

    if (data != null) {
      mockHttpServletRequest.setContent(data);

      String contentType = headers.remove(HttpHeaders.CONTENT_TYPE);

      if (contentType != null) {
        mockHttpServletRequest.setContentType(contentType);
      } else {
        mockHttpServletRequest.setContentType(ContentTypes.TEXT_PLAIN);
      }
    }

    for (Map.Entry<String, String> entry : headers.entrySet()) {
      String key = entry.getKey();
      String value = entry.getValue();

      mockHttpServletRequest.addHeader(key, value);
    }

    try {
      MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();

      webDAVServlet.service(mockHttpServletRequest, mockHttpServletResponse);

      int statusCode = mockHttpServletResponse.getStatus();
      byte[] responseBody = mockHttpServletResponse.getContentAsByteArray();

      Map<String, String> responseHeaders = new HashMap<String, String>();

      for (String name : mockHttpServletResponse.getHeaderNames()) {
        responseHeaders.put(name, (String) mockHttpServletResponse.getHeader(name));
      }

      return new Tuple(statusCode, responseBody, responseHeaders);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return null;
  }
 protected String extractPrefix(String ddmFormFieldParameterName) {
   return StringUtil.extractLast(
       ddmFormFieldParameterName, DDMFormRendererConstants.DDM_FORM_FIELD_NAME_PREFIX);
 }
  protected void writeEclipseFiles(File libDir, File projectDir, List<String> dependencyJars)
      throws Exception {

    String projectDirName = projectDir.getCanonicalPath();

    String projectName = StringUtil.extractLast(projectDirName, File.separatorChar);

    boolean javaProject = false;

    for (String sourceDirName : _SOURCE_DIR_NAMES) {
      if (_fileUtil.exists(projectDirName + "/" + sourceDirName)) {
        javaProject = true;

        break;
      }
    }

    if (!javaProject) {
      System.out.println(
          "Eclipse Java project will not be used because a source " + "folder does not exist");
    }

    writeProjectFile(projectDirName, projectName, javaProject);

    writeClasspathFile(libDir, dependencyJars, projectDirName, projectName, javaProject);

    for (String sourceDirName : _SOURCE_DIR_NAMES) {
      if (_fileUtil.exists(projectDirName + "/" + sourceDirName)) {
        List<String> gitIgnores = new ArrayList<String>();

        if (sourceDirName.endsWith("ext-impl/src")) {
          gitIgnores.add("/classes");
          gitIgnores.add("/ext-impl.jar");
        } else if (sourceDirName.endsWith("ext-service/src")) {
          gitIgnores.add("/classes");
          gitIgnores.add("/ext-service.jar");
        } else if (sourceDirName.endsWith("ext-util-bridges/src")) {
          gitIgnores.add("/classes");
          gitIgnores.add("/ext-util-bridges.jar");
        } else if (sourceDirName.endsWith("ext-util-java/src")) {
          gitIgnores.add("/classes");
          gitIgnores.add("/ext-util-java.jar");
        } else if (sourceDirName.endsWith("ext-util-taglib/src")) {
          gitIgnores.add("/classes");
          gitIgnores.add("/ext-util-taglib.jar");
        } else {
          continue;
        }

        String dirName = projectDirName + "/" + sourceDirName + "/../";

        if (gitIgnores.isEmpty()) {
          _fileUtil.delete(dirName + ".gitignore");
        } else {
          String gitIgnoresString = StringUtil.merge(gitIgnores, "\n");

          _fileUtil.write(dirName + ".gitignore", gitIgnoresString);
        }
      }
    }

    if (_fileUtil.exists(projectDirName + "/test")) {
      _fileUtil.write(projectDirName + "/.gitignore", "/test-classes\n/test-results");
    } else {
      _fileUtil.delete(projectDirName + "/.gitignore");
    }
  }