Esempio n. 1
0
  private void processAliasFile(File aliasesFile, Set<String> validClasses)
      throws ContentFileProcessingException, XMLStreamException, FileNotFoundException, IOException,
          NamespaceException {
    XMLStreamReader2 streamReader = null;

    try (FileReader fileReader = new FileReader(aliasesFile)) {
      streamReader = (XMLStreamReader2) inputFactory.createXMLStreamReader(fileReader);
      AliasProcessor aliasProcessor =
          new AliasProcessor(this, streamReader, aliasesFile, validClasses);

      if (aliasesFile.getName().equals("aliasDefinitions.xml")) {
        streamReader.validateAgainst(aliasDefinitionsSchema);
        aliasProcessor.processAliasDefinitionsFile();
      } else {
        streamReader.validateAgainst(aliasSchema);
        aliasProcessor.processAliasesFile();
      }
    } catch (WstxValidationException e) {
      Location location = e.getLocation();

      throw new ContentFileProcessingException(
          aliasesFile, location.getLineNumber(), location.getColumnNumber(), e.getMessage());
    } finally {
      streamReader.close();
    }
  }
  public void testElementDefault() throws Exception {
    XMLValidationSchema schema = parseW3CSchema(SCHEMA_WITH_DEFAULTS);
    XMLStreamReader2 sr = getReader("<price>129</price>");
    sr.validateAgainst(schema);
    // first: if explicitly defined, should show that value
    assertTokenType(START_ELEMENT, sr.next());
    assertEquals("price", sr.getLocalName());
    assertEquals("129", sr.getElementText());
    assertTokenType(END_ELEMENT, sr.getEventType());
    sr.close();

    // then, if missing, default to given default
    sr = getReader("<price />");
    sr.validateAgainst(schema);
    // first: if explicitly defined, should show that value
    assertTokenType(START_ELEMENT, sr.next());
    assertEquals("price", sr.getLocalName());
    assertEquals("10", sr.getElementText());
    assertTokenType(END_ELEMENT, sr.getEventType());
    sr.close();
  }
  public void testAttributeDefault() throws Exception {
    XMLValidationSchema schema = parseW3CSchema(SCHEMA_WITH_DEFAULTS);
    XMLStreamReader2 sr = getReader("<price currency='FIM'>129</price>");
    sr.validateAgainst(schema);
    // first: if explicitly defined, should show that value
    assertTokenType(START_ELEMENT, sr.next());
    assertEquals("price", sr.getLocalName());
    assertEquals(1, sr.getAttributeCount());
    assertEquals("FIM", sr.getAttributeValue(null, "currency"));
    sr.close();

    // then, if missing, default to given default
    sr = getReader("<price>129</price>");
    sr.validateAgainst(schema);
    // first: if explicitly defined, should show that value
    assertTokenType(START_ELEMENT, sr.next());
    assertEquals("price", sr.getLocalName());
    assertEquals(1, sr.getAttributeCount());
    assertEquals("USD", sr.getAttributeValue(null, "currency"));
    sr.close();
  }