Example usage for java.util.regex Pattern MULTILINE

List of usage examples for java.util.regex Pattern MULTILINE

Introduction

In this page you can find the example usage for java.util.regex Pattern MULTILINE.

Prototype

int MULTILINE

To view the source code for java.util.regex Pattern MULTILINE.

Click Source Link

Document

Enables multiline mode.

Usage

From source file:org.apache.hadoop.hive.ql.udf.generic.GenericUDFRegExpInstr.java

@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
    IntWritable intWritable = new IntWritable(0);

    int position = 1;
    int occurrence = 1;
    int return_option = 0;
    String match_parameter = "c";

    if (arguments[0].get() == null || arguments[1].get() == null) {
        return null;
    }//from  w  w w.  ja v a 2s  . c o  m

    str = (String) converters[0].convert(arguments[0].get());
    substr = (String) converters[1].convert(arguments[1].get());

    String strFromPosition = str;

    if (arguments.length > 2) {
        position = ((IntObjectInspector) argumentOIs[2]).get(arguments[2].get());
        if (position > str.length() || position < 1) {
            LOG.warn("illegal start position");
            return intWritable;
        }

        if (arguments.length > 3) {
            occurrence = ((IntObjectInspector) argumentOIs[3]).get(arguments[3].get());
            if (occurrence > str.length() || occurrence < 0) {
                LOG.warn("illegal occurrence");
                return intWritable;
            }
        }

        if (arguments.length > 4) {
            return_option = ((IntObjectInspector) argumentOIs[4]).get(arguments[4].get());
            if ((return_option != 0) && (return_option != 1)) {
                LOG.warn("illegal occurrence");
                return intWritable;
            }
        }

        if (arguments.length > 5) {
            match_parameter = ((StringObjectInspector) argumentOIs[5])
                    .getPrimitiveJavaObject(arguments[5].get());
            match_parameter = match_parameter.toLowerCase();
            char[] tmp_char = match_parameter.toCharArray();

            String tmp_str = "icnmx";
            for (int i = 0; i < match_parameter.length(); i++) {
                if (!tmp_str.contains(String.valueOf(tmp_char[i]))) {
                    LOG.warn("illegal match_parameter");
                    return intWritable;
                }
            }
            match_parameter = String.valueOf(tmp_char[match_parameter.length() - 1]);
        }
    }

    try {
        if (match_parameter.compareToIgnoreCase("i") == 0) {
            p = Pattern.compile(substr.toString(), Pattern.CASE_INSENSITIVE);
        } else if (match_parameter.compareToIgnoreCase("c") == 0) {
            p = Pattern.compile(substr.toString());
        } else if (match_parameter.compareToIgnoreCase("n") == 0) {
            p = Pattern.compile(substr.toString(), Pattern.DOTALL);
        } else if (match_parameter.compareToIgnoreCase("m") == 0) {
            p = Pattern.compile(substr.toString(), Pattern.MULTILINE);
        } else if (match_parameter.compareToIgnoreCase("x") == 0) {
            p = Pattern.compile(substr.toString(), Pattern.COMMENTS);
        } else {
            p = Pattern.compile(substr.toString());
        }

        if (position > 1) {
            strFromPosition = str.substring(position - 1);
        }

        Matcher m = p.matcher(strFromPosition.toString());
        for (int i = 0; i < occurrence; i++) {
            if (m.find()) {
                if (return_option == 0) {
                    intWritable.set(m.start() + position);
                } else {
                    intWritable.set(m.end() + position);
                }
            } else {
                LOG.info("m.find() = " + m.find());
                intWritable.set(0);
                break;
            }
        }
        return intWritable;
    } catch (PatternSyntaxException e) {
        LOG.info("PatternSyntaxException");
        return intWritable;
    }
}

From source file:org.squale.welcom.struts.webServer.WebEngine.java

/**
 * Suppresion des commentaires ///*www  . ja  va 2  s. c o  m*/
 * 
 * @param s chaine  nettoyer
 * @return chaine nettoye
 */
private String smartReplaceAll(final String s) {
    Pattern pattern = Pattern.compile("(.)(//[^\\n\\\\]*)\\n", Pattern.DOTALL | Pattern.MULTILINE);
    Matcher matcher = pattern.matcher(s);

    StringBuffer sb = new StringBuffer();
    boolean result = matcher.find();
    while (result) {
        if (Util.isEquals(matcher.group(1), "\\")) {
            matcher.appendReplacement(sb, "\\" + matcher.group());
        } else if (Util.isEquals(matcher.group(1), ":")) {
            matcher.appendReplacement(sb, matcher.group());
        } else {
            matcher.appendReplacement(sb, matcher.group(1));
        }
        result = matcher.find();
    }
    matcher.appendTail(sb);

    // Recherche le ligne qui ont chapp au filtre et qui sont des commentaires
    pattern = Pattern.compile("^//[^\\n]*\\n", Pattern.DOTALL | Pattern.MULTILINE);
    matcher = pattern.matcher(sb.toString());
    sb = new StringBuffer();
    while (matcher.find()) {
        matcher.appendReplacement(sb, "");
    }
    matcher.appendTail(sb);

    return sb.toString();
}

From source file:org.apache.nifi.processors.enrich.AbstractEnrichProcessor.java

/**
 * This method returns the parsed record string in the form of
 * a map of two strings, consisting of a iteration aware attribute
 * names and its values/*w w w .j av a 2  s  .c o  m*/
 *
        
 * @param  rawResult the raw query results to be parsed
 * @param queryParser The parsing mechanism being used to parse the data into groups
 * @param queryRegex The regex to be used to split the query results into groups. The regex MUST implement at least on named capture group "KEY" to be used to populate the table rows
 * @param lookupKey The regular expression number or the column of a split to be used for matching
 * @return  Table with attribute names and values where each Table row uses the value of the KEY named capture group specified in @param queryRegex
 */
protected Table<String, String, String> parseBatchResponse(String rawResult, String queryParser,
        String queryRegex, int lookupKey, String schema) {
    // Note the hardcoded record0.
    //  Since iteration is done within the parser and Multimap is used, the record number here will always be 0.
    // Consequentially, 0 is hardcoded so that batched and non batched attributes follow the same naming
    // conventions
    final String recordPosition = ".record0";

    final Table<String, String, String> results = HashBasedTable.create();

    switch (queryParser) {
    case "Split":
        Scanner scanner = new Scanner(rawResult);
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            // Time to Split the results...
            String[] splitResult = line.split(queryRegex);

            for (int r = 0; r < splitResult.length; r++) {
                results.put(splitResult[lookupKey - 1],
                        "enrich." + schema + recordPosition + ".group" + String.valueOf(r), splitResult[r]);
            }
        }
        break;
    case "RegEx":
        // prepare the regex
        Pattern p;
        // Regex is multiline. Each line should include a KEY for lookup
        p = Pattern.compile(queryRegex, Pattern.MULTILINE);

        Matcher matcher = p.matcher(rawResult);
        while (matcher.find()) {
            try {
                // Note that RegEx matches capture group 0 is usually broad but starting with it anyway
                // for the sake of purity
                for (int r = 0; r <= matcher.groupCount(); r++) {
                    results.put(matcher.group(lookupKey),
                            "enrich." + schema + recordPosition + ".group" + String.valueOf(r),
                            matcher.group(r));
                }
            } catch (IndexOutOfBoundsException e) {
                getLogger().warn(
                        "Could not find capture group {} while processing result. You may want to review your "
                                + "Regular Expression to match against the content \"{}\"",
                        new Object[] { lookupKey, rawResult });
            }
        }
        break;
    }

    return results;
}

From source file:org.projectforge.core.CreateI18nKeys.java

private List<String> find(final File file, final String content, final String regexp) {
    final List<String> result = new ArrayList<String>();
    final Pattern p = Pattern.compile(regexp, Pattern.MULTILINE); // Compiles regular expression into Pattern.
    final Matcher m = p.matcher(content);
    while (m.find()) {
        result.add(m.group(1));//  ww w  .ja va  2s  .  co  m
    }
    return result;
}

From source file:matteroverdrive.gui.pages.PageGuideDescription.java

private Map<String, String> loadStyleSheetMap(Element element) {
    if (element.hasAttribute("stylesheet")) {
        try {//w ww  . ja va2 s.c om
            Map<String, String> styleMap = new HashMap<>();
            InputStream stylesheetStream = Minecraft.getMinecraft().getResourceManager()
                    .getResource(new ResourceLocation(element.getAttribute("stylesheet"))).getInputStream();
            String rawStyle = IOUtils.toString(stylesheetStream, "UTF-8");
            rawStyle = rawStyle.replaceAll("\\r|\\n|\\s+", "");
            rawStyle = rawStyle.replaceAll("(?s)/\\*.*?\\*/", ""); //remove comments
            Matcher matcher = Pattern.compile("([^\\}\\{]+)(\\{[^\\}]+\\})", Pattern.DOTALL | Pattern.MULTILINE)
                    .matcher(rawStyle);
            while (matcher.find()) {
                styleMap.put(matcher.group(1), matcher.group(2).substring(1, matcher.group(2).length() - 1));
            }
            return styleMap;
        } catch (IOException e) {
            MatterOverdrive.log.log(Level.ERROR, e, "There was a problem loading the stylesheet");
        }
    }
    return null;
}

From source file:org.squale.welcom.struts.lazyLoading.WLazyUtil.java

/**
 * pure le corps d'un combo/*from  w  w w.j  ava2  s  . c o  m*/
 * 
 * @param s chaine contenant le flux  modifier
 * @return le flux modifi
 */
public static String getLightCombo(final String s) {
    final StringBuffer options = new StringBuffer();

    // Search name
    final Pattern reOptionSelected = Pattern.compile("<\\s*option[^>]+selected[^>]*>[^<]*<\\/\\s*option\\s*>",
            Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    final Pattern reOption = Pattern.compile("<\\s*option[^>]*>([^<]*)<\\/\\s*option\\s*>",
            Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    final Matcher maOptionSelected = reOptionSelected.matcher(s);
    final Matcher maOption = reOption.matcher(s);

    // RE reOptionSelected = new RE
    // ("<\\s*option[^>]+selected[^>]*>[^<]*<\\/\\s*option\\s*>",RE.MATCH_CASEINDEPENDENT);
    // RE reOption = new RE ("<\\s*option[^>]*>([^<]*)<\\/\\s*option\\s*>",RE.MATCH_CASEINDEPENDENT);
    if (maOptionSelected.find()) {
        options.append(maOptionSelected.group(0));
    } else {
        if (maOption.find()) {
            options.append(maOption.group(0));
        } else {
            return s;
        }
    }

    int pos = 0;
    String longer = "";

    while (maOption.find(pos)) {
        if (WFontSimulator.getSize(maOption.group(1)) > WFontSimulator.getSize(longer)) {
            longer = maOption.group(1);
        }

        pos = maOption.end(0);
    }

    if (options.toString().indexOf(longer) < 0) {
        options.append("<option>" + longer + "</option>");
    }
    return options.toString();
}

From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java

public StatusArrayString getArrayListItemStatus(String lookupPattern, String html, int groupNo[],
        String lookupName) {/*from  w ww . j av  a2 s.  c om*/
    Status iStatus = new Status();
    StatusArrayString getItemListStatus = new StatusArrayString();
    ArrayList<String> arraylistItemStatus = new ArrayList<String>();
    //LOG.debug("getArrayListItemStatus - loolupPattern: " + lookupPattern);
    Pattern findPattern = Pattern.compile(lookupPattern, Pattern.MULTILINE + Pattern.CASE_INSENSITIVE);
    Matcher findPatternMatch = findPattern.matcher(html);
    String itemValue = "";
    String itemValueFormat = "";
    boolean itemFound = false;

    while (findPatternMatch.find()) {
        String finalValue = "";
        itemFound = true;
        for (int x = 0; x < groupNo.length; x++) {
            itemValue = findPatternMatch.group(groupNo[x]);
            //LOG.debug("Process group: " + x + " .itemValue: " + itemValue);
            // This section for removing extra fields in Call No 
            if (itemValue.contains("<!-- field v -->")) {
                itemValueFormat = itemValue.replaceAll("<!-- field v -->", "");
                itemValue = itemValueFormat.trim();
                //LOG.debug("Found <!-- field # --> " + "- New itemValue: " + itemValue);
            }
            if (itemValue.contains("<!-- field # -->")) {
                itemValueFormat = itemValue.replaceAll("<!-- field # -->", "");
                itemValue = itemValueFormat.trim();
                //LOG.debug("Found <!-- field # --> " + "- New itemValue: " + itemValue);
            }
            if (itemValue.contains("<!-- field y -->")) {
                itemValueFormat = itemValue.replaceAll("<!-- field y -->", "");
                itemValue = itemValueFormat.trim();
                //LOG.debug("Found <!-- field y --> " + "- New itemValue: " + itemValue);
            }
            // This section for removing extra fields in Location
            if (itemValue.contains("<!-- field ! -->")) {
                itemValueFormat = itemValue.replaceAll("<!-- field ! -->", "");
                itemValue = itemValueFormat.trim();
                //LOG.debug("Found <!-- field ! --> " + "- New itemValue: " + itemValue);
            }
            // This section for removing <br />
            if (itemValue.contains("<br />")) {
                itemValueFormat = itemValue.replaceAll("<br />", "");
                itemValue = itemValueFormat.trim();
                LOG.debug("Found <br /> " + "- New itemValue: " + itemValue);
            }
            // This section for removing <em>
            if (itemValue.contains("<em>")) {
                itemValueFormat = itemValue.replaceAll("<em>", "");
                itemValue = itemValueFormat.trim();
                //LOG.debug("Found <em> " + "- New itemValue: " + itemValue);
            }
            // This section for removing </em>
            if (itemValue.contains("</em>")) {
                itemValueFormat = itemValue.replaceAll("</em>", "");
                itemValue = itemValueFormat.trim();
                //LOG.debug("Found </em> " + "- New itemValue: " + itemValue);
            }
            if (itemValue.contains("&nbsp;")) {
                itemValueFormat = itemValue.replaceAll("&nbsp;", "");
                itemValue = itemValueFormat.trim();
                //LOG.debug("Found &nbsp; " + "- New itemValue: " + itemValue);
            }
            if (itemValue.contains("\n")) {
                itemValueFormat = itemValue.replaceAll("\n", "");
                itemValue = itemValueFormat.trim();
                //LOG.debug("Found '\n' " + "- New itemValue: " + itemValue);
            }
            itemValue = itemValue.trim();
            if (itemValue.contains("<a href=")) {
                String patternLookup = "^<a(.*?)>(.*?)</a>(?s)(.*?)$";
                //LOG.debug("itemValue: " + itemValue);
                int noGroup[];
                noGroup = new int[2];
                noGroup[0] = 2;
                noGroup[1] = 3;
                StatusArrayString getArrayListItemItemStatusNoLink = new StatusArrayString();
                getArrayListItemItemStatusNoLink = getArrayListItemStatus(patternLookup, itemValue, noGroup,
                        "Link");
                //LOG.debug("getArrayListItemItemStatusNoLink Size is: " + getArrayListItemItemStatusNoLink.itemsList.size());
                if (getArrayListItemItemStatusNoLink.itemsList.size() > 0) {
                    itemValue = getArrayListItemItemStatusNoLink.itemsList.get(0);
                }
            }
            //LOG.debug("itemValue: " + itemValue);
            if (itemValue.length() > 0) {
                if (finalValue.length() > 0) {
                    finalValue = finalValue + " " + itemValue.trim();
                } else {
                    finalValue = itemValue.trim();
                }
            }
        }
        if (finalValue.length() <= 0) {
            finalValue = "Missing";
        }
        //LOG.debug("finalValue: " + finalValue);
        arraylistItemStatus.add(finalValue);
    }
    if (itemFound) {
        iStatus.returnStatus = true;
        //iStatus.returnMsg = "Found pattern match for: " + lookupName;
        iStatus.returnMsg = errorCodeMsg.ErrorMessage(102) + lookupName;
        getItemListStatus.recordStatus = iStatus;
        getItemListStatus.itemsList = arraylistItemStatus;
    } else {
        iStatus.returnStatus = false;
        //iStatus.returnMsg = "Could not find pattern match for: " + lookupName;
        iStatus.returnMsg = errorCodeMsg.ErrorMessage(103) + lookupName;
        getItemListStatus.recordStatus = iStatus;
        getItemListStatus.itemsList = null;
    }
    return getItemListStatus;
}

From source file:de.tarent.maven.plugins.pkg.packager.DebPackager.java

/**
 * Validates arguments and test tools./*w ww .java  2  s .  com*/
 * 
 * @throws MojoExecutionException
 */
@Override
public void checkEnvironment(Log l, WorkspaceSession workspaceSession) throws MojoExecutionException {

    Utils.checkProgramAvailability("dpkg-deb");
    String output = Utils.getProgramVersionOutput("dpkg-deb");

    /*
     * We will check if the minor version number is smaller than 15.
     * Problems have been reported regarding older versions of dpkg-deb and
     * - what dpkg-deb understands as version numbers - not containing
     * numbers (bug #2912), e.g. "-SNAPSHOT".
     */

    Pattern p = Pattern.compile("version (1\\.([0-9]{2})\\.([0-9]*\\.*)*)* ", Pattern.MULTILINE);
    Matcher m = p.matcher(output);
    if (m.find()) {
        l.info("dpkg-deb version: " + m.group(1));
        int versionNumber = Integer.parseInt(m.group(2));
        if (versionNumber < 15 && workspaceSession.getHelper().getPackageVersion().contains("-SNAPSHOT")) {
            throw new MojoExecutionException(
                    "You are trying to build a snapshot with an older version of dpkg-deb. "
                            + "You are advised to add a revision number to your package (e.g. r1) or "
                            + "your package will not be built correctly.");
        }
    }
    // Some external tools are only needed if the package is to be signed
    if (workspaceSession.getTargetConfiguration().isSign()) {
        Utils.checkProgramAvailability("dpkg-distaddfile");
        Utils.checkProgramAvailability("gpg");
        Utils.checkProgramAvailability("ar");
    }
}

From source file:org.opennms.netmgt.syslogd.ConvertToEvent.java

/**
 * Constructs a new event encapsulation instance based upon the
 * information passed to the method. The passed byte array is decoded into
 * a string using the <tt>US-ASCII</tt> character encoding.
 *
 * @param addr The remote agent's address.
 * @param port The remote agent's port/*w w w . ja v  a  2s . com*/
 * @param data The XML data in US-ASCII encoding.
 * @param len  The length of the XML data in the buffer.
 * @throws java.io.UnsupportedEncodingException
 *          Thrown if the data buffer cannot be decoded using the
 *          US-ASCII encoding.
 * @throws MessageDiscardedException 
 */
public ConvertToEvent(final InetAddress addr, final int port, final String data, final SyslogdConfig config)
        throws UnsupportedEncodingException, MessageDiscardedException {

    if (config == null) {
        throw new IllegalArgumentException("Config cannot be null");
    }

    final UeiList ueiList = config.getUeiList();
    final HideMessage hideMessage = config.getHideMessages();
    final String discardUei = config.getDiscardUei();

    final String syslogString;
    if (data.endsWith("\0")) {
        syslogString = data.substring(0, data.length() - 1);
    } else {
        syslogString = data;
    }

    LOG.debug("Converting to event: {}", this);

    SyslogParser parser = SyslogParser.getParserInstance(config, syslogString);
    if (!parser.find()) {
        throw new MessageDiscardedException("message does not match");
    }
    SyslogMessage message;
    try {
        message = parser.parse();
    } catch (final SyslogParserException ex) {
        LOG.debug("Unable to parse '{}'", syslogString, ex);
        throw new MessageDiscardedException(ex);
    }

    LOG.debug("got syslog message {}", message);
    if (message == null) {
        throw new MessageDiscardedException(String.format("Unable to parse '%s'", syslogString));
    }
    // Build a basic event out of the syslog message
    final String priorityTxt = message.getSeverity().toString();
    final String facilityTxt = message.getFacility().toString();

    EventBuilder bldr = new EventBuilder("uei.opennms.org/syslogd/" + facilityTxt + "/" + priorityTxt,
            "syslogd");
    bldr.setCreationTime(message.getDate());

    // Set event host
    bldr.setHost(InetAddressUtils.getLocalHostName());

    final String hostAddress = message.getHostAddress();
    if (hostAddress != null && hostAddress.length() > 0) {
        // Set nodeId
        long nodeId = SyslogdIPMgrJDBCImpl.getInstance().getNodeId(hostAddress);
        if (nodeId != -1) {
            bldr.setNodeid(nodeId);
        }

        bldr.setInterface(addr(hostAddress));
    }

    bldr.setLogDest("logndisplay");

    // We will also here find out if, the host needs to
    // be replaced, the message matched to a UEI, and
    // last if we need to actually hide the message.
    // this being potentially helpful in avoiding showing
    // operator a password or other data that should be
    // confidential.

    /*
    * We matched on a regexp for host/message pair.
    * This can be a forwarded message as in BSD Style
    * or syslog-ng.
    * We assume that the host is given to us
    * as an IP/Hostname and that the resolver
    * on the ONMS host actually can resolve the
    * node to match against nodeId.
     */

    Pattern msgPat = null;
    Matcher msgMat = null;

    // Time to verify UEI matching.

    final String fullText = message.getFullText();
    final String matchedText = message.getMatchedMessage();

    final List<UeiMatch> ueiMatch = ueiList == null ? null : ueiList.getUeiMatchCollection();
    if (ueiMatch == null) {
        LOG.warn("No ueiList configured.");
    } else {
        for (final UeiMatch uei : ueiMatch) {
            final boolean otherStuffMatches = containsIgnoreCase(uei.getFacilityCollection(), facilityTxt)
                    && containsIgnoreCase(uei.getSeverityCollection(), priorityTxt)
                    && matchProcess(uei.getProcessMatch(), message.getProcessName())
                    && matchHostname(uei.getHostnameMatch(), message.getHostName())
                    && matchHostAddr(uei.getHostaddrMatch(), message.getHostAddress());

            // Single boolean check is added instead of performing multiple
            // boolean check for both if and else if which causes a extra time
            if (otherStuffMatches) {
                if (uei.getMatch().getType().equals("substr")) {
                    if (matchSubstring(discardUei, bldr, matchedText, uei)) {
                        break;
                    }
                } else if ((uei.getMatch().getType().startsWith("regex"))) {
                    if (matchRegex(message, uei, bldr, discardUei)) {
                        break;
                    }
                }
            }
        }
    }

    // Time to verify if we need to hide the message
    boolean doHide = false;
    final List<HideMatch> hideMatch = hideMessage == null ? null : hideMessage.getHideMatchCollection();
    if (hideMatch == null) {
        LOG.warn("No hideMessage configured.");
    } else {
        for (final HideMatch hide : hideMatch) {
            if (hide.getMatch().getType().equals("substr")) {
                if (fullText.contains(hide.getMatch().getExpression())) {
                    // We should hide the message based on this match
                    doHide = true;
                }
            } else if (hide.getMatch().getType().equals("regex")) {
                try {
                    msgPat = Pattern.compile(hide.getMatch().getExpression(), Pattern.MULTILINE);
                    msgMat = msgPat.matcher(fullText);
                } catch (PatternSyntaxException pse) {
                    LOG.warn("Failed to compile regex pattern '{}'", hide.getMatch().getExpression(), pse);
                    msgMat = null;
                }
                if ((msgMat != null) && (msgMat.find())) {
                    // We should hide the message based on this match
                    doHide = true;
                }
            }
            if (doHide) {
                LOG.debug("Hiding syslog message from Event - May contain sensitive data");
                message.setMessage(HIDDEN_MESSAGE);
                // We want to stop here, no point in checking further hideMatches
                break;
            }
        }
    }

    // Using parms provides configurability.
    bldr.setLogMessage(message.getMessage());

    bldr.addParam("syslogmessage", message.getMessage());
    bldr.addParam("severity", "" + priorityTxt);
    bldr.addParam("timestamp", message.getSyslogFormattedDate());

    if (message.getProcessName() != null) {
        bldr.addParam("process", message.getProcessName());
    }

    bldr.addParam("service", "" + facilityTxt);

    if (message.getProcessId() != null) {
        bldr.addParam("processid", message.getProcessId().toString());
    }

    m_event = bldr.getEvent();
}

From source file:org.opennms.web.rest.NodeRestServiceTest.java

@Test
@JUnitTemporaryDatabase//  w w  w.java  2s . c  o  m
public void testLimits() throws Exception {
    JAXBContext context = JAXBContext.newInstance(OnmsNodeList.class);
    Unmarshaller unmarshaller = context.createUnmarshaller();

    // Testing POST
    for (m_nodeCounter = 0; m_nodeCounter < 20; m_nodeCounter++) {
        createNode();
    }
    String url = "/nodes";
    // Testing GET Collection
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("limit", "10");
    parameters.put("orderBy", "id");
    String xml = sendRequest(GET, url, parameters, 200);
    assertTrue(xml, xml.contains("Darwin TestMachine 9.4.0 Darwin Kernel Version 9.4.0"));
    Pattern p = Pattern.compile("<node [^>]*\\s*id=",
            Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE);
    Matcher m = p.matcher(xml);
    int count = 0;
    while (m.find()) {
        count++;
    }
    assertEquals("should get 10 nodes back", 10, count);

    // Validate object by unmarshalling
    OnmsNodeList list = (OnmsNodeList) unmarshaller.unmarshal(new StringReader(xml));
    assertEquals(Integer.valueOf(10), list.getCount());
    assertEquals(10, list.size());
    assertEquals(Integer.valueOf(20), list.getTotalCount());
    int i = 0;
    Set<OnmsNode> sortedNodes = new TreeSet<OnmsNode>(new Comparator<OnmsNode>() {
        @Override
        public int compare(OnmsNode o1, OnmsNode o2) {
            if (o1 == null && o2 == null) {
                return 0;
            } else if (o1 == null) {
                return 1;
            } else if (o2 == null) {
                return -1;
            } else {
                if (o1.getId() == null) {
                    throw new IllegalStateException("Null ID on node: " + o1.toString());
                }
                return o1.getId().compareTo(o2.getId());
            }
        }
    });
    // Sort the nodes by ID
    sortedNodes.addAll(list.getObjects());
    for (OnmsNode node : sortedNodes) {
        assertEquals(node.toString(), "TestMachine" + i++, node.getLabel());
    }
}