001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.model;
016    
017    import com.liferay.portal.kernel.security.pacl.DoPrivileged;
018    import com.liferay.portal.kernel.util.PropsKeys;
019    import com.liferay.portal.kernel.util.StringUtil;
020    import com.liferay.portal.security.xml.SecureXMLFactoryProvider;
021    import com.liferay.portal.security.xml.SecureXMLFactoryProviderUtil;
022    import com.liferay.portal.service.ClassNameLocalServiceUtil;
023    import com.liferay.portal.util.PropsUtil;
024    import com.liferay.portal.util.PropsValues;
025    import com.liferay.portal.xml.SAXReaderFactory;
026    
027    import org.dom4j.io.SAXReader;
028    
029    /**
030     * @author Raymond Aug??
031     */
032    @DoPrivileged
033    public class DefaultModelHintsImpl extends BaseModelHintsImpl {
034    
035            @Override
036            public ModelHintsCallback getModelHintsCallback() {
037                    return _modelHintsCallback;
038            }
039    
040            @Override
041            public String[] getModelHintsConfigs() {
042                    return _modelHintsConfigs;
043            }
044    
045            @Override
046            public SAXReader getSAXReader() {
047                    SecureXMLFactoryProvider secureXMLFactoryProvider =
048                            SecureXMLFactoryProviderUtil.getSecureXMLFactoryProvider();
049    
050                    return SAXReaderFactory.getSAXReader(
051                            secureXMLFactoryProvider.newXMLReader(),
052                            PropsValues.XML_VALIDATION_ENABLED, false);
053            }
054    
055            public class RuntimeModelHintsCallback implements ModelHintsCallback {
056    
057                    @Override
058                    public void execute(ClassLoader classLoader, String name) {
059                            if (classLoader != BaseModelHintsImpl.class.getClassLoader()) {
060                                    ClassNameLocalServiceUtil.getClassName(name);
061                            }
062                    }
063    
064            }
065    
066            private final ModelHintsCallback _modelHintsCallback =
067                    new RuntimeModelHintsCallback();
068            private final String[] _modelHintsConfigs = StringUtil.split(
069                    PropsUtil.get(PropsKeys.MODEL_HINTS_CONFIGS));
070    
071    }