List of usage examples for java.security InvalidParameterException InvalidParameterException
public InvalidParameterException(String msg)
From source file:org.xwoot.xwootUtil.FileUtil.java
/** * Checks if the given directory path exists and if it's a valid and writable directory. If it doesn't exist, it is * created.// w ww .ja va2 s.c om * * @param directoryPath the path to check. * @throws IOException if the directory did not exist and can not be created. It is also thrown if the path is valid * but not writable. * @throws InvalidParameterException if the given path is valid but it points to a file instead of pointing to a * directory. * @throws NullPointerException if the directoryPath is null. */ public static void checkDirectoryPath(String directoryPath) throws IOException, InvalidParameterException { if (directoryPath == null) { throw new NullPointerException("The provided directoryPath is null."); } File directory = new File(directoryPath); if (!directory.exists()) { if (!directory.mkdirs()) { throw new IOException("Can't create directory: " + directoryPath); } } else if (!directory.isDirectory()) { throw new InvalidParameterException(directoryPath + " -- is not a directory"); } else if (!directory.canWrite()) { throw new IOException(directoryPath + " -- isn't writable"); } }
From source file:com.ca.dvs.app.dvs_servlet.resources.RAML.java
/** * Produce a CA LISA/DevTest Virtual Service Image (VSI) from an uploaded RAML file * <p>/*from w w w . j a va 2 s .c o m*/ * @param uploadedInputStream the file content associated with the RAML file upload * @param fileDetail the file details associated with the RAML file upload * @param baseUri the baseUri to use in the returned WADL file. Optionally provided, this will override that which is defined in the uploaded RAML. * @param generateServiceDocument when true, the VSI transformation will include a service document transaction defined. (default: false) * @return HTTP response containing the VSI transformation from the uploaded RAML file */ @POST @Path("vsi") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_XML) public Response genVsi(@DefaultValue("") @FormDataParam("file") InputStream uploadedInputStream, @DefaultValue("") @FormDataParam("file") FormDataContentDisposition fileDetail, @DefaultValue("") @FormDataParam("baseUri") String baseUri, @DefaultValue("false") @FormDataParam("generateServiceDocument") Boolean generateServiceDocument) { log.info("POST raml/vsi"); Response response = null; File uploadedFile = null; File ramlFile = null; FileInputStream ramlFileStream = null; try { if (fileDetail == null || fileDetail.getFileName() == null || fileDetail.getName() == null) { throw new InvalidParameterException("file"); } if (!baseUri.isEmpty()) { // validate URI syntax try { new URI(baseUri); } catch (URISyntaxException uriEx) { throw new InvalidParameterException(String.format("baseUri - %s", uriEx.getMessage())); } } uploadedFile = FileUtil.getUploadedFile(uploadedInputStream, fileDetail); if (uploadedFile.isDirectory()) { // find RAML file in directory // First, look for a raml file that has the same base name as the uploaded file String targetName = Files.getNameWithoutExtension(fileDetail.getFileName()) + ".raml"; ramlFile = FileUtil.selectRamlFile(uploadedFile, targetName); } else { ramlFile = uploadedFile; } List<ValidationResult> results = null; try { results = RamlUtil.validateRaml(ramlFile); } catch (IOException e) { String msg = String.format("RAML validation failed catastrophically for %s", ramlFile.getName()); throw new Exception(msg, e.getCause()); } // If the RAML file is valid, get to work... if (ValidationResult.areValid(results)) { try { ramlFileStream = new FileInputStream(ramlFile.getAbsolutePath()); } catch (FileNotFoundException e) { String msg = String.format("Failed to open input stream from %s", ramlFile.getAbsolutePath()); throw new Exception(msg, e.getCause()); } FileResourceLoader resourceLoader = new FileResourceLoader(ramlFile.getParentFile()); RamlDocumentBuilder rdb = new RamlDocumentBuilder(resourceLoader); Raml raml = rdb.build(ramlFileStream, ramlFile.getAbsolutePath()); ramlFileStream.close(); ramlFileStream = null; if (!baseUri.isEmpty()) { raml.setBaseUri(baseUri); } VSI vsi = new VSI(raml, ramlFile.getParentFile(), generateServiceDocument); Document doc = null; doc = vsi.getDocument(); StringWriter stringWriter = new StringWriter(); VSI.prettyPrint(doc, stringWriter); response = Response.status(Status.OK).entity(stringWriter.toString()).build(); } else { // RAML file failed validation StringBuilder sb = new StringBuilder(); for (ValidationResult result : results) { sb.append(result.getLevel()); if (result.getLine() > 0) { sb.append(String.format(" (line %d)", result.getLine())); } sb.append(String.format(" - %s\n", result.getMessage())); } response = Response.status(Status.BAD_REQUEST).entity(sb.toString()).build(); } } catch (Exception ex) { ex.printStackTrace(); String msg = ex.getMessage(); log.error(msg, ex.getCause()); if (ex instanceof JsonSyntaxException) { response = Response.status(Status.BAD_REQUEST).entity(msg).build(); } else if (ex instanceof InvalidParameterException) { response = Response.status(Status.BAD_REQUEST) .entity(String.format("Invalid form parameter - %s", ex.getMessage())).build(); } else { response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } return response; } finally { if (null != ramlFileStream) { try { ramlFileStream.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != uploadedFile) { if (uploadedFile.isDirectory()) { try { System.gc(); // To help release files that snakeyaml abandoned open streams on -- otherwise, some files may not delete // Wait a bit for the system to close abandoned streams try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } FileUtils.deleteDirectory(uploadedFile); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { uploadedFile.delete(); } } } return response; }
From source file:com.appnativa.rare.ui.chart.jfreechart.ChartHandler.java
protected JFreeChart createCharts(ChartPanel chartPanel, ChartDefinition cd) { List<DataSetValue> datasets = createDataSets(cd); int len = datasets.size(); UIFont f = getAxisLabelFont(cd.getRangeAxis()); UIFontMetrics fm = UIFontMetrics.getMetrics(f); tickSize = (int) fm.getHeight(); if (cd.getChartType() == ChartType.PIE) { PiePlot plot;/*from ww w .j a v a2s . c o m*/ PieCollection pie = (PieCollection) datasets.get(0).dataset; if (cd.isDraw3D()) { plot = new PiePlot3D(pie); } else { plot = new PiePlot(pie); } customizePiePlot(cd, plot, pie); return new JFreeChart(null, getChartFont(), plot, false); } ChartInfo ci = (ChartInfo) cd.getChartHandlerInfo(); XYPlot xyplot = null; NumberAxis yAxis = cd.isDraw3D() ? new NumberAxis3DEx(cd, true, cd.getRangeLabel()) : new NumberAxisEx(cd, false, cd.getRangeLabel()); yAxis.setAutoRangeIncludesZero(false); yAxis.setAutoRange(false); NumberAxis xAxis; if (ci.categoryDomain) { LabelData[] labels = ci.createLabelData(cd, fm, true); xAxis = cd.isDraw3D() ? new NumberAxis3DEx(cd, true, cd.getDomainLabel()) : new NumberAxisEx(cd, labels, cd.getDomainLabel()); } else { xAxis = cd.isDraw3D() ? new NumberAxis3DEx(cd, true, cd.getDomainLabel()) : new NumberAxisEx(cd, true, cd.getDomainLabel()); } xAxis.setAutoRangeIncludesZero(false); xAxis.setAutoRange(false); xyplot = new XYPlotEx(null, xAxis, yAxis, null); for (int i = 0; i < len; i++) { DataSetValue dv = datasets.get(i); xyplot.setDataset(i, (XYDataset) dv.dataset); switch (dv.chartType) { case SPLINE: xyplot.setRenderer(i, new XYSplineRendererEx(ci.seriesData)); break; case LINE: xyplot.setRenderer(i, cd.isDraw3D() ? new XYLine3DRendererEx(ci.seriesData) : new XYLineAndShapeRendererEx(ci.seriesData)); break; case BAR: { XYClusteredBarRendererEx renderer = new XYClusteredBarRendererEx(ci.seriesData); renderer.setShadowVisible(false); xyplot.setRenderer(i, renderer); } break; case STACKED_BAR: { StackedXYBarRenderer renderer = new XYStackedBarRendererEx(0.10, ci.seriesData); renderer.setDrawBarOutline(false); renderer.setShadowVisible(false); xyplot.setRenderer(i, renderer); } break; case RANGE_AREA: xyplot.setRenderer(i, new XYRangeAreaRendererEx(ci.seriesData)); break; case RANGE_BAR: xyplot.setRenderer(i, new XYRangeBarRendererEx(ci.seriesData)); break; case STACKED_AREA: XYStackedAreaRendererEx renderer = new XYStackedAreaRendererEx(ci.seriesData); renderer.setOutline(false); xyplot.setRenderer(i, renderer); break; case SPLINE_AREA: case AREA: XYItemRenderer r; if (dv.chartType == ChartType.SPLINE_AREA) { r = new XYAreaSplineRendererEx(ci.seriesData); } else { r = new XYAreaRendererEx(ci.seriesData); } xyplot.setRenderer(r); break; default: throw new InvalidParameterException("Unsupported chart type"); } } customizeXYPlot(chartPanel, cd, xyplot); JFreeChart chart = new JFreeChart(null, getChartFont(), xyplot, false); return chart; }
From source file:org.easyxml.xml.Element.java
/** * //ww w .ja v a 2 s . com * Set the values of innerText/attribute/childElements/childAttributes * specified by 'path'. * * This would facilitate creation of a layered DOM tree conveniently. * * For example, run setValuesOf("Child>GrandChild<Id", "1st", "2nd") of an * empty element would: * * 1) Create a new <Child> element; * * 2) Create TWO new <GrandChild> element under the newly created <Child> * element; * * 3) First <GrandChild> element would have "Id" attribute of "1st", and * second <GrandChild> of "2nd". * * If then call setValuesOf("Child>GrandChild<Id", "1", "2", "3"), no a new * <GrandChild> element would be created * * and the attribute values of these <GrandChild> elements would be set to * "1", "2" and "3" respectively. * * @param path * - The whole path of a Element or a Attribute. * * For example, "SOAP:Envelope>SOAP:Body>Child" denotes <Child> * element/elements under <SOAP:Body>. * * "SOAP:Envelope>SOAP:Body>Child<Attr" denotes the "Attr" * attribute of the above <Child> element/elements. * * @param values * - The values to be set when 'path': * * 1) equals to "Value": then set the new value of the innerText * of this element. * * 2) equals to some existing attribute name: then set the new * value of that attribute. * * 3) is parsed as some elements, then their innerText would be * set. * * 4) is parsed as some attributes, then these attribute values * would be set. * * @return 'true' if setting is successful, 'false' if failed. */ public Boolean setValuesOf(String path, String... values) { try { if (path == Value) { if (values.length != 1) throw new InvalidParameterException( "Only one String value is expected to set the value of this element"); // Change the innerText value of this element setValue(values[0]); return true; } else if (attributes != null && attributes.containsKey(path)) { if (values.length != 1) throw new InvalidParameterException( "Only one String value is expected to set the attribute value."); // Set the attribute value of this element setAttributeValue(path, values[0]); return true; } String[] segments = parsePath(path); String elementPath = segments[0]; // Try to treat the path as a key to its direct children elements // first List<Element> elements = getElementsOf(elementPath); Element newElement = null; if (elements == null) { // 'path' is not a key for its own direct children, thus split // it with '>' // For instance, "Child>GrandChild" would be split to {"Child", // "GrandChild"} then this element would: // 1) search "Child" as its direct children elements; // 2) if no <Child> element exists, create one; // 3) search "Child>GrandChild" as its direct children elements; // 4) if no exists, create new <GrandChild> as a new child of // <Child> element. String[] containers = elementPath.split(DefaultElementPathSign); String next = ""; Element last = this; for (int i = 0; i < containers.length; i++) { next += containers[i]; if (getElementsOf(next) == null) { newElement = new Element(containers[i], last); } last = getElementsOf(next).get(0); next += DefaultElementPathSign; } elements = getElementsOf(elementPath); } int size = values.length; if (size > elements.size()) { // In case the existing elements are less than values.length, // create new elements under the last container int lastChildMark = elementPath.lastIndexOf(DefaultElementPathSign); String lastContainerPath = lastChildMark == -1 ? "" : elementPath.substring(0, lastChildMark); String lastElementName = elementPath.substring(lastChildMark + 1); Element firstContainer = getElementsOf(lastContainerPath).get(0); for (int i = elements.size(); i < size; i++) { newElement = new Element(lastElementName, firstContainer); } elements = getElementsOf(elementPath); } if (segments.length == 1) { // The path identify Element, thus set their innerText for (int i = 0; i < size; i++) { elements.get(i).setValue(values[i]); } } else { // The path identify Attribute, thus set values of these // attribute accordingly String attributeName = segments[1]; for (int i = 0; i < size; i++) { elements.get(i).setAttributeValue(attributeName, values[i]); } } return true; } catch (InvalidParameterException ex) { ex.printStackTrace(); return false; } }
From source file:fr.paris.lutece.plugins.sponsoredlinks.web.SponsoredLinksJspBean.java
/** * Process the data capture form of a modified sponsoredlinks set * * @param request The Http Request/* w w w. j ava2 s. c o m*/ * @return The Jsp URL of the process result */ public String doModifySet(HttpServletRequest request) { String strSetId = request.getParameter(PARAMETER_SET_ID); if ((request.getParameter(PARAMETER_CANCEL) != null) || (StringUtils.isNotBlank(strSetId) && !RBACService.isAuthorized(SponsoredLinkSet.RESOURCE_TYPE, strSetId, SponsoredLinksSetResourceIdService.PERMISSION_MODIFY_SET, getUser()))) { return JSP_REDIRECT_TO_MANAGE_SET; } String strTitle = request.getParameter(PARAMETER_SET_TITLE); String strGroupId = request.getParameter(PARAMETER_GROUP_ID); String[] strArrayLinks = request.getParameterValues(PARAMETER_SET_LINK_LIST); // Mandatory fields if (StringUtils.isBlank(strSetId) || StringUtils.isBlank(strTitle) || StringUtils.isBlank(strGroupId) || (strArrayLinks == null) || (strArrayLinks.length == 0)) { return AdminMessageService.getMessageUrl(request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP); } int nSetId = Integer.parseInt(strSetId); int nGroupId = Integer.parseInt(strGroupId); SponsoredLinkSet set = new SponsoredLinkSet(); List<SponsoredLink> linkList = new ArrayList<SponsoredLink>(); SponsoredLink currentLink; for (int i = strArrayLinks.length - 1; i >= 0; --i) { if (!strArrayLinks[i].trim().equals("\u00A0")) { currentLink = new SponsoredLink(); currentLink.setOrder(i + 1); currentLink.setLink(strArrayLinks[i]); if (currentLink.isValidLink()) { linkList.add(currentLink); } else { AppLogService.error(new InvalidParameterException("In SponsoredLinkSet \"" + strTitle + "\" : " + " SponsoredLink[" + currentLink.getOrder() + "] - " + currentLink.getLink() + "> : is not a valid html link")); } } } set.setId(nSetId); set.setTitle(strTitle); set.setGroupId(nGroupId); set.setSponsoredLinkList(linkList); SponsoredLinkSetHome.update(set, getPlugin()); // if the operation occurred well, redirects towards the list of sets return JSP_REDIRECT_TO_MANAGE_SET; }
From source file:petascope.wcst.transaction.executeTransaction.java
/** * Processes one <Coverage> node from the input XML * * @param elem the JAXB node equivalent to the <Coverage> node *//*www . j a v a2 s .c o m*/ private void processInputCoverageNode(CoverageType elem) throws WCSTException, WCPSException, PetascopeException { if (elem.getAction() == null) { throw new WCSTException(ExceptionCode.InvalidParameterValue, "Action. Explanation: " + "Every <Coverage> node must contain an <Action> child node."); } String action = elem.getAction().getValue(); String identifier = null; List references = null; if (elem.getIdentifier() == null) { throw new InvalidParameterException("Identifier"); } identifier = elem.getIdentifier().getValue(); references = elem.getAbstractReferenceBase(); if (action.equalsIgnoreCase("Add")) { actionAddCoverage(identifier, references); } else if (action.equalsIgnoreCase("UpdateMetadata")) { actionUpdateMetadata(identifier, references); } else if (action.equalsIgnoreCase("Delete")) { actionDeleteCoverage(identifier, references); } else if (action.equalsIgnoreCase("UpdateAll")) { actionUpdateAll(identifier, references); } else if (action.equalsIgnoreCase("UpdateDataPart")) { throw new WCSTException(ExceptionCode.OperationNotSupported, "\"UpdateDataPart\" is not supported yet."); /* TODO: UpdateDataPart is not yet functional. The Rasdaman server * returns with an unexpected internal error (code: 10000) when * a partial update query is sent. */ // actionUpdateDataPart(identifier, references); } }
From source file:com.appnativa.rare.ui.chart.jfreechart.ChartHandler.java
protected List<DataSetValue> createDataSets(ChartDefinition cd) { ChartInfo ci = (ChartInfo) cd.getChartHandlerInfo(); List<SeriesData> seriesData = ci.seriesData; int len = (seriesData == null) ? 0 : seriesData.size(); ChartType ct;/*from w w w.j ava2 s.c om*/ if (len == 0) { ct = cd.getChartType(); switch (ct) { case PIE: return Arrays.asList(new DataSetValue(ct, new DefaultPieDatasetEx())); case RANGE_BAR: case RANGE_AREA: case STACKED_BAR: case STACKED_AREA: case AREA: case BAR: case LINE: case SPLINE: case SPLINE_AREA: { return Arrays.asList(new DataSetValue(ct, new XYSeriesCollectionEx())); } default: throw new InvalidParameterException("Unsupported chart type:" + ct.toString()); } } boolean allSameType = areAllTheSameType(cd); List<DataSetValue> list = new ArrayList<DataSetValue>(len); XYSeriesCollectionEx xysc = null; for (int i = 0; i < len; i++) { SeriesData data = seriesData.get(i); ct = data.chartType; switch (ct) { case PIE: list.add(new DataSetValue(ct, ChartHelper.createPieDataset(cd))); if (!allSameType) { throw new UnsupportedOperationException("Can include a Pie Chart with other chart types"); } break; case RANGE_BAR: case RANGE_AREA: XYSeriesCollectionEx rxysc = new XYSeriesCollectionEx(true); list.add(new DataSetValue(ct, rxysc)); rxysc.addSeries(ChartHelper.populateXYSeries(null, data)); break; case STACKED_BAR: case STACKED_AREA: case AREA: case BAR: case LINE: case SPLINE: case SPLINE_AREA: { if ((xysc == null) || !allSameType) { xysc = new XYSeriesCollectionEx(); list.add(new DataSetValue(ct, xysc)); } xysc.addSeries(ChartHelper.populateXYSeries(null, data)); break; } default: throw new InvalidParameterException("Unsupported chart type:" + ct.toString()); } } return list; }
From source file:org.xwoot.xwootUtil.FileUtil.java
/** * @param moduleName the name of the module. * @return the working directory for tests for the specified module. *//*from w w w . j a va 2 s . co m*/ public static String getTestsWorkingDirectoryPathForModule(String moduleName) { if (moduleName == null || moduleName.length() == 0) { throw new InvalidParameterException("Module name must not be null or empty."); } return getTestsWorkingDirectoryPath() + File.separator + moduleName; }
From source file:com.andexert.calendarlistview.library.SimpleMonthView.java
public void setMonthParams(HashMap<String, Integer> params) { if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) { throw new InvalidParameterException("You must specify month and year for this view"); }/* ww w. j av a 2 s . c om*/ setTag(params); if (params.containsKey(VIEW_PARAMS_HEIGHT)) { mRowHeight = params.get(VIEW_PARAMS_HEIGHT); if (mRowHeight < MIN_HEIGHT) { mRowHeight = MIN_HEIGHT; } } if (params.containsKey(VIEW_PARAMS_SELECTED_BEGIN_DAY)) { mSelectedBeginDay = params.get(VIEW_PARAMS_SELECTED_BEGIN_DAY); } if (params.containsKey(VIEW_PARAMS_SELECTED_LAST_DAY)) { mSelectedLastDay = params.get(VIEW_PARAMS_SELECTED_LAST_DAY); } if (params.containsKey(VIEW_PARAMS_SELECTED_BEGIN_MONTH)) { mSelectedBeginMonth = params.get(VIEW_PARAMS_SELECTED_BEGIN_MONTH); } if (params.containsKey(VIEW_PARAMS_SELECTED_LAST_MONTH)) { mSelectedLastMonth = params.get(VIEW_PARAMS_SELECTED_LAST_MONTH); } if (params.containsKey(VIEW_PARAMS_SELECTED_BEGIN_YEAR)) { mSelectedBeginYear = params.get(VIEW_PARAMS_SELECTED_BEGIN_YEAR); } if (params.containsKey(VIEW_PARAMS_SELECTED_LAST_YEAR)) { mSelectedLastYear = params.get(VIEW_PARAMS_SELECTED_LAST_YEAR); } mMonth = params.get(VIEW_PARAMS_MONTH); mYear = params.get(VIEW_PARAMS_YEAR); mHasToday = false; mToday = -1; mCalendar.set(Calendar.MONTH, mMonth); mCalendar.set(Calendar.YEAR, mYear); mCalendar.set(Calendar.DAY_OF_MONTH, 1); mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK); if (params.containsKey(VIEW_PARAMS_WEEK_START)) { mWeekStart = params.get(VIEW_PARAMS_WEEK_START); } else { mWeekStart = mCalendar.getFirstDayOfWeek(); } mNumCells = CalendarUtils.getDaysInMonth(mMonth, mYear); for (int i = 0; i < mNumCells; i++) { final int day = i + 1; if (sameDay(day, today)) { mHasToday = true; mToday = day; } mIsPrev = prevDay(day, today); } mNumRows = calculateNumRows(); }
From source file:com.vmware.photon.controller.common.xenon.ServiceHostUtils.java
/** * Constructs a URI to start service under. * * @param host/*from w w w . java 2s. c o m*/ * @param service * @param path * @return */ private static URI buildServiceUri(ServiceHost host, Class service, String path) { URI serviceUri; String error; if (path != null) { serviceUri = UriUtils.buildUri(host, path); error = String.format("Invalid path for starting service [%s]", path); } else { serviceUri = UriUtils.buildUri(host, service); error = String.format("No SELF_LINK field in class %s", service.getCanonicalName()); } if (serviceUri == null) { throw new InvalidParameterException(error); } return serviceUri; }