From a39ebd0c00d56b0315843ea9a13b768bfece1ab4 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Fri, 4 Aug 2017 16:36:17 +0300 Subject: [PATCH] IDEA-139856 Generate XML Document From XSD Schema: error message could be more sensible --- ...erateInstanceDocumentFromSchemaAction.java | 2 +- .../actions/xmlbeans/Xsd2InstanceUtils.java | 11 +- .../intellij/xml/GenerateXmlFromXsdTest.kt | 44 + xml/tests/testData/generate/vast4.xsd | 1404 +++++++++++++++++ 4 files changed, 1455 insertions(+), 6 deletions(-) create mode 100644 xml/tests/src/com/intellij/xml/GenerateXmlFromXsdTest.kt create mode 100644 xml/tests/testData/generate/vast4.xsd diff --git a/xml/impl/src/com/intellij/xml/actions/xmlbeans/GenerateInstanceDocumentFromSchemaAction.java b/xml/impl/src/com/intellij/xml/actions/xmlbeans/GenerateInstanceDocumentFromSchemaAction.java index 7ad672fc1ffc..49a453f78749 100644 --- a/xml/impl/src/com/intellij/xml/actions/xmlbeans/GenerateInstanceDocumentFromSchemaAction.java +++ b/xml/impl/src/com/intellij/xml/actions/xmlbeans/GenerateInstanceDocumentFromSchemaAction.java @@ -69,7 +69,7 @@ public class GenerateInstanceDocumentFromSchemaAction extends AnAction { dialog.show(); } - private static void doAction(final Project project, final GenerateInstanceDocumentFromSchemaDialog dialog) { + public static void doAction(final Project project, final GenerateInstanceDocumentFromSchemaDialog dialog) { FileDocumentManager.getInstance().saveAllDocuments(); @NonNls List parameters = new LinkedList<>(); diff --git a/xml/impl/src/com/intellij/xml/actions/xmlbeans/Xsd2InstanceUtils.java b/xml/impl/src/com/intellij/xml/actions/xmlbeans/Xsd2InstanceUtils.java index 1e05b09ebf65..adfe286847ee 100644 --- a/xml/impl/src/com/intellij/xml/actions/xmlbeans/Xsd2InstanceUtils.java +++ b/xml/impl/src/com/intellij/xml/actions/xmlbeans/Xsd2InstanceUtils.java @@ -94,7 +94,6 @@ public class Xsd2InstanceUtils { SchemaTypeSystem sts = null; if (schemas.length > 0) { - Collection errors = new ArrayList(); XmlOptions compileOptions = new XmlOptions(); if (dl) compileOptions.setCompileDownloadUrls(); @@ -105,10 +104,12 @@ public class Xsd2InstanceUtils { try { sts = XmlBeans.compileXsd(schemas, XmlBeans.getBuiltinTypeSystem(), compileOptions); - } catch (XmlException e) { - String out = "Schema compilation errors: "; - for (Object error : errors) out += "\n" + error; - throw new IllegalArgumentException(out); + } + catch (XmlException e) { + StringBuilder out = new StringBuilder("Schema compilation errors: "); + Collection errors = e.getErrors(); + for (Object error : errors) out.append("\n").append(error); + throw new IllegalArgumentException(out.toString()); } } diff --git a/xml/tests/src/com/intellij/xml/GenerateXmlFromXsdTest.kt b/xml/tests/src/com/intellij/xml/GenerateXmlFromXsdTest.kt new file mode 100644 index 000000000000..cd7260587fae --- /dev/null +++ b/xml/tests/src/com/intellij/xml/GenerateXmlFromXsdTest.kt @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.xml + +import com.intellij.openapi.util.Disposer +import com.intellij.openapi.vfs.LocalFileSystem +import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase +import com.intellij.xml.actions.xmlbeans.GenerateInstanceDocumentFromSchemaAction +import com.intellij.xml.actions.xmlbeans.GenerateInstanceDocumentFromSchemaDialog +import junit.framework.TestCase + +/** + * @author Dmitry Avdeev + */ +class GenerateXmlFromXsdTest: LightCodeInsightFixtureTestCase() { + fun testErrorMessage() { + val file = LocalFileSystem.getInstance().findFileByPath(testDataPath + "/vast4.xsd") + val dialog = GenerateInstanceDocumentFromSchemaDialog(project, file) + try { + GenerateInstanceDocumentFromSchemaAction.doAction(project, dialog) + TestCase.fail() + } + catch (e: Exception) { + TestCase.assertTrue(e.message!!.contains("vast4.xsd:192:13: error: src-resolve.a: Could not find type 'VideoClicks_Base_type'")) + } + Disposer.dispose(dialog.disposable) + } + + + override fun getBasePath(): String = "/xml/tests/testData/generate" +} \ No newline at end of file diff --git a/xml/tests/testData/generate/vast4.xsd b/xml/tests/testData/generate/vast4.xsd new file mode 100644 index 000000000000..cc3c23ddc5aa --- /dev/null +++ b/xml/tests/testData/generate/vast4.xsd @@ -0,0 +1,1404 @@ + + + + + + IAB VAST (Video Ad Serving Template), Version 4.0.0 + + + + + + Top-level element, wraps each ad in the response or ad unit in an ad pod. + This MUST be present unless an Error element is present. + + + + + + Second-level element surrounding complete ad data for a single ad + + + + + Second-level element surrounding wrapper ad pointing to Secondary ad server. + + + + + + + Identifies the sequence of multiple Ads that are part of an Ad Pod. + + + + + A Boolean value that identifies a conditional ad. + + + + + + + + Used when there is no ad response. When the ad server does not or cannot return an Ad. + If included the video player must send a request to the URI provided (Sec 3.2.1). + + + + + + + Current version is 4.0 + + + + + + + + + + URLs to ping when icon action occurs. + + + + + + + + + + + + The name of the event to track for the element. The creativeView should always be requested when present. + + + + + + + The name of the event to track. For nonlinear ads these events should be recorded on the video within the ad. + + + + + + + + + + + + + + + + + + + + + + + + + + + + The time during the video at which this url should be pinged. Must be present for progress event. + + + + + + + + + + + + + + + + + + URL to request for tracking purposes when user clicks on the video + + + + + + + + + + + + URLs to request on custom events such as hotspotted video + + + + + + + + + + + + + + + + + + URL to open as destination page when user clicks on the video + + + + + + + + + + + + + + + + + + + + + + + + A base creative resource type (sec 3.13) for non-video creative content. + This specifies static, IFrame, or HTML content, or a combination thereof + + + + + + URI to a static file, such as an image or SWF file + + + + + + + MIME type of static resource + + + + + + + + + URI source for an IFrame to display the companion element + + + + + HTML to display the companion element + + + + + + + + + + + + + + URL to open as destination page when user clicks on the icon. + + + + + URLs to ping when user clicks on the the icon. + + + + + + + + URLs to ping when icon is shown. + + + + + + Program represented in the Icon. + + + + + Pixel dimensions of icon. + + + + + Pixel dimensions of icon. + + + + + The horizontal alignment location (in pixels) or a specific alignment. + + + + + + + + + + The vertical alignment location (in pixels) or a specific alignment. + + + + + + + + + + The duration for which the player must display the icon. Expressed in standard time format hh:mm:ss. + + + + + Start time at which the player should display the icon. Expressed in standard time format hh:mm:ss. + + + + + The apiFramework defines the method to use for communication with the icon element + + + + + The pixel ratio for which the icon creative is intended. + The pixel ratio is the ratio of physical pixels on the device to the device-independent pixels. + An ad intended for display on a device with a pixel ratio that is twice that of a standard 1:1 + pixel ratio would use the value "2" Default value is "1" + + + + + + + + + + Any valid XML may be included in the Extensions node + + + + + + + + + + + + + + + + Specifies whether the parameters are XML-encoded + + + + + + + + + + + Specifies whether the HTML is XML-encoded + + + + + + + + + Video formatted ad that plays linearly + + + + + + + + Any number of icons representing advertising industry initiatives. + + + + + + + + + + The time at which the ad becomes skippable, if absent, the ad is not skippable. + + + + + + + + + + + Video formatted ad that plays linearly + + + + + + + + + + + + Video formatted ad that plays linearly + + + + + + + Duration in standard time format, hh:mm:ss + + + + + Data to be passed into the video ad. Used to pass VAST info to VPAID object. + + + + + + + + URI location of linear file. Content must be wrapped in CDATA tag. + + + + + + + For any media file that uses APIs for advanced creative functionality, the + InteractivityCreativeFile element is used to identify the file and framework needed to + execute advanced functions for the ad. + + + + + + + + Identifies the MIME type of the file provided. + + + + + identifies the API needed to execute the Creative file if applicable + + + + + + + + + + + Optional identifier + + + + + Method of delivery of ad + + + + + + + + + + + + MIME type. Popular MIME types include, but are not limited to “video/x-ms-wmv” for Windows Media, and “video/x-flv” for Flash Video. Image ads or interactive ads can be included in the MediaFiles section with appropriate Mime + types + + + + + + Bitrate of encoded video in Kbps. If bitrate is supplied, minBitrate and maxBitrate should not be supplied. + + + + + Minimum bitrate of an adaptive stream in Kbps. If minBitrate is supplied, maxBitrate must be supplied and bitrate should not be supplied. + + + + + Maximum bitrate of an adaptive stream in Kbps. If maxBitrate is supplied, minBitrate must be supplied and bitrate should not be supplied. + + + + + Pixel dimensions of video + + + + + Pixel dimensions of video + + + + + Whether it is acceptable to scale the image. + + + + + Whether the ad must have its aspect ratio maintained when scales + + + + + + The apiFramework defines the method to use for communication if the MediaFile is interactive. Suggested values for this element are “VPAID”, “FlashVars” (for Flash/Flex), “initParams” (for Silverlight) and “GetVariables” + (variables placed in key/value pairs on the asset request). + + + + + + The codec used to produce the media file as specified in RFC 4281. + + + + + Specifies if ad is formatted for adaptive streaming or not. + + + + + + + + URI location to raw, high-quality media file for high-resolution environments. + Content must be wrapped in CDATA tag. + + + + + + + + + + + + + + + + + + + An ad that is overlain on top of video content during playback + + + + + URLs to ping when user clicks on the the non-linear ad unit. + + + + + + + Identifier provided to ad server for click reports + + + + + + + + + + + An ad that is overlain on top of video content during playback + + + + + + + URLs to ping when user clicks on the the non-linear ad unit. + + + + + + + Identifier provided to ad server for click reports + + + + + + + + + URI to advertiser page opened on viewer clicks through. + + + + + Custom content used to pass information to ad unit + + + + + + + + + + + + + + The creativeView should always be requested when present. For Companions creativeView is the only supported event. + + + + + URL to open as destination page when user clicks on the the companion banner ad. + + + + + URLs to ping when user clicks on the the companion banner ad. + + + + + Alt text to be displayed when companion is rendered in HTML environment. + + + + + Data to be passed into the companion ads. The apiFramework defines the method to use for communication (e.g. “FlashVar”) + + + + + + Optional identifier + + + + + Pixel dimensions of companion slot + + + + + Pixel dimensions of companion slot + + + + + Pixel dimensions of the companion asset + + + + + Pixel dimensions of the companion asset + + + + + Pixel dimensions of expanding companion ad when in expanded state + + + + + Pixel dimensions of expanding companion ad when in expanded state + + + + + The apiFramework defines the method to use for communication with the companion + + + + + Used to match companion creative to publisher placement areas on the page. + + + + + The pixel ratio for which the icon creative is intended. + The pixel ratio is the ratio of physical pixels on the device to the device-independent pixels. + An ad intended for display on a device with a pixel ratio that is twice that of a standard 1:1 + pixel ratio would use the value "2" Default value is "1" + + + + + + + + + + + + How the player should treat a companion ad when multiple are supplied + + + + + + + + + + + + + + + The preferred order in which multiple Creatives should be displayed + + + + + Identifies an API needed to execute the creative + + + + + To be deprecated in future version of VAST. Ad-ID for the creative (formerly ISCI) + + + + + + + + + + + + + + + + Any number of companions in any desired pixel dimensions. + + + + + + + + + + + + + + + + + The UniversalAdId is used to provide a unique creative identifier for the purposes of tracking ad creative. + This is used for Ad-ID(r) for ads served in the United States. + + + + + + + + + + + + + + + + + + + + Any number of companions in any desired pixel dimensions. + + + + + + + + + + + + + + + Base type structure used by Inline or Wrapper ad content element types + + + + + + Indicates source ad server + + + + + + + Internal version used by ad system + + + + + + + + + URI for impression tracking + + + + + + + Ad server ID for the impression + + + + + + + + + The price of the ad that can be used in real time bidding systems. + + + + + + + The pricing model used. + + + + + + + + + + + + + + Three letter ISO-4217 currency symbol that identifies the currency of the value provied. + Ex: USD, GBP, etc. + + + + + + + + + + + + + + + URL to request if ad does not play due to error + + + + + + + + XML node for custom extensions, as defined by the ad server. When used, a custom + element should be nested under <Extensions> to help separate custom XML elements from VAST elements. + + + + + + + + + + + + + + + The ViewableImpression element allows for tracking URIs to report viewability + + + + + + + + + + + An ad server id for the impression. Impression resources of the same id should be + requested at the same time or as close in time as possible to help prevent discrepancies. + + + + + + + + + + + + + The AdVerification element is used to initiate a controlled container where code can be + executed for collecting data to verify ad playback details. + + + + + + + + + The name of the event to track for the element. + The creativeView should always be requested when present. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A URI to another VAST response that may be another VAST Wrapper or a VAST InLine ad. + + + + + + + + + + + A container for one or more Creative elements used to provide creative files for ad. + + + + + + + + + + + + a Boolean value that identifies whether subsequent wrappers after a requested VAST response is allowed. + + + + + a Boolean value that identifies whether multiple ads are allowed in the requested VAST response. + + + + + a Boolean value that provides instruction for using an available Ad when the requested VAST response returns no ads. + + + + + + + + + + + + + Common name of ad + + + + + Longer description of ad + + + + + Name of advertiser as defined by the ad serving party + + + + + + String providing category code or label + + + + + + + URI for the organizational authority that produced the category list and content + + + + + + + + + URL of request to survey vendor + + + + + + + MIME type of the resource being served + + + + + + + + + + A container for one or more Creative elements used to provide creative files for ad. + + + + + + + + + + + + +