com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper Java Examples

The following examples show how to use com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper. 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: XMLConvertor.java    From SI with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void initialize(String schema) throws JAXBException {

		um = context.createUnmarshaller();
		um.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/xml");
	
		m = context.createMarshaller();
		m.setProperty(Marshaller.JAXB_ENCODING, "utf-8");
		m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
		m.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper",
				new NamespacePrefixMapper() {
					@Override
					public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
						if(namespaceUri.equals(WellKnownNamespace.XML_SCHEMA_INSTANCE)) {
							return "xsi";
						} else 
							return "m2m";
					}
				});
		String schemaLocation = schema;

		if(schemaLocation != null) {
			m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.onem2m.org/xml/protocols " + schemaLocation);
		}
		m.setProperty(MarshallerProperties.MEDIA_TYPE, "application/xml");
	}
 
Example #2
Source File: XMLConvertor.java    From SI with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void initialize(String schema) throws JAXBException {

		um = context.createUnmarshaller();
		um.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/xml");
	
		m = context.createMarshaller();
		m.setProperty(Marshaller.JAXB_ENCODING, "utf-8");
		m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
		m.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper",
				new NamespacePrefixMapper() {
					@Override
					public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
						if(namespaceUri.equals(WellKnownNamespace.XML_SCHEMA_INSTANCE)) {
							return "xsi";
						} else 
							return "m2m";
					}
				});
		String schemaLocation = schema;

		if(schemaLocation != null) {
			m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.onem2m.org/xml/protocols " + schemaLocation);
		}
		m.setProperty(MarshallerProperties.MEDIA_TYPE, "application/xml");
	}
 
Example #3
Source File: NamespaceContextImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public NamespacePrefixMapper getPrefixMapper() {
    return prefixMapper;
}
 
Example #4
Source File: NamespaceContextImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void setPrefixMapper( NamespacePrefixMapper mapper ) {
    if(mapper==null)
        mapper = defaultNamespacePrefixMapper;
    this.prefixMapper = mapper;
}
 
Example #5
Source File: MarshallerImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setProperty(String name, Object value) throws PropertyException {
    if( INDENT_STRING.equals(name) ) {
        checkString(name, value);
        indent = (String)value;
        return;
    }
    if( ENCODING_HANDLER.equals(name) || ENCODING_HANDLER2.equals(name)) {
        if(!(value instanceof CharacterEscapeHandler))
            throw new PropertyException(
                Messages.MUST_BE_X.format(
                        name,
                        CharacterEscapeHandler.class.getName(),
                        value.getClass().getName() ) );
        escapeHandler = (CharacterEscapeHandler)value;
        return;
    }
    if( PREFIX_MAPPER.equals(name) ) {
        if(!(value instanceof NamespacePrefixMapper))
            throw new PropertyException(
                Messages.MUST_BE_X.format(
                        name,
                        NamespacePrefixMapper.class.getName(),
                        value.getClass().getName() ) );
        prefixMapper = (NamespacePrefixMapper)value;
        return;
    }
    if( XMLDECLARATION.equals(name) ) {
        checkBoolean(name, value);
        // com.sun.xml.internal.bind.xmlDeclaration is an alias for JAXB_FRAGMENT
        // setting it to false is treated the same as setting fragment to true.
        super.setProperty(JAXB_FRAGMENT, !(Boolean)value);
        return;
    }
    if( XML_HEADERS.equals(name) ) {
        checkString(name, value);
        header = (String)value;
        return;
    }
    if( C14N.equals(name) ) {
        checkBoolean(name,value);
        c14nSupport = (Boolean)value;
        return;
    }
    if (OBJECT_IDENTITY_CYCLE_DETECTION.equals(name)) {
            checkBoolean(name,value);
        serializer.setObjectIdentityCycleDetection((Boolean)value);
        return;
    }

    super.setProperty(name, value);
}
 
Example #6
Source File: XMLSerializer.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void setPrefixMapper(NamespacePrefixMapper prefixMapper) {
    nsContext.setPrefixMapper(prefixMapper);
}
 
Example #7
Source File: NamespaceContextImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void setPrefixMapper( NamespacePrefixMapper mapper ) {
    if(mapper==null)
        mapper = defaultNamespacePrefixMapper;
    this.prefixMapper = mapper;
}
 
Example #8
Source File: NamespaceContextImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public NamespacePrefixMapper getPrefixMapper() {
    return prefixMapper;
}
 
Example #9
Source File: MarshallerImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setProperty(String name, Object value) throws PropertyException {
    if( INDENT_STRING.equals(name) ) {
        checkString(name, value);
        indent = (String)value;
        return;
    }
    if( ENCODING_HANDLER.equals(name) || ENCODING_HANDLER2.equals(name)) {
        if(!(value instanceof CharacterEscapeHandler))
            throw new PropertyException(
                Messages.MUST_BE_X.format(
                        name,
                        CharacterEscapeHandler.class.getName(),
                        value.getClass().getName() ) );
        escapeHandler = (CharacterEscapeHandler)value;
        return;
    }
    if( PREFIX_MAPPER.equals(name) ) {
        if(!(value instanceof NamespacePrefixMapper))
            throw new PropertyException(
                Messages.MUST_BE_X.format(
                        name,
                        NamespacePrefixMapper.class.getName(),
                        value.getClass().getName() ) );
        prefixMapper = (NamespacePrefixMapper)value;
        return;
    }
    if( XMLDECLARATION.equals(name) ) {
        checkBoolean(name, value);
        // com.sun.xml.internal.bind.xmlDeclaration is an alias for JAXB_FRAGMENT
        // setting it to false is treated the same as setting fragment to true.
        super.setProperty(JAXB_FRAGMENT, !(Boolean)value);
        return;
    }
    if( XML_HEADERS.equals(name) ) {
        checkString(name, value);
        header = (String)value;
        return;
    }
    if( C14N.equals(name) ) {
        checkBoolean(name,value);
        c14nSupport = (Boolean)value;
        return;
    }
    if (OBJECT_IDENTITY_CYCLE_DETECTION.equals(name)) {
            checkBoolean(name,value);
        serializer.setObjectIdentityCycleDetection((Boolean)value);
        return;
    }

    super.setProperty(name, value);
}
 
Example #10
Source File: XMLSerializer.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void setPrefixMapper(NamespacePrefixMapper prefixMapper) {
    nsContext.setPrefixMapper(prefixMapper);
}
 
Example #11
Source File: NamespaceContextImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void setPrefixMapper( NamespacePrefixMapper mapper ) {
    if(mapper==null)
        mapper = defaultNamespacePrefixMapper;
    this.prefixMapper = mapper;
}
 
Example #12
Source File: NamespaceContextImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public NamespacePrefixMapper getPrefixMapper() {
    return prefixMapper;
}
 
Example #13
Source File: MarshallerImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setProperty(String name, Object value) throws PropertyException {
    if( INDENT_STRING.equals(name) ) {
        checkString(name, value);
        indent = (String)value;
        return;
    }
    if( ENCODING_HANDLER.equals(name) || ENCODING_HANDLER2.equals(name)) {
        if(!(value instanceof CharacterEscapeHandler))
            throw new PropertyException(
                Messages.MUST_BE_X.format(
                        name,
                        CharacterEscapeHandler.class.getName(),
                        value.getClass().getName() ) );
        escapeHandler = (CharacterEscapeHandler)value;
        return;
    }
    if( PREFIX_MAPPER.equals(name) ) {
        if(!(value instanceof NamespacePrefixMapper))
            throw new PropertyException(
                Messages.MUST_BE_X.format(
                        name,
                        NamespacePrefixMapper.class.getName(),
                        value.getClass().getName() ) );
        prefixMapper = (NamespacePrefixMapper)value;
        return;
    }
    if( XMLDECLARATION.equals(name) ) {
        checkBoolean(name, value);
        // com.sun.xml.internal.bind.xmlDeclaration is an alias for JAXB_FRAGMENT
        // setting it to false is treated the same as setting fragment to true.
        super.setProperty(JAXB_FRAGMENT, !(Boolean)value);
        return;
    }
    if( XML_HEADERS.equals(name) ) {
        checkString(name, value);
        header = (String)value;
        return;
    }
    if( C14N.equals(name) ) {
        checkBoolean(name,value);
        c14nSupport = (Boolean)value;
        return;
    }
    if (OBJECT_IDENTITY_CYCLE_DETECTION.equals(name)) {
            checkBoolean(name,value);
        serializer.setObjectIdentityCycleDetection((Boolean)value);
        return;
    }

    super.setProperty(name, value);
}
 
Example #14
Source File: XMLSerializer.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void setPrefixMapper(NamespacePrefixMapper prefixMapper) {
    nsContext.setPrefixMapper(prefixMapper);
}
 
Example #15
Source File: NamespaceContextImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void setPrefixMapper( NamespacePrefixMapper mapper ) {
    if(mapper==null)
        mapper = defaultNamespacePrefixMapper;
    this.prefixMapper = mapper;
}
 
Example #16
Source File: NamespaceContextImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public NamespacePrefixMapper getPrefixMapper() {
    return prefixMapper;
}
 
Example #17
Source File: MarshallerImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setProperty(String name, Object value) throws PropertyException {
    if( INDENT_STRING.equals(name) ) {
        checkString(name, value);
        indent = (String)value;
        return;
    }
    if( ENCODING_HANDLER.equals(name) || ENCODING_HANDLER2.equals(name)) {
        if(!(value instanceof CharacterEscapeHandler))
            throw new PropertyException(
                Messages.MUST_BE_X.format(
                        name,
                        CharacterEscapeHandler.class.getName(),
                        value.getClass().getName() ) );
        escapeHandler = (CharacterEscapeHandler)value;
        return;
    }
    if( PREFIX_MAPPER.equals(name) ) {
        if(!(value instanceof NamespacePrefixMapper))
            throw new PropertyException(
                Messages.MUST_BE_X.format(
                        name,
                        NamespacePrefixMapper.class.getName(),
                        value.getClass().getName() ) );
        prefixMapper = (NamespacePrefixMapper)value;
        return;
    }
    if( XMLDECLARATION.equals(name) ) {
        checkBoolean(name, value);
        // com.sun.xml.internal.bind.xmlDeclaration is an alias for JAXB_FRAGMENT
        // setting it to false is treated the same as setting fragment to true.
        super.setProperty(JAXB_FRAGMENT, !(Boolean)value);
        return;
    }
    if( XML_HEADERS.equals(name) ) {
        checkString(name, value);
        header = (String)value;
        return;
    }
    if( C14N.equals(name) ) {
        checkBoolean(name,value);
        c14nSupport = (Boolean)value;
        return;
    }
    if (OBJECT_IDENTITY_CYCLE_DETECTION.equals(name)) {
            checkBoolean(name,value);
        serializer.setObjectIdentityCycleDetection((Boolean)value);
        return;
    }

    super.setProperty(name, value);
}
 
Example #18
Source File: NamespaceContextImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void setPrefixMapper( NamespacePrefixMapper mapper ) {
    if(mapper==null)
        mapper = defaultNamespacePrefixMapper;
    this.prefixMapper = mapper;
}
 
Example #19
Source File: NamespaceContextImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void setPrefixMapper( NamespacePrefixMapper mapper ) {
    if(mapper==null)
        mapper = defaultNamespacePrefixMapper;
    this.prefixMapper = mapper;
}
 
Example #20
Source File: NamespaceContextImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public NamespacePrefixMapper getPrefixMapper() {
    return prefixMapper;
}
 
Example #21
Source File: MarshallerImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setProperty(String name, Object value) throws PropertyException {
    if( INDENT_STRING.equals(name) ) {
        checkString(name, value);
        indent = (String)value;
        return;
    }
    if( ENCODING_HANDLER.equals(name) || ENCODING_HANDLER2.equals(name)) {
        if(!(value instanceof CharacterEscapeHandler))
            throw new PropertyException(
                Messages.MUST_BE_X.format(
                        name,
                        CharacterEscapeHandler.class.getName(),
                        value.getClass().getName() ) );
        escapeHandler = (CharacterEscapeHandler)value;
        return;
    }
    if( PREFIX_MAPPER.equals(name) ) {
        if(!(value instanceof NamespacePrefixMapper))
            throw new PropertyException(
                Messages.MUST_BE_X.format(
                        name,
                        NamespacePrefixMapper.class.getName(),
                        value.getClass().getName() ) );
        prefixMapper = (NamespacePrefixMapper)value;
        return;
    }
    if( XMLDECLARATION.equals(name) ) {
        checkBoolean(name, value);
        // com.sun.xml.internal.bind.xmlDeclaration is an alias for JAXB_FRAGMENT
        // setting it to false is treated the same as setting fragment to true.
        super.setProperty(JAXB_FRAGMENT, !(Boolean)value);
        return;
    }
    if( XML_HEADERS.equals(name) ) {
        checkString(name, value);
        header = (String)value;
        return;
    }
    if( C14N.equals(name) ) {
        checkBoolean(name,value);
        c14nSupport = (Boolean)value;
        return;
    }
    if (OBJECT_IDENTITY_CYCLE_DETECTION.equals(name)) {
            checkBoolean(name,value);
        serializer.setObjectIdentityCycleDetection((Boolean)value);
        return;
    }

    super.setProperty(name, value);
}
 
Example #22
Source File: XMLSerializer.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void setPrefixMapper(NamespacePrefixMapper prefixMapper) {
    nsContext.setPrefixMapper(prefixMapper);
}
 
Example #23
Source File: NamespaceContextImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void setPrefixMapper( NamespacePrefixMapper mapper ) {
    if(mapper==null)
        mapper = defaultNamespacePrefixMapper;
    this.prefixMapper = mapper;
}
 
Example #24
Source File: NamespaceContextImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public NamespacePrefixMapper getPrefixMapper() {
    return prefixMapper;
}
 
Example #25
Source File: MarshallerImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setProperty(String name, Object value) throws PropertyException {
    if( INDENT_STRING.equals(name) ) {
        checkString(name, value);
        indent = (String)value;
        return;
    }
    if( ENCODING_HANDLER.equals(name) || ENCODING_HANDLER2.equals(name)) {
        if(!(value instanceof CharacterEscapeHandler))
            throw new PropertyException(
                Messages.MUST_BE_X.format(
                        name,
                        CharacterEscapeHandler.class.getName(),
                        value.getClass().getName() ) );
        escapeHandler = (CharacterEscapeHandler)value;
        return;
    }
    if( PREFIX_MAPPER.equals(name) ) {
        if(!(value instanceof NamespacePrefixMapper))
            throw new PropertyException(
                Messages.MUST_BE_X.format(
                        name,
                        NamespacePrefixMapper.class.getName(),
                        value.getClass().getName() ) );
        prefixMapper = (NamespacePrefixMapper)value;
        return;
    }
    if( XMLDECLARATION.equals(name) ) {
        checkBoolean(name, value);
        // com.sun.xml.internal.bind.xmlDeclaration is an alias for JAXB_FRAGMENT
        // setting it to false is treated the same as setting fragment to true.
        super.setProperty(JAXB_FRAGMENT, !(Boolean)value);
        return;
    }
    if( XML_HEADERS.equals(name) ) {
        checkString(name, value);
        header = (String)value;
        return;
    }
    if( C14N.equals(name) ) {
        checkBoolean(name,value);
        c14nSupport = (Boolean)value;
        return;
    }
    if (OBJECT_IDENTITY_CYCLE_DETECTION.equals(name)) {
            checkBoolean(name,value);
        serializer.setObjectIdentityCycleDetection((Boolean)value);
        return;
    }

    super.setProperty(name, value);
}
 
Example #26
Source File: XMLSerializer.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void setPrefixMapper(NamespacePrefixMapper prefixMapper) {
    nsContext.setPrefixMapper(prefixMapper);
}
 
Example #27
Source File: XMLSerializer.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void setPrefixMapper(NamespacePrefixMapper prefixMapper) {
    nsContext.setPrefixMapper(prefixMapper);
}
 
Example #28
Source File: NamespaceContextImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public NamespacePrefixMapper getPrefixMapper() {
    return prefixMapper;
}
 
Example #29
Source File: MarshallerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setProperty(String name, Object value) throws PropertyException {
    if( INDENT_STRING.equals(name) ) {
        checkString(name, value);
        indent = (String)value;
        return;
    }
    if( ENCODING_HANDLER.equals(name) || ENCODING_HANDLER2.equals(name)) {
        if(!(value instanceof CharacterEscapeHandler))
            throw new PropertyException(
                Messages.MUST_BE_X.format(
                        name,
                        CharacterEscapeHandler.class.getName(),
                        value.getClass().getName() ) );
        escapeHandler = (CharacterEscapeHandler)value;
        return;
    }
    if( PREFIX_MAPPER.equals(name) ) {
        if(!(value instanceof NamespacePrefixMapper))
            throw new PropertyException(
                Messages.MUST_BE_X.format(
                        name,
                        NamespacePrefixMapper.class.getName(),
                        value.getClass().getName() ) );
        prefixMapper = (NamespacePrefixMapper)value;
        return;
    }
    if( XMLDECLARATION.equals(name) ) {
        checkBoolean(name, value);
        // com.sun.xml.internal.bind.xmlDeclaration is an alias for JAXB_FRAGMENT
        // setting it to false is treated the same as setting fragment to true.
        super.setProperty(JAXB_FRAGMENT, !(Boolean)value);
        return;
    }
    if( XML_HEADERS.equals(name) ) {
        checkString(name, value);
        header = (String)value;
        return;
    }
    if( C14N.equals(name) ) {
        checkBoolean(name,value);
        c14nSupport = (Boolean)value;
        return;
    }
    if (OBJECT_IDENTITY_CYCLE_DETECTION.equals(name)) {
            checkBoolean(name,value);
        serializer.setObjectIdentityCycleDetection((Boolean)value);
        return;
    }

    super.setProperty(name, value);
}
 
Example #30
Source File: XMLSerializer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void setPrefixMapper(NamespacePrefixMapper prefixMapper) {
    nsContext.setPrefixMapper(prefixMapper);
}