Search in sources :

Example 76 with Attribute

use of javax.xml.stream.events.Attribute in project S-argo by Expugn.

the class SettingsParser method tryRead.

private void tryRead(String configFile) throws FailedToReadSettingFileException {
    InputStream in;
    XMLEventReader eventReader;
    /* CREATE XMLInputFactory AND XMLEventReader */
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    try {
        in = new FileInputStream(configFile);
    } catch (FileNotFoundException e) {
        throw new FailedToReadSettingFileException();
    }
    try {
        eventReader = inputFactory.createXMLEventReader(in);
    } catch (XMLStreamException e) {
        try {
            in.close();
        } catch (IOException ex) {
        /* IGNORED */
        }
        throw new FailedToReadSettingFileException();
    }
    ignoredChannelNames = new ArrayList<>();
    recordCrystalRates = new ArrayList<>();
    circulatingRecordCrystalRates = new ArrayList<>();
    // goldBanners = new ArrayList<>();
    // goldBannersv2 = new ArrayList<>();
    shopItems = new TreeMap<>();
    /* READ XML FILE */
    while (eventReader.hasNext()) {
        XMLEvent event;
        try {
            event = eventReader.nextEvent();
        } catch (XMLStreamException e) {
            try {
                in.close();
            } catch (IOException ex) {
            /* IGNORED */
            }
            try {
                eventReader.close();
            } catch (XMLStreamException ex) {
            /* IGNORED */
            }
            throw new FailedToReadSettingFileException();
        }
        if (event.isStartElement()) {
            /* BOT SETTINGS */
            if (event.asStartElement().getName().getLocalPart().equals("Token")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                botToken = event.asCharacters().getData();
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals("NoGUI")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                isNoGUI = Boolean.parseBoolean(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals("GitHubDataRepository")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                gitHubRepoURL = event.asCharacters().getData();
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals("BotOwnerID")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                botOwnerDiscordID = event.asCharacters().getData();
                continue;
            }
            /* COMMAND SETTINGS */
            if (event.asStartElement().getName().getLocalPart().equals("UseMention")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                useMention = Boolean.parseBoolean(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals("CommandPrefix")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                commandPrefix = event.asCharacters().getData().charAt(0);
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals("DeleteUserMessage")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                deleteUserMessage = Boolean.parseBoolean(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals("iChannel")) {
                Iterator<Attribute> attributes = event.asStartElement().getAttributes();
                while (attributes.hasNext()) {
                    Attribute attribute = attributes.next();
                    if (attribute.getName().toString().equals("channelName")) {
                        ignoredChannelNames.add(attribute.getValue());
                    }
                }
                continue;
            }
            /* SCOUT SETTINGS */
            if (event.asStartElement().getName().getLocalPart().equals("DisableImages")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                isDisableImages = Boolean.parseBoolean(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals("SimpleMessage")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                isSimpleMessage = Boolean.parseBoolean(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals("RarityStars")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                isRarityStars = Boolean.parseBoolean(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals("ScoutMaster")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                try {
                    scoutMaster = event.asCharacters().getData();
                } catch (ClassCastException e) {
                    scoutMaster = "";
                }
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals("copper")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                copperRates = Double.parseDouble(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals("silver")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                silverRates = Double.parseDouble(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals("gold")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                goldRates = Double.parseDouble(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals("platinum")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                platinumRates = Double.parseDouble(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals("RecordCrystal")) {
                double rate = 0.0;
                Iterator<Attribute> attributes = event.asStartElement().getAttributes();
                while (attributes.hasNext()) {
                    Attribute attribute = attributes.next();
                    if (attribute.getName().toString().equals("rate")) {
                        rate = Double.parseDouble(attribute.getValue());
                    }
                }
                recordCrystalRates.add(rate);
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals("CirculatingRecordCrystal")) {
                double rate = 0.0;
                Iterator<Attribute> attributes = event.asStartElement().getAttributes();
                while (attributes.hasNext()) {
                    Attribute attribute = attributes.next();
                    if (attribute.getName().toString().equals("rate")) {
                        rate = Double.parseDouble(attribute.getValue());
                    }
                }
                circulatingRecordCrystalRates.add(rate);
                continue;
            }
            /* SHOP SETTINGS */
            if (event.asStartElement().getName().getLocalPart().equals("MaxShopLimit")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                maxShopLimit = Integer.parseInt(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals("shopItem")) {
                HashMap<Double, Integer> priceAndAmount = new HashMap<>();
                String itemName = "";
                Double price = 0.0;
                int amount = 0;
                Iterator<Attribute> attributes = event.asStartElement().getAttributes();
                while (attributes.hasNext()) {
                    Attribute attribute = attributes.next();
                    if (attribute.getName().toString().equals("itemName")) {
                        itemName = attribute.getValue();
                    }
                    if (attribute.getName().toString().equals("price")) {
                        price = Double.parseDouble(attribute.getValue());
                    }
                    if (attribute.getName().toString().equals("amount")) {
                        amount = Integer.parseInt(attribute.getValue());
                    }
                }
                priceAndAmount.put(price, amount);
                shopItems.put(itemName, priceAndAmount);
            }
        }
    }
}
Also used : Attribute(javax.xml.stream.events.Attribute) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) XMLStreamException(javax.xml.stream.XMLStreamException) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader) XMLInputFactory(javax.xml.stream.XMLInputFactory) FailedToReadSettingFileException(io.github.spugn.Sargo.Exceptions.FailedToReadSettingFileException)

Example 77 with Attribute

use of javax.xml.stream.events.Attribute in project S-argo by Expugn.

the class ScoutSettingsParser method read.

private void read() throws FailedToReadSettingFileException {
    InputStream in;
    XMLEventReader eventReader;
    /* CREATE XMLInputFactory AND XMLEventReader */
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    try {
        in = new FileInputStream(FILE_PATH);
    } catch (FileNotFoundException e) {
        throw new FailedToReadSettingFileException();
    }
    try {
        eventReader = inputFactory.createXMLEventReader(in);
    } catch (XMLStreamException e) {
        try {
            in.close();
        } catch (IOException ex) {
        /* IGNORED */
        }
        throw new FailedToReadSettingFileException();
    }
    recordCrystalRates = new ArrayList<>();
    circulatingRecordCrystalRates = new ArrayList<>();
    /* READ XML FILE */
    while (eventReader.hasNext()) {
        XMLEvent event;
        try {
            event = eventReader.nextEvent();
        } catch (XMLStreamException e) {
            try {
                in.close();
            } catch (IOException ex) {
            /* IGNORED */
            }
            try {
                eventReader.close();
            } catch (XMLStreamException ex) {
            /* IGNORED */
            }
            throw new FailedToReadSettingFileException();
        }
        if (event.isStartElement()) {
            if (event.asStartElement().getName().getLocalPart().equals(DISABLE_IMAGES)) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                isDisableImages = Boolean.parseBoolean(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals(SIMPLE_MESSAGE)) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                isSimpleMessage = Boolean.parseBoolean(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals(RARITY_STARS)) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                isRarityStars = Boolean.parseBoolean(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals(SCOUT_MASTER)) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                try {
                    scoutMaster = event.asCharacters().getData();
                } catch (ClassCastException e) {
                    scoutMaster = "";
                }
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals(COPPER)) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                copperRate = Double.parseDouble(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals(SILVER)) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                silverRate = Double.parseDouble(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals(GOLD)) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                goldRate = Double.parseDouble(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals(PLATINUM)) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                platinumRate = Double.parseDouble(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals(PLATINUM6)) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadSettingFileException();
                }
                platinum6Rate = Double.parseDouble(event.asCharacters().getData());
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals(RECORD_CRYSTAL)) {
                double rate = 0.0;
                Iterator<Attribute> attributes = event.asStartElement().getAttributes();
                while (attributes.hasNext()) {
                    Attribute attribute = attributes.next();
                    if (attribute.getName().toString().equals("rate")) {
                        rate = Double.parseDouble(attribute.getValue());
                    }
                }
                recordCrystalRates.add(rate);
                continue;
            }
            if (event.asStartElement().getName().getLocalPart().equals(CIRCULATING_RECORD_CRYSTAL)) {
                double rate = 0.0;
                Iterator<Attribute> attributes = event.asStartElement().getAttributes();
                while (attributes.hasNext()) {
                    Attribute attribute = attributes.next();
                    if (attribute.getName().toString().equals("rate")) {
                        rate = Double.parseDouble(attribute.getValue());
                    }
                }
                circulatingRecordCrystalRates.add(rate);
            }
        }
    }
}
Also used : Attribute(javax.xml.stream.events.Attribute) XMLEvent(javax.xml.stream.events.XMLEvent) FailedToReadSettingFileException(io.github.spugn.Sargo.Exceptions.FailedToReadSettingFileException)

Example 78 with Attribute

use of javax.xml.stream.events.Attribute in project hibernate-orm by hibernate.

the class JpaNamespaceTransformingEventReader method transform.

private StartElement transform(StartElement startElement) {
    String elementName = startElement.getName().getLocalPart();
    // use the start element to determine whether we have a persistence.xml or orm.xml
    if (START_ELEMENT_TO_NAMESPACE_URI.containsKey(elementName)) {
        currentDocumentNamespaceUri = START_ELEMENT_TO_NAMESPACE_URI.get(elementName);
    }
    List<Attribute> newElementAttributeList = updateElementAttributes(startElement);
    List<Namespace> newNamespaceList = updateElementNamespaces(startElement);
    // create the new element
    return xmlEventFactory.createStartElement(new QName(currentDocumentNamespaceUri, startElement.getName().getLocalPart()), newElementAttributeList.iterator(), newNamespaceList.iterator());
}
Also used : Attribute(javax.xml.stream.events.Attribute) QName(javax.xml.namespace.QName) Namespace(javax.xml.stream.events.Namespace)

Example 79 with Attribute

use of javax.xml.stream.events.Attribute in project bazel by bazelbuild.

the class DataResourceXml method parse.

/**
   * Parses xml resources from a Path to the provided overwritable and combining collections.
   *
   * <p>This method is a bit tricky in the service of performance -- creating several collections
   * and merging them was more expensive than writing to mutable collections directly.
   *
   * @param xmlInputFactory Used to create an XMLEventReader from the supplied resource path.
   * @param path The path to the xml resource to be parsed.
   * @param fqnFactory Used to create {@link FullyQualifiedName}s from the resource names.
   * @param overwritingConsumer A consumer for overwritable {@link DataResourceXml}s.
   * @param combiningConsumer A consumer for combining {@link DataResourceXml}s.
   * @throws XMLStreamException Thrown with the resource format is invalid.
   * @throws FactoryConfigurationError Thrown with the {@link XMLInputFactory} is misconfigured.
   * @throws IOException Thrown when there is an error reading a file.
   */
public static void parse(XMLInputFactory xmlInputFactory, Path path, Factory fqnFactory, KeyValueConsumer<DataKey, DataResource> overwritingConsumer, KeyValueConsumer<DataKey, DataResource> combiningConsumer) throws XMLStreamException, FactoryConfigurationError, IOException {
    XMLEventReader eventReader = xmlInputFactory.createXMLEventReader(new BufferedInputStream(Files.newInputStream(path)), StandardCharsets.UTF_8.toString());
    try {
        // TODO(corysmith): Make the xml parsing more readable.
        for (StartElement resources = XmlResourceValues.moveToResources(eventReader); resources != null; resources = XmlResourceValues.moveToResources(eventReader)) {
            // Record attributes on the <resources> tag.
            Iterator<Attribute> attributes = XmlResourceValues.iterateAttributesFrom(resources);
            while (attributes.hasNext()) {
                Attribute attribute = attributes.next();
                Namespaces namespaces = Namespaces.from(attribute.getName());
                String attributeName = attribute.getName().getNamespaceURI().isEmpty() ? attribute.getName().getLocalPart() : attribute.getName().getPrefix() + ":" + attribute.getName().getLocalPart();
                overwritingConsumer.consume(fqnFactory.create(VirtualType.RESOURCES_ATTRIBUTE, attributeName), DataResourceXml.createWithNamespaces(path, ResourcesAttribute.of(attributeName, attribute.getValue()), namespaces));
            }
            // Process resource declarations.
            for (StartElement start = XmlResourceValues.findNextStart(eventReader); start != null; start = XmlResourceValues.findNextStart(eventReader)) {
                Namespaces.Collector namespacesCollector = Namespaces.collector();
                if (XmlResourceValues.isEatComment(start) || XmlResourceValues.isSkip(start)) {
                    continue;
                }
                ResourceType resourceType = getResourceType(start);
                if (resourceType == null) {
                    throw new XMLStreamException(path + " contains an unrecognized resource type: " + start, start.getLocation());
                }
                if (resourceType == DECLARE_STYLEABLE) {
                    // Styleables are special, as they produce multiple overwrite and combining values,
                    // so we let the value handle the assignments.
                    XmlResourceValues.parseDeclareStyleable(fqnFactory, path, overwritingConsumer, combiningConsumer, eventReader, start);
                } else {
                    // Of simple resources, only IDs and Public are combining.
                    KeyValueConsumer<DataKey, DataResource> consumer = (resourceType == ID || resourceType == PUBLIC) ? combiningConsumer : overwritingConsumer;
                    String elementName = XmlResourceValues.getElementName(start);
                    if (elementName == null) {
                        throw new XMLStreamException(String.format("resource name is required for %s", resourceType), start.getLocation());
                    }
                    FullyQualifiedName key = fqnFactory.create(resourceType, elementName);
                    XmlResourceValue xmlResourceValue = parseXmlElements(resourceType, eventReader, start, namespacesCollector);
                    consumer.consume(key, DataResourceXml.createWithNamespaces(path, xmlResourceValue, namespacesCollector.toNamespaces()));
                }
            }
        }
    } catch (XMLStreamException e) {
        throw new XMLStreamException(path + ": " + e.getMessage(), e.getLocation(), e);
    } catch (RuntimeException e) {
        throw new RuntimeException("Error parsing " + path, e);
    }
}
Also used : Namespaces(com.google.devtools.build.android.xml.Namespaces) Attribute(javax.xml.stream.events.Attribute) ResourcesAttribute(com.google.devtools.build.android.xml.ResourcesAttribute) ResourceType(com.android.resources.ResourceType) StartElement(javax.xml.stream.events.StartElement) StyleableXmlResourceValue(com.google.devtools.build.android.xml.StyleableXmlResourceValue) PublicXmlResourceValue(com.google.devtools.build.android.xml.PublicXmlResourceValue) SimpleXmlResourceValue(com.google.devtools.build.android.xml.SimpleXmlResourceValue) StyleXmlResourceValue(com.google.devtools.build.android.xml.StyleXmlResourceValue) ArrayXmlResourceValue(com.google.devtools.build.android.xml.ArrayXmlResourceValue) IdXmlResourceValue(com.google.devtools.build.android.xml.IdXmlResourceValue) AttrXmlResourceValue(com.google.devtools.build.android.xml.AttrXmlResourceValue) PluralXmlResourceValue(com.google.devtools.build.android.xml.PluralXmlResourceValue) XMLStreamException(javax.xml.stream.XMLStreamException) BufferedInputStream(java.io.BufferedInputStream) XMLEventReader(javax.xml.stream.XMLEventReader)

Example 80 with Attribute

use of javax.xml.stream.events.Attribute in project uPortal by Jasig.

the class LayoutPortalDataType method postProcessSinglePortalDataKey.

@SuppressWarnings("deprecation")
@Override
protected PortalDataKey postProcessSinglePortalDataKey(String systemId, PortalDataKey portalDataKey, XMLEventReader reader) {
    /* Fragment layouts are differentiated _only_ by file extension;  these
         * layouts must be imported BEFORE non-fragment layouts (i.e. layouts of
         * regular users)
         */
    if (systemId.endsWith(".fragment-layout.xml") || systemId.endsWith(".fragment-layout")) /* legacy file extension */
    {
        /* NOTE: In the future we could consider handling this case
             * similarly to how "default" users are handled (below):  by reading
             * the username attribute and checking it against the list of known
             * fragment layout owners.
             */
        return convertToFragmentKey(portalDataKey);
    }
    // in 2.6 and 3.0 format layout files)
    if (IMPORT_26_DATA_KEY.equals(portalDataKey) || IMPORT_30_DATA_KEY.equals(portalDataKey)) {
        final StartElement startElement = StaxUtils.getRootElement(reader);
        final Attribute usernameAttr = startElement.getAttributeByName(new QName("username"));
        if (usernameAttr != null) {
            final String username = usernameAttr.getValue();
            if (this.userIdentityStore.isDefaultUser(username)) {
                return convertToDefaultUserKey(portalDataKey);
            }
        } else {
            logger.warn("No username attribute on StartElement for {}", systemId);
        }
    }
    return portalDataKey;
}
Also used : StartElement(javax.xml.stream.events.StartElement) Attribute(javax.xml.stream.events.Attribute) QName(javax.xml.namespace.QName)

Aggregations

Attribute (javax.xml.stream.events.Attribute)144 QName (javax.xml.namespace.QName)73 StartElement (javax.xml.stream.events.StartElement)63 XMLEvent (javax.xml.stream.events.XMLEvent)54 XMLEventReader (javax.xml.stream.XMLEventReader)30 EndElement (javax.xml.stream.events.EndElement)26 Namespace (javax.xml.stream.events.Namespace)26 ArrayList (java.util.ArrayList)23 XMLStreamException (javax.xml.stream.XMLStreamException)20 XMLInputFactory (javax.xml.stream.XMLInputFactory)18 InputStream (java.io.InputStream)14 IOException (java.io.IOException)12 Iterator (java.util.Iterator)11 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileInputStream (java.io.FileInputStream)7 HashMap (java.util.HashMap)7 Test (org.junit.Test)7 HashSet (java.util.HashSet)6 Characters (javax.xml.stream.events.Characters)6 QNm (org.brackit.xquery.atomic.QNm)5