List of usage examples for java.lang Character isISOControl
public static boolean isISOControl(int codePoint)
From source file:httpmultiplexer.httpproxy.ProxyServlet.java
/** * Encodes characters in the query or fragment part of the URI. * * <p>/* ww w. j a v a 2 s. c om*/ * Unfortunately, an incoming URI sometimes has characters disallowed by the * spec. HttpClient insists that the outgoing proxied request has a valid * URI because it uses Java's {@link URI}. To be more forgiving, we must * escape the problematic characters. See the URI class for the spec. * * @param in example: name=value&foo=bar#fragment */ protected static CharSequence encodeUriQuery(CharSequence in) { //Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things. StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {//not-ascii escape = false; } if (!escape) { if (outBuf != null) { outBuf.append(c); } } else { //escape if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } //leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c);//TODO } } return outBuf != null ? outBuf : in; }
From source file:io.hops.hopsworks.api.kibana.ProxyServlet.java
/** * Encodes characters in the query or fragment part of the URI. * <p>/*from ww w. j a va2 s . c om*/ * <p> * Unfortunately, an incoming URI sometimes has characters disallowed by the * spec. HttpClient * insists that the outgoing proxied request has a valid URI because it uses * Java's {@link URI}. * To be more forgiving, we must escape the problematic characters. See the * URI class for the * spec. * * @param in example: name=value&foo=bar#fragment */ protected static CharSequence encodeUriQuery(CharSequence in) { //Note that I can't simply use URI.java to encode because it will escape //pre-existing escaped things. StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {//not-ascii escape = false; } if (!escape) { if (outBuf != null) { outBuf.append(c); } } else { //escape if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } //leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c);//TODO } } return outBuf != null ? outBuf : in; }
From source file:com.google.gwt.jolokia.server.servlet.ProxyServlet.java
/** * Encodes characters in the query or fragment part of the URI. * * <p>/*w ww . j av a 2s . c om*/ * Unfortunately, an incoming URI sometimes has characters disallowed by the * spec. HttpClient insists that the outgoing proxied request has a valid * URI because it uses Java's {@link URI}. To be more forgiving, we must * escape the problematic characters. See the URI class for the spec. * * @param in * example: name=value&foo=bar#fragment */ protected static CharSequence encodeUriQuery(CharSequence in) { // Note that I can't simply use URI.java to encode because it will // escape pre-existing escaped things. StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {// not-ascii escape = false; } if (!escape) { if (outBuf != null) outBuf.append(c); } else { // escape if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } // leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c);// TODO } } return outBuf != null ? outBuf : in; }
From source file:org.dspace.content.Item.java
/** * Add metadata fields. These are appended to existing values. * Use <code>clearDC</code> to remove values. The ordering of values * passed in is maintained.//w w w . ja va2s . c o m * @param schema * the schema for the metadata field. <em>Must</em> match * the <code>name</code> of an existing metadata schema. * @param element * the metadata element name * @param qualifier * the metadata qualifier name, or <code>null</code> for * unqualified * @param lang * the ISO639 language code, optionally followed by an underscore * and the ISO3166 country code. <code>null</code> means the * value has no language (for example, a date). * @param values * the values to add. * @param authorities * the external authority key for this value (or null) * @param confidences * the authority confidence (default 0) */ public void addMetadata(String schema, String element, String qualifier, String lang, String[] values, String authorities[], int confidences[]) { List<DCValue> dublinCore = getMetadata(); MetadataAuthorityManager mam = MetadataAuthorityManager.getManager(); boolean authorityControlled = mam.isAuthorityControlled(schema, element, qualifier); boolean authorityRequired = mam.isAuthorityRequired(schema, element, qualifier); String fieldName = schema + "." + element + ((qualifier == null) ? "" : "." + qualifier); // We will not verify that they are valid entries in the registry // until update() is called. for (int i = 0; i < values.length; i++) { DCValue dcv = new DCValue(); dcv.schema = schema; dcv.element = element; dcv.qualifier = qualifier; dcv.language = (lang == null ? null : lang.trim()); // Logic to set Authority and Confidence: // - normalize an empty string for authority to NULL. // - if authority key is present, use given confidence or NOVALUE if not given // - otherwise, preserve confidence if meaningful value was given since it may document a failed authority lookup // - CF_UNSET signifies no authority nor meaningful confidence. // - it's possible to have empty authority & CF_ACCEPTED if e.g. user deletes authority key if (authorityControlled) { if (authorities != null && authorities[i] != null && authorities[i].length() > 0) { dcv.authority = authorities[i]; dcv.confidence = confidences == null ? Choices.CF_NOVALUE : confidences[i]; } else { dcv.authority = null; dcv.confidence = confidences == null ? Choices.CF_UNSET : confidences[i]; } // authority sanity check: if authority is required, was it supplied? // XXX FIXME? can't throw a "real" exception here without changing all the callers to expect it, so use a runtime exception if (authorityRequired && (dcv.authority == null || dcv.authority.length() == 0)) { throw new IllegalArgumentException("The metadata field \"" + fieldName + "\" requires an authority key but none was provided. Vaue=\"" + dcv.value + "\""); } } if (values[i] != null) { // remove control unicode char String temp = values[i].trim(); char[] dcvalue = temp.toCharArray(); for (int charPos = 0; charPos < dcvalue.length; charPos++) { if (Character.isISOControl(dcvalue[charPos]) && !String.valueOf(dcvalue[charPos]).equals("\u0009") && !String.valueOf(dcvalue[charPos]).equals("\n") && !String.valueOf(dcvalue[charPos]).equals("\r")) { dcvalue[charPos] = ' '; } } dcv.value = String.valueOf(dcvalue); } else { dcv.value = null; } dublinCore.add(dcv); addDetails(fieldName); } if (values.length > 0) { dublinCoreChanged = true; } }
From source file:com.fuseim.webapp.ProxyServlet.java
/** * Encodes characters in the query or fragment part of the URI. * * <p>Unfortunately, an incoming URI sometimes has characters disallowed by the spec. HttpClient * insists that the outgoing proxied request has a valid URI because it uses Java's {@link URI}. * To be more forgiving, we must escape the problematic characters. See the URI class for the * spec./*from w w w . j a va2s . co m*/ * * @param in example: name=value&foo=bar#fragment */ protected static CharSequence encodeUriQuery(CharSequence in) { //Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things. StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) { //not-ascii escape = false; } if (!escape) { if (outBuf != null) outBuf.append(c); } else { //escape if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } //leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c); //TODO } } return outBuf != null ? outBuf : in; }
From source file:uk.ac.ucl.cs.cmic.giftcloud.uploadapp.ConfigurationDialog.java
public static boolean isValidAETitle(String aet) { // Per PS 3.5: Default Character Repertoire excluding character code 5CH (the BACKSLASH \? in ISO-IR 6), and control characters LF, FF, CR and ESC. 16 bytes maximum boolean good = true; if (aet == null) { good = false;// w w w.j a va2s. com } else if (aet.length() == 0) { good = false; } else if (aet.length() > 16) { good = false; } else if (aet.trim().length() == 0) { // all whitespace is illegal good = false; } else if (aet.contains("\\")) { good = false; } else { int l = aet.length(); for (int i = 0; i < l; ++i) { int codePoint = aet.codePointAt(i); try { Character.UnicodeBlock codeBlock = Character.UnicodeBlock.of(codePoint); if (codeBlock != Character.UnicodeBlock.BASIC_LATIN) { good = false; } else if (Character.isISOControl(codePoint)) { good = false; } } catch (IllegalArgumentException e) { // if not a valid code point good = false; } } } return good; }
From source file:com.ngdata.hbaseindexer.model.impl.IndexerModelImpl.java
/** * Check the validity of an indexer name. * <p>/*from ww w . java2s . c om*/ * An indexer name can be any string of printable unicode characters that has a length greater than 0. Printable * characters in this context are considered to be anything that is not an ISO control character as defined by * {@link Character#isISOControl(int)}. * * @param indexerName The name to validate */ public static void validateIndexerName(String indexerName) { Preconditions.checkNotNull(indexerName); if (indexerName.length() == 0) { throw new IllegalArgumentException("Indexer name is empty"); } for (int charIdx = 0; charIdx < indexerName.length(); charIdx++) { if (Character.isISOControl(indexerName.codePointAt(charIdx))) { throw new IllegalArgumentException("Indexer names may only consist of printable characters"); } } }
From source file:org.apache.pdfbox.debugger.PDFDebugger.java
private String convertToString(Object selectedNode) { String data = null;/*from w w w .j av a2s . c o m*/ if (selectedNode instanceof COSBoolean) { data = "" + ((COSBoolean) selectedNode).getValue(); } else if (selectedNode instanceof COSFloat) { data = "" + ((COSFloat) selectedNode).floatValue(); } else if (selectedNode instanceof COSNull) { data = "null"; } else if (selectedNode instanceof COSInteger) { data = "" + ((COSInteger) selectedNode).intValue(); } else if (selectedNode instanceof COSName) { data = "" + ((COSName) selectedNode).getName(); } else if (selectedNode instanceof COSString) { String text = ((COSString) selectedNode).getString(); // display unprintable strings as hex for (char c : text.toCharArray()) { if (Character.isISOControl(c)) { text = "<" + ((COSString) selectedNode).toHexString() + ">"; break; } } data = "" + text; } else if (selectedNode instanceof COSStream) { try { COSStream stream = (COSStream) selectedNode; InputStream ioStream = stream.createInputStream(); ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int amountRead; while ((amountRead = ioStream.read(buffer, 0, buffer.length)) != -1) { byteArray.write(buffer, 0, amountRead); } data = byteArray.toString(); } catch (IOException e) { throw new RuntimeException(e); } } else if (selectedNode instanceof MapEntry) { data = convertToString(((MapEntry) selectedNode).getValue()); } else if (selectedNode instanceof ArrayEntry) { data = convertToString(((ArrayEntry) selectedNode).getValue()); } return data; }
From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java
@SuppressWarnings("serial") private JPanel createParamsweepGUI() { // left//from ww w.j a va 2 s. c om parameterList = new JList(); parameterList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); new ListAction(parameterList, new AbstractAction() { public void actionPerformed(final ActionEvent event) { final AvailableParameter selectedParameter = (AvailableParameter) parameterList.getSelectedValue(); addParameterToTree(new AvailableParameter[] { selectedParameter }, parameterTreeBranches.get(0)); enableDisableParameterCombinationButtons(); } }); parameterList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!parameterList.isSelectionEmpty()) { boolean success = true; if (editedNode != null) success = modify(); if (success) { cancelAllSelectionBut(parameterList); resetSettings(); updateDescriptionField(parameterList.getSelectedValues()); enableDisableParameterCombinationButtons(); } else parameterList.clearSelection(); } } }); final JScrollPane parameterListPane = new JScrollPane(parameterList); parameterListPane.setBorder(BorderFactory.createTitledBorder("")); // for rounded border parameterListPane.setPreferredSize(new Dimension(300, 300)); final JPanel parametersPanel = FormsUtils.build("p ' p:g", "[DialogBorder]00||" + "12||" + "34||" + // "56||" + "55||" + "66 f:p:g", new FormsUtils.Separator("<html><b>General parameters</b></html>"), NUMBER_OF_TURNS_LABEL_TEXT, numberOfTurnsFieldPSW, NUMBER_OF_TIMESTEPS_TO_IGNORE_LABEL_TEXT, numberTimestepsIgnoredPSW, // UPDATE_CHARTS_LABEL_TEXT,onLineChartsCheckBoxPSW, new FormsUtils.Separator("<html><b>Model parameters</b></html>"), parameterListPane).getPanel(); combinationsPanel = new JPanel(new GridLayout(0, 1, 5, 5)); combinationsScrPane = new JScrollPane(combinationsPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); combinationsScrPane.setBorder(null); combinationsScrPane.setPreferredSize(new Dimension(550, 500)); parameterDescriptionLabel = new JXLabel(); parameterDescriptionLabel.setLineWrap(true); parameterDescriptionLabel.setVerticalAlignment(SwingConstants.TOP); final JScrollPane descriptionScrollPane = new JScrollPane(parameterDescriptionLabel); descriptionScrollPane.setBorder(BorderFactory.createTitledBorder(null, "Description", TitledBorder.LEADING, TitledBorder.BELOW_TOP)); descriptionScrollPane.setPreferredSize( new Dimension(PARAMETER_DESCRIPTION_LABEL_WIDTH, PARAMETER_DESCRIPTION_LABEL_HEIGHT)); descriptionScrollPane.setViewportBorder(null); final JButton addNewBoxButton = new JButton("Add new combination"); addNewBoxButton.setActionCommand(ACTIONCOMMAND_ADD_BOX); final JPanel left = FormsUtils.build("p ~ f:p:g ~ p", "011 f:p:g ||" + "0_2 p", parametersPanel, combinationsScrPane, addNewBoxButton).getPanel(); left.setBorder(BorderFactory.createTitledBorder(null, "Specify parameter combinations", TitledBorder.LEADING, TitledBorder.BELOW_TOP)); Style.registerCssClasses(left, Dashboard.CSS_CLASS_COMMON_PANEL); final JPanel leftAndDesc = new JPanel(new BorderLayout()); leftAndDesc.add(left, BorderLayout.CENTER); leftAndDesc.add(descriptionScrollPane, BorderLayout.SOUTH); Style.registerCssClasses(leftAndDesc, Dashboard.CSS_CLASS_COMMON_PANEL); // right editedParameterText = new JLabel(ORIGINAL_TEXT); editedParameterText.setPreferredSize(new Dimension(280, 40)); constDef = new JRadioButton("Constant"); listDef = new JRadioButton("List"); incrDef = new JRadioButton("Increment"); final JPanel rightTop = FormsUtils.build("p:g", "[DialogBorder]0||" + "1||" + "2||" + "3", editedParameterText, constDef, listDef, incrDef).getPanel(); Style.registerCssClasses(rightTop, Dashboard.CSS_CLASS_COMMON_PANEL); constDefField = new JTextField(); final JPanel constDefPanel = FormsUtils .build("p ~ p:g", "[DialogBorder]01 p", "Constant value: ", CellConstraints.TOP, constDefField) .getPanel(); listDefArea = new JTextArea(); final JScrollPane listDefScr = new JScrollPane(listDefArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); final JPanel listDefPanel = FormsUtils.build("p ~ p:g", "[DialogBorder]01|" + "_1 f:p:g||" + "_2 p", "Value list: ", listDefScr, "(Separate values with spaces!)").getPanel(); incrStartValueField = new JTextField(); incrEndValueField = new JTextField(); incrStepField = new JTextField(); final JPanel incrDefPanel = FormsUtils.build("p ~ p:g", "[DialogBorder]01||" + "23||" + "45", "Start value: ", incrStartValueField, "End value: ", incrEndValueField, "Step: ", incrStepField) .getPanel(); enumDefBox = new JComboBox(new DefaultComboBoxModel()); final JPanel enumDefPanel = FormsUtils .build("p ~ p:g", "[DialogBorder]01 p", "Constant value:", CellConstraints.TOP, enumDefBox) .getPanel(); submodelTypeBox = new JComboBox(); final JPanel submodelTypePanel = FormsUtils .build("p ~ p:g", "[DialogBorder]01", "Constant value:", CellConstraints.TOP, submodelTypeBox) .getPanel(); fileTextField = new JTextField(); fileTextField.addKeyListener(new KeyAdapter() { public void keyTyped(final KeyEvent e) { final char character = e.getKeyChar(); final File file = new File(Character.isISOControl(character) ? fileTextField.getText() : fileTextField.getText() + character); fileTextField.setToolTipText(file.getAbsolutePath()); } }); fileBrowseButton = new JButton(BROWSE_BUTTON_TEXT); fileBrowseButton.setActionCommand(ACTIONCOMMAND_BROWSE); final JPanel fileDefPanel = FormsUtils .build("p ~ p:g ~p", "[DialogBorder]012", "File:", fileTextField, fileBrowseButton).getPanel(); constDefPanel.setName("CONST"); listDefPanel.setName("LIST"); incrDefPanel.setName("INCREMENT"); enumDefPanel.setName("ENUM"); submodelTypePanel.setName("SUBMODEL"); fileDefPanel.setName("FILE"); Style.registerCssClasses(constDefPanel, Dashboard.CSS_CLASS_COMMON_PANEL); Style.registerCssClasses(listDefPanel, Dashboard.CSS_CLASS_COMMON_PANEL); Style.registerCssClasses(incrDefPanel, Dashboard.CSS_CLASS_COMMON_PANEL); Style.registerCssClasses(enumDefPanel, Dashboard.CSS_CLASS_COMMON_PANEL); Style.registerCssClasses(submodelTypePanel, Dashboard.CSS_CLASS_COMMON_PANEL); Style.registerCssClasses(fileDefPanel, Dashboard.CSS_CLASS_COMMON_PANEL); rightMiddle = new JPanel(new CardLayout()); Style.registerCssClasses(rightMiddle, Dashboard.CSS_CLASS_COMMON_PANEL); rightMiddle.add(constDefPanel, constDefPanel.getName()); rightMiddle.add(listDefPanel, listDefPanel.getName()); rightMiddle.add(incrDefPanel, incrDefPanel.getName()); rightMiddle.add(enumDefPanel, enumDefPanel.getName()); rightMiddle.add(submodelTypePanel, submodelTypePanel.getName()); rightMiddle.add(fileDefPanel, fileDefPanel.getName()); modifyButton = new JButton("Modify"); cancelButton = new JButton("Cancel"); final JPanel rightBottom = FormsUtils .build("p:g p ~ p ~ p:g", "[DialogBorder]_01_ p", modifyButton, cancelButton).getPanel(); Style.registerCssClasses(rightBottom, Dashboard.CSS_CLASS_COMMON_PANEL); final JPanel right = new JPanel(new BorderLayout()); right.add(rightTop, BorderLayout.NORTH); right.add(rightMiddle, BorderLayout.CENTER); right.add(rightBottom, BorderLayout.SOUTH); right.setBorder(BorderFactory.createTitledBorder(null, "Parameter settings", TitledBorder.LEADING, TitledBorder.BELOW_TOP)); Style.registerCssClasses(right, Dashboard.CSS_CLASS_COMMON_PANEL); // the whole paramsweep panel final JPanel content = FormsUtils.build("p:g p", "01 f:p:g", leftAndDesc, right).getPanel(); Style.registerCssClasses(content, Dashboard.CSS_CLASS_COMMON_PANEL); sweepPanel = new JPanel(); Style.registerCssClasses(sweepPanel, Dashboard.CSS_CLASS_COMMON_PANEL); sweepPanel.setLayout(new BorderLayout()); final JScrollPane sp = new JScrollPane(content); sp.setBorder(null); sp.setViewportBorder(null); sweepPanel.add(sp, BorderLayout.CENTER); GUIUtils.createButtonGroup(constDef, listDef, incrDef); constDef.setSelected(true); constDef.setActionCommand("CONST"); listDef.setActionCommand("LIST"); incrDef.setActionCommand("INCREMENT"); constDefField.setActionCommand("CONST_FIELD"); incrStartValueField.setActionCommand("START_FIELD"); incrEndValueField.setActionCommand("END_FIELD"); incrStepField.setActionCommand("STEP_FIELD"); modifyButton.setActionCommand("EDIT"); cancelButton.setActionCommand("CANCEL"); listDefArea.setLineWrap(true); listDefArea.setWrapStyleWord(true); listDefScr.setPreferredSize(new Dimension(100, 200)); GUIUtils.addActionListener(this, modifyButton, cancelButton, constDef, listDef, incrDef, constDefField, incrStartValueField, incrEndValueField, incrStepField, addNewBoxButton, submodelTypeBox, fileBrowseButton); return sweepPanel; }