Writes a property for a specified resource.<p>

@param resourcename the name of resource with complete path
@param property the property to write

@throws CmsException if something goes wrong
194239
public void writePropertyObject(String resourcename, CmsProperty property) throws CmsException {

        CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION);
        getResourceType(resource).writePropertyObject(this, m_securityManager, resource, property);
    }
1056579
private void deleteResource(CmsResource resource) throws CmsException {

        String path = null;
        CmsObject cms = getCmsObject();
        try {
            path = cms.getSitePath(resource);
            cms.lockResource(path);
            cms.deleteResource(path, CmsResource.DELETE_PRESERVE_SIBLINGS);
            // check if any detail container page resources exist to this resource
            List<CmsResource> detailContainers = CmsDetailOnlyContainerUtil.getDetailOnlyResources(cms, resource);
            for (CmsResource detailContainer : detailContainers) {
                deleteResource(detailContainer);
            }
        } finally {
            try {
                if (path != null) {
                    getCmsObject().unlockResource(path);
                }
            } catch (Exception e) {
                // should really never happen
                LOG.debug(e.getLocalizedMessage(), e);
            }
        }
    }
824012
private void init(CmsResource resource, CmsObject cms, String property) {

        try {
            cms.readPropertyDefinition(property);
            CmsProperty prop = cms.readPropertyObject(resource, property, false);

            if (prop == CmsProperty.getNullProperty()) {
                m_propertyValue = "";
            } else {
                m_propertyValue = prop.getValue();
            }
        } catch (CmsDbEntryNotFoundException dbe) {
            // property are not configured
            throw new CmsIllegalArgumentException(
                Messages.get().container(Messages.ERR_COLLECTOR_PARAM_PROPERTY_NOT_FOUND_1, property));
        } catch (CmsException cmse) {
            // something's gone wrong...
            cmse.printStackTrace();
        }
    }
875221
public void write(@NonNull Resource resource) throws IOException {
      try (JsonWriter writer = Json.createWriter(resource)) {
         writer.beginDocument();
         writer.property("id", getId());
         writer.property("content", toString());

         if (attributes.size() > 0) {
            writer.beginObject("attributes");
            for (Map.Entry<AttributeType, Val> entry : attributeEntrySet()) {
               writer.property(entry.getKey().name(), entry.getKey().getValueType().encode(entry.getValue()));
            }
            writer.endObject();
         }

         if (annotationSet.size() > 0) {
            writer.beginObject("completed");
            for (AnnotatableType type : getAnnotationSet().getCompleted()) {
               writer.property(type.canonicalName(), getAnnotationSet().getAnnotationProvider(type));
            }
            writer.endObject();

            writer.beginArray("annotations");
            for (Annotation annotation : annotationSet) {
               writer.beginObject();
               writer.property("type", annotation.getType().name());
               writer.property("start", annotation.start());
               writer.property("end", annotation.end());
               writer.property("id", annotation.getId());
               if (Config.get("Annotation.writeContent").asBooleanValue(false)) {
                  writer.property("content", annotation.toString());
               }

               if (annotation.getAttributeMap().size() > 0) {
                  writer.beginObject("attributes");
                  for (Map.Entry<AttributeType, Val> entry : annotation.attributeEntrySet()) {
                     writer.property(entry.getKey().name(),
                                     entry.getKey().getValueType().encode(entry.getValue()));

                  }
                  writer.endObject();
               }

               Collection<Relation> relations = annotation.relations();
               if (relations.size() > 0) {
                  writer.beginArray("relations");
                  for (Relation relation : relations) {
                     writer.beginObject();
                     writer.property("type", relation.getType());
                     writer.property("value", relation.getValue());
                     writer.property("target", relation.getTarget());
                     writer.endObject();
                  }
                  writer.endArray();
               }

               writer.endObject();
            }
            writer.endArray();
         }
         writer.endDocument();
      }
   }
662271
protected void showResources(String propertyName) {

        CmsSearchReplaceSettings settings = new CmsSearchReplaceSettings();
        settings.setPaths(Collections.singletonList("/"));
        settings.setSiteRoot("");
        settings.setSearchpattern(".*");
        settings.setType(SearchType.properties);
        try {
            settings.setProperty(A_CmsUI.getCmsObject().readPropertyDefinition(propertyName));
        } catch (CmsException e) {
            //
        }
        CmsAppWorkplaceUi.get().getNavigator().navigateTo(
            CmsSourceSearchAppConfiguration.APP_ID + "/" + CmsSourceSearchApp.generateState(settings));
    }
108612
public void moveTo(String cmsNewPath) throws CmsException {

        ensureLock();
        m_cms.moveResource(m_cms.getSitePath(m_resource), cmsNewPath);
        CmsUUID id = m_resource.getStructureId();
        CmsResource updatedRes = m_cms.readResource(id, CmsJlanDiskInterface.STANDARD_FILTER);
        m_resource = updatedRes;
        updateFromResource();
    }
390618
public CmsPropertiesBean loadPropertyData(CmsUUID id) throws CmsException {

        CmsObject cms = m_cms;
        String originalSiteRoot = cms.getRequestContext().getSiteRoot();
        CmsPropertiesBean result = new CmsPropertiesBean();
        CmsResource resource = cms.readResource(id, CmsResourceFilter.IGNORE_EXPIRATION);
        result.setReadOnly(!isWritable(cms, resource));
        result.setFolder(resource.isFolder());
        result.setContainerPage(CmsResourceTypeXmlContainerPage.isContainerPage(resource));
        String sitePath = cms.getSitePath(resource);
        Map<String, CmsXmlContentProperty> propertyConfig = OpenCms.getADEManager().lookupConfiguration(
            cms,
            resource.getRootPath()).getPropertyConfigurationAsMap();
        Map<String, CmsXmlContentProperty> defaultProperties = getDefaultProperties(

            Collections.singletonList(resource.getStructureId())).get(resource.getStructureId());
        Map<String, CmsXmlContentProperty> mergedConfig = new LinkedHashMap<String, CmsXmlContentProperty>();
        mergedConfig.putAll(defaultProperties);
        mergedConfig.putAll(propertyConfig);
        propertyConfig = mergedConfig;

        // Resolve macros in the property configuration
        propertyConfig = CmsXmlContentPropertyHelper.resolveMacrosInProperties(
            propertyConfig,
            CmsMacroResolver.newWorkplaceLocaleResolver(cms));
        updateWysiwygConfig(propertyConfig, cms, resource);

        result.setPropertyDefinitions(new LinkedHashMap<String, CmsXmlContentProperty>(propertyConfig));
        try {
            cms.getRequestContext().setSiteRoot("");
            String parentPath = CmsResource.getParentFolder(resource.getRootPath());
            CmsResource parent = cms.readResource(parentPath, CmsResourceFilter.IGNORE_EXPIRATION);
            List<CmsProperty> parentProperties = cms.readPropertyObjects(parent, true);
            List<CmsProperty> ownProperties = cms.readPropertyObjects(resource, false);
            result.setOwnProperties(convertProperties(ownProperties));
            result.setInheritedProperties(convertProperties(parentProperties));
            result.setPageInfo(CmsVfsService.getPageInfo(cms, resource));
            List<CmsPropertyDefinition> propDefs = cms.readAllPropertyDefinitions();
            List<String> propNames = new ArrayList<String>();
            for (CmsPropertyDefinition propDef : propDefs) {
                propNames.add(propDef.getName());
            }
            CmsTemplateFinder templateFinder = new CmsTemplateFinder(cms);
            result.setTemplates(templateFinder.getTemplates());
            result.setAllProperties(propNames);
            result.setStructureId(id);
            result.setSitePath(sitePath);
            return result;
        } finally {
            cms.getRequestContext().setSiteRoot(originalSiteRoot);
        }
    }
515542
private CmsClientTemplateBean getTemplateBean(CmsObject cms, CmsResource resource) throws CmsException {

        CmsProperty titleProp = cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_TITLE, false);
        CmsProperty descProp = cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_DESCRIPTION, false);
        CmsProperty imageProp = cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_TEMPLATE_IMAGE, false);
        CmsProperty selectValueProp = cms.readPropertyObject(
            resource,
            CmsPropertyDefinition.PROPERTY_TEMPLATE_PROVIDER,
            false);
        String sitePath = cms.getSitePath(resource);
        String templateValue = sitePath;
        if (!selectValueProp.isNullProperty() && !CmsStringUtil.isEmptyOrWhitespaceOnly(selectValueProp.getValue())) {
            String selectValue = selectValueProp.getValue();
            CmsMacroResolver resolver = new CmsMacroResolver();
            resolver.addMacro(MACRO_TEMPLATEPATH, sitePath);
            templateValue = resolver.resolveMacros(selectValue);
        }
        return new CmsClientTemplateBean(
            titleProp.getValue(),
            descProp.getValue(),
            templateValue,
            imageProp.getValue());
    }
720820
public String buildResourceList() throws CmsException {

        List resourcesWithProperty = getCms().readResourcesWithProperty(getParamPropertyName());

        return buildResourceList(resourcesWithProperty, false);
    }
982146
public static void checkResourceName(String name) {

        try {
            CmsResource.checkResourceName(name);
        } catch (CmsIllegalArgumentException e) {
            throw new CmisNameConstraintViolationException(e.getLocalizedMessage(), e);
        }
    }
347771
public void setResourceId(String resourceId) {

        try {
            if (!m_resourceBuilder.isFolder()) {
                m_resourceBuilder.setResourceId(new CmsUUID(resourceId));
            } else {
                m_resourceBuilder.setResourceId(new CmsUUID());
            }
        } catch (Throwable e) {
            setThrowable(e);
        }
    }
351146
public static void updateWysiwygConfig(
        Map<String, CmsXmlContentProperty> propertyConfig,
        CmsObject cms,
        CmsResource resource) {

        Map<String, CmsXmlContentProperty> wysiwygUpdates = Maps.newHashMap();
        String wysiwygConfig = null;
        for (Map.Entry<String, CmsXmlContentProperty> entry : propertyConfig.entrySet()) {
            CmsXmlContentProperty prop = entry.getValue();
            if (prop.getWidget().equals("wysiwyg")) {
                if (wysiwygConfig == null) {
                    String configStr = "";
                    try {
                        String filePath = OpenCms.getSystemInfo().getConfigFilePath(cms, "wysiwyg/property-widget");
                        String configFromVfs = (String)CmsVfsMemoryObjectCache.getVfsMemoryObjectCache().loadVfsObject(
                            cms,
                            filePath,
                            new Transformer() {

                                public Object transform(Object rootPath) {

                                    try {
                                        CmsFile file = cms.readFile(
                                            (String)rootPath,
                                            CmsResourceFilter.IGNORE_EXPIRATION);
                                        return new String(file.getContents(), "UTF-8");
                                    } catch (Exception e) {
                                        return "";
                                    }
                                }
                            });
                        configStr = configFromVfs;
                    } catch (Exception e) {
                        LOG.error(e.getLocalizedMessage(), e);
                    }

                    CmsHtmlWidgetOption opt = new CmsHtmlWidgetOption(configStr);
                    Locale locale = resource != null
                    ? OpenCms.getLocaleManager().getDefaultLocale(cms, resource)
                    : Locale.ENGLISH;
                    String json = CmsHtmlWidget.getJSONConfiguration(opt, cms, resource, locale).toString();
                    List<String> nums = Lists.newArrayList();
                    try {
                        for (byte b : json.getBytes("UTF-8")) {
                            nums.add("" + b);
                        }
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    wysiwygConfig = "v:" + CmsStringUtil.listAsString(nums, ",");
                }
                CmsXmlContentProperty prop2 = prop.withConfig(wysiwygConfig);
                wysiwygUpdates.put(entry.getKey(), prop2);
            }
        }
        propertyConfig.putAll(wysiwygUpdates);
    }
753574
public void addProperty(String propertyType) {

        if (m_properties == null) {
            // this list will be used and clean up in the importResource method
            m_properties = new HashMap<String, CmsProperty>();
        }
        try {
            if ((m_propertyName == null) || getIgnoredProperties().contains(m_propertyName)) {
                // continue if the current property (name) should be ignored or is null
                return;
            }
            CmsProperty property = m_properties.get(m_propertyName);
            if (property == null) {
                property = new CmsProperty();
                property.setName(m_propertyName);
                property.setAutoCreatePropertyDefinition(true);
                m_properties.put(m_propertyName, property);
            }

            if (m_propertyValue == null) {
                m_propertyValue = "";
            }

            if ((propertyType != null) && propertyType.equals(PROPERTY_ATTRIB_TYPE_SHARED)) {
                // it is a shared/resource property value
                property.setResourceValue(m_propertyValue);
            } else {
                // it is an individual/structure value
                property.setStructureValue(m_propertyValue);
            }
        } finally {
            m_propertyName = null;
            m_propertyValue = null;
        }
    }
245713
protected void performSingleDeleteOperation(String resource, CmsResourceDeleteMode deleteOption)
    throws CmsException {

        // lock resource if autolock is enabled
        checkLock(resource);
        // delete the resource
        getCms().deleteResource(resource, deleteOption);
    }
643562
public void setResourceType(String resourceType) {

        if (CmsStringUtil.isEmptyOrWhitespaceOnly(resourceType)) {
            throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_VALUE_EMPTY_0));
        }
        m_resourceType = resourceType;
    }
169971
private void initXmlBundle() throws CmsException {

        CmsFile file = m_cms.readFile(m_resource);
        m_bundleFiles.put(null, m_resource);
        m_xmlBundle = CmsXmlContentFactory.unmarshal(m_cms, file);
        initKeySetForXmlBundle();

    }
296184
public void setIndex(String indexName) throws CmsException {

        if (CmsStringUtil.isEmpty(indexName)) {
            throw new CmsException(Messages.get().container(Messages.ERR_INDEXSOURCE_CREATE_MISSING_NAME_0));
        }
        CmsSolrIndex index = OpenCms.getSearchManager().getIndexSolr(indexName);
        if (index == null) {
            throw new CmsException(Messages.get().container(Messages.ERR_INDEX_NOT_FOUND_1, indexName));
        }

        m_index = index;

    }