List of usage examples for java.lang StringBuffer deleteCharAt
@Override public synchronized StringBuffer deleteCharAt(int index)
From source file:com.wabacus.system.component.application.report.UltraListReportType.java
protected void loadGroupConfig(UltraListReportGroupBean groupBean, XmlElementBean eleGroupBean, DisplayBean disbean, UltraListReportGroupBean parentGroupBean) { String label = eleGroupBean.attributeValue("label"); label = label == null ? "" : label.trim(); String labelstyleproperty = eleGroupBean.attributeValue("labelstyleproperty"); labelstyleproperty = labelstyleproperty == null ? "" : labelstyleproperty.trim(); groupBean.setLabelstyleproperty(labelstyleproperty, false); labelstyleproperty = groupBean.getLabelstyleproperty(null, true); labelstyleproperty = Tools.addPropertyValueToStylePropertyIfNotExist(labelstyleproperty, "align", "center"); labelstyleproperty = Tools.addPropertyValueToStylePropertyIfNotExist(labelstyleproperty, "valign", "middle"); groupBean.setLabelstyleproperty(labelstyleproperty, true); if (label != null) { label = label.trim();/*from ww w. j a va 2 s . c om*/ label = Config.getInstance().getResourceString(null, disbean.getPageBean(), label, true); } groupBean.setLabel(label); String rowspan = Tools.getPropertyValueByName("rowspan", labelstyleproperty, true); if (rowspan != null && !rowspan.trim().equals("")) { try { groupBean.setRowspan(Integer.parseInt(rowspan)); } catch (NumberFormatException e) { log.warn("" + disbean.getReportBean().getPath() + "?<group/>labelstylepropertyrowspan??", e); groupBean.setRowspan(1); } } List<XmlElementBean> lstEleGroupBeans = new ArrayList<XmlElementBean>(); lstEleGroupBeans.add(eleGroupBean); LoadExtendConfigManager.loadBeforeExtendConfigForReporttype(groupBean, lstEleGroupBeans); List lstGroupChildren = new ArrayList(); groupBean.setLstChildren(lstGroupChildren); StringBuffer childIdsBuf = new StringBuffer(); List<XmlElementBean> lstChildrenElements = eleGroupBean.getLstChildElements(); if (lstChildrenElements == null || lstChildrenElements.size() == 0) { throw new WabacusConfigLoadingException("" + disbean.getReportBean().getPath() + "?group" + label + "??"); } for (XmlElementBean eleChildBeanTmp : lstChildrenElements) { if (eleChildBeanTmp.getName().equalsIgnoreCase("col")) { ColBean colbean = ComponentConfigLoadManager.loadColConfig(eleChildBeanTmp, disbean); // {//? // setAlwaysDisplayTypeToGroupBean(ulrdbean,groupBean); AbsListReportColBean alrcbean = (AbsListReportColBean) colbean .getExtendConfigDataForReportType(AbsListReportType.KEY); AbsListReportDisplayBean alrdbeanTmp = (AbsListReportDisplayBean) disbean .getExtendConfigDataForReportType(AbsListReportType.KEY); if (alrdbeanTmp != null && alrdbeanTmp.getRowgrouptype() == 2 && alrcbean != null && alrcbean.isRowgroup()) { throw new WabacusConfigLoadingException("" + disbean.getReportBean().getPath() + "<group/><col/>??"); } UltraListReportColBean ulrcbeanTmp = (UltraListReportColBean) colbean .getExtendConfigDataForReportType(KEY); if (ulrcbeanTmp == null) { ulrcbeanTmp = new UltraListReportColBean(colbean); colbean.setExtendConfigDataForReportType(KEY, ulrcbeanTmp); } ulrcbeanTmp.setParentGroupid(groupBean.getGroupid()); disbean.getLstCols().add(colbean); lstGroupChildren.add(colbean); childIdsBuf.append(colbean.getColid()).append(","); } else if (eleChildBeanTmp.getName().equalsIgnoreCase("group")) { UltraListReportGroupBean groupBeanChild = new UltraListReportGroupBean(disbean); groupBeanChild.setParentGroupid(groupBean.getGroupid()); lstGroupChildren.add(groupBeanChild); loadGroupConfig(groupBeanChild, eleChildBeanTmp, disbean, groupBean); childIdsBuf.append(groupBeanChild.getGroupid()).append(","); } } if (lstGroupChildren.size() == 0) { throw new WabacusConfigLoadingException("" + disbean.getReportBean().getPath() + "" + label + "??"); } if (childIdsBuf.charAt(childIdsBuf.length() - 1) == ',') childIdsBuf.deleteCharAt(childIdsBuf.length() - 1); groupBean.setChildids(childIdsBuf.toString()); LoadExtendConfigManager.loadAfterExtendConfigForReporttype(groupBean, lstEleGroupBeans); }
From source file:edu.mit.isda.permitws.permit.java
/** * * @param authId/*from w w w . ja v a2 s .com*/ * @param proxyUserName * @return * @throws edu.mit.isda.permitws.permitException */ @SuppressWarnings("unchecked") public String listEditableAuthorizationByAuthId(String authId, String proxyUserName) throws permitException { Collection auth = null; Iterator iter; String Message; String ApplicationID = ""; StringBuffer xml = new StringBuffer("\r\n{\"authorizations\": ["); AuthenticateRemoteClient AuthenticateClient = new AuthenticateRemoteClient(); try { ApplicationID = AuthenticateClient.authenticateClient("permitws"); if (proxyUserName == null) { Message = "Invalid certificate"; throw new Exception(Message); } if (proxyUserName.length() == 0) { Message = "No certificate user detected"; throw new Exception(Message); } AuthorizationManager instance = AuthorizationFactory.getManager(); auth = instance.listEditableAuthorizationByAuthId(authId, proxyUserName.trim().toUpperCase()); if (null == auth) { xml = new StringBuffer(EMPTY_RESULT_MESSAGE); } else if (auth.isEmpty()) { xml = new StringBuffer(EMPTY_RESULT_MESSAGE); } else { iter = auth.iterator(); while (iter.hasNext()) { EditableAuthorizationRaw a = (EditableAuthorizationRaw) iter.next(); AuthorizationPK apk = a.getAuthorizationPK(); Long aid = apk.getAuthorizationId(); xml = createAuthorizationXML(xml, a.getCategory(), a.getFunction(), a.getFunctionDesc(), a.getQualifierType(), a.getQualifierName(), a.getQualifierCode(), a.getPerson(), a.getFirstName(), a.getLastName(), aid, a.getEffectiveDate(), a.getExpirationDate(), a.getIsActiveNow(), a.getDoFunction(), a.getGrantAuthorization(), a.getModifiedBy(), a.getModifiedDate(), a.getRequestingUser(), a.isEditable()); } int lastCharIndex = xml.length(); xml.deleteCharAt(lastCharIndex - 1); xml.append("\r\n]}"); } } catch (Exception e) { Message = "permitws Web Service: " + e.getMessage(); log.error(Message); e.printStackTrace(); throw new permitException(e); } try { return (URLEncoder.encode(xml.toString(), "UTF-8")); } catch (Exception e) { throw new permitException(e.getLocalizedMessage()); } }
From source file:org.opencms.widgets.CmsCategoryWidget.java
/** >>>>>>> THEIRS//from ww w.j a v a 2 s . c o m * @see org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter) */ public String getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { // get select box options from default value String CmsCategory selected = null; try { String name = param.getStringValue(cms); selected = CmsCategoryService.getInstance().getCategory(cms, name); } catch (CmsException e) { // ignore } StringBuffer result = new StringBuffer(16); List<List<CmsSelectWidgetOption>> levels = new ArrayList<List<CmsSelectWidgetOption>>(); try { // write arrays of categories result.append("<script language='javascript'>\n"); String referencePath = null; try { referencePath = cms.getSitePath(getResource(cms, param)); } catch (Exception e) { // ignore, this can happen if a new resource is edited using direct edit } String startingCat = getStartingCategory(cms, referencePath); List<CmsCategory> cats = CmsCategoryService.getInstance().readCategories(cms, startingCat, true, referencePath); int baseLevel; if (CmsStringUtil.isEmptyOrWhitespaceOnly(startingCat)) { baseLevel = 0; } else { baseLevel = CmsResource.getPathLevel(startingCat); if (!(startingCat.startsWith("/") && startingCat.endsWith("/"))) { baseLevel++; } } int level; Set<String> done = new HashSet<String>(); List<CmsSelectWidgetOption> options = new ArrayList<CmsSelectWidgetOption>(); String jsId = CmsStringUtil.substitute(param.getId(), ".", ""); for (level = baseLevel + 1; !cats.isEmpty(); level++) { if (level != (baseLevel + 1)) { result.append("var cat" + (level - baseLevel) + jsId + " = new Array(\n"); } Iterator<CmsCategory> itSubs = cats.iterator(); while (itSubs.hasNext()) { CmsCategory cat = itSubs.next(); String title = cat.getTitle(); String titleJs = StringEscapeUtils.escapeJavaScript(title); String titleHtml = StringEscapeUtils.escapeHtml(title); if ((CmsResource.getPathLevel(cat.getPath()) + 1) == level) { itSubs.remove(); if (done.contains(cat.getPath())) { continue; } if (level != (baseLevel + 1)) { result.append("new Array('" + cat.getId() + "', '" + CmsCategoryService .getInstance().readCategory(cms, CmsResource.getParentFolder(cat.getPath()), referencePath) .getId() + "', '" + titleJs + "'),\n"); } if ((level == (baseLevel + 1)) || ((selected != null) && selected.getPath().startsWith(CmsResource.getParentFolder(cat.getPath())))) { if (levels.size() < (level - baseLevel)) { options = new ArrayList<CmsSelectWidgetOption>(); levels.add(options); options.add(new CmsSelectWidgetOption("", true, Messages.get() .getBundle(widgetDialog.getLocale()).key(Messages.GUI_CATEGORY_SELECT_0))); } options.add(new CmsSelectWidgetOption(cat.getId().toString(), false, titleHtml)); } done.add(cat.getPath()); } } if (level != (baseLevel + 1)) { result.deleteCharAt(result.length() - 1); result.deleteCharAt(result.length() - 1); result.append(");\n"); } } result.append("</script>\n"); result.append("<td class=\"xmlTd\" >"); result.append("<input id='" + param.getId() + "' name='" + param.getId() + "' type='hidden' value='" + (selected != null ? selected.getId().toString() : "") + "'>\n"); for (int i = 1; i < (level - baseLevel); i++) { result.append("<span id='" + param.getId() + "cat" + i + "IdDisplay'"); if (levels.size() >= i) { options = levels.get(i - 1); } else { result.append(" style='display:none'"); options = new ArrayList<CmsSelectWidgetOption>(); options.add(new CmsSelectWidgetOption("", true, Messages.get() .getBundle(widgetDialog.getLocale()).key(Messages.GUI_CATEGORY_SELECT_0))); } result.append(">"); result.append(buildSelectBox(param.getId(), i, options, (selected != null ? CmsCategoryService.getInstance() .readCategory(cms, CmsResource.getPathPart(selected.getPath(), i + baseLevel), referencePath) .getId().toString() : ""), param.hasError(), (i == (level - baseLevel - 1)))); result.append("</span> "); } result.append("</td>"); } catch (CmsException e) { result.append(e.getLocalizedMessage()); } return result.toString(); }
From source file:org.etudes.mneme.impl.SubmissionServiceImpl.java
/** * Notifies students about the evaluation * /*w ww . j av a 2 s. c o m*/ * @param assessment * The assessment. */ protected void notifyStudentEvaluation(Assessment assessment) { if (!assessment.getFormalCourseEval() && !assessment.getNotifyEval()) return; // to List<User> submitUsers = assessment.getSubmitUsers(); StringBuffer toStrBuf = new StringBuffer(); for (User user : submitUsers) { toStrBuf.append(user.getEmail()); toStrBuf.append(","); } if (toStrBuf.length() > 0 && toStrBuf.charAt(toStrBuf.length() - 1) == ',') toStrBuf.deleteCharAt(toStrBuf.length() - 1); String to = toStrBuf.toString(); // from String from = "\"" + this.serverConfigurationService.getString("ui.service", "Sakai") + "\"<no-reply@" + this.serverConfigurationService.getServerName() + ">"; String siteTitle = ""; try { Site site = this.siteService.getSite(assessment.getContext()); siteTitle = site.getTitle(); } catch (IdUnusedException e) { } // subject String subject = null; if (assessment.getFormalCourseEval()) subject = "Course Evaluation Now Open: " + siteTitle; // for html List<String> headers = new ArrayList<String>(); headers.add("content-type: text/html"); String content = getEvalNotificationSample(assessment); this.emailService.send(from, to, subject, content, null, null, headers); // mark the assessment as having the results sent this.assessmentService.setEvaluationSent(assessment, new Date()); }
From source file:org.infoglue.cms.controllers.kernel.impl.simple.ContentController.java
/** * The input is a list of hashmaps.//w w w . jav a2 s . c o m */ protected List getContentVOListByContentTypeIds(List<Integer> contentTypeDefinitionIdList, Database db) throws SystemException, Exception { List contents = new ArrayList(); StringBuffer sb = new StringBuffer(); for (Integer ctdId : contentTypeDefinitionIdList) { sb.append(ctdId + ","); } sb.deleteCharAt(sb.length() - 1); OQLQuery oql = null; if (CmsPropertyHandler.getUseShortTableNames().equals("true")) oql = db.getOQLQuery( "CALL SQL SELECT c.contId, c.name, c.publishDateTime, c.expireDateTime, c.isBranch, c.isProtected, c.isDeleted, c.creator, c.contentTypeDefId, c.repositoryId, c.parentContId FROM cmCont c where c.contentTypeDefId IN(" + sb.toString() + ") AS org.infoglue.cms.entities.content.impl.simple.SmallContentImpl"); else oql = db.getOQLQuery( "CALL SQL SELECT c.contentId, c.name, c.publishDateTime, c.expireDateTime, c.isBranch, c.isProtected, c.isDeleted, c.creator, c.contentTypeDefinitionId, c.repositoryId, c.parentContentId FROM cmContent c where c.contentTypeDefinitionId IN(" + sb.toString() + ") AS org.infoglue.cms.entities.content.impl.simple.SmallContentImpl"); QueryResults results = oql.execute(Database.READONLY); while (results.hasMore()) { SmallContentImpl content = (SmallContentImpl) results.next(); contents.add(content.getValueObject()); } results.close(); oql.close(); return contents; }
From source file:com.pari.nm.utils.db.ReportDBHelper.java
public static void createTempPaginationTable(ServiceDescriptor descriptor, TableDefinition tableDef, String reportId, String sessionId, ArrayList<String> childColNamesList) throws SQLException { Connection c = null;/*www . ja v a2 s. c o m*/ Statement st = null; int result = -1; int childResult = -1; try { if (descriptor == null) { throw new Exception("Unable to get ServiceDescriptor for ReportId:\t" + reportId + "\t SessionId:\t" + sessionId); } if (descriptor.getIdentifier().equals("extended_device_attributes_report")) { createTempTableForPagination(tableDef, reportId, sessionId, childColNamesList); } else { StringBuffer sb = new StringBuffer(); StringBuilder childTblCreateQuery = new StringBuilder(); String childTblName = null; String tblName = getTempPaginationTblName(reportId, sessionId); if (tblName == null) { throw new Exception( "No Table Exist with ReportId:\t" + reportId + "and SessionId:\t" + sessionId); } System.out.println("Temporary Report Table Name:\t" + tblName); sb.append("CREATE TABLE \t" + tblName + " \t ("); AttributeDescriptor[] attrDescArr = descriptor.getAllAttributeDescriptors(); if (attrDescArr != null) { for (AttributeDescriptor attrDesc : attrDescArr) { String identifier = attrDesc.getIdentifier(); identifier = identifier.replace(' ', '_'); String columnName = getRenderColumnName(identifier, tableDef); identifier = (null == columnName) ? identifier : columnName; logger.info("attrDesc.getIdentifier()====\t" + attrDesc.getIdentifier()); if (identifier.equals("RowId")) { // ProfileRunSummary Report contains RowId, which is conflicting with Oracle RowId, so // appended // RowId with 123 sb.append(identifier + "123" + "\tvarchar2(4000),"); } else if (identifier.equals("User")) { // Unmanaged Device Report contains User, which is conflicting with Oracle User, so appended // User with 123 sb.append(identifier + "123" + "\tvarchar2(4000),"); } else if (identifier.equalsIgnoreCase("Comment")) { // Pending Approvals Report contains Comment, which is conflicting with Oracle Reserved Word // Comment, so appended // Comment with 123 sb.append(identifier + "123" + "\tvarchar2(4000),"); } else if (identifier.equals("Size")) { // Manage script repository export contains size, which is conflicting with Oracle reserved // word, and this column changed to 'size123' sb.append(identifier + "123" + "\tvarchar2(4000),"); } else if (identifier.toLowerCase().equals("timestamp")) { // Manage script repository export contains size, which is conflicting with Oracle reserved // word, and this column changed to 'size123' sb.append(identifier + "123" + "\tvarchar2(4000),"); } else if (identifier.toLowerCase().equals("violationdetails")) { // Manage script repository export contains size, which is conflicting with Oracle reserved // word, and this column changed to 'size123' sb.append(identifier + "\tBlob,"); } else { sb.append(identifier + "\tvarchar2(4000),"); } } Def[] childDefArr = descriptor.getAllChildRefs(); List<StringBuffer> childBufferList = new ArrayList<>(); if (childDefArr != null && childDefArr.length > 0) { for (Def def : childDefArr) { String defName = def.getName(); sb.append(defName + "\tvarchar2(4000),"); // For Hierarchical Reports we need to create a child table // table name like reportId_sessionId_defName manipulationTempPaginationTable(reportId, sessionId, defName, null); childTblName = getTempPaginationTblName(reportId, sessionId, defName); logger.info("ChildTableName:\t" + childTblName); if (childTblName == null) { throw new Exception("No Table Exist with ReportId:\t" + reportId + "and SessionId:\t" + sessionId + "and ChildTableIdentifier:\t" + defName); } // childTblName = reportId+"_"+sessionId+"_"+defName; logger.info("ChildTableName:\t" + childTblName); // childTblCreateQuery.append("CREATE TABLE \t" + childTblName + " \t ("); // childTblCreateQuery.append("PAGINATION_PK" + "\t NUMBER,"); ServiceDescriptor childServiceDesc = descriptor .getContainedServiceDescriptorByName(defName); if (childServiceDesc != null) { AttributeDescriptor[] childAttrDescArr = childServiceDesc .getAllAttributeDescriptors(); if (childAttrDescArr != null) { /* * for (AttributeDescriptor childAttrDesc : childAttrDescArr) { * logger.info("childAttrDesc.getIdentifier()====\t" + * childAttrDesc.getIdentifier()); * childTblCreateQuery.append(childAttrDesc.getIdentifier() + "\tvarchar2(4000),"); * } */ // for (String colName : childColNamesList) // { // childTblCreateQuery.append(colName + "\tvarchar2(4000),"); // } // // childTblCreateQuery.toString(); // String childTblStr = childTblCreateQuery.substring(0, // childTblCreateQuery.length() - 1); // childTblCreateQuery = new StringBuilder(); // childTblCreateQuery.append(childTblStr); // childTblCreateQuery.append(")"); // logger.info("create child table in stringbuilder format is----" // + childTblCreateQuery.toString()); StringBuffer childBuffer = new StringBuffer(); childBuffer.append("CREATE TABLE " + childTblName + " ("); // Multiple children was not considered in previous implementation. Now this is // addressed and // child table for each child entry in table definition will be created. Using child // table // column ids instead of childColNamesList which was used earlier. TableDefinition childTable = tableDef.getChildTableById(defName); ColumnDefinition[] columnDefs = childTable.getColumnDefs(); for (ColumnDefinition columnDef : columnDefs) { childBuffer.append(columnDef.getId() + " varchar2(4000),"); } childBuffer.deleteCharAt(childBuffer.length() - 1); childBuffer.append(")"); logger.info("[CREATE-PAGINATION-TEMP-TABLE] Create Child Table format is " + String.valueOf(childBuffer)); childBufferList.add(childBuffer); } } } } // sb.append("PAGINATION_PK" + "\t NUMBER,"); String tempStr = sb.substring(0, sb.length() - 1); sb = new StringBuffer(); sb.append(tempStr); sb.append(")"); logger.info("create table in stringbuffer format is----" + sb.toString()); c = DBHelper.getConnection(); if (c == null) { logger.error("Unable to Obtain Connection to create Temporary Pagination Table."); return; } try { st = c.createStatement(); } catch (SQLException e) { logger.info( "Exception Occured while Creating Statement to create Temporary Pagination Table.", e); return; } try { result = st.executeUpdate(sb.toString()); } catch (SQLException e) { logger.info( "Exception Occured while executing the Query to Create Temporary Pagination Table.", e); return; } if (result > 0) { logger.info("Table:" + tblName + "\t Created Successfully."); } // try // { // childResult = st.executeUpdate(childTblCreateQuery.toString()); // } // catch (SQLException e) // { // logger.info( // "Exception Occured while executing the Child Table Query to Create Temporary Pagination Table.", // e); // return; // } if (childBufferList.size() > 0) { for (StringBuffer childBuffer : childBufferList) { if (0 != childBuffer.length()) { try { result = st.executeUpdate(childBuffer.toString()); logger.info(result <= 2 ? "[CREATE-PAGINATION-TEMP-TABLE] Child Table '" + childTblName + "' created successfully." : "[CREATE-PAGINATION-TEMP-TABLE] Failed to cretae child table '" + childTblName + "'."); } catch (SQLException e) { logger.info( "Exception Occured while executing the Child Table Query to Create Temporary Pagination Table.", e); return; } } } } if (childResult > 0) { logger.info("Table:" + childTblName + "\t Created Successfully."); } } } } catch (Exception e) { logger.error("Exception Occured while Creating Temporary Pagination Table.", e); return; } finally { if (st != null) { st.close(); } DBHelper.releaseConnection(c); } }
From source file:edu.mit.isda.permitws.permit.java
/** * * @param UserName//from w ww. j a v a 2s . c o m * @param category * @param isActive * @param willExpand * @param proxyUserName * @return * @throws edu.mit.isda.permitws.permitException */ @SuppressWarnings("unchecked") public String listAuthorizationsByPersonXML(String UserName, String category, boolean isActive, boolean willExpand, String proxyUserName) throws permitException { Set auth = null; Iterator iter; String Message; String ApplicationID = ""; StringBuffer xml = new StringBuffer("\r\n{\"authorizations\": ["); AuthenticateRemoteClient AuthenticateClient = new AuthenticateRemoteClient(); utils u = new utils(); try { UserName = u.validateUser(UserName); if (UserName == null) { Message = "invalid user name"; throw new Exception(Message); } if (UserName.length() == 0) { Message = "user name not specified"; throw new Exception(Message); } ApplicationID = AuthenticateClient.authenticateClient("permitws"); if (category == null) { category = ""; } if (proxyUserName == null) { Message = "Invalid certificate"; throw new Exception(Message); } if (proxyUserName.length() == 0) { Message = "No certificate user detected"; throw new Exception(Message); } AuthorizationManager instance = AuthorizationFactory.getManager(); auth = instance.listAuthorizationsByPerson(UserName.trim(), category.trim(), Boolean.valueOf(isActive), Boolean.valueOf(willExpand), ApplicationID.trim(), proxyUserName.trim()); iter = auth.iterator(); while (iter.hasNext()) { Authorization a = (Authorization) iter.next(); Category c = a.getCategory(); Function f = a.getFunction(); Qualifier q = a.getQualifier(); Person p = a.getPerson(); AuthorizationPK apk = a.getAuthorizationPK(); Long aid = apk.getAuthorizationId(); xml = createAuthorizationXML(xml, c.getCategory(), f.getName(), f.getDescription(), f.getFqt().getType(), q.getName(), q.getCode(), p.getKerberosName(), p.getFirstName(), p.getLastName(), aid, a.getEffectiveDate(), a.getExpirationDate(), null, a.getDoFunction(), a.getGrantAuthorization(), a.getModifiedBy(), a.getModifiedDate(), proxyUserName, false); } int lastCharIndex = xml.length(); xml.deleteCharAt(lastCharIndex - 1); xml.append("\r\n]}"); } catch (Exception e) { Message = "permitws Web Service: " + e.getMessage(); log.error(Message); e.printStackTrace(); throw new permitException(e); } try { return (URLEncoder.encode(xml.toString(), "UTF-8")); } catch (Exception e) { throw new permitException(e.getLocalizedMessage()); } }
From source file:edu.mit.isda.permitws.permit.java
/** * * @param UserName//from ww w . j av a 2 s . c om * @param category * @param isActive * @param willExpand * @param proxyUserName * @return * @throws edu.mit.isda.permitws.permitException */ @SuppressWarnings("unchecked") public String listAuthorizationsByPersonRawXML(String UserName, String category, boolean isActive, boolean willExpand, String proxyUserName) throws permitException { Collection auth = null; Iterator iter; String Message; String ApplicationID = ""; StringBuffer xml = new StringBuffer("\r\n{\"authorizations\": ["); AuthenticateRemoteClient AuthenticateClient = new AuthenticateRemoteClient(); utils u = new utils(); try { UserName = u.validateUser(UserName); if (UserName == null) { Message = "invalid user name"; throw new Exception(Message); } if (UserName.length() == 0) { Message = "user name not specified"; throw new Exception(Message); } ApplicationID = AuthenticateClient.authenticateClient("permitws"); if (category == null) { category = ""; } if (proxyUserName == null) { Message = "Invalid certificate"; throw new Exception(Message); } if (proxyUserName.length() == 0) { Message = "No certificate user detected"; throw new Exception(Message); } AuthorizationManager instance = AuthorizationFactory.getManager(); auth = instance.listAuthorizationsByPersonRaw(UserName.trim(), category.trim(), Boolean.valueOf(isActive), Boolean.valueOf(willExpand), ApplicationID.trim(), proxyUserName.trim()); if (null == auth) { xml = new StringBuffer(EMPTY_RESULT_MESSAGE); } else if (auth.isEmpty()) { xml = new StringBuffer(EMPTY_RESULT_MESSAGE); } else { iter = auth.iterator(); while (iter.hasNext()) { AuthorizationRaw a = (AuthorizationRaw) iter.next(); AuthorizationPK apk = a.getAuthorizationPK(); Long aid = apk.getAuthorizationId(); xml = createAuthorizationXML(xml, a.getCategory(), a.getFunction(), a.getFunctionDesc(), a.getQualifierType(), a.getQualifierName(), a.getQualifierCode(), a.getPerson(), a.getFirstName(), a.getLastName(), aid, a.getEffectiveDate(), a.getExpirationDate(), a.getIsActiveNow(), a.getDoFunction(), a.getGrantAuthorization(), a.getModifiedBy(), a.getModifiedDate(), proxyUserName, false); } int lastCharIndex = xml.length(); xml.deleteCharAt(lastCharIndex - 1); xml.append("\r\n]}"); } } catch (Exception e) { Message = "permitws Web Service: " + e.getMessage(); log.error(Message); e.printStackTrace(); throw new permitException(e); } try { return (URLEncoder.encode(xml.toString(), "UTF-8")); } catch (Exception e) { throw new permitException(e.getLocalizedMessage()); } }
From source file:spade.reporter.Audit.java
private boolean addNetworkKernelModule(String kernelModulePath, String kernelModuleControllerPath, String uid, boolean ignoreUid, List<String> ignorePids, List<String> ignorePpids, boolean interceptSendRecv) { if (uid == null || uid.isEmpty() || ignorePids == null || ignorePids.isEmpty() || ignorePpids == null || ignorePpids.isEmpty()) {//w w w .j a v a 2 s .co m logger.log(Level.SEVERE, "Invalid args. uid={0}, pids={1}, ppids={2}", new Object[] { uid, ignorePids, ignorePpids }); return false; } else { try { if (!FileUtility.isFileReadable(kernelModulePath)) { logger.log(Level.SEVERE, "Kernel module path not readable: " + kernelModulePath); return false; } } catch (Exception e) { logger.log(Level.SEVERE, "Failed to check if kernel module path is readable: " + kernelModulePath, e); return false; } try { if (!FileUtility.isFileReadable(kernelModuleControllerPath)) { logger.log(Level.SEVERE, "Controller kernel module path not readable: " + kernelModuleControllerPath); return false; } } catch (Exception e) { logger.log(Level.SEVERE, "Failed to check if controller kernel module path is readable: " + kernelModuleControllerPath, e); return false; } String kernelModuleName = getKernelModuleName(kernelModulePath); if (kernelModuleName != null) { String kernelModuleControllerName = getKernelModuleName(kernelModuleControllerPath); if (kernelModuleControllerName != null) { Boolean kernelModuleControllerExists = kernelModuleExists(kernelModuleControllerName); if (kernelModuleControllerExists != null) { if (kernelModuleControllerExists) { logger.log(Level.SEVERE, "Kernel module controller '" + kernelModuleControllerPath + "' " + "already exists."); return false; } else { Boolean kernelModuleExists = kernelModuleExists(kernelModuleName); if (kernelModuleExists != null) { if (kernelModuleExists == false) { // add the main kernel module String kernelModuleAddCommand = "insmod " + kernelModulePath; if (!addKernelModule(kernelModuleAddCommand)) { return false; } } // add the controller kernel module StringBuffer pids = new StringBuffer(); ignorePids.forEach(ignorePid -> { pids.append(ignorePid).append(","); }); pids.deleteCharAt(pids.length() - 1);// delete trailing comma StringBuffer ppids = new StringBuffer(); ignorePpids.forEach(ignorePpid -> { ppids.append(ignorePpid).append(","); }); ppids.deleteCharAt(ppids.length() - 1);// delete trailing comma String ignoreUidsArg = ignoreUid ? "1" : "0"; // 0 is capture String kernelModuleControllerAddCommand = String.format( "insmod %s uids=\"%s\" syscall_success=\"1\" " + "pids_ignore=\"%s\" ppids_ignore=\"%s\" net_io=\"%s\" " + "ignore_uids=\"%s\"", kernelModuleControllerPath, uid, pids, ppids, interceptSendRecv ? "1" : "0", ignoreUidsArg); if (!addKernelModule(kernelModuleControllerAddCommand)) { return false; } else { return true; } } } } } } } return false; }
From source file:org.openhealthtools.mdht.uml.cda.core.util.CDAModelUtil.java
public static String computeConformanceMessage(Constraint constraint, boolean markup) { StringBuffer message = new StringBuffer(); String strucTextBody = null;/*from w ww.j a v a 2 s. c o m*/ String analysisBody = null; Map<String, String> langBodyMap = new HashMap<String, String>(); ValueSpecification spec = constraint.getSpecification(); if (spec instanceof OpaqueExpression) { for (int i = 0; i < ((OpaqueExpression) spec).getLanguages().size(); i++) { String lang = ((OpaqueExpression) spec).getLanguages().get(i); String body = ((OpaqueExpression) spec).getBodies().get(i); if ("StrucText".equals(lang)) { strucTextBody = body; } else if ("Analysis".equals(lang)) { analysisBody = body; } else { langBodyMap.put(lang, body); } } } String displayBody = null; if (strucTextBody != null && strucTextBody.trim().length() > 0) { // TODO if markup, parse strucTextBody and insert DITA markup displayBody = strucTextBody; } else if (analysisBody != null && analysisBody.trim().length() > 0) { if (markup) { // escape non-dita markup in analysis text displayBody = escapeMarkupCharacters(analysisBody); // change severity words to bold text displayBody = replaceSeverityWithBold(displayBody); } else { displayBody = analysisBody; } } if (!markup) { message.append(getPrefixedSplitName(constraint.getContext())).append(" "); } if (displayBody == null || !containsSeverityWord(displayBody)) { String keyword = getValidationKeyword(constraint); if (keyword == null) { keyword = "SHALL"; } message.append(markup ? "<b>" : ""); message.append(keyword); message.append(markup ? "</b>" : ""); message.append(" satisfy: "); } if (displayBody == null) { message.append(constraint.getName()); } else { message.append(displayBody); } appendConformanceRuleIds(constraint, message, markup); // include comment text only in markup output if (false && markup && constraint.getOwnedComments().size() > 0) { message.append("<ul>"); for (Comment comment : constraint.getOwnedComments()) { message.append("<li>"); message.append(fixNonXMLCharacters(comment.getBody())); message.append("</li>"); } message.append("</ul>"); } // Include other constraint languages, e.g. OCL or XPath if (false && langBodyMap.size() > 0) { message.append("<ul>"); for (String lang : langBodyMap.keySet()) { message.append("<li>"); message.append("<codeblock>[" + lang + "]: "); message.append(escapeMarkupCharacters(langBodyMap.get(lang))); message.append("</codeblock>"); message.append("</li>"); } message.append("</ul>"); } if (!markup) { // remove line feeds int index; while ((index = message.indexOf("\r")) >= 0) { message.deleteCharAt(index); } while ((index = message.indexOf("\n")) >= 0) { message.deleteCharAt(index); if (message.charAt(index) != ' ') { message.insert(index, " "); } } } return message.toString(); }