Content of file ResourceFileNetBeansPlatform.java.html
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../../jacoco-resources/report.gif" type="image/gif"/><title>ResourceFileNetBeansPlatform.java</title><link rel="stylesheet" href="../../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../../index.html" class="el_report">NorthernWind :: Filesystems :: SCM</a> > <a href="../index.html" class="el_bundle">it-tidalwave-northernwind-core-filesystem-basic</a> > <a href="index.source.html" class="el_package">it.tidalwave.northernwind.frontend.filesystem.impl</a> > <span class="el_source">ResourceFileNetBeansPlatform.java</span></div><h1>ResourceFileNetBeansPlatform.java</h1><pre class="source lang-java linenums">/*
* #%L
* *********************************************************************************************************************
*
* NorthernWind - lightweight CMS
* http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
* %%
* Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
* %%
* *********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* *********************************************************************************************************************
*
*
* *********************************************************************************************************************
* #L%
*/
package it.tidalwave.northernwind.frontend.filesystem.impl;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Provider;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.io.File;
import java.io.IOException;
import org.springframework.beans.factory.annotation.Configurable;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import it.tidalwave.util.As;
import it.tidalwave.northernwind.core.model.MimeTypeResolver;
import it.tidalwave.northernwind.core.model.ResourceFile;
import it.tidalwave.northernwind.core.model.ResourceFileSystem;
import it.tidalwave.northernwind.core.model.ResourcePath;
import it.tidalwave.northernwind.core.model.spi.ResourceFileFinderSupport;
import lombok.Getter;
import lombok.ToString;
import lombok.experimental.Delegate;
import lombok.extern.slf4j.Slf4j;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
*
**********************************************************************************************************************/
<span class="fc" id="L61">@Configurable @Slf4j @ToString(of = "delegate")</span>
public class ResourceFileNetBeansPlatform implements ResourceFile
{
interface Exclusions
{
public String getName();
public ResourcePath getPath();
public ResourceFile getParent();
public ResourceFile getFileObject (String fileName);
public Collection<ResourceFile> getChildren();
public Collection<ResourceFile> getChildren (boolean b);
public String getMIMEType();
public File toFile();
public ResourceFile createFolder (String name);
public void copyTo (ResourceFile targetFolder);
public ResourceFileSystem getFileSystem();
public Date lastModified();
}
@Inject
private Provider<MimeTypeResolver> mimeTypeResolver;
<span class="nc" id="L83"> @Getter @Nonnull</span>
private final ResourceFileSystemNetBeansPlatform fileSystem;
<span class="pc" id="L86"> @Getter @Delegate(excludes = Exclusions.class) @Nonnull</span>
private final FileObject delegate;
<span class="pc" id="L89"> @Delegate</span>
<span class="fc" id="L90"> private final As asSupport = As.forObject(this);</span>
public ResourceFileNetBeansPlatform (@Nonnull final ResourceFileSystemNetBeansPlatform fileSystem,
@Nonnull final FileObject delegate)
<span class="pc bpc" id="L94" title="9 of 18 branches missed."> {</span>
<span class="fc" id="L95"> this.fileSystem = fileSystem;</span>
<span class="fc" id="L96"> this.delegate = delegate;</span>
<span class="pc bpc" id="L97" title="2 of 4 branches missed."> }</span>
@Override @Nonnull
public ResourcePath getPath()
{
<span class="fc" id="L102"> return ResourcePath.of(delegate.getPath());</span>
}
@Override @Nonnull
public String getName()
{
<span class="fc" id="L108"> return delegate.getNameExt();</span>
}
@Override
public ResourceFile getParent()
{
<span class="nc" id="L114"> return fileSystem.createResourceFile(delegate.getParent());</span>
}
@Override @Nonnull
public ResourceFile createFolder (@Nonnull final String name)
throws IOException
{
<span class="nc" id="L121"> return fileSystem.createResourceFile(delegate.createFolder(name));</span>
}
@Override @Nonnull
public Finder findChildren()
{
<span class="fc" id="L127"> return ResourceFileFinderSupport.withComputeResults(getClass().getSimpleName(), f -></span>
{
<span class="fc" id="L129"> final var name = f.getName();</span>
<span class="fc" id="L130"> final var recursive = f.isRecursive();</span>
<span class="fc" id="L132"> final List<ResourceFile> result = new ArrayList<>();</span>
<span class="pc bpc" id="L134" title="1 of 2 branches missed."> if (name != null)</span>
{
<span class="nc" id="L136"> final var child = delegate.getFileObject(name);</span>
<span class="nc bnc" id="L138" title="All 2 branches missed."> if (child != null)</span>
{
<span class="nc" id="L140"> result.add(fileSystem.createResourceFile(child));</span>
}
<span class="nc" id="L142"> }</span>
else
{
<span class="fc bfc" id="L145" title="All 2 branches covered."> for (final FileObject child : Collections.list(delegate.getChildren(recursive)))</span>
{
<span class="fc" id="L147"> result.add(fileSystem.createResourceFile(child));</span>
<span class="fc" id="L148"> }</span>
}
<span class="fc" id="L151"> return result;</span>
});
}
@Override @Nonnull
public String getMimeType()
{
<span class="nc" id="L158"> return mimeTypeResolver.get().getMimeType(delegate.getNameExt());</span>
}
@Override @Nonnull
public ZonedDateTime getLatestModificationTime()
{
// See NW-154
<span class="nc" id="L165"> final var file = toFile();</span>
<span class="nc bnc" id="L167" title="All 2 branches missed."> final var millis = (file != null) ? file.lastModified() : delegate.lastModified().getTime();</span>
<span class="nc" id="L168"> return Instant.ofEpochMilli(millis).atZone(ZoneId.of("GMT"));</span>
}
@Nonnull
@Override
public File toFile()
{
<span class="nc" id="L175"> return FileUtil.toFile(delegate);</span>
}
@Override
public void copyTo (@Nonnull final ResourceFile targetFolder)
throws IOException
{
<span class="nc" id="L182"> FileUtil.copyFile(delegate, ((ResourceFileNetBeansPlatform)targetFolder).delegate, delegate.getName());</span>
<span class="nc" id="L183"> }</span>
// TODO: equals and hashcode
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.9.202303310957</span></div></body></html>