コード例 #1
0
  public int doEndTag() throws JspException {
    try {
      if (digitalAssetId != null) {
        produceResult(getController().getAssetUrlForAssetWithId(digitalAssetId));
      } else {
        if (languageId == null) languageId = getController().getLanguageId();

        DigitalAssetVO assetVO = null;
        if (principal != null) {
          assetVO = getController().getPrincipalAsset(principal, assetKey, languageId);
        } else if (userName != null) {
          assetVO =
              getController()
                  .getPrincipalAsset(getController().getPrincipal(userName), assetKey, languageId);
        } else {
          assetVO =
              getController()
                  .getPrincipalAsset(getController().getPrincipal(), assetKey, languageId);
        }

        if (assetVO != null)
          produceResult(getController().getAssetUrlForAssetWithId(assetVO.getId()));
      }
    } catch (Exception e) {
      throw new JspTagException("ComponentLogic.getAssetUrl Error: " + e.getMessage());
    }

    languageId = null;
    userName = null;
    principal = null;

    return EVAL_PAGE;
  }
コード例 #2
0
  public String doExecute() // throws Exception
      {
    try {
      MultiPartRequestWrapper mpr = ActionContext.getMultiPartRequest();
      if (mpr == null) {
        return "input";
      }

      log.debug("Handling upload...");
      Enumeration names = mpr.getFileNames();
      if (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        log.debug("name:" + name);
        File uploadedFile = mpr.getFile(name);
        if (uploadedFile == null || uploadedFile.length() == 0) {
          log.error("No file found in multipart request");
          return "input";
        }

        String contentType = mpr.getContentType(name);
        String fileName = mpr.getFilesystemName(name);
        String filePath = CmsPropertyHandler.getDigitalAssetPath();
        log.debug("fileName:" + fileName);

        // Pluto prepare portlet-war
        String appName = fileName;
        int dot = appName.lastIndexOf(".");
        if (dot > 0) {
          appName = appName.substring(0, dot);
        }

        log.info("appName:" + appName);

        // Create file where Deployer will write updated
        // (pluto-prepared) .war
        File file = new File(uploadedFile.getParentFile(), "tmp" + System.currentTimeMillis());
        log.info("file:" + file.getAbsolutePath());
        PortletApplicationDefinition pad = Deploy.prepareArchive(uploadedFile, file, appName);

        // Extract portlet application information to be added to
        // portlet entity registry
        log.info("Adding portlet application to registry: " + appName);
        PortletApplicationEntityImpl pae = new PortletApplicationEntityImpl();
        pae.setId(appName);

        PortletDefinitionList pdl = pad.getPortletDefinitionList();
        for (Iterator it = pdl.iterator(); it.hasNext(); ) {
          PortletDefinition pd = (PortletDefinition) it.next();
          log.debug("Adding portlet: " + pd.getName());
          PortletEntityImpl pe = new PortletEntityImpl();
          pe.setId(pd.getName());

          // Copy preferences
          ArrayList destPrefs = new ArrayList();
          PreferenceSet prefSet = pd.getPreferenceSet();
          for (Iterator prefs = prefSet.iterator(); prefs.hasNext(); ) {
            Preference src = (Preference) prefs.next();
            ArrayList destValues = new ArrayList();
            for (Iterator values = src.getValues(); values.hasNext(); ) {
              destValues.add(values.next());
            }
            destPrefs.add(new PreferenceImpl(src.getName(), destValues));
          }
          pe.setPreferenceSet(new PreferenceSetImpl(destPrefs));
          pae.addPortletEntity(pe);
        }

        // Create Digital Asset
        log.debug("Creating Digital Asset...");
        DigitalAssetVO newAsset = new DigitalAssetVO();
        newAsset.setAssetContentType(contentType);
        newAsset.setAssetKey(fileName);
        newAsset.setAssetFileName(fileName);
        newAsset.setAssetFilePath(filePath);
        newAsset.setAssetFileSize(new Integer(new Long(file.length()).intValue()));

        // Check existance of portlet and remove old ones
        List assets = PortletAssetController.getDigitalAssetByName(fileName);
        if (assets != null && assets.size() > 0) {
          log.info("Removing old instance of " + fileName);
          for (Iterator it = assets.iterator(); it.hasNext(); ) {
            DigitalAsset oldAsset = (DigitalAsset) it.next();
            PortletAssetController.delete(oldAsset.getId());
          }
        }

        log.info("Storing Digital Asset (portlet) " + fileName);
        InputStream is = new FileInputStream(file);
        digitalAsset = PortletAssetController.create(newAsset, is);
        is.close();
        log.debug("Digital Asset stored as id=" + digitalAsset.getId());

        // Cleanup
        uploadedFile.delete();
        file.delete();

        // Add the new application to portlet registry
        // Update persisted portlet registry
        // TODO check existance first?
        PortletApplicationEntityList pael = PortletEntityRegistry.getPortletApplicationEntityList();
        if (pael instanceof PortletApplicationEntityListImpl) {
          ((PortletApplicationEntityListImpl) pael).add(pae);
          log.debug("Portlet application successfully added to registry");
        } else {
          log.error(
              "Unknown implementation of PortletApplicationEntityList, "
                  + "cannot add portlet application!");
          return "error";
        }
        PortletEntityRegistry.store();

        // Refresh deliver-engines
        updateDeliverEngines(digitalAsset.getId());
      } else {
        throw new SystemException("No file was uploaded...");
      }
    } catch (Throwable e) {
      log.error("ERROR", e);
      return "error";
    }

    return "success";
  }