use of org.compiere.model.MMedia in project adempiere by adempiere.
the class WebProjectDeploy method doIt.
// prepare
/**
* Process
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
org.compiere.cm.CacheHandler thisHandler = new org.compiere.cm.CacheHandler(org.compiere.cm.CacheHandler.convertJNPURLToCacheURL(getCtx().getProperty("java.naming.provider.url")), log, getCtx(), get_TrxName());
log.info("CM_WebProject_ID=" + p_CM_WebProject_ID);
m_project = new MWebProject(getCtx(), p_CM_WebProject_ID, get_TrxName());
if (m_project.get_ID() != p_CM_WebProject_ID)
throw new AdempiereUserError("@NotFound@ @CM_WebProject_ID@ " + p_CM_WebProject_ID);
// Deploy Media
MMedia[] media = MMedia.getMedia(m_project);
MMediaServer[] mserver = MMediaServer.getMediaServer(m_project);
for (int i = 0; i < mserver.length; i++) mserver[i].deploy(media);
// Stage
MCStage[] stages = MCStage.getStages(m_project);
for (int i = 0; i < stages.length; i++) m_map.put(new Integer(stages[i].getCM_CStage_ID()), stages[i]);
// Copy Stage Tree
MTree treeS = new MTree(getCtx(), m_project.getAD_TreeCMS_ID(), false, false, get_TrxName());
MTreeNode root = treeS.getRoot();
copyStage(root, "/");
// Delete Inactive Containers
MContainer[] containers = MContainer.getContainers(m_project);
for (int i = 0; i < containers.length; i++) {
MContainer container = containers[i];
if (!m_idList.contains(new Integer(container.getCM_Container_ID()))) {
String name = container.getName();
if (container.delete(true))
log.fine("Deleted: " + name);
else // e.g. was referenced
{
log.warning("Failed Delete: " + name);
addLog(0, null, null, "@Error@ @Delete@: " + name);
}
}
// Remove Container from cache
thisHandler.cleanContainer(container.get_ID());
}
// Delete Inactive
// Sync Stage & Container Tree
MTree_NodeCMS[] nodesCMS = MTree_NodeCMS.getTree(getCtx(), m_project.getAD_TreeCMS_ID(), get_TrxName());
MTree_NodeCMC[] nodesCMC = MTree_NodeCMC.getTree(getCtx(), m_project.getAD_TreeCMC_ID(), get_TrxName());
for (int s = 0; s < nodesCMS.length; s++) {
MTree_NodeCMS nodeCMS = nodesCMS[s];
int Node_ID = nodeCMS.getNode_ID();
for (int c = 0; c < nodesCMC.length; c++) {
MTree_NodeCMC nodeCMC = nodesCMC[c];
if (nodeCMC.getNode_ID() == Node_ID) {
//if (nodeCMS.getParent_ID()!=0)
nodeCMC.setParent_ID(nodeCMS.getParent_ID());
nodeCMC.setSeqNo(nodeCMS.getSeqNo());
nodeCMC.saveEx();
break;
}
}
}
// for all stage nodes
// Clean ContainerTree Cache
thisHandler.cleanContainerTree(p_CM_WebProject_ID);
return "@Copied@ @CM_Container_ID@ #" + m_idList.size();
}
use of org.compiere.model.MMedia in project adempiere by adempiere.
the class MediaBroadcast method doGet.
/**
* Process the HTTP Get request
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Create New Session
HttpSession sess = request.getSession(true);
sess.setMaxInactiveInterval(WebEnv.TIMEOUT);
if (configLoaded && !fatalError) {
String requestURL = request.getRequestURL().toString();
String serverName = request.getServerName();
String baseURL = requestURL.substring(0, requestURL.indexOf(serverName) + serverName.length() + 6) + request.getContextPath();
String relativeURL = requestURL.substring(baseURL.length());
// If the relativeURL still contains / we will simply strip them off...
if (relativeURL.indexOf('/') >= 0)
relativeURL = relativeURL.substring(relativeURL.lastIndexOf('/') + 1);
// We should have only an ID before the first dot.
Integer mediaID = null;
try {
if (relativeURL.indexOf('.') >= 0) {
mediaID = Integer.parseInt(relativeURL.substring(0, relativeURL.indexOf('.')));
} else {
mediaID = Integer.parseInt(relativeURL);
}
} catch (NumberFormatException ne) {
}
if (mediaID != null && mediaID.intValue() > 0) {
MMedia thisMedia = new org.compiere.model.MMedia(webProjectCache.getCtx(), mediaID, null);
if (thisMedia != null && thisMedia.get_ID() > 0) {
if (thisMedia.getMediaType().equals("CSS")) {
response.setContentType("text/css");
// Text Content will get handled via direct Stream
response.setContentLength(thisMedia.getContentText().length());
PrintWriter out;
out = response.getWriter();
out.print(thisMedia.getContentText());
out.close();
} else {
response.setContentType(thisMedia.getMediaType());
// Binary / Image content will get handled here
MImage thisImage = thisMedia.getImage();
if (thisImage != null) {
response.setContentLength(thisImage.getData().length);
// Open the file and output streams
byte[] buffer = thisImage.getData();
ByteArrayInputStream in = new ByteArrayInputStream(buffer);
OutputStream out = response.getOutputStream();
// Copy the contents of the file to the output stream
byte[] buf = new byte[1024];
int count = 0;
while ((count = in.read(buf)) >= 0) {
out.write(buf, 0, count);
}
in.close();
out.close();
}
}
} else {
response.sendError(404);
}
} else {
response.sendError(404);
}
} else if (fatalError) {
response.sendError(500, ErrorMessage);
}
}
Aggregations