public TextRange surroundExpression( final Project project, final Editor editor, PsiExpression expr) throws IncorrectOperationException { assert expr.isValid(); PsiType[] types = GuessManager.getInstance(project).guessTypeToCast(expr); final boolean parenthesesNeeded = expr instanceof PsiPolyadicExpression || expr instanceof PsiConditionalExpression || expr instanceof PsiAssignmentExpression; String exprText = parenthesesNeeded ? "(" + expr.getText() + ")" : expr.getText(); final Template template = generateTemplate(project, exprText, types); TextRange range; if (expr.isPhysical()) { range = expr.getTextRange(); } else { final RangeMarker rangeMarker = expr.getUserData(ElementToWorkOn.TEXT_RANGE); if (rangeMarker == null) return null; range = new TextRange(rangeMarker.getStartOffset(), rangeMarker.getEndOffset()); } editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset()); editor.getCaretModel().moveToOffset(range.getStartOffset()); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); TemplateManager.getInstance(project).startTemplate(editor, template); return null; }
@Command( aliases = {"update", "u"}, parent = "r2w", helpLookup = "r2w update", description = "Update the template", permissions = {"r2w.command.update"}, toolTip = "/r2w update <world_name> <world_dimension> x1 y1 z1 x2 y2 z2", min = 9, max = 9) public void update(final MessageReceiver caller, final String[] parameters) throws InterruptedException, ExecutionException { final int x1 = Integer.parseInt(parameters[3]); final int y1 = Integer.parseInt(parameters[4]); final int z1 = Integer.parseInt(parameters[5]); final int x2 = Integer.parseInt(parameters[6]); final int y2 = Integer.parseInt(parameters[7]); final int z2 = Integer.parseInt(parameters[8]); final Future<Boolean> future = templateManager.update( parameters[1], DimensionType.fromName(parameters[2]), x1, y1, z1, x2, y2, z2); if (future.get()) { sendMessage(caller, "Completed updating template"); } else { sendMessage(caller, "Failed updating template"); } }
/** * Gets all People Containers under the organization. * * @return guids identifying People Containers under the organization * @exception UMSException Failure * @supported.api */ public Collection getPeopleContainerGuids() throws UMSException { Collection pcs = new ArrayList(); SearchTemplate template = TemplateManager.getTemplateManager() .getSearchTemplate("BasicPeopleContainerSearch", getGuid()); SearchResults results = search(template, null); while (results.hasMoreElements()) { pcs.add(results.next().getGuid()); } return pcs; }
private static Template generateTemplate( Project project, String exprText, final PsiType[] suggestedTypes) { final TemplateManager templateManager = TemplateManager.getInstance(project); final Template template = templateManager.createTemplate("", ""); template.setToReformat(true); Set<LookupElement> itemSet = new LinkedHashSet<>(); for (PsiType type : suggestedTypes) { itemSet.add(PsiTypeLookupItem.createLookupItem(type, null)); } final LookupElement[] lookupItems = itemSet.toArray(new LookupElement[itemSet.size()]); final Result result = suggestedTypes.length > 0 ? new PsiTypeResult(suggestedTypes[0], project) : null; Expression expr = new Expression() { @Override public LookupElement[] calculateLookupItems(ExpressionContext context) { return lookupItems.length > 1 ? lookupItems : null; } @Override public Result calculateResult(ExpressionContext context) { return result; } @Override public Result calculateQuickResult(ExpressionContext context) { return null; } }; template.addTextSegment("(("); template.addVariable(TYPE_TEMPLATE_VARIABLE, expr, expr, true); template.addTextSegment(")" + exprText + ")"); template.addEndVariable(); return template; }
@NonNull TemplateHandler getTemplateHandler() { if (mTemplateHandler == null) { File inputPath; if (mTemplateLocation != null) { inputPath = mTemplateLocation; } else { // Default inputPath = TemplateManager.getTemplateLocation(BLANK_ACTIVITY); } mTemplateHandler = TemplateHandler.createFromPath(inputPath); } return mTemplateHandler; }
private void parseAttributes(String keyword) throws IOException { if (templateManager == null) { templateManager = new TemplateManager(); } int token = nextToken(); if (token == '=') { String s = parseWord(); if (s.equals("compatibility") == false) { throw excLine("Expected 'compatibility', read " + s); } setCompatibilityAttributes(); return; } if (token != '(') { throw excToken("Expected '(' or '=', read"); } String op = parseOperation(); parseComma(); long objectClass = parseObjectClass(); parseComma(); long keyAlg = parseKeyAlgorithm(); token = nextToken(); if (token != ')') { throw excToken("Expected ')', read"); } parseEquals(); parseOpenBraces(); List<CK_ATTRIBUTE> attributes = new ArrayList<CK_ATTRIBUTE>(); while (true) { token = nextToken(); if (isCloseBraces(token)) { break; } if (token == TT_EOL) { continue; } if (token != TT_WORD) { throw excToken("Expected mechanism, read"); } String attributeName = st.sval; long attributeId = decodeAttributeName(attributeName); parseEquals(); String attributeValue = parseWord(); attributes.add(decodeAttributeValue(attributeId, attributeValue)); } templateManager.addTemplate(op, objectClass, keyAlg, attributes.toArray(CK_A0)); }
@Override public void init(IWorkbench workbench, IStructuredSelection selection) { super.init(workbench, selection); mValues = new NewTemplateWizardState(); File template = TemplateManager.getTemplateLocation(mTemplateName); if (template != null) { mValues.setTemplateLocation(template); } hideBuiltinParameters(); List<IProject> projects = AdtUtils.getSelectedProjects(selection); if (projects.size() == 1) { mValues.project = projects.get(0); } mMainPage = new NewTemplatePage(mValues, true); }
@Command( aliases = {"remove"}, parent = "r2w", helpLookup = "r2w remove", description = "Remove world template", permissions = {"r2w.command.remove"}, toolTip = "/r2w remove <world_name> <world_dimension>", min = 3, max = 3) public void removeTemplate(final MessageReceiver caller, final String[] parameters) throws IOException, InterruptedException, ExecutionException { final Future<Boolean> future = templateManager.removeTemplate(parameters[1], DimensionType.fromName(parameters[2])); if (future.get()) { sendMessage(caller, "Completed removing template"); } else { sendMessage(caller, "Failed removing template"); } }
public static void main(String[] args) { TemplateManager tm = TemplateManager.getInstance(); TemplateTree root = new TemplateTree(tm.get("word[0]")); TemplateTree t2 = new TemplateTree(tm.get("pos[-1]")); root.addChild(t2); t2.addChild(new Features()); TemplateTree t3 = new TemplateTree(tm.get("pos[0]")); root.addChild(t3); t3.addChild(new Features()); TemplateTree t4 = new TemplateTree(tm.get("pos[-1]")); t2.addChild(t4); t4.addChild(new Features()); Document doc = DocumentTester.getMockDocument(); Context ctx = new Context(doc, 1); ctx.token = 2; root.apply(ctx); System.out.println(ctx); }
/** * Constructs Organization object without a session. Unlike the constructor with a session * parameter , this one simply creates a Group object in memory, using the default template. Call * the save() method to save the object to the persistent store. * * @param attrSet attribute/value set */ Organization(AttrSet attrSet) throws UMSException { this(TemplateManager.getTemplateManager().getCreationTemplate(_class, null), attrSet); }
@Override @OutboundActionMeta(name = "alarm") public void handleOutbound(Context ctx) throws ServletException, IOException { Model model = new Model(ctx); Payload payload = ctx.getPayload(); Action action = payload.getAction(); int userId = getLoginUserId(ctx); boolean result = false; switch (action) { case ALARM_RECORD_LIST: m_recordManager.queryUserAlarmRecords(model, userId); break; case ALARM_RULE_ADD: m_ruleManager.ruleAdd(payload, model); break; case ALARM_RULE_ADD_SUBMIT: m_ruleManager.ruleAddSubmit(payload, model); break; case ALARM_RULE_UPDATE: m_ruleManager.ruleUpdate(payload, model); break; case ALARM_RULE_UPDATE_SUBMIT: m_ruleManager.ruleUpdateSubmit(payload, model); break; case EXCEPTION_ALARM_RULE_DELETE: m_ruleManager.ruleDelete(payload); m_ruleManager.queryExceptionRuleList(model, userId); break; case EXCEPTION_ALARM_RULE_SUB: result = m_ruleManager.ruleSub(payload, userId); if (result) { model.setOpState(SUCCESS); } else { model.setOpState(FAIL); } break; case EXCEPTION_ALARM_RULE_LIST: m_ruleManager.queryExceptionRuleList(model, userId); break; case ALARM_TEMPLATE_LIST: m_templateManager.queryTemplateByName(payload, model); break; case ALARM_TEMPLATE_ADD: break; case ALARM_TEMPLATE_ADD_SUBMIT: m_templateManager.templateAddSubmit(payload, model); break; case ALARM_TEMPLATE_DELETE: break; case ALARM_TEMPLATE_UPDATE: m_templateManager.templateUpdate(payload, model); break; case ALARM_TEMPLATE_UPDATE_SUBMIT: m_templateManager.templateUpdateSubmit(payload, model); break; case SERVICE_ALARM_RULE_DELETE: m_ruleManager.ruleDelete(payload); m_ruleManager.queryServiceRuleList(model, userId); break; case SERVICE_ALARM_RULE_LIST: m_ruleManager.queryServiceRuleList(model, userId); break; case SERVICE_ALARM_RULE_SUB: result = m_ruleManager.ruleSub(payload, userId); if (result) { model.setOpState(SUCCESS); } else { model.setOpState(FAIL); } break; case ALARM_RECORD_DETAIL: m_recordManager.queryAlarmRecordDetail(payload, model); break; case SCHEDULED_REPORT_ADD: m_scheduledManager.scheduledReportAdd(payload, model); break; case SCHEDULED_REPORT_ADD_SUBMIT: m_scheduledManager.scheduledReportAddSubmit(payload, model); break; case SCHEDULED_REPORT_DELETE: m_scheduledManager.scheduledReportDelete(payload); m_scheduledManager.queryScheduledReports(model, userId); break; case SCHEDULED_REPORT_LIST: m_scheduledManager.queryScheduledReports(model, userId); break; case SCHEDULED_REPORT_UPDATE: m_scheduledManager.scheduledReportUpdate(payload, model); break; case SCHEDULED_REPORT_UPDATE_SUBMIT: m_scheduledManager.scheduledReportUpdateSubmit(payload, model); break; case SCHEDULED_REPORT_SUB: result = m_scheduledManager.scheduledReportSub(payload, userId); if (result) { model.setOpState(SUCCESS); } else { model.setOpState(FAIL); } break; case REPORT_RECORD_LIST: m_recordManager.queryUserReportRecords(model, userId); break; } model.setAction(payload.getAction()); model.setPage(SystemPage.ALARM); m_jspViewer.view(ctx, model); }
@SuppressWarnings(value = "unchecked") public String execute(Map root) throws IOException, TemplateException { return nullTemplate ? null : manager.execute(TEMPLATE_NAME, root); }
public SingleTemplateManager(String template) { if (template != null) { nullTemplate = false; manager.addTemplate(TEMPLATE_NAME, template); } }
@Command( aliases = {"restore", "r"}, parent = "r2w", helpLookup = "r2w restore", description = "Restore from template", permissions = {"r2w.command.restore"}, toolTip = "/r2w restore [world_name world_dimension] [x1 y1 z1 [x2 y2 z2]]", min = 1, max = 9) public void restore(final MessageReceiver caller, final String[] parameters) throws InterruptedException, ExecutionException { boolean set = false; String world = null; String dimension = null; int x1 = 0; int y1 = 0; int z1 = 0; int x2 = 0; int y2 = 0; int z2 = 0; if (caller instanceof Player) { final Player player = (Player) caller; if (parameters.length == 1) { final Block block = getBlockLookingAt(player); world = block.getWorld().getName(); dimension = block.getWorld().getType().getName(); x1 = x2 = block.getX(); y1 = y2 = block.getY(); z1 = z2 = block.getZ(); set = true; } else if (parameters.length == 4) { world = player.getWorld().getName(); dimension = player.getWorld().getType().getName(); x1 = x2 = Integer.parseInt(parameters[2]); y1 = y2 = Integer.parseInt(parameters[3]); z1 = z2 = Integer.parseInt(parameters[4]); set = true; } else if (parameters.length == 7) { world = player.getWorld().getName(); dimension = player.getWorld().getType().getName(); x1 = Integer.parseInt(parameters[2]); y1 = Integer.parseInt(parameters[3]); z1 = Integer.parseInt(parameters[4]); x2 = Integer.parseInt(parameters[5]); y2 = Integer.parseInt(parameters[6]); z2 = Integer.parseInt(parameters[7]); set = true; } } if (!set) { world = parameters[1]; dimension = parameters[2]; x1 = Integer.parseInt(parameters[3]); y1 = Integer.parseInt(parameters[4]); z1 = Integer.parseInt(parameters[5]); x2 = Integer.parseInt(parameters[6]); y2 = Integer.parseInt(parameters[7]); z2 = Integer.parseInt(parameters[8]); } final Future<Boolean> future = templateManager.restore(world, DimensionType.fromName(dimension), x1, y1, z1, x2, y2, z2); if (future.get()) { sendMessage(caller, "Completed restoring template"); } else { sendMessage(caller, "Failed restoring template"); } }
private void setCompatibilityAttributes() { // all secret keys templateManager.addTemplate( O_ANY, CKO_SECRET_KEY, PCKK_ANY, new CK_ATTRIBUTE[] { TOKEN_FALSE, SENSITIVE_FALSE, EXTRACTABLE_TRUE, ENCRYPT_TRUE, DECRYPT_TRUE, WRAP_TRUE, UNWRAP_TRUE, }); // generic secret keys are special // They are used as MAC keys plus for the SSL/TLS (pre)master secrets templateManager.addTemplate( O_ANY, CKO_SECRET_KEY, CKK_GENERIC_SECRET, new CK_ATTRIBUTE[] { SIGN_TRUE, VERIFY_TRUE, ENCRYPT_NULL, DECRYPT_NULL, WRAP_NULL, UNWRAP_NULL, DERIVE_TRUE, }); // all private and public keys templateManager.addTemplate( O_ANY, CKO_PRIVATE_KEY, PCKK_ANY, new CK_ATTRIBUTE[] { TOKEN_FALSE, SENSITIVE_FALSE, EXTRACTABLE_TRUE, }); templateManager.addTemplate( O_ANY, CKO_PUBLIC_KEY, PCKK_ANY, new CK_ATTRIBUTE[] { TOKEN_FALSE, }); // additional attributes for RSA private keys templateManager.addTemplate( O_ANY, CKO_PRIVATE_KEY, CKK_RSA, new CK_ATTRIBUTE[] { DECRYPT_TRUE, SIGN_TRUE, SIGN_RECOVER_TRUE, UNWRAP_TRUE, }); // additional attributes for RSA public keys templateManager.addTemplate( O_ANY, CKO_PUBLIC_KEY, CKK_RSA, new CK_ATTRIBUTE[] { ENCRYPT_TRUE, VERIFY_TRUE, VERIFY_RECOVER_TRUE, WRAP_TRUE, }); // additional attributes for DSA private keys templateManager.addTemplate( O_ANY, CKO_PRIVATE_KEY, CKK_DSA, new CK_ATTRIBUTE[] { SIGN_TRUE, }); // additional attributes for DSA public keys templateManager.addTemplate( O_ANY, CKO_PUBLIC_KEY, CKK_DSA, new CK_ATTRIBUTE[] { VERIFY_TRUE, }); // additional attributes for DH private keys templateManager.addTemplate( O_ANY, CKO_PRIVATE_KEY, CKK_DH, new CK_ATTRIBUTE[] { DERIVE_TRUE, }); // additional attributes for EC private keys templateManager.addTemplate( O_ANY, CKO_PRIVATE_KEY, CKK_EC, new CK_ATTRIBUTE[] { SIGN_TRUE, DERIVE_TRUE, }); // additional attributes for EC public keys templateManager.addTemplate( O_ANY, CKO_PUBLIC_KEY, CKK_EC, new CK_ATTRIBUTE[] { VERIFY_TRUE, }); }