protected static int getValue(char c) { if ((c >= CharPool.UPPER_CASE_A) && (c <= CharPool.UPPER_CASE_Z)) { return c - 65; } if ((c >= CharPool.LOWER_CASE_A) && (c <= CharPool.LOWER_CASE_Z)) { return (c - 97) + 26; } if ((c >= CharPool.NUMBER_0) && (c <= CharPool.NUMBER_9)) { return (c - 48) + 52; } if (c == CharPool.PLUS) { return 62; } if (c == CharPool.SLASH) { return 63; } return c != CharPool.EQUAL ? -1 : 0; }
public static Object processTreePath(Object treePath) { if (treePath == null) { return null; } if (treePath instanceof Set) { Set<?> treePathSet = (Set<?>)treePath; Set<Object> treePathFiltered = new HashSet<Object>(); for (Object obj : treePathSet) { if (Validator.isNotNull(obj)) { treePathFiltered.add(obj); } } return treePathFiltered; } if (!(treePath instanceof String)) { return treePath; } String treePathStr = (String)treePath; if ((treePathStr.length() > 0) && (treePathStr.charAt(0) == CharPool.SLASH)) { treePathStr = treePathStr.substring(1); } if (Validator.isNull(treePathStr)) { return StringPool.BLANK; } return StringUtil.split(treePathStr, CharPool.SLASH); }
private CSVWriter initCsv(ResourceResponse resourceResponse) throws IOException, UnsupportedEncodingException { //Necesario para crear el fichero csv. resourceResponse.setCharacterEncoding(StringPool.UTF8); resourceResponse.setContentType(ContentTypes.TEXT_CSV_UTF8); resourceResponse.addProperty(HttpHeaders.CONTENT_DISPOSITION,"attachment; fileName=Statistics.csv"); byte b[] = {(byte)0xEF, (byte)0xBB, (byte)0xBF}; resourceResponse.getPortletOutputStream().write(b); CSVWriter writer = new CSVWriter(new OutputStreamWriter(resourceResponse.getPortletOutputStream(),StringPool.UTF8),CharPool.SEMICOLON); return writer; }
private int _toInt(String color) { if (color.charAt(0) == CharPool.POUND) { color = color.substring(1); } return Integer.parseInt(color, 16); }
@Override public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws PortalException { ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask); long userId = backgroundTask.getUserId(); StringBundler sb = new StringBundler(4); sb.append(StringUtil.replace(exportImportConfiguration.getName(), CharPool.SPACE, CharPool.UNDERLINE)); sb.append(StringPool.DASH); sb.append(Time.getTimestamp()); sb.append(".zip"); File xmlFile = TaskRecordLocalServiceUtil.exportTaskRecordsAsFile(exportImportConfiguration); BackgroundTaskManagerUtil.addBackgroundTaskAttachment(userId, backgroundTask.getBackgroundTaskId(), sb.toString(), xmlFile); return BackgroundTaskResult.SUCCESS; }
@Override public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws PortalException { ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask); long userId = backgroundTask.getUserId(); StringBundler sb = new StringBundler(4); sb.append(StringUtil.replace(exportImportConfiguration.getName(), CharPool.SPACE, CharPool.UNDERLINE)); sb.append(StringPool.DASH); sb.append(Time.getTimestamp()); sb.append(".zip"); File xmlFile = ContactLocalServiceUtil.exportContactsAsFile(exportImportConfiguration); BackgroundTaskManagerUtil.addBackgroundTaskAttachment(userId, backgroundTask.getBackgroundTaskId(), sb.toString(), xmlFile); return BackgroundTaskResult.SUCCESS; }
@Override public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws PortalException { ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask); long userId = backgroundTask.getUserId(); StringBundler sb = new StringBundler(4); sb.append(StringUtil.replace(exportImportConfiguration.getName(), CharPool.SPACE, CharPool.UNDERLINE)); sb.append(StringPool.DASH); sb.append(Time.getTimestamp()); sb.append(".zip"); File xmlFile = MeasurementLocalServiceUtil.exportMeasurementsAsFile(exportImportConfiguration); BackgroundTaskManagerUtil.addBackgroundTaskAttachment(userId, backgroundTask.getBackgroundTaskId(), sb.toString(), xmlFile); return BackgroundTaskResult.SUCCESS; }
@Override public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws IOException, PortletException { ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); String action = ParamUtil.getString(resourceRequest, "action"); long actId = ParamUtil.getLong(resourceRequest, "actId",0); if(action.equals("export")){ try { CalificationType ct = new CalificationTypeRegistry().getCalificationType(CourseLocalServiceUtil.getCourseByGroupCreatedId(themeDisplay.getScopeGroupId()).getCalificationType()); //Necesario para crear el fichero csv. resourceResponse.setCharacterEncoding(StringPool.UTF8); resourceResponse.setContentType(ContentTypes.TEXT_CSV_UTF8); resourceResponse.addProperty(HttpHeaders.CONTENT_DISPOSITION,"attachment; fileName=data.csv"); byte b[] = {(byte)0xEF, (byte)0xBB, (byte)0xBF}; resourceResponse.getPortletOutputStream().write(b); CSVWriter writer = new CSVWriter(new OutputStreamWriter(resourceResponse.getPortletOutputStream(),StringPool.UTF8),CharPool.SEMICOLON); String[] cabeceras = new String[4]; //En esta columna vamos a tener el nombre del usuario. cabeceras[0]= LanguageUtil.get(getPortletConfig(), themeDisplay.getLocale(), "onlinetaskactivity.export.user"); cabeceras[1]= LanguageUtil.get(getPortletConfig(), themeDisplay.getLocale(), "onlinetaskactivity.export.date"); cabeceras[2]= LanguageUtil.get(getPortletConfig(), themeDisplay.getLocale(), "onlinetaskactivity.export.result"); cabeceras[3]= LanguageUtil.get(getPortletConfig(), themeDisplay.getLocale(), "onlinetaskactivity.export.comment"); writer.writeNext(cabeceras); DynamicQuery dq=DynamicQueryFactoryUtil.forClass(LearningActivityResult.class); Criterion criterion=PropertyFactoryUtil.forName("actId").eq(actId); dq.add(criterion); //Partiremos del usuario para crear el csv para que sea más facil ver los intentos. List<LearningActivityResult> listresult = LearningActivityResultLocalServiceUtil.dynamicQuery(dq); for(LearningActivityResult learningActivityResult:listresult){ //Array con los resultados de los intentos. String[] resultados = new String[4]; //En la primera columna del csv introducidos el nombre del estudiante. resultados[0] = UserLocalServiceUtil.getUser(learningActivityResult.getUserId()).getScreenName(); resultados[1] = _dateFormat.format(learningActivityResult.getEndDate()); resultados[2] = ct.translate(themeDisplay.getLocale(), themeDisplay.getScopeGroupId(), learningActivityResult.getResult()); resultados[3] = learningActivityResult.getComments()!=null?learningActivityResult.getComments():""; //Escribimos las respuestas obtenidas para el intento en el csv. writer.writeNext(resultados); } writer.flush(); writer.close(); resourceResponse.getPortletOutputStream().flush(); resourceResponse.getPortletOutputStream().close(); } catch (NestableException e) { }finally{ resourceResponse.getPortletOutputStream().flush(); resourceResponse.getPortletOutputStream().close(); } } }
protected void fixTypeSettings(Layout layout) throws Exception { if (!layout.isTypeURL()) { return; } UnicodeProperties typeSettings = layout.getTypeSettingsProperties(); String url = GetterUtil.getString(typeSettings.getProperty("url")); String friendlyURLPrivateGroupPath = PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING; String friendlyURLPrivateUserPath = PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING; String friendlyURLPublicPath = PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING; if (!url.startsWith(friendlyURLPrivateGroupPath) && !url.startsWith(friendlyURLPrivateUserPath) && !url.startsWith(friendlyURLPublicPath)) { return; } int x = url.indexOf(CharPool.SLASH, 1); if (x == -1) { return; } int y = url.indexOf(CharPool.SLASH, x + 1); if (y == -1) { return; } String friendlyURL = url.substring(x, y); if (!friendlyURL.equals(LayoutExporter.SAME_GROUP_FRIENDLY_URL)) { return; } Group group = layout.getGroup(); typeSettings.setProperty( "url", url.substring(0, x) + group.getFriendlyURL() + url.substring(y)); }