1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.security.authorization.testwikis.internal.parser

File TestWikiFactory.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

4
13
4
1
86
48
7
0.54
3.25
4
1.75

Classes

Class Line # Actions
TestWikiFactory 43 13 0% 7 2
0.904761990.5%
 

Contributing tests

This file is covered by 15 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20   
21    package org.xwiki.security.authorization.testwikis.internal.parser;
22   
23    import java.util.Arrays;
24    import java.util.List;
25   
26    import org.xml.sax.Attributes;
27    import org.xml.sax.SAXException;
28    import org.xwiki.model.EntityType;
29    import org.xwiki.model.reference.EntityReference;
30    import org.xwiki.model.reference.WikiReference;
31    import org.xwiki.security.authorization.testwikis.TestEntity;
32    import org.xwiki.security.authorization.testwikis.TestWiki;
33    import org.xwiki.security.authorization.testwikis.internal.entities.DefaultTestDocument;
34    import org.xwiki.security.authorization.testwikis.internal.entities.DefaultTestWiki;
35    import org.xwiki.security.authorization.testwikis.internal.entities.DefaultTestDefinition;
36   
37    /**
38    * Test wiki factory.
39    *
40    * @version $Id: 54422501e6b1345f895c92024743f6a55b6fd4ed $
41    * @since 5.0M2
42    */
 
43    public class TestWikiFactory extends AbstractSecureEntityFactory<TestWiki>
44    {
45    /**
46    * Create a new factory for wikis of the given parent (usually a root entity).
47    * @param parent parent entity to used by this factory.
48    */
 
49  15 toggle TestWikiFactory(TestEntity parent)
50    {
51  15 setParent(parent);
52    }
53   
 
54  15 toggle @Override
55    public List<String> getTagNames()
56    {
57  15 return Arrays.asList("wiki");
58    }
59   
 
60  55 toggle @Override
61    TestWiki getNewInstance(ElementParser parser, String name, TestEntity parent, Attributes attributes)
62    throws SAXException
63    {
64  55 EntityReference reference = new WikiReference(attributes.getValue("name"));
65  55 boolean isMainWiki = "true".equals(attributes.getValue("mainWiki"));
66  55 String ownerString = attributes.getValue("owner");
67  55 EntityReference owner = (ownerString) != null ? parser.getResolver().resolve(ownerString,
68    DefaultTestDocument.TYPE, new EntityReference(XWikiConstants.XWIKI_SPACE, EntityType.SPACE, reference))
69    : null;
70   
71  55 if (isMainWiki && ((DefaultTestDefinition) parent).getMainWiki() != null) {
72  0 throw new SAXException(parser.getLocatedMessage("Only one main wiki may be defined."));
73    }
74   
75  55 return new DefaultTestWiki(reference, isMainWiki, owner, attributes.getValue("alt"), parent);
76    }
77   
 
78  55 toggle @Override
79    protected void registerFactories(ElementParser parser, TestWiki entity)
80    {
81  55 super.registerFactories(parser, entity);
82  55 parser.register(new TestSpaceFactory(entity));
83  55 parser.register(new TestUserFactory(entity));
84  55 parser.register(new TestGroupFactory(entity));
85    }
86    }