Evaluate the XPath on an XMLResource and convert the result into aReturnType.

@param <T> the expected type of the result
@param resource
@param aReturnType
@return
@throws Exception
517855
public <T> T eval(XMLResource resource, Class<T>aReturnType) throws Exception {
		T retVal = (T) xPathExpression.evaluate(resource.doc(), getConstant(aReturnType));
		return retVal;
	}
846928
public List<ReconfigBeanDefinitionHolder> load(Resource resource) {
    List<ReconfigBeanDefinitionHolder> holders = new ArrayList<ReconfigBeanDefinitionHolder>();
    try {
      InputStream inputStream = resource.getInputStream();
      try {
        InputSource inputSource = new InputSource(inputStream);
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = factory.newDocumentBuilder();
        Document doc = docBuilder.parse(inputSource);
        Element root = doc.getDocumentElement();
        NodeList nl = root.getChildNodes();
        BeanDefinitionParser parser = new BeanDefinitionParser();
        for (int i = 0; i < nl.getLength(); i++) {
          Node node = nl.item(i);
          if (node instanceof Element) {
            Element ele = (Element) node;
            ReconfigBeanDefinitionHolder holder = parser.parseBeanDefinitionElement(ele);
            holders.add(holder);
          }
        }
      } finally {
        if (null != inputStream) {
          inputStream.close();
        }
      }
    } catch (Exception ex) {
      throw new RuntimeException("IOException parsing XML document from " + resource.getDescription(), ex);
    }
    return holders;
  }
651177
@Override
    public boolean transform(IResource resource) throws Exception {
        String path = resource.getSourcePath();
        
        if (path.startsWith("META-INF/")) {
            return false;
        }
        
        if (hsFile == null && loader.isHelpSetFile(path)) {
            hsFile = getResourceBase() + resource.getTargetPath();
        }
        
        return super.transform(resource);
    }
11554
protected static boolean isFolder(CmsResource resource) throws CmsLoaderException {

        I_CmsResourceType resourceType = OpenCms.getResourceManager().getResourceType(resource.getTypeId());
        return resourceType.isFolder();
    }
654366
public static void check(final Object result, final Class<?> targetType) {
        if (result != null && !targetType.isAssignableFrom(result.getClass())) {
            // note: conversion logic may go wrong (e.g. because converter expect collection input mostly and may
            // not work correctly for single element), but anyway overall conversion would be considered failed.
            throw new ResultConversionException(String.format("Failed to convert %s to %s",
                    toStringType(result), targetType.getSimpleName()));
        }
    }
1157246
@Override
    public void processXML()
                    throws InjectionException
    {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "processXML");

        // Process all of the corresponding XML types in no particular
        // order other than it is the same as in prior releases.

        List<? extends EnvEntry> envEntries = ivNameSpaceConfig.getEnvEntries();
        if (envEntries != null)
        {
            processXMLEnvEntries(envEntries);
        }

        List<? extends ResourceRef> resourceRefs = ivNameSpaceConfig.getResourceRefs();
        if (resourceRefs != null)
        {
            processXMLResourceRefs(resourceRefs);
        }

        List<? extends ResourceEnvRef> resourceEnvRefs = ivNameSpaceConfig.getResourceEnvRefs();
        if (resourceEnvRefs != null)
        {
            processXMLResourceEnvRefs(resourceEnvRefs);
        }

        List<? extends MessageDestinationRef> msgDestRefs = ivNameSpaceConfig.getMsgDestRefs();
        if (msgDestRefs != null)
        {
            processXMLMsgDestRefs(msgDestRefs);
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "processXML");
    }
863477
@Override
    public LoadedResource<Templates> loadResource(Resource resource) throws IOException {
        final TransformerFactory transformerFactory = TransformerFactory.newInstance();

        if (this.transformerAttributes != null) {
            for (final Map.Entry<String, Object> attributeEntry :
                    this.transformerAttributes.entrySet()) {
                transformerFactory.setAttribute(attributeEntry.getKey(), attributeEntry.getValue());
            }
        }

        final ResourceTrackingURIResolver uriResolver =
                new ResourceTrackingURIResolver(this.resourceLoader);
        transformerFactory.setURIResolver(uriResolver);

        final URI uri = resource.getURI();
        final String systemId = uri.toString();

        final InputStream stream = resource.getInputStream();
        final Templates templates;
        try {
            final StreamSource source = new StreamSource(stream, systemId);
            templates = transformerFactory.newTemplates(source);
        } catch (TransformerConfigurationException e) {
            throw new IOException("Failed to parse stream into Templates", e);
        } finally {
            IOUtils.closeQuietly(stream);
        }

        final Map<Resource, Long> resolvedResources = uriResolver.getResolvedResources();

        return new LoadedResourceImpl<Templates>(templates, resolvedResources);
    }
1039133
private void createResourceType() {

        CmsProject currentProject = m_cms.getRequestContext().getCurrentProject();
        try {

            CmsProject workProject = m_cms.createProject(
                "Add_resource_type_project",
                "Add resource type project",
                OpenCms.getDefaultUsers().getGroupAdministrators(),
                OpenCms.getDefaultUsers().getGroupAdministrators(),
                CmsProject.PROJECT_TYPE_TEMPORARY);
            m_cms.getRequestContext().setCurrentProject(workProject);

            if (!m_cms.existsResource(m_parentSchema.getValue())) {

                I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(
                    CmsResourceTypeFolder.RESOURCE_TYPE_NAME);
                CmsResource res = m_cms.createResource(m_parentSchema.getValue(), type);
                m_cms.unlockResource(res);

            }
            if (!m_cms.existsResource(m_parentFormatter.getValue())) {

                I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(
                    CmsResourceTypeFolder.RESOURCE_TYPE_NAME);
                CmsResource res = m_cms.createResource(m_parentFormatter.getValue(), type);
                m_cms.unlockResource(res);

            }

            String formatterPath = m_parentFormatter.getValue() + m_typeShortName.getValue() + ".jsp";
            String formatterConfigPath = m_parentFormatter.getValue() + m_typeShortName.getValue() + ".xml";
            String schemaPath = m_parentSchema.getValue() + m_typeShortName.getValue() + ".xsd";
            if (!m_cms.existsResource(formatterPath)) {
                m_cms.copyResource(SAMPLE_FORMATTER, formatterPath);
            }
            if (!m_cms.existsResource(schemaPath)) {
                m_cms.copyResource(SAMPLE_SCHEMA, schemaPath);
            }

            if (!m_cms.existsResource(formatterConfigPath)) {
                I_CmsResourceType configType = OpenCms.getResourceManager().getResourceType(
                    CmsFormatterConfigurationCache.TYPE_FORMATTER_CONFIG);
                List<CmsProperty> props = new ArrayList<CmsProperty>();
                props.add(new CmsProperty(CmsPropertyDefinition.PROPERTY_LOCALE, "en", null));
                props.add(new CmsProperty(CmsPropertyDefinition.PROPERTY_AVAILABLE_LOCALES, "en", null));

                m_cms.createResource(formatterConfigPath, configType, null, props);
            }
            CmsLockUtil.tryUnlock(m_cms, m_cms.readResource(formatterPath));
            CmsLockUtil.tryUnlock(m_cms, m_cms.readResource(formatterConfigPath));
            CmsLockUtil.tryUnlock(m_cms, m_cms.readResource(schemaPath));
            addResourceToModule(formatterPath, m_module);
            addResourceToModule(formatterConfigPath, m_module);
            addResourceToModule(schemaPath, m_module);
            adjustFormatterConfig(formatterPath, formatterConfigPath);
            adjustSchema(schemaPath, m_typeXPathName.getValue());
            adjustModuleConfig();

            List<I_CmsResourceType> types = new ArrayList<I_CmsResourceType>(m_module.getResourceTypes());
            // create the new resource type
            CmsResourceTypeXmlContent type = new CmsResourceTypeXmlContent();
            type.addConfigurationParameter(CmsResourceTypeXmlContent.CONFIGURATION_SCHEMA, schemaPath);
            type.setAdditionalModuleResourceType(true);
            type.setModuleName(m_module.getName());
            type.initConfiguration(
                m_typeShortName.getValue(),
                m_typeID.getValue(),
                CmsResourceTypeXmlContent.class.getName());
            types.add(type);
            m_module.setResourceTypes(types);

            List<CmsExplorerTypeSettings> settings = new ArrayList<CmsExplorerTypeSettings>(
                m_module.getExplorerTypes());
            // create the matching explorer type
            CmsExplorerTypeSettings setting = new CmsExplorerTypeSettings();
            setting.setTypeAttributes(
                m_typeShortName.getValue(),
                m_typeName.getValue(), //ToDo nicename
                null,
                null,
                ICON_SMALL_DEFAULT,
                ICON_BIG_DEFAULT,
                "xmlcontent",
                null,
                "false",
                null,
                null);
            setting.setAutoSetNavigation("false");
            setting.setAutoSetTitle("false");
            setting.setNewResourceOrder("10");
            setting.setAddititionalModuleExplorerType(true);
            addTypeMessages(setting, getMessageParentFolder(m_module.getName()));
            settings.add(setting);
            m_module.setExplorerTypes(settings);
            m_cms.unlockProject(workProject.getUuid());
            OpenCms.getPublishManager().publishProject(
                m_cms,
                new CmsLogReport(m_cms.getRequestContext().getLocale(), getClass()));
            OpenCms.getPublishManager().waitWhileRunning();
        } catch (Exception e) {
            LOG.error("Unable to create resource type", e);
        } finally {
            m_cms.getRequestContext().setCurrentProject(currentProject);
        }
    }
691445
@Override
    public final Transformer getTransformer(
            HttpServletRequest request, HttpServletResponse response) {
        final Resource stylesheetResource = this.getStylesheetResource(request);
        try {
            return this.xmlUtilities.getTransformer(stylesheetResource);
        } catch (TransformerConfigurationException e) {
            throw new RuntimeException(
                    "Failed to get Transformer for stylesheet: " + stylesheetResource, e);
        } catch (IOException e) {
            throw new RuntimeException("Failed to load stylesheet: " + stylesheetResource, e);
        }
    }
809893
public void setResourceType(java.util.Collection<StringFilter> resourceType) {
        if (resourceType == null) {
            this.resourceType = null;
            return;
        }

        this.resourceType = new java.util.ArrayList<StringFilter>(resourceType);
    }
247263
public Object castToType(int t, XPathContext support)
          throws javax.xml.transform.TransformerException
  {

    Object result;

    switch (t)
    {
    case CLASS_STRING :
      result = str();
      break;
    case CLASS_NUMBER :
      result = new Double(num());
      break;
    case CLASS_NODESET :
      result = iter();
      break;
    case CLASS_BOOLEAN :
      result = new Boolean(bool());
      break;
    case CLASS_UNKNOWN :
      result = m_obj;
      break;

    // %TBD%  What to do here?
    //    case CLASS_RTREEFRAG :
    //      result = rtree(support);
    //      break;
    default :
      error(XPATHErrorResources.ER_CANT_CONVERT_TO_TYPE,
            new Object[]{ getTypeString(),
                          Integer.toString(t) });  //"Can not convert "+getTypeString()+" to a type#"+t);

      result = null;
    }

    return result;
  }
339230
protected static void checkIsFolder(CmsResource resource) throws CmsException {

        if (!isFolder(resource)) {
            throw new CmsIllegalArgumentException(
                Messages.get().container(
                    org.opencms.file.Messages.ERR_REWRITE_LINKS_ROOT_NOT_FOLDER_1,
                    resource.getRootPath()));
        }
    }
1338327
public static boolean isNavLevelFolder(CmsObject cms, CmsResource resource) {

        if (resource.isFolder()) {
            I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(resource);
            if (CmsResourceTypeFolder.RESOURCE_TYPE_NAME.equals(type.getTypeName())) {
                try {
                    CmsProperty prop = cms.readPropertyObject(
                        resource,
                        CmsPropertyDefinition.PROPERTY_DEFAULT_FILE,
                        false);
                    return !prop.isNullProperty() && NAVIGATION_LEVEL_FOLDER.equals(prop.getValue());
                } catch (CmsException e) {
                    LOG.debug(e.getMessage(), e);
                }
            }
        }
        return false;
    }
1183969
public static List<Resource> getChildrenByResourceType(final Resource resource, String resourceType) {
        final ArrayList<Resource> children = new ArrayList<>();
        if (resource != null) {
            for (final Resource child : resource.getChildren()) {
                if (child.isResourceType(resourceType)) {
                    children.add(child);
                }
            }
        }
        return children;
    }
90607
private Reader getResourceReader(String resource) throws ResourceNotFoundException {
		List<Class<?>> excluded = new ArrayList<>();
		excluded.add(ILessCssResourceGenerator.class);
		return rsReaderHandler.getResource(bundle, resource, false, excluded);
	}
273178
public static void generateResourceTypeXml(
        Element startNode,
        List<I_CmsResourceType> resourceTypes,
        boolean module) {

        for (int i = 0; i < resourceTypes.size(); i++) {
            I_CmsResourceType resType = resourceTypes.get(i);
            // only add this resource type to the xml output, if it is no additional type defined
            // in a module
            if (resType.isAdditionalModuleResourceType() == module) {
                Element resourceType = startNode.addElement(N_TYPE).addAttribute(A_CLASS, resType.getClassName());
                // add type id and type name
                resourceType.addAttribute(A_NAME, resType.getTypeName());
                resourceType.addAttribute(A_ID, String.valueOf(resType.getTypeId()));
                // add resource mappings
                List<String> mappings = resType.getConfiguredMappings();
                if ((mappings != null) && (mappings.size() > 0)) {
                    Element mappingsNode = resourceType.addElement(N_MAPPINGS);
                    for (int j = 0; j < mappings.size(); j++) {
                        Element mapping = mappingsNode.addElement(N_MAPPING);
                        mapping.addAttribute(A_SUFFIX, mappings.get(j));
                    }
                }
                // add default properties
                List<CmsProperty> properties = resType.getConfiguredDefaultProperties();
                if (properties != null) {
                    if (properties.size() > 0) {
                        Element propertiesNode = resourceType.addElement(N_PROPERTIES);
                        Iterator<CmsProperty> p = properties.iterator();
                        while (p.hasNext()) {
                            CmsProperty property = p.next();
                            Element propertyNode = propertiesNode.addElement(N_PROPERTY);
                            propertyNode.addElement(N_NAME).addText(property.getName());
                            if (property.getStructureValue() != null) {
                                propertyNode.addElement(N_VALUE).addCDATA(property.getStructureValue());
                            }
                            if (property.getResourceValue() != null) {
                                propertyNode.addElement(N_VALUE).addAttribute(A_TYPE, CmsProperty.TYPE_SHARED).addCDATA(
                                    property.getResourceValue());
                            }
                        }
                    }
                }
                // add copy resources
                List<CmsConfigurationCopyResource> copyRes = resType.getConfiguredCopyResources();
                if ((copyRes != null) && (copyRes.size() > 0)) {
                    Element copyResNode = resourceType.addElement(N_COPY_RESOURCES);
                    Iterator<CmsConfigurationCopyResource> p = copyRes.iterator();
                    String adjustLinksFolder = resType.getAdjustLinksFolder();
                    if (adjustLinksFolder != null) {
                        copyResNode.addAttribute(A_ADJUST_LINKS_FOLDER, adjustLinksFolder);
                    }
                    while (p.hasNext()) {
                        CmsConfigurationCopyResource cRes = p.next();
                        Element cNode = copyResNode.addElement(N_COPY_RESOURCE);
                        cNode.addAttribute(A_SOURCE, cRes.getSource());
                        if (!cRes.isTargetWasNull()) {
                            cNode.addAttribute(A_TARGET, cRes.getTarget());
                        }
                        if (!cRes.isTypeWasNull()) {
                            cNode.addAttribute(A_TYPE, cRes.getTypeString());
                        }
                    }
                }
                // add optional parameters
                CmsParameterConfiguration configuration = resType.getConfiguration();
                if (configuration != null) {
                    List<String> ignore = null;
                    if ((resType instanceof CmsResourceTypeXmlContainerPage)) {
                        ignore = new ArrayList<String>(1);
                        ignore.add(CmsResourceTypeXmlContent.CONFIGURATION_SCHEMA);
                    }
                    configuration.appendToXml(resourceType, ignore);
                }
            }
        }
    }
119493
public static void checkContentResourceType(NodeType contentNodeType) throws NoSuchNodeTypeException
   {
      if (!contentNodeType.isNodeType(WebDavConst.NodeTypes.NT_RESOURCE))
      {
         throw new NoSuchNodeTypeException("Content-Node type " + contentNodeType.getName()
            + " must extend nt:resource.");
      }
   }