Search in sources :

Example 1 with Attribute

use of com.mindbright.security.x509.Attribute in project wpcleaner by WPCleaner.

the class ApiXmlPropertiesResult method updatePageInformation.

/**
 * Update page information.
 *
 * @param node Element for the page.
 * @param page Page.
 * @throws JDOMException Exception from due to the DOM.
 */
public void updatePageInformation(Element node, Page page) throws JDOMException {
    // Retrieve basic page information
    Attribute attrPageId = node.getAttribute("pageid");
    if (attrPageId != null) {
        page.setPageId(attrPageId.getValue());
    }
    Attribute attrTitle = node.getAttribute("title");
    if (attrTitle != null) {
        page.setTitle(attrTitle.getValue());
    }
    Optional.ofNullable(node.getAttributeValue("starttimestamp")).ifPresent(timestamp -> page.setStartTimestamp(timestamp));
    Attribute attrRedirect = node.getAttribute("redirect");
    if (attrRedirect != null) {
        page.getRedirects().isRedirect(true);
    }
    Attribute attrMissing = node.getAttribute("missing");
    if (attrMissing != null) {
        page.setExisting(Boolean.FALSE);
    }
    // Retrieve protection information
    XPathExpression<Element> xpaProtection = XPathFactory.instance().compile("protection/pr[@type=\"edit\"]", Filters.element());
    List<Element> protectionNodes = xpaProtection.evaluate(node);
    for (Element protectionNode : protectionNodes) {
        if ("edit".equals(protectionNode.getAttributeValue("type"))) {
            page.setEditProtectionLevel(protectionNode.getAttributeValue("level"));
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 2 with Attribute

use of com.mindbright.security.x509.Attribute in project wpcleaner by WPCleaner.

the class ApiJsonResult method getPage.

/**
 * Get a page corresponding to a page node.
 *
 * @param wiki Wiki.
 * @param pageNode Page node.
 * @param knownPages Already known pages.
 * @param useDisambig True if disambiguation property should be used.
 * @return Page.
 */
protected static Page getPage(EnumWikipedia wiki, Element pageNode, List<Page> knownPages, boolean useDisambig) {
    if (pageNode == null) {
        return null;
    }
    String title = pageNode.getAttributeValue("title");
    Attribute pageIdAttr = pageNode.getAttribute("pageid");
    Integer pageId = null;
    if (pageIdAttr != null) {
        try {
            String tmp = pageIdAttr.getValue();
            pageId = Integer.valueOf(tmp);
        } catch (NumberFormatException e) {
        // 
        }
    }
    String revisionId = pageNode.getAttributeValue("lastrevid");
    Page page = DataManager.getPage(wiki, title, pageId, revisionId, knownPages);
    page.setNamespace(pageNode.getAttributeValue("ns"));
    if (pageNode.getAttribute("missing") != null) {
        page.setExisting(Boolean.FALSE);
    } else if (pageId != null) {
        page.setExisting(Boolean.TRUE);
    }
    if (pageNode.getAttribute("redirect") != null) {
        page.getRedirects().isRedirect(true);
    }
    if (useDisambig) {
        Element pageProps = pageNode.getChild("pageprops");
        boolean dabPage = (pageProps != null) && (pageProps.getAttribute("disambiguation") != null);
        page.setDisambiguationPage(Boolean.valueOf(dabPage));
    }
    return page;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Page(org.wikipediacleaner.api.data.Page)

Example 3 with Attribute

use of com.mindbright.security.x509.Attribute in project wpcleaner by WPCleaner.

the class ApiXmlResult method shouldContinue.

/**
 * Manage query-continue in request.
 *
 * @param root Root of the DOM tree.
 * @param queryContinue XPath query to the query-continue node.
 * @param properties Properties defining request.
 * @return True if request should be continued.
 */
protected boolean shouldContinue(Element root, String queryContinue, Map<String, String> properties) {
    if ((root == null) || (queryContinue == null)) {
        return false;
    }
    boolean result = false;
    XPathExpression<Element> xpa = XPathFactory.instance().compile(queryContinue, Filters.element());
    List<Element> results = xpa.evaluate(root);
    if ((results == null) || (results.isEmpty())) {
        xpa = XPathFactory.instance().compile("/api/continue", Filters.element());
        results = xpa.evaluate(root);
    }
    if (results != null) {
        for (Object currentNode : results) {
            List attributes = ((Element) currentNode).getAttributes();
            if (attributes != null) {
                for (Object currentAttribute : attributes) {
                    Attribute attribute = (Attribute) currentAttribute;
                    properties.put(attribute.getName(), attribute.getValue());
                    result = true;
                }
            }
        }
    }
    return result;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) List(java.util.List)

Example 4 with Attribute

use of com.mindbright.security.x509.Attribute in project AndroidSampleLibrary by JackChen365.

the class AndroidManifest method parserAndroidManifest.

@Nonnull
private ManifestInformation parserAndroidManifest(File manifestFile) throws JDOMException, IOException {
    ManifestInformation manifestInformation = new ManifestInformation();
    if (!manifestFile.exists()) {
        System.out.println("File:" + manifestFile.getPath() + " not exists!");
    } else {
        SAXBuilder saxBuilder = new SAXBuilder();
        Document document = saxBuilder.build(manifestFile);
        XPathFactory xPathFactory = XPathFactory.instance();
        Namespace androidNameSpace = Namespace.getNamespace("android", "http://schemas.android.com/apk/res/android");
        XPathExpression<Attribute> applicationExpression = xPathFactory.compile("//application/@android:name", Filters.attribute(), null, androidNameSpace);
        Attribute applicationAttribute = applicationExpression.evaluateFirst(document);
        if (null != applicationAttribute) {
            manifestInformation.application = applicationAttribute.getValue();
        }
        XPathExpression<Attribute> applicationIdExpression = xPathFactory.compile("/manifest/@package", Filters.attribute(), null, androidNameSpace);
        Attribute applicationIdAttribute = applicationIdExpression.evaluateFirst(document);
        if (null != applicationIdAttribute) {
            manifestInformation.applicationId = applicationIdAttribute.getValue();
        }
        XPathExpression<Attribute> expression = xPathFactory.compile("//activity/@android:name", Filters.attribute(), null, androidNameSpace);
        List<Attribute> attributeList = expression.evaluate(document);
        for (int i = 0; i < attributeList.size(); i++) {
            Attribute attribute = attributeList.get(i);
            manifestInformation.addActivity(attribute.getValue());
        }
    }
    return manifestInformation;
}
Also used : XPathFactory(org.jdom2.xpath.XPathFactory) SAXBuilder(org.jdom2.input.SAXBuilder) Attribute(org.jdom2.Attribute) Document(org.jdom2.Document) Namespace(org.jdom2.Namespace) Nonnull(javax.annotation.Nonnull)

Example 5 with Attribute

use of com.mindbright.security.x509.Attribute in project core by authzforce.

the class StandardJavaTypeToXacmlAttributeDatatypeConversionTest method test.

@Test
public void test() {
    if (rawValues == null || rawValues.isEmpty()) {
        try {
            attValFactories.newAttributeBag(rawValues);
            Assert.fail("Should have raised IllegalArgumentException because of invalid rawValues");
        } catch (final Exception e) {
            Assert.assertTrue("Unexpected error: " + e, expectedExceptionClass != null && expectedExceptionClass.isInstance(e));
        }
        return;
    }
    // rawValues has at least one value
    if (rawValues.size() == 1) {
        final Serializable rawVal = rawValues.iterator().next();
        if (rawVal == null) {
            /*
				 * Instantiate using expected datatype to check if null is spotted as invalid value
				 */
            try {
                attValFactories.newExpression(expectedAttributeDatatypeId, Collections.singletonList(null), null, null);
                Assert.assertNull("Parsing raw value into AttributeValue did not throw exception as expected", expectedExceptionClass);
            } catch (final Exception e) {
                Assert.assertTrue("Unexpected error: " + e, expectedExceptionClass != null && expectedExceptionClass.isInstance(e));
            }
        } else {
            try {
                final AttributeValueFactory<?> attValFactory = attValFactories.getCompatibleFactory(rawVal.getClass());
                final String actualDatatypeId = attValFactory.getDatatype().getId();
                Assert.assertEquals("Invalid datatype for created attribute value", actualDatatypeId, expectedAttributeDatatypeId);
                attValFactories.newAttributeValue(rawVal);
                Assert.assertNull("Parsing raw value into AttributeValue did not throw exception as expected", expectedExceptionClass);
            } catch (final Exception e) {
                Assert.assertTrue("Unexpected error: " + e, expectedExceptionClass != null && expectedExceptionClass.isInstance(e));
            }
        }
    }
    try {
        final AttributeBag<?> attBag = attValFactories.newAttributeBag(rawValues);
        Assert.assertEquals("Invalid datatype for created attribute values", attBag.getElementDatatype().getId(), expectedAttributeDatatypeId);
        /*
			 * Marshall to XACML and try to unmarshall to original Java value to make sure marshalling is OK
			 */
        final List<AttributeValueType> outXacmlAttVals = attBag.elements().stream().map(attVal -> new AttributeValueType(attVal.getContent(), attBag.getElementDatatype().getId(), attVal.getXmlAttributes())).collect(Collectors.toList());
        final Attribute outXacmlAtt = new Attribute(outXacmlAttVals, testId.toString(), null, false);
        final Marshaller marshaller = Xacml3JaxbHelper.createXacml3Marshaller();
        final StringWriter strWriter = new StringWriter();
        marshaller.marshal(outXacmlAtt, strWriter);
        final String outStr = strWriter.toString();
        final Unmarshaller unmarshaller = Xacml3JaxbHelper.createXacml3Unmarshaller();
        final Attribute inXacmlAtt = (Attribute) unmarshaller.unmarshal(new StringReader(outStr));
        final List<AttributeValueType> inXacmlAttVals = inXacmlAtt.getAttributeValues();
        if (inXacmlAttVals.isEmpty()) {
            Assert.fail("Marshalling/unmarshalling failed: no AttributeValue after unmarshalling: " + outStr);
            return;
        }
        final AttributeValueType inXacmlAttVal0 = inXacmlAttVals.get(0);
        final AttributeValueFactory<?> attValFactory = this.attValFactories.getExtension(inXacmlAttVal0.getDataType());
        final List<AttributeValue> inAttVals = inXacmlAttVals.stream().map(inputXacmlAttValue -> attValFactory.getInstance(inputXacmlAttValue.getContent(), inputXacmlAttValue.getOtherAttributes(), null)).collect(Collectors.toList());
        Assert.assertEquals("AttributeValues after unmarshalling do not match original AttributeValues before marshalling: " + outStr, attBag.elements(), ImmutableMultiset.copyOf(inAttVals));
        Assert.assertNull("Parsing raw value into AttributeValue did not throw exception as expected", expectedExceptionClass);
    } catch (final Exception e) {
        Assert.assertTrue("Unexpected error: " + e, expectedExceptionClass != null && expectedExceptionClass.isInstance(e));
    }
}
Also used : Unmarshaller(javax.xml.bind.Unmarshaller) Attribute(oasis.names.tc.xacml._3_0.core.schema.wd_17.Attribute) java.util(java.util) Xacml3JaxbHelper(org.ow2.authzforce.xacml.Xacml3JaxbHelper) X500Principal(javax.security.auth.x500.X500Principal) AttributeValueType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType) org.ow2.authzforce.core.pdp.api.value(org.ow2.authzforce.core.pdp.api.value) Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) java.time(java.time) StringReader(java.io.StringReader) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImmutableMultiset(com.google.common.collect.ImmutableMultiset) BigInteger(java.math.BigInteger) URI(java.net.URI) Assert(org.junit.Assert) DatatypeConverter(javax.xml.bind.DatatypeConverter) Parameterized(org.junit.runners.Parameterized) Serializable(java.io.Serializable) Marshaller(javax.xml.bind.Marshaller) AttributeValueType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType) Attribute(oasis.names.tc.xacml._3_0.core.schema.wd_17.Attribute) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Aggregations

Attribute (org.jdom2.Attribute)316 Element (org.jdom2.Element)210 Attribute (ucar.nc2.Attribute)65 IOException (java.io.IOException)55 ArrayList (java.util.ArrayList)51 Document (org.jdom2.Document)43 Variable (ucar.nc2.Variable)39 List (java.util.List)31 HashMap (java.util.HashMap)25 Namespace (org.jdom2.Namespace)24 File (java.io.File)21 Array (ucar.ma2.Array)21 DataConversionException (org.jdom2.DataConversionException)19 Test (org.junit.Test)19 Dimension (ucar.nc2.Dimension)19 Map (java.util.Map)17 JDOMException (org.jdom2.JDOMException)16 XmlDslUtils.addMigrationAttributeToElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement)15 Editor (jmri.jmrit.display.Editor)15 NamedIcon (jmri.jmrit.catalog.NamedIcon)13