Java 类com.intellij.util.xml.XmlFileHeader 实例源码

项目:consulo    文件:NanoXmlUtilTest.java   
@Test
public void testXsdHeader() throws Exception {
  XmlFileHeader xmlFileHeader = NanoXmlUtil.parseHeaderWithException(new StringReader("<?xml version=\"1.0\"?>\n" +
                                                                                      "\n" +
                                                                                      "<note\n" +
                                                                                      "xmlns=\"https://www.w3schools.com\"\n" +
                                                                                      "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
                                                                                      "xsi:schemaLocation=\"https://www.w3schools.com/xml/note.xsd\">\n" +
                                                                                      "  <to>Tove</to>\n" +
                                                                                      "  <from>Jani</from>\n" +
                                                                                      "  <heading>Reminder</heading>\n" +
                                                                                      "  <body>Don't forget me this weekend!</body>\n" +
                                                                                      "</note>"));

  assertEquals("note", xmlFileHeader.getRootTagLocalName());
  assertEquals("https://www.w3schools.com", xmlFileHeader.getRootTagNamespace());
}
项目:intellij-ce-playground    文件:FileStubSerializer.java   
@Override
public void serialize(@NotNull FileStub stub, @NotNull StubOutputStream dataStream) throws IOException {
  XmlFileHeader header = stub.getHeader();
  dataStream.writeName(header.getRootTagLocalName());
  dataStream.writeName(header.getRootTagNamespace());
  dataStream.writeName(header.getPublicId());
  dataStream.writeName(header.getSystemId());
}
项目:intellij-ce-playground    文件:FileStub.java   
public FileStub(StringRef tagName, StringRef tagNamespace, StringRef publicId, StringRef systemId) {
  super(null, tagName, tagNamespace, 0, false, null, "");
  myHeader = new XmlFileHeader(tagName.getString(),
                               tagNamespace == null ? null : tagNamespace.getString(),
                               publicId == null ? null : publicId.getString(),
                               systemId == null ? null : systemId.getString());
}
项目:tools-idea    文件:FileStubSerializer.java   
@Override
public void serialize(@NotNull FileStub stub, @NotNull StubOutputStream dataStream) throws IOException {
  XmlFileHeader header = stub.getHeader();
  dataStream.writeName(header.getRootTagLocalName());
  dataStream.writeName(header.getRootTagNamespace());
  dataStream.writeName(header.getPublicId());
  dataStream.writeName(header.getSystemId());
}
项目:tools-idea    文件:FileStub.java   
public FileStub(StringRef tagName, StringRef tagNamespace, StringRef publicId, StringRef systemId) {
  super(null, tagName, tagNamespace, false);
  myHeader = new XmlFileHeader(tagName.getString(),
                               tagNamespace == null ? null : tagNamespace.getString(),
                               publicId == null ? null : publicId.getString(),
                               systemId == null ? null : systemId.getString());
}
项目:consulo    文件:NanoXmlUtilTest.java   
@Test
public void testDtdHeader() throws Exception {
  XmlFileHeader xmlFileHeader = NanoXmlUtil.parseHeaderWithException(new StringReader("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                                                                                      "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" +
                                                                                      "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" +
                                                                                      "<!-- the XHTML document body starts here-->\n" +
                                                                                      "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
                                                                                      "</html>"));

  assertEquals("html", xmlFileHeader.getRootTagLocalName());
  assertEquals("http://www.w3.org/1999/xhtml", xmlFileHeader.getRootTagNamespace());
  assertEquals("-//W3C//DTD XHTML 1.0 Transitional//EN", xmlFileHeader.getPublicId());
  assertEquals("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xmlFileHeader.getSystemId());
}
项目:consulo-xml    文件:FileStubSerializer.java   
@Override
public void serialize(@NotNull FileStub stub, @NotNull StubOutputStream dataStream) throws IOException
{
    XmlFileHeader header = stub.getHeader();
    dataStream.writeName(header.getRootTagLocalName());
    dataStream.writeName(header.getRootTagNamespace());
    dataStream.writeName(header.getPublicId());
    dataStream.writeName(header.getSystemId());
}
项目:consulo-xml    文件:FileDescriptionCachedValueProvider.java   
public String getFileElementWithLogging()
{
    final XmlFileHeader rootTagName = myDomService.getXmlFileHeader(myXmlFile);
    final StringBuilder log = new StringBuilder();
    myLastResult = _computeFileElement(false, rootTagName, log);
    return log.toString();
}
项目:intellij-ce-playground    文件:FileContentPattern.java   
@NotNull
private static XmlFileHeader parseHeaderWithException(FileContent fileContent) throws IOException {
  //noinspection IOResourceOpenedButNotSafelyClosed
  return NanoXmlUtil.parseHeaderWithException(CharArrayUtil.readerFromCharSequence(fileContent.getContentAsText()));
}
项目:intellij-ce-playground    文件:FileStub.java   
public FileStub(XmlFileHeader header) {
  super(null, StringRef.fromString(header.getRootTagLocalName()), StringRef.fromString(header.getRootTagNamespace()), 0, false, null, "");
  myHeader = header;
}
项目:intellij-ce-playground    文件:FileStub.java   
public XmlFileHeader getHeader() {
  return myHeader;
}
项目:tools-idea    文件:FileContentPattern.java   
@NotNull
private static XmlFileHeader parseHeaderWithException(FileContent fileContent) throws IOException {
  //noinspection IOResourceOpenedButNotSafelyClosed
  return NanoXmlUtil.parseHeaderWithException(CharArrayUtil.readerFromCharSequence(fileContent.getContentAsText()));
}
项目:tools-idea    文件:FileStub.java   
public FileStub(XmlFileHeader header) {
  super(null, StringRef.fromString(header.getRootTagLocalName()), StringRef.fromString(header.getRootTagNamespace()), false);
  myHeader = header;
}
项目:tools-idea    文件:FileStub.java   
public XmlFileHeader getHeader() {
  return myHeader;
}
项目:consulo    文件:FileContentPattern.java   
@Nonnull
private static XmlFileHeader parseHeaderWithException(FileContent fileContent) throws IOException {
  //noinspection IOResourceOpenedButNotSafelyClosed
  return NanoXmlUtil.parseHeaderWithException(CharArrayUtil.readerFromCharSequence(fileContent.getContentAsText()));
}
项目:consulo-xml    文件:FileStub.java   
public FileStub(StringRef tagName, StringRef tagNamespace, StringRef publicId, StringRef systemId)
{
    super(null, tagName, tagNamespace, 0, false, null);
    myHeader = new XmlFileHeader(tagName.getString(), tagNamespace == null ? null : tagNamespace.getString(),
            publicId == null ? null : publicId.getString(), systemId == null ? null : systemId.getString());
}
项目:consulo-xml    文件:FileStub.java   
public FileStub(XmlFileHeader header)
{
    super(null, StringRef.fromString(header.getRootTagLocalName()), StringRef.fromString(header.getRootTagNamespace()), 0, false, null);
    myHeader = header;
}
项目:consulo-xml    文件:FileStub.java   
public XmlFileHeader getHeader()
{
    return myHeader;
}
项目:consulo-xml    文件:DomStubBuilder.java   
@Override
public Stub buildStubTree(FileContent fileContent)
{
    VirtualFile file = fileContent.getFile();
    Project project = fileContent.getProject();
    PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    if(!(psiFile instanceof XmlFile))
    {
        return null;
    }

    XmlFile xmlFile = (XmlFile) psiFile;
    try
    {
        XmlUtil.BUILDING_DOM_STUBS.set(Boolean.TRUE);
        psiFile.putUserData(CONTENT_FOR_DOM_STUBS, fileContent);
        DomFileElement<? extends DomElement> fileElement = DomManager.getDomManager(project).getFileElement(xmlFile);
        if(fileElement == null || !fileElement.getFileDescription().hasStubs())
        {
            return null;
        }

        XmlFileHeader header = DomService.getInstance().getXmlFileHeader(xmlFile);
        if(header.getRootTagLocalName() == null)
        {
            LOG.error("null root tag for " + fileElement + " for " + file);
        }
        FileStub fileStub = new FileStub(header);
        XmlTag rootTag = xmlFile.getRootTag();
        if(rootTag != null)
        {
            new DomStubBuilderVisitor(DomManagerImpl.getDomManager(project)).visitXmlElement(rootTag, fileStub, 0);
        }
        return fileStub;
    }
    finally
    {
        XmlUtil.BUILDING_DOM_STUBS.set(Boolean.FALSE);
        psiFile.putUserData(CONTENT_FOR_DOM_STUBS, null);
    }
}
项目:consulo-xml    文件:FileDescriptionCachedValueProvider.java   
@Nullable
private DomFileElementImpl<T> _computeFileElement(final boolean fireEvents, @NotNull final XmlFileHeader rootTagName, @Nullable StringBuilder sb)
{
    if(sb != null)
    {
        sb.append(rootTagName).append("\n");
    }

    if(!myXmlFile.isValid())
    {
        return null;
    }
    if(sb != null)
    {
        sb.append("File is valid\n");
    }

    final DomFileDescription<T> description = findFileDescription(rootTagName, sb);

    final DomFileElementImpl oldValue = getLastValue();
    if(sb != null)
    {
        sb.append("last " + oldValue + "\n");
    }
    final List<DomEvent> events = fireEvents ? new SmartList<DomEvent>() : Collections.<DomEvent>emptyList();
    if(oldValue != null)
    {
        if(fireEvents)
        {
            events.add(new DomEvent(oldValue, false));
        }
    }

    if(description == null)
    {
        return null;
    }

    final Class<T> rootElementClass = description.getRootElementClass();
    final XmlName xmlName = DomImplUtil.createXmlName(description.getRootTagName(), rootElementClass, null);
    assert xmlName != null;
    final EvaluatedXmlNameImpl rootTagName1 = EvaluatedXmlNameImpl.createEvaluatedXmlName(xmlName, xmlName.getNamespaceKey(), false);

    VirtualFile file = myXmlFile.getVirtualFile();
    FileStub stub = null;
    if(description.hasStubs() && file instanceof VirtualFileWithId && !isFileParsed())
    {
        ApplicationManager.getApplication().assertReadAccessAllowed();
        if(!XmlUtil.isStubBuilding())
        {
            ObjectStubTree stubTree = StubTreeLoader.getInstance().readOrBuild(myXmlFile.getProject(), file, myXmlFile);
            if(stubTree != null)
            {
                stub = (FileStub) stubTree.getRoot();
            }
        }
    }

    DomFileElementImpl<T> result = new DomFileElementImpl<T>(myXmlFile, rootElementClass, rootTagName1, myDomManager, description, stub);
    if(sb != null)
    {
        sb.append("success " + result + "\n");
    }

    if(fireEvents)
    {
        events.add(new DomEvent(result, true));
    }
    return result;
}
项目:consulo-xml    文件:FileDescriptionCachedValueProvider.java   
@Nullable
private DomFileDescription<T> findFileDescription(final XmlFileHeader rootTagName, @Nullable StringBuilder sb)
{
    final DomFileDescription<T> mockDescription = myXmlFile.getUserData(DomManagerImpl.MOCK_DESCRIPTION);
    if(mockDescription != null)
    {
        return mockDescription;
    }

    if(sb != null)
    {
        sb.append("no mock\n");
    }

    final XmlFile originalFile = (XmlFile) myXmlFile.getOriginalFile();
    if(sb != null)
    {
        sb.append("original: " + originalFile + "\n");
    }
    if(!originalFile.equals(myXmlFile))
    {
        final FileDescriptionCachedValueProvider<T> provider = myDomManager.getOrCreateCachedValueProvider(originalFile);
        final DomFileElementImpl<T> element = provider.getFileElement();
        if(sb != null)
        {
            sb.append("originalDom " + element + "\n");
        }
        return element == null ? null : element.getFileDescription();
    }

    //noinspection unchecked
    final Set<DomFileDescription> namedDescriptions = myDomManager.getFileDescriptions(rootTagName.getRootTagLocalName());
    if(sb != null)
    {
        sb.append("named " + new HashSet<DomFileDescription>(namedDescriptions) + "\n");
    }
    DomFileDescription<T> description = ContainerUtil.find(namedDescriptions, myCondition);
    if(description == null)
    {
        final Set<DomFileDescription> unnamed = myDomManager.getAcceptingOtherRootTagNameDescriptions();
        description = ContainerUtil.find(unnamed, myCondition);
    }
    if(sb != null)
    {
        sb.append("found " + description + "\n");
    }
    return description;
}