List of usage examples for org.apache.wicket.util.io IOUtils toString
public static String toString(final Reader input) throws IOException
Reader as a String. From source file:ca.travelagency.VelocityTemplateHelper.java
License:Apache License
public String getExpected(InputStream inputStream) throws Exception { return cleanupString(IOUtils.toString(inputStream)); }
From source file:com.gitblit.auth.RedmineAuthProvider.java
License:Apache License
private String getCurrentUserAsJson(String username, char[] password) throws IOException { if (testingJson != null) { // for testing return testingJson; }/*from ww w . ja v a2 s .c o m*/ String url = this.settings.getString(Keys.realm.redmine.url, ""); if (!url.endsWith("/")) { url = url.concat("/"); } HttpURLConnection http; if (username == null) { // apikey authentication String apiKey = String.valueOf(password); String apiUrl = url + "users/current.json?key=" + apiKey; http = (HttpURLConnection) ConnectionUtils.openConnection(apiUrl, null, null); } else { // username/password BASIC authentication String apiUrl = url + "users/current.json"; http = (HttpURLConnection) ConnectionUtils.openConnection(apiUrl, username, password); } http.setRequestMethod("GET"); http.connect(); InputStreamReader reader = new InputStreamReader(http.getInputStream()); return IOUtils.toString(reader); }
From source file:com.google.code.jqwicket.SourcePanel.java
License:Apache License
private String getSource(String url) { try {/*from w ww .ja v a 2s. com*/ InputStream in = SourcePanel.class.getResourceAsStream(url); if (in == null) return "not available"; return IOUtils.toString(in); } catch (IOException e) { e.printStackTrace(); return "not available"; } }
From source file:com.zh.snmp.snmpweb.pages.snmp.DeviceConfigEditPanel.java
License:Open Source License
@Override protected boolean onModalSave(AjaxRequestTarget target) { String errKey = null;//from w ww .j av a2 s. c o m DeviceConfigEntity saveable = (DeviceConfigEntity) form.getDefaultModelObject(); DeviceConfigEntity checkCode = service.findConfigEntityByCode(saveable.getId()); if (checkCode != null && !checkCode.getId().equals(saveable.getId())) { errKey = "deviceConfigEntity.error.codeExists"; } else if (saveable.getId() == null) { FileUpload upload = file.getFileUpload(); InputStream is = null; try { is = upload.getInputStream(); saveable.setSnmpDescriptor(IOUtils.toString(is)); } catch (IOException e) { IOUtils.closeQuietly(is); errKey = "fileUpload.exception"; } } if (errKey != null) { error(getString(errKey)); target.addComponent(feedback); return false; } else { service.saveEntity(saveable); return true; } }
From source file:org.apache.syncope.client.console.init.MIMETypesLoader.java
License:Apache License
public void load() { if (CollectionUtils.isEmpty(mimeTypes)) { Set<String> mediaTypes = new HashSet<>(); this.mimeTypes = new ArrayList<>(); try {// w ww . j a v a 2 s . c o m final String mimeTypesFile = IOUtils.toString(getClass().getResourceAsStream("/MIMETypes")); for (String fileRow : mimeTypesFile.split("\n")) { if (StringUtils.isNotBlank(fileRow) && !fileRow.startsWith("#")) { mediaTypes.add(fileRow); } } this.mimeTypes.addAll(mediaTypes); Collections.sort(this.mimeTypes); } catch (Exception e) { LOG.error("Error reading file MIMETypes from resources", e); } } }
From source file:org.apache.syncope.client.console.pages.XMLEditorPopupPage.java
License:Apache License
public XMLEditorPopupPage() { Form wfForm = new Form("workflowDefForm"); String definition;/*from w w w . j a v a 2s. co m*/ try { definition = IOUtils.toString(wfRestClient.getDefinition(MediaType.APPLICATION_XML_TYPE)); } catch (IOException e) { LOG.error("Could not get workflow definition", e); definition = StringUtils.EMPTY; } final TextArea<String> workflowDefArea = new TextArea<String>("workflowDefArea", new Model<String>(definition)); wfForm.add(workflowDefArea); AjaxButton submit = new ClearIndicatingAjaxButton(APPLY, new Model<String>(getString(SUBMIT)), getPageReference()) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmitInternal(final AjaxRequestTarget target, final Form<?> form) { try { wfRestClient.updateDefinition(MediaType.APPLICATION_XML_TYPE, workflowDefArea.getModelObject()); info(getString(Constants.OPERATION_SUCCEEDED)); } catch (SyncopeClientException scee) { error(getString(Constants.ERROR) + ": " + scee.getMessage()); } feedbackPanel.refresh(target); } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; final Button close = new Button("closePage", new Model<String>(getString(CANCEL))); MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, xmlRolesReader.getEntitlement("Configuration", "workflowDefUpdate")); wfForm.add(submit); wfForm.add(close); this.add(wfForm); }
From source file:org.apache.syncope.client.console.panels.ImplementationModalPanel.java
License:Apache License
public ImplementationModalPanel(final BaseModal<ImplementationTO> modal, final ImplementationTO implementation, final PageReference pageRef) { super(modal, pageRef); this.implementation = implementation; this.viewMode = implementation.getEngine() == ImplementationEngine.GROOVY ? ViewMode.GROOVY_BODY : implementation.getType() == ImplementationType.REPORTLET || implementation.getType() == ImplementationType.ACCOUNT_RULE || implementation.getType() == ImplementationType.PASSWORD_RULE || implementation.getType() == ImplementationType.PULL_CORRELATION_RULE ? ViewMode.JSON_BODY : ViewMode.JAVA_CLASS; this.create = implementation.getKey() == null; add(new AjaxTextFieldPanel("key", "key", new PropertyModel<>(implementation, "key"), false) .addRequiredLabel().setEnabled(create)); List<String> classes = Collections.emptyList(); if (viewMode == ViewMode.JAVA_CLASS) { Optional<JavaImplInfo> javaClasses = SyncopeConsoleSession.get().getPlatformInfo() .getJavaImplInfo(implementation.getType()); classes = javaClasses.isPresent() ? new ArrayList<>(javaClasses.get().getClasses()) : new ArrayList<>(); } else if (viewMode == ViewMode.JSON_BODY) { ClassPathScanImplementationLookup implementationLookup = (ClassPathScanImplementationLookup) SyncopeConsoleApplication .get().getServletContext().getAttribute(ConsoleInitializer.CLASSPATH_LOOKUP); switch (implementation.getType()) { case REPORTLET: classes = implementationLookup.getReportletConfs().keySet().stream().collect(Collectors.toList()); break; case ACCOUNT_RULE: classes = implementationLookup.getAccountRuleConfs().keySet().stream().collect(Collectors.toList()); break; case PASSWORD_RULE: classes = implementationLookup.getPasswordRuleConfs().keySet().stream() .collect(Collectors.toList()); break; case PULL_CORRELATION_RULE: classes = implementationLookup.getPullCorrelationRuleConfs().keySet().stream() .collect(Collectors.toList()); break; default:/*ww w. j a v a2 s .co m*/ } } Collections.sort(classes); AjaxDropDownChoicePanel<String> javaClass = new AjaxDropDownChoicePanel<>("javaClass", "Class", new PropertyModel<>(implementation, "body")); javaClass.setNullValid(false); javaClass.setChoices(classes); javaClass.addRequiredLabel(); javaClass.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true); javaClass.setVisible(viewMode == ViewMode.JAVA_CLASS); add(javaClass); AjaxDropDownChoicePanel<String> jsonClass = new AjaxDropDownChoicePanel<>("jsonClass", "Class", new Model<>()); jsonClass.setNullValid(false); jsonClass.setChoices(classes); jsonClass.addRequiredLabel(); jsonClass.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true); jsonClass.setVisible(viewMode == ViewMode.JSON_BODY); if (viewMode == ViewMode.JSON_BODY && StringUtils.isNotBlank(implementation.getBody())) { try { JsonNode node = MAPPER.readTree(implementation.getBody()); if (node.has("@class")) { jsonClass.setModelObject(node.get("@class").asText()); } } catch (IOException e) { LOG.error("Could not parse as JSON payload: {}", implementation.getBody(), e); } } jsonClass.setReadOnly(jsonClass.getModelObject() != null); add(jsonClass); WebMarkupContainer groovyClassContainer = new WebMarkupContainer("groovyClassContainer"); groovyClassContainer.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true); groovyClassContainer.setVisible(viewMode != ViewMode.JAVA_CLASS); add(groovyClassContainer); if (StringUtils.isBlank(implementation.getBody()) && implementation.getEngine() == ImplementationEngine.GROOVY) { String templateClassName = null; switch (implementation.getType()) { case REPORTLET: templateClassName = "MyReportlet"; break; case ACCOUNT_RULE: templateClassName = "MyAccountRule"; break; case PASSWORD_RULE: templateClassName = "MyPasswordRule"; break; case ITEM_TRANSFORMER: templateClassName = "MyItemTransformer"; break; case TASKJOB_DELEGATE: templateClassName = "MySchedTaskJobDelegate"; break; case RECON_FILTER_BUILDER: templateClassName = "MyReconFilterBuilder"; break; case LOGIC_ACTIONS: templateClassName = "MyLogicActions"; break; case PROPAGATION_ACTIONS: templateClassName = "MyPropagationActions"; break; case PULL_ACTIONS: templateClassName = "MyPullActions"; break; case PUSH_ACTIONS: templateClassName = "MyPushActions"; break; case PULL_CORRELATION_RULE: templateClassName = "MyPullCorrelationRule"; break; case VALIDATOR: templateClassName = "MyValidator"; break; case RECIPIENTS_PROVIDER: templateClassName = "MyRecipientsProvider"; break; default: } if (templateClassName != null) { try { implementation.setBody(StringUtils.substringAfter(IOUtils.toString( getClass().getResourceAsStream("/org/apache/syncope/client/console/implementations/" + templateClassName + ".groovy")), "*/\n")); } catch (IOException e) { LOG.error("Could not load the expected Groovy template {} for {}", templateClassName, implementation.getType(), e); } } } TextArea<String> groovyClass = new TextArea<>("groovyClass", new PropertyModel<>(implementation, "body")); groovyClass.setMarkupId("groovyClass").setOutputMarkupPlaceholderTag(true); groovyClass.setVisible(viewMode != ViewMode.JAVA_CLASS); groovyClass.setRequired(true); groovyClassContainer.add(groovyClass); jsonClass.add(new AjaxEventBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = 5538299138211283825L; @Override protected void onEvent(final AjaxRequestTarget target) { ClassPathScanImplementationLookup implementationLookup = (ClassPathScanImplementationLookup) SyncopeConsoleApplication .get().getServletContext().getAttribute(ConsoleInitializer.CLASSPATH_LOOKUP); Class<?> clazz = null; switch (implementation.getType()) { case REPORTLET: clazz = implementationLookup.getReportletConfs().get(jsonClass.getModelObject()); break; case ACCOUNT_RULE: clazz = implementationLookup.getAccountRuleConfs().get(jsonClass.getModelObject()); break; case PASSWORD_RULE: clazz = implementationLookup.getPasswordRuleConfs().get(jsonClass.getModelObject()); break; case PULL_CORRELATION_RULE: clazz = implementationLookup.getPullCorrelationRuleConfs().get(jsonClass.getModelObject()); break; default: } if (clazz != null) { try { target.appendJavaScript("editor.getDoc().setValue('" + MAPPER.writeValueAsString(clazz.newInstance()) + "');"); } catch (Exception e) { LOG.error("Could not generate a value for {}", jsonClass.getModelObject(), e); } } } }); }
From source file:org.apache.syncope.client.console.panels.WorkflowDirectoryPanel.java
License:Apache License
@Override public ActionsPanel<WorkflowDefinitionTO> getActions(final IModel<WorkflowDefinitionTO> model) { final ActionsPanel<WorkflowDefinitionTO> panel = super.getActions(model); panel.add(new ActionLink<WorkflowDefinitionTO>() { private static final long serialVersionUID = -184018732772021627L; @Override// w w w .ja v a 2 s . c om public void onClick(final AjaxRequestTarget target, final WorkflowDefinitionTO ignore) { final IModel<String> wfDefinition = new Model<>(); try { wfDefinition.setObject(IOUtils.toString( restClient.getDefinition(MediaType.APPLICATION_XML_TYPE, model.getObject().getKey()))); } catch (IOException e) { LOG.error("Could not get workflow definition", e); } utility.header(Model.of(model.getObject().getKey())); utility.setContent(new XMLEditorPanel(utility, wfDefinition, false, pageRef) { private static final long serialVersionUID = -7688359318035249200L; @Override public void onSubmit(final AjaxRequestTarget target, final Form<?> form) { if (StringUtils.isNotBlank(wfDefinition.getObject())) { try { restClient.setDefinition(MediaType.APPLICATION_XML_TYPE, model.getObject().getKey(), wfDefinition.getObject()); SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED)); target.add(container); utility.show(false); utility.close(target); } catch (SyncopeClientException e) { SyncopeConsoleSession.get() .error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage()); } ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target); } } }); utility.show(target); target.add(utility); } }, ActionLink.ActionType.EDIT, StandardEntitlement.WORKFLOW_DEF_SET); panel.add(new ActionLink<WorkflowDefinitionTO>() { private static final long serialVersionUID = 3109256773218160485L; @Override public void onClick(final AjaxRequestTarget target, final WorkflowDefinitionTO ignore) { modal.header(Model.of(model.getObject().getKey())); modal.setContent( new ImageModalPanel<>(modal, restClient.getDiagram(model.getObject().getKey()), pageRef)); modal.show(target); target.add(modal); } }, ActionLink.ActionType.VIEW, StandardEntitlement.WORKFLOW_DEF_GET); panel.add(new ActionLink<WorkflowDefinitionTO>() { private static final long serialVersionUID = -184018732772021627L; @Override public Class<? extends Page> getPageClass() { return ModelerPopupPage.class; } @Override public PageParameters getPageParameters() { PageParameters parameters = new PageParameters(); if (modelerCtx != null) { parameters.add(Constants.MODELER_CONTEXT, modelerCtx); } parameters.add(Constants.MODEL_ID_PARAM, model.getObject().getModelId()); return parameters; } @Override protected boolean statusCondition(final WorkflowDefinitionTO modelObject) { return modelerCtx != null; } @Override public void onClick(final AjaxRequestTarget target, final WorkflowDefinitionTO ignore) { // do nothing } }, ActionLink.ActionType.WORKFLOW_MODELER, StandardEntitlement.WORKFLOW_DEF_SET); panel.add(new ActionLink<WorkflowDefinitionTO>() { private static final long serialVersionUID = -7978723352517770644L; @Override protected boolean statusCondition(final WorkflowDefinitionTO modelObject) { return !modelObject.isMain(); } @Override public void onClick(final AjaxRequestTarget target, final WorkflowDefinitionTO ignore) { try { restClient.deleteDefinition(model.getObject().getKey()); SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED)); target.add(container); } catch (SyncopeClientException e) { LOG.error("While deleting workflow definition {}", model.getObject().getName(), e); SyncopeConsoleSession.get() .error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage()); } ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target); } }, ActionLink.ActionType.DELETE, StandardEntitlement.WORKFLOW_DEF_DELETE, true); return panel; }
From source file:org.apache.syncope.client.console.panels.XMLWorkflowEditorModalPanel.java
License:Apache License
public XMLWorkflowEditorModalPanel(final BaseModal<String> modal, final WorkflowRestClient wfRestClient, final PageReference pageRef) { super(modal, pageRef); this.wfRestClient = wfRestClient; try {//from ww w. j av a2s . c o m wfDefinition = IOUtils.toString(wfRestClient.getDefinition(MediaType.APPLICATION_XML_TYPE)); } catch (IOException e) { LOG.error("Could not get workflow definition", e); wfDefinition = StringUtils.EMPTY; } workflowDefArea = new TextArea<>("workflowDefArea", new Model<>(wfDefinition)); add(workflowDefArea); }
From source file:org.apache.syncope.client.console.resources.WorkflowDefPUTResource.java
License:Apache License
@Override protected ResourceResponse newResourceResponse(final Attributes attributes) { String definition = null;/*from ww w .ja va 2 s . c om*/ try { HttpServletRequest request = (HttpServletRequest) attributes.getRequest().getContainerRequest(); String requestBody = IOUtils.toString(request.getInputStream()); String[] split = requestBody.split("&"); for (int i = 0; i < split.length && definition == null; i++) { String keyValue = split[i]; if (keyValue.startsWith("json_xml=")) { definition = UrlUtils.urlDecode(keyValue.split("=")[1]); } } } catch (IOException e) { LOG.error("Could not extract workflow definition from request", e); } new WorkflowRestClient().updateDefinition(MediaType.APPLICATION_JSON_TYPE, definition); ResourceResponse response = new ResourceResponse(); response.setStatusCode(204); return response; }