Package org.eclipse.sapphire.modeling.xml

Examples of org.eclipse.sapphire.modeling.xml.XmlElement


    }

    @Override
    public Element convert( final XmlResource resource )
    {
        final XmlElement element = resource.getXmlElement();
       
        if( element != null )
        {
            return element.getDomNode();
        }
       
        return null;
    }
View Full Code Here


           
            if( ! range.initialized() )
            {
                Element modElement = element;
                Resource resource = modElement.resource();
                XmlElement xmlElement = null;
               
                if( resource != null )
                {
                    xmlElement = ( (XmlResource) resource ).getXmlElement();
                }
               
                while( xmlElement == null && modElement != null )
                {
                    final Property parent = modElement.parent();
                   
                    if( parent == null )
                    {
                        modElement = null;
                    }
                    else
                    {
                        modElement = parent.element();
                        resource = modElement.resource();
                       
                        if( resource != null )
                        {
                            xmlElement = ( (XmlResource) resource ).getXmlElement();
                        }
                    }
                }
                   
                if( xmlElement != null )
                {
                    final IDOMNode domNode = (IDOMNode) xmlElement.getDomNode();
                    range.merge( domNode.getStartOffset(), domNode.getEndOffset() );
                }
            }
           
            final TextSelection textSelection
View Full Code Here

    {
        final Resource resource = element.resource();
       
        if( resource instanceof XmlResource )
        {
            final XmlElement xmlElement = ( (XmlResource) resource ).getXmlElement();
           
            if( xmlElement != null )
            {
                return xmlElement.getDomNode();
            }
        }
       
        return null;
    }
View Full Code Here

    private static final String EL_NUMBER = "number";
   
    @Override
    public String read()
    {
        final XmlElement el = ( (XmlResource) property().element().resource() ).getXmlElement( false );
       
        final String pnStr = el.getChildNodeText( EL_NUMBER );
        final ParsedPhoneNumber pn = new ParsedPhoneNumber( pnStr );

        return pn.getLocalNumber();
    }
View Full Code Here

    }

    @Override
    public void write( final String value )
    {
        final XmlElement el = ( (XmlResource) property().element().resource() ).getXmlElement( false );
       
        final String pnStr = el.getChildNodeText( EL_NUMBER );
        final ParsedPhoneNumber pn = new ParsedPhoneNumber( pnStr );

        pn.setLocalNumber( value );
        el.setChildNodeText( EL_NUMBER, pn.toString(), true );
    }
View Full Code Here

    private static final XmlPath PATH_CONTENT = new XmlPath( "content", NAMESPACE_RESOLVER );
   
    @Override
    public String read()
    {
        final XmlElement element = xml();
        HtmlContentSourceType type = null;
       
        if( element.getChildNode( PATH_URL, false ) != null )
        {
            type = HtmlContentSourceType.REMOTE;
        }
        else if( element.getChildNode( PATH_CONTENT, false ) != null )
        {
            type = HtmlContentSourceType.EMBEDDED;
        }
       
        return property().element().property( HtmlPanelDef.PROP_CONTENT_SOURCE_TYPE ).service( MasterConversionService.class ).convert( type, String.class );
View Full Code Here

    }

    @Override
    public void write( final String value )
    {
        final XmlElement element = xml();
        final HtmlContentSourceType type = property().element().property( HtmlPanelDef.PROP_CONTENT_SOURCE_TYPE ).service( MasterConversionService.class ).convert( value, HtmlContentSourceType.class );
       
        if( value == null )
        {
            element.removeChildNode( PATH_URL );
            element.removeChildNode( PATH_CONTENT );
        }
        else if( type == HtmlContentSourceType.REMOTE )
        {
            element.removeChildNode( PATH_CONTENT );
            element.getChildNode( PATH_URL, true );
        }
        else if( type == HtmlContentSourceType.EMBEDDED )
        {
            element.removeChildNode( PATH_URL );
            element.getChildNode( PATH_CONTENT, true );
        }
        else
        {
            throw new IllegalStateException();
        }
View Full Code Here

    }

    @Override
    public XmlNode getXmlNode()
    {
        final XmlElement element = xml();
       
        XmlNode node = element.getChildNode( PATH_URL, false );
       
        if( node != null )
        {
            return node;
        }
       
        node = element.getChildNode( PATH_CONTENT, false );
       
        if( node != null )
        {
            return node;
        }
View Full Code Here

           
            try
            {
                final WorkspaceFileResourceStore fileResourceStore = new WorkspaceFileResourceStore( targetSchemaFile );
                final XmlResourceStore xmlResourceStore = new XmlResourceStore( fileResourceStore );
                final XmlElement root = new XmlElement( xmlResourceStore, xmlResourceStore.getDomDocument().getDocumentElement() );
               
                final String targetNamespace = root.getAttributeText( "targetNamespace" );
                String targetNamespacePrefix = null;
               
                for( XmlAttribute attribute : root.getAttributes() )
                {
                    final String name = attribute.getDomNode().getName();
                    final String value = attribute.getText();
                   
                    if( name.startsWith( "xmlns:" ) && value.equals( targetNamespace ) )
                    {
                        targetNamespacePrefix = name.substring( 6 );
                    }
                }
   
                final Set<String> included = new HashSet<String>();
                included.add( sourceSchemaFile.getLocation().toOSString() );
                while( inlineIncludes( root, sourceSchemaFile.getParent().getLocation().toOSString(), included ) );
               
                removeComments( root );
                removeAnnotations( root );
                removeDefaultMinMaxOccurs( root );
               
                if( operation.getRemoveWildcards().content() )
                {
                    removeWildcards( root );
                }
               
                exclude( root, operation.getExclusions() );
               
                final Map<String,XmlElement> types = new HashMap<String,XmlElement>();
                final Map<String,XmlElement> elements = new HashMap<String,XmlElement>();
                final Map<String,XmlElement> groups = new HashMap<String,XmlElement>();
               
                for( XmlElement element : root.getChildElements() )
                {
                    final String elname = element.getLocalName();
                   
                    if( elname.equals( "simpleType" ) || elname.equals( "complexType" ) )
                    {
                        String tname = element.getAttributeText( "name" );
                       
                        if( tname.length() > 0 )
                        {
                            if( targetNamespacePrefix != null )
                            {
                                tname = targetNamespacePrefix + ":" + tname;
                            }
                           
                            if( types.containsKey( tname ) )
                            {
                                element.remove();
                            }
                            else
                            {
                                types.put( tname, element );
                            }
                        }
                    }
                    else if( elname.equals( "element" ) )
                    {
                        String ename = element.getAttributeText( "name" );
                       
                        if( ename.length() > 0 )
                        {
                            if( targetNamespacePrefix != null )
                            {
                                ename = targetNamespacePrefix + ":" + ename;
                            }
                           
                            if( elements.containsKey( ename ) )
                            {
                                element.remove();
                            }
                            else
                            {
                                elements.put( ename, element );
                            }
                        }
                    }
                    else if( elname.equals( "group" ) )
                    {
                        String gname = element.getAttributeText( "name" );
                       
                        if( gname.length() > 0 )
                        {
                            if( targetNamespacePrefix != null )
                            {
                                gname = targetNamespacePrefix + ":" + gname;
                            }
                           
                            if( groups.containsKey( gname ) )
                            {
                                element.remove();
                            }
                            else
                            {
                                groups.put( gname, element );
                            }
                        }
                    }
                }
               
                changeSchemaNamespacePrefix( root.getDomNode().getOwnerDocument(), "xsd" );
               
                final Map<String,String> typeSubstitutions = new HashMap<String,String>();
               
                for( TypeSubstitution sub : operation.getTypeSubstitutions() )
                {
                    typeSubstitutions.put( sub.getBefore().content(), sub.getAfter().content() );
                }
               
                applyTypeSubstitutions( root, typeSubstitutions );
               
                boolean keepInlining = true;
               
                while( keepInlining )
                {
                    keepInlining =
                        inlineRestriction( root )
                        || inlineExtension( root )
                        || inlineSequenceInSequence( root )
                        || inlineSequenceInChoice( root )
                        || inlineTypes( root, types, SetFactory.<String>empty() )
                        || inlineElements( root, elements, SetFactory.<String>empty() )
                        || inlineGroups( root, groups, SetFactory.<String>empty() )
                        || removeRedundantMinMaxOccursInChoice( root );
                }
               
                for( XmlElement element : root.getChildElements() )
                {
                    final String elname = element.getLocalName();
                   
                    if( elname.equals( "simpleType" ) || elname.equals( "complexType" ) || elname.equals( "group" ) )
                    {
                        element.remove();
                    }
                }
               
                // If root elements are specified, remove all other top-level elements.
               
                if( ! operation.getRootElements().empty() )
                {
                    final SetFactory<String> rootsFactory = SetFactory.start();
                   
                    operation.visit
                    (
                        "RootElements/Name",
                        new PropertyVisitor()
                        {
                            @Override
                            public boolean visit( final Value<?> property )
                            {
                                rootsFactory.add( property.text() );
                                return true;
                            }
                        }
                    );
                   
                    final Set<String> roots = rootsFactory.result();
                           
                    for( XmlElement element : root.getChildElements() )
                    {
                        final String elname = element.getLocalName();
                       
                        if( elname.equals( "element" ) && ! roots.contains( element.getAttributeText( "name" ) ) )
                        {
                            element.remove();
                        }
                    }
                }
               
                sortChoiceContent( root );
                sortElementContent( root );
               
                if( operation.getSortSequenceContent().content() )
                {
                    sortSequenceContent( root );
                }
               
                sort( root );
               
                root.format();
               
                xmlResourceStore.save();
            }
            catch( ResourceStoreException e )
            {
View Full Code Here

                {
                    includedSchemaResourceStore = new FileResourceStore( new File( includedSchemaLocation ) );
                }
           
                final XmlResourceStore xmlResourceStore = new XmlResourceStore( includedSchemaResourceStore );
                final XmlElement includedSchemaRoot = new XmlElement( xmlResourceStore, xmlResourceStore.getDomDocument().getDocumentElement() );
   
                for( XmlElement includedSchemaElement : includedSchemaRoot.getChildElements() )
                {
                    final Element inlinedDomNode = (Element) document.importNode( includedSchemaElement.getDomNode(), true );
                    rootDomNode.insertBefore( inlinedDomNode, includeElementDomNode );
                }
               
View Full Code Here

TOP

Related Classes of org.eclipse.sapphire.modeling.xml.XmlElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.