Java Code Examples for org.xmlpull.v1.XmlPullParser#START_TAG

The following examples show how to use org.xmlpull.v1.XmlPullParser#START_TAG . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WISPAccessGatewayParam.java    From WiFiAfterConnect with Apache License 2.0 6 votes vote down vote up
private void parseRedirect (XmlPullParser parser) throws XmlPullParserException, IOException {
	parser.require(XmlPullParser.START_TAG, ns, "Redirect");
    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String name = parser.getName();
        if (name.equals("AccessProcedure")) {
        	accessProcedure = parseSimpleTag (parser, "AccessProcedure");
        } else if (name.equals("AccessLocation")) {
        	accessLocation = parseSimpleTag (parser, "AccessLocation");
        } else if (name.equals("LocationName")) {
        	locationName = parseSimpleTag (parser, "LocationName");
        } else if (name.equals("LoginURL")) {
        	loginURL = parseSimpleTag (parser, "LoginURL");
        } else if (name.equals("MessageType")) {
        	messageType = parseSimpleTag (parser, "MessageType");
        } else if (name.equals("ResponseCode")) {
        	responseCode = parseSimpleTag (parser, "ResponseCode");
        } else {
            skip(parser);
        }
    }
}
 
Example 2
Source File: PListParser.java    From Connect-SDK-Android-Core with Apache License 2.0 6 votes vote down vote up
private JSONArray readArray(XmlPullParser parser) throws IOException, XmlPullParserException,
        JSONException {
    JSONArray plist = new JSONArray();
    parser.require(XmlPullParser.START_TAG, ns, TAG_ARRAY);

    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String name = parser.getName();
        if (name.equals(TAG_DICT)) {
            plist.put(readDict(parser));
        }
    }
    return plist;
}
 
Example 3
Source File: XMLParser.java    From mConference-Framework with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static SponsorDetails readSponsorItem(XmlPullParser parser) throws XmlPullParserException, IOException {
    parser.require(XmlPullParser.START_TAG, null, ITEM_TAG);
    SponsorDetails sponsor = new SponsorDetails();

    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG)
            continue;

        String name = parser.getName();
        if (name.equals(NAME_TAG))
            sponsor.setName(readText(parser));

        else if (name.equals(IMAGE_TAG))
            sponsor.setLogoURL(readText(parser));
    }

    parser.require(XmlPullParser.END_TAG, null, ITEM_TAG);

    return sponsor;
}
 
Example 4
Source File: WeChatHelper.java    From WechatHook-Dusan with Apache License 2.0 6 votes vote down vote up
public static String getFromXml(String xmlmsg, String node) throws XmlPullParserException, IOException {
    String xl = xmlmsg.substring(xmlmsg.indexOf("<msg>"));
    //nativeurl
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XmlPullParser pz = factory.newPullParser();
    pz.setInput(new StringReader(xl));
    int eventType = pz.getEventType();
    String result = "";
    while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG) {
            if (pz.getName().equals(node)) {
                pz.nextToken();
                result = pz.getText();
                break;
            }
        }
        eventType = pz.next();
    }
    return result;
}
 
Example 5
Source File: ChangeLogDialog.java    From Contacts with MIT License 6 votes vote down vote up
private void parseReleaseTag(final StringBuilder changelogBuilder, final XmlPullParser resourceParser) throws XmlPullParserException, IOException {
    changelogBuilder.append("<h1>Release: ").append(resourceParser.getAttributeValue(null, "version")).append("</h1>");

    //Add date if available
    if (resourceParser.getAttributeValue(null, "date") != null) {
        changelogBuilder.append("<span class='date'>").append(parseDate(resourceParser.getAttributeValue(null, "date"))).append("</span>");
    }

    //Add summary if available
    if (resourceParser.getAttributeValue(null, "summary") != null) {
        changelogBuilder.append("<span class='summary'>").append(resourceParser.getAttributeValue(null, "summary")).append("</span>");
    }

    changelogBuilder.append("<ul>");

    //Parse child nodes
    int eventType = resourceParser.getEventType();
    while ((eventType != XmlPullParser.END_TAG) || (resourceParser.getName().equals("change"))) {
        if ((eventType == XmlPullParser.START_TAG) && (resourceParser.getName().equals("change"))) {
            eventType = resourceParser.next();
            changelogBuilder.append("<li>" + resourceParser.getText() + "</li>");
        }
        eventType = resourceParser.next();
    }
    changelogBuilder.append("</ul>");
}
 
Example 6
Source File: BluetoothXmlParser.java    From EFRConnect-android with Apache License 2.0 6 votes vote down vote up
private void skip(XmlPullParser parser) throws XmlPullParserException, IOException {
    if (parser.getEventType() != XmlPullParser.START_TAG) {
        throw new IllegalStateException();
    }
    int depth = 1;
    while (depth != 0) {
        switch (parser.next()) {
        case XmlPullParser.END_TAG:
            depth--;
            break;
        case XmlPullParser.START_TAG:
            depth++;
            break;
        }
    }
}
 
Example 7
Source File: KeyboardBuilder.java    From LokiBoard-Android-Keylogger with Apache License 2.0 6 votes vote down vote up
private void parseMerge(final XmlPullParser parser, final KeyboardRow row, final boolean skip)
        throws XmlPullParserException, IOException {
    if (DEBUG) startTag("<%s>", TAG_MERGE);
    while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
        final int event = parser.next();
        if (event == XmlPullParser.START_TAG) {
            final String tag = parser.getName();
            if (TAG_MERGE.equals(tag)) {
                if (row == null) {
                    parseKeyboardContent(parser, skip);
                } else {
                    parseRowContent(parser, row, skip);
                }
                return;
            }
            throw new XmlParseUtils.ParseException(
                    "Included keyboard layout must have <merge> root element", parser);
        }
    }
}
 
Example 8
Source File: PullSOAPActionProcessorImpl.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
protected Map<String, String> getMatchingNodes(XmlPullParser xpp, ActionArgument[] args) throws Exception {

        // This is a case-insensitive search!
        List<String> names = new ArrayList<String>();
        for (ActionArgument argument : args) {
            names.add(argument.getName().toUpperCase());
            for (String alias : Arrays.asList(argument.getAliases())) {
                names.add(alias.toUpperCase());
            }
        }

        Map<String, String> matches = new HashMap<String, String>();

        String enclosingTag = xpp.getName();

        int event;
        do {
            event = xpp.next();
            if(event == XmlPullParser.START_TAG && names.contains(xpp.getName().toUpperCase())) {
                matches.put(xpp.getName(), xpp.nextText());
            }

        }
        while (event != XmlPullParser.END_DOCUMENT && (event != XmlPullParser.END_TAG || !xpp.getName().equals(enclosingTag)));

        if (matches.size() < args.length) {
            throw new ActionException(
                ErrorCode.ARGUMENT_VALUE_INVALID,
                "Invalid number of input or output arguments in XML message, expected "
                    + args.length + " but found " + matches.size()
            );
        }
        return matches;
    }
 
Example 9
Source File: XmlBackup.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
public XmlBackupItem getNext() throws IOException, XmlPullParserException {
  while (parser.next() != XmlPullParser.END_DOCUMENT) {
    if (parser.getEventType() != XmlPullParser.START_TAG) {
      continue;
    }

    String name = parser.getName();

    if (!name.equalsIgnoreCase("sms")) {
      continue;
    }

    int attributeCount = parser.getAttributeCount();

    if (attributeCount <= 0) {
      continue;
    }

    XmlBackupItem item = new XmlBackupItem();

    for (int i=0;i<attributeCount;i++) {
      String attributeName = parser.getAttributeName(i);

      if      (attributeName.equals(PROTOCOL      )) item.protocol      = Integer.parseInt(parser.getAttributeValue(i));
      else if (attributeName.equals(ADDRESS       )) item.address       = parser.getAttributeValue(i);
      else if (attributeName.equals(DATE          )) item.date          = Long.parseLong(parser.getAttributeValue(i));
      else if (attributeName.equals(TYPE          )) item.type          = Integer.parseInt(parser.getAttributeValue(i));
      else if (attributeName.equals(SUBJECT       )) item.subject       = parser.getAttributeValue(i);
      else if (attributeName.equals(BODY          )) item.body          = parser.getAttributeValue(i);
      else if (attributeName.equals(SERVICE_CENTER)) item.serviceCenter = parser.getAttributeValue(i);
      else if (attributeName.equals(READ          )) item.read          = Integer.parseInt(parser.getAttributeValue(i));
      else if (attributeName.equals(STATUS        )) item.status        = Integer.parseInt(parser.getAttributeValue(i));
    }

    return item;
  }

  return null;
}
 
Example 10
Source File: SlicePermissionManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void writeBackup(XmlSerializer out) throws IOException, XmlPullParserException {
    synchronized (this) {
        out.startTag(null, TAG_LIST);
        out.attribute(null, ATT_VERSION, String.valueOf(DB_VERSION));

        // Don't do anything with changes from the backup, because there shouldn't be any.
        DirtyTracker tracker = obj -> { };
        if (mHandler.hasMessages(H.MSG_PERSIST)) {
            mHandler.removeMessages(H.MSG_PERSIST);
            handlePersist();
        }
        for (String file : new File(mSliceDir.getAbsolutePath()).list()) {
            try (ParserHolder parser = getParser(file)) {
                Persistable p = null;
                while (parser.parser.getEventType() != XmlPullParser.END_DOCUMENT) {
                    if (parser.parser.getEventType() == XmlPullParser.START_TAG) {
                        if (SliceClientPermissions.TAG_CLIENT.equals(parser.parser.getName())) {
                            p = SliceClientPermissions.createFrom(parser.parser, tracker);
                        } else {
                            p = SliceProviderPermissions.createFrom(parser.parser, tracker);
                        }
                        break;
                    }
                    parser.parser.next();
                }
                if (p != null) {
                    p.writeTo(out);
                } else {
                    Slog.w(TAG, "Invalid or empty slice permissions file: " + file);
                }
            }
        }

        out.endTag(null, TAG_LIST);
    }
}
 
Example 11
Source File: GroupDelete.java    From olat with Apache License 2.0 5 votes vote down vote up
@Override
public IQ parseIQ(final XmlPullParser parser) throws Exception {

    final GroupDelete groupDelete = new GroupDelete();
    boolean done = false;
    while (!done) {
        final int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            groupDelete.setDeleted(true);
            done = true;
        }
    }
    return groupDelete;
}
 
Example 12
Source File: ConversationHistoryPlugin.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Loads the previous history.
 */
private void loadPreviousHistory() {
    if (!conFile.exists()) {
        return;
    }

    // Otherwise load it.
    try {
        final MXParser parser = new MXParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(conFile), "UTF-8"));
        parser.setInput(in);
        boolean done = false;
        while (!done) {
            int eventType = parser.next();
            if (eventType == XmlPullParser.START_TAG && "user".equals(parser.getName())) {
                EntityBareJid jid = JidCreate.entityBareFromUnescapedOrThrowUnchecked(parser.nextText());
                historyList.add(jid);
            }
            else if (eventType == XmlPullParser.END_TAG && "conversations".equals(parser.getName())) {
                done = true;
            }
        }
        in.close();
    }
    catch (Exception e) {
        Log.error(e);
    }
}
 
Example 13
Source File: SessionItems.java    From olat with Apache License 2.0 5 votes vote down vote up
@Override
public IQ parseIQ(final XmlPullParser parser) throws Exception {
    String username = "";
    String presenceStatus = "";
    String presenceMsg = "";
    long lastActivity = 0;
    long loginTime = 0;
    String resource = "";

    final IMSessionItems items = new IMSessionItems();
    IMSessionItems.Item item;
    boolean done = false;
    while (!done) {
        final int eventType = parser.next();

        if (eventType == XmlPullParser.START_TAG && "item".equals(parser.getName())) {
            // Initialize the variables from the parsed XML
            username = parser.getAttributeValue("", "username");
            presenceStatus = parser.getAttributeValue("", "presenceStatus");
            presenceMsg = parser.getAttributeValue("", "presenceMsg");
            lastActivity = Long.valueOf(parser.getAttributeValue("", "lastActivity")).longValue();
            loginTime = Long.valueOf(parser.getAttributeValue("", "loginTime")).longValue();
            resource = parser.getAttributeValue("", "resource");
        } else if (eventType == XmlPullParser.END_TAG && "item".equals(parser.getName())) {
            // Create a new Item and add it to DiscoverItems.
            item = new IMSessionItems.Item(username);
            item.setPresenceStatus(presenceStatus);
            item.setPresenceMsg(presenceMsg);
            item.setLastActivity(lastActivity);
            item.setLoginTime(loginTime);
            item.setResource(resource);
            items.addItem(item);
        } else if (eventType == XmlPullParser.END_TAG && "query".equals(parser.getName())) {
            done = true;
        }
    }
    return items;
}
 
Example 14
Source File: ScanStatusParser.java    From Popeens-DSub with GNU General Public License v3.0 5 votes vote down vote up
public boolean parse(Reader reader, ProgressListener progressListener) throws Exception {
	init(reader);

	String scanName, scanningName;
	if(ServerInfo.isMadsonic(context, instance)) {
		scanName = "status";
		scanningName = "started";
	} else {
		scanName = "scanStatus";
		scanningName = "scanning";
	}

	Boolean scanning = null;
	int eventType;
	do {
		eventType = nextParseEvent();
		if (eventType == XmlPullParser.START_TAG) {
			String name = getElementName();
			if(scanName.equals(name)) {
				scanning = getBoolean(scanningName);

				String msg = context.getResources().getString(R.string.parser_scan_count, getInteger("count"));
				progressListener.updateProgress(msg);
			} else if ("error".equals(name)) {
				handleError();
			}
		}
	} while (eventType != XmlPullParser.END_DOCUMENT);

	validate();

	return scanning != null && scanning;
}
 
Example 15
Source File: SearchResult2Parser.java    From Audinaut with GNU General Public License v3.0 5 votes vote down vote up
public SearchResult parse(InputStream inputStream) throws Exception {
    init(inputStream);

    List<Artist> artists = new ArrayList<>();
    List<MusicDirectory.Entry> albums = new ArrayList<>();
    List<MusicDirectory.Entry> songs = new ArrayList<>();
    int eventType;
    do {
        eventType = nextParseEvent();
        if (eventType == XmlPullParser.START_TAG) {
            String name = getElementName();
            switch (name) {
                case "artist":
                    Artist artist = new Artist();
                    artist.setId(get("id"));
                    artist.setName(get("name"));
                    artists.add(artist);
                    break;
                case "album":
                    MusicDirectory.Entry entry = parseEntry("");
                    entry.setDirectory(true);
                    albums.add(entry);
                    break;
                case "song":
                    songs.add(parseEntry(""));
                    break;
                case "error":
                    handleError();
                    break;
            }
        }
    } while (eventType != XmlPullParser.END_DOCUMENT);

    validate();

    return new SearchResult(artists, albums, songs);
}
 
Example 16
Source File: GPXParser.java    From android-gpx-parser with Apache License 2.0 4 votes vote down vote up
private Metadata readMetadata(XmlPullParser parser) throws XmlPullParserException, IOException {
    Metadata.Builder metadataBuilder = new Metadata.Builder();

    parser.require(XmlPullParser.START_TAG, namespace, TAG_METADATA);
    while (loopMustContinue(parser.next())) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String name = parser.getName();
        switch (name) {
            case TAG_NAME:
                metadataBuilder.setName(readName(parser));
                break;
            case TAG_DESC:
                metadataBuilder.setDesc(readDesc(parser));
                break;
            case TAG_AUTHOR:
                metadataBuilder.setAuthor(readAuthor(parser));
                break;
            case TAG_COPYRIGHT:
                metadataBuilder.setCopyright(readCopyright(parser));
                break;
            case TAG_LINK:
                metadataBuilder.setLink(readLink(parser));
                break;
            case TAG_TIME:
                metadataBuilder.setTime(readTime(parser));
                break;
            case TAG_KEYWORDS:
                metadataBuilder.setKeywords(readString(parser, TAG_KEYWORDS));
                break;
            case TAG_BOUNDS:
                metadataBuilder.setBounds(readBounds(parser));
                break;
            case TAG_EXTENSIONS:
            default:
                skip(parser);
                break;
        }
    }
    parser.require(XmlPullParser.END_TAG, namespace, TAG_METADATA);
    return metadataBuilder.build();
}
 
Example 17
Source File: Wenku8Parser.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 4 votes vote down vote up
static public NovelItemMeta parseNovelFullMeta(String xml) {
    // get full XML metadata of a novel, here is an example:
    // -----------------------------------------------------
    // <?xml version="1.0" encoding="utf-8"?>
    // <metadata>
    // <data name="Title" aid="1306"><![CDATA[向森之魔物献上花束(向森林的魔兽少女献花)]]></data>
    // <data name="Author" value="小木君人"/>
    // <data name="DayHitsCount" value="26"/>
    // <data name="TotalHitsCount" value="43984"/>
    // <data name="PushCount" value="1735"/>
    // <data name="FavCount" value="848"/>
    // <data name="PressId" value="小学馆" sid="10"/>
    // <data name="BookStatus" value="已完成"/>
    // <data name="BookLength" value="105985"/>
    // <data name="LastUpdate" value="2012-11-02"/>
    // <data name="LatestSection" cid="41897"><![CDATA[第一卷 插图]]></data>
    // </metadata>
    Log.d(Wenku8Parser.class.getSimpleName(), xml);

    try {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        XmlPullParser xmlPullParser = factory.newPullParser();
        NovelItemMeta nfi = new NovelItemMeta();
        xmlPullParser.setInput(new StringReader(xml));
        int eventType = xmlPullParser.getEventType();

        while (eventType != XmlPullParser.END_DOCUMENT) {
            switch (eventType) {
                case XmlPullParser.START_DOCUMENT:
                    break;

                case XmlPullParser.START_TAG:

                    if ("metadata".equals(xmlPullParser.getName())) {
                        break;
                    } else if ("data".equals(xmlPullParser.getName())) {
                        if ("Title".equals(xmlPullParser.getAttributeValue(0))) {
                            nfi.aid = Integer.valueOf(xmlPullParser.getAttributeValue(1));
                            nfi.title = xmlPullParser.nextText();
                        } else if ("Author".equals(xmlPullParser
                                .getAttributeValue(0))) {
                            nfi.author = xmlPullParser.getAttributeValue(1);
                        } else if ("DayHitsCount".equals(xmlPullParser
                                .getAttributeValue(0))) {
                            nfi.dayHitsCount = Integer.valueOf(xmlPullParser.getAttributeValue(1));
                        } else if ("TotalHitsCount".equals(xmlPullParser
                                .getAttributeValue(0))) {
                            nfi.totalHitsCount = Integer.valueOf(xmlPullParser.getAttributeValue(1));
                        } else if ("PushCount".equals(xmlPullParser
                                .getAttributeValue(0))) {
                            nfi.pushCount = Integer.valueOf(xmlPullParser.getAttributeValue(1));
                        } else if ("FavCount".equals(xmlPullParser
                                .getAttributeValue(0))) {
                            nfi.favCount = Integer.valueOf(xmlPullParser.getAttributeValue(1));
                        } else if ("PressId".equals(xmlPullParser
                                .getAttributeValue(0))) {
                            nfi.pressId = xmlPullParser.getAttributeValue(1);
                        } else if ("BookStatus".equals(xmlPullParser
                                .getAttributeValue(0))) {
                            nfi.bookStatus = xmlPullParser.getAttributeValue(1);
                        } else if ("BookLength".equals(xmlPullParser
                                .getAttributeValue(0))) {
                            nfi.bookLength = Integer.valueOf(xmlPullParser.getAttributeValue(1));
                        } else if ("LastUpdate".equals(xmlPullParser
                                .getAttributeValue(0))) {
                            nfi.lastUpdate = xmlPullParser.getAttributeValue(1);
                        } else if ("LatestSection".equals(xmlPullParser
                                .getAttributeValue(0))) {
                            nfi.latestSectionCid = Integer.valueOf(xmlPullParser.getAttributeValue(1));
                            nfi.latestSectionName=xmlPullParser.nextText();
                        }
                    }
                    break;
            }
            eventType = xmlPullParser.next();
        }
        return nfi;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 18
Source File: ComponentDescription.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void parseService(XmlPullParser p)
    throws IOException, XmlPullParserException
{
  if (services != null) {
    throw new IllegalXMLException(
                                  "More than one service-tag in component: \""
                                      + componentName + "\"", p);
  }
  ArrayList<String> sl = new ArrayList<String>();
  if (!immediateSet) {
    immediate = false;
  }
  /* If there is an attribute in the service tag */
  for (int i = 0; i < p.getAttributeCount(); i++) {
    if (scrNSminor < 3 && p.getAttributeName(i).equals("servicefactory")) {
      isServiceFactory = parseBoolean(p, i);
      if (isServiceFactory) {
        if (factory != null) {
          throw new IllegalXMLException("Attribute servicefactory in service-tag "
                                        + "cannot be set to \"true\" when component "
                                        + "is a factory component", p);
        }
        if (immediate) {
          throw new IllegalXMLException("Attribute servicefactory in service-tag "
                                        + "cannot be set to \"true\" when component "
                                        + "is an immediate component", p);
        }
        scope = Constants.SCOPE_BUNDLE;
      }
    } else if (scrNSminor > 2 && p.getAttributeName(i).equals("scope")) {
      scope = p.getAttributeValue(i);
      if (!Constants.SCOPE_SINGLETON.equals(scope)) {
        isServiceFactory = true;
        if (!Constants.SCOPE_BUNDLE.equals(scope) && !Constants.SCOPE_PROTOTYPE.equals(scope)) {
          throw new IllegalXMLException("Attribute scope in service-tag must be set to "
                                        + "\"bundle\", \"prototype\" or \"singleton\"", p);
        }
        if (factory != null) {
          throw new IllegalXMLException("Attribute scope in service-tag must be "
                                        + "set to \"singleton\" when component "
                                        + "is a factory component", p);
        }
        if (immediate) {
          throw new IllegalXMLException(
                                        "Attribute scope in service-tag must be "
                                        + "set to \"singleton\" when component "
                                        + "is an immediate component", p);
        }
      }
    } else {
      unrecognizedAttr(p, i);
    }
  }
  int event = p.next();
  while (event != XmlPullParser.END_TAG) {
    if (event != XmlPullParser.START_TAG) {
      event = p.next();
      continue;
    }
    if ("provide".equals(p.getName())) {
      String interfaceName = null;
      for (int i = 0; i < p.getAttributeCount(); i++) {
        if (p.getAttributeName(i).equals("interface")) {
          interfaceName = p.getAttributeValue(i);
        } else {
          throw new IllegalXMLException("Unrecognized attribute \""
                                        + p.getAttributeName(i)
                                        + "\" in provide-tag", p);
        }
      }
      if (interfaceName == null) {
        missingAttr(p, "interface");
      }
      sl.add(interfaceName);
    }
    skip(p);
    event = p.getEventType();
  }
  p.next();
  /* check if required attributes has been set */
  if (sl.isEmpty()) {
    throw new IllegalXMLException("Service-tag did not contain a proper provide-tag",
                                  p);
  }
  services = sl.toArray(new String[sl.size()]);
}
 
Example 19
Source File: AndroidFont.java    From CrossMobile with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("UseSpecificCatch")
private static Map<String, Map<String, FontInfo>> fonts() {
    if (font_map != null)
        return font_map;

    font_map = new LinkedHashMap<>();

    Map<String, FontInfo> family = new LinkedHashMap<>();
    family.put("Sans Serif Regular", new FontInfo(false, false, Typeface.SANS_SERIF));
    family.put("Sans Serif Italic", new FontInfo(false, true, Typeface.SANS_SERIF));
    family.put("Sans Serif Bold", new FontInfo(true, false, Typeface.SANS_SERIF));
    family.put("Sans Serif Bold Italic", new FontInfo(true, true, Typeface.SANS_SERIF));
    font_map.put("Sans Serif", family);

    family = new LinkedHashMap<>();
    family.put("Serif", new FontInfo(false, false, Typeface.SERIF));
    font_map.put("Serif", family);

    family = new LinkedHashMap<>();
    family.put("Monospace", new FontInfo(false, false, Typeface.MONOSPACE));
    font_map.put("Monospace", family);

    XmlResourceParser parser = MainActivity.current.getResources().getXml(AndroidFileBridge.getResourceID("xml", "fontlist"));
    try {
        int eventType = parser.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            switch (eventType) {
                case XmlPullParser.START_TAG:
                    if (parser.getName().equals("font")) {
                        String file = parser.getAttributeValue(null, "file");
                        String familyname = parser.getAttributeValue(null, "family");
                        String name = parser.getAttributeValue(null, "name");
                        boolean bold = parser.getAttributeBooleanValue(null, "bold", false);
                        boolean italic = parser.getAttributeBooleanValue(null, "italic", false);
                        family = font_map.get(familyname);
                        if (family == null) {
                            family = new LinkedHashMap<>();
                            font_map.put(familyname, family);
                        }
                        family.put(name, new FontInfo(bold, italic, file));
                    }
                    break;
                default:
                    break;
            }
            eventType = parser.next();
        }
        parser.close();
    } catch (Exception e) {
    }
    return font_map;
}
 
Example 20
Source File: SsManifestParser.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
public final Object parse(XmlPullParser xmlParser) throws XmlPullParserException, IOException {
  String tagName;
  boolean foundStartTag = false;
  int skippingElementDepth = 0;
  while (true) {
    int eventType = xmlParser.getEventType();
    switch (eventType) {
      case XmlPullParser.START_TAG:
        tagName = xmlParser.getName();
        if (tag.equals(tagName)) {
          foundStartTag = true;
          parseStartTag(xmlParser);
        } else if (foundStartTag) {
          if (skippingElementDepth > 0) {
            skippingElementDepth++;
          } else if (handleChildInline(tagName)) {
            parseStartTag(xmlParser);
          } else {
            ElementParser childElementParser = newChildParser(this, tagName, baseUri);
            if (childElementParser == null) {
              skippingElementDepth = 1;
            } else {
              addChild(childElementParser.parse(xmlParser));
            }
          }
        }
        break;
      case XmlPullParser.TEXT:
        if (foundStartTag && skippingElementDepth == 0) {
          parseText(xmlParser);
        }
        break;
      case XmlPullParser.END_TAG:
        if (foundStartTag) {
          if (skippingElementDepth > 0) {
            skippingElementDepth--;
          } else {
            tagName = xmlParser.getName();
            parseEndTag(xmlParser);
            if (!handleChildInline(tagName)) {
              return build();
            }
          }
        }
        break;
      case XmlPullParser.END_DOCUMENT:
        return null;
      default:
        // Do nothing.
        break;
    }
    xmlParser.next();
  }
}