Search in sources :

Example 1 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class Image method touchDestination.

private String touchDestination() throws IOException {
    if (destination == null) {
        String name = CreateUUID.call(pageContext) + "." + format;
        Resource folder = pageContext.getConfig().getTempDirectory().getRealResource("graph");
        if (!folder.exists())
            folder.mkdirs();
        destination = folder.getRealResource(name);
        cleanOld(folder);
        // create path
        String cp = pageContext.getHttpServletRequest().getContextPath();
        if (StringUtil.isEmpty(cp))
            cp = "";
        return cp + "/lucee/graph.cfm?img=" + name + "&type=" + (ListUtil.last(ImageUtil.getMimeTypeFromFormat(format), '/').trim());
    }
    return ContractPath.call(pageContext, destination.getAbsolutePath());
}
Also used : Resource(lucee.commons.io.res.Resource)

Example 2 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class Index method doDelete.

/**
 * delete a collection
 * @throws PageException
 * @throws SearchException
 */
private void doDelete() throws PageException, SearchException {
    required("index", action, "collection", collection);
    if (type != SearchIndex.TYPE_CUSTOM)
        required("index", action, "key", key);
    // no type defined
    if (type == -1) {
        if (query != null) {
            type = SearchIndex.TYPE_CUSTOM;
        } else {
            Resource file = null;
            try {
                file = ResourceUtil.toResourceExisting(pageContext, key);
                pageContext.getConfig().getSecurityManager().checkFileLocation(file);
            } catch (ExpressionException e) {
            }
            if (file != null && file.exists() && file.isFile())
                type = SearchIndex.TYPE_FILE;
            else if (file != null && file.exists() && file.isDirectory())
                type = SearchIndex.TYPE_PATH;
            else {
                try {
                    new URL(key);
                    type = SearchIndex.TYPE_URL;
                } catch (MalformedURLException e) {
                }
            }
        }
    }
    collection.deleteIndex(pageContext, key, type, query);
}
Also used : MalformedURLException(java.net.MalformedURLException) Resource(lucee.commons.io.res.Resource) ExpressionException(lucee.runtime.exp.ExpressionException) URL(java.net.URL)

Example 3 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class MailParam method doStartTag.

@Override
public int doStartTag() throws PageException {
    if (content != null) {
        required("mailparam", "file", file);
        String id = "id-" + CreateUniqueId.invoke();
        String ext = ResourceUtil.getExtension(file, "tmp");
        if (StringUtil.isEmpty(fileName) && !StringUtil.isEmpty(file))
            fileName = ListUtil.last(file, "/\\", true);
        Resource res = SystemUtil.getTempDirectory().getRealResource(id + "." + ext);
        if (res.exists())
            ResourceUtil.removeEL(res, true);
        try {
            IOUtil.write(res, content);
        } catch (IOException e) {
            throw Caster.toPageException(e);
        }
        this.file = ResourceUtil.getCanonicalPathEL(res);
        remove = true;
    } else if (!StringUtil.isEmpty(this.file)) {
        Resource res = ResourceUtil.toResourceNotExisting(pageContext, this.file);
        if (res != null) {
            if (res.exists())
                pageContext.getConfig().getSecurityManager().checkFileLocation(res);
            this.file = ResourceUtil.getCanonicalPathEL(res);
        }
    }
    // check attributes
    boolean hasFile = !StringUtil.isEmpty(file);
    boolean hasName = !StringUtil.isEmpty(name);
    // both attributes
    if (hasName && hasFile) {
        throw new ApplicationException("Wrong Context for tag MailParam, you cannot use attribute file and name together");
    }
    // no attributes
    if (!hasName && !hasFile) {
        throw new ApplicationException("Wrong Context for tag MailParam, you must use attribute file or attribute name for this tag");
    }
    // get Mail Tag
    Tag parent = getParent();
    while (parent != null && !(parent instanceof Mail)) {
        parent = parent.getParent();
    }
    if (parent instanceof Mail) {
        Mail mail = (Mail) parent;
        mail.setParam(type, file, fileName, name, value, disposition, contentID, remove);
    } else {
        throw new ApplicationException("Wrong Context, tag MailParam must be inside a Mail tag");
    }
    return SKIP_BODY;
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException) Tag(javax.servlet.jsp.tagext.Tag)

Example 4 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class Admin method doBuildBundle.

private void doBuildBundle() throws PageException {
    String name = getString("admin", action, "name");
    String symName = getString("symbolicname", null);
    String existingRelation = getString("existingrelation", null);
    // boolean doDyn=StringUtil.isEmpty(existingRelation) || (existingRelation=existingRelation.trim()).equalsIgnoreCase("dynamic");
    // print.e("dynamic:"+existingRelation+"<>"+doDyn);
    boolean ignoreExistingManifest = getBoolV("ignoreExistingManifest", false);
    Resource dest = ResourceUtil.toResourceNotExisting(pageContext, getString("admin", action, "destination"));
    String strJar = getString("admin", action, "jar");
    if (StringUtil.isEmpty(strJar, true))
        throw new ApplicationException("missing valid jar path");
    Resource jar = ResourceUtil.toResourceExisting(pageContext, strJar.trim());
    Set<String> relatedPackages = null;
    try {
        // OSGiUtil.getBootdelegation()
        relatedPackages = JarUtil.getExternalImports(jar, new String[0]);
    } catch (IOException e1) {
        SystemOut.printDate(e1);
    }
    if (relatedPackages == null)
        relatedPackages = new HashSet<String>();
    // org.osgi.framework.bootdelegation
    BundleBuilderFactory factory;
    try {
        symName = StringUtil.isEmpty(symName, true) ? null : symName.trim();
        if (symName == null)
            symName = name;
        factory = new BundleBuilderFactory(jar, symName);
        factory.setName(name);
        factory.setIgnoreExistingManifest(ignoreExistingManifest);
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
    String activator = getString("bundleActivator", null);
    if (activator == null)
        activator = getString("activator", null);
    if (!StringUtil.isEmpty(activator, true))
        factory.setActivator(activator.trim());
    String version = getString("version", null);
    if (!StringUtil.isEmpty(version, true))
        factory.setVersion(OSGiUtil.toVersion(version, null));
    String description = getString("description", null);
    if (!StringUtil.isEmpty(description, true))
        factory.setDescription(description.trim());
    String classPath = getString("classPath", null);
    if (!StringUtil.isEmpty(classPath, true))
        factory.addClassPath(classPath.trim());
    // dynamic import packages
    String dynamicImportPackage = getString("dynamicimportpackage", null);
    if (!StringUtil.isEmpty(dynamicImportPackage, true))
        factory.addDynamicImportPackage(dynamicImportPackage = dynamicImportPackage.trim());
    Set<String> dynamicImportPackageSet = ListUtil.listToSet(dynamicImportPackage, ",", true);
    /*
		 * String dynamicImportPackage=getString("dynamicimportpackage",null); if(doDyn) { if(relatedPackages.size()>0) { // add importPackage to set
		 * if(!StringUtil.isEmpty(dynamicImportPackage)) { String[] arr = ListUtil.trimItems(ListUtil.listToStringArray(dynamicImportPackage, ',')); for(int
		 * i=0;i<arr.length;i++){ relatedPackages.add(arr[i]); } } dynamicImportPackage=ListUtil.toList(relatedPackages, ","); } relatedPackages.clear(); }
		 * if(!StringUtil.isEmpty(dynamicImportPackage,true))factory.addDynamicImportPackage(dynamicImportPackage.trim());
		 */
    // Import Package
    // we remove all imports that are defined as dyn import
    Iterator<String> it = dynamicImportPackageSet.iterator();
    while (it.hasNext()) {
        relatedPackages.remove(it.next());
    }
    String importPackage = getString("importpackage", null);
    // add importPackage to set
    if (!StringUtil.isEmpty(importPackage)) {
        String[] arr = ListUtil.trimItems(ListUtil.listToStringArray(importPackage, ','));
        for (int i = 0; i < arr.length; i++) {
            relatedPackages.add(arr[i]);
        }
    }
    // remove all packages defined in dynamic imports
    if (!StringUtil.isEmpty(dynamicImportPackage)) {
        String[] arr = ListUtil.trimItems(ListUtil.listToStringArray(dynamicImportPackage, ','));
        List<String> newDynImport = new ArrayList<String>();
        for (int i = 0; i < arr.length; i++) {
            if (!relatedPackages.contains(arr[i]))
                newDynImport.add(arr[i]);
        // relatedPackages.remove(arr[i]);
        }
        if (arr.length != newDynImport.size())
            dynamicImportPackage = ListUtil.listToListEL(newDynImport, ",");
    }
    List sortedList = new ArrayList(relatedPackages);
    Collections.sort(sortedList);
    importPackage = ListUtil.toList(sortedList, ",");
    if (!StringUtil.isEmpty(importPackage, true))
        factory.addImportPackage(importPackage.trim());
    String bundleActivationPolicy = getString("bundleActivationPolicy", null);
    if (!StringUtil.isEmpty(bundleActivationPolicy, true))
        factory.setBundleActivationPolicy(bundleActivationPolicy.trim());
    String exportPackage = getString("exportpackage", null);
    if (!StringUtil.isEmpty(exportPackage, true)) {
        exportPackage = ListUtil.sort(exportPackage.trim(), "text", "asc", ",");
        factory.addExportPackage(exportPackage);
    }
    String requireBundle = getString("requireBundle", null);
    if (!StringUtil.isEmpty(requireBundle, true)) {
        requireBundle = ListUtil.sort(requireBundle.trim(), "text", "asc", ",");
        factory.addRequireBundle(requireBundle);
    }
    String requireBundleFragment = getString("requireBundleFragment", null);
    if (!StringUtil.isEmpty(requireBundleFragment, true)) {
        requireBundleFragment = ListUtil.sort(requireBundleFragment.trim(), "text", "asc", ",");
        factory.addRequireBundleFragment(requireBundleFragment);
    }
    String fragmentHost = getString("fragmentHost", null);
    if (!StringUtil.isEmpty(fragmentHost, true))
        factory.addFragmentHost(fragmentHost.trim());
    try {
        factory.build(dest);
    } catch (IOException e) {
        throw Caster.toPageException(e);
    }
}
Also used : Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PageException(lucee.runtime.exp.PageException) SecurityException(lucee.runtime.exp.SecurityException) IOException(java.io.IOException) DeprecatedException(lucee.runtime.exp.DeprecatedException) BundleException(org.osgi.framework.BundleException) MalformedURLException(java.net.MalformedURLException) SMTPException(lucee.runtime.net.mail.SMTPException) ApplicationException(lucee.runtime.exp.ApplicationException) BundleBuilderFactory(lucee.runtime.osgi.BundleBuilderFactory) ApplicationException(lucee.runtime.exp.ApplicationException) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 5 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class Admin method doCompileFile.

private void doCompileFile(Mapping mapping, Resource file, String path, Map<String, String> errors, Boolean explicitIgnoreScope) throws PageException {
    if (ResourceUtil.exists(file)) {
        if (file.isDirectory()) {
            Resource[] files = file.listResources(FILTER_CFML_TEMPLATES);
            if (files != null)
                for (int i = 0; i < files.length; i++) {
                    String p = path + '/' + files[i].getName();
                    // print.ln(files[i]+" - "+p);
                    doCompileFile(mapping, files[i], p, errors, explicitIgnoreScope);
                }
        } else if (file.isFile()) {
            PageSource ps = mapping.getPageSource(path);
            PageContextImpl pci = (PageContextImpl) pageContext;
            boolean envIgnoreScopes = pci.ignoreScopes();
            try {
                if (explicitIgnoreScope != null)
                    pci.setIgnoreScopes(explicitIgnoreScope);
                ((PageSourceImpl) ps).clear();
                ((PageSourceImpl) ps).loadPage(pageContext, explicitIgnoreScope != null);
            // pageContext.compile(ps);
            } catch (PageException pe) {
                SystemOut.printDate(pe);
                String template = ps.getDisplayPath();
                StringBuilder msg = new StringBuilder(pe.getMessage());
                msg.append(", Error Occurred in File [");
                msg.append(template);
                if (pe instanceof PageExceptionImpl) {
                    try {
                        PageExceptionImpl pei = (PageExceptionImpl) pe;
                        Array context = pei.getTagContext(config);
                        if (context.size() > 0) {
                            msg.append(":");
                            msg.append(Caster.toString(((Struct) context.getE(1)).get("line")));
                        }
                    } catch (Throwable t) {
                        ExceptionUtil.rethrowIfNecessary(t);
                    }
                }
                msg.append("]");
                if (errors != null)
                    errors.put(template, msg.toString());
                else
                    throw new ApplicationException(msg.toString());
            } finally {
                pci.setIgnoreScopes(envIgnoreScopes);
            }
        }
    }
}
Also used : Array(lucee.runtime.type.Array) PageException(lucee.runtime.exp.PageException) ApplicationException(lucee.runtime.exp.ApplicationException) PageExceptionImpl(lucee.runtime.exp.PageExceptionImpl) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) PageSource(lucee.runtime.PageSource) Struct(lucee.runtime.type.Struct)

Aggregations

Resource (lucee.commons.io.res.Resource)309 IOException (java.io.IOException)100 ApplicationException (lucee.runtime.exp.ApplicationException)54 PageException (lucee.runtime.exp.PageException)40 ArrayList (java.util.ArrayList)31 Struct (lucee.runtime.type.Struct)28 ByteArrayInputStream (java.io.ByteArrayInputStream)21 InputStream (java.io.InputStream)21 ExpressionException (lucee.runtime.exp.ExpressionException)19 StructImpl (lucee.runtime.type.StructImpl)18 MalformedURLException (java.net.MalformedURLException)17 PageContextImpl (lucee.runtime.PageContextImpl)17 PageSource (lucee.runtime.PageSource)16 FileResource (lucee.commons.io.res.type.file.FileResource)15 SecurityException (lucee.runtime.exp.SecurityException)15 BundleException (org.osgi.framework.BundleException)15 ZipEntry (java.util.zip.ZipEntry)13 ExtensionResourceFilter (lucee.commons.io.res.filter.ExtensionResourceFilter)13 Array (lucee.runtime.type.Array)13 File (java.io.File)12