Java Code Examples for com.helger.xml.namespace.MapBasedNamespaceContext#addDefaultNamespaceURI()

The following examples show how to use com.helger.xml.namespace.MapBasedNamespaceContext#addDefaultNamespaceURI() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PSWriterSettings.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to extract the namespace mapping from the provided
 * Schematron.
 *
 * @param aSchema
 *        The schema to extract the namespace context from. May not be
 *        <code>null</code>.
 * @return A non-<code>null</code> but maybe empty namespace context
 */
@Nonnull
@ReturnsMutableCopy
public static MapBasedNamespaceContext createNamespaceMapping (@Nonnull final PSSchema aSchema)
{
  final MapBasedNamespaceContext ret = new MapBasedNamespaceContext ();
  ret.addDefaultNamespaceURI (CSchematron.NAMESPACE_SCHEMATRON);
  ret.addMapping ("xsl", CSchematron.NAMESPACE_URI_XSL);
  for (final PSNS aItem : aSchema.getAllNSs ())
    ret.addMapping (aItem.getPrefix (), aItem.getUri ());
  return ret;
}
 
Example 2
Source File: UBL22WriterBuilder.java    From ph-ubl with Apache License 2.0 5 votes vote down vote up
public UBL22WriterBuilder (@Nonnull final EUBL22DocumentType eDocType)
{
  super (eDocType);

  // Create a special namespace context for the passed document type
  final MapBasedNamespaceContext aNSContext = UBL22NamespaceContext.getInstance ().getClone ();
  aNSContext.addDefaultNamespaceURI (m_aDocType.getNamespaceURI ());
  setNamespaceContext (aNSContext);
}
 
Example 3
Source File: DianUBLWriterBuilder.java    From ph-ubl with Apache License 2.0 5 votes vote down vote up
public DianUBLWriterBuilder (@Nonnull final EDianUBLDocumentType eDocType)
{
  super (eDocType);

  // Create a special namespace context for the passed document type
  final MapBasedNamespaceContext aNSContext = new MapBasedNamespaceContext ();
  aNSContext.addMappings (new DianUBLNamespaceContext ());
  aNSContext.addDefaultNamespaceURI (m_aDocType.getNamespaceURI ());
  setNamespaceContext (aNSContext);
}
 
Example 4
Source File: UBL21WriterBuilder.java    From ph-ubl with Apache License 2.0 5 votes vote down vote up
public UBL21WriterBuilder (@Nonnull final EUBL21DocumentType eDocType)
{
  super (eDocType);

  // Create a special namespace context for the passed document type
  final MapBasedNamespaceContext aNSContext = UBL21NamespaceContext.getInstance ().getClone ();
  aNSContext.addDefaultNamespaceURI (m_aDocType.getNamespaceURI ());
  setNamespaceContext (aNSContext);
}
 
Example 5
Source File: UBLTRWriterBuilder.java    From ph-ubl with Apache License 2.0 5 votes vote down vote up
public UBLTRWriterBuilder (@Nonnull final EUBLTRDocumentType eDocType)
{
  super (eDocType);

  // Create a special namespace context for the passed document type
  final MapBasedNamespaceContext aNSContext = new MapBasedNamespaceContext ();
  aNSContext.addMappings (new UBLTRNamespaceContext ());
  aNSContext.addDefaultNamespaceURI (m_aDocType.getNamespaceURI ());
  setNamespaceContext (aNSContext);
}
 
Example 6
Source File: UBL20WriterBuilder.java    From ph-ubl with Apache License 2.0 5 votes vote down vote up
public UBL20WriterBuilder (@Nonnull final EUBL20DocumentType eDocType)
{
  super (eDocType);

  // Create a special namespace context for the passed document type
  final MapBasedNamespaceContext aNSContext = UBL20NamespaceContext.getInstance ().getClone ();
  aNSContext.addDefaultNamespaceURI (m_aDocType.getNamespaceURI ());
  setNamespaceContext (aNSContext);
}
 
Example 7
Source File: UBLPEWriterBuilder.java    From ph-ubl with Apache License 2.0 5 votes vote down vote up
public UBLPEWriterBuilder (@Nonnull final EUBLPEDocumentType eDocType)
{
  super (eDocType);

  // Create a special namespace context for the passed document type
  final MapBasedNamespaceContext aNSContext = new MapBasedNamespaceContext ();
  aNSContext.addMappings (new UBLPENamespaceContext ());
  aNSContext.addDefaultNamespaceURI (m_aDocType.getNamespaceURI ());
  setNamespaceContext (aNSContext);
}
 
Example 8
Source File: UBL23WriterBuilder.java    From ph-ubl with Apache License 2.0 5 votes vote down vote up
public UBL23WriterBuilder (@Nonnull final EUBL23DocumentType eDocType)
{
  super (eDocType);

  // Create a special namespace context for the passed document type
  final MapBasedNamespaceContext aNSContext = UBL23NamespaceContext.getInstance ().getClone ();
  aNSContext.addDefaultNamespaceURI (m_aDocType.getNamespaceURI ());
  setNamespaceContext (aNSContext);
}
 
Example 9
Source File: SchematronPreprocessMojo.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
public void execute () throws MojoExecutionException, MojoFailureException
{
  StaticLoggerBinder.getSingleton ().setMavenLog (getLog ());
  if (m_aSourceFile == null)
    throw new MojoExecutionException ("No Source file specified!");
  if (m_aSourceFile.exists () && !m_aSourceFile.isFile ())
    throw new MojoExecutionException ("The specified Source file " + m_aSourceFile + " is not a file!");

  if (m_aTargetFile == null)
    throw new MojoExecutionException ("No Target file specified!");
  if (m_aTargetFile.exists ())
  {
    if (!m_bOverwriteWithoutNotice)
    {
      // 3.1 Not overwriting the existing file
      getLog ().debug ("Skipping Target file '" + m_aTargetFile.getPath () + "' because it already exists!");
    }
    else
    {
      if (!m_aTargetFile.isFile ())
        throw new MojoExecutionException ("The specified Target file " + m_aTargetFile + " is not a file!");
    }
  }

  try
  {
    final PSSchema aSchema = new PSReader (new FileSystemResource (m_aSourceFile), null, null).readSchema ();
    final IPSQueryBinding aQueryBinding = PSQueryBindingRegistry.getQueryBindingOfNameOrThrow (aSchema.getQueryBinding ());

    final PSPreprocessor aPreprocessor = new PSPreprocessor (aQueryBinding);
    aPreprocessor.setKeepTitles (m_bKeepTitles);
    aPreprocessor.setKeepDiagnostics (m_bKeepDiagnostics);
    aPreprocessor.setKeepReports (m_bKeepReports);
    aPreprocessor.setKeepEmptyPatterns (m_bKeepEmptyPatterns);

    // Pre-process
    final PSSchema aPreprocessedSchema = aPreprocessor.getForcedPreprocessedSchema (aSchema);
    if (aPreprocessedSchema == null)
      throw new SchematronPreprocessException ("Failed to preprocess schema " +
                                               aSchema +
                                               " with query binding " +
                                               aQueryBinding);

    // Convert to XML string
    final MapBasedNamespaceContext aNSCtx = new MapBasedNamespaceContext ();
    aNSCtx.addDefaultNamespaceURI (CSchematron.NAMESPACE_SCHEMATRON);
    aNSCtx.addMapping ("xsl", CSchematron.NAMESPACE_URI_XSL);
    aNSCtx.addMapping ("svrl", CSVRL.SVRL_NAMESPACE_URI);

    // Add all <ns> elements from schema as NS context
    for (final PSNS aItem : aSchema.getAllNSs ())
      aNSCtx.setMapping (aItem.getPrefix (), aItem.getUri ());

    final IXMLWriterSettings XWS = new XMLWriterSettings ().setIndent (EXMLSerializeIndent.INDENT_AND_ALIGN)
                                                           .setNamespaceContext (aNSCtx);
    final IMicroDocument aDoc = new MicroDocument ();
    aDoc.appendChild (aPreprocessedSchema.getAsMicroElement ());
    if (MicroWriter.writeToFile (aDoc, m_aTargetFile, XWS).isSuccess ())
      getLog ().info ("Successfully wrote preprocessed Schematron file '" + m_aTargetFile.getPath () + "'");
    else
      getLog ().error ("Error writing preprocessed Schematron file to '" + m_aTargetFile.getPath () + "'");
  }
  catch (final SchematronException ex)
  {
    throw new MojoExecutionException ("Error preprocessing Schematron file '" + m_aSourceFile + "'", ex);
  }
}