📄 cmsdbaccess.java
字号:
dataset.m_lastModifiedBy = new CmsUUID(res.getString(i++));
dataset.m_dateCreated = res.getTimestamp(i++).getTime();
dataset.m_dateLastModified = res.getTimestamp(i++).getTime();
//// USERDATA ////
dataset.m_publicationDate = res.getTimestamp(i++).getTime();
dataset.m_purgeDate = res.getTimestamp(i++).getTime();
dataset.m_flags = res.getInt(i++);
dataset.m_feedId = res.getInt(i++);
dataset.m_feedReference = res.getInt(i++);
dataset.m_feedFilename = res.getString(i++);
dataset.m_title = res.getString(i++);
//// GENERIC DATA ////
i = sqlSetTextArray(res, dataset.m_dataBig, i);
i = sqlSetTextArray(res, dataset.m_dataMedium, i);
i = sqlSetTextArray(res, dataset.m_dataSmall, i);
i = sqlSetIntArray(res, dataset.m_dataInt, i);
i = sqlSetIntArray(res, dataset.m_dataReference, i);
i = sqlSetDateArray(res, dataset.m_dataDate, i);
return i;
}
/**
* Computes the correct project id based on the current user and the channels.<p>
*
* @param cms the CmsObject
* @param dataset the dataSet
* @return int the project id
* @throws SQLException if something goes wrong
*/
protected int computeProjectId(CmsObject cms, CmsMasterDataSet dataset) throws SQLException {
//int onlineProjectId = I_CmsConstants.UNKNOWN_ID;
int offlineProjectId = CmsDbUtil.UNKNOWN_ID;
offlineProjectId = cms.getRequestContext().currentProject().getId();
//onlineProjectId = I_CmsConstants.ONLINE_PROJECT_ID;
if (!isOnlineProject(cms)) {
// this is an offline project -> compute if we have to return the
// online project id or the offline project id
// the owner and the administrtor has always access
if ((cms.getRequestContext().currentUser().getId().equals(dataset.m_userId)) || cms.isAdmin()) {
return offlineProjectId;
}
return offlineProjectId;
// DISABLED: always return current offline project ID!
// String statement_key = "read_channel_offline";
//
// PreparedStatement stmt = null;
// ResultSet res = null;
// Connection conn = null;
// cms.getRequestContext().saveSiteRoot();
// try {
// cms.setContextToCos();
// conn = m_sqlManager.getConnection();
// stmt = m_sqlManager.getPreparedStatement(conn, statement_key);
// stmt.setString(1, dataset.m_masterId.toString());
// res = stmt.executeQuery();
// while (res.next()) {
// // get the channel id
// String channelId = res.getString(1);
// // read the resource by property "channelid"
// CmsFolder channelFolder = null;
// try {
// channelFolder = cms.readFolder(new CmsUUID(channelId), false);
// //resources = cms.getResourcesWithPropertyDefintion(I_CmsConstants.C_PROPERTY_CHANNELID, channelId + "", CmsResourceTypeFolder.C_RESOURCE_TYPE_ID);
// } catch (CmsException exc) {
// // ignore the exception - read the next one
// }
// if (channelFolder != null) {
// int resProjectId = channelFolder.getProjectLastModified();
// if (resProjectId == offlineProjectId) {
// // yes - we have found a channel that belongs to
// // the current offlineproject -> we can return the
// // offline project id as computed project id
// return offlineProjectId;
// }
// }
// }
// } finally {
// cms.getRequestContext().restoreSiteRoot();
// m_sqlManager.closeAll(conn, stmt, res);
// }
}
// no channel found that belongs to the offlineproject ->
// return the online project id.
return offlineProjectId;
}
/**
* Sets an array of strings into the statement.<p>
*
* @param stmt the PreparedStatement to set the values into.
* @param array the array of strings to set.
* @param the columnscounter for the statement.
* @return the increased columnscounter;
*/
protected int sqlSetTextArray(PreparedStatement stmt, String[] array, int columnscounter) throws SQLException {
for (int j = 0; j < array.length; j++) {
if (array[j] == null) {
stmt.setNull(columnscounter++, Types.LONGVARCHAR);
} else {
stmt.setString(columnscounter++, array[j]);
}
}
return columnscounter;
}
/**
* Sets an array of strings from the resultset.<p>
*
* @param res the ResultSet to get the values from.
* @param array the array of strings to set.
* @param the columnscounter for the res.
* @return the increased columnscounter;
*/
protected int sqlSetTextArray(ResultSet res, String[] array, int columnscounter) throws SQLException {
for (int j = 0; j < array.length; j++) {
array[j] = res.getString(columnscounter++);
}
return columnscounter;
}
/**
* Sets an array of ints into the statement.<p>
*
* @param stmt the PreparedStatement to set the values into.
* @param array the array of ints to set.
* @param the columnscounter for the stmnt.
* @return the increased columnscounter;
*/
protected int sqlSetIntArray(PreparedStatement stmt, int[] array, int columnscounter) throws SQLException {
for (int j = 0; j < array.length; j++) {
stmt.setInt(columnscounter++, array[j]);
}
return columnscounter;
}
/**
* Sets an array of ints from the resultset.<p>
*
* @param res the ResultSet to get the values from.
* @param array the array of ints to set.
* @param the columnscounter for the res.
* @return the increased columnscounter;
*/
protected int sqlSetIntArray(ResultSet res, int[] array, int columnscounter) throws SQLException {
for (int j = 0; j < array.length; j++) {
array[j] = res.getInt(columnscounter++);
}
return columnscounter;
}
/**
* Sets an array of longs (dates) into the statement.<p>
*
* @param stmt the PreparedStatement to set the values into.
* @param array the array of longs to set.
* @param the columnscounter for the stmnt.
* @return the increased columnscounter;
*/
protected int sqlSetDateArray(PreparedStatement stmt, long[] array, int columnscounter) throws SQLException {
for (int j = 0; j < array.length; j++) {
stmt.setTimestamp(columnscounter++, new Timestamp(array[j]));
}
return columnscounter;
}
/**
* Sets an array of longs (dates) from the resultset.<p>
*
* @param res the ResultSet to get the values from.
* @param array the array of longs to set.
* @param the columnscounter for the res.
* @return the increased columnscounter;
*/
protected int sqlSetDateArray(ResultSet res, long[] array, int columnscounter) throws SQLException {
for (int j = 0; j < array.length; j++) {
array[j] = res.getTimestamp(columnscounter++).getTime();
}
return columnscounter;
}
/**
* Returns a vector of contentdefinitions based on the sql resultset.
* Never mind about the visible flag.<p>
*
* @param res the ResultSet to get data lines from.
* @param contentDefinitionClass the class of the cd to create new instances.
* @param cms the CmsObject to get access to cms resources.
* @throws SqlException if nothing could be read from the resultset.
*/
protected Vector createVectorOfCd(ResultSet res, Class contentDefinitionClass, CmsObject cms) throws SQLException {
return createVectorOfCd(res, contentDefinitionClass, cms, false);
}
/**
* Returns a vector of contentdefinitions based on the sql resultset.<p>
*
* @param res the ResultSet to get data-lines from.
* @param contentDefinitionClass the class of the cd to create new instances.
* @param cms the CmsObject to get access to cms resources.
* @param viewonly decides, if only the ones that are visible should be returned
* @throws SqlException if nothing could be read from the resultset.
*/
protected Vector createVectorOfCd(ResultSet res, Class contentDefinitionClass, CmsObject cms, boolean viewonly) throws SQLException {
Constructor constructor;
Vector retValue = new Vector();
try { // to get the constructor to create an empty contentDefinition
constructor = contentDefinitionClass.getConstructor(new Class[] { CmsObject.class, CmsMasterDataSet.class });
} catch (NoSuchMethodException exc) {
if (CmsLog.getLog(this).isWarnEnabled()) {
CmsLog.getLog(this).warn("Cannot locate constructor", exc);
}
// canno't fill the vector - missing constructor
return retValue;
}
while (res.next()) { // while there is data in the resultset
CmsMasterDataSet dataset = new CmsMasterDataSet();
try { // to invoce the constructor to get a new empty instance
CmsMasterContent content = (CmsMasterContent)constructor.newInstance(new Object[] { cms, dataset });
sqlFillValues(res, cms, dataset);
// add the cd only if read (and visible) permissions are granted.
// the visible-permissens will be checked, if viewonly is set to true
// viewonly=true is needed for the backoffice
if (checkAccess(content, viewonly)) {
retValue.add(content);
}
} catch (Exception exc) {
if (CmsLog.getLog(this).isWarnEnabled()) {
CmsLog.getLog(this).warn("Cannot invoce constructor", exc);
}
}
}
return retValue;
}
/**
* Returns a vector of contentdefinitions based on the sql resultset.<p>
*
* @param datasets the vector with the datasets.
* @param contentDefinitionClass the class of the cd to create new instances.
* @param cms the CmsObject to get access to cms-ressources.
* @throws SqlException if nothing could be read from the resultset.
*/
protected Vector createVectorOfCd(Vector datasets, Class contentDefinitionClass, CmsObject cms) throws SQLException {
Constructor constructor;
Vector retValue = new Vector();
try { // to get the constructor to create an empty contentDefinition
constructor = contentDefinitionClass.getConstructor(new Class[] { CmsObject.class, CmsMasterDataSet.class });
} catch (NoSuchMethodException exc) {
if (CmsLog.getLog(this).isWarnEnabled()) {
CmsLog.getLog(this).warn("Cannot locate constructor", exc);
}
// canno't fill the vector - missing constructor
return retValue;
}
// create content definition for each dataset
for (int i = 0; i < datasets.size(); i++) {
CmsMasterDataSet dataset = (CmsMasterDataSet)datasets.elementAt(i);
try { // to invoce the constructor to get a new empty instance
CmsMasterContent content = (CmsMasterContent)constructor.newInstance(new Object[] { cms, dataset });
retValue.add(content);
} catch (Exception exc) {
if (CmsLog.getLog(this).isWarnEnabled()) {
CmsLog.getLog(this).warn("Cannot invoce constructor", exc);
}
}
}
return retValue;
}
/**
* Checks if read (and visible) permissions are granted.
* the visible permissions will be checked, if viewonly is set to true
* viewonly=true is needed for the backoffice.<p>
*
* @param content the cd to check.
* @param viewonly if set to true the v-Flag will be checked, too.
*/
protected boolean checkAccess(CmsMasterContent content, boolean viewonly) {
if (!content.isReadable()) {
// was not readable
return false;
} else if (viewonly) {
// additional check for v-Flags
return content.isVisible();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -