set attributes on file

@param file
@throws PageException
514055
private static void setAttributes(Resource file, String attributes) throws PageException {
	if (!SystemUtil.isWindows() || StringUtil.isEmpty(attributes)) return;
	try {
	    ResourceUtil.setAttribute(file, attributes);
	}
	catch (IOException e) {
	    throw new ApplicationException("can't change attributes of file " + file, e.getMessage());
	}
    }
402189
public function addResource(string $file): void
    {
        $contents = file_get_contents($file);
        
        if ($contents === false) {
            throw new \RuntimeException("Error reading file at $file.");
        }
        
        $this->processData(json_decode($contents, true));
    }
181374
private void actionDelete() throws PageException {
	checkFile(pageContext, securityManager, file, serverPassword, false, false, false, false);
	setACL(pageContext, file, acl);
	try {
	    if (!file.delete()) throw new ApplicationException("can't delete file [" + file + "]");
	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	    throw new ApplicationException(t.getMessage());
	}
    }
650320
public static void setAttributeCollection(PageContext pc, Tag tag, MissingAttribute[] missingAttrs, Struct _attrs, int attrType) throws PageException {

	TagLibTag tlt = null;
	Key k;

	if (pc.getConfig() instanceof ConfigWebImpl) {
	    ConfigWebImpl cw = (ConfigWebImpl) pc.getConfig();

	    List<TagLib> allTlds = new ArrayList();
	    // allTlds.addAll(Arrays.asList(cw.getTLDs(CFMLEngine.DIALECT_CFML)));
	    // allTlds.addAll(Arrays.asList(cw.getTLDs(CFMLEngine.DIALECT_LUCEE)));
	    allTlds.addAll(Arrays.asList(cw.getTLDs(CFMLEngine.DIALECT_BOTH)));

	    for (TagLib tld: allTlds) {
		tlt = tld.getTag(tag.getClass());
		if (tlt != null) break;
	    }
	}

	Map<Key, Object> att = new HashMap<Key, Object>();
	{
	    Iterator<Entry<Key, Object>> it = _attrs.entryIterator();
	    Entry<Key, Object> e;
	    TagLibTagAttr alias = null;

	    while (it.hasNext()) {
		e = it.next();
		k = e.getKey();
		if (tlt != null) {
		    alias = tlt.getAttributeByAlias(k.toString());
		    if (alias != null) k = KeyImpl.getInstance(alias.getName()); // translate alias to canonical name
		}
		att.put(k, e.getValue());
	    }
	}

	if (!ArrayUtil.isEmpty(missingAttrs)) {
	    Object value;
	    MissingAttribute miss;
	    for (int i = 0; i < missingAttrs.length; i++) {
		miss = missingAttrs[i];
		value = att.get(miss.getName());
		// check alias; TODO: is this still needed? we now translate aliases above
		if (value == null && !ArrayUtil.isEmpty(miss.getAlias())) {
		    String[] alias = miss.getAlias();
		    for (int y = 0; y < alias.length; y++) {
			value = att.get(k = KeyImpl.init(alias[y]));
			if (value != null) {
			    att.remove(k);
			    break;
			}
		    }
		}

		if (value == null) throw new ApplicationException("attribute " + missingAttrs[i].getName().getString() + " is required but missing");
		// throw new ApplicationException("attribute "+missingAttrs[i].getName().getString()+" is required
		// for tag "+tag.getFullName());
		att.put(missingAttrs[i].getName(), Caster.castTo(pc, missingAttrs[i].getType(), value, false));
	    }
	}

	setAttributes(pc, tag, att, attrType);
    }
479440
public void load(String file) {
		Context context = factory.enterContext();
		
		try {
			URL url = Thread.currentThread().getContextClassLoader().getResource(file);
			
			if (url == null) {
				logger.debug("Configuration [" + file + "] does not exist");
				return;
			}
			
			File f = new File(url.getPath());
			
			if (f.exists()) {
				logger.info("Loading configuration [" + file + "]");
				context.evaluateReader(scope, new FileReader(f), file.substring(file.lastIndexOf("/") + 1), 1, null);
			}
			
		} catch (Exception e) {
			logger.error("Failed to load configuration [" + file + "]", e);
			throw new UncheckedException(e);
		} finally {
			Context.exit();
		}
	}
526523
public void setAttribute(File file, String attribute, Object value, boolean create) {
    String view = getViewName(attribute);
    String attr = getSingleAttribute(attribute);
    setAttributeInternal(file, view, attr, value, create);
  }
340541
@Override
  public void readHeader(RandomAccessFile file) throws IOException {
    file.seek(0);
    if(file.readInt() != FILE_VERSION) {
      throw new RuntimeException("File " + file + " is not a PersistentPageFile or wrong version!");
    }

    this.pageSize = file.readInt();
  }
1012273
public static void setProperty(Object obj, String prop, Object value) throws PageException {
	boolean done = false;
	try {
	    if (setField(obj, prop, value)) done = true;
	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	}
	if (!done) callSetter(obj, prop, value);
    }
1201457
public static void updateMetadata(final File file, final PropertyMap map) throws FrameworkException {
		updateMetadata(file, map, false);
	}
551667
void setInitialAttributes(File file, FileAttribute<?>... attrs) {
    state.checkOpen();
    attributes.setInitialAttributes(file, attrs);
  }
131719
void setAttribute(File file, String attribute, Object value) {
    state.checkOpen();
    // TODO(cgdecker): Change attribute stuff to avoid the sad boolean parameter
    attributes.setAttribute(file, attribute, value, false);
  }
120065
public static void setAttribute(PageContext pageContext, String scope, String name, Object value) throws JspTagException {
		pageContext.setAttribute(name, value, Scope.getScopeId(scope));
	}
659455
public static void updateMetadata(final File file, final PropertyMap map, final boolean calcChecksums) throws FrameworkException {

		final java.io.File fileOnDisk = file.getFileOnDisk(false);

		if (fileOnDisk != null && fileOnDisk.exists()) {

			try {

				final PropertyKey<Long> fileModificationDateKey = StructrApp.key(File.class, "fileModificationDate");
				final PropertyKey<String> contentTypeKey        = StructrApp.key(File.class, "contentType");
				final PropertyKey<Long> sizeKey                 = StructrApp.key(File.class, "size");

				String contentType = file.getContentType();

				// Don't overwrite existing MIME type
				if (StringUtils.isBlank(contentType)) {

					try {

						contentType = getContentMimeType(file);
						map.put(contentTypeKey, contentType);

					} catch (IOException ex) {
						logger.debug("Unable to detect content MIME type", ex);
					}
				}

				map.put(fileModificationDateKey, fileOnDisk.lastModified());

				if (calcChecksums) {
					map.putAll(getChecksums(file, fileOnDisk));
				}

				if (contentType != null) {

					// modify type when image type is detected AND the type is "File"
					if (contentType.startsWith("image/") && Boolean.FALSE.equals(Image.class.isAssignableFrom(file.getClass())) && File.class.getSimpleName().equals(file.getClass().getSimpleName())) {
						map.put(AbstractNode.type, Image.class.getSimpleName());
					}
				}

				long fileSize = FileHelper.getSize(fileOnDisk);
				if (fileSize > 0) {

					map.put(sizeKey, fileSize);
				}

				file.unlockSystemPropertiesOnce();
				file.setProperties(file.getSecurityContext(), map);

			} catch (IOException ioex) {
				logger.warn("Unable to access {} on disk: {}", fileOnDisk, ioex.getMessage());
			}
		}
	}
7073
public void load(File file) {
    try {
      PropertiesConfiguration config = new PropertiesConfiguration();
      // disabled to prevent accumulo classpath value from being shortened
      config.setDelimiterParsingDisabled(true);
      config.load(file);
      ((CompositeConfiguration) internalConfig).addConfiguration(config);
    } catch (ConfigurationException e) {
      throw new IllegalArgumentException(e);
    }
  }
463017
public static void writeTo(Node node, Resource file) throws PageException {
	OutputStream os = null;
	try {
	    os = IOUtil.toBufferedOutputStream(file.getOutputStream());
	    writeTo(node, new StreamResult(os), false, false, null, null, null);
	}
	catch (IOException ioe) {
	    throw Caster.toPageException(ioe);
	}
	finally {
	    IOUtil.closeEL(os);
	}
    }
535354
public void setMailLog(String logFile, String level) throws PageException {
	checkWriteAccess();
	boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_MAIL);

	if (!hasAccess) throw new SecurityException("no access to update mail server settings");
	ConfigWebUtil.getFile(config, config.getRootDirectory(), logFile, FileUtil.TYPE_FILE);

	Element logging = XMLConfigWebFactory.getChildByName(doc.getDocumentElement(), "logging");
	Element[] children = XMLUtil.getChildElementsAsArray(logging);
	Element logger = null;

	for (int i = 0; i < children.length; i++) {
	    if (children[i].getTagName().equals("logger") && "mail".equalsIgnoreCase(children[i].getAttribute("name"))) {
		logger = children[i];
		break;
	    }
	}
	if (logger == null) {
	    logger = doc.createElement("logger");
	    logging.appendChild(logger);
	}
	logger.setAttribute("name", "mail");
	if ("console".equalsIgnoreCase(logFile)) {
	    setClass(logger, null, "appender-", Log4jUtil.appenderClassDefintion("console"));
	    setClass(logger, null, "layout-", Log4jUtil.layoutClassDefintion("pattern"));
	}
	else {
	    setClass(logger, null, "appender-", Log4jUtil.appenderClassDefintion("resource"));
	    setClass(logger, null, "layout-", Log4jUtil.layoutClassDefintion("classic"));
	    logger.setAttribute("appender-arguments", "path:" + logFile);
	}
	logger.setAttribute("log-level", level);
    }
250711
private void doGetDatasourceSetting() throws PageException {
	Struct sct = new StructImpl();
	pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
	sct.set("psq", Caster.toBoolean(config.getPSQL()));
    }