You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by le...@apache.org on 2009/10/03 06:12:28 UTC
svn commit: r821238 -
/ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java
Author: lektran
Date: Sat Oct 3 04:12:28 2009
New Revision: 821238
URL: http://svn.apache.org/viewvc?rev=821238&view=rev
Log:
Cleaned up imports
Additional generics markup
Enhanced for loops
Fixed a comment typos
Removed an unused method variable
Modified:
ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java
Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java?rev=821238&r1=821237&r2=821238&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java Sat Oct 3 04:12:28 2009
@@ -18,7 +18,6 @@
*******************************************************************************/
package org.ofbiz.content.data;
-import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -41,6 +40,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
import javolution.util.FastList;
import javolution.util.FastMap;
@@ -49,15 +50,11 @@
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
-import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.FOPException;
-import org.apache.fop.apps.Fop;
-import org.apache.fop.apps.FopFactory;
-import org.apache.fop.apps.MimeConstants;
import org.ofbiz.base.location.FlexibleLocation;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.FileUtil;
import org.ofbiz.base.util.GeneralException;
+import org.ofbiz.base.util.UtilGenerics;
import org.ofbiz.base.util.UtilHttp;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.UtilProperties;
@@ -68,7 +65,6 @@
import org.ofbiz.base.util.template.XslTransform;
import org.ofbiz.common.email.NotificationServices;
import org.ofbiz.content.content.UploadContentAndImage;
-import org.ofbiz.content.content.ContentMapFacade;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
@@ -79,27 +75,11 @@
import org.ofbiz.widget.screen.ScreenFactory;
import org.ofbiz.widget.screen.ScreenRenderer;
import org.ofbiz.widget.screen.ScreenStringRenderer;
-import org.ofbiz.widget.screen.ScreenFopViewHandler;
-import org.ofbiz.webapp.view.ApacheFopWorker;
-import org.ofbiz.webapp.view.FopRenderer;
-
-import freemarker.template.Template;
-import freemarker.template.TemplateException;
-
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
-import com.meterware.httpunit.GetMethodWebRequest;
-
-import javax.xml.transform.Result;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.sax.SAXResult;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.parsers.ParserConfigurationException;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
/**
* DataResourceWorker Class
@@ -115,7 +95,7 @@
* @param getAll Indicates that all descendants are to be gotten. Used as "true" to populate an
* indented select list.
*/
- public static String getDataCategoryMap(GenericDelegator delegator, int depth, Map categoryNode, List categoryTypeIds, boolean getAll) throws GenericEntityException {
+ public static String getDataCategoryMap(GenericDelegator delegator, int depth, Map<String, Object> categoryNode, List<String> categoryTypeIds, boolean getAll) throws GenericEntityException {
String errorMsg = null;
String parentCategoryId = (String) categoryNode.get("id");
String currentDataCategoryId = null;
@@ -135,14 +115,14 @@
} else {
matchValue = null;
}
- List categoryValues = delegator.findByAndCache("DataCategory", UtilMisc.toMap("parentCategoryId", matchValue));
+ List<GenericValue> categoryValues = delegator.findByAndCache("DataCategory", UtilMisc.toMap("parentCategoryId", matchValue));
categoryNode.put("count", Integer.valueOf(categoryValues.size()));
- List subCategoryIds = FastList.newInstance();
+ List<Map<String, Object>> subCategoryIds = FastList.newInstance();
for (int i = 0; i < categoryValues.size(); i++) {
GenericValue category = (GenericValue) categoryValues.get(i);
String id = (String) category.get("dataCategoryId");
String categoryName = (String) category.get("categoryName");
- Map newNode = FastMap.newInstance();
+ Map<String, Object> newNode = FastMap.newInstance();
newNode.put("id", id);
newNode.put("name", categoryName);
errorMsg = getDataCategoryMap(delegator, depth + 1, newNode, categoryTypeIds, getAll);
@@ -169,7 +149,7 @@
/**
* Finds the parents of DataCategory entity and puts them in a list, the start entity at the top.
*/
- public static void getDataCategoryAncestry(GenericDelegator delegator, String dataCategoryId, List categoryTypeIds) throws GenericEntityException {
+ public static void getDataCategoryAncestry(GenericDelegator delegator, String dataCategoryId, List<String> categoryTypeIds) throws GenericEntityException {
categoryTypeIds.add(dataCategoryId);
GenericValue dataCategoryValue = delegator.findByPrimaryKey("DataCategory", UtilMisc.toMap("dataCategoryId", dataCategoryId));
if (dataCategoryValue == null)
@@ -184,28 +164,26 @@
* Takes a DataCategory structure and builds a list of maps, one value (id) is the dataCategoryId value and the other is an indented string suitable for
* use in a drop-down pick list.
*/
- public static void buildList(Map nd, List lst, int depth) {
+ public static void buildList(Map<String, Object> nd, List<Map<String, Object>> lst, int depth) {
String id = (String) nd.get("id");
String nm = (String) nd.get("name");
String spc = "";
for (int i = 0; i < depth; i++)
spc += " ";
- Map map = FastMap.newInstance();
+ Map<String, Object> map = FastMap.newInstance();
map.put("dataCategoryId", id);
map.put("categoryName", spc + nm);
if (id != null && !id.equals("ROOT") && !id.equals("")) {
lst.add(map);
}
- List kids = (List) nd.get("kids");
- int sz = kids.size();
- for (int i = 0; i < sz; i++) {
- Map kidNode = (Map) kids.get(i);
+ List<Map<String, Object>> kids = UtilGenerics.checkList(nd.get("kids"));
+ for (Map<String, Object> kidNode : kids) {
buildList(kidNode, lst, depth + 1);
}
}
/**
- * Uploads image data from a form and stores it in ImageDataResource. Expects key data in a field identitified by the "idField" value and the binary data
+ * Uploads image data from a form and stores it in ImageDataResource. Expects key data in a field identified by the "idField" value and the binary data
* to be in a field id'd by uploadField.
*/
// TODO: This method is not used and should be removed. amb
@@ -214,11 +192,11 @@
//String idFieldValue = null;
ServletFileUpload fu = new ServletFileUpload(new DiskFileItemFactory(10240, FileUtil.getFile("runtime/tmp")));
- List lst = null;
+ List<FileItem> lst = null;
Locale locale = UtilHttp.getLocale(request);
try {
- lst = fu.parseRequest(request);
+ lst = UtilGenerics.checkList(fu.parseRequest(request));
} catch (FileUploadException e) {
request.setAttribute("_ERROR_MESSAGE_", e.toString());
return "error";
@@ -235,7 +213,7 @@
FileItem fi = null;
FileItem imageFi = null;
String imageFileName = null;
- Map passedParams = FastMap.newInstance();
+ Map<String, Object> passedParams = FastMap.newInstance();
HttpSession session = request.getSession();
GenericValue userLogin = (GenericValue)session.getAttribute("userLogin");
passedParams.put("userLogin", userLogin);
@@ -300,8 +278,8 @@
/**
* callDataResourcePermissionCheck Formats data for a call to the checkContentPermission service.
*/
- public static String callDataResourcePermissionCheck(GenericDelegator delegator, LocalDispatcher dispatcher, Map context) {
- Map permResults = callDataResourcePermissionCheckResult(delegator, dispatcher, context);
+ public static String callDataResourcePermissionCheck(GenericDelegator delegator, LocalDispatcher dispatcher, Map<String, Object> context) {
+ Map<String, Object> permResults = callDataResourcePermissionCheckResult(delegator, dispatcher, context);
String permissionStatus = (String) permResults.get("permissionStatus");
return permissionStatus;
}
@@ -309,9 +287,9 @@
/**
* callDataResourcePermissionCheck Formats data for a call to the checkContentPermission service.
*/
- public static Map callDataResourcePermissionCheckResult(GenericDelegator delegator, LocalDispatcher dispatcher, Map context) {
+ public static Map<String, Object> callDataResourcePermissionCheckResult(GenericDelegator delegator, LocalDispatcher dispatcher, Map<String, Object> context) {
- Map permResults = FastMap.newInstance();
+ Map<String, Object> permResults = FastMap.newInstance();
String skipPermissionCheck = (String) context.get("skipPermissionCheck");
if (Debug.infoOn()) Debug.logInfo("in callDataResourcePermissionCheckResult, skipPermissionCheck:" + skipPermissionCheck,"");
@@ -319,7 +297,7 @@
|| skipPermissionCheck.length() == 0
|| (!skipPermissionCheck.equalsIgnoreCase("true") && !skipPermissionCheck.equalsIgnoreCase("granted"))) {
GenericValue userLogin = (GenericValue) context.get("userLogin");
- Map serviceInMap = FastMap.newInstance();
+ Map<String, Object> serviceInMap = FastMap.newInstance();
serviceInMap.put("userLogin", userLogin);
serviceInMap.put("targetOperationList", context.get("targetOperationList"));
serviceInMap.put("contentPurposeList", context.get("contentPurposeList"));
@@ -364,7 +342,6 @@
public static byte[] acquireImage(GenericDelegator delegator, GenericValue dataResource) throws GenericEntityException {
byte[] b = null;
- String dataResourceTypeId = dataResource.getString("dataResourceTypeId");
String dataResourceId = dataResource.getString("dataResourceId");
GenericValue imageDataResource = delegator.findByPrimaryKey("ImageDataResource", UtilMisc.toMap("dataResourceId", dataResourceId));
if (imageDataResource != null) {
@@ -418,7 +395,7 @@
}
public static String buildRequestPrefix(GenericDelegator delegator, Locale locale, String webSiteId, String https) {
- Map prefixValues = FastMap.newInstance();
+ Map<String, Object> prefixValues = FastMap.newInstance();
String prefix;
NotificationServices.setBaseUrl(delegator, webSiteId, prefixValues);
@@ -518,7 +495,7 @@
}
// descending comparator
- Comparator desc = new Comparator() {
+ Comparator<Object> desc = new Comparator<Object>() {
public int compare(Object o1, Object o2) {
if (((Long) o1).longValue() > ((Long) o2).longValue()) {
return -1;
@@ -532,7 +509,7 @@
// check for the latest subdirectory
String parentDir = ofbizHome + initialPath;
File parent = FileUtil.getFile(parentDir);
- TreeMap dirMap = new TreeMap(desc);
+ TreeMap<Long, File> dirMap = new TreeMap<Long, File>(desc);
if (parent.exists()) {
File[] subs = parent.listFiles();
for (int i = 0; i < subs.length; i++) {
@@ -583,7 +560,7 @@
// DataResource rendering methods
// -------------------------------------
- public static String renderDataResourceAsText(GenericDelegator delegator, String dataResourceId, Map templateContext,
+ public static String renderDataResourceAsText(GenericDelegator delegator, String dataResourceId, Map<String, Object> templateContext,
Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException {
Writer writer = new StringWriter();
renderDataResourceAsText(delegator, dataResourceId, writer, templateContext, locale, targetMimeTypeId, cache);
@@ -591,7 +568,7 @@
}
public static void renderDataResourceAsText(GenericDelegator delegator, String dataResourceId, Appendable out,
- Map templateContext, Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException {
+ Map<String, Object> templateContext, Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException {
if (dataResourceId == null) {
throw new GeneralException("Cannot lookup data resource with for a null dataResourceId");
}
@@ -671,8 +648,8 @@
File sourceFileLocation = null;
File targetFileLocation = new File(System.getProperty("ofbiz.home")+"/runtime/tempfiles/docbook.css");
if (templateContext.get("visualThemeId") != null) {
- Map layoutSettings = (Map) templateContext.get("layoutSettings");
- List<String> docbookStyleSheets = (List) layoutSettings.get("VT_DOCBOOKSTYLESHEET");
+ Map<String, Object> layoutSettings = UtilGenerics.checkMap(templateContext.get("layoutSettings"));
+ List<String> docbookStyleSheets = UtilGenerics.checkList(layoutSettings.get("VT_DOCBOOKSTYLESHEET"));
String docbookStyleLocation = docbookStyleSheets.get(0);
sourceFileLocation = new File(System.getProperty("ofbiz.home")+"/themes"+docbookStyleLocation);
}
@@ -681,8 +658,8 @@
} else {
String defaultVisualThemeId = UtilProperties.getPropertyValue("general", "VISUAL_THEME");
if (defaultVisualThemeId != null) {
- GenericValue themeValue = delegator.findByPrimaryKeyCache("VisualThemeResource", UtilMisc.toMap("visualThemeId", defaultVisualThemeId,"resourceTypeEnumId","VT_DOCBOOKSTYLESHEET","sequenceId","01"));
- sourceFileLocation = new File(System.getProperty("ofbiz.home")+"/themes"+themeValue.get("resourceValue"));
+ GenericValue themeValue = delegator.findByPrimaryKeyCache("VisualThemeResource", UtilMisc.toMap("visualThemeId", defaultVisualThemeId, "resourceTypeEnumId", "VT_DOCBOOKSTYLESHEET", "sequenceId", "01"));
+ sourceFileLocation = new File(System.getProperty("ofbiz.home") + "/themes" + themeValue.get("resourceValue"));
UtilMisc.copyFile(sourceFileLocation,targetFileLocation);
}
}
@@ -700,12 +677,12 @@
// Screen Widget template
} else if ("SCREEN_COMBINED".equals(dataTemplateTypeId)) {
try {
- MapStack context = MapStack.create(templateContext);
+ MapStack<String> context = MapStack.create(templateContext);
context.put("locale", locale);
// prepare the map for preRenderedContent
String textData = (String) context.get("textData");
if (UtilValidate.isNotEmpty(textData)) {
- Map prc = FastMap.newInstance();
+ Map<String, Object> prc = FastMap.newInstance();
String mapKey = (String) context.get("mapKey");
if (mapKey != null) {
prc.put(mapKey, mapKey);
@@ -727,10 +704,10 @@
modelScreen = ScreenFactory.getScreenFromLocation(combinedName);
} else { // stored in a single file, long or short text
Document screenXml = UtilXml.readXmlDocument(getDataResourceText(dataResource, targetMimeTypeId, locale, templateContext, delegator, cache), true);
- Map modelScreenMap = ScreenFactory.readScreenDocument(screenXml, "DataResourceId: " + dataResource.getString("dataResourceId"));
+ Map<String, ModelScreen> modelScreenMap = ScreenFactory.readScreenDocument(screenXml, "DataResourceId: " + dataResource.getString("dataResourceId"));
if (UtilValidate.isNotEmpty(modelScreenMap)) {
- Map.Entry entry = (Map.Entry) (modelScreenMap.entrySet().iterator().next()); // get first entry, only one screen allowed per file
- modelScreen = (ModelScreen) entry.getValue();
+ Map.Entry<String, ModelScreen> entry = modelScreenMap.entrySet().iterator().next(); // get first entry, only one screen allowed per file
+ modelScreen = entry.getValue();
}
}
if (UtilValidate.isNotEmpty(modelScreen)) {
@@ -782,16 +759,16 @@
// Data Resource Data Gathering
// ----------------------------
- public static String getDataResourceText(GenericValue dataResource, String mimeTypeId, Locale locale, Map context,
+ public static String getDataResourceText(GenericValue dataResource, String mimeTypeId, Locale locale, Map<String, Object> context,
GenericDelegator delegator, boolean cache) throws IOException, GeneralException {
Writer out = new StringWriter();
writeDataResourceText(dataResource, mimeTypeId, locale, context, delegator, out, cache);
return out.toString();
}
- public static void writeDataResourceText(GenericValue dataResource, String mimeTypeId, Locale locale, Map templateContext,
+ public static void writeDataResourceText(GenericValue dataResource, String mimeTypeId, Locale locale, Map<String, Object> templateContext,
GenericDelegator delegator, Appendable out, boolean cache) throws IOException, GeneralException {
- Map context = (Map) templateContext.get("context");
+ Map<String, Object> context = UtilGenerics.checkMap(templateContext.get("context"));
if (context == null) {
context = FastMap.newInstance();
}
@@ -911,7 +888,7 @@
writeDataResourceText(dataResource, mimeTypeId, locale, context, delegator, out, false);
}
- public static void writeText(GenericValue dataResource, String textData, Map context, String targetMimeTypeId, Locale locale, Appendable out) throws GeneralException, IOException {
+ public static void writeText(GenericValue dataResource, String textData, Map<String, Object> context, String targetMimeTypeId, Locale locale, Appendable out) throws GeneralException, IOException {
String dataResourceMimeTypeId = dataResource.getString("mimeTypeId");
GenericDelegator delegator = dataResource.getDelegator();
@@ -936,7 +913,7 @@
if (mimeTypeTemplate != null && mimeTypeTemplate.get("templateLocation") != null) {
// prepare the context
- Map mimeContext = FastMap.newInstance();
+ Map<String, Object> mimeContext = FastMap.newInstance();
mimeContext.putAll(context);
mimeContext.put("dataResource", dataResource);
mimeContext.put("textData", textData);
@@ -951,7 +928,7 @@
}
}
- public static String renderMimeTypeTemplate(GenericValue mimeTypeTemplate, Map context) throws GeneralException, IOException {
+ public static String renderMimeTypeTemplate(GenericValue mimeTypeTemplate, Map<String, Object> context) throws GeneralException, IOException {
String location = mimeTypeTemplate.getString("templateLocation");
StringWriter writer = new StringWriter();
try {
@@ -1030,7 +1007,7 @@
* @throws IOException
* @throws GeneralException
*/
- public static Map getDataResourceStream(GenericValue dataResource, String https, String webSiteId, Locale locale, String contextRoot, boolean cache) throws IOException, GeneralException {
+ public static Map<String, Object> getDataResourceStream(GenericValue dataResource, String https, String webSiteId, Locale locale, String contextRoot, boolean cache) throws IOException, GeneralException {
if (dataResource == null) {
throw new GeneralException("Cannot stream null data resource!");
}
@@ -1216,12 +1193,12 @@
return byteBuffer;
}
- public String renderDataResourceAsTextExt(GenericDelegator delegator, String dataResourceId, Map templateContext,
+ public String renderDataResourceAsTextExt(GenericDelegator delegator, String dataResourceId, Map<String, Object> templateContext,
Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException {
return renderDataResourceAsText(delegator, dataResourceId, templateContext, locale, targetMimeTypeId, cache);
}
- public void renderDataResourceAsTextExt(GenericDelegator delegator, String dataResourceId, Appendable out, Map templateContext,
+ public void renderDataResourceAsTextExt(GenericDelegator delegator, String dataResourceId, Appendable out, Map<String, Object> templateContext,
Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException {
renderDataResourceAsText(delegator, dataResourceId, out, templateContext, locale, targetMimeTypeId, cache);
}
Re: svn commit: r821238 - /ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java
Posted by Scott Gray <sc...@hotwaxmedia.com>.
On 4/10/2009, at 7:12 AM, Adam Heath wrote:
> lektran@apache.org wrote:
>> Author: lektran
>> Date: Sat Oct 3 04:12:28 2009
>> New Revision: 821238
>>
>> URL: http://svn.apache.org/viewvc?rev=821238&view=rev
>> Log:
>> Cleaned up imports
>> Additional generics markup
>> Enhanced for loops
>> Fixed a comment typos
>> Removed an unused method variable
>
> Just to show that I don't always have bad things to say, this is a
> good changelog. While it does several things, all of them are
> actually just code cleanups. Good job.
That's a relief, I saw I had a reply and thought oh man what now!
Because you're being so nice I'll give you a bottom post :-)
Regards
Scott
Re: svn commit: r821238 - /ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java
Posted by Adam Heath <do...@brainfood.com>.
lektran@apache.org wrote:
> Author: lektran
> Date: Sat Oct 3 04:12:28 2009
> New Revision: 821238
>
> URL: http://svn.apache.org/viewvc?rev=821238&view=rev
> Log:
> Cleaned up imports
> Additional generics markup
> Enhanced for loops
> Fixed a comment typos
> Removed an unused method variable
Just to show that I don't always have bad things to say, this is a
good changelog. While it does several things, all of them are
actually just code cleanups. Good job.