Loads the OpenCms configuration from the given XML file.<p>

@throws SAXException in case of XML parse errors
@throws IOException in case of file IO errors
434099
public void loadXmlConfiguration() throws SAXException, IOException {

        URL baseUrl = m_baseFolder.toURI().toURL();
        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.LOG_BASE_URL_1, baseUrl));
        }

        // first load the base configuration
        loadXmlConfiguration(baseUrl, this);

        // now iterate all sub-configurations
        Iterator<I_CmsXmlConfiguration> i = m_configurations.iterator();
        while (i.hasNext()) {
            loadXmlConfiguration(baseUrl, i.next());
        }

        // remove the old backups
        removeOldBackups(MAX_BACKUP_DAYS);
    }
133618
public void initialize(CmsObject cms) throws CmsRoleViolationException {

        OpenCms.getRoleManager().checkRole(cms, CmsRole.WORKPLACE_MANAGER);
        try {
            // store the Admin cms to index Cms resources
            m_adminCms = OpenCms.initCmsObject(cms);
        } catch (CmsException e) {
            // this should never happen
            LOG.error(e.getLocalizedMessage(), e);
        }
        // make sure the site root is the root site
        m_adminCms.getRequestContext().setSiteRoot("/");

        // create the extraction result cache
        m_extractionResultCache = new CmsExtractionResultCache(
            OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(getDirectory()),
            "/extractCache");
        initializeFieldConfigurations();
        initializeIndexes();
        initOfflineIndexes();

        // register this object as event listener
        OpenCms.addCmsEventListener(
            this,
            new int[] {
                I_CmsEventListener.EVENT_CLEAR_CACHES,
                I_CmsEventListener.EVENT_PUBLISH_PROJECT,
                I_CmsEventListener.EVENT_REBUILD_SEARCHINDEXES});
    }
267727
protected void init() {

        // initialize OpenCms access objects
        CmsFlexController controller = CmsFlexController.getController(pageContext.getRequest());
        m_cms = controller.getCmsObject();

        int startLevel = m_startLevel == null ? Integer.MIN_VALUE : Integer.parseInt(m_startLevel);
        int endLevel = m_endLevel == null ? Integer.MIN_VALUE : Integer.parseInt(m_endLevel);

        // load navigation bean in the JSP context
        CmsJspNavigationBean bean = new CmsJspNavigationBean(
            m_cms,
            m_type,
            startLevel,
            endLevel,
            m_resource,
            m_param,
            m_locale);
        storeAttribute(getVar(), bean);
    }
431673
private CmsTemplateMapperConfiguration getConfiguration(final CmsObject cms) {

        if (!m_enabled) {
            return CmsTemplateMapperConfiguration.EMPTY_CONFIG;
        }

        if (m_configPath == null) {
            m_configPath = OpenCms.getSystemInfo().getConfigFilePath(cms, "template-mapping.xml");
        }

        return (CmsTemplateMapperConfiguration)(CmsVfsMemoryObjectCache.getVfsMemoryObjectCache().loadVfsObject(
            cms,
            m_configPath,
            new Transformer() {

                @Override
                public Object transform(Object input) {

                    try {
                        CmsFile file = cms.readFile(m_configPath, CmsResourceFilter.IGNORE_EXPIRATION);
                        SAXReader saxBuilder = new SAXReader();
                        try (ByteArrayInputStream stream = new ByteArrayInputStream(file.getContents())) {
                            Document document = saxBuilder.read(stream);
                            CmsTemplateMapperConfiguration config = new CmsTemplateMapperConfiguration(cms, document);
                            return config;
                        }
                    } catch (Exception e) {
                        LOG.warn(e.getLocalizedMessage(), e);
                        return new CmsTemplateMapperConfiguration(); // empty configuration, does not do anything
                    }

                }
            }));
    }
817458
public void fromXML(String file) throws DocumentException
    {
        SAXReader reader = new SAXReader();
        fromXML(reader.read(new StringReader(file)));
    }
1068757
public static Config parse(InputStream in) throws XmlPullParserException, IOException {
        try {
            XmlPullParser parser = Xml.newPullParser();
            parser.setInput(in, null);
            parser.nextTag();
            return readFamilies(parser);
        } finally {
            in.close();
        }
    }
745499
public void initializeCms(CmsObject adminCms) {

        try {
            m_cmsObject = adminCms;
            try {
                String path = CONFIG_PATH;
                if (m_cmsObject.existsResource(path)) {
                    LOG.info("Flex configuration found at " + CONFIG_PATH + ", initializing...");
                    m_bucketConfiguration = CmsFlexBucketConfiguration.loadFromVfsFile(m_cmsObject, path);
                }
            } catch (Exception e) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        } catch (Exception e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    }
194227
protected void prepareXMLReader() throws VerifierConfigurationException {
		try {
			SAXParserFactory factory = SAXParserFactory.newInstance();
			factory.setNamespaceAware(true);
			reader = factory.newSAXParser().getXMLReader();
		} catch( SAXException e ) {
			throw new VerifierConfigurationException(e);
		} catch( ParserConfigurationException pce ) {
			throw new VerifierConfigurationException(pce);
		}
	}
590283
protected void init() throws CmsException {

        m_cms = OpenCms.initCmsObject(m_cms);
        // we want to use autocorrection when writing XML contents back
        //m_cms.getRequestContext().setAttribute(CmsXmlContent.AUTO_CORRECTION_ATTRIBUTE, Boolean.TRUE);
        m_cms.getRequestContext().setSiteRoot("");
        List<CmsPair<CmsResource, CmsResource>> allMatchingResources = Lists.newArrayList();
        for (CmsPair<String, String> pair : m_sourceTargetPairs) {
            List<CmsPair<CmsResource, CmsResource>> matchingResources = getMatchingResources(
                pair.getFirst(),
                pair.getSecond());
            allMatchingResources.addAll(matchingResources);
        }
        for (CmsPair<CmsResource, CmsResource> resPair : allMatchingResources) {
            CmsResource source = resPair.getFirst();
            CmsResource target = resPair.getSecond();
            m_translationsById.put(source.getStructureId(), target);
            m_translationsByPath.put(source.getRootPath(), target);
        }
    }
1126165
void initXmlReader() throws SAXException {
        if (parserMap.containsKey(ATTR_FORMAT_VALUE_DITA)) {
            reader = XMLReaderFactory.createXMLReader(parserMap.get(ATTR_FORMAT_VALUE_DITA));
            final Map<String, Boolean> features = parserFeatures.getOrDefault(ATTR_FORMAT_VALUE_DITA, emptyMap());
            for (final Map.Entry<String, Boolean> feature : features.entrySet()) {
                try {
                    reader.setFeature(feature.getKey(), feature.getValue());
                } catch (final SAXNotRecognizedException e) {
                    // Not Xerces, ignore exception
                }
            }
        } else {
            reader = XMLUtils.getXMLReader();
        }

        reader.setFeature(FEATURE_NAMESPACE_PREFIX, true);
        if (validate) {
            reader.setFeature(FEATURE_VALIDATION, true);
            try {
                reader.setFeature(FEATURE_VALIDATION_SCHEMA, true);
            } catch (final SAXNotRecognizedException e) {
                // Not Xerces, ignore exception
            }
        }
        if (gramcache) {
            final XMLGrammarPool grammarPool = GrammarPoolManager.getGrammarPool();
            try {
                reader.setProperty(FEATURE_GRAMMAR_POOL, grammarPool);
                logger.info("Using Xerces grammar pool for DTD and schema caching.");
            } catch (final NoClassDefFoundError e) {
                logger.debug("Xerces not available, not using grammar caching");
            } catch (final SAXNotRecognizedException | SAXNotSupportedException e) {
                logger.warn("Failed to set Xerces grammar pool for parser: " + e.getMessage());
            }
        }

        CatalogUtils.setDitaDir(ditaDir);
        reader.setEntityResolver(CatalogUtils.getCatalogResolver());
    }
221606
public static void initialize(CmsObject cms) throws CmsException {

        OpenCms.getRoleManager().checkRole(cms, CmsRole.ADMINISTRATOR);
        try {
            // store the Admin cms to index Cms resources
            m_adminCms = OpenCms.initCmsObject(cms);
            m_adminCms.getRequestContext().setSiteRoot("");
        } catch (CmsException e) {
            // this should never happen
        }
    }
374892
protected void scanJspConfig() throws IOException, SAXException {
        JspConfigDescriptor jspConfigDescriptor = context.getJspConfigDescriptor();
        if (jspConfigDescriptor == null) {
            return;
        }

        Collection<TaglibDescriptor> descriptors = jspConfigDescriptor.getTaglibs();
        for (TaglibDescriptor descriptor : descriptors) {
            if (descriptor == null) {
                continue;
            }
            String taglibURI = descriptor.getTaglibURI();
            String resourcePath = descriptor.getTaglibLocation();
            // Note: Whilst the Servlet 2.4 DTD implies that the location must
            // be a context-relative path starting with '/', JSP.7.3.6.1 states
            // explicitly how paths that do not start with '/' should be
            // handled.
            if (!resourcePath.startsWith("/")) {
                resourcePath = WEB_INF + resourcePath;
            }
            if (uriTldResourcePathMap.containsKey(taglibURI)) {
                LOG.warn(Localizer.getMessage(MSG + ".webxmlSkip", resourcePath, taglibURI));
                continue;
            }

            if (LOG.isTraceEnabled()) {
                LOG.trace(Localizer.getMessage(MSG + ".webxmlAdd", resourcePath, taglibURI));
            }

            URL url = context.getResource(resourcePath);
            if (url != null) {
                TldResourcePath tldResourcePath;
                if (resourcePath.endsWith(".jar")) {
                    // if the path points to a jar file, the TLD is presumed to
                    // be
                    // inside at META-INF/taglib.tld
                    tldResourcePath = new TldResourcePath(url, resourcePath, "META-INF/taglib.tld");
                } else {
                    tldResourcePath = new TldResourcePath(url, resourcePath);
                }
                // parse TLD but store using the URI supplied in the descriptor
                TaglibXml tld = tldParser.parse(tldResourcePath);
                uriTldResourcePathMap.put(taglibURI, tldResourcePath);
                tldResourcePathTaglibXmlMap.put(tldResourcePath, tld);
                if (tld.getListeners() != null) {
                    listeners.addAll(tld.getListeners());
                }
            } else {
                LOG.warn(Localizer.getMessage(MSG + ".webxmlFailPathDoesNotExist", resourcePath, taglibURI));
                continue;
            }
        }
    }
273802
public void fromXML(File file) throws DocumentException
    {
        SAXReader reader = new SAXReader();
        fromXML(reader.read(file));

    }
247054
protected CmsPair<String, String> decode(CmsFile file) throws CmsException {

        String content = null;
        String encoding = getConfiguredEncoding(m_cms, file);
        I_CmsResourceType resType = OpenCms.getResourceManager().getResourceType(file.getTypeId());
        if (resType instanceof CmsResourceTypeJsp) {
            content = decode(file.getContents(), encoding);
        } else {
            try {
                CmsXmlEntityResolver resolver = new CmsXmlEntityResolver(m_cms);
                // parse the XML and serialize it back to  a string with the configured encoding
                Document doc = CmsXmlUtils.unmarshalHelper(file.getContents(), resolver);
                content = CmsXmlUtils.marshal(doc, encoding);
            } catch (Exception e) {
                // invalid xml structure, just use the configured encoding
                content = decode(file.getContents(), encoding);
            }
        }
        return CmsPair.create(content, encoding);
    }
732406
private void mergePageFile(String resourcename) throws CmsXmlException, CmsImportExportException {

        try {

            if (LOG.isDebugEnabled()) {
                LOG.debug(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_START_MERGING_1, resourcename));
            }

            // in OpenCms versions <5 node names have not been case sensitive. thus, nodes are read both in upper
            // and lower case letters, or have to be tested for equality ignoring upper/lower case...

            // get the header file
            CmsFile pagefile = m_cms.readFile(resourcename, CmsResourceFilter.ALL);
            Document contentXml = CmsXmlUtils.unmarshalHelper(pagefile.getContents(), null);

            // get the <masterTemplate> node to check the content. this node contains the name of the template file.
            String masterTemplateNodeName = "//masterTemplate";
            Node masterTemplateNode = contentXml.selectSingleNode(masterTemplateNodeName);
            if (masterTemplateNode == null) {
                masterTemplateNode = contentXml.selectSingleNode(masterTemplateNodeName.toLowerCase());
            }
            if (masterTemplateNode == null) {
                masterTemplateNode = contentXml.selectSingleNode(masterTemplateNodeName.toUpperCase());
            }

            // there is only one <masterTemplate> allowed
            String mastertemplate = null;
            if (masterTemplateNode != null) {
                // get the name of the mastertemplate
                mastertemplate = masterTemplateNode.getText().trim();
            }

            // get the <ELEMENTDEF> nodes to check the content.
            // this node contains the information for the body element.
            String elementDefNodeName = "//ELEMENTDEF";
            Node bodyNode = contentXml.selectSingleNode(elementDefNodeName);
            if (bodyNode == null) {
                bodyNode = contentXml.selectSingleNode(elementDefNodeName.toLowerCase());
            }

            // there is only one <ELEMENTDEF> allowed
            if (bodyNode != null) {

                String bodyclass = null;
                String bodyname = null;
                Map<String, String> bodyparams = null;

                List<Element> nodes = ((Element)bodyNode).elements();
                for (int i = 0, n = nodes.size(); i < n; i++) {

                    Node node = nodes.get(i);

                    if ("CLASS".equalsIgnoreCase(node.getName())) {
                        bodyclass = node.getText().trim();
                    } else if ("TEMPLATE".equalsIgnoreCase(node.getName())) {
                        bodyname = node.getText().trim();
                        if (!bodyname.startsWith("/")) {
                            bodyname = CmsResource.getFolderPath(resourcename) + bodyname;
                        }
                    } else if ("PARAMETER".equalsIgnoreCase(node.getName())) {
                        Element paramElement = (Element)node;
                        if (bodyparams == null) {
                            bodyparams = new HashMap<String, String>();
                        }
                        bodyparams.put((paramElement.attribute("name")).getText(), paramElement.getTextTrim());
                    }
                }

                if ((mastertemplate == null) || (bodyname == null)) {

                    CmsMessageContainer message = Messages.get().container(
                        Messages.ERR_IMPORTEXPORT_ERROR_CANNOT_MERGE_PAGE_FILE_3,
                        resourcename,
                        mastertemplate,
                        bodyname);
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(message.key());
                    }

                    throw new CmsImportExportException(message);
                }

                // lock the resource, so that it can be manipulated
                m_cms.lockResource(resourcename);

                // get all properties
                List<CmsProperty> properties = m_cms.readPropertyObjects(resourcename, false);

                // now get the content of the bodyfile and insert it into the control file
                CmsFile bodyfile = m_cms.readFile(bodyname, CmsResourceFilter.IGNORE_EXPIRATION);

                //get the encoding
                String encoding = CmsProperty.get(
                    CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING,
                    properties).getValue();
                if (encoding == null) {
                    encoding = OpenCms.getSystemInfo().getDefaultEncoding();
                }

                if (m_convertToXmlPage) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_START_CONVERTING_TO_XML_0));
                    }

                    CmsXmlPage xmlPage = CmsXmlPageConverter.convertToXmlPage(
                        m_cms,
                        bodyfile.getContents(),
                        getLocale(resourcename, properties),
                        encoding);

                    if (LOG.isDebugEnabled()) {
                        LOG.debug(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_END_CONVERTING_TO_XML_0));
                    }

                    if (xmlPage != null) {
                        pagefile.setContents(xmlPage.marshal());

                        // set the type to xml page
                        pagefile.setType(CmsResourceTypeXmlPage.getStaticTypeId());
                    }
                }

                // add the template and other required properties
                CmsProperty newProperty = new CmsProperty(
                    CmsPropertyDefinition.PROPERTY_TEMPLATE,
                    mastertemplate,
                    null);
                // property lists must not contain equal properties
                properties.remove(newProperty);
                properties.add(newProperty);

                // if set, add the bodyclass as property
                if (CmsStringUtil.isNotEmpty(bodyclass)) {
                    newProperty = new CmsProperty(CmsPropertyDefinition.PROPERTY_TEMPLATE, mastertemplate, null);
                    newProperty.setAutoCreatePropertyDefinition(true);
                    properties.remove(newProperty);
                    properties.add(newProperty);
                }
                // if set, add bodyparams as properties
                if (bodyparams != null) {
                    for (Iterator<Entry<String, String>> p = bodyparams.entrySet().iterator(); p.hasNext();) {
                        Entry<String, String> entry = p.next();
                        String key = entry.getKey();
                        String value = entry.getValue();
                        newProperty = new CmsProperty(key, value, null);
                        newProperty.setAutoCreatePropertyDefinition(true);
                        properties.remove(newProperty);
                        properties.add(newProperty);
                    }
                }

                if (LOG.isDebugEnabled()) {
                    LOG.debug(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_START_IMPORTING_XML_PAGE_0));
                }

                // now import the resource
                m_cms.importResource(resourcename, pagefile, pagefile.getContents(), properties);

                // finally delete the old body file, it is not needed anymore
                m_cms.lockResource(bodyname);
                m_cms.deleteResource(bodyname, CmsResource.DELETE_PRESERVE_SIBLINGS);

                if (LOG.isDebugEnabled()) {
                    LOG.debug(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_END_IMPORTING_XML_PAGE_0));
                }

                m_report.println(
                    org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
                    I_CmsReport.FORMAT_OK);

            } else {

                // there are more than one template nodes in this control file
                // convert the resource into a plain text file
                // lock the resource, so that it can be manipulated
                m_cms.lockResource(resourcename);
                // set the type to plain
                pagefile.setType(CmsResourceTypePlain.getStaticTypeId());
                // write all changes
                m_cms.writeFile(pagefile);
                // done, unlock the resource
                m_cms.unlockResource(resourcename);

                if (LOG.isDebugEnabled()) {
                    LOG.debug(
                        Messages.get().getBundle().key(
                            Messages.LOG_IMPORTEXPORT_CANNOT_CONVERT_XML_STRUCTURE_1,
                            resourcename));
                }

                m_report.println(Messages.get().container(Messages.RPT_NOT_CONVERTED_0), I_CmsReport.FORMAT_OK);

            }

            if (LOG.isDebugEnabled()) {
                LOG.debug(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_END_MERGING_1, resourcename));
            }
        } catch (CmsXmlException e) {

            throw e;
        } catch (CmsException e) {

            m_report.println(e);

            CmsMessageContainer message = Messages.get().container(
                Messages.ERR_IMPORTEXPORT_ERROR_MERGING_PAGE_FILE_1,
                resourcename);
            if (LOG.isDebugEnabled()) {
                LOG.debug(message.key(), e);
            }

            throw new CmsImportExportException(message, e);
        }

    }
130315
private void loadConfiguration() {

        CmsRpcAction<CmsGalleryConfiguration> action = new CmsRpcAction<CmsGalleryConfiguration>() {

            @Override
            public void execute() {

                start(200, false);
                m_galleryService.getAdeViewModeConfiguration(this);
            }

            @Override
            protected void onResponse(CmsGalleryConfiguration result) {

                stop(false);
                if (result.getReferencePath() == null) {
                    result.setReferencePath(CmsCoreProvider.get().getUri());
                }
                openDialog(result);

            }
        };
        if (m_dialog != null) {
            openDialog(null);
        } else {
            action.execute();
        }

    }
743357
public void load() throws IOException, JAXBException
    {
        Unmarshaller unmarshaller = jaxbCtx.createUnmarshaller();
        content =  (JAXBElement<T>) unmarshaller.unmarshal(url);
    }