Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2003 - 2013 The eFaps Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Revision: $Rev: 8848 $
* Last Changed: $Date: 2013-02-19 10:49:59 -0500 (Tue, 19 Feb 2013) $
* Last Changed By: $Author: [email protected] $
*/
package org.efaps.update.schema.dbproperty;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import org.apache.commons.jexl.JexlContext;
import org.efaps.admin.datamodel.Type;
import org.efaps.ci.CIAdmin;
import org.efaps.db.Insert;
import org.efaps.db.Instance;
import org.efaps.db.InstanceQuery;
import org.efaps.db.QueryBuilder;
import org.efaps.db.Update;
import org.efaps.update.IUpdate;
import org.efaps.update.Profile;
import org.efaps.update.UpdateLifecycle;
import org.efaps.update.util.InstallationException;
import org.efaps.util.EFapsException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Class for importing or updating of Properties from a properties-file into the
* Database for use as eFaps-Admin_Properties.
* The import depends on the UUID of the Bundle. That means all Keys of the
* Properties must be unique within a Bundle. Therefore the import will update a
* key, if it is already existing inside this bundle. The Bundle will always be
* identified by the UUID and not by the name.
*
* @author The eFaps Team
* @version $Id: DBPropertiesUpdate.java 8848 2013-02-19 15:49:59Z [email protected] $
*/
public class DBPropertiesUpdate
implements IUpdate
{
/**
* name for the Type.
*/
private static final String TYPE_PROPERTIES = "Admin_Common_DBProperties";
/**
* name for the Type.
*/
private static final String TYPE_PROPERTIES_BUNDLE = "Admin_Common_DBPropertiesBundle";
/**
* name for the Type.
*/
private static final String TYPE_PROPERTIES_LOCAL = "Admin_Common_DBPropertiesLocal";
/**
* Logging instance used to give logging information of this class.
*/
private static final Logger LOG = LoggerFactory.getLogger(DBPropertiesUpdate.class);
/**
* the name of the Bundle.
*/
private String bundlename;
/**
* the UUID of the Bundle.
*/
private String bundeluuid;
/**
* the ID of the Bundle.
*/
private long bundleid;
/**
* Sequence of the Bundle.
*/
private String bundlesequence;
/**
* root of the XML-file to be imported.
*/
private final String root;
/**
* List of all Resources in this Properties.
*/
private final List resources = new ArrayList();
/**
* Name of the application.
*/
private String fileApplication;
/**
* Current read source.
* @see #readXML(List, Map, String)
*/
private Resource curResource;
/**
* The URL of the underlying file.
*/
private final URL url;
/**
* @param _url url for the file
*/
public DBPropertiesUpdate(final URL _url)
{
this.url = _url;
final String urlStr = _url.toString();
this.root = urlStr.substring(0, urlStr.lastIndexOf(File.separator) + 1);
}
/**
* find out the Id of the language used for this properties.
* @param _language Language
* @return ID of the Language
*/
private Long getLanguageId(final String _language)
{
Long ret = null;
try {
final QueryBuilder queryBldr = new QueryBuilder(CIAdmin.Language);
queryBldr.addWhereAttrEqValue(CIAdmin.Language.Language, _language);
final InstanceQuery query = queryBldr.getQuery();
query.executeWithoutAccessCheck();
if (query.next()) {
ret = query.getCurrentValue().getId();
} else {
ret = insertNewLanguage(_language);
}
} catch (final EFapsException e) {
DBPropertiesUpdate.LOG.error("getLanguageId()", e);
}
return ret;
}
/**
* inserts a new language into the Database.
*
* @param _language language to be inserted
* @return ID of the new language
*/
private long insertNewLanguage(final String _language)
{
Long ret = null;
try {
final Insert insert = new Insert(CIAdmin.Language);
insert.add(CIAdmin.Language.Language, _language);
insert.executeWithoutAccessCheck();
ret = insert.getId();
insert.close();
} catch (final EFapsException e) {
DBPropertiesUpdate.LOG.error("insertNewLanguage()", e);
}
return ret;
}
/**
* Insert a new Bundle into the Database.
*
* @return ID of the new Bundle
*/
private long insertNewBundle()
{
Long ret = null;
try {
final Insert insert = new Insert(DBPropertiesUpdate.TYPE_PROPERTIES_BUNDLE);
insert.add("Name", this.bundlename);
insert.add("UUID", this.bundeluuid);
insert.add("Sequence", this.bundlesequence);
insert.executeWithoutAccessCheck();
ret = insert.getId();
insert.close();
} catch (final EFapsException e) {
DBPropertiesUpdate.LOG.error("insertNewBundle()", e);
}
return ret;
}
/**
* Import Properties from a Properties-File as default, if the key is
* already existing, the default will be replaced with the new default.
*
* @param _url Complete Path/Name of the property file to import
*/
private void importFromProperties(final URL _url)
{
try {
final InputStream propInFile = _url.openStream();
final Properties props = new Properties();
props.load(propInFile);
final Iterator> iter = props.entrySet().iterator();
while (iter.hasNext()) {
final Entry