summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
d8aabf3)
When we are transforming a source, we should also be forwarding symbolic
name requests.
JIRA: YANGTOOLS-1275
Change-Id: I0aa0420aee4c51d9c006f28b3e669eabc89c1787
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit
738badcf0d51117f00d1ee585e546eeb454e22cc)
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
+import java.util.Optional;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
* @param identifier Schema source identifier
* @param source W3C DOM source
* @return A new {@link YinDomSchemaSource} instance.
* @param identifier Schema source identifier
* @param source W3C DOM source
* @return A new {@link YinDomSchemaSource} instance.
+ * @deprecated Use {@link #create(SourceIdentifier, DOMSource, String)} instead.
+ @Deprecated(forRemoval = true)
public static @NonNull YinDomSchemaSource create(final @NonNull SourceIdentifier identifier,
final @NonNull DOMSource source) {
public static @NonNull YinDomSchemaSource create(final @NonNull SourceIdentifier identifier,
final @NonNull DOMSource source) {
+ return create(identifier, source, null);
+ }
+
+ /**
+ * Create a new {@link YinDomSchemaSource} using an identifier and a source.
+ *
+ * @param identifier Schema source identifier
+ * @param source W3C DOM source
+ * @param symbolicName Source symbolic name
+ * @return A new {@link YinDomSchemaSource} instance.
+ */
+ public static @NonNull YinDomSchemaSource create(final @NonNull SourceIdentifier identifier,
+ final @NonNull DOMSource source, final @Nullable String symbolicName) {
final Node root = source.getNode().getFirstChild();
final String rootNs = root.getNamespaceURI();
if (rootNs == null) {
// Let whoever is using this deal with this
final Node root = source.getNode().getFirstChild();
final String rootNs = root.getNamespaceURI();
if (rootNs == null) {
// Let whoever is using this deal with this
- return new Simple(identifier, source);
+ return new Simple(identifier, source, symbolicName);
}
final QName qname = QName.create(rootNs, root.getLocalName());
}
final QName qname = QName.create(rootNs, root.getLocalName());
REVISION_STMT.getLocalName());
if (revisions.getLength() == 0) {
// FIXME: is module name important (as that may have changed)
REVISION_STMT.getLocalName());
if (revisions.getLength() == 0) {
// FIXME: is module name important (as that may have changed)
- return new Simple(identifier, source);
+ return new Simple(identifier, source, symbolicName);
}
final Element revisionStmt = (Element) revisions.item(0);
}
final Element revisionStmt = (Element) revisions.item(0);
- return new Simple(id, source);
+ return new Simple(id, source, symbolicName);
throws TransformerException {
final YinDomSchemaSource cast = castSchemaSource(xmlSchemaSource);
return cast != null ? cast :
throws TransformerException {
final YinDomSchemaSource cast = castSchemaSource(xmlSchemaSource);
return cast != null ? cast :
- create(xmlSchemaSource.getIdentifier(), transformSource(xmlSchemaSource.getSource()));
+ create(xmlSchemaSource.getIdentifier(), transformSource(xmlSchemaSource.getSource()),
+ xmlSchemaSource.getSymbolicName().orElse(null));
final Source source = xmlSchemaSource.getSource();
if (source instanceof DOMSource) {
final Source source = xmlSchemaSource.getSource();
if (source instanceof DOMSource) {
- return create(xmlSchemaSource.getIdentifier(), (DOMSource) source);
+ return create(xmlSchemaSource.getIdentifier(), (DOMSource) source,
+ xmlSchemaSource.getSymbolicName().orElse(null));
private static final class Simple extends YinDomSchemaSource {
private final @NonNull SourceIdentifier identifier;
private final @NonNull DOMSource source;
private static final class Simple extends YinDomSchemaSource {
private final @NonNull SourceIdentifier identifier;
private final @NonNull DOMSource source;
+ private final String symbolicName;
- Simple(final @NonNull SourceIdentifier identifier, final @NonNull DOMSource source) {
+ Simple(final @NonNull SourceIdentifier identifier, final @NonNull DOMSource source,
+ final @Nullable String symbolicName) {
this.identifier = requireNonNull(identifier);
this.source = requireNonNull(source);
this.identifier = requireNonNull(identifier);
this.source = requireNonNull(source);
+ this.symbolicName = symbolicName;
+ @Override
+ public Optional<String> getSymbolicName() {
+ return Optional.ofNullable(symbolicName);
+ }
+
@Override
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
return toStringHelper.add("source", source);
@Override
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
return toStringHelper.add("source", source);
return xmlSchemaSource.getIdentifier();
}
return xmlSchemaSource.getIdentifier();
}
+ @Override
+ public Optional<String> getSymbolicName() {
+ return xmlSchemaSource.getSymbolicName();
+ }
+
@Override
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
return toStringHelper.add("xmlSchemaSource", xmlSchemaSource);
@Override
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
return toStringHelper.add("xmlSchemaSource", xmlSchemaSource);
final SAXParser parser = UntrustedXML.newSAXParser();
final DefaultHandler handler = new StatementSourceReferenceHandler(doc, null);
parser.parse(source.openStream(), handler);
final SAXParser parser = UntrustedXML.newSAXParser();
final DefaultHandler handler = new StatementSourceReferenceHandler(doc, null);
parser.parse(source.openStream(), handler);
- return YinDomSchemaSource.create(source.getIdentifier(), new DOMSource(doc));
+ return YinDomSchemaSource.create(source.getIdentifier(), new DOMSource(doc),
+ source.getSymbolicName().orElse(null));