Beispiel #1
0
  protected void addModelValidatorTags() {
    Class<?> model = getModel();

    if ((model == null) || Validator.isNotNull(getType())) {
      return;
    }

    List<Tuple> modelValidators = ModelHintsUtil.getValidators(model.getName(), getField());

    if (modelValidators == null) {
      return;
    }

    for (Tuple modelValidator : modelValidators) {
      String validatorName = (String) modelValidator.getObject(1);
      String validatorErrorMessage = (String) modelValidator.getObject(2);
      String validatorValue = (String) modelValidator.getObject(3);
      boolean customValidator = (Boolean) modelValidator.getObject(4);

      ValidatorTag validatorTag =
          new ValidatorTagImpl(
              validatorName, validatorErrorMessage, validatorValue, customValidator);

      addValidatorTag(validatorName, validatorTag);
    }
  }
    @Override
    public JobDetail getJobDetail(JobKey jobKey) {
      Tuple tuple = _jobs.get(jobKey);

      if (tuple == null) {
        return null;
      }

      return (JobDetail) tuple.getObject(0);
    }
    @Override
    public org.quartz.Trigger getTrigger(TriggerKey triggerKey) {
      Tuple tuple = _jobs.get(new JobKey(triggerKey.getName(), triggerKey.getGroup()));

      if (tuple == null) {
        return null;
      }

      return (org.quartz.Trigger) tuple.getObject(1);
    }
    @Override
    public void pauseJob(JobKey jobKey) {
      Tuple tuple = _jobs.get(jobKey);

      if (tuple == null) {
        return;
      }

      _jobs.put(jobKey, new Tuple(tuple.getObject(0), tuple.getObject(1), TriggerState.PAUSED));
    }
    @Override
    public Date rescheduleJob(TriggerKey triggerKey, org.quartz.Trigger trigger) {

      JobKey jobKey = new JobKey(triggerKey.getName(), triggerKey.getGroup());

      Tuple tuple = _jobs.get(jobKey);

      if (tuple == null) {
        return null;
      }

      _jobs.put(jobKey, new Tuple(tuple.getObject(0), trigger, tuple.getObject(2)));

      return null;
    }
  protected int getStatus(RenderRequest renderRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (!themeDisplay.isSignedIn()) {
      return WorkflowConstants.STATUS_APPROVED;
    }

    String statusString = renderRequest.getParameter("status");

    int status = GetterUtil.getInteger(statusString);

    if ((statusString != null) && (status == WorkflowConstants.STATUS_APPROVED)) {

      return WorkflowConstants.STATUS_APPROVED;
    }

    Tuple resourceTuple = getResourceTuple(renderRequest);

    long resourcePrimKey = (Long) resourceTuple.getObject(1);

    if (resourcePrimKey == KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
      return WorkflowConstants.STATUS_APPROVED;
    }

    long resourceClassNameId = (Long) resourceTuple.getObject(0);

    long kbArticleClassNameId = PortalUtil.getClassNameId(KBArticleConstants.getClassName());

    if (resourceClassNameId == kbArticleClassNameId) {
      KBArticle kbArticle =
          KBArticleServiceUtil.fetchLatestKBArticle(resourcePrimKey, WorkflowConstants.STATUS_ANY);

      if (kbArticle == null) {
        return WorkflowConstants.STATUS_APPROVED;
      }

      if (KBArticlePermission.contains(
          themeDisplay.getPermissionChecker(), resourcePrimKey, ActionKeys.UPDATE)) {

        return ParamUtil.getInteger(renderRequest, "status", WorkflowConstants.STATUS_ANY);
      }
    }

    return WorkflowConstants.STATUS_APPROVED;
  }
  private void _updateJavadocsXmlFile(
      String fileName, JavaClass javaClass, Document javaClassDocument) throws Exception {

    String javaClassFullyQualifiedName = javaClass.getFullyQualifiedName();

    /*if (!javaClassFullyQualifiedName.contains(".service.") ||
    	!javaClassFullyQualifiedName.endsWith("ServiceImpl")) {

    	return;
    }*/

    Tuple javadocsXmlTuple = _getJavadocsXmlTuple(fileName);

    if (javadocsXmlTuple == null) {
      return;
    }

    Document javadocsXmlDocument = (Document) javadocsXmlTuple.getObject(3);

    Element javadocsXmlRootElement = javadocsXmlDocument.getRootElement();

    List<Element> javadocElements = javadocsXmlRootElement.elements("javadoc");

    for (Element javadocElement : javadocElements) {
      String type = javadocElement.elementText("type");

      if (type.equals(javaClassFullyQualifiedName)) {
        Element javaClassRootElement = javaClassDocument.getRootElement();

        if (Validator.equals(
            javadocElement.formattedString(), javaClassRootElement.formattedString())) {

          return;
        }

        javadocElement.detach();

        break;
      }
    }

    javadocsXmlRootElement.add(javaClassDocument.getRootElement());
  }
  protected void updateScope(ActionRequest actionRequest, Portlet portlet) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String oldScopeName = getOldScopeName(actionRequest, portlet);

    PortletPreferences portletPreferences = actionRequest.getPreferences();

    String[] scopes = StringUtil.split(ParamUtil.getString(actionRequest, "scope"));

    String scopeType = scopes[0];

    portletPreferences.setValue("lfrScopeType", scopeType);

    String scopeLayoutUuid = StringPool.BLANK;

    if ((scopes.length > 1) && scopeType.equals("layout")) {
      scopeLayoutUuid = scopes[1];
    }

    portletPreferences.setValue("lfrScopeLayoutUuid", scopeLayoutUuid);

    String portletTitle = getPortletTitle(actionRequest, portlet, portletPreferences);

    Tuple newScopeTuple = getNewScope(actionRequest);

    String newScopeName = (String) newScopeTuple.getObject(1);

    String newPortletTitle =
        PortalUtil.getNewPortletTitle(portletTitle, oldScopeName, newScopeName);

    if (!newPortletTitle.equals(portletTitle)) {
      portletPreferences.setValue(
          "portletSetupTitle_" + themeDisplay.getLanguageId(), newPortletTitle);
      portletPreferences.setValue("portletSetupUseCustomTitle", Boolean.TRUE.toString());
    }

    portletPreferences.store();
  }
  protected void setDDMStructure() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    _ddmStructureDisplayFieldValue = StringPool.BLANK;
    _ddmStructureFieldLabel = StringPool.BLANK;
    _ddmStructureFieldName = StringPool.BLANK;
    _ddmStructureFieldValue = null;

    long[] classNameIds = getClassNameIds();
    long[] classTypeIds = getClassTypeIds();

    if (isSubtypeFieldsFilterEnabled()
        && (classNameIds.length == 1)
        && (classTypeIds.length == 1)) {

      _ddmStructureDisplayFieldValue =
          GetterUtil.getString(
              _portletPreferences.getValue("ddmStructureDisplayFieldValue", StringPool.BLANK));
      _ddmStructureFieldName =
          GetterUtil.getString(
              _portletPreferences.getValue("ddmStructureFieldName", StringPool.BLANK));
      _ddmStructureFieldValue =
          _portletPreferences.getValue("ddmStructureFieldValue", StringPool.BLANK);

      if (Validator.isNotNull(_ddmStructureFieldName)
          && Validator.isNotNull(_ddmStructureFieldValue)) {

        AssetRendererFactory assetRendererFactory =
            AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
                PortalUtil.getClassName(classNameIds[0]));

        Tuple classTypeFieldName =
            assetRendererFactory.getClassTypeFieldName(
                classTypeIds[0], _ddmStructureFieldName, themeDisplay.getLocale());

        _ddmStructureFieldLabel = (String) classTypeFieldName.getObject(0);
      }
    }
  }
  public JavadocFormatter(String[] args) throws Exception {
    Map<String, String> arguments = ArgumentsUtil.parseArguments(args);

    String init = arguments.get("javadoc.init");

    if (Validator.isNotNull(init) && !init.startsWith("$")) {
      _initializeMissingJavadocs = GetterUtil.getBoolean(init);
    }

    _inputDir = GetterUtil.getString(arguments.get("javadoc.input.dir"));

    if (_inputDir.startsWith("$")) {
      _inputDir = "./";
    }

    if (!_inputDir.endsWith("/")) {
      _inputDir += "/";
    }

    System.out.println("Input directory is " + _inputDir);

    String limit = arguments.get("javadoc.limit");

    _outputFilePrefix = GetterUtil.getString(arguments.get("javadoc.output.file.prefix"));

    if (_outputFilePrefix.startsWith("$")) {
      _outputFilePrefix = "javadocs";
    }

    String update = arguments.get("javadoc.update");

    if (Validator.isNotNull(update) && !update.startsWith("$")) {
      _updateJavadocs = GetterUtil.getBoolean(update);
    }

    DirectoryScanner directoryScanner = new DirectoryScanner();

    directoryScanner.setBasedir(_inputDir);
    directoryScanner.setExcludes(new String[] {"**\\classes\\**", "**\\portal-client\\**"});

    List<String> includes = new ArrayList<String>();

    if (Validator.isNotNull(limit) && !limit.startsWith("$")) {
      System.out.println("Limit on " + limit);

      String[] limitArray = StringUtil.split(limit, '/');

      for (String curLimit : limitArray) {
        includes.add("**\\" + StringUtil.replace(curLimit, ".", "\\") + "\\**\\*.java");
        includes.add("**\\" + curLimit + ".java");
      }
    } else {
      includes.add("**\\*.java");
    }

    directoryScanner.setIncludes(includes.toArray(new String[includes.size()]));

    directoryScanner.scan();

    String[] fileNames = directoryScanner.getIncludedFiles();

    if ((fileNames.length == 0) && Validator.isNotNull(limit) && !limit.startsWith("$")) {

      StringBundler sb = new StringBundler("Limit file not found: ");

      sb.append(limit);

      if (limit.contains(".")) {
        sb.append(" Specify limit filename without package path or ");
        sb.append("file type suffix.");
      }

      System.out.println(sb.toString());
    }

    _languagePropertiesFile = new File("src/content/Language.properties");

    if (_languagePropertiesFile.exists()) {
      _languageProperties = new Properties();

      _languageProperties.load(new FileInputStream(_languagePropertiesFile.getAbsolutePath()));
    }

    for (String fileName : fileNames) {
      fileName = StringUtil.replace(fileName, "\\", "/");

      _format(fileName);
    }

    for (Map.Entry<String, Tuple> entry : _javadocxXmlTuples.entrySet()) {
      Tuple tuple = entry.getValue();

      File javadocsXmlFile = (File) tuple.getObject(1);
      String oldJavadocsXmlContent = (String) tuple.getObject(2);
      Document javadocsXmlDocument = (Document) tuple.getObject(3);

      Element javadocsXmlRootElement = javadocsXmlDocument.getRootElement();

      javadocsXmlRootElement.sortElementsByChildElement("javadoc", "type");

      String newJavadocsXmlContent = javadocsXmlDocument.formattedString();

      if (!oldJavadocsXmlContent.equals(newJavadocsXmlContent)) {
        _fileUtil.write(javadocsXmlFile, newJavadocsXmlContent);
      }

      _detachUnnecessaryTypes(javadocsXmlRootElement);

      File javadocsRuntimeXmlFile =
          new File(StringUtil.replaceLast(javadocsXmlFile.toString(), "-all.xml", "-rt.xml"));

      String oldJavadocsRuntimeXmlContent = StringPool.BLANK;

      if (javadocsRuntimeXmlFile.exists()) {
        oldJavadocsRuntimeXmlContent = _fileUtil.read(javadocsRuntimeXmlFile);
      }

      String newJavadocsRuntimeXmlContent = javadocsXmlDocument.compactString();

      if (!oldJavadocsRuntimeXmlContent.equals(newJavadocsRuntimeXmlContent)) {

        _fileUtil.write(javadocsRuntimeXmlFile, newJavadocsRuntimeXmlContent);
      }
    }
  }
  private boolean _isOverrideMethod(
      JavaClass javaClass, JavaMethod javaMethod, Collection<Tuple> ancestorJavaClassTuples) {

    if (javaMethod.isConstructor() || javaMethod.isPrivate() || javaMethod.isStatic()) {

      return false;
    }

    String methodName = javaMethod.getName();

    JavaParameter[] javaParameters = javaMethod.getParameters();

    Type[] types = new Type[javaParameters.length];

    for (int i = 0; i < javaParameters.length; i++) {
      types[i] = javaParameters[i].getType();
    }

    // Check for matching method in each ancestor

    for (Tuple ancestorJavaClassTuple : ancestorJavaClassTuples) {
      JavaClass ancestorJavaClass = (JavaClass) ancestorJavaClassTuple.getObject(0);

      JavaMethod ancestorJavaMethod = null;

      if (ancestorJavaClassTuple.getSize() > 1) {

        // LPS-35613

        Type[] ancestorActualTypeArguments = (Type[]) ancestorJavaClassTuple.getObject(1);

        Type[] genericTypes = new Type[types.length];

        for (int i = 0; i < types.length; i++) {
          Type type = types[i];

          String typeValue = type.getValue();

          boolean useGenericType = false;

          for (int j = 0; j < ancestorActualTypeArguments.length; j++) {

            if (typeValue.equals(ancestorActualTypeArguments[j].getValue())) {

              useGenericType = true;

              break;
            }
          }

          if (useGenericType) {
            genericTypes[i] = new Type("java.lang.Object");
          } else {
            genericTypes[i] = type;
          }
        }

        ancestorJavaMethod = ancestorJavaClass.getMethodBySignature(methodName, genericTypes);
      } else {
        ancestorJavaMethod = ancestorJavaClass.getMethodBySignature(methodName, types);
      }

      if (ancestorJavaMethod == null) {
        continue;
      }

      boolean samePackage = false;

      JavaPackage ancestorJavaPackage = ancestorJavaClass.getPackage();

      if (ancestorJavaPackage != null) {
        samePackage = ancestorJavaPackage.equals(javaClass.getPackage());
      }

      // Check if the method is in scope

      if (samePackage) {
        return !ancestorJavaMethod.isPrivate();
      } else {
        if (ancestorJavaMethod.isProtected() || ancestorJavaMethod.isPublic()) {

          return true;
        } else {
          return false;
        }
      }
    }

    return false;
  }
  public AssetEntryQuery getAssetEntryQuery() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    long[] groupIds = getGroupIds();

    if (!ArrayUtil.contains(groupIds, themeDisplay.getScopeGroupId())) {
      groupIds = ArrayUtil.append(groupIds, themeDisplay.getScopeGroupId());
    }

    AssetEntryQuery assetEntryQuery =
        AssetPublisherUtil.getAssetEntryQuery(_portletPreferences, groupIds);

    long[] classNameIds = getClassNameIds();
    long[] classTypeIds = getClassTypeIds();

    if (isSubtypeFieldsFilterEnabled()
        && (classNameIds.length == 1)
        && (classTypeIds.length == 1)
        && Validator.isNotNull(getDDMStructureFieldName())
        && Validator.isNotNull(getDDMStructureFieldValue())) {

      AssetRendererFactory assetRendererFactory =
          AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
              PortalUtil.getClassName(classNameIds[0]));

      Tuple classTypeFieldName =
          assetRendererFactory.getClassTypeFieldName(
              classTypeIds[0], getDDMStructureFieldName(), themeDisplay.getLocale());

      long ddmStructureId = GetterUtil.getLong(classTypeFieldName.getObject(3));

      assetEntryQuery.setAttribute(
          "ddmStructureFieldName",
          DDMIndexerUtil.encodeName(
              ddmStructureId, getDDMStructureFieldName(), themeDisplay.getLocale()));
      assetEntryQuery.setAttribute("ddmStructureFieldValue", getDDMStructureFieldValue());
    }

    AssetPublisherUtil.processAssetEntryQuery(
        themeDisplay.getUser(), _portletPreferences, assetEntryQuery);

    assetEntryQuery.setAllCategoryIds(getAllAssetCategoryIds());

    if (hasLayoutGroup(groupIds)) {
      assetEntryQuery.setAllTagIds(
          AssetTagLocalServiceUtil.getTagIds(groupIds, getAllAssetTagNames()));
    } else {
      assetEntryQuery.setAllTagIds(
          AssetTagLocalServiceUtil.getTagIds(getGroupIds(), getAllAssetTagNames()));
    }

    assetEntryQuery.setClassTypeIds(classTypeIds);
    assetEntryQuery.setEnablePermissions(isEnablePermissions());
    assetEntryQuery.setExcludeZeroViewCount(isExcludeZeroViewCount());

    String portletName = getPortletName();

    if (!portletName.equals(PortletKeys.RELATED_ASSETS)) {
      assetEntryQuery.setGroupIds(getGroupIds());
    }

    if (isShowOnlyLayoutAssets()) {
      assetEntryQuery.setLayout(themeDisplay.getLayout());
    }

    if (portletName.equals(PortletKeys.RELATED_ASSETS)) {
      AssetEntry layoutAssetEntry = (AssetEntry) _request.getAttribute(WebKeys.LAYOUT_ASSET_ENTRY);

      if (layoutAssetEntry != null) {
        assetEntryQuery.setLinkedAssetEntryId(layoutAssetEntry.getEntryId());
      }
    }

    assetEntryQuery.setPaginationType(getPaginationType());
    assetEntryQuery.setOrderByCol1(getOrderByColumn1());
    assetEntryQuery.setOrderByCol2(getOrderByColumn2());
    assetEntryQuery.setOrderByType1(getOrderByType1());
    assetEntryQuery.setOrderByType2(getOrderByType2());

    return assetEntryQuery;
  }
Beispiel #13
0
 protected static byte[] getResponseBody(Tuple tuple) {
   return (byte[]) tuple.getObject(1);
 }
Beispiel #14
0
 protected static Map<String, String> getHeaders(Tuple tuple) {
   return (Map<String, String>) tuple.getObject(2);
 }
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    try {
      ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

      int status = getStatus(renderRequest);

      renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_STATUS, status);

      KBArticle kbArticle = null;

      Tuple resourceTuple = getResourceTuple(renderRequest);

      long resourcePrimKey = (Long) resourceTuple.getObject(1);

      if (resourcePrimKey != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        long resourceClassNameId = (Long) resourceTuple.getObject(0);

        long kbFolderClassNameId = PortalUtil.getClassNameId(KBFolderConstants.getClassName());

        if (resourceClassNameId == kbFolderClassNameId) {
          PortalPreferences portalPreferences =
              PortletPreferencesFactoryUtil.getPortalPreferences(renderRequest);

          String preferredKBFolderURLTitle =
              portalPreferences.getValue(
                  PortletKeys.KNOWLEDGE_BASE_DISPLAY, "preferredKBFolderURLTitle");

          kbArticle =
              getKBFolderKBArticle(
                  themeDisplay.getScopeGroupId(), resourcePrimKey, preferredKBFolderURLTitle);
        } else {
          kbArticle = KBArticleServiceUtil.fetchLatestKBArticle(resourcePrimKey, status);
        }
      } else {
        long parentResourcePrimKey =
            ParamUtil.getLong(
                renderRequest, "parentResourcePrimKey", KBFolderConstants.DEFAULT_PARENT_FOLDER_ID);

        if (parentResourcePrimKey == KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

          List<KBArticle> kbArticles =
              KBArticleLocalServiceUtil.getGroupKBArticles(
                  themeDisplay.getScopeGroupId(),
                  status,
                  0,
                  1,
                  new KBArticlePriorityComparator(true));

          if (!kbArticles.isEmpty()) {
            kbArticle = kbArticles.get(0);
          }
        }
      }

      renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_KB_ARTICLE, kbArticle);
    } catch (Exception e) {
      if (e instanceof NoSuchArticleException || e instanceof PrincipalException) {

        SessionErrors.add(renderRequest, e.getClass());

        SessionMessages.add(
            renderRequest,
            PortalUtil.getPortletId(renderRequest)
                + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
      } else {
        throw new PortletException(e);
      }
    }

    super.render(renderRequest, renderResponse);
  }
Beispiel #16
0
 public static int getStatusCode(Tuple tuple) {
   return (Integer) tuple.getObject(0);
 }
  protected void doConvert() throws Exception {
    DataSource dataSource = getDataSource();

    Dialect dialect = DialectDetector.getDialect(dataSource);

    DB db = DBFactoryUtil.getDB(dialect);

    List<String> modelNames = ModelHintsUtil.getModels();

    List<Tuple> tableDetails = new ArrayList<Tuple>();

    Connection connection = dataSource.getConnection();

    try {
      MaintenanceUtil.appendStatus("Collecting information for database tables to migration");

      for (String modelName : modelNames) {
        if (!modelName.contains(".model.")) {
          continue;
        }

        String implClassName =
            modelName.replaceFirst("(\\.model\\.)(\\p{Upper}.*)", "$1impl.$2Impl");

        if (_log.isDebugEnabled()) {
          _log.debug("Loading class " + implClassName);
        }

        Class<?> implClass = getImplClass(implClassName);

        if (implClass == null) {
          _log.error("Unable to load class " + implClassName);

          continue;
        }

        Field[] fields = implClass.getFields();

        for (Field field : fields) {
          Tuple tuple = null;

          String fieldName = field.getName();

          if (fieldName.equals("TABLE_NAME")) {
            tuple = getTableDetails(implClass, field, fieldName);
          } else if (fieldName.startsWith("MAPPING_TABLE_") && fieldName.endsWith("_NAME")) {

            tuple = getTableDetails(implClass, field, fieldName);
          }

          if (tuple != null) {
            tableDetails.add(tuple);
          }
        }
      }

      for (Tuple tuple : _UNMAPPED_TABLES) {
        tableDetails.add(tuple);
      }

      if (_log.isDebugEnabled()) {
        _log.debug("Migrating database tables");
      }

      for (int i = 0; i < tableDetails.size(); i++) {
        if ((i > 0) && (i % (tableDetails.size() / 4) == 0)) {
          MaintenanceUtil.appendStatus((i * 100 / tableDetails.size()) + "%");
        }

        Tuple tuple = tableDetails.get(i);

        String table = (String) tuple.getObject(0);
        Object[][] columns = (Object[][]) tuple.getObject(1);
        String sqlCreate = (String) tuple.getObject(2);

        migrateTable(db, connection, table, columns, sqlCreate);
      }
    } finally {
      DataAccess.cleanUp(connection);
    }

    MaintenanceUtil.appendStatus("Please change your JDBC settings before restarting server");

    ShutdownUtil.shutdown(0);
  }