📄 a_cmschannelbackoffice.java
字号:
posInt=CmsDbUtil.UNKNOWN_ID;
}
}
// get the media_position
String media_position = (String) parameters.get("media_position");
media_position=(media_position!=null?media_position.trim():"");
int media_positionInt=0;
if (!media_position.equals("")) {
try {
media_positionInt=Integer.parseInt(media_position);
} catch (Exception e) {
media_positionInt=0;
}
}
//the media_type
int media_type=0;
//the media_mimetype
String media_mimetype="";
//media content definition
CmsMasterMedia mediaCD=null;
//selected media content definition
CmsMasterMedia selectedmediaCD=null;
//get all media files from this content definition
Vector dbmedia = masterCD.getMedia();
//Vector
Vector media = null;
//try to get the medias from session
try {
media=(Vector)session.getValue("media");
} catch (Exception e) {
e.printStackTrace(System.err);
}
//get the selected CmsMasterMedia
if (dbmedia!=null) {
//if you are here for the fist time - get the medias from db
if (media==null) {
//copy medias in your vector
media=new Vector();
//media=(Vector)dbmedia.clone();
for (int i=0; i<dbmedia.size(); i++) {
CmsMasterMedia cd = (CmsMasterMedia)dbmedia.elementAt(i);
//if the type is == paragraph1
if (cd.getType()>=0) {
media.add(cd);
}
}
}
for (int i=0; i<media.size(); i++) {
if (posInt==i) {
selectedmediaCD=(CmsMasterMedia)media.elementAt(i);
}
}
}
//delete media
if (media_action.equals("delPicture")) {
if (selectedmediaCD!=null) {
masterCD.deleteMedia(selectedmediaCD);
//remove CD from vector
media.removeElementAt(posInt);
}
} else if (media_action.equals("addPicture") && !media_name.equals("unknown")) {
// get the picture file and/or file from the RequestContext if there is any
CmsRequestContext reqCont = cms.getRequestContext();
Enumeration en = CmsXmlTemplateLoader.getRequest(reqCont).getFileNames();
String filename = "";
byte[] mediafile = null;
//get the file
while (en.hasMoreElements()) {
filename = (String) en.nextElement();
if (!filename.equals("unknown")) {
mediafile = CmsXmlTemplateLoader.getRequest(reqCont).getFile(filename);
//set the media_mimetype
media_mimetype = OpenCms.getResourceManager().getMimeType(filename, null);
//set the type
if (!media_mimetype.startsWith("image")) {
media_type=1;
}
}
}
if (mediafile!=null) {
//new media
mediaCD=new CmsMasterMedia(media_positionInt, 0, 0, mediafile.length, media_mimetype, media_type, media_title, media_name, "default", mediafile);
if (mediaCD!=null) {
//add media
masterCD.addMedia(mediaCD);
//add Cd to vector
media.addElement(mediaCD);
//set media_position back to default
media_position="";
}
} else {
//set new values
selectedmediaCD.setName(media_name);
selectedmediaCD.setTitle(media_title);
selectedmediaCD.setPosition(media_positionInt);
//set media_position back to default
media_position="";
//update media
masterCD.updateMedia(selectedmediaCD);
//update the vector
media.insertElementAt(selectedmediaCD, posInt);
//remove old CD
media.removeElementAt(posInt+1);
}
}
//empty the input fields and select box
if (media_action.equals("clear")) {
//set media_position back to default
media_position="";
}
//open window on reload
if (media_action.equals("prevPicture") && (selectedmediaCD != null)) {
//set the url
templateFile.setData("sid", "" + masterCD.getSubId());
templateFile.setData("cid", "" + selectedmediaCD.getMasterId());
templateFile.setData("mid", "" + selectedmediaCD.getId());
templateFile.setData("file", "" + selectedmediaCD.getName());
templateFile.setData("preview", templateFile.getProcessedDataValue("media_preview", this));
} else {
//set the url to default
templateFile.setData("preview", "");
}
//special template for edit
if (media_action.equals("editPicture") && (selectedmediaCD!=null)) {
//set media_position back to default
media_position=""+selectedmediaCD.getPosition();
//put the media_position in session
session.putValue("media_position", media_position);
//fill the template
templateFile.setData("media_name", selectedmediaCD.getName());
templateFile.setData("posEdit", pos);
String title=selectedmediaCD.getTitle();
title=org.opencms.i18n.CmsEncoder.unescape(title,
cms.getRequestContext().getEncoding());
templateFile.setData("media_alt_text", title);
templateFile.setData("media_file", templateFile.getProcessedDataValue("media_edit", this));
} else {
//put the media_position in session
session.putValue("media_position", media_position);
//no edit - build normal template
templateFile.setData("media_file", templateFile.getProcessedDataValue("media_upload", this));
}
//fill the list
if (media!=null) {
//content of the position select box
String selectBoxContent="";
try {
//get the content
selectBoxContent=selectBoxContent(cms);
} catch (Exception e) {
}
for (int i=0; i<media.size(); i++) {
mediaCD= (CmsMasterMedia)media.elementAt(i);
templateFile.setData("pos", ""+i);
templateFile.setData("media_row_name", mediaCD.getName());
templateFile.setData("media_title", mediaCD.getTitle());
//get the name to the value
String mediapos=""+mediaCD.getPosition();
StringTokenizer t = new StringTokenizer(selectBoxContent, ";");
while (t.hasMoreElements()) {
String s=t.nextToken();
if (s!=null && !s.equals("")) {
int z=s.indexOf(":");
String value=s.substring(0, z);
String name=s.substring(z+1);
if (mediapos.equals(name)) {
mediapos=value;
}
}
}
templateFile.setData("media_position", ""+mediapos);
templateFile.setData("media_size", ""+mediaCD.getSize());
templateFile.setData("media_type", ""+mediaCD.getType());
//set String
row += templateFile.getProcessedDataValue("media_row", this);
//set back
mediapos="";
}
templateFile.setData("media_line", row);
}
//build the content
content=templateFile.getProcessedDataValue("media_content", this);
//put the vector in session
if (media!=null) {
session.putValue("media", media);
}
//put the vector in session
if (selectedmediaCD!=null) {
session.putValue("selectedmediaCD", selectedmediaCD);
}
//return
return content;
}
/**
* Method to return option values for media-position selectbox
* has to be overriden to provide values and names for the selectbox
*
* @param cms CmsObject to access system resources
* @return the option values
*/
protected String selectBoxContent(CmsObject cms) {
return "";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -