Java 类org.dom4j.tree.DefaultDocument 实例源码

项目:jaxen    文件:DOM4JXPathTest.java   
public void testNamespaceNodesAreInherited() throws JaxenException
{
        Namespace ns0 = Namespace.get("p0", "www.acme0.org");
        Namespace ns1 = Namespace.get("p1", "www.acme1.org");
        Namespace ns2 = Namespace.get("p2", "www.acme2.org");
        Element element = new DefaultElement("test", ns1);
        Attribute attribute = new DefaultAttribute("pre:foo", "bar", ns2);
        element.add(attribute);
        Element root = new DefaultElement("root", ns0);
        root.add(element);
        Document doc = new DefaultDocument(root);

        XPath xpath = new Dom4jXPath( "/*/*/namespace::node()" );

        List results = xpath.selectNodes( doc );

        assertEquals( 4,
                      results.size() );
}
项目:olat    文件:CPManifest.java   
/**
 * @param doc
 */
public void buildDocument(final DefaultDocument doc) {
    // Manifest is the root-node of the document, therefore we need to pass the
    // "doc"
    final DefaultElement manifestElement = new DefaultElement(CPCore.MANIFEST);

    manifestElement.add(new DefaultAttribute(CPCore.IDENTIFIER, this.identifier));
    manifestElement.add(new DefaultAttribute(CPCore.SCHEMALOCATION, this.schemaLocation));
    // manifestElement.setNamespace(this.getNamespace()); //FIXME: namespace

    doc.add(manifestElement);

    if (metadata != null) {
        metadata.buildDocument(manifestElement);
    }
    organizations.buildDocument(manifestElement);
    resources.buildDocument(manifestElement);

}
项目:olat    文件:ContentPackage.java   
/**
 * writes the manifest.xml
 */
void writeToFile() {
    final String filename = "imsmanifest.xml";
    final OutputFormat format = OutputFormat.createPrettyPrint();

    try {
        VFSLeaf outFile;
        // file may exist
        outFile = (VFSLeaf) cpcore.getRootDir().resolve("/" + filename);
        if (outFile == null) {
            // if not, create it
            outFile = cpcore.getRootDir().createChildLeaf("/" + filename);
        }
        final DefaultDocument manifestDocument = cpcore.buildDocument();
        final XMLWriter writer = new XMLWriter(outFile.getOutputStream(false), format);
        writer.write(manifestDocument);
    } catch (final Exception e) {
        log.error("imsmanifest for ores " + ores.getResourceableId() + "couldn't be written to file.", e);
        throw new OLATRuntimeException(CPOrganizations.class, "Error writing imsmanifest-file", new IOException());
    }
}
项目:olat    文件:CPManifest.java   
/**
 * @param doc
 */
public void buildDocument(final DefaultDocument doc) {
    // Manifest is the root-node of the document, therefore we need to pass the
    // "doc"
    final DefaultElement manifestElement = new DefaultElement(CPCore.MANIFEST);

    manifestElement.add(new DefaultAttribute(CPCore.IDENTIFIER, this.identifier));
    manifestElement.add(new DefaultAttribute(CPCore.SCHEMALOCATION, this.schemaLocation));
    // manifestElement.setNamespace(this.getNamespace()); //FIXME: namespace

    doc.add(manifestElement);

    if (metadata != null) {
        metadata.buildDocument(manifestElement);
    }
    organizations.buildDocument(manifestElement);
    resources.buildDocument(manifestElement);

}
项目:olat    文件:ContentPackage.java   
/**
 * writes the manifest.xml
 */
void writeToFile() {
    final String filename = "imsmanifest.xml";
    final OutputFormat format = OutputFormat.createPrettyPrint();

    try {
        VFSLeaf outFile;
        // file may exist
        outFile = (VFSLeaf) cpcore.getRootDir().resolve("/" + filename);
        if (outFile == null) {
            // if not, create it
            outFile = cpcore.getRootDir().createChildLeaf("/" + filename);
        }
        final DefaultDocument manifestDocument = cpcore.buildDocument();
        final XMLWriter writer = new XMLWriter(outFile.getOutputStream(false), format);
        writer.write(manifestDocument);
    } catch (final Exception e) {
        log.error("imsmanifest for ores " + ores.getResourceableId() + "couldn't be written to file.", e);
        throw new OLATRuntimeException(CPOrganizations.class, "Error writing imsmanifest-file", new IOException());
    }
}
项目:community-edition-old    文件:TestAbstractListItemsEndpointTest.java   
/**
 * ALF-19833: MacOS: Could not save to SharePoint
 */
@Test
public void canGetListUsingCorrectListAndSiteName() throws Exception
{
    VtiSoapRequest soapRequest = Mockito.mock(VtiSoapRequest.class);
    VtiSoapResponse soapResponse = new VtiSoapResponse(new MockHttpServletResponse());//Mockito.mock(VtiSoapResponse.class);
    Element requestElement = Mockito.mock(Element.class);
    SimpleNamespaceContext nc = Mockito.mock(SimpleNamespaceContext.class);

    Element rootElement = new DefaultElement(QName.get("root", "lists", "some://uri"));
    when(soapRequest.getDocument()).thenReturn(new DefaultDocument(rootElement));

    // Invoke the method under test.
    listItemsEndpoint.executeListActionDetails(soapRequest, soapResponse,
                "my-site", "documentLibrary", requestElement, nc);

    // Check the condition this test is for.
    verify(listHandler).getList("documentLibrary", "my-site");
}
项目:jaxen    文件:DOM4JXPathTest.java   
public void testJaxen20AttributeNamespaceNodes() throws JaxenException
{

    Namespace ns1 = Namespace.get("p1", "www.acme1.org");
    Namespace ns2 = Namespace.get("p2", "www.acme2.org");
    Element element = new DefaultElement("test", ns1);
    Attribute attribute = new DefaultAttribute("pre:foo", "bar", ns2);
    element.add(attribute); 
    Document doc = new DefaultDocument(element);

    XPath xpath = new Dom4jXPath( "//namespace::node()" );
    List results = xpath.selectNodes( doc );
    assertEquals( 3, results.size() );

}
项目:olat    文件:CPManagerImpl.java   
/**
*/
  @Override
  public ContentPackage load(final VFSContainer directory, final OLATResourceable ores) {
      final XMLParser parser = new XMLParser();
      ContentPackage cp;

      final VFSLeaf file = (VFSLeaf) directory.resolve("imsmanifest.xml");

      if (file != null) {
          try {
              final DefaultDocument doc = (DefaultDocument) parser.parse(file.getInputStream(), false);
              cp = new ContentPackage(doc, directory, ores);
              // If a wiki is imported or a new cp created, set a unique orga
              // identifier.
              if (cp.getLastError() == null) {
                  if (cp.isOLATContentPackage() && CPCore.OLAT_ORGANIZATION_IDENTIFIER.equals(cp.getFirstOrganizationInManifest().getIdentifier())) {
                      setUniqueOrgaIdentifier(cp);
                  }
              }

          } catch (final OLATRuntimeException e) {
              cp = new ContentPackage(null, directory, ores);
              log.error("Reading imsmanifest failed. Dir: " + directory.getName() + ". Ores: " + ores.getResourceableId(), e);
              cp.setLastError("Exception reading XML for IMS CP: invalid xml-file ( " + directory.getName() + ")");
          }

      } else {
          cp = new ContentPackage(null, directory, ores);
          cp.setLastError("Exception reading XML for IMS CP: IMS-Manifest not found in " + directory.getName());
          log.error("IMS manifiest xml couldn't be found in dir " + directory.getName() + ". Ores: " + ores.getResourceableId(), null);
          throw new OLATRuntimeException(this.getClass(), "The imsmanifest.xml file was not found.", new IOException());
      }
      return cp;
  }
项目:olat    文件:CPCore.java   
/**
 * Returns the DefaultDocument of this CP
 * 
 * @return the xml Document of this CP
 */
public DefaultDocument buildDocument() {
    // if (doc != null) return doc;
    final DefaultDocument newDoc = new DefaultDocument();
    rootNode.buildDocument(newDoc);
    return newDoc;
}
项目:olat    文件:CPManagerImpl.java   
/**
*/
  @Override
  public ContentPackage load(final VFSContainer directory, final OLATResourceable ores) {
      final XMLParser parser = new XMLParser();
      ContentPackage cp;

      final VFSLeaf file = (VFSLeaf) directory.resolve("imsmanifest.xml");

      if (file != null) {
          try {
              final DefaultDocument doc = (DefaultDocument) parser.parse(file.getInputStream(), false);
              cp = new ContentPackage(doc, directory, ores);
              // If a wiki is imported or a new cp created, set a unique orga
              // identifier.
              if (cp.getLastError() == null) {
                  if (cp.isOLATContentPackage() && CPCore.OLAT_ORGANIZATION_IDENTIFIER.equals(cp.getFirstOrganizationInManifest().getIdentifier())) {
                      setUniqueOrgaIdentifier(cp);
                  }
              }

          } catch (final OLATRuntimeException e) {
              cp = new ContentPackage(null, directory, ores);
              log.error("Reading imsmanifest failed. Dir: " + directory.getName() + ". Ores: " + ores.getResourceableId(), e);
              cp.setLastError("Exception reading XML for IMS CP: invalid xml-file ( " + directory.getName() + ")");
          }

      } else {
          cp = new ContentPackage(null, directory, ores);
          cp.setLastError("Exception reading XML for IMS CP: IMS-Manifest not found in " + directory.getName());
          log.error("IMS manifiest xml couldn't be found in dir " + directory.getName() + ". Ores: " + ores.getResourceableId(), null);
          throw new OLATRuntimeException(this.getClass(), "The imsmanifest.xml file was not found.", new IOException());
      }
      return cp;
  }
项目:olat    文件:CPCore.java   
/**
 * Returns the DefaultDocument of this CP
 * 
 * @return the xml Document of this CP
 */
public DefaultDocument buildDocument() {
    // if (doc != null) return doc;
    final DefaultDocument newDoc = new DefaultDocument();
    rootNode.buildDocument(newDoc);
    return newDoc;
}
项目:community-edition-old    文件:TestAbstractListItemsEndpointTest.java   
@Test
public void correctErrorCodeReturnedWhenSiteNotFound() throws Exception
{
    VtiSoapRequest soapRequest = Mockito.mock(VtiSoapRequest.class);
    VtiSoapResponse soapResponse = new VtiSoapResponse(new MockHttpServletResponse());//Mockito.mock(VtiSoapResponse.class);
    Element requestElement = Mockito.mock(Element.class);
    SimpleNamespaceContext nc = Mockito.mock(SimpleNamespaceContext.class);

    when(nc.translateNamespacePrefixToUri(anyString())).thenReturn("some://uri");

    Element rootElement = new DefaultElement("root");
    when(soapRequest.getDocument()).thenReturn(new DefaultDocument(rootElement));

    // ALF-19833: listName was being passed to getList for both arguments.
    when(listHandler.getList("documentLibrary", "my-site")).thenThrow(new SiteDoesNotExistException(""));

    // Invoke the method under test.
    try
    {
        listItemsEndpoint.executeListActionDetails(soapRequest, soapResponse,
                    "my-site", "documentLibrary", requestElement, nc);

        fail("Expected exception was not thrown.");
    }
    catch(VtiSoapException e)
    {
        assertEquals(VtiError.V_LIST_NOT_FOUND.getErrorCode(), e.getErrorCode());
    }
}
项目:netarchivesuite-svngit-migration    文件:JobDispatcherTester.java   
private Job createJob(long jobID) {
    Job job = mock(Job.class);
    when(job.getJobID()).thenReturn(jobID);
    when(job.getOrigHarvestDefinitionID()).thenReturn(9L);
    when(job.getOrderXMLdoc()).thenReturn(new DefaultDocument());
    return job;
}
项目:iaf    文件:XmlUtils.java   
public static String getAdapterSite(Object document)
        throws DomBuilderException, IOException, TransformerException {
    String input;
    if (document instanceof DefaultDocument) {
        DefaultDocument defaultDocument = (DefaultDocument) document;
        input = defaultDocument.asXML();
    } else {
        input = document.toString();
    }
    return getAdapterSite(input, null);
}
项目:olat    文件:CPManagerImpl.java   
/**
*/
  @Override
  public DefaultDocument getDocument(final ContentPackage cp) {
      return cp.getDocument();
  }
项目:olat    文件:ContentPackage.java   
ContentPackage(final DefaultDocument doc, final VFSContainer parent, final OLATResourceable ores) {
    this.cpcore = new CPCore(doc, parent);
    this.ores = ores;
}
项目:olat    文件:ContentPackage.java   
protected DefaultDocument getDocument() {
    return cpcore.buildDocument();
}
项目:olat    文件:CPCore.java   
public CPCore(final DefaultDocument doc, final VFSContainer rootDir) {
    this.doc = doc;
    this.rootDir = rootDir;
    errors = new Vector<String>();
    buildTree();
}
项目:olat    文件:CPManagerImpl.java   
/**
*/
  @Override
  public DefaultDocument getDocument(final ContentPackage cp) {
      return cp.getDocument();
  }
项目:olat    文件:ContentPackage.java   
ContentPackage(final DefaultDocument doc, final VFSContainer parent, final OLATResourceable ores) {
    this.cpcore = new CPCore(doc, parent);
    this.ores = ores;
}
项目:olat    文件:ContentPackage.java   
protected DefaultDocument getDocument() {
    return cpcore.buildDocument();
}
项目:olat    文件:CPCore.java   
public CPCore(final DefaultDocument doc, final VFSContainer rootDir) {
    this.doc = doc;
    this.rootDir = rootDir;
    errors = new Vector<String>();
    buildTree();
}
项目:olat    文件:CPManager.java   
/**
 * Returns the DefaultDocument of the ContentPackage cp
 * 
 * @return the xml Document of the cp
 */
public abstract DefaultDocument getDocument(ContentPackage cp);
项目:olat    文件:CPManager.java   
/**
 * Returns the DefaultDocument of the ContentPackage cp
 * 
 * @return the xml Document of the cp
 */
public abstract DefaultDocument getDocument(ContentPackage cp);