Builds the JSON code to create items for the folder.<p>

@param resourceitems the file resource to build the displayed items
@param parentFolder the parent folder of the collected files (for a gallery)
422942
protected void buildJsonResourceItems(List<CmsResource> resourceitems, String parentFolder) {

        if (resourceitems == null) {
            resourceitems = new ArrayList<CmsResource>();
        }

        boolean isPublishEnabled = false;
        boolean hasDirectPublish = false;
        boolean hasWritePermission = false;
        if (CmsStringUtil.isNotEmpty(parentFolder)) {
            // check if there are changes in the currently selected gallery and the user has direct edit permissions
            try {
                if ((OpenCms.getPublishManager().getPublishList(
                    getCms(),
                    getCms().readResource(parentFolder),
                    false).size() > 0)) {
                    isPublishEnabled = true;
                }
            } catch (CmsException e) {
                // ignore, gallery can not be published
            }
            // check if the user has direst publish permissions,
            // used to enable the gallerypublish button, if user has enough permissions
            try {
                if (getCms().hasPermissions(
                    getCms().readResource(parentFolder),
                    CmsPermissionSet.ACCESS_DIRECT_PUBLISH,
                    false,
                    CmsResourceFilter.ALL)) {
                    hasDirectPublish = true;
                }
            } catch (CmsException e) {
                // ignore, no publish permissions for gallery
            }
            try {
                // check if the user has write permissions,
                // used to display the upload buttons
                if (getCms().hasPermissions(
                    getCms().readResource(parentFolder),
                    CmsPermissionSet.ACCESS_WRITE,
                    false,
                    CmsResourceFilter.ALL)) {
                    hasWritePermission = true;
                }
            } catch (CmsException e) {
                // ignore, no write permissions for gallery
            }
        }
        JSONObject publishInfo = new JSONObject();
        try {
            publishInfo.put("publishable", isPublishEnabled);
            publishInfo.put("directpublish", hasDirectPublish);
            publishInfo.put("writepermission", hasWritePermission);
        } catch (JSONException e) {
            // ignore
        }
        JSONArray items = new JSONArray();
        items.put(publishInfo);
        Iterator<CmsResource> i = resourceitems.iterator();
        while (i.hasNext()) {
            CmsResource res = i.next();
            // build a JSON object from the item and add it to the list
            items.put(buildJsonItemObject(res));
        }
        JspWriter out = getJsp().getJspContext().getOut();
        try {
            // print the JSON array
            out.print(items.toString());
        } catch (IOException e) {
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
    }
1246984
public static com.simiacryptus.util.io.HtmlNotebookOutput create(final File parentDirectory) throws FileNotFoundException {
    @javax.annotation.Nonnull final FileOutputStream out = new FileOutputStream(new File(parentDirectory, "index.html"));
    return new com.simiacryptus.util.io.HtmlNotebookOutput(parentDirectory, out) {
      @Override
      public void close() throws IOException {
        out.close();
      }
    };
  }
418703
private void setFolder(final StructrShellCommand parent, final Folder currentFolder, final String targetFolderName) throws IOException, FrameworkException {

		final App app = StructrApp.getInstance();
		String target = targetFolderName;

		// remove trailing slash
		if (target.endsWith("/")) {
			target = target.substring(0, target.length() - 1);
		}

		if (target.startsWith("/")) {

			final Folder folder = app.nodeQuery(Folder.class).and(StructrApp.key(Folder.class, "path"), target).sort(AbstractNode.name).getFirst();
			if (folder != null) {

				if (parent.isAllowed(folder, Permission.read, true)) {

					parent.setCurrentFolder(folder);

				} else {

				term.println("Permission denied");
				}

			} else {

				term.println("Folder " + target + " does not exist");
			}

		} else {

			final Folder newFolder = parent.findRelativeFolder(currentFolder, target);
			if (newFolder == null) {

				term.println("Folder " + target + " does not exist");

			} else {

				if (parent.isAllowed(newFolder, Permission.read, true)) {

					parent.setCurrentFolder(newFolder);

				} else {

					term.println("Permission denied");
				}
			}
		}
	}
1117023
public void buildCategoryTree(List<CmsCategoryTreeEntry> treeEntries, Collection<String> selectedCategories) {

        m_valuesSet = 0;
        m_allSidePath.clear();
        m_categories.removeFromParent();
        m_categories.clear();

        if ((treeEntries != null) && !treeEntries.isEmpty()) {
            // add the first level and children
            for (CmsCategoryTreeEntry category : treeEntries) {
                // set the category tree item and add to list
                CmsTreeItem treeItem;
                boolean hasSelectedChildren = hasSelectedChildren(category.getChildren(), selectedCategories);
                if (!category.getPath().isEmpty() || hasSelectedChildren) {
                    if (m_selectParent || !hasSelectedChildren) {
                        treeItem = buildTreeItem(category, selectedCategories, false);
                        if (treeItem.isOpen()) {
                            m_allSidePath.add(category.getSitePath());
                        }
                    } else {
                        treeItem = buildTreeItem(category, selectedCategories, true);
                    }
                    if (treeItem.isOpen()) {
                        m_singleSidePath = category.getSitePath();

                        m_valuesSet++;
                        addChildren(treeItem, category.getChildren(), selectedCategories);
                    }
                }
            }
        }
        m_scrollPanel.add(m_categories);
        m_scrollPanel.onResizeDescendant();

    }
1176730
private void addSources( final Collection<File> items, final Collection<String> sourceRoots )
    {
        for ( String path : sourceRoots )
        {
            items.add( new File( path ) );
        }
    }
1184672
private void setParentFolder(final AbstractFile file) throws FrameworkException {

		final Path parentPath = getParent();
		if (parentPath != null && parentPath instanceof StructrFilePath) {

			final StructrFilePath parentFilePath = (StructrFilePath)parentPath;
			final Folder parentFolder = (Folder)parentFilePath.getActualFile();
			if (parentFolder != null) {

				file.setParent(parentFolder);
			}
		}
	}
648220
public static void fillItemDefault(Item resourceItem, CmsObject cms, CmsResource resource, Locale locale) {

        if (resource == null) {
            LOG.error("Error rendering item for 'null' resource");
            return;
        }

        if (resourceItem == null) {
            LOG.error("Error rendering 'null' item for resource " + resource.getRootPath());
            return;
        }
        if (cms == null) {
            cms = A_CmsUI.getCmsObject();
            LOG.warn("CmsObject was 'null', using thread local CmsObject");
        }
        CmsResourceUtil resUtil = new CmsResourceUtil(cms, resource);
        Map<String, CmsProperty> resourceProps = null;
        try {
            List<CmsProperty> props = cms.readPropertyObjects(resource, false);
            resourceProps = new HashMap<String, CmsProperty>();
            for (CmsProperty prop : props) {
                resourceProps.put(prop.getName(), prop);
            }
        } catch (CmsException e1) {
            LOG.debug("Unable to read properties for resource '" + resource.getRootPath() + "'.", e1);
        }
        I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(resource);
        if (resourceItem.getItemProperty(PROPERTY_TYPE_ICON) != null) {
            resourceItem.getItemProperty(PROPERTY_TYPE_ICON).setValue(
                new CmsResourceIcon(resUtil, resource.getState(), true));
        }

        if (resourceItem.getItemProperty(PROPERTY_PROJECT) != null) {
            Label projectFlag = null;
            switch (resUtil.getProjectState().getMode()) {
                case 1:
                    projectFlag = new Label(
                        new CmsCssIcon(OpenCmsTheme.ICON_PROJECT_CURRENT).getHtml(resUtil.getLockedInProjectName()),
                        ContentMode.HTML);
                    break;
                case 2:
                    projectFlag = new Label(
                        new CmsCssIcon(OpenCmsTheme.ICON_PROJECT_OTHER).getHtml(resUtil.getLockedInProjectName()),
                        ContentMode.HTML);
                    break;
                case 5:
                    projectFlag = new Label(
                        new CmsCssIcon(OpenCmsTheme.ICON_PUBLISH).getHtml(resUtil.getLockedInProjectName()),
                        ContentMode.HTML);
                    break;
                default:
            }
            resourceItem.getItemProperty(PROPERTY_PROJECT).setValue(projectFlag);
        }

        if (resourceItem.getItemProperty(PROPERTY_INSIDE_PROJECT) != null) {
            resourceItem.getItemProperty(PROPERTY_INSIDE_PROJECT).setValue(Boolean.valueOf(resUtil.isInsideProject()));
        }

        if (resourceItem.getItemProperty(PROPERTY_RELEASED_NOT_EXPIRED) != null) {
            resourceItem.getItemProperty(PROPERTY_RELEASED_NOT_EXPIRED).setValue(
                Boolean.valueOf(resUtil.isReleasedAndNotExpired()));
        }

        if (resourceItem.getItemProperty(PROPERTY_RESOURCE_NAME) != null) {
            resourceItem.getItemProperty(PROPERTY_RESOURCE_NAME).setValue(resource.getName());
        }

        if (resourceItem.getItemProperty(PROPERTY_SITE_PATH) != null) {
            resourceItem.getItemProperty(PROPERTY_SITE_PATH).setValue(cms.getSitePath(resource));
        }

        if ((resourceItem.getItemProperty(PROPERTY_TITLE) != null) && (resourceProps != null)) {
            resourceItem.getItemProperty(PROPERTY_TITLE).setValue(
                resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_TITLE)
                ? resourceProps.get(CmsPropertyDefinition.PROPERTY_TITLE).getValue()
                : "");
        }
        boolean inNavigation = false;
        if ((resourceItem.getItemProperty(PROPERTY_NAVIGATION_TEXT) != null) && (resourceProps != null)) {
            resourceItem.getItemProperty(PROPERTY_NAVIGATION_TEXT).setValue(
                resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_NAVTEXT)
                ? resourceProps.get(CmsPropertyDefinition.PROPERTY_NAVTEXT).getValue()
                : "");
            inNavigation = resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_NAVTEXT);
        }

        if ((resourceItem.getItemProperty(PROPERTY_NAVIGATION_POSITION) != null) && (resourceProps != null)) {
            try {
                Float navPos = resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_NAVPOS)
                ? Float.valueOf(resourceProps.get(CmsPropertyDefinition.PROPERTY_NAVPOS).getValue())
                : (inNavigation ? Float.valueOf(Float.MAX_VALUE) : null);
                resourceItem.getItemProperty(PROPERTY_NAVIGATION_POSITION).setValue(navPos);
                inNavigation = navPos != null;
            } catch (Exception e) {
                LOG.debug("Error evaluating navPos property", e);
            }
        }

        if (resourceItem.getItemProperty(PROPERTY_IN_NAVIGATION) != null) {
            if (inNavigation
                && (resourceProps != null)
                && resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_NAVINFO)
                && CmsClientSitemapEntry.HIDDEN_NAVIGATION_ENTRY.equals(
                    resourceProps.get(CmsPropertyDefinition.PROPERTY_NAVINFO).getValue())) {
                inNavigation = false;
            }
            resourceItem.getItemProperty(PROPERTY_IN_NAVIGATION).setValue(Boolean.valueOf(inNavigation));
        }

        if ((resourceItem.getItemProperty(PROPERTY_COPYRIGHT) != null) && (resourceProps != null)) {
            resourceItem.getItemProperty(PROPERTY_COPYRIGHT).setValue(
                resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_COPYRIGHT)
                ? resourceProps.get(CmsPropertyDefinition.PROPERTY_COPYRIGHT).getValue()
                : "");
        }

        if ((resourceItem.getItemProperty(PROPERTY_CACHE) != null) && (resourceProps != null)) {
            resourceItem.getItemProperty(PROPERTY_CACHE).setValue(
                resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_CACHE)
                ? resourceProps.get(CmsPropertyDefinition.PROPERTY_CACHE).getValue()
                : "");
        }

        if (resourceItem.getItemProperty(PROPERTY_RESOURCE_TYPE) != null) {
            resourceItem.getItemProperty(PROPERTY_RESOURCE_TYPE).setValue(
                CmsWorkplaceMessages.getResourceTypeName(locale, type.getTypeName()));
        }

        if (resourceItem.getItemProperty(PROPERTY_IS_FOLDER) != null) {
            resourceItem.getItemProperty(PROPERTY_IS_FOLDER).setValue(Boolean.valueOf(resource.isFolder()));
        }

        if (resourceItem.getItemProperty(PROPERTY_SIZE) != null) {
            if (resource.isFile()) {
                resourceItem.getItemProperty(PROPERTY_SIZE).setValue(Integer.valueOf(resource.getLength()));
            }
        }

        if (resourceItem.getItemProperty(PROPERTY_PERMISSIONS) != null) {
            resourceItem.getItemProperty(PROPERTY_PERMISSIONS).setValue(resUtil.getPermissionString());
        }

        if (resourceItem.getItemProperty(PROPERTY_DATE_MODIFIED) != null) {
            resourceItem.getItemProperty(PROPERTY_DATE_MODIFIED).setValue(Long.valueOf(resource.getDateLastModified()));
        }

        if (resourceItem.getItemProperty(PROPERTY_USER_MODIFIED) != null) {
            resourceItem.getItemProperty(PROPERTY_USER_MODIFIED).setValue(resUtil.getUserLastModified());
        }

        if (resourceItem.getItemProperty(PROPERTY_DATE_CREATED) != null) {
            resourceItem.getItemProperty(PROPERTY_DATE_CREATED).setValue(Long.valueOf(resource.getDateCreated()));
        }

        if (resourceItem.getItemProperty(PROPERTY_USER_CREATED) != null) {
            resourceItem.getItemProperty(PROPERTY_USER_CREATED).setValue(resUtil.getUserCreated());
        }

        if (resourceItem.getItemProperty(PROPERTY_DATE_RELEASED) != null) {
            long release = resource.getDateReleased();
            if (release != CmsResource.DATE_RELEASED_DEFAULT) {
                resourceItem.getItemProperty(PROPERTY_DATE_RELEASED).setValue(Long.valueOf(release));
            } else {
                resourceItem.getItemProperty(PROPERTY_DATE_RELEASED).setValue(null);
            }
        }

        if (resourceItem.getItemProperty(PROPERTY_DATE_EXPIRED) != null) {
            long expire = resource.getDateExpired();
            if (expire != CmsResource.DATE_EXPIRED_DEFAULT) {
                resourceItem.getItemProperty(PROPERTY_DATE_EXPIRED).setValue(Long.valueOf(expire));
            } else {
                resourceItem.getItemProperty(PROPERTY_DATE_EXPIRED).setValue(null);
            }
        }

        if (resourceItem.getItemProperty(PROPERTY_STATE_NAME) != null) {
            resourceItem.getItemProperty(PROPERTY_STATE_NAME).setValue(resUtil.getStateName());
        }

        if (resourceItem.getItemProperty(PROPERTY_STATE) != null) {
            resourceItem.getItemProperty(PROPERTY_STATE).setValue(resource.getState());
        }

        if (resourceItem.getItemProperty(PROPERTY_USER_LOCKED) != null) {
            resourceItem.getItemProperty(PROPERTY_USER_LOCKED).setValue(resUtil.getLockedByName());
        }
    }
444398
public void createSitemapSubEntry(final CmsClientSitemapEntry parent, final String sitemapFolderType) {

        CmsSitemapTreeItem item = CmsSitemapTreeItem.getItemById(parent.getId());
        AsyncCallback<CmsClientSitemapEntry> callback = new AsyncCallback<CmsClientSitemapEntry>() {

            public void onFailure(Throwable caught) {

                // do nothing
            }

            public void onSuccess(CmsClientSitemapEntry result) {

                makeNewEntry(parent, new I_CmsSimpleCallback<CmsClientSitemapEntry>() {

                    public void execute(CmsClientSitemapEntry newEntry) {

                        newEntry.setResourceTypeName(sitemapFolderType);
                        createSitemapSubEntry(newEntry, parent.getId(), sitemapFolderType);
                    }
                });
            }
        };
        if (item.getLoadState().equals(LoadState.UNLOADED)) {
            getChildren(parent.getId(), true, callback);
        } else {
            callback.onSuccess(parent);
        }
    }
1160937
public void setResourceShareArns(java.util.Collection<String> resourceShareArns) {
        if (resourceShareArns == null) {
            this.resourceShareArns = null;
            return;
        }

        this.resourceShareArns = new java.util.ArrayList<String>(resourceShareArns);
    }
1204183
public void buildResourcePaths() {
        try {
            if (Boolean.getBoolean(Stapler.class.getName()+".noResourcePathCache")) {
                resourcePaths = null;
                return;
            }

            Map<String,URL> paths = new HashMap<String,URL>();
            Stack<String> q = new Stack<String>();
            q.push("/");
            while (!q.isEmpty()) {
                String dir = q.pop();
                Set<String> children = context.getResourcePaths(dir);
                if (children!=null) {
                    for (String child : children) {
                        if (child.endsWith("/"))
                            q.push(child);
                        else {
                            URL v = context.getResource(child);
                            if (v==null) {
                                resourcePaths = null;
                                return; // this can't happen. abort with no cache
                            }
                            paths.put(child, v);
                        }
                    }
                }
            }

            resourcePaths = Collections.unmodifiableMap(paths);
        } catch (MalformedURLException e) {
            resourcePaths = null; // abort
        }
    }
389413
private void addPropertiesToModel(List<Property> localProperties, Item parent) {
        for (Property property : localProperties) {
            Item propertyItem = new Item(property, parent);
            model.add(propertyItem);

            // add any sub-properties
            Property[] subProperties = property.getSubProperties();
            if (subProperties != null && subProperties.length > 0) {
                addPropertiesToModel(Arrays.asList(subProperties), propertyItem);
            }
        }
    }
1282689
public void setFolders(java.util.Collection<FolderMetadata> folders) {
        if (folders == null) {
            this.folders = null;
            return;
        }

        this.folders = new java.util.ArrayList<FolderMetadata>(folders);
    }
926191
public CmsUUID addForbiddenParentFolder(String parentFolder, String reason) {

        CmsUUID id = new CmsUUID();
        m_forbiddenParentFolders.put(id, new ForbiddenFolderEntry(parentFolder, reason));
        return id;
    }
465701
public MenuView.ItemView createItemView(ViewGroup parent) {
        return (MenuView.ItemView) mSystemInflater.inflate(mItemLayoutRes, parent, false);
    }
98392
protected void buildJsonGalleryList() {

        String lastUsed = getSettings().getLastUsedGallery("" + getGalleryTypeId());
        // check the value of last Used, if gallery is opened for the first time
        if (CmsStringUtil.isEmpty(lastUsed)) {
            // start gallery settings for this gallery type for the current user
            String startGallerySetting = getSettings().getUserSettings().getStartGallery(
                getGalleryTypeName(),
                getCms());
            if (startGallerySetting != null) {
                // handle the case, "global settings" are selected
                if (startGallerySetting.equals(CmsWorkplace.INPUT_DEFAULT)) {
                    // get selected value from workplace xml settings
                    String preselectedValue = OpenCms.getWorkplaceManager().getDefaultUserSettings().getStartGallery(
                        getGalleryTypeName());
                    if (preselectedValue != null) {
                        startGallerySetting = preselectedValue;
                    }
                }
                // checks if the resource exists
                String sitePath = getCms().getRequestContext().removeSiteRoot(startGallerySetting);
                if (getCms().existsResource(sitePath)) {
                    lastUsed = sitePath;
                }
            }
        }
        JSONArray galleries = new JSONArray();
        Iterator<CmsResource> i = getGalleries().iterator();
        boolean isFirst = true;
        while (i.hasNext()) {
            CmsResource res = i.next();
            String path = getCms().getSitePath(res);
            JSONObject jsonObj = new JSONObject();
            // 1: gallery title
            String title = "";
            try {
                // read the gallery title
                title = getCms().readPropertyObject(path, CmsPropertyDefinition.PROPERTY_TITLE, false).getValue("");
            } catch (CmsException e) {
                // error reading title property
                if (LOG.isErrorEnabled()) {
                    LOG.error(e.getLocalizedMessage(), e);
                }
            }
            try {
                jsonObj.put("title", title);
                // 2: gallery path
                jsonObj.put("path", path);
                // 3: active flag
                boolean active = false;
                if ((CmsStringUtil.isEmpty(lastUsed) && isFirst) || path.equals(lastUsed)) {
                    // TODO: adjust logic to get active gallery
                    active = true;
                }
                jsonObj.put("active", active);
                galleries.put(jsonObj);
            } catch (JSONException e) {
                if (LOG.isErrorEnabled()) {
                    LOG.error(e.getLocalizedMessage(), e);
                }
            }
            isFirst = false;
        }
        JspWriter out = getJsp().getJspContext().getOut();
        try {
            out.print(galleries.toString());
        } catch (IOException e) {
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
    }
1252996
@SuppressWarnings("deprecation")
    public CmsResource createFolder(String targetFolder, String folderName) throws Exception {

        if (m_cms.existsResource(targetFolder + folderName)) {
            m_shell.getOut().println(
                getMessages().key(Messages.GUI_SHELL_FOLDER_ALREADY_EXISTS_1, targetFolder + folderName));
            return null;
        }
        return m_cms.createResource(targetFolder + folderName, CmsResourceTypeFolder.getStaticTypeId());
    }
1247355
private CmsTreeItem buildTreeItem(
        CmsCategoryTreeEntry category,
        Collection<String> selectedCategories,
        boolean inactive) {

        CmsDataValue categoryTreeItem = new CmsDataValue(
            500,
            4,
            CmsCategoryBean.SMALL_ICON_CLASSES,
            category.getTitle(),
            category.getPath());
        if (inactive) {
            categoryTreeItem.setInactive();
        }
        categoryTreeItem.setTitle(
            CmsStringUtil.isNotEmptyOrWhitespaceOnly(category.getDescription())
            ? category.getDescription()
            : category.getPath());
        CmsTreeItem treeItem = new CmsTreeItem(false, categoryTreeItem);
        treeItem.setId(category.getPath());
        boolean isPartofPath = false;
        Iterator<String> it = selectedCategories.iterator();
        while (it.hasNext()) {
            String path = it.next();
            if (path.startsWith(category.getPath()) || path.contains("/" + category.getPath())) {
                isPartofPath = true;
            }
        }
        if (isPartofPath) {
            m_categories.add(treeItem);
            treeItem.setOpen(true);
        }
        return treeItem;
    }