Package dk.valtech.octools.collectors

Source Code of dk.valtech.octools.collectors.SingleNumberedFileCollector

/*

  This library is part of octools
  Copyright (c) 2000-2007 Valtech A/S (http://www.valtech.dk)

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.

 
  Alkacon OpenCms and the OpenCms logo are registered trademarks of
  Alkacon Software GmbH in Germany, the USA and other countries
 
  For further information about Alkacon Software GmbH, please see the
  company website: http://www.alkacon.com

  For further information about OpenCms, please see the
  project website: http://www.opencms.org
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/
package dk.valtech.octools.collectors;

import java.util.ArrayList;
import java.util.List;

import org.opencms.file.CmsDataAccessException;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.file.collectors.A_CmsResourceCollector;
import org.opencms.file.collectors.CmsDefaultResourceCollector;
import org.opencms.file.collectors.I_CmsResourceCollector;
import org.opencms.file.types.I_CmsResourceType;
import org.opencms.main.CmsException;
import org.opencms.main.OpenCms;

/**
* A collector for a single file, but with the ability to return a {@link #getCreateLink(CmsObject, String, String))}
* @author Stefan Uldum Grinsted (stefan.grinsted@valtech.dk)
*
*/
public class SingleNumberedFileCollector extends A_CmsResourceCollector implements I_CmsResourceCollector {

  private String createParam;
 
  public List<String> getCollectorNames() {
    ArrayList<String> names = new ArrayList<String>();
    names.add("singleNumberedFile");
    return names;
  }

  public String getCreateLink(CmsObject cms, String collectorName, String param) throws CmsException, CmsDataAccessException {
    String filename = null;
    if (param.indexOf("${number}") < 0) {
          int pos1 = param.indexOf('|');
          if (pos1 < 0) {
            pos1 = param.length();
          }
          String path = param.substring(0, pos1);
      filename = CmsResource.getName(path);
      String foldername = CmsResource.getFolderPath(path);
      CmsResource res = cms.readResource(path);
      I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(res.getTypeId());
     
     
      createParam = foldername.concat(filename.replaceFirst("[0-9]{4}", "\\${number}")).concat("|").concat(type.getTypeName());
    } else {
      createParam = param;
    }
    filename = getCreateInFolder(cms, createParam);
    return filename;
  }

  public String getCreateParam(CmsObject cms, String collectorName, String param) throws CmsDataAccessException {
    try {
      getCreateLink(cms, collectorName, param);
    } catch (CmsException e) {
    }
    return createParam;
  }

  @SuppressWarnings("unchecked")
  public List<CmsResource> getResults(CmsObject cms, String collectorName, String param) throws CmsDataAccessException, CmsException {
    CmsDefaultResourceCollector rc = new CmsDefaultResourceCollector();
    return rc.getResults(cms, "singleFile", param);
  }
 
 
}
TOP

Related Classes of dk.valtech.octools.collectors.SingleNumberedFileCollector

TOP
Copyright © 2018 www.massapi.com. 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.